import{f as se,er as je,$ as Ge,K as q,cy as Ue,c_ as U,dK as Re,k8 as ke,Y as Be,E as Me,eY as We,_ as $e,aV as x,eX as Ve,bN as ce,bO as he,s as Qe,k9 as fe,dZ as k,dS as Ze,ar as G,ep as ze,bc as pe,fI as Je,eo as Ke,gu as _e,S as Xe}from"./index-b5c8f851.js";import{ap as ae,aq as b,V as Ye,ag as v,ah as ye,ai as ge,aj as me,ak as we,al as Fe,aw as W,ax as re,ay as He,az as K,N as et,aA as tt,aB as $,aC as it}from"./arcadeUtils-ed8f0788.js";import{x as T,s as C,a as D,n as N,t as A,r as st}from"./WhereClause-08dab84b.js";import{x as O,t as y,g as P,m as V,a as R,y as at,L as rt,w as J,E as Se,T as Ie,S as be,F as nt,v as ve,p as lt,D as Q,I as ot,d as j,b as ut,f as dt,c as w}from"./SpatialFilter-6a7eecc0.js";import{c as ct,b as ht,n as ft}from"./TimeOnly-99f1af45.js";import xe from"./SubtypeGroupLayer-2faf6bb4.js";import{a as pt,s as Ce}from"./executeQueryJSON-b554ead2.js";import{n as _t}from"./executeQueryPBF-95281324.js";import"./AttachmentInfo-36750a43.js";import{n as yt,s as gt}from"./executeForIds-8a8c155e.js";import"./pbf-eb90fa42.js";import"./featureConversionUtils-6aca8295.js";let Ne=class{constructor(){this.declaredRootClass="esri.arcade.featureSetCollection",this._layerById={},this._layerByName={}}add(e,t,i){this._layerById[t]=i,this._layerByName[e]=i}async featureSetByName(e,t=!0,i=["*"]){return this._layerByName[e]===void 0?null:this._layerByName[e]}async featureSetById(e,t=!0,i=["*"]){return this._layerById[e]===void 0?null:this._layerById[e]}castToText(e=!1){return"object, FeatureSetCollection"}},Ae=class X extends O{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.actions.AttributeFilter",this._maxProcessing=1e3,this._parent=e.parentfeatureset,e.whereclause instanceof T?(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=ae.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 i;let t=(i=this._parent)==null?void 0:i._isInFeatureSet(e);return t===b.NotInFeatureSet?t:(t=this._idstates[e],t===void 0?b.Unknown:t)}_getFeature(e,t,i){return this._parent._getFeature(e,t,i)}_getFeatures(e,t,i,s){return this._parent._getFeatures(e,t,i,s)}_featureFromCache(e){return this._parent._featureFromCache(e)}executeWhereClause(e){var t;return((t=this._whereclause)==null?void 0:t.testFeature(e))??!1}async executeWhereClauseDeferred(e){if(this._whereClauseFunction!==null){const t=this._whereClauseFunction(e);return je(t),t}return this.executeWhereClause(e)}async _fetchAndRefineFeatures(e,t,i){var a,l,u;const s=new y([],e,!1,null),r=Math.min(t,e.length);if(await((a=this._parent)==null?void 0:a._getFeatures(s,-1,r,i)),this._checkCancelled(i),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" ("+s+" "+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+" "+s+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)+") "}case"null":return"null";case"boolean":return e.value===!0?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":return`timestamp '${e.value}'`;case"date":return`date '${e.value}'`;case"time":return`time '${e.value}'`;case"number":return e.value.toString();case"current-time":return rt(e.mode==="date",t);case"column-reference":return i&&i.toLowerCase()===e.column.toLowerCase()?"("+s+")":e.column;case"data-type":return e.value;case"function":{const o=this.evaluateNodeToWhereClause(e.args,t,i,F.BADNESS,r);return at(e.name,o,t)}}throw new N(A.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof T?this.reverseLkp[T.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}};wt.BADNESS="_!!!_BAD_LKP_!!!!";class Ft extends Z{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:V(e,this.field.name,R(this._sql,v.Standardised),t.getFieldsIndex())}}extractValue(e){return T.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}let St=class extends O{static findField(e,t){for(const i of e)if(i.name.toLowerCase()===t.toString().toLowerCase())return i;return null}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}_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=ae.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 i=null;return i=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await((t=this._parent)==null?void 0:t._getSet(e)),this._checkCancelled(e),Ge(i),this._wset=new y(i._candidates.slice(0),i._known.slice(0),i._ordered,this._clonePageDefinition(i.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(e,t,i,s){var o,d;const r=[];t!==-1&&this._featureCache[t]===void 0&&r.push(t);const n=this._maxQueryRate();if(this._checkIfNeedToExpandKnownPage(e,n)===!0)return await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s);let a=0;for(let h=e._lastFetchedIndex;h=n)));h++);if(r.length===0)return"success";e=new y([],r,e._ordered,null);const l=Math.min(r.length,i);await((o=this._parent)==null?void 0:o._getFeatures(e,-1,l,s)),this._checkCancelled(s);const u=[];for(let h=0;h0&&(s=s.replaceFields(d))}i!==null?this._extraFilter!==null&&(i=P(this._extraFilter,i)):i=this._extraFilter,await this._ensureLoaded();const u=await this._parent._getFilteredSet(e,t,i,s,r);let o;return this._checkCancelled(r),o=n===!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 i of this.adaptedFields)if(ve(e,i.field.name)===!0){const s=i.rewriteSql(e,this);if(s.rewritten!==!0){t.cannot=!0,t.where=null;break}t.where=s.where}}return t}async _stat(e,t,i,s,r,n,a){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&&i===""&&s===null?this._manualStat(e,t,n,a):{calculated:!1};const o=await this._parent._stat(e,t,i,s,r,n,a);return o.calculated===!1?r===null&&i===""&&s===null?this._manualStat(e,t,n,a):{calculated:!1}:o}async _canDoAggregates(e,t,i,s,r){if(this._parent===null)return!1;for(let l=0;l{for(let s=0;s0?(await W(this._refineSetBlock(e,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(e,t,i,s)):t}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,i,s){return this._parent._getFeatures(e,t,i,s)}_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,i,s,r){await this._ensureLoaded();const n=await this._parent._getFilteredSet(e,t,i,s===null?this._orderbyclause:s,r);this._checkCancelled(r);const a=new y(n._candidates.slice(0),n._known.slice(0),n._ordered,this._clonePageDefinition(n.pagesDefinition));let l=!0;if(n._candidates.length>0&&(l=!1),a._ordered===!1){let u=await this.manualOrderSet(a,r);return l===!1&&(t===null&&i===null||(u=new y(u._candidates.slice(0).concat(u._known.slice(0)),[],u._ordered,this._clonePageDefinition(u.pagesDefinition)))),u}return a}static registerAction(){O._featuresetFunctions.orderBy=function(e){return e===""?this:new Le({parentfeatureset:this,orderbyclause:new B(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}};function It(c){if(c.parseTree.type==="function"){if(c.parseTree.args.value.length===0)return{name:c.parseTree.name,expr:null};if(c.parseTree.args.value.length>1)throw new N(A.MissingStatisticParameters);const e=T.create(lt(c.parseTree.args.value[0],v.Standardised,c.parameters),c.fieldsIndex,c.timeZone);return{name:c.parseTree.name,expr:e}}return null}let Te=class ee{constructor(){this.field="",this.tofieldname="",this.typeofstat="MIN",this.workingexpr=null}clone(){const e=new ee;return e.field=this.field,e.tofieldname=this.tofieldname,e.typeofstat=this.typeofstat,e.workingexpr=this.workingexpr,e}static parseStatField(e,t,i,s){const r=new ee;r.field=e;const n=T.create(t,i,s),a=It(n);if(a===null)throw new N(A.UnsupportedSqlFunction,{function:""});const l=a.name.toUpperCase().trim();if(l==="MIN"){if(r.typeofstat="MIN",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:"min"})}else if(l==="MAX"){if(r.typeofstat="MAX",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:"max"})}else if(l==="COUNT")r.typeofstat="COUNT",r.workingexpr=a.expr;else if(l==="STDEV"){if(r.typeofstat="STDDEV",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:"stdev"})}else if(l==="SUM"){if(r.typeofstat="SUM",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:"sum"})}else if(l==="MEAN"){if(r.typeofstat="AVG",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:l})}else if(l==="AVG"){if(r.typeofstat="AVG",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:"avg"})}else{if(l!=="VAR")throw new N(A.UnsupportedSqlFunction,{function:l});if(r.typeofstat="VAR",r.workingexpr=a.expr,n===null)throw new N(A.InvalidFunctionParameters,{function:"var"})}return r}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 bt(c){if(!c)return"COUNT";switch(c.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"}let Ct=class Oe extends O{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 b.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,i=1;const s=this._parent?this._parent.getFieldsIndex():new Ue([]);for(this.objectIdField="ROW__ID",this.globalIdField="";t===!1;){let n=!1;for(let a=0;a0)for(const n of this._parent.fields)this._adaptedFields.push(new Y(n));for(let n=0;n0&&(l=new St({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),a.nowhereclause===!0)n=new y(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new H({parentfeatureset:l,orderbyclause:new B(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let u=l;if(i!==null){let o=null;i&&(o=this._reformulateWhereClauseWithoutGroupByFields(i)),u=new Ae({parentfeatureset:u,whereclause:o})}n=new y(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new H({parentfeatureset:u,orderbyclause:new B(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return n}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=V(e,t.tofieldname,R(t.workingexpr,v.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=V(e,t.tofieldname,R(t.expression,v.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.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,i){return this._checkIfNeedToExpandCandidatePage(e,this._maxQuery)===!0?(await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i)):(this._checkCancelled(i),e._candidates.length,this._refineKnowns(e,t),e._candidates.length,e._candidates.length,e)}_expandPagedSet(e,t,i,s,r){return this._expandPagedSetFeatureSet(e,t,i,s,r)}async _getPhysicalPage(e,t,i){if(e.pagesDefinition.aggregatefeaturesetpagedefinition===!0)return this._sequentialGetPhysicalItem(e,e.pagesDefinition.resultRecordCount,i,[]);const s=await this._getAgregagtePhysicalPage(e,t,i);for(const r of s){const n={geometry:r.geometry,attributes:{}},a={};for(const l in r.attributes)a[l.toLowerCase()]=r.attributes[l];for(const l of this._decodedGroupbyfield)n.attributes[l.tofieldname]=a[l.name.toLowerCase()];for(const l of this._decodedStatsfield)n.attributes[l.tofieldname]=a[l.field.toLowerCase()];this._featureCache[n.attributes[this.objectIdField]]=new q(n)}return s.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise((r,n)=>{e.pagesDefinition.internal.iterator===null&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),e.pagesDefinition.internal.fullyResolved===!0||t===0?r(s.length):this._nextAggregateItem(e,t,i,s,a=>{a===null?r(s.length):(t-=1,r(this._sequentialGetPhysicalItem(e,t,i,s)))},n)})}_nextAggregateItem(e,t,i,s,r,n){try{W(e.pagesDefinition.internal.iterator.next()).then(a=>{if(a===null)if(e.pagesDefinition.internal.workingItem!==null){const l=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);s.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(a);if(e.pagesDefinition.internal.workingItem===null)e.pagesDefinition.internal.workingItem={features:[a],id:l};else{if(l!==e.pagesDefinition.internal.workingItem.id){const u=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return s.push(u),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(u.attributes[this.objectIdField]),t-=1,e.pagesDefinition.internal.workingItem={features:[a],id:l},void r(u)}e.pagesDefinition.internal.workingItem.features.push(a)}this._nextAggregateItem(e,t,i,s,r,n)}},n)}catch(a){n(a)}}_calculateFieldStat(e,t,i){const s=[];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===b.NotInFeatureSet)return t;const i=this._idstates[e];return i===b.InFeatureSet||i===b.NotInFeatureSet?i:t===b.InFeatureSet&&i===void 0?this._countedinthis._topnum&&(t=this._topnum),this._countedin>=this._topnum&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset){let a=e._known.length;return a>0&&e._known[a-1]==="GETPAGES"&&(e._known.length=a-1),a=e._candidates.length,a>0&&e._candidates[a-1]==="GETPAGES"&&(e._candidates.length=a-1),"success"}const n=await this._parent._expandPagedSet(e,t,i,s,r);return this._setKnownLength(e)>this._topnum&&(e._known.length=this._topnum),this._setKnownLength(e)>=this._topnum&&(e._candidates.length=0),n}async _getFeatures(e,t,i,s){const r=[],n=this._maxQueryRate();if(this._checkIfNeedToExpandKnownPage(e,n)===!0)return await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s);t!==-1&&this._featureCache[t]===void 0&&r.push(t);let a=0;for(let o=e._lastFetchedIndex;on)));o++);if(r.length===0)return"success";const l=new y([],r,!1,null),u=Math.min(r.length,i);await this._parent._getFeatures(l,-1,u,s);for(let o=0;o=this._topnum)break}else if(a===b.NotInFeatureSet)s===null?s={start:n,end:n}:s.end===n-1?s.end=n:(r.push(s),s={start:n,end:n}),i+=1;else if(a===b.Unknown)break;if(i>=t)break}s!==null&&r.push(s);for(let n=r.length-1;n>=0;n--)e._candidates.splice(r[n].start,r[n].end-r[n].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(){O._featuresetFunctions.top=function(e){return new ne({parentfeatureset:this,topnum:e})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}async function Dt(c,e,t,i){return kt(e,await Tt(c,e,t,i),t,i)}async function Tt(c,e,t,i){var o;const s={...i},r=vt(e,t),n=((o=e.outStatistics)==null?void 0:o[0])!=null,a=Be("featurelayer-pbf-statistics"),l=!n||a;let u;if((t==null?void 0:t.format)==="pbf"&&l)try{u=await _t(c,r,s)}catch(d){if(d.name!=="query:parsing-pbf")throw d;t.format="json"}return(t==null?void 0:t.format)!=="json"&&l||(u=await pt(c,r,s)),Rt(t==null?void 0:t.fieldsIndex,u.fields),u}function Rt(c,e){if(c!=null&&e!=null)for(const t of e){const i=c.get(t.name);i&&Object.assign(t,i.toJSON())}}async function kt(c,e,t,i){var n;const s=t==null?void 0:t.infoFor3D;if(!Ee(c,s)||s==null||!e.assetMaps||!((n=e.features)!=null&&n.length))return Me.fromJSON(e);const{meshFeatureSetFromJSON:r}=await We($e(()=>import("./meshFeatureSet-b57dd5d4.js").then(a=>a.b),["assets/meshFeatureSet-b57dd5d4.js","assets/index-b5c8f851.js","assets/index-86716609.css","assets/georeference-f533c6ae.js","assets/mat4f64-1413b4a7.js","assets/spatialReferenceEllipsoidUtils-bc18a3f3.js","assets/MeshLocalVertexSpace-702f1ae9.js","assets/MeshGeoreferencedRelativeVertexSpace-7e8894cd.js","assets/quat-59e6d063.js","assets/quatf64-3363c48e.js","assets/vec32-567858f4.js","assets/BufferView-db785e2d.js","assets/earcut-d423749e.js","assets/Indices-8bd7636c.js","assets/deduplicate-d84e5ef3.js","assets/plane-66dd48d1.js","assets/sphere-5667aa69.js","assets/ByteSizeUnit-d4757d40.js","assets/triangle-f93283ef.js","assets/lineSegment-95273d56.js","assets/basicInterfaces-11f56cb3.js","assets/VertexAttribute-0e674613.js","assets/External-7e16e2e2.js"]),i);return r(c,s,e)}function vt(c,e){let t=x.from(c);t.sourceSpatialReference=t.sourceSpatialReference??(e==null?void 0:e.sourceSpatialReference)??null,(e!=null&&e.gdbVersion||e!=null&&e.dynamicDataSource)&&(t=t===c?t.clone():t,t.gdbVersion=c.gdbVersion||e.gdbVersion,t.dynamicDataSource=c.dynamicDataSource?Ve.from(c.dynamicDataSource):e.dynamicDataSource);const i=e==null?void 0:e.infoFor3D;if(i!=null&&Ee(c,i)){t=t===c?t.clone():t,t.formatOf3DObjects=null;const{supportedFormats:s,queryFormats:r}=i,n=ce("model/gltf-binary",s)??he("glb",s),a=ce("model/gltf+json",s)??he("gtlf",s);for(const l of r){if(l===n){t.formatOf3DObjects=l;break}l!==a||t.formatOf3DObjects||(t.formatOf3DObjects=l)}if(!t.formatOf3DObjects)throw new Qe("query:unsupported-3d-query-formats","Could not find any supported 3D object query format. Only supported formats are 3D_glb and 3D_gltf");if(t.outFields==null||!t.outFields.includes("*")){t=t===c?t.clone():t,t.outFields==null&&(t.outFields=[]);const{originX:l,originY:u,originZ:o,translationX:d,translationY:h,translationZ:p,scaleX:g,scaleY:m,scaleZ:I,rotationX:S,rotationY:f,rotationZ:_,rotationDeg:M}=i.transformFieldRoles;t.outFields.push(l,u,o,d,h,p,g,m,I,S,f,_,M)}}return t}function Ee(c,e){return e!=null&&c.returnGeometry===!0&&c.multipatchOption!=="xyFootprint"&&!c.outStatistics}let xt=class te extends O{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}get urlQueryPath(){return this._layer.parsedUrl.path||""}convertQueryToLruCacheKey(e){const t=this.urlQueryPath+","+He(e.toJSON());return Re(t,ke.String)}async loadImpl(){return this._layer.loaded===!0?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){var e,t,i,s,r,n;if(this.spatialReference==null&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this.hasZ=((i=(t=(e=this._layer)==null?void 0:e.capabilities)==null?void 0:t.data)==null?void 0:i.supportsZ)===!0,this.hasM=((n=(r=(s=this._layer)==null?void 0:s.capabilities)==null?void 0:r.data)==null?void 0:n.supportsM)===!0,this._overrideFields!==null)if(this._overrideFields.length===1&&this._overrideFields[0]==="*")this._overrideFields=null;else{const a=[],l=[];for(const u of this.fields)if(u.type==="oid")a.push(u),l.push(u.name);else for(const o of this._overrideFields)if(o.toLowerCase()===u.name.toLowerCase()){a.push(u),l.push(u.name);break}this.fields=a,this._overrideFields=l}if(this._layer.source&&this._layer.source.sourceJSON){const a=this._layer.source.sourceJSON.currentVersion;this._layer.source.sourceJSON.useStandardizedQueries===!0?(this._databaseType=v.StandardisedNoInterval,a!=null&&a>=10.61&&(this._databaseType=v.Standardised)):a!=null&&(a>=10.5&&(this._databaseType=v.StandardisedNoInterval,this._requestStandardised=!0),a>=10.61&&(this._databaseType=v.Standardised))}this.objectIdField=this._layer.objectIdField;for(const a of this.fields)a.type==="global-id"&&(this.globalIdField=a.name);this._layer instanceof xe?(this.typeIdField=this._layer.subtypeField??"",this.types=this._layer.subtypes):(this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types)}_isInFeatureSet(){return b.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 x;this.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),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 i,s;const t=(s=(i=this._layer)==null?void 0:i.capabilities)==null?void 0:s.query;return!e.outStatistics&&(t==null?void 0:t.supportsFormatPBF)===!0&&(t==null?void 0:t.supportsQuantizationEditMode)===!0}async queryPBF(e){return e.quantizationParameters={mode:"edit"},(await Dt(this._layer.parsedUrl,e,{format:"pbf"},{})).unquantize()}get gdbVersion(){return this._layer&&this._layer.capabilities&&this._layer.capabilities.data&&this._layer.capabilities.data.isVersioned?this._layer.gdbVersion||"SDE.DEFAULT":""}nativeCapabilities(){return{title:this._layer.title??"",source:this,canQueryRelated:!0,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:this._requestStandardised}}executeQuery(e,t){e.returnZ=this.hasZ,e.returnM=this.hasM;const i=t==="execute"?Ce:t==="executeForCount"?yt:gt,s=t==="execute"&&this.pbfSupportedForQuery(e);let r=null;if(this.recentlyUsedQueries){const n=this.convertQueryToLruCacheKey(e);r=this.recentlyUsedQueries.getFromCache(n),r===null&&(r=s!==!0?i(this._layer.parsedUrl.path,e):this.queryPBF(e),this.recentlyUsedQueries.addToCache(n,r),r=r.catch(a=>{var l;throw(l=this.recentlyUsedQueries)==null||l.removeFromCache(n),a}))}return this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:e,method:t}),r===null&&(r=s!==!0?i(this._layer.parsedUrl.path,e):this.queryPBF(e)),r}async _getFilteredSet(e,t,i,s,r){const n=await this.databaseType();if(this.isTable()&&t&&e!==null&&e!=="")return new y([],[],!0,null);if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,s,r);let a="",l=!1;s!==null&&this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsOrderBy===!0&&(a=s.constructClause(),l=!0);const u=new x;this.datesInUnknownTimezone&&(u.timeReferenceUnknownClient=!0),u.where=i===null?t===null?"1=1":"":R(i,n),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=a!==""?a.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,i,s,r){return this._expandPagedSetFeatureSet(e,t,i,s,r)}async _getFilteredSetUsingPaging(e,t,i,s,r){var p;let n="",a=!1;s!==null&&this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsOrderBy===!0&&(n=s.constructClause(),a=!0);const l=await this.databaseType();let u=i===null?t===null?"1=1":"":R(i,l);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=u!==""?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let o=this._maxQueryRate();const d=(p=this._layer.capabilities)==null?void 0:p.query.maxRecordCount;d!=null&&d=this._maxProcessingRate()-1))break}if(n>=i&&r.length===0)break}if(r.length===0)return"success";const a=new x;this._requestStandardised&&(a.sqlFormat="standard"),this.datesInUnknownTimezone&&(a.timeReferenceUnknownClient=!0),a.objectIds=r,a.outFields=this._overrideFields??this._fieldsIncludingObjectId(["*"]),a.returnGeometry=!0,this._removeGeometry===!0&&(a.returnGeometry=!1),a.outSpatialReference=this.spatialReference;const l=await this.executeQuery(a,"execute");if(this._checkCancelled(s),l.error!==void 0)throw new C(D.RequestFailed,{reason:l.error});const u=this._layer.objectIdField;for(let o=0;o=a)break}return m.features.length===0?l:m.features.length===((S=this._layer.capabilities)==null?void 0:S.query.maxRecordCount)&&l.length"+e.pagesDefinition.internal.lastMaxId.toString()+")":e.pagesDefinition.generatedOid+">"+e.pagesDefinition.internal.lastMaxId.toString());const r=e.pagesDefinition.internal.lastRetrieved,n=r,a=e.pagesDefinition.internal.lastPage,l=new x;if(this._requestStandardised&&(l.sqlFormat="standard"),l.where=s,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,this.datesInUnknownTimezone&&(l.timeReferenceUnknownClient=!0),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(i),!u.hasOwnProperty("features"))throw new C(D.InvalidStatResponse);const o=[];if(e.pagesDefinition.internal.lastPage!==a)return[];u.features.length>0&&u.features[0].attributes[e.pagesDefinition.generatedOid]===void 0&&(e.pagesDefinition.generatedOid=e.pagesDefinition.generatedOid.toLowerCase());for(let d=0;d0||i&&i>0)&&(a.size=[t&&t>0?t:0,i&&i>0?i:t+1]),s&&s.length>0&&(a.attachmentTypes=s),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:a,method:"attachments"});const l=await this._layer.queryAttachments(a),u=[];return l&&l[e]&&l[e].forEach(o=>{const d=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+o.id.toString();let h=null;r&&o.exifInfo&&(h=et.convertJsonToArcade(o.exifInfo,"system",!0)),u.push(new tt(o.id,o.name,o.contentType,o.size,d,h,o.keywords??null))}),u}return[]}async queryRelatedFeatures(e){var s;const t={f:"json",relationshipId:e.relationshipId.toString(),definitionExpression:e.where,outFields:(s=e.outFields)==null?void 0:s.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=Ze(e.outSpatialReference)),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:t,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const i=await G(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:t});if(i.data){const r={},n=i.data;if(n!=null&&n.relatedRecordGroups){const a=n.spatialReference;for(const l of n.relatedRecordGroups){const u=l.objectId,o=[];for(const d of l.relatedRecords){d.geometry&&(d.geometry.spatialReference=a);const h=new q({geometry:d.geometry?ze(d.geometry):null,attributes:d.attributes});o.push(h)}r[u]={features:o,exceededTransferLimit:n.exceededTransferLimit===!0}}}return r}throw new C(D.InvalidRequest)}async getFeatureByObjectId(e,t){const i=new x;i.outFields=t,i.returnGeometry=!1,i.outSpatialReference=this.spatialReference,i.where=this.objectIdField+"="+e.toString(),this.datesInUnknownTimezone&&(i.timeReferenceUnknownClient=!0),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:i,method:"execute"});const s=await Ce(this._layer.parsedUrl.path,i);return s.features.length===1?s.features[0]:null}async getIdentityUser(){var t;await this.load();const e=(t=pe)==null?void 0:t.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){var s,r;await this.load();const e=(s=pe)==null?void 0:s.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let t=this._layer.url;const i=t.toLowerCase().indexOf("/rest/services");if(t=i>-1?t.substring(0,i):t,t){t+="/rest/info";try{const n=await G(t,{query:{f:"json"}});let a="";return(r=n.data)!=null&&r.owningSystemUrl&&(a=n.data.owningSystemUrl),a}catch{return""}}return""}getDataSourceFeatureSet(){const e=new te({layer:this._layer,spatialReference:this.spatialReference??void 0,outFields:this._overrideFields??void 0,includeGeometry:!this._removeGeometry,lrucache:this.recentlyUsedQueries??void 0,interceptor:this.featureSetQueryInterceptor??void 0});return e._useDefinitionExpression=!1,e}get preferredTimeZone(){return this._layer.preferredTimeZone??null}get dateFieldsTimeZone(){return this._layer.dateFieldsTimeZone??null}get datesInUnknownTimezone(){return this._layer.datesInUnknownTimezone}get editFieldsInfo(){return this._layer.editFieldsInfo??null}get timeInfo(){return this._layer.timeInfo??null}async getFeatureSetInfo(){var r,n;if(this.fsetInfo)return this.fsetInfo;let e=null,{parsedUrl:{path:t},serviceItemId:i=null}=this._layer;if(t){const a=await G(t,{responseType:"json",query:{f:"json"}});e=((r=a==null?void 0:a.data)==null?void 0:r.name)??null,i=((n=a==null?void 0:a.data)==null?void 0:n.serviceItemId)??null}const s=this._layer.title&&(this._layer.parent??null)!==null;return this.featureSetInfo={layerId:this._layer.layerId,layerName:e===""?null:e,itemId:i===""?null:i,serviceLayerUrl:t===""?null:t,webMapLayerId:s?this._layer.id??null:null,webMapLayerTitle:s?this._layer.title??null:null,className:null,objectClassId:null},this.fsetInfo}};class le extends O{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(){var e,t,i,s,r,n;if(this.spatialReference==null&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this._overrideFields!==null)if(this._overrideFields.length===1&&this._overrideFields[0]==="*")this._overrideFields=null;else{const a=[],l=[];for(const u of this.fields)if(u.type==="oid")a.push(u),l.push(u.name);else for(const o of this._overrideFields)if(o.toLowerCase()===u.name.toLowerCase()){a.push(u),l.push(u.name);break}this.fields=a,this._overrideFields=l}this.objectIdField=this._layer.objectIdField;for(const a of this.fields)a.type==="global-id"&&(this.globalIdField=a.name);this._databaseType=v.Standardised,this.hasZ=((i=(t=(e=this._layer)==null?void 0:e.capabilities)==null?void 0:t.data)==null?void 0:i.supportsZ)===!0,this.hasM=((n=(r=(s=this._layer)==null?void 0:s.capabilities)==null?void 0:r.data)==null?void 0:n.supportsM)===!0,this._layer instanceof xe?(this.typeIdField=this._layer.subtypeField??"",this.types=this._layer.subtypes):(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 b.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 i of this.fields)t[i.name]=e.attributes[i.name];return new q({geometry:this._removeGeometry===!0?null:e.geometry,attributes:t})}async _getFilteredSet(e,t,i,s,r){let n="",a=!1;if(s!==null&&(n=s.constructClause(),a=!0),this.isTable()&&t&&e!==null&&e!=="")return new y([],[],!0,null);const l=new x;l.returnZ=this.hasZ,l.returnM=this.hasM,l.where=i===null?t===null?"1=1":"":R(i,v.Standardised),l.spatialRelationship=this._makeRelationshipEnum(e),l.outSpatialReference=this.spatialReference,l.orderByFields=n!==""?n.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([],[],a,null);this._checkCancelled(r);const o=[];return u.features.forEach(d=>{const h=d.attributes[this._layer.objectIdField];o.push(h),this._featureCache[h]=this._changeFeature(d)}),new y([],o,a,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 x;if(e.where="1=1",await this._ensureLoaded(),this._layer.source&&this._layer.source.items){const s=[];return this._layer.source.items.forEach(r=>{const n=r.attributes[this._layer.objectIdField];s.push(n),this._featureCache[n]=this._changeFeature(r)}),this._wset=new y([],s,!1,null),this._wset}e.returnZ=this.hasZ,e.returnM=this.hasM;const t=await this._layer.queryFeatures(e),i=[];return t.features.forEach(s=>{const r=s.attributes[this._layer.objectIdField];i.push(r),this._featureCache[r]=this._changeFeature(s)}),this._wset=new y([],i,!1,null),this._wset}async _getFeatures(e,t,i){const s=[];t!==-1&&this._featureCache[t]===void 0&&s.push(t);for(let r=e._lastFetchedIndex;ri)));r++);if(s.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 i in e)t[i]=e[i];return t}nativeCapabilities(){return{title:this._layer.title??"",canQueryRelated:!1,source:this,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:!0}}static create(e,t){var g,m,I,S;let i=e.layerDefinition.objectIdField;const s=e.layerDefinition.typeIdField??"",r=[];if(e.layerDefinition.types)for(const f of e.layerDefinition.types)r.push(Je.fromJSON(f));let n=e.layerDefinition.geometryType;n===void 0&&(n=e.featureSet.geometryType||"");let a=e.featureSet.features;const l=t.toJSON();if(!i){let f=!1;for(const _ of e.layerDefinition.fields)if(_.type==="oid"||_.type==="esriFieldTypeOID"){i=_.name,f=!0;break}if(f===!1){let _="FID",M=!0,de=0;for(;M;){let E=!0;for(const qe of e.layerDefinition.fields)if(qe.name===_){E=!1;break}E===!0?M=!1:(de++,_="FID"+de.toString())}e.layerDefinition.fields.push({type:"esriFieldTypeOID",name:_,alias:_});const z=[];for(let E=0;E_.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=a!==""?a.split(","):null;const h=await n.source.queryRelatedFeatures(u);this._checkCancelled(r);const p=h[this._findObjectId]?h[this._findObjectId].features:[],g=[];for(let _=0;__.name):["*"]);return g=new y(h||p?["GETPAGES"]:[],h||p?[]:["GETPAGES"],a,{outFields:I.join(","),resultRecordCount:o,resultOffset:0,objectIds:[this._findObjectId],where:u,orderByFields:n,returnGeometry:m,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}}),await this._expandPagedSet(g,o,0,0,r),g}_expandPagedSet(e,t,i,s,r){return this._expandPagedSetFeatureSet(e,t,i,s,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,i){const s=e.pagesDefinition.internal.lastRetrieved,r=s,n=e.pagesDefinition.internal.lastPage,a=this._layer.nativeCapabilities(),l=new _e;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 a.source.queryRelatedFeatures(l);if(this._checkCancelled(i),e.pagesDefinition.internal.lastPage!==n)return 0;const o=u[this._findObjectId]?u[this._findObjectId].features:[];for(let h=0;hi)))&&!(a>=i&&r.length===0);l++);if(r.length===0)return"success";throw new C(D.MissingFeatures)}async _refineSetBlock(e,t,i){return e}async _stat(e,t,i,s,r,n,a){return{calculated:!1}}get gdbVersion(){return this._relatedLayer.gdbVersion}async _canDoAggregates(e,t,i,s,r){return!1}relationshipMetaData(){return this._relatedLayer.relationshipMetaData()}serviceUrl(){return this._relatedLayer.serviceUrl()}queryAttachments(e,t,i,s,r){return this._relatedLayer.queryAttachments(e,t,i,s,r)}getFeatureByObjectId(e,t){return this._relatedLayer.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._relatedLayer.getOwningSystemUrl()}getIdentityUser(){return this._relatedLayer.getIdentityUser()}getDataSourceFeatureSet(){return this._relatedLayer}get preferredTimeZone(){var e;return((e=this._relatedLayer)==null?void 0:e.preferredTimeZone)??null}get dateFieldsTimeZone(){var e;return((e=this._relatedLayer)==null?void 0:e.dateFieldsTimeZone)??null}get datesInUnknownTimezone(){var e;return(e=this._relatedLayer)==null?void 0:e.datesInUnknownTimezone}get editFieldsInfo(){var e;return((e=this._relatedLayer)==null?void 0:e.editFieldsInfo)??null}get timeInfo(){var e;return((e=this._relatedLayer)==null?void 0:e.timeInfo)??null}async getFeatureSetInfo(){return this.fsetInfo??this._layer.featureSetInfo}}function At(){w.applicationCache===null&&(w.applicationCache=new w)}async function ie(c,e){if(w.applicationCache){const t=w.applicationCache.getLayerInfo(c);if(t){const r=await t;return new k({url:c,outFields:e,sourceJSON:r})}const i=new k({url:c,outFields:e}),s=(async()=>(await i.load(),i.sourceJSON))();if(w.applicationCache){w.applicationCache.setLayerInfo(c,s);try{return await s,i}catch(r){throw w.applicationCache.clearLayerInfo(c),r}}return await s,i}return new k({url:c,outFields:e})}async function oe(c,e,t,i,s,r=null){return L(await ie(c,["*"]),e,t,i,s,r)}function L(c,e=null,t=null,i=!0,s=null,r=null){if(c instanceof k||$(c)){const a={layer:c,spatialReference:e,outFields:t,includeGeometry:i,lrucache:s,interceptor:r};return c.url||!c.source?new xt(a):new le(a)}const n=L(c.parent,e,t,i,s,r);return n.filter(T.create(c.parent.subtypeField+"="+c.subtypeCode.toString(),c.parent.fieldsIndex,n.dateFieldsTimeZoneDefaultUTC))}async function Lt(c){if(w.applicationCache!==null){const t=w.applicationCache.getLayerInfo(c);if(t!==null)return t}const e=(async()=>{const t=await G(c,{responseType:"json",query:{f:"json"}});return t.data?t.data:null})();if(w.applicationCache!==null){w.applicationCache.setLayerInfo(c,e);try{return await e}catch(t){throw w.applicationCache.clearLayerInfo(c),t}}return e}async function Ot(c,e){const t="QUERYDATAELEMTS:"+e.toString()+":"+c;if(w.applicationCache!==null){const s=w.applicationCache.getLayerInfo(t);if(s!==null)return s}const i=(async()=>{var r;const s=await G(c+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([e.toString()]),f:"json"}});if(s.data){const n=s.data;if((r=n.layerDataElements)!=null&&r[0])return n.layerDataElements[0]}throw new C(D.DataElementsNotFound)})();if(w.applicationCache!==null){w.applicationCache.setLayerInfo(t,i);try{return await i}catch(s){throw w.applicationCache.clearLayerInfo(t),s}}return i}async function Pe(c){if(w.applicationCache!==null){const t=w.applicationCache.getLayerInfo(c);if(t!==null)return t}const e=(async()=>{const t=await G(c,{responseType:"json",query:{f:"json"}});if(t.data){const i=t.data;return i.layers||(i.layers=[]),i.tables||(i.tables=[]),i}return{layers:[],tables:[]}})();if(w.applicationCache!==null){w.applicationCache.setLayerInfo(c,e);try{return await e}catch(t){throw w.applicationCache.clearLayerInfo(c),t}}return e}async function Et(c,e){var s,r,n;const t={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},i=await Pe(c);if(t.metadata=i,((s=i.controllerDatasetLayers)==null?void 0:s.utilityNetworkLayerId)!==void 0&&i.controllerDatasetLayers.utilityNetworkLayerId!==null){if(i.layers)for(const u of i.layers)t.layerNameLkp[u.id]=u.name;if(i.tables)for(const u of i.tables)t.layerNameLkp[u.id]=u.name;const a=i.controllerDatasetLayers.utilityNetworkLayerId;t.networkId=a;const l=await Ot(c,a);if(l){t.queryelem=l,(r=t.queryelem)!=null&&r.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 o of t.queryelem.dataElement.domainNetworks){for(const d of o.edgeSources??[]){const h={layerId:d.layerId,sourceId:d.sourceId,className:t.layerNameLkp[d.layerId]??null};h.className&&(t.lkp[h.className]=h)}for(const d of o.junctionSources??[]){const h={layerId:d.layerId,sourceId:d.sourceId,className:t.layerNameLkp[d.layerId]??null};h.className&&(t.lkp[h.className]=h)}}if(t.queryelem.dataElement.terminalConfigurations)for(const o of t.queryelem.dataElement.terminalConfigurations)for(const d of o.terminals)t.terminals.push({terminalId:d.terminalId,terminalName:d.terminalName});const u=await Lt(c+"/"+a);if(((n=u.systemLayers)==null?void 0:n.associationsTableId)!==void 0&&u.systemLayers.associationsTableId!==null){const o=[];t.unVersion>=4&&(o.push("STATUS"),o.push("PERCENTALONG"));let d=await oe(c+"/"+u.systemLayers.associationsTableId.toString(),e,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...o],!1,null,null);return await d.load(),t.unVersion>=4&&(d=d.filter(T.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)",d.getFieldsIndex(),d.dateFieldsTimeZoneDefaultUTC)),await d.load()),{lkp:t.lkp,associations:d,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 Pt(c,e,t,i=null,s=null,r=!0,n=null,a=null){let l=c.serviceUrl();if(!l)return null;l=l.charAt(l.length-1)==="/"?l+e.relatedTableId.toString():l+"/"+e.relatedTableId.toString();const u=await oe(l,i,s,r,n,a);return new Nt({layer:c,relatedLayer:u,relationship:e,objectId:t,spatialReference:i,outFields:s,includeGeometry:r,lrucache:n,interceptor:a})}Ae.registerAction(),Ct.registerAction(),H.registerAction(),dt.registerAction(),ne.registerAction();class qt extends Ne{constructor(e,t=null,i=null,s=null){super(),this._map=e,this._overridespref=t,this._lrucache=i,this._interceptor=s,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,i=null){const s=L(e,this._overridespref,i===null?["*"]:i,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:s,opitem:e,includeGeometry:t,outFields:JSON.stringify(i)}),s}async featureSetByName(e,t=!0,i=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,i);i===null&&(i=["*"]),i=(i=i.slice(0)).sort();const s=JSON.stringify(i);for(let a=0;a{if(a instanceof k){if(a.title===e)return!0}else if($(a)){if(a.title===e)return!0;r.push(a)}return!1});if(n)return this._makeAndAddFeatureSet(n,t,i);if(this._map.tables){const a=this._map.tables.find(l=>!!(l.title&&l.title===e||l.title&&l.title===e));if(a){if(a instanceof k)return this._makeAndAddFeatureSet(a,t,i);if(!a._materializedTable){const l=a.outFields?a:{...a,outFields:["*"]};a._materializedTable=new k(l)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,i)}}for(const a of r){if(a.loadStatus==="not-loaded"||a.loadStatus==="loading")try{await a.load()}catch{}const l=a.sublayers.find(u=>u.title===e);if(l)return this._makeAndAddFeatureSet(l,t,i)}return null}async featureSetById(e,t=!0,i=["*"]){if(this._map.loaded!==void 0&&this._map.load!==void 0&&this._map.loaded===!1)return await this._map.load(),this.featureSetById(e,t,i);i===null&&(i=["*"]),i=(i=i.slice(0)).sort();const s=JSON.stringify(i);for(let a=0;a{if(a instanceof k){if(a.id===e)return!0}else if($(a)){if(a.id===e)return!0;r.push(a)}return!1});if(n)return this._makeAndAddFeatureSet(n,t,i);if(this._map.tables){const a=this._map.tables.find(l=>l.id===e);if(a){if(a instanceof k)return this._makeAndAddFeatureSet(a,t,i);if(!a._materializedTable){const l={...a,outFields:["*"]};a._materializedTable=new k(l)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,i)}}for(const a of r){if(a.loadStatus==="not-loaded"||a.loadStatus==="loading")try{await a.load()}catch{}const l=a.sublayers.find(u=>u.id===e);if(l)return this._makeAndAddFeatureSet(l,t,i)}return null}}class ue extends Ne{constructor(e,t=null,i=null,s=null){super(),this._url=e,this._overridespref=t,this._lrucache=i,this._interceptor=s,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,i=null){const s=L(e,this._overridespref,i===null?["*"]:i,t,this._lrucache);return this._instantLayers.push({featureset:s,opitem:e,includeGeometry:t,outFields:JSON.stringify(i)}),s}async _loadMetaData(){const e=await Pe(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,i=null){i===null&&(i=["*"]),i=(i=i.slice(0)).sort();const s=JSON.stringify(i);for(let a=0;a