import{aL as se,hG as we,b2 as V,ea as Fe,cJ as q,ca as Se,gB as B,kD as pe,kE as _e,cV as O,gf as be,gg as Ie,cL as Ce,gT as De,kF as de,i0 as R,U as j,c1 as ve,j0 as ce,dA as Y,i_ as Re,cE as ke,hR as he,bO as xe,cs as Te}from"./index.6c049565.js";import{C as L,t as y,i as P,o as C,n as D,c as K,s as v,l as Ne,d as Ae,f as H,a as T,b as N,N as Le,y as ye,e as Oe,w as z,p as Pe,g as G,m as Ee,h as qe,j as g}from"./SpatialFilter.bbcd60f7.js";import{$ as ie,a0 as S,a1 as je,a2 as k,v as Ge,a3 as J,a4 as re,a5 as Be,a6 as $,J as Ue,a7 as We}from"./arcadeUtils.8527a548.js";import{WhereClause as A}from"./WhereClause.39c9a123.js";import{n as Me,s as Qe}from"./executeForIds.4e97b9d4.js";class ge{constructor(){this.declaredRootClass="esri.arcade.featureSetCollection",this._layerById={},this._layerByName={}}add(e,t,s){this._layerById[t]=s,this._layerByName[e]=s}async featureSetByName(e,t=!0,s=["*"]){return this._layerByName[e]===void 0?null:this._layerByName[e]}async featureSetById(e,t=!0,s=["*"]){return this._layerById[e]===void 0?null:this._layerById[e]}castToText(e=!1){return"object, FeatureSetCollection"}}class U extends L{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.actions.AttributeFilter",this._maxProcessing=1e3,this._parent=e.parentfeatureset,e.whereclause instanceof A?(this._whereclause=e.whereclause,this._whereClauseFunction=null):(this._whereClauseFunction=e.whereclause,this._whereclause=null)}_initialiseFeatureSet(){this._parent!==null?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.fields=[],this.typeIdField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new se({wkid:4326}),this.geometryType=ie.point)}async _getSet(e){if(this._wset===null){await this._ensureLoaded();const t=await this._parent._getFilteredSet("",null,this._whereclause,null,e);return this._checkCancelled(e),this._whereClauseFunction!==null?this._wset=new y(t._candidates.slice(0).concat(t._known.slice(0)),[],t._ordered,this._clonePageDefinition(t.pagesDefinition)):this._wset=new y(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){var s;let t=(s=this._parent)==null?void 0:s._isInFeatureSet(e);return t===S.NotInFeatureSet?t:(t=this._idstates[e],t===void 0?S.Unknown:t)}_getFeature(e,t,s){return this._parent._getFeature(e,t,s)}_getFeatures(e,t,s,i){return this._parent._getFeatures(e,t,s,i)}_featureFromCache(e){return this._parent._featureFromCache(e)}executeWhereClause(e){var t,s;return(s=(t=this._whereclause)==null?void 0:t.testFeature(e))!=null?s:!1}async executeWhereClauseDeferred(e){if(this._whereClauseFunction!==null){const t=this._whereClauseFunction(e);return we(t),t}return this.executeWhereClause(e)}async _fetchAndRefineFeatures(e,t,s){var n,l,u;const i=new y([],e,!1,null),r=Math.min(t,e.length);if(await((n=this._parent)==null?void 0:n._getFeatures(i,-1,r,s)),this._checkCancelled(s),this._whereClauseFunction==null){for(let o=0;o":case"=":if(e.left.type==="column-reference"&&e.right.type==="string"){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&this.lkp[e.right.value.toString()]!==void 0)return" ("+i+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if(e.right.type==="column-reference"&&e.left.type==="string"&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+i+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,s,w.BADNESS,r)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,s,w.BADNESS,r)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":return" ("+this.evaluateNodeToWhereClause(e.left,t,s,w.BADNESS,r)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,s,w.BADNESS,r)+") "}case"null":return"null";case"boolean":return e.value===!0?"1":"0";case"string":return"'"+e.value.toString().replace(/'/g,"''")+"'";case"timestamp":case"date":return H(e.value,t);case"number":return e.value.toString();case"current-time":return Ae(e.mode==="date",t);case"column-reference":return s&&s.toLowerCase()===e.column.toLowerCase()?"("+i+")":e.column;case"function":{const o=this.evaluateNodeToWhereClause(e.args,t,s,w.BADNESS,r);return Ne(e.name,o,t)}}throw new T(N.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof A?this.reverseLkp[this.codefield.calculateValueCompiled(e)]:this.reverseLkp[e.attributes[this.codefield]]}}w.BADNESS="_!!!_BAD_LKP_!!!!";class Je extends X{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:K(e,this.field.name,v(this._sql,k.Standardised),t.getFieldsIndex())}}extractValue(e){return this._sql.calculateValueCompiled(e)}}class Ke extends L{constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=[],this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}static findField(e,t){for(const s of e)if(s.name.toLowerCase()===t.toString().toLowerCase())return s;return null}_initialiseFeatureSet(){this._parent!==null?(this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.spatialReference=new se({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=ie.point,this.typeIdField="",this.types=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){var t;if(this._wset===null){await this._ensureLoaded();let s=null;return s=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await((t=this._parent)==null?void 0:t._getSet(e)),this._checkCancelled(e),Fe(s),this._wset=new y(s._candidates.slice(0),s._known.slice(0),s._ordered,this._clonePageDefinition(s.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return V(this._parent)._isInFeatureSet(e)}async _getFeatures(e,t,s,i){var o,d;const r=[];t!==-1&&this._featureCache[t]===void 0&&r.push(t);const a=this._maxQueryRate();if(this._checkIfNeedToExpandKnownPage(e,a)===!0)return await this._expandPagedSet(e,a,0,0,i),this._getFeatures(e,t,s,i);let n=0;for(let c=e._lastFetchedIndex;c=a)));c++);if(r.length===0)return"success";e=new y([],r,e._ordered,null);const l=Math.min(r.length,s);await((o=this._parent)==null?void 0:o._getFeatures(e,-1,l,i)),this._checkCancelled(i);const u=[];for(let c=0;c0&&(i=i.replaceFields(d))}s!==null?this._extraFilter!==null&&(s=P(this._extraFilter,s)):s=this._extraFilter,await this._ensureLoaded();const u=await V(this._parent)._getFilteredSet(e,t,s,i,r);let o;return this._checkCancelled(r),o=a===!0?new y(u._candidates.slice(0).concat(u._known.slice(0)),[],l===!0&&u._ordered,this._clonePageDefinition(u.pagesDefinition)):new y(u._candidates.slice(0),u._known.slice(0),l===!0&&u._ordered,this._clonePageDefinition(u.pagesDefinition)),o}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(e!==null){for(const s of this.adaptedFields)if(ye(e,s.field.name)===!0){const i=s.rewriteSql(e,this);if(i.rewritten!==!0){t.cannot=!0,t.where=null;break}t.where=i.where}}return t}async _stat(e,t,s,i,r,a,n){let l=!1,u=this._reformulateWithoutAdaptions(t);if(l=u.cannot,t=u.where,u=this._reformulateWithoutAdaptions(r),l=l||u.cannot,(r=u.where)!==null?this._extraFilter!==null&&(r=P(this._extraFilter,r)):r=this._extraFilter,l===!0)return r===null&&s===""&&i===null?this._manualStat(e,t,a,n):{calculated:!1};const o=await V(this._parent)._stat(e,t,s,i,r,a,n);return o.calculated===!1?r===null&&s===""&&i===null?this._manualStat(e,t,a,n):{calculated:!1}:o}async _canDoAggregates(e,t,s,i,r){if(this._parent===null)return!1;for(let l=0;l{for(let i=0;i0?(await J(this._refineSetBlock(e,this._maxProcessingRate(),i)),this._checkCancelled(i),this.getIdColumnDictionary(e,t,s,i)):t}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,s,i){return this._parent._getFeatures(e,t,s,i)}_featureFromCache(e){if(this._featureCache[e]===void 0){const t=this._parent._featureFromCache(e);return t===void 0?void 0:t===null?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new C(D.NeverReach)}async _getFilteredSet(e,t,s,i,r){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,s,i===null?this._orderbyclause:i,r);this._checkCancelled(r);const n=new y(a._candidates.slice(0),a._known.slice(0),a._ordered,this._clonePageDefinition(a.pagesDefinition));let l=!0;if(a._candidates.length>0&&(l=!1),n._ordered===!1){let u=await this.manualOrderSet(n,r);return l===!1&&(t===null&&s===null||(u=new y(u._candidates.slice(0).concat(u._known.slice(0)),[],u._ordered,this._clonePageDefinition(u.pagesDefinition)))),u}return n}static registerAction(){L._featuresetFunctions.orderBy=function(e){return e===""?this:new M({parentfeatureset:this,orderbyclause:new W(e)})}}}function ze(h){if(h.parseTree.type==="function"){if(h.parseTree.args.value.length===0)return{name:h.parseTree.name,expr:null};if(h.parseTree.args.value.length>1)throw new T(N.MissingStatisticParameters);const e=A.create(Oe(h.parseTree.args.value[0],k.Standardised,h.parameters),h.fieldsIndex);return{name:h.parseTree.name,expr:e}}return null}class Q{constructor(){this.field="",this.tofieldname="",this.typeofstat="MIN",this.workingexpr=null}clone(){const e=new Q;return e.field=this.field,e.tofieldname=this.tofieldname,e.typeofstat=this.typeofstat,e.workingexpr=this.workingexpr,e}static parseStatField(e,t,s){const i=new Q;i.field=e;const r=A.create(t,s),a=ze(r);if(a===null)throw new T(N.UnsupportedSqlFunction,{function:""});const n=a.name.toUpperCase().trim();if(n==="MIN"){if(i.typeofstat="MIN",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:"min"})}else if(n==="MAX"){if(i.typeofstat="MAX",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:"max"})}else if(n==="COUNT")i.typeofstat="COUNT",i.workingexpr=a.expr;else if(n==="STDEV"){if(i.typeofstat="STDDEV",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:"stdev"})}else if(n==="SUM"){if(i.typeofstat="SUM",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:"sum"})}else if(n==="MEAN"){if(i.typeofstat="AVG",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:n})}else if(n==="AVG"){if(i.typeofstat="AVG",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:"avg"})}else{if(n!=="VAR")throw new T(N.UnsupportedSqlFunction,{function:n});if(i.typeofstat="VAR",i.workingexpr=a.expr,r===null)throw new T(N.InvalidFunctionParameters,{function:"var"})}return i}toStatisticsName(){switch(this.typeofstat.toUpperCase()){case"MIN":return"min";case"MAX":return"max";case"SUM":return"sum";case"COUNT":default:return"count";case"VAR":return"var";case"STDDEV":return"stddev";case"AVG":return"avg"}}}function Ze(h){if(!h)return"COUNT";switch(h.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class ae extends L{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(this._wset===null){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return S.InFeatureSet}_nextUniqueName(e){for(;e["T"+this._uniqueIds.toString()]===1;)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,s=1;const i=this._parent?this._parent.getFieldsIndex():new Se([]);for(this.objectIdField="ROW__ID",this.globalIdField="";t===!1;){let a=!1;for(let n=0;n0)for(const a of this._parent.fields)this._adaptedFields.push(new ee(a));for(let a=0;a0&&(l=new Ke({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),n.nowhereclause===!0)a=new y(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new M({parentfeatureset:l,orderbyclause:new W(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let u=l;if(s!==null){let o=null;s&&(o=this._reformulateWhereClauseWithoutGroupByFields(s)),u=new U({parentfeatureset:u,whereclause:o})}a=new y(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new M({parentfeatureset:u,orderbyclause:new W(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return a}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=K(e,t.tofieldname,v(t.workingexpr,k.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=K(e,t.tofieldname,v(t.expression,k.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const s of this._decodedGroupbyfield)s.tofieldname!==s.name&&t.push({field:s.tofieldname,newfield:s.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return e===null?null:e.aggregatefeaturesetpagedefinition===!0?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,s){return this._checkIfNeedToExpandCandidatePage(e,this._maxQuery)===!0?(await this._expandPagedSet(e,this._maxQuery,0,0,s),this._refineSetBlock(e,t,s)):(this._checkCancelled(s),e._candidates.length,this._refineKnowns(e,t),e._candidates.length,e._candidates.length,e)}_expandPagedSet(e,t,s,i,r){return this._expandPagedSetFeatureSet(e,t,s,i,r)}async _getPhysicalPage(e,t,s){if(e.pagesDefinition.aggregatefeaturesetpagedefinition===!0)return this._sequentialGetPhysicalItem(e,e.pagesDefinition.resultRecordCount,s,[]);const i=await this._getAgregagtePhysicalPage(e,t,s);for(const r of i){const a={geometry:r.geometry,attributes:{}};for(const n of this._decodedGroupbyfield)a.attributes[n.tofieldname]=r.attributes[n.name];for(const n of this._decodedStatsfield)a.attributes[n.tofieldname]=r.attributes[n.field];this._featureCache[a.attributes[this.objectIdField]]=new q(a)}return i.length}_sequentialGetPhysicalItem(e,t,s,i){return new Promise((r,a)=>{e.pagesDefinition.internal.iterator===null&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(s)),e.pagesDefinition.internal.fullyResolved===!0||t===0?r(i.length):this._nextAggregateItem(e,t,s,i,n=>{n===null?r(i.length):(t-=1,r(this._sequentialGetPhysicalItem(e,t,s,i)))},a)})}_nextAggregateItem(e,t,s,i,r,a){try{J(e.pagesDefinition.internal.iterator.next()).then(n=>{if(n===null)if(e.pagesDefinition.internal.workingItem!==null){const l=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);i.push(l),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(l.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const l=this._generateAggregateHash(n);if(e.pagesDefinition.internal.workingItem===null)e.pagesDefinition.internal.workingItem={features:[n],id:l};else{if(l!==e.pagesDefinition.internal.workingItem.id){const u=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return i.push(u),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(u.attributes[this.objectIdField]),t-=1,e.pagesDefinition.internal.workingItem={features:[n],id:l},void r(u)}e.pagesDefinition.internal.workingItem.features.push(n)}this._nextAggregateItem(e,t,s,i,r,a)}},a)}catch(n){a(n)}}_calculateFieldStat(e,t,s){const i=[];for(let r=0;rthis._topnum&&(this._wset._known=this._wset._known.slice(0,this._topnum)),this._setKnownLength(this._wset)>=this._topnum&&(this._wset._candidates=[]),this._wset}return this._wset}_setKnownLength(e){return e._known.length>0&&e._known[e._known.length-1]==="GETPAGES"?e._known.length-1:e._known.length}_isInFeatureSet(e){const t=this._parent._isInFeatureSet(e);if(t===S.NotInFeatureSet)return t;const s=this._idstates[e];return s===S.InFeatureSet||s===S.NotInFeatureSet?s:t===S.InFeatureSet&&s===void 0?this._countedinthis._topnum&&(t=this._topnum),this._countedin>=this._topnum&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset){let n=e._known.length;return n>0&&e._known[n-1]==="GETPAGES"&&(e._known.length=n-1),n=e._candidates.length,n>0&&e._candidates[n-1]==="GETPAGES"&&(e._candidates.length=n-1),"success"}const a=await this._parent._expandPagedSet(e,t,s,i,r);return this._setKnownLength(e)>this._topnum&&(e._known.length=this._topnum),this._setKnownLength(e)>=this._topnum&&(e._candidates.length=0),a}async _getFeatures(e,t,s,i){const r=[],a=this._maxQueryRate();if(this._checkIfNeedToExpandKnownPage(e,a)===!0)return await this._expandPagedSet(e,a,0,0,i),this._getFeatures(e,t,s,i);t!==-1&&this._featureCache[t]===void 0&&r.push(t);let n=0;for(let o=e._lastFetchedIndex;oa)));o++);if(r.length===0)return"success";const l=new y([],r,!1,null),u=Math.min(r.length,s);await this._parent._getFeatures(l,-1,u,i);for(let o=0;o=this._topnum)break}else if(n===S.NotInFeatureSet)i===null?i={start:a,end:a}:i.end===a-1?i.end=a:(r.push(i),i={start:a,end:a}),s+=1;else if(n===S.Unknown)break;if(s>=t)break}i!==null&&r.push(i);for(let a=r.length-1;a>=0;a--)e._candidates.splice(r[a].start,r[a].end-r[a].start+1);this._setKnownLength(e)>this._topnum&&(e._known=e._known.slice(0,this._topnum)),this._setKnownLength(e)>=this._topnum&&(e._candidates=[])}async _stat(){return{calculated:!1}}async _canDoAggregates(){return!1}static registerAction(){L._featuresetFunctions.top=function(e){return new ne({parentfeatureset:this,topnum:e})}}}class Z extends L{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerDynamic",this._removeGeometry=!1,this._overrideFields=null,this.formulaCredential=null,this._pageJustIds=!1,this._requestStandardised=!1,this._useDefinitionExpression=!0,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,e.outFields!==void 0&&(this._overrideFields=e.outFields),e.includeGeometry!==void 0&&(this._removeGeometry=e.includeGeometry===!1)}_maxQueryRate(){return re}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}convertQueryToLruCacheKey(e){const t=Be(e.toJSON());return pe(t,_e.String)}async loadImpl(){return this._layer.loaded===!0?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){var e;if(this.spatialReference==null&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this._layer.outFields&&!(this._layer.outFields.length===1&&this._layer.outFields[0]==="*")){const t=[];for(const s of this.fields)if(s.type==="oid")t.push(s);else for(const i of this._layer.outFields)if(i.toLowerCase()===s.name.toLowerCase()){t.push(s);break}this.fields=t}if(this._overrideFields!==null)if(this._overrideFields.length===1&&this._overrideFields[0]==="*")this._overrideFields=null;else{const t=[],s=[];for(const i of this.fields)if(i.type==="oid")t.push(i),s.push(i.name);else for(const r of this._overrideFields)if(r.toLowerCase()===i.name.toLowerCase()){t.push(i),s.push(i.name);break}this.fields=t,this._overrideFields=s}if(this._layer.source&&this._layer.source.sourceJSON){const t=this._layer.source.sourceJSON.currentVersion;this._layer.source.sourceJSON.useStandardizedQueries===!0?(this._databaseType=k.StandardisedNoInterval,t!=null&&t>=10.61&&(this._databaseType=k.Standardised)):t!=null&&(t>=10.5&&(this._databaseType=k.StandardisedNoInterval,this._requestStandardised=!0),t>=10.61&&(this._databaseType=k.Standardised))}this.objectIdField=this._layer.objectIdField;for(const t of this.fields)t.type==="global-id"&&(this.globalIdField=t.name);this.hasM=this._layer.supportsM,this.hasZ=this._layer.supportsZ,this.typeIdField=(e=this._layer.typeIdField)!=null?e:"",this.types=this._layer.types}_isInFeatureSet(){return S.InFeatureSet}async _refineSetBlock(e){return e}_candidateIdTransform(e){return e}async _getSet(e){if(this._wset===null){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}async _runDatabaseProbe(e){await this._ensureLoaded();const t=new O;t.where=e.replace("OBJECTID",this._layer.objectIdField);try{return await this._layer.queryObjectIds(t),!0}catch{return!1}}_canUsePagination(){return!(!this._layer.capabilities||!this._layer.capabilities.query||this._layer.capabilities.query.supportsPagination!==!0)}_cacheableFeatureSetSourceKey(){return this._layer.url}pbfSupportedForQuery(e){var s,i;const t=(i=(s=this._layer)==null?void 0:s.capabilities)==null?void 0:i.query;return!e.outStatistics&&(t==null?void 0:t.supportsFormatPBF)===!0&&(t==null?void 0:t.supportsQuantizationEditMode)===!0}async queryPBF(e){e.quantizationParameters={mode:"edit"};const t=await be(this._layer.parsedUrl,e,new Ie({}));return Ce.fromJSON(De(t.data)).unquantize()}get gdbVersion(){return this._layer&&this._layer.capabilities&&this._layer.capabilities.data&&this._layer.capabilities.data.isVersioned?this._layer.gdbVersion?this._layer.gdbVersion:"SDE.DEFAULT":""}nativeCapabilities(){var e;return{title:(e=this._layer.title)!=null?e:"",source:this,canQueryRelated:!0,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:this._requestStandardised}}executeQuery(e,t){const s=t==="execute"?ce:t==="executeForCount"?Me:Qe,i=t==="execute"&&this.pbfSupportedForQuery(e);let r=null;if(this.recentlyUsedQueries){const a=this.convertQueryToLruCacheKey(e);r=this.recentlyUsedQueries.getFromCache(a),r===null&&(r=i!==!0?s(this._layer.parsedUrl.path,e):this.queryPBF(e),this.recentlyUsedQueries.addToCache(a,r),r=r.catch(n=>{var l;throw(l=this.recentlyUsedQueries)==null||l.removeFromCache(a),n}))}return this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:e,method:t}),r===null&&(r=i!==!0?s(this._layer.parsedUrl.path,e):this.queryPBF(e)),r}async _getFilteredSet(e,t,s,i,r){const a=await this.databaseType();if(this.isTable()&&t&&e!==null&&e!=="")return new y([],[],!0,null);if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,s,i,r);let n="",l=!1;i!==null&&this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsOrderBy===!0&&(n=i.constructClause(),l=!0);const u=new O;u.where=s===null?t===null?"1=1":"":v(s,a),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=n!==""?n.split(","):null,u.geometry=t===null?null:t,u.relationParameter=this._makeRelationshipParam(e);let o=await this.executeQuery(u,"executeForIds");return o===null&&(o=[]),this._checkCancelled(r),new y([],o,l,null)}_expandPagedSet(e,t,s,i,r){return this._expandPagedSetFeatureSet(e,t,s,i,r)}async _getFilteredSetUsingPaging(e,t,s,i,r){var f;let a="",n=!1;i!==null&&this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsOrderBy===!0&&(a=i.constructClause(),n=!0);const l=await this.databaseType();let u=s===null?t===null?"1=1":"":v(s,l);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=u!==""?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let o=this._maxQueryRate();const d=(f=this._layer.capabilities)==null?void 0:f.query.maxRecordCount;d!==void 0&&d=this._maxProcessingRate()-1))break}if(a>=s&&r.length===0)break}if(r.length===0)return"success";const n=new O;this._requestStandardised&&(n.sqlFormat="standard"),n.objectIds=r,n.outFields=this._overrideFields!==null?this._overrideFields:this._fieldsIncludingObjectId(this._layer.outFields?this._layer.outFields:["*"]),n.returnGeometry=!0,this._removeGeometry===!0&&(n.returnGeometry=!1),n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(i),l.error!==void 0)throw new C(D.RequestFailed,{reason:l.error});const u=this._layer.objectIdField;for(let o=0;o=n)break}return m.features.length===0?l:m.features.length===((_=this._layer.capabilities)==null?void 0:_.query.maxRecordCount)&&l.length"+e.pagesDefinition.internal.lastMaxId.toString()+")":e.pagesDefinition.generatedOid+">"+e.pagesDefinition.internal.lastMaxId.toString());const r=e.pagesDefinition.internal.lastRetrieved,a=r,n=e.pagesDefinition.internal.lastPage,l=new O;if(this._requestStandardised&&(l.sqlFormat="standard"),l.where=i,l.spatialRelationship=e.pagesDefinition.spatialRel,l.relationParameter=e.pagesDefinition.relationParam,l.outFields=e.pagesDefinition.outFields,l.outStatistics=e.pagesDefinition.outStatistics,l.geometry=e.pagesDefinition.geometry,l.groupByFieldsForStatistics=e.pagesDefinition.groupByFieldsForStatistics,l.num=e.pagesDefinition.resultRecordCount,l.start=e.pagesDefinition.internal.lastPage,l.returnGeometry=e.pagesDefinition.returnGeometry,l.orderByFields=e.pagesDefinition.orderByFields!==""?e.pagesDefinition.orderByFields.split(","):null,this.isTable()&&l.geometry&&l.spatialRelationship)return[];const u=await this.executeQuery(l,"execute");if(this._checkCancelled(s),!u.hasOwnProperty("features"))throw new C(D.InvalidStatResponse);const o=[];if(e.pagesDefinition.internal.lastPage!==n)return[];for(let d=0;d0||s&&s>0)&&(n.size=[t&&t>0?t:0,s&&s>0?s:t+1]),i&&i.length>0&&(n.attachmentTypes=i),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:n,method:"attachments"});const l=await this._layer.queryAttachments(n),u=[];return l&&l[e]&&l[e].forEach(o=>{const d=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+o.id.toString();let c=null;r&&o.exifInfo&&(c=Ue.convertJsonToArcade(o.exifInfo,!0)),u.push(new We(o.id,o.name,o.contentType,o.size,d,c))}),u}return[]}async queryRelatedFeatures(e){var i;const t={f:"json",relationshipId:e.relationshipId.toString(),definitionExpression:e.where,outFields:(i=e.outFields)==null?void 0:i.join(","),returnGeometry:e.returnGeometry.toString()};e.resultOffset!==void 0&&e.resultOffset!==null&&(t.resultOffset=e.resultOffset.toString()),e.resultRecordCount!==void 0&&e.resultRecordCount!==null&&(t.resultRecordCount=e.resultRecordCount.toString()),e.orderByFields&&(t.orderByFields=e.orderByFields.join(",")),e.objectIds&&e.objectIds.length>0&&(t.objectIds=e.objectIds.join(",")),e.outSpatialReference&&(t.outSR=JSON.stringify(e.outSpatialReference.toJSON())),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:t,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await j(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:t});if(s.data){const r={},a=s.data;if(a&&a.relatedRecordGroups){const n=a.spatialReference;for(const l of a.relatedRecordGroups){const u=l.objectId,o=[];for(const d of l.relatedRecords){d.geometry&&(d.geometry.spatialReference=n);const c=new q({geometry:d.geometry?ve(d.geometry):null,attributes:d.attributes});o.push(c)}r[u]={features:o,exceededTransferLimit:a.exceededTransferLimit===!0}}}return r}throw new C(D.InvalidRequest)}async getFeatureByObjectId(e,t){const s=new O;s.outFields=t,s.returnGeometry=!1,s.outSpatialReference=this.spatialReference,s.where=this.objectIdField+"="+e.toString(),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:s,method:"execute"});const i=await ce(this._layer.parsedUrl.path,s);return i.features.length===1?i.features[0]:null}async getIdentityUser(){var t;await this.load();const e=(t=Y)==null?void 0:t.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){var i;await this.load();const e=(i=Y)==null?void 0:i.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let t=this._layer.url;const s=t.toLowerCase().indexOf("/rest/services");if(t=s>-1?t.substring(0,s):t,t){t+="/rest/info";try{const r=await j(t,{query:{f:"json"}});let a="";return r.data&&r.data.owningSystemUrl&&(a=r.data.owningSystemUrl),a}catch{return""}}return""}getDataSourceFeatureSet(){var t,s,i,r;const e=new Z({layer:this._layer,spatialReference:(t=this.spatialReference)!=null?t:void 0,outFields:(s=this._overrideFields)!=null?s:void 0,includeGeometry:!this._removeGeometry,lrucache:(i=this.recentlyUsedQueries)!=null?i:void 0,interceptor:(r=this.featureSetQueryInterceptor)!=null?r:void 0});return e._useDefinitionExpression=!1,e}}class le extends L{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerMemory",this._removeGeometry=!1,this._overrideFields=null,this._forceIsTable=!1,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,e.isTable===!0&&(this._forceIsTable=!0),e.outFields!==void 0&&(this._overrideFields=e.outFields),e.includeGeometry!==void 0&&(this._removeGeometry=e.includeGeometry===!1)}_maxQueryRate(){return re}end(){return this._layer}optimisePagingFeatureQueries(){}async loadImpl(){return this._layer.loaded===!0?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}get gdbVersion(){return""}_initialiseFeatureSet(){if(this.spatialReference==null&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this._layer.outFields&&!(this._layer.outFields.length===1&&this._layer.outFields[0]==="*")){const e=[];for(const t of this.fields)if(t.type==="oid")e.push(t);else for(const s of this._layer.outFields)if(s.toLowerCase()===t.name.toLowerCase()){e.push(t);break}this.fields=e}if(this._overrideFields!==null)if(this._overrideFields.length===1&&this._overrideFields[0]==="*")this._overrideFields=null;else{const e=[],t=[];for(const s of this.fields)if(s.type==="oid")e.push(s),t.push(s.name);else for(const i of this._overrideFields)if(i.toLowerCase()===s.name.toLowerCase()){e.push(s),t.push(s.name);break}this.fields=e,this._overrideFields=t}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)e.type==="global-id"&&(this.globalIdField=e.name);this.hasM=this._layer.supportsM,this.hasZ=this._layer.supportsZ,this._databaseType=k.Standardised,this.typeIdField=this._layer.typeIdField,this.types=this._layer.types}isTable(){return this._forceIsTable||this._layer.isTable||this._layer.type==="table"||!this._layer.geometryType}_isInFeatureSet(){return S.InFeatureSet}_candidateIdTransform(e){return e}async _getSet(e){if(this._wset===null){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}_changeFeature(e){const t={};for(const s of this.fields)t[s.name]=e.attributes[s.name];return new q({geometry:this._removeGeometry===!0?null:e.geometry,attributes:t})}async _getFilteredSet(e,t,s,i,r){let a="",n=!1;if(i!==null&&(a=i.constructClause(),n=!0),this.isTable()&&t&&e!==null&&e!=="")return new y([],[],!0,null);const l=new O;l.where=s===null?t===null?"1=1":"":v(s,k.Standardised),l.spatialRelationship=this._makeRelationshipEnum(e),l.outSpatialReference=this.spatialReference,l.orderByFields=a!==""?a.split(","):null,l.geometry=t===null?null:t,l.returnGeometry=!0,l.relationParameter=this._makeRelationshipParam(e);const u=await this._layer.queryFeatures(l);if(u===null)return new y([],[],n,null);this._checkCancelled(r);const o=[];return u.features.forEach(d=>{const c=d.attributes[this._layer.objectIdField];o.push(c),this._featureCache[c]=this._changeFeature(d)}),new y([],o,n,null)}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _queryAllFeatures(){if(this._wset)return this._wset;const e=new O;if(e.where="1=1",await this._ensureLoaded(),this._layer.source&&this._layer.source.items){const i=[];return this._layer.source.items.forEach(r=>{const a=r.attributes[this._layer.objectIdField];i.push(a),this._featureCache[a]=this._changeFeature(r)}),this._wset=new y([],i,!1,null),this._wset}const t=await this._layer.queryFeatures(e),s=[];return t.features.forEach(i=>{const r=i.attributes[this._layer.objectIdField];s.push(r),this._featureCache[r]=this._changeFeature(i)}),this._wset=new y([],s,!1,null),this._wset}async _getFeatures(e,t,s){const i=[];t!==-1&&this._featureCache[t]===void 0&&i.push(t);for(let r=e._lastFetchedIndex;rs)));r++);if(i.length===0)return"success";throw new C(D.MissingFeatures)}async _refineSetBlock(e){return e}async _stat(){return{calculated:!1}}async _canDoAggregates(){return!1}relationshipMetaData(){return[]}static _cloneAttr(e){const t={};for(const s in e)t[s]=e[s];return t}nativeCapabilities(){var e;return{title:(e=this._layer.title)!=null?e:"",canQueryRelated:!1,source:this,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:!0}}static create(e,t){let s=e.layerDefinition.objectIdField;const i=e.layerDefinition.typeIdField?e.layerDefinition.typeIdField:"",r=[];if(e.layerDefinition.types)for(const f of e.layerDefinition.types)r.push(Re.fromJSON(f));let a=e.layerDefinition.geometryType;a===void 0&&(a=e.featureSet.geometryType||"");let n=e.featureSet.features;const l=t.toJSON();if(s===""||s===void 0){let f=!1;for(const p of e.layerDefinition.fields)if(p.type==="oid"||p.type==="esriFieldTypeOID"){s=p.name,f=!0;break}if(f===!1){let p="FID",m=!0,I=0;for(;m;){let _=!0;for(const b of e.layerDefinition.fields)if(b.name===p){_=!1;break}_===!0?m=!1:(I++,p="FID"+I.toString())}e.layerDefinition.fields.push({type:"esriFieldTypeOID",name:p,alias:p});const F=[];for(let _=0;__.name):["*"]);u.outFields=o,u.relationshipId=this.relationship.id,u.where="1=1";let d=!0;this._removeGeometry===!0&&(d=!1),u.returnGeometry=d,this._requestStandardised&&(u.sqlFormat="standard"),u.outSpatialReference=this.spatialReference,u.orderByFields=n!==""?n.split(","):null;const c=await a.source.queryRelatedFeatures(u);this._checkCancelled(r);const f=c[this._findObjectId]?c[this._findObjectId].features:[],p=[];for(let _=0;_b.name):["*"]);return p=new y(c||f?["GETPAGES"]:[],c||f?[]:["GETPAGES"],n,{outFields:I.join(","),resultRecordCount:o,resultOffset:0,objectIds:[this._findObjectId],where:u,orderByFields:a,returnGeometry:m,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}}),await this._expandPagedSet(p,o,0,0,r),p}_expandPagedSet(e,t,s,i,r){return this._expandPagedSetFeatureSet(e,t,s,i,r)}_clonePageDefinition(e){return e===null?null:e.groupbypage!==!0?{groupbypage:!1,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,where:e.where,objectIds:e.objectIds,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,objectIds:e.objectIds,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,s){const i=e.pagesDefinition.internal.lastRetrieved,r=i,a=e.pagesDefinition.internal.lastPage,n=this._layer.nativeCapabilities(),l=new he;this._requestStandardised===!0&&(l.sqlFormat="standard"),l.relationshipId=this.relationship.id,l.objectIds=e.pagesDefinition.objectIds,l.resultOffset=e.pagesDefinition.internal.lastPage,l.resultRecordCount=e.pagesDefinition.resultRecordCount,l.outFields=e.pagesDefinition.outFields.split(","),l.where=e.pagesDefinition.where,l.orderByFields=e.pagesDefinition.orderByFields!==""?e.pagesDefinition.orderByFields.split(","):null,l.returnGeometry=e.pagesDefinition.returnGeometry,l.outSpatialReference=this.spatialReference;const u=await n.source.queryRelatedFeatures(l);if(this._checkCancelled(s),e.pagesDefinition.internal.lastPage!==a)return 0;const o=u[this._findObjectId]?u[this._findObjectId].features:[];for(let c=0;cs)))&&!(n>=s&&r.length===0);l++);if(r.length===0)return"success";throw new C(D.MissingFeatures)}async _refineSetBlock(e,t,s){return e}async _stat(e,t,s,i,r,a,n){return{calculated:!1}}get gdbVersion(){return this._relatedLayer.gdbVersion}async _canDoAggregates(e,t,s,i,r){return!1}relationshipMetaData(){return this._relatedLayer.relationshipMetaData()}serviceUrl(){return this._relatedLayer.serviceUrl()}queryAttachments(e,t,s,i,r){return this._relatedLayer.queryAttachments(e,t,s,i,r)}getFeatureByObjectId(e,t){return this._relatedLayer.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._relatedLayer.getOwningSystemUrl()}getIdentityUser(){return this._relatedLayer.getIdentityUser()}getDataSourceFeatureSet(){return this._relatedLayer}}function He(){g.applicationCache===null&&(g.applicationCache=new g)}async function te(h,e){if(g.applicationCache){const t=g.applicationCache.getLayerInfo(h);if(t){const r=await t;return new R({url:h,outFields:e,sourceJSON:r})}const s=new R({url:h,outFields:e}),i=(async()=>(await s.load(),s.sourceJSON))();if(g.applicationCache){g.applicationCache.setLayerInfo(h,i);try{return await i,s}catch(r){throw g.applicationCache.clearLayerInfo(h),r}}return await i,s}return new R({url:h,outFields:e})}async function oe(h,e,t,s,i,r=null){return E(await te(h,["*"]),e,t,s,i,r)}function E(h,e=null,t=null,s=!0,i=null,r=null){const a={layer:h,spatialReference:e,outFields:t,includeGeometry:s,lrucache:i,interceptor:r};return h._hasMemorySource()===!0?new le(a):new Z(a)}async function Ye(h){if(g.applicationCache!==null){const t=g.applicationCache.getLayerInfo(h);if(t!==null)return t}const e=(async()=>{const t=await j(h,{responseType:"json",query:{f:"json"}});return t.data?t.data:null})();if(g.applicationCache!==null){g.applicationCache.setLayerInfo(h,e);try{return await e}catch(t){throw g.applicationCache.clearLayerInfo(h),t}}return e}async function $e(h,e){const t="QUERYDATAELEMTS:"+e.toString()+":"+h;if(g.applicationCache!==null){const i=g.applicationCache.getLayerInfo(t);if(i!==null)return i}const s=(async()=>{const i=await j(h+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([e.toString()]),f:"json"}});if(i.data){const r=i.data;if(r.layerDataElements&&r.layerDataElements[0])return r.layerDataElements[0]}throw new C(D.DataElementsNotFound)})();if(g.applicationCache!==null){g.applicationCache.setLayerInfo(t,s);try{return await s}catch(i){throw g.applicationCache.clearLayerInfo(t),i}}return s}async function me(h){if(g.applicationCache!==null){const t=g.applicationCache.getLayerInfo(h);if(t!==null)return t}const e=(async()=>{const t=await j(h,{responseType:"json",query:{f:"json"}});if(t.data){const s=t.data;return s.layers||(s.layers=[]),s.tables||(s.tables=[]),s}return{layers:[],tables:[]}})();if(g.applicationCache!==null){g.applicationCache.setLayerInfo(h,e);try{return await e}catch(t){throw g.applicationCache.clearLayerInfo(h),t}}return e}async function et(h,e){const t={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},s=await me(h);if(t.metadata=s,s.controllerDatasetLayers&&s.controllerDatasetLayers.utilityNetworkLayerId!==void 0&&s.controllerDatasetLayers.utilityNetworkLayerId!==null){if(s.layers)for(const a of s.layers)t.layerNameLkp[a.id]=a.name;if(s.tables)for(const a of s.tables)t.layerNameLkp[a.id]=a.name;const i=s.controllerDatasetLayers.utilityNetworkLayerId;t.networkId=i;const r=await $e(h,i);if(r){t.queryelem=r,t.queryelem&&t.queryelem.dataElement&&t.queryelem.dataElement.schemaGeneration!==void 0&&(t.unVersion=t.queryelem.dataElement.schemaGeneration),t.lkp={},t.queryelem.dataElement.domainNetworks||(t.queryelem.dataElement.domainNetworks=[]);for(const n of t.queryelem.dataElement.domainNetworks){for(const l of n.edgeSources?n.edgeSources:[]){const u={layerId:l.layerId,sourceId:l.sourceId,className:t.layerNameLkp[l.layerId]?t.layerNameLkp[l.layerId]:null};u.className&&(t.lkp[u.className]=u)}for(const l of n.junctionSources?n.junctionSources:[]){const u={layerId:l.layerId,sourceId:l.sourceId,className:t.layerNameLkp[l.layerId]?t.layerNameLkp[l.layerId]:null};u.className&&(t.lkp[u.className]=u)}}if(t.queryelem.dataElement.terminalConfigurations)for(const n of t.queryelem.dataElement.terminalConfigurations)for(const l of n.terminals)t.terminals.push({terminalId:l.terminalId,terminalName:l.terminalName});const a=await Ye(h+"/"+i);if(a.systemLayers&&a.systemLayers.associationsTableId!==void 0&&a.systemLayers.associationsTableId!==null){const n=[];t.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let l=await oe(h+"/"+a.systemLayers.associationsTableId.toString(),e,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await l.load(),t.unVersion>=4&&(l=l.filter(A.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62,63)",l.getFieldsIndex())),await l.load()),{lkp:t.lkp,associations:l,unVersion:t.unVersion,terminals:t.terminals}}return{associations:null,unVersion:t.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:t.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:t.unVersion,lkp:null,terminals:[]}}async function tt(h,e,t,s=null,i=null,r=!0,a=null,n=null){let l=h.serviceUrl();if(!l)return null;l=l.charAt(l.length-1)==="/"?l+e.relatedTableId.toString():l+"/"+e.relatedTableId.toString();const u=await oe(l,s,i,r,a,n);return new Xe({layer:h,relatedLayer:u,relationship:e,objectId:t,spatialReference:s,outFields:i,includeGeometry:r,lrucache:a,interceptor:n})}U.registerAction(),ae.registerAction(),M.registerAction(),qe.registerAction(),ne.registerAction();class st extends ge{constructor(e,t=null,s=null,i=null){super(),this._map=e,this._overridespref=t,this._lrucache=s,this._interceptor=i,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,s=null){const i=E(e,this._overridespref,s===null?["*"]:s,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:i,opitem:e,includeGeometry:t,outFields:JSON.stringify(s)}),i}async featureSetByName(e,t=!0,s=null){if(this._map.loaded!==void 0&&this._map.load!==void 0&&this._map.loaded===!1)return await this._map.load(),this.featureSetByName(e,t,s);s===null&&(s=["*"]),s=(s=s.slice(0)).sort();const i=JSON.stringify(s);for(let a=0;aa instanceof R&&a.title===e);if(r)return this._makeAndAddFeatureSet(r,t,s);if(this._map.tables){const a=this._map.tables.find(n=>!!(n.title&&n.title===e||n.title&&n.title===e));if(a){if(a instanceof R)return this._makeAndAddFeatureSet(a,t,s);if(!a._materializedTable){const n=a.outFields?a:{...a,outFields:["*"]};a._materializedTable=new R(n)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,s)}}return null}async featureSetById(e,t=!0,s=["*"]){if(this._map.loaded!==void 0&&this._map.load!==void 0&&this._map.loaded===!1)return await this._map.load(),this.featureSetById(e,t,s);s===null&&(s=["*"]),s=(s=s.slice(0)).sort();const i=JSON.stringify(s);for(let a=0;aa instanceof R&&a.id===e);if(r)return this._makeAndAddFeatureSet(r,t,s);if(this._map.tables){const a=this._map.tables.find(n=>n.id===e);if(a){if(a instanceof R)return this._makeAndAddFeatureSet(a,t,s);if(!a._materializedTable){const n={...a,outFields:["*"]};a._materializedTable=new R(n)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,s)}}return null}}class ue extends ge{constructor(e,t=null,s=null,i=null){super(),this._url=e,this._overridespref=t,this._lrucache=s,this._interceptor=i,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,s=null){const i=E(e,this._overridespref,s===null?["*"]:s,t,this._lrucache);return this._instantLayers.push({featureset:i,opitem:e,includeGeometry:t,outFields:JSON.stringify(s)}),i}async _loadMetaData(){const e=await me(this._url);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new ue(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,s=null){s===null&&(s=["*"]),s=(s=s.slice(0)).sort();const i=JSON.stringify(s);for(let n=0;n