2 lines
94 KiB
JavaScript
2 lines
94 KiB
JavaScript
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<r;o++){const d=(l=this._parent)==null?void 0:l._featureFromCache(e[o]);this.executeWhereClause(d)===!0?this._idstates[e[o]]=b.InFeatureSet:this._idstates[e[o]]=b.NotInFeatureSet}return"success"}const n=[];for(let o=0;o<r;o++){const d=(u=this._parent)==null?void 0:u._featureFromCache(e[o]);n.push(await this.executeWhereClauseDeferred(d))}for(let o=0;o<t;o++)n[o]===!0?this._idstates[e[o]]=b.InFeatureSet:this._idstates[e[o]]=b.NotInFeatureSet;return"success"}async _getFilteredSet(e,t,i,s,r){this._whereClauseFunction!==null||(i!==null?this._whereclause!==null&&(i=P(this._whereclause,i)):i=this._whereclause),await this._ensureLoaded();const n=await this._parent._getFilteredSet(e,t,i,s,r);let a;return this._checkCancelled(r),a=this._whereClauseFunction!==null?new y(n._candidates.slice(0).concat(n._known.slice(0)),[],n._ordered,this._clonePageDefinition(n.pagesDefinition)):new y(n._candidates.slice(0),n._known.slice(0),n._ordered,this._clonePageDefinition(n.pagesDefinition)),a}async _stat(e,t,i,s,r,n,a){if(this._whereClauseFunction!==null)return r===null&&i===""&&s===null?this._manualStat(e,t,n,a):{calculated:!1};let l=this._whereclause;r!==null&&this._whereclause!==null&&(l=P(this._whereclause,r));const u=await this._parent._stat(e,t,i,s,l,n,a);return u.calculated===!1?r===null&&i===""&&s===null?this._manualStat(e,t,n,a):{calculated:!1}:u}async _canDoAggregates(e,t,i,s,r){return this._whereClauseFunction===null&&(r!==null?this._whereclause!==null&&(r=P(this._whereclause,r)):r=this._whereclause,this._parent!==null&&this._parent._canDoAggregates(e,t,i,s,r))}async _getAggregatePagesDataSourceDefinition(e,t,i,s,r,n,a){if(this._parent===null)throw new C(D.NeverReach);return r!==null?this._whereclause!==null&&(r=P(this._whereclause,r)):r=this._whereclause,this._parent._getAggregatePagesDataSourceDefinition(e,t,i,s,r,n,a)}static registerAction(){O._featuresetFunctions.filter=function(e){if(typeof e=="function")return new X({parentfeatureset:this,whereclause:e});let t=null;return e instanceof T&&(t=e),new X({parentfeatureset:this,whereclause:t})}}getFieldsIndex(){return this._parent.getFieldsIndex()}},Z=class{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}},Y=class extends Z{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}},mt=class extends Z{constructor(e,t,i){super(Ye(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=i}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:V(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}},wt=class F extends Z{constructor(e,t,i){super(e),this.codefield=t,this.lkp=i,this.reverseLkp={};for(const s in i)this.reverseLkp[i[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const i=this.evaluateNodeToWhereClause(e.parseTree,v.Standardised,this.field.name,this.codefield instanceof T?R(this.codefield,v.Standardised):this.codefield,e.parameters);return i.includes(F.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:T.create(i,t._parent.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC)}}evaluateNodeToWhereClause(e,t,i=null,s=null,r){let n,a,l,u;switch(e.type){case"interval":return nt(this.evaluateNodeToWhereClause(e.value,t,i,s,r),e.qualifier,e.op);case"case-expression":{let o=" CASE ";e.format==="simple"&&(o+=this.evaluateNodeToWhereClause(e.operand,t,i,F.BADNESS,r));for(let d=0;d<e.clauses.length;d++)o+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[d].operand,t,i,F.BADNESS,r)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[d].value,t,i,F.BADNESS,r);return e.else!==null&&(o+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,i,F.BADNESS,r)),o+=" END ",o}case"parameter":{const o=r[e.value.toLowerCase()];if(typeof o=="string")return"'"+o.toString().replaceAll("'","''")+"'";if(ye(o))return J(o,t);if(ge(o))return J(o,t);if(me(o))return Se(o,t);if(we(o))return Ie(o,t);if(Fe(o))return be(o,t);if(o instanceof Array){const d=[];for(let h=0;h<o.length;h++)typeof o[h]=="string"?d.push("'"+o[h].toString().replaceAll("'","''")+"'"):ye(o[h])||ge(o[h])?d.push(J(o[h],t)):me(o[h])?d.push(Se(o[h],t)):we(o[h])?d.push(Ie(o[h],t)):Fe(o[h])?d.push(be(o[h],t)):d.push(o[h].toString());return d}return o.toString()}case"expression-list":a=[];for(const o of e.value)a.push(this.evaluateNodeToWhereClause(o,t,i,s,r));return a;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,i,F.BADNESS,r)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" AND "+this.evaluateNodeToWhereClause(e.right,t,i,s,r)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" OR "+this.evaluateNodeToWhereClause(e.right,t,i,s,r)+") ";case"IS":if(e.right.type!=="null")throw new N(A.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" IS NULL )";case"ISNOT":if(e.right.type!=="null")throw new N(A.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" IS NOT NULL )";case"IN":if(n=[],e.right.type==="expression-list"){if(e.left.type==="column-reference"&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const o=[];let d=!0;for(const h of e.right.value){if(h.type!=="string"){d=!1;break}if(this.lkp[h.value]===void 0){d=!1;break}o.push(this.lkp[h.value].toString())}if(d)return" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" IN ("+o.join(",")+")) "}return n=this.evaluateNodeToWhereClause(e.right,t,i,s,r)," ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" IN ("+n.join(",")+")) "}return u=this.evaluateNodeToWhereClause(e.right,t,i,s,r),u instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" IN ("+u.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" IN ("+u+")) ";case"NOT IN":if(n=[],e.right.type==="expression-list"){if(e.left.type==="column-reference"&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const o=[];let d=!0;for(const h of e.right.value){if(h.type!=="string"){d=!1;break}if(this.lkp[h.value]===void 0){d=!1;break}o.push(this.lkp[h.value].toString())}if(d)return" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" NOT IN ("+o.join(",")+")) "}return n=this.evaluateNodeToWhereClause(e.right,t,i,s,r)," ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" NOT IN ("+n.join(",")+")) "}return u=this.evaluateNodeToWhereClause(e.right,t,i,s,r),u instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" NOT IN ("+u.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,i,s,r)+" NOT IN ("+u+")) ";case"BETWEEN":return l=this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)," ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" BETWEEN "+l[0]+" AND "+l[1]+" ) ";case"NOTBETWEEN":return l=this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)," ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" NOT BETWEEN "+l[0]+" AND "+l[1]+" ) ";case"LIKE":return e.escape!==""?" ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)+") ";case"NOT LIKE":return e.escape!==""?" ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,i,F.BADNESS,r)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,i,F.BADNESS,r)+") ";case"<>":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<e._known.length&&(a++,a<=i&&(e._lastFetchedIndex+=1),!(this._featureCache[e._known[h]]===void 0&&(e._known[h]!==t&&r.push(e._known[h]),r.length>=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;h<l;h++){const p=(d=this._parent)==null?void 0:d._featureFromCache(r[h]);p!==void 0&&u.push({geometry:p.geometry,attributes:p.attributes,id:r[h]})}for(const h of u){const p=[];for(const g of this.adaptedFields)p[g.field.name]=g.extractValue(h);this._featureCache[h.id]=new q({attributes:p,geometry:ct(h.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new C(D.NeverReach)}async _getFilteredSet(e,t,i,s,r){let n=!1;const a=this._reformulateWithoutAdaptions(i);n=a.cannot,i=a.where;let l=!1;if(s!==null){l=!0;const d=[];for(const h of this.adaptedFields)if(!(h instanceof Y)&&s.scanForField(h.field.name)===!0){if(!(h instanceof mt)){s=null,l=!1;break}d.push({field:h.field.name,newfield:h.originalField.name})}s&&d.length>0&&(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<e.length;l++)for(const u of this.adaptedFields)if(e[l].toLowerCase()===u.field.name.toLowerCase()&&!(u instanceof Y))return!1;const n=[];for(let l=0;l<t.length;l++){const u=t[l];if(u.workingexpr!==null){const o=this._reformulateWithoutAdaptions(u.workingexpr);if(o.cannot)return!1;const d=u.clone();d.workingexpr=o.where,n.push(d)}else n.push(u)}const a=this._reformulateWithoutAdaptions(r);return!a.cannot&&((r=a.where)!==null?this._extraFilter!==null&&(r=P(this._extraFilter,r)):r=this._extraFilter,this._parent._canDoAggregates(e,n,i,s,r))}async _getAggregatePagesDataSourceDefinition(e,t,i,s,r,n,a){if(this._parent===null)throw new C(D.NeverReach);const l=[];for(let o=0;o<t.length;o++){const d=t[o];if(d.workingexpr!==null){const h=this._reformulateWithoutAdaptions(d.workingexpr);if(h.cannot)throw new C(D.NeverReach);const p=d.clone();p.workingexpr=h.where,l.push(p)}else l.push(d)}const u=this._reformulateWithoutAdaptions(r);if(u.cannot)throw new C(D.NeverReach);return(r=u.where)!==null?this._extraFilter!==null&&(r=P(this._extraFilter,r)):r=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,l,i,s,r,n,a)}};function De(c,e){return c===e?0:c===null?-1:e===null?1:c<e?-1:1}class B{constructor(e){const t=e.split(",");this._fields=[],this._directions=[];for(let i=0;i<t.length;i++){const s=t[i].match(/\S+/g);this._fields.push(s[0]),s.length===2?s[1].toLowerCase()==="asc"?this._directions.push(1):this._directions.push(0):this._directions.push(1)}}constructClause(){let e="";for(let t=0;t<this._fields.length;t++)t!==0&&(e+=","),e+=this._fields[t],this._directions[t]===1?e+=" ASC":e+=" DESC";return e}order(e){e.sort((t,i)=>{for(let s=0;s<this._fields.length;s++){const r=this.featureValue(t.feature,this._fields[s],s),n=this.featureValue(i.feature,this._fields[s],s);let a=0;if(a=this._directions[s]===1?De(r,n):-1*De(r,n),a!==0)return a}return 0})}scanForField(e){for(let t=0;t<this._fields.length;t++)if(this._fields[t].toLowerCase().trim()===e.toLowerCase().trim())return!0;return!1}replaceFields(e){let t="";for(let i=0;i<this._fields.length;i++){i!==0&&(t+=",");let s=this._fields[i];for(const r of e)if(s.toLowerCase()===r.field.toLowerCase()){s=r.newfield;break}t+=s,this._directions[i]===1?t+=" ASC":t+=" DESC"}return new B(t)}featureValue(e,t,i){const s=e.attributes[t];if(s!==void 0)return s;for(const r in e.attributes)if(t.toLowerCase()===r.toLowerCase())return this._fields[i]=r,e.attributes[r];return null}}let H=class Le extends O{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(this._wset===null){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){var r;const i=await this.getIdColumnDictionary(e,[],-1,t);(r=this._orderbyclause)==null||r.order(i);const s=new y([],[],!0,null);for(let n=0;n<i.length;n++)s._known.push(i[n].id);return s}async getIdColumnDictionary(e,t,i,s){if(i<e._known.length-1){const r=this._maxQueryRate();if(e._known[i+1]==="GETPAGES")return await W(this._parent._expandPagedSet(e,r,0,0,s)),this.getIdColumnDictionary(e,t,i,s);let n=i+1;const a=[];for(;n<e._known.length&&e._known[n]!=="GETPAGES";)a.push(e._known[n]),n++;i+=a.length;const l=await W(this._parent._getFeatureBatch(a,s));this._checkCancelled(s);for(const u of l)t.push({id:u.attributes[this.objectIdField],feature:u});return this.getIdColumnDictionary(e,t,i,s)}return e._candidates.length>0?(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;a<this._config.groupbyfields.length;a++)if(this._config.groupbyfields[a].name.toLowerCase()===this.objectIdField.toLowerCase()){n=!0;break}if(n===!1){for(let a=0;a<this._config.statsfields.length;a++)if(this._config.statsfields[a].name.toLowerCase()===this.objectIdField.toLowerCase()){n=!0;break}}n===!1?t=!0:(this.objectIdField="ROW__ID"+i.toString(),i++)}for(const n of this._config.statsfields){const a=new Te;a.field=n.name,a.tofieldname=n.name,a.workingexpr=n.expression instanceof T?n.expression:T.create(n.expression,s,this.dateFieldsTimeZoneDefaultUTC),a.typeofstat=bt(n.statistic),this._decodedStatsfield.push(a)}this._decodedGroupbyfield=[];for(const n of this._config.groupbyfields){const a={name:n.name,singlefield:null,tofieldname:n.name,expression:n.expression instanceof T?n.expression:T.create(n.expression,s,this.dateFieldsTimeZoneDefaultUTC),sqlType:null};this._decodedGroupbyfield.push(a)}if(this._parent!==null){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const n of this._parent.fields)e[n.name.toUpperCase()]=1;this.types=null}else this.geometryType=ae.point,this.typeIdField="",this.types=null,this.spatialReference=new se({wkid:4326});this.fields=[];const r=new Te;r.field=this._nextUniqueName(e),r.tofieldname=this.objectIdField,r.workingexpr=T.create(this._parent.objectIdField,this._parent.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),r.typeofstat="MIN",this._decodedStatsfield.push(r);for(const n of this._decodedGroupbyfield){const a=new U;if(n.name=this._nextUniqueName(e),a.name=n.tofieldname,a.alias=a.name,Q(n.expression)){const l=this._parent.getField(R(n.expression,v.Standardised));if(!l)throw new C(D.AggregationFieldNotFound);n.name=l.name,n.singlefield=l.name,this.phsyicalgroupbyfields.push(l.name),a.type=l.type,n.sqlType=l.type}else{a.type=this._convertToEsriFieldType(ot(n.expression,this._parent.fields));const l=new U;l.name=n.name,l.alias=l.name,this.phsyicalgroupbyfields.push(n.name),this._adaptedFields.push(new Ft(l,n.expression)),this._candosimplegroupby=!1,n.sqlType=a.type}this.fields.push(a)}if(this._adaptedFields.length>0)for(const n of this._parent.fields)this._adaptedFields.push(new Y(n));for(let n=0;n<this._decodedStatsfield.length;n++){const a=new U;let l=null;const u=this._decodedStatsfield[n];u.field=this._nextUniqueName(e),u.tofieldname===this.objectIdField&&(this._internalObjectIdField=u.field),a.name=u.tofieldname,a.alias=a.name;const o=u.workingexpr!==null&&Q(u.workingexpr)?R(u.workingexpr,v.Standardised):"";switch(this._decodedStatsfield[n].typeofstat){case"SUM":if(o!==""){if(l=this._parent.getField(o),!l)throw new C(D.AggregationFieldNotFound);a.type=l.type}else a.type="double";break;case"MIN":case"MAX":if(o!==""){if(l=this._parent.getField(o),!l)throw new C(D.AggregationFieldNotFound);a.type=l.type}else a.type="double";break;case"COUNT":a.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(o!==""&&(l=this._parent.getField(o),!l))throw new C(D.AggregationFieldNotFound);a.type="double"}this.fields.push(a)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){t!==-1&&this._featureCache[t];const r=this._maxQuery;return this._checkIfNeedToExpandKnownPage(e,r)===!0?(await this._expandPagedSet(e,r,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,r){if(e!=="")return new y([],[],!0,null);let n=null;const a={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),i!==null){for(let u=0;u<this._decodedStatsfield.length;u++)if(ve(i,this._decodedStatsfield[u].tofieldname)===!0){a.nowhereclause=!0,i=null;break}}if(s!==null){a.ordered=!0;for(let u=0;u<this._decodedStatsfield.length;u++)if(s.scanForField(this._decodedStatsfield[u].tofieldname)===!0){s=null,a.ordered=!1;break}if(s!==null){for(const u of this._decodedGroupbyfield)if(u.singlefield===null&&s.scanForField(u.tofieldname)===!0){s=null,a.ordered=!1;break}}}if(this._candosimplegroupby!==!1&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let u=null;i&&(u=this._reformulateWhereClauseWithoutGroupByFields(i));let o=null;s&&(o=this._reformulateOrderClauseWithoutGroupByFields(s));const d=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,u,o,this._internalObjectIdField);return this._checkCancelled(r),n=a.nowhereclause===!0?new y(d._candidates.slice(0).concat(d._known.slice(0)),[],a.ordered===!0&&d._ordered,this._clonePageDefinition(d.pagesDefinition)):new y(d._candidates.slice(0),d._known.slice(0),a.ordered===!0&&d._ordered,this._clonePageDefinition(d.pagesDefinition)),n}let l=this._parent;if(this._adaptedFields.length>0&&(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;r<e.features.length;r++)if(t.workingexpr!==null){const n=t.workingexpr.calculateValue(e.features[r]);n!==null&&(n instanceof ht||n instanceof ft?s.push(n.toNumber()):n instanceof st?s.push(n.toMilliseconds()):s.push(n))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=j("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=j("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=j("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=j("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=j("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=j("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(e){const t={attributes:{},geometry:null};for(const s of this._decodedGroupbyfield){const r=s.singlefield?e.features[0].attributes[s.singlefield]:T.convertValueToStorageFormat(s.expression.calculateValue(e.features[0]),s.sqlType);t.attributes[s.tofieldname]=r}for(const s of this._decodedStatsfield)this._calculateFieldStat(e,s,t);const i=[];for(let s=0;s<this._decodedStatsfield.length;s++)i.push(this._calculateFieldStat(e,this._decodedStatsfield[s],t));return this._featureCache[t.attributes[this.objectIdField]]=new q({attributes:t.attributes,geometry:t.geometry}),t}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=s==null?":":":"+s.toString()}return Re(t,ke.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){O._featuresetFunctions.groupby=function(e,t){return new Oe({parentfeatureset:this,groupbyfields:e,statsfields:t})}}};class ne extends O{constructor(e){super(e),this._topnum=0,this.declaredClass="esri.arcade.featureset.actions.Top",this._countedin=0,this._maxProcessing=100,this._topnum=e.topnum,this._parent=e.parentfeatureset}async _getSet(e){if(this._wset===null){await this._ensureLoaded();const t=await this._parent._getSet(e);return this._wset=new y(t._candidates.slice(0),t._known.slice(0),!1,this._clonePageDefinition(t.pagesDefinition)),this._setKnownLength(this._wset)>this._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._countedin<this._topnum?(this._idstates[e]=b.InFeatureSet,this._countedin++,b.InFeatureSet):(this._idstates[e]=b.NotInFeatureSet,b.NotInFeatureSet):b.Unknown}async _expandPagedSet(e,t,i,s,r){if(this._parent===null)throw new C(D.NotImplemented);if(t>this._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;o<e._known.length&&(a++,a<=i&&(e._lastFetchedIndex+=1),!(this._featureCache[e._known[o]]===void 0&&(e._known[o]!==t&&r.push(e._known[o]),r.length>n)));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<u;o++){const d=this._parent._featureFromCache(r[o]);d!==void 0&&(this._featureCache[r[o]]=d)}return"success"}async _getFilteredSet(e,t,i,s,r){await this._ensureLoaded();const n=await this._getSet(r);return new y(n._candidates.slice(0).concat(n._known.slice(0)),[],!1,this._clonePageDefinition(n.pagesDefinition))}_refineKnowns(e,t){let i=0,s=null;const r=[];for(let n=0;n<e._candidates.length;n++){const a=this._isInFeatureSet(e._candidates[n]);if(a===b.InFeatureSet){if(e._known.push(e._candidates[n]),i+=1,s===null?s={start:n,end:n}:s.end===n-1?s.end=n:(r.push(s),s={start:n,end:n}),e._known.length>=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<o&&(o=d);let h=null;if(this._pageJustIds===!0)h=new y([],["GETPAGES"],a,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:o,resultOffset:0,geometry:t===null?null:t,where:u,orderByFields:n,returnGeometry:!1,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}});else{let g=!0;this._removeGeometry===!0&&(g=!1);const m=this._overrideFields??this._fieldsIncludingObjectId(["*"]);h=new y([],["GETPAGES"],a,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:m.join(","),resultRecordCount:o,resultOffset:0,geometry:t===null?null:t,where:u,orderByFields:n,returnGeometry:g,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(h,o,0,1,r),h}_clonePageDefinition(e){return e===null?null:e.groupbypage!==!0?{groupbypage:!1,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,spatialRel:e.spatialRel,relationParam:e.relationParam,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,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=new x;this._requestStandardised&&(a.sqlFormat="standard"),this.datesInUnknownTimezone&&(a.timeReferenceUnknownClient=!0),a.spatialRelationship=e.pagesDefinition.spatialRel,a.relationParameter=e.pagesDefinition.relationParam,a.outFields=e.pagesDefinition.outFields.split(","),a.num=e.pagesDefinition.resultRecordCount,a.start=e.pagesDefinition.internal.lastPage,a.geometry=e.pagesDefinition.geometry,a.where=e.pagesDefinition.where,a.orderByFields=e.pagesDefinition.orderByFields!==""?e.pagesDefinition.orderByFields.split(","):null,a.returnGeometry=e.pagesDefinition.returnGeometry,a.outSpatialReference=this.spatialReference;const l=await this.executeQuery(a,"execute");if(this._checkCancelled(i),e.pagesDefinition.internal.lastPage!==n)return"done";const u=this._layer.objectIdField;for(let o=0;o<l.features.length;o++)e.pagesDefinition.internal.set[r+o]=l.features[o].attributes[u];if(this._pageJustIds===!1)for(let o=0;o<l.features.length;o++)this._featureCache[l.features[o].attributes[u]]=l.features[o];return(l.exceededTransferLimit===void 0&&l.features.length!==e.pagesDefinition.resultRecordCount||l.exceededTransferLimit===!1)&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=s+l.features.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,"done"}_fieldsIncludingObjectId(e){if(e===null)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let i=!1;for(const s of t)if(s.toUpperCase()===this.objectIdField.toUpperCase()){i=!0;break}return i===!1&&t.push(this.objectIdField),t}async _getFeatures(e,t,i,s){const r=[];if(t!==-1&&this._featureCache[t]===void 0&&r.push(t),this._checkIfNeedToExpandKnownPage(e,this._maxProcessingRate())===!0)return await this._expandPagedSet(e,this._maxProcessingRate(),0,0,s),this._getFeatures(e,t,i,s);let n=0;for(let o=e._lastFetchedIndex;o<e._known.length;o++){if(e._lastFetchedIndex+=1,n++,this._featureCache[e._known[o]]===void 0){let d=!1;if(this._layer._mode!==null&&this._layer._mode!==void 0){const h=this._layer._mode;if(h._featureMap[e._known[o]]!==void 0){const p=h._featureMap[e._known[o]];p!==null&&(d=!0,this._featureCache[e._known[o]]=p)}}if(d===!1&&(e._known[o]!==t&&r.push(e._known[o]),r.length>=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<l.features.length;o++)this._featureCache[l.features[o].attributes[u]]=l.features[o];return"success"}async _getDistinctPages(e,t,i,s,r,n,a,l,u){var S;await this._ensureLoaded();const o=await this.databaseType();let d=i.parseTree.column;const h=this._layer.fields??[];for(let f=0;f<h.length;f++)if(h[f].name.toLowerCase()===d.toLowerCase()){d=h[f].name;break}const p=new x;this._requestStandardised&&(p.sqlFormat="standard"),this.datesInUnknownTimezone&&(p.timeReferenceUnknownClient=!0);let g=n===null?r===null?"1=1":"":R(n,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(g=g!==""?"(("+this._layer.definitionExpression+") AND ("+g+"))":this._layer.definitionExpression),p.where=g,p.spatialRelationship=this._makeRelationshipEnum(s),p.relationParameter=this._makeRelationshipParam(s),p.geometry=r===null?null:r,p.returnDistinctValues=!0,p.returnGeometry=!1,p.outFields=[d];const m=await this.executeQuery(p,"execute");if(this._checkCancelled(u),!m.hasOwnProperty("features"))throw new C(D.InvalidStatResponse);let I=!1;for(let f=0;f<h.length;f++)if(h[f].name===d){h[f].type==="date"&&(I=!0);break}for(let f=0;f<m.features.length;f++){if(I){const _=m.features[f].attributes[d];_!==null?l.push(new Date(_)):l.push(_)}else l.push(m.features[f].attributes[d]);if(l.length>=a)break}return m.features.length===0?l:m.features.length===((S=this._layer.capabilities)==null?void 0:S.query.maxRecordCount)&&l.length<a?{calculated:!0,result:await this._getDistinctPages(e+m.features.length,t,i,s,r,n,a,l,u)}:l}async _distinctStat(e,t,i,s,r,n,a){return{calculated:!0,result:await this._getDistinctPages(0,e,t,i,s,r,n,[],a)}}isTable(){return this._layer.isTable||this._layer.geometryType===null||this._layer.type==="table"||this._layer.geometryType===""||this._layer.geometryType==="esriGeometryNull"}async _countstat(e,t,i,s){const r=await this.databaseType(),n=new x;if(this._requestStandardised&&(n.sqlFormat="standard"),this.isTable()&&i&&t!==null&&t!=="")return{calculated:!0,result:0};let a=s===null?i===null?"1=1":"":R(s,r);return this._layer.definitionExpression&&this._useDefinitionExpression&&(a=a!==""?"(("+this._layer.definitionExpression+") AND ("+a+"))":this._layer.definitionExpression),n.where=a,this.datesInUnknownTimezone&&(n.timeReferenceUnknownClient=!0),n.where=a,n.spatialRelationship=this._makeRelationshipEnum(t),n.relationParameter=this._makeRelationshipParam(t),n.geometry=i===null?null:i,n.returnGeometry=!1,{calculated:!0,result:await this.executeQuery(n,"executeForCount")}}async _stats(e,t,i,s,r,n,a){await this._ensureLoaded();const l=this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsSqlExpression===!0,u=this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsStatistics===!0,o=this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsDistinct===!0;if(e==="count")return o?this._countstat(e,i,s,r):{calculated:!1};if(u===!1||Q(t)===!1&&l===!1||t.isStandardized===!1)return i!==""||r!==null?{calculated:!1}:this._manualStat(e,t,n,a);if(e==="distinct")return o===!1?i!==""||r!==null?{calculated:!1}:this._manualStat(e,t,n,a):this._distinctStat(e,t,i,s,r,n,a);const d=await this.databaseType();if(this.isTable()&&s&&i!==null&&i!=="")return{calculated:!0,result:null};const h=new x;this._requestStandardised&&(h.sqlFormat="standard");let p=r===null?s===null?"1=1":"":R(r,d);this._layer.definitionExpression&&this._useDefinitionExpression&&(p=p!==""?"(("+this._layer.definitionExpression+") AND ("+p+"))":this._layer.definitionExpression),h.where=p,h.spatialRelationship=this._makeRelationshipEnum(i),h.relationParameter=this._makeRelationshipParam(i),h.geometry=s===null?null:s,this.datesInUnknownTimezone&&(h.timeReferenceUnknownClient=!0);const g=new fe;g.statisticType=ut(e),g.onStatisticField=R(t,d),g.outStatisticFieldName="ARCADE_STAT_RESULT",h.returnGeometry=!1;let m="ARCADE_STAT_RESULT";h.outStatistics=[g];const I=await this.executeQuery(h,"execute");if(!I.hasOwnProperty("features")||I.features.length===0)throw new C(D.InvalidStatResponse);let S=!1;const f=I.fields??[];for(let _=0;_<f.length;_++)if(f[_].name.toUpperCase()==="ARCADE_STAT_RESULT"){m=f[_].name,f[_].type==="date"&&(S=!0);break}if(S){let _=I.features[0].attributes[m];return _!==null&&(_=new Date(I.features[0].attributes[m])),{calculated:!0,result:_}}return{calculated:!0,result:I.features[0].attributes[m]}}_stat(e,t,i,s,r,n,a){return this._stats(e,t,i,s,r,n,a)}async _canDoAggregates(e,t){var n,a;await this._ensureLoaded();let i=!1;const s=(n=this._layer.capabilities)==null?void 0:n.query,r=(s==null?void 0:s.supportsSqlExpression)===!0;if(s!=null&&s.supportsStatistics===!0&&s.supportsOrderBy===!0&&(i=!0),i)for(let l=0;l<t.length-1;l++)(((a=t[l].workingexpr)==null?void 0:a.isStandardized)===!1||Q(t[l].workingexpr)===!1&&r===!1)&&(i=!1);return i!==!1}_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 _getAggregatePagesDataSourceDefinition(e,t,i,s,r,n,a){var I;await this._ensureLoaded();const l=await this.databaseType();let u="",o=!1,d=!1;n!==null&&this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsOrderBy===!0&&(u=n.constructClause(),d=!0),this._layer.capabilities&&this._layer.capabilities.query&&this._layer.capabilities.query.supportsPagination===!1&&(d=!1,o=!0,u=this._layer.objectIdField);const h=[];for(let S=0;S<t.length;S++){const f=new fe;f.onStatisticField=t[S].workingexpr!==null?R(t[S].workingexpr,l):"",f.outStatisticFieldName=t[S].field,f.statisticType=t[S].toStatisticsName(),h.push(f)}u===""&&(u=e.join(","));let p=this._maxQueryRate();const g=(I=this._layer.capabilities)==null?void 0:I.query.maxRecordCount;g!=null&&g<p&&(p=g);let m=r===null?s===null?"1=1":"":R(r,l);return this._layer.definitionExpression&&this._useDefinitionExpression&&(m=m!==""?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression),new y([],["GETPAGES"],d,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:o,generatedOid:a,resultRecordCount:p,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:h,geometry:s===null?null:s,where:m,orderByFields:u,returnGeometry:!1,returnIdsOnly:!1,internal:{lastMaxId:-1,set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}async _getAgregagtePhysicalPage(e,t,i){let s=e.pagesDefinition.where;e.pagesDefinition.useOIDpagination===!0&&(s=s!==""?"("+s+") AND ("+e.pagesDefinition.generatedOid+">"+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;d<u.features.length;d++)e.pagesDefinition.internal.set[n+d]=u.features[d].attributes[e.pagesDefinition.generatedOid];for(let d=0;d<u.features.length;d++)o.push(new q({attributes:u.features[d].attributes,geometry:null}));return e.pagesDefinition.useOIDpagination===!0?u.features.length===0?e.pagesDefinition.internal.fullyResolved=!0:e.pagesDefinition.internal.lastMaxId=u.features[u.features.length-1].attributes[e.pagesDefinition.generatedOid]:(u.exceededTransferLimit===void 0&&u.features.length!==e.pagesDefinition.resultRecordCount||u.exceededTransferLimit===!1)&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=r+u.features.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,o}static create(e,t,i,s,r){const n=new k({url:e,outFields:t===null?["*"]:t});return new te({layer:n,spatialReference:i,lrucache:s,interceptor:r})}relationshipMetaData(){var e;return this._layer&&this._layer.source&&((e=this._layer.source.sourceJSON)!=null&&e.relationships)?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return K(this._layer.parsedUrl.path)}async queryAttachments(e,t,i,s,r){const n=this._layer.capabilities;if(n!=null&&n.data.supportsAttachment&&(n!=null&&n.operations.supportsQueryAttachments)){const a={objectIds:[e],returnMetadata:r};(t&&t>0||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;r<e._known.length&&(e._lastFetchedIndex+=1,!(this._featureCache[e._known[r]]===void 0&&(e._known[r]!==t&&s.push(e._known[r]),s.length>i)));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<a.length;E++)z.push({geometry:e.featureSet.features[E].geometry,attributes:e.featureSet.features[E].attributes?this._cloneAttr(e.featureSet.features[E].attributes):{}}),z[E].attributes[_]=E;a=z,i=_}}const u=[];for(const f of e.layerDefinition.fields)f instanceof U?u.push(f):u.push(U.fromJSON(f));let o=n;switch(o||(o=""),o){case"esriGeometryPoint":o="point";break;case"esriGeometryPolyline":o="polyline";break;case"esriGeometryPolygon":o="polygon";break;case"esriGeometryEnvelope":o="extent";break;case"esriGeometryMultipoint":o="multipoint";break;case"":case"esriGeometryNull":o="esriGeometryNull"}if(o!=="esriGeometryNull")for(const f of a)f.geometry&&!(f.geometry instanceof Ke)&&(f.geometry.type=o,f.geometry.spatialReference===void 0&&(f.geometry.spatialReference=l));else for(const f of a)f.geometry&&(f.geometry=null);const d={outFields:["*"],source:a,fields:u,hasZ:((g=e==null?void 0:e.layerDefinition)==null?void 0:g.hasZ)===!0||((m=e==null?void 0:e.featureSet)==null?void 0:m.hasZ)===!0,hasM:((I=e==null?void 0:e.layerDefinition)==null?void 0:I.hasM)===!0||((S=e==null?void 0:e.featureSet)==null?void 0:S.hasM)===!0,types:r,typeIdField:s,objectIdField:i,spatialReference:t},h=o==="esriGeometryNull"||o===null;h||(d.geometryType=o);const p=new k(d);return new le({layer:p,spatialReference:t,isTable:h})}async queryAttachments(){return[]}async getFeatureByObjectId(e){const t=new x;t.where=this.objectIdField+"="+e.toString(),t.returnZ=this.hasZ,t.returnM=this.hasM;const i=await this._layer.queryFeatures(t);return i.features.length===1?i.features[0]:null}async getOwningSystemUrl(){return""}async getIdentityUser(){return""}get preferredTimeZone(){return this._layer.preferredTimeZone??null}get dateFieldsTimeZone(){return this._layer.dateFieldsTimeZone??null}get datesInUnknownTimezone(){var e;return(e=this._layer)==null?void 0:e.datesInUnknownTimezone}get editFieldsInfo(){var e;return(e=this._layer)==null?void 0:e.editFieldsInfo}get timeInfo(){var e;return(e=this._layer)==null?void 0:e.timeInfo}async getFeatureSetInfo(){const e=this._layer.title&&this._layer.parent;return this.fsetInfo??{layerId:null,layerName:null,itemId:null,serviceLayerUrl:null,webMapLayerId:e?this._layer.id??null:null,webMapLayerTitle:e?this._layer.title??null:null,className:null,objectClassId:null}}}class Nt extends O{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerRelated",this._findObjectId=-1,this._requestStandardised=!1,this._removeGeometry=!1,this._overrideFields=null,this.featureObjectId=null,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,this._findObjectId=e.objectId,this.featureObjectId=e.objectId,this.relationship=e.relationship,this._relatedLayer=e.relatedLayer,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(){var e;return await Promise.all([this._layer.load(),(e=this._relatedLayer)==null?void 0:e.load()]),this._initialiseFeatureSet(),this}nativeCapabilities(){return this._relatedLayer.nativeCapabilities()}_initialiseFeatureSet(){if(this.spatialReference==null&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._relatedLayer.geometryType,this.fields=this._relatedLayer.fields.slice(0),this.hasZ=this._relatedLayer.hasZ,this.hasM=this._relatedLayer.hasM,this._overrideFields!==null)if(this._overrideFields.length===1&&this._overrideFields[0]==="*")this._overrideFields=null;else{const t=[],i=[];for(const s of this.fields)if(s.type==="oid")t.push(s),i.push(s.name);else for(const r of this._overrideFields)if(r.toLowerCase()===s.name.toLowerCase()){t.push(s),i.push(s.name);break}this.fields=t,this._overrideFields=i}const e=this._layer.nativeCapabilities();e&&(this._databaseType=e.databaseType,this._requestStandardised=e.requestStandardised),this.objectIdField=this._relatedLayer.objectIdField,this.globalIdField=this._relatedLayer.globalIdField,this.hasM=this._relatedLayer.supportsM,this.hasZ=this._relatedLayer.supportsZ,this.typeIdField=this._relatedLayer.typeIdField,this.types=this._relatedLayer.types}async databaseType(){return await this._relatedLayer.databaseType(),this._databaseType=this._relatedLayer._databaseType,this._databaseType}isTable(){return this._relatedLayer.isTable()}_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){var S,f;if(await this.databaseType(),this.isTable()&&t&&e!==null&&e!=="")return new y([],[],!0,null);const n=this._layer.nativeCapabilities();if(n.canQueryRelated===!1)return new y([],[],!0,null);if((S=n.capabilities)!=null&&S.queryRelated&&n.capabilities.queryRelated.supportsPagination)return this._getFilteredSetUsingPaging(e,t,i,s,r);let a="",l=!1;s!==null&&((f=n.capabilities)!=null&&f.queryRelated)&&n.capabilities.queryRelated.supportsOrderBy===!0&&(a=s.constructClause(),l=!0);const u=new _e;u.objectIds=[this._findObjectId];const o=this._overrideFields!==null?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map(_=>_.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;_<p.length;_++)this._featureCache[p[_].attributes[this._relatedLayer.objectIdField]]=p[_],g.push(p[_].attributes[this._relatedLayer.objectIdField]);const m=t&&e!==null&&e!=="",I=i!=null;return new y(m||I?g:[],m||I?[]:g,l,null)}_fieldsIncludingObjectId(e){if(e===null)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let i=!1;for(const s of t)if(s.toUpperCase()===this.objectIdField.toUpperCase()){i=!0;break}return i===!1&&t.push(this.objectIdField),t}async _getFilteredSetUsingPaging(e,t,i,s,r){var S,f;let n="",a=!1;const l=this._layer.nativeCapabilities();s!==null&&((S=l==null?void 0:l.capabilities)!=null&&S.queryRelated)&&l.capabilities.queryRelated.supportsOrderBy===!0&&(n=s.constructClause(),a=!0),await this.databaseType();const u="1=1";let o=this._maxQueryRate();const d=(f=l.capabilities)==null?void 0:f.query.maxRecordCount;d!=null&&d<o&&(o=d);const h=t&&e!==null&&e!=="",p=i!=null;let g=null,m=!0;this._removeGeometry===!0&&(m=!1);const I=this._overrideFields!==null?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map(_=>_.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;h<o.length;h++)e.pagesDefinition.internal.set[r+h]=o[h].attributes[this._relatedLayer.objectIdField];for(let h=0;h<o.length;h++)this._featureCache[o[h].attributes[this._relatedLayer.objectIdField]]=o[h];const d=!u[this._findObjectId]||u[this._findObjectId].exceededTransferLimit===!1;return o.length!==e.pagesDefinition.resultRecordCount&&d&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=s+o.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,o.length}async _getFeatures(e,t,i,s){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 l=e._lastFetchedIndex;l<e._known.length&&(a++,a<=i&&(e._lastFetchedIndex+=1),!(e._known[l]!=="GETPAGES"&&this._featureCache[e._known[l]]===void 0&&(e._known[l]!==t&&r.push(e._known[l]),r.length>i)))&&!(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<this._instantLayers.length;a++){const l=this._instantLayers[a];if(l.opitem.title===e&&l.includeGeometry===t&&l.outFields===s)return this._instantLayers[a].featureset}const r=[],n=this._map.allLayers.find(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<this._instantLayers.length;a++){const l=this._instantLayers[a];if(l.opitem.id===e&&l.includeGeometry===t&&l.outFields===s)return this._instantLayers[a].featureset}const r=[],n=this._map.allLayers.find(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<this._instantLayers.length;a++){const l=this._instantLayers[a];if(l.opitem.title===e&&l.includeGeometry===t&&l.outFields===s)return this._instantLayers[a].featureset}const r=await this._loadMetaData();let n=null;for(const a of r.layers??[])a.name===e&&(n=a);if(!n)for(const a of r.tables??[])a.name===e&&(n=a);if(n){const a=await ie(this._url+"/"+n.id,["*"]);return this._makeAndAddFeatureSet(a,t,i)}return null}async featureSetById(e,t=!0,i=["*"]){i===null&&(i=["*"]),i=(i=i.slice(0)).sort();const s=JSON.stringify(i);e=e!=null?e.toString():"";for(let a=0;a<this._instantLayers.length;a++){const l=this._instantLayers[a];if(l.opitem.id===e&&l.includeGeometry===t&&l.outFields===s)return this._instantLayers[a].featureset}const r=await this._loadMetaData();let n=null;for(const a of r.layers??[])a.id!==null&&a.id!==void 0&&a.id.toString()===e&&(n=a);if(!n)for(const a of r.tables??[])a.id!==null&&a.id!==void 0&&a.id.toString()===e&&(n=a);if(n){const a=await ie(this._url+"/"+n.id,["*"]);return this._makeAndAddFeatureSet(a,t,i)}return null}}function jt(c,e,t=null,i=null){return new qt(c,e,t,i)}function Gt(c,e,t=null,i=null){return new ue(c,e,t,i)}function Ut(c,e,t,i,s){if(c===null)return null;if(c instanceof k){switch(e){case"datasource":return L(c,s,c.outFields,!0,t,i).getDataSourceFeatureSet();case"parent":case"root":return L(c,s,c.outFields,!0,t,i)}return null}if($(c)){switch(e){case"datasource":return L(c,s,c.outFields,!0,t,i).getDataSourceFeatureSet();case"parent":case"root":return L(c,s,c.outFields,!0,t,i)}return null}if(it(c)){switch(e){case"datasource":return L(c.parent,s,c.parent.outFields,!0,t,i).getDataSourceFeatureSet();case"parent":case"root":return L(c,s,c.parent.outFields,!0,t,i)}return null}if(c instanceof O)switch(e){case"datasource":return c.getDataSourceFeatureSet();case"parent":return c;case"root":return c.getRootFeatureSet()}return null}async function Bt(c,e,t,i,s,r,n,a=null){if(w.applicationCache){const u=w.applicationCache.getLayerInfo(c+":"+r.url);if(u){const o=await u;return L(new k({url:K(o.url)+"/"+e,outFields:["*"]}),t,i,s,n,a)}}const l=new Xe({id:c,portal:r}).load();w.applicationCache&&w.applicationCache.setLayerInfo(c+":"+r.url,l);try{const u=await l;return L(new k({url:K(u.url??"")+"/"+e,outFields:["*"]}),t,i,s,n,a)}catch(u){throw w.applicationCache&&w.applicationCache.clearLayerInfo(c+":"+r.url),u}}const ri=Object.freeze(Object.defineProperty({__proto__:null,constructAssociationMetaDataFeatureSetFromUrl:Et,constructFeatureSet:L,constructFeatureSetFromPortalItem:Bt,constructFeatureSetFromRelationship:Pt,constructFeatureSetFromUrl:oe,convertToFeatureSet:Ut,createFeatureSetCollectionFromMap:jt,createFeatureSetCollectionFromService:Gt,initialiseMetaDataCache:At},Symbol.toStringTag,{value:"Module"}));export{Ft as B,oe as F,Y as I,St as L,Et as T,B as a,H as b,Ae as c,ne as d,Ne as e,le as f,L as g,wt as h,mt as i,Ut as j,Pt as k,ri as l,Bt as q};
|