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