import{a8 as q,a2 as d,a9 as k,aa as H,ab as J,ac as Y,$ as j,a0 as T,ad as V,ae as W,af as L,ag as C,ah as U}from"./arcadeUtils.8527a548.js";import{b2 as x,aL as Z,ca as X,hG as O}from"./index.6c049565.js";import{WhereClause as I}from"./WhereClause.39c9a123.js";import{b as z,K as ee,W as te,M as ne,F as re,R as se,m as ae,S as ie,x as le,O as ue,p as oe,h as G}from"./geometryEngineAsync.d256b0dc.js";var p;(function(s){s.InvalidFunctionParameters="InvalidFunctionParameters",s.UnsupportedSqlFunction="UnsupportedSqlFunction",s.UnsupportedOperator="UnsupportedOperator",s.UnsupportedSyntax="UnsupportedSyntax",s.UnsupportedIsRhs="UnsupportedIsRhs",s.UnsupportedIsLhs="UnsupportedIsLhs",s.MissingStatisticParameters="MissingStatisticParameters"})(p||(p={}));const ce={[p.MissingStatisticParameters]:"Statistic does not have 1 or 0 Parameters",[p.InvalidFunctionParameters]:"Invalid parameters for call to {function}",[p.UnsupportedIsLhs]:"Unsupported left hand expression in is statement",[p.UnsupportedIsRhs]:"Unsupported right hand expression in is statement",[p.UnsupportedOperator]:"Unsupported operator - {operator}",[p.UnsupportedSyntax]:"Unsupported syntax - {node}",[p.UnsupportedSqlFunction]:"Sql function not found = {function}"};class g extends Error{constructor(e,t){super(q(ce[e],t)),this.declaredRootClass="esri.arcade.featureset.support.sqlerror",Error.captureStackTrace&&Error.captureStackTrace(this,g)}}var f;(function(s){s.NeverReach="NeverReach",s.NotImplemented="NotImplemented",s.Cancelled="Cancelled",s.InvalidStatResponse="InvalidStatResponse",s.InvalidRequest="InvalidRequest",s.RequestFailed="RequestFailed",s.MissingFeatures="MissingFeatures",s.AggregationFieldNotFound="AggregationFieldNotFound",s.DataElementsNotFound="DataElementsNotFound"})(f||(f={}));const he={[f.Cancelled]:"Cancelled",[f.InvalidStatResponse]:"Invalid statistics response from service",[f.InvalidRequest]:"Invalid request",[f.RequestFailed]:"Request failed - {reason}",[f.MissingFeatures]:"Missing features",[f.AggregationFieldNotFound]:"Aggregation field not found",[f.DataElementsNotFound]:"Data elements not found on service",[f.NeverReach]:"Encountered unreachable logic",[f.NotImplemented]:"Not implemented"};class m extends Error{constructor(e,t){super(q(he[e],t)),this.declaredRootClass="esri.arcade.featureset.support.featureseterror",Error.captureStackTrace&&Error.captureStackTrace(this,m)}}class R{constructor(){this._databaseTypeMetaData={},this._layerInfo={}}clearDatabaseType(e){this._databaseTypeMetaData[e]===void 0&&delete this._databaseTypeMetaData[e]}getDatabaseType(e){return e==="MUSTBESET"||this._databaseTypeMetaData[e]===void 0?null:this._databaseTypeMetaData[e]}setDatabaseType(e,t){this._databaseTypeMetaData[e]=t}getLayerInfo(e){return this._layerInfo[e]===void 0?null:this._layerInfo[e]}setLayerInfo(e,t){this._layerInfo[e]=t}clearLayerInfo(e){this._layerInfo[e]!==void 0&&delete this._layerInfo[e]}}R.applicationCache=null;class de{constructor(e,t){this._lastId=-1,this._progress=t,this._parent=e}reset(){this._lastId=-1}nextBatch(e){if(this._parent._mainSetInUse!==null)return this._parent._mainSetInUse.then(r=>this.nextBatch(e),r=>this.nextBatch(e));const t={returnpromise:null,hasset:!1},n=[];return t.returnpromise=new Promise((r,a)=>{this._parent._getSet(this._progress).then(i=>{const l=x(i._known,"known");let u=l.length-1;if(l[l.length-1]==="GETPAGES"&&(u-=1),this._lastId+e>u&&l.length>0&&l[l.length-1]==="GETPAGES")return void this._parent._expandPagedSet(i,this._parent._maxQueryRate(),0,0,this._progress).then(_=>{t.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(e).then(r,a)},_=>{t.hasset=!0,this._parent._mainSetInUse=null,a(_)});const o=x(i._candidates,"candidates");if(u>=this._lastId+e||o.length===0){for(let _=0;_=l.length)break;n[_]=l[w]}return this._lastId+=n.length,n.length===0&&(t.hasset=!0,this._parent._mainSetInUse=null,r([])),void this._parent._getFeatureBatch(n,this._progress).then(_=>{t.hasset=!0,this._parent._mainSetInUse=null,r(_)},_=>{t.hasset=!0,this._parent._mainSetInUse=null,a(_)})}this._parent._refineSetBlock(i,this._parent._maxProcessingRate(),this._progress).then(()=>{t.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(e).then(r,a)},_=>{t.hasset=!0,this._parent._mainSetInUse=null,a(_)})},i=>{t.hasset=!0,this._parent._mainSetInUse=null,a(i)})}),t.hasset===!1&&(this._parent._mainSetInUse=t.returnpromise,t.hasset=!0),t.returnpromise}next(){if(this._parent._mainSetInUse!==null)return this._parent._mainSetInUse.then(t=>this.next(),t=>this.next());const e={returnpromise:null,hasset:!1};return e.returnpromise=new Promise((t,n)=>{this._parent._getSet(this._progress).then(r=>{const a=x(r._known,"known");this._lastId(e.hasset=!0,this._parent._mainSetInUse=null,this.next())).then(t,n):(this._lastId+=1,this._parent._getFeature(r,a[this._lastId],this._progress).then(i=>{e.hasset=!0,this._parent._mainSetInUse=null,t(i)},i=>{e.hasset=!0,this._parent._mainSetInUse=null,n(i)})):x(r._candidates,"candidates").length>0?this._parent._refineSetBlock(r,this._parent._maxProcessingRate(),this._progress).then(()=>{e.hasset=!0,this._parent._mainSetInUse=null,this.next().then(t,n)},i=>{e.hasset=!0,this._parent._mainSetInUse=null,n(i)}):(e.hasset=!0,this._parent._mainSetInUse=null,t(null))},r=>{e.hasset=!0,this._parent._mainSetInUse=null,n(r)})}),e.hasset===!1&&(this._parent._mainSetInUse=e.returnpromise,e.hasset=!0),e.returnpromise}async count(){if(this._parent._totalCount!==-1)return this._parent._totalCount;const e=await this._parent._getSet(this._progress),t=await this._refineAllSets(e);return this._parent._totalCount=t._known.length,this._parent._totalCount}async _refineAllSets(e){if(e._known.length>0&&e._known[e._known.length-1]==="GETPAGES")return await this._parent._expandPagedSet(e,this._parent._maxQueryRate(),0,1,this._progress),this._refineAllSets(e);if(e._candidates.length>0){if(e._known[e._candidates.length-1]==="GETPAGES")return await this._parent._expandPagedSet(e,this._parent._maxQueryRate(),0,2,this._progress),this._refineAllSets(e);const t=await this._parent._refineSetBlock(e,this._parent._maxProcessingRate(),this._progress);return t._candidates.length>0?this._refineAllSets(t):t}return e}}class v{constructor(e,t,n,r){this._lastFetchedIndex=0,this._ordered=!1,this.pagesDefinition=null,this._candidates=e,this._known=t,this._ordered=n,this.pagesDefinition=r}}function M(s,e){return c(s==null?void 0:s.parseTree,e,s==null?void 0:s.parameters)}function Ae(s,e,t){return c(s,e,t)}function ke(s,e,t,n){return I.create(c(s.parseTree,d.Standardised,s.parameters,e,t),n)}function Le(s,e,t="AND"){return I.create("(("+M(s,d.Standardised)+")"+t+"("+M(e,d.Standardised)+"))",s.fieldsIndex)}function c(s,e,t,n=null,r=null){let a,i,l,u;switch(s.type){case"interval":return me(c(s.value,e,t,n,r),s.qualifier,s.op);case"case-expression":{let o=" CASE ";s.format==="simple"&&(o+=c(s.operand,e,t,n,r));for(let _=0;_":case"<":case">":case">=":case"<=":case"=":case"*":case"-":case"+":case"/":return" ("+c(s.left,e,t,n,r)+" "+s.operator+" "+c(s.right,e,t,n,r)+") "}throw new g(p.UnsupportedOperator,{operator:s.operator});case"null":return"null";case"boolean":return s.value===!0?"1":"0";case"string":return"'"+s.value.toString().replace(/'/g,"''")+"'";case"timestamp":case"date":return N(s.value,e);case"number":return s.value.toString();case"current-time":return _e(s.mode==="date",e);case"column-reference":return n&&n.toLowerCase()===s.column.toLowerCase()?"("+r+")":s.column;case"function":{const o=c(s.args,e,t,n,r);return pe(s.name,o,e)}}throw new g(p.UnsupportedSyntax,{node:s.type})}function pe(s,e,t){switch(s.toLowerCase().trim()){case"abs":if(e.length!==1)throw new g(p.InvalidFunctionParameters,{function:"abs"});return"abs("+e[0]+")";case"ceiling":case"ceil":if(e.length!==1)throw new g(p.InvalidFunctionParameters,{function:"ceiling"});switch(t){case d.Standardised:case d.StandardisedNoInterval:}return"CEILING("+e[0]+")";case"floor":if(e.length!==1)throw new g(p.InvalidFunctionParameters,{function:"floor"});return"FLOOR("+e[0]+")";case"log":if(e.length!==1)throw new g(p.InvalidFunctionParameters,{function:"log"});return"LOG("+e[0]+")";case"log10":if(e.length!==1)throw new g(p.InvalidFunctionParameters,{function:"log10"});return"LOG10("+e[0]+")";case"power":if(e.length!==2)throw new g(p.InvalidFunctionParameters,{function:"power"});return"POWER("+e[0]+","+e[1]+")";case"round":if(e.length===2)return"ROUND("+e[0]+","+e[1]+")";if(e.length===1)return"ROUND("+e[0]+")";throw new g(p.InvalidFunctionParameters,{function:"round"});case"truncate":if(e.length<1||e.length>2)throw new g(p.InvalidFunctionParameters,{function:"truncate"});return t===d.SqlServer?"ROUND("+e[0]+(e.length===1?"0":","+e[1])+",1)":"TRUNCATE("+e[0]+(e.length===1?")":","+e[1]+")");case"char_length":case"len":if(e.length!==1)throw new g(p.InvalidFunctionParameters,{function:"char_length"});switch(t){case d.SqlServer:return"LEN("+e[0]+")";case d.Oracle:return"LENGTH("+e[0]+")";default:return"CHAR_LENGTH("+e[0]+")"}case"concat":if(e.length<1)throw new g(p.InvalidFunctionParameters,{function:"concat"});{let n="CONCAT(";for(let r=0;r":case"<":case">":case">=":case"<=":case"=":return"boolean";case"IS":case"ISNOT":if(e.right.type!=="null")throw new g(p.UnsupportedIsRhs);return"boolean";case"*":case"-":case"+":case"/":return P([y(s,e.left,t,n),y(s,e.right,t,n)]);default:throw new g(p.UnsupportedOperator,{operator:e.operator})}case"null":return"";case"boolean":return"boolean";case"string":return"string";case"number":return e.value===null?"":e.value%1==0?"integer":"double";case"date":case"timestamp":case"current-time":return"date";case"column-reference":{const a=s[e.column.toLowerCase()];return a===void 0?"":a}case"function":switch(e.name.toLowerCase()){case"position":case"extract":case"char_length":return"integer";case"round":return r=y(s,e.args,t,n),r instanceof Array?r.length>0?r[0]:"":r;case"sign":return r=y(s,e.args,t,n),r instanceof Array&&(r=P(r)),r==="integer"||r==="double"?r:"double";case"ceiling":case"floor":case"abs":{const a=y(s,e.args,t,n);return a instanceof Array?P(a):a}case"area":case"length":case"log":case"log10":case"sin":case"cos":case"tan":case"asin":case"acos":case"atan":case"power":case"truncate":return"double";case"substring":case"trim":case"concat":case"lower":case"upper":return"string"}return""}throw new g(p.UnsupportedSyntax,{node:e.type})}const $={boolean:1,string:2,integer:3,double:4,date:5};function P(s){if(s){let e="";for(const t of s)t!==""&&(e=e===""||$[e]<$[t]?t:e);return e}return""}function Ce(s,e){return S(s.parseTree,e)}function ge(s){return(s==null?void 0:s.parseTree.type)==="column-reference"}function S(s,e){if(s==null)return!1;switch(s.type){case"when-clause":return S(s.operand,e)||S(s.value,e);case"case-expression":for(const t of s.clauses)if(S(t,e))return!0;return!(s.format!=="simple"||!S(s.operand,e))||!(s.else===null||!S(s.else,e));case"parameter":case"null":case"boolean":case"date":case"timestamp":case"string":case"number":return!1;case"expression-list":for(const t of s.value)if(S(t,e))return!0;return!1;case"unary-expression":return S(s.expr,e);case"binary-expression":return S(s.left,e)||S(s.right,e);case"column-reference":return e.toLowerCase()===s.column.toLowerCase();case"function":return S(s.args,e)}return!1}function A(s){let e="";return e+=s.period.toUpperCase(),e}function me(s,e,t){let n="";return n=e.type==="interval-period"?A(e):A(e.start)+" TO "+A(e.end),"INTERVAL "+t+" "+s+" "+n}function ye(s){return s=+s,isFinite(s)?s-s%1||(s<0?-0:s===0?s:0):s}function D(s){let e=0;for(let t=0;t=e&&e!==-1)return t}return t}function Ue(s){switch(s.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function Oe(s,e,t=1e3){switch(s.toLowerCase()){case"distinct":return Se(e,t);case"avg":case"mean":return D(e);case"min":return Math.min.apply(Math,e);case"sum":return K(e);case"max":return Math.max.apply(Math,e);case"stdev":case"stddev":return Math.sqrt(B(e));case"var":case"variance":return B(e);case"count":return e.length}return 0}async function we(s,e,t){const n=await E(s,e,t,!0);return n.length===0?null:Math.min.apply(Math,n)}async function Ie(s,e,t){const n=await E(s,e,t,!0);return n.length===0?null:Math.max.apply(Math,n)}async function Fe(s,e,t){let n="";e&&!ge(e)&&(n=fe(e,s.fields));const r=await E(s,e,t,!0);if(r.length===0)return null;const a=D(r);return a===null?a:n==="integer"?ye(a):a}async function Te(s,e,t){const n=await E(s,e,t,!0);return n.length===0?null:Q(n)}async function be(s,e,t){const n=await E(s,e,t,!0);return n.length===0?null:Math.sqrt(Q(n))}async function ve(s,e,t){const n=await E(s,e,t,!0);return n.length===0?null:K(n)}async function Re(s,e){return s.iterator(e).count()}async function E(s,e,t,n=!1){const r=s.iterator(t),a=[],i={ticker:0};let l=await r.next();for(;l!==null;){if(i.ticker++,t.aborted)throw new m(f.Cancelled);i.ticker%100==0&&(i.ticker=0,await new Promise(o=>{setTimeout(o,0)}));const u=e==null?void 0:e.calculateValue(l);u===null?n===!1&&(a[a.length]=u):a[a.length]=u,l=await r.next()}return a}async function Ee(s,e,t=1e3,n=null){const r=s.iterator(n),a=[],i={},l={ticker:0};let u=await r.next();for(;u!==null;){if(l.ticker++,n&&n.aborted)throw new m(f.Cancelled);l.ticker%100==0&&(l.ticker=0,await new Promise(_=>{setTimeout(_,0)}));const o=e==null?void 0:e.calculateValue(u);if(o!=null&&i[o]===void 0&&(a.push(o),i[o]=1),a.length>=t&&t!==-1)return a;u=await r.next()}return a}class h{constructor(e){this.recentlyUsedQueries=null,this.featureSetQueryInterceptor=null,this._idstates=[],this._parent=null,this._wset=null,this._mainSetInUse=null,this._maxProcessing=200,this._maxQuery=500,this._totalCount=-1,this._databaseType=d.NotEvaluated,this._databaseTypeProbed=null,this.declaredRootClass="esri.arcade.featureset.support.FeatureSet",this._featureCache=[],this.typeIdField=null,this.types=null,this.fields=null,this.geometryType="",this.objectIdField="",this.globalIdField="",this.spatialReference=null,this.hasM=!1,this.hasZ=!1,this._transparent=!1,this.loaded=!1,this._loadPromise=null,this._fieldsIndex=null,e&&e.lrucache&&(this.recentlyUsedQueries=e.lrucache),e&&e.interceptor&&(this.featureSetQueryInterceptor=e.interceptor)}optimisePagingFeatureQueries(e){this._parent&&this._parent.optimisePagingFeatureQueries(e)}_hasMemorySource(){return!0}prop(e,t){return t===void 0?this[e]:(this[e]!==void 0&&(this[e]=t),this)}end(){return this._parent!==null&&this._parent._transparent===!0?this._parent.end():this._parent}_ensureLoaded(){return this.load()}load(){return this._loadPromise===null&&(this._loadPromise=this.loadImpl()),this._loadPromise}async loadImpl(){var e,t;return((e=this._parent)==null?void 0:e.loaded)===!0?(this._initialiseFeatureSet(),this):(await((t=this._parent)==null?void 0:t.load()),this._initialiseFeatureSet(),this)}_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 Z({wkid:4326}),this.geometryType=j.point)}getField(e,t){let n;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some(r=>(r&&r.name.toLowerCase()===e&&(n=r),!!n))),n}getFieldsIndex(){return this._fieldsIndex===null&&(this._fieldsIndex=new X(this.fields)),this._fieldsIndex}_maxProcessingRate(){return this._parent!==null?Math.min(this._maxProcessing,this._parent._maxProcessingRate()):Math.min(this._maxProcessing,this._maxQueryRate())}_maxQueryRate(){return this._parent!==null?Math.max(this._maxQuery,this._parent._maxQueryRate()):this._maxQuery}_checkCancelled(e){if(e!=null&&e.aborted)throw new m(f.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,n,r,a){return this._parent!==null&&this._parent._canDoAggregates(e,t,n,r,a)}async _getAggregatePagesDataSourceDefinition(e,t,n,r,a,i,l){if(this._parent===null)throw new m(f.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,t,n,r,a,i,l)}async _getAgregagtePhysicalPage(e,t,n){if(this._parent===null)throw new m(f.NeverReach);return this._parent._getAgregagtePhysicalPage(e,t,n)}async databaseType(){if(this._databaseType===d.NotEvaluated){if(R.applicationCache!==null){const e=R.applicationCache.getDatabaseType(this._cacheableFeatureSetSourceKey());if(e!==null)return e}if(this._databaseTypeProbed!==null)return this._databaseTypeProbed;try{this._databaseTypeProbed=this._getDatabaseTypeImpl(),R.applicationCache!==null&&R.applicationCache.setDatabaseType(this._cacheableFeatureSetSourceKey(),this._databaseTypeProbed)}catch(e){throw R.applicationCache!==null&&R.applicationCache.clearDatabaseType(this._cacheableFeatureSetSourceKey()),e}return this._databaseTypeProbed}return this._databaseType}async _getDatabaseTypeImpl(){const e=[{thetype:d.SqlServer,testwhere:"(CAST( '2015-01-01' as DATETIME) = CAST( '2015-01-01' as DATETIME)) AND OBJECTID<0"},{thetype:d.Oracle,testwhere:"(TO_DATE('2003-11-18','YYYY-MM-DD') = TO_DATE('2003-11-18','YYYY-MM-DD')) AND OBJECTID<0"},{thetype:d.StandardisedNoInterval,testwhere:"(date '2015-01-01 10:10:10' = date '2015-01-01 10:10:10') AND OBJECTID<0"}];for(const t of e)if(await this._runDatabaseProbe(t.testwhere)===!0)return t.thetype;return d.StandardisedNoInterval}_cacheableFeatureSetSourceKey(){return"MUSTBESET"}async _runDatabaseProbe(e){if(this._parent!==null)return this._parent._runDatabaseProbe(e);throw new m(f.NotImplemented)}isTable(){var e,t;return(t=(e=this._parent)==null?void 0:e.isTable())!=null?t:!1}_featureFromCache(e){if(this._featureCache[e]!==void 0)return this._featureCache[e]}_isInFeatureSet(e){return T.Unknown}_getSet(e){throw new m(f.NotImplemented)}async _getFeature(e,t,n){if(this._checkCancelled(n),this._featureFromCache(t)!==void 0)return this._featureFromCache(t);if(await this._getFeatures(e,t,this._maxProcessingRate(),n),this._checkCancelled(n),this._featureFromCache(t)!==void 0)return this._featureFromCache(t);throw new m(f.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const n=new v([],e,!1,null),r=[];await this._getFeatures(n,-1,e.length,t),this._checkCancelled(t);for(const a of e)this._featureFromCache(a)!==void 0&&r.push(this._featureFromCache(a));return r}async _getFeatures(e,t,n,r){return"success"}_getFilteredSet(e,t,n,r,a){throw new m(f.NotImplemented)}async _refineSetBlock(e,t,n){if(this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate())===!0)return await this._expandPagedSet(e,this._maxQueryRate(),0,0,n),this._refineSetBlock(e,t,n);this._checkCancelled(n);const r=e._candidates.length;this._refineKnowns(e,t);let a=r-e._candidates.length;if(e._candidates.length===0||a>=t)return e;if(await this._refineIfParentKnown(e,t-a,n),this._checkCancelled(n),this._refineKnowns(e,t-a),a=r-e._candidates.length,a0){const i=t-a,l=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(l,l.length>i?i:e._candidates.length,n),this._checkCancelled(n),this._refineKnowns(e,t-a),e}return e}_fetchAndRefineFeatures(e,t,n){return null}_prepareFetchAndRefineSet(e){const t=[];for(let n=0;n=t)break}r!==null&&a.push(r);for(let i=a.length-1;i>=0;i--)e._candidates.splice(a[i].start,a[i].end-a[i].start+1)}_refineIfParentKnown(e,t,n){const r=new v([],[],e._ordered,null);return r._candidates=e._candidates.slice(0),this._parent._refineSetBlock(r,t,n)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(e.pagesDefinition===null)return!1;let n=0;for(let r=e._lastFetchedIndex;r=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(e.pagesDefinition===null)return!1;let n=0;for(let r=0;r=t)break}return!1}async _expandPagedSet(e,t,n,r,a){if(this._parent===null)throw new m(f.NotImplemented);return this._parent._expandPagedSet(e,t,n,r,a)}async _expandPagedSetFeatureSet(e,t,n,r,a){if(e._known.length>0&&e._known[e._known.length-1]==="GETPAGES"&&(r=1),r===0&&e._candidates.length>0&&e._candidates[e._candidates.length-1]==="GETPAGES"&&(r=2),r===0)return"finished";const i=await this._getPage(e,r,a);return n+ie.pagesDefinition.resultOffset||e.pagesDefinition.internal.fullyResolved===!0){r.length=r.length-1;let a=0;for(let l=0;l=e.pagesDefinition.internal.set.length);l++)r[r.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+l],a++;e.pagesDefinition.resultOffset+=a;let i=!1;return e.pagesDefinition.internal.fullyResolved===!0&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(i=!0),i===!1&&r.push("GETPAGES"),a}return await this._getPhysicalPage(e,t,n),this._getPage(e,t,n)}_getPhysicalPage(e,t,n){return null}_clonePageDefinition(e){return this._parent===null?null:this._parent._clonePageDefinition(e)}_first(e){return this.iterator(e).next()}first(e){return this._first(e)}async calculateStatistic(e,t,n,r){await this._ensureLoaded();let a=await this._stat(e,t,"",null,null,n,r);return a.calculated===!1&&(a=await this._manualStat(e,t,n,r)),a.result}async _manualStat(e,t,n,r){let a=null;switch(e.toLowerCase()){case"count":return a=await Re(this,r),{calculated:!0,result:a};case"distinct":return a=await Ee(this,t,n,r),{calculated:!0,result:a};case"avg":case"mean":return a=await Fe(this,t,r),{calculated:!0,result:a};case"stdev":return a=await be(this,t,r),{calculated:!0,result:a};case"variance":return a=await Te(this,t,r),{calculated:!0,result:a};case"sum":return a=await ve(this,t,r),{calculated:!0,result:a};case"min":return a=await we(this,t,r),{calculated:!0,result:a};case"max":return a=await Ie(this,t,r),{calculated:!0,result:a};default:return{calculated:!0,result:0}}}async _stat(e,t,n,r,a,i,l){const u=await this._parent._stat(e,t,n,r,a,i,l);return u.calculated===!1?a===null&&n===""&&r===null?this._manualStat(e,t,i,l):{calculated:!1}:u}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),n=[];return new Promise((r,a)=>{this._unionShapeInBatches(n,t,r,a)})}_unionAllGeom(e){return new Promise((t,n)=>{const r=this.iterator(this._defaultTracker(e)),a=[];this._unionShapeInBatches(a,r,t,n)})}_unionShapeInBatches(e,t,n,r){t.next().then(a=>{try{a!==null&&a.geometry!==null&&e.push(a.geometry),e.length>30||a===null&&e.length>1?z(e).then(i=>{try{a===null?n(i):(e=[i],this._unionShapeInBatches(e,t,n,r))}catch(l){r(l)}},r):a===null?e.length===1?n(e[0]):n(null):this._unionShapeInBatches(e,t,n,r)}catch(i){r(i)}},r)}iterator(e){return new de(this,e)}intersection(e,t=!1){return h._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,n=!0){return h._featuresetFunctions.difference.bind(this)(e,t,n)}symmetricDifference(e,t=!1,n=!0){return h._featuresetFunctions.symmetricDifference.bind(this)(e,t,n)}morphShape(e,t,n="unknown",r=null){return h._featuresetFunctions.morphShape.bind(this)(e,t,n,r)}morphShapeAndAttributes(e,t,n="unknown"){return h._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,n)}union(e,t=!1){return h._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return h._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return h._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return h._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return h._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return h._featuresetFunctions.relate.bind(this)(e,t)}within(e){return h._featuresetFunctions.within.bind(this)(e)}touches(e){return h._featuresetFunctions.touches.bind(this)(e)}top(e){return h._featuresetFunctions.top.bind(this)(e)}crosses(e){return h._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,n,r=!0){return h._featuresetFunctions.buffer.bind(this)(e,t,n,r)}filter(e,t=null){return h._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return h._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return h._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return h._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,n){return new Promise((r,a)=>{this._reduceImpl(this.iterator(this._defaultTracker(n)),e,t,0,r,a,0)})}_reduceImpl(e,t,n,r,a,i,l){try{if(++l>1e3)return void setTimeout(()=>{l=0,this._reduceImpl(e,t,n,r,a,i,l)});e.next().then(u=>{try{if(u===null)a(n);else{const o=t(n,u,r,this);O(o)?o.then(_=>{this._reduceImpl(e,t,_,r+1,a,i,l)},i):this._reduceImpl(e,t,o,r+1,a,i,l)}}catch(o){i(o)}},i)}catch(u){i(u)}}removeField(e){return h._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,n=null){return h._featuresetFunctions.addField.bind(this)(e,t,n)}sumArea(e,t=!1,n){const r=V(e);return this.reduce((a,i)=>i.geometry===null?0:t?ee(i.geometry,r).then(l=>a+l):te(i.geometry,r).then(l=>a+l),0,n)}sumLength(e,t=!1,n){const r=W(e);return this.reduce((a,i)=>i.geometry===null?0:t?ne(i.geometry,r).then(l=>a+l):re(i.geometry,r).then(l=>a+l),0,n)}_substituteVars(e,t){if(t!==null){const n={};for(const r in t)n[r.toLowerCase()]=t[r];e.parameters=n}}async distinct(e,t=1e3,n=null,r){await this.load();const a=I.create(e,this.getFieldsIndex());return this._substituteVars(a,n),this.calculateStatistic("distinct",a,t,this._defaultTracker(r))}async min(e,t=null,n){await this.load();const r=I.create(e,this.getFieldsIndex());return this._substituteVars(r,t),this.calculateStatistic("min",r,-1,this._defaultTracker(n))}async max(e,t=null,n){await this.load();const r=I.create(e,this.getFieldsIndex());return this._substituteVars(r,t),this.calculateStatistic("max",r,-1,this._defaultTracker(n))}async avg(e,t=null,n){await this.load();const r=I.create(e,this.getFieldsIndex());return this._substituteVars(r,t),this.calculateStatistic("avg",r,-1,this._defaultTracker(n))}async sum(e,t=null,n){await this.load();const r=I.create(e,this.getFieldsIndex());return this._substituteVars(r,t),this.calculateStatistic("sum",r,-1,this._defaultTracker(n))}async stdev(e,t=null,n){await this.load();const r=I.create(e,this.getFieldsIndex());return this._substituteVars(r,t),this.calculateStatistic("stdev",r,-1,this._defaultTracker(n))}async variance(e,t=null,n){await this.load();const r=I.create(e,this.getFieldsIndex());return this._substituteVars(r,t),this.calculateStatistic("variance",r,-1,this._defaultTracker(n))}async count(e){return await this.load(),this.calculateStatistic("count",I.create("1",this.getFieldsIndex()),-1,this._defaultTracker(e))}_defaultTracker(e){return e||{aborted:!1}}forEach(e,t){return new Promise((n,r)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,n,r,0)})}_forEachImpl(e,t,n,r,a,i){try{if(++i>1e3)return void setTimeout(()=>{i=0,this._forEachImpl(e,t,n,r,a,i)},0);e.next().then(l=>{try{if(l===null)r(n);else{const u=t(l);u==null?this._forEachImpl(e,t,n,r,a,i):O(u)?u.then(()=>{try{this._forEachImpl(e,t,n,r,a,i)}catch(o){a(o)}},a):this._forEachImpl(e,t,n,r,a,i)}}catch(u){a(u)}},a)}catch(l){a(l)}}convertToJSON(e){const t={layerDefinition:{geometryType:this.geometryType,fields:[]},featureSet:{features:[],geometryType:this.geometryType}};for(let n=0;n{const a={geometry:r.geometry&&r.geometry.toJSON(),attributes:{}};for(const i in r.attributes)a.attributes[i]=r.attributes[i];return t.featureSet.features.push(a),1},0,e).then(()=>t)}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,n,r,a){return this._parent.queryAttachments(e,t,n,r,a)}serviceUrl(){return this._parent.serviceUrl()}subtypes(){return this.typeIdField?{subtypeField:this.typeIdField,subtypes:this.types?this.types.map(e=>({name:e.name,code:e.id})):[]}:null}relationshipMetaData(){return this._parent.relationshipMetaData()}get gdbVersion(){return this._parent?this._parent.gdbVersion:""}schema(){const e=[];for(const t of this.fields)e.push(L(t));return{objectIdField:this.objectIdField,globalIdField:this.globalIdField,geometryType:C[this.geometryType]===void 0?"":C[this.geometryType],fields:e}}async convertToText(e,t){if(e==="schema")return await this._ensureLoaded(),JSON.stringify(this.schema());if(e==="featureset"){await this._ensureLoaded();const n=[];await this.reduce((a,i)=>{const l={geometry:i.geometry?i.geometry.toJSON():null,attributes:i.attributes};return l.geometry!==null&&l.geometry.spatialReference&&delete l.geometry.spatialReference,n.push(l),1},0,t);const r=this.schema();return r.features=n,r.spatialReference=this.spatialReference.toJSON(),JSON.stringify(r)}return this.castToText()}getFeatureByObjectId(e,t){return this._parent.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._parent.getOwningSystemUrl()}getIdentityUser(){return this._parent.getIdentityUser()}getRootFeatureSet(){return this._parent!==null?this._parent.getRootFeatureSet():this}getDataSourceFeatureSet(){return this._parent!==null?this._parent.getDataSourceFeatureSet():this}castAsJson(e=null){return(e==null?void 0:e.featureset)==="keeptype"?this:(e==null?void 0:e.featureset)==="none"?null:{type:"FeatureSet"}}async castAsJsonAsync(e=null,t=null){var a;if((t==null?void 0:t.featureset)==="keeptype")return this;if((t==null?void 0:t.featureset)==="schema")return await this._ensureLoaded(),JSON.parse(JSON.stringify(this.schema()));if((t==null?void 0:t.featureset)==="none")return null;await this._ensureLoaded();const n=[];await this.reduce((i,l)=>{const u={geometry:l.geometry?(t==null?void 0:t.keepGeometryType)===!0?l.geometry:l.geometry.toJSON():null,attributes:l.attributes};return u.geometry!==null&&u.geometry.spatialReference&&(t==null?void 0:t.keepGeometryType)!==!0&&delete u.geometry.spatialReference,n.push(u),1},0,e);const r=this.schema();return r.features=n,r.spatialReference=(t==null?void 0:t.keepGeometryType)===!0?this.spatialReference:(a=this.spatialReference)==null?void 0:a.toJSON(),r}}h._featuresetFunctions={};class b extends h{constructor(e){super(e),this.declaredClass="esri.layers.featureset.sources.Empty",this._maxProcessing=1e3,this._wset=new v([],[],!1,null),this._parent=e.parentfeatureset,this._databaseType=d.Standardised}async _getSet(){return this._wset}optimisePagingFeatureQueries(){}_isInFeatureSet(){return T.NotInFeatureSet}async _getFeature(){throw new m(f.NeverReach)}async queryAttachments(){return[]}async _getFeatures(){return"success"}_featureFromCache(){return null}async _fetchAndRefineFeatures(){throw new m(f.NeverReach)}async _getFilteredSet(){return new v([],[],!1,null)}_stat(e,t,n,r,a,i,l){return this._manualStat(e,t,i,l)}async _canDoAggregates(){return!1}}class F extends h{constructor(e){super(e),this._relation="",this._relationGeom=null,this._relationString="",this.declaredClass="esri.arcade.featureset.actions.SpatialFilter",this._relationString=e.relationString,this._parent=e.parentfeatureset,this._maxProcessing=40,this._relation=e.relation,this._relationGeom=e.relationGeom}async _getSet(e){if(this._wset===null){await this._ensureLoaded();const t=await this._parent._getFilteredSet(this._relation!=="esriSpatialRelRelation"?this._relation:this._relation+":"+this._relationString,this._relationGeom,null,null,e);return this._checkCancelled(e),this._wset=new v(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){let t=this._parent._isInFeatureSet(e);return t===T.NotInFeatureSet?t:(t=this._idstates[e],t===void 0?T.Unknown:t)}_getFeature(e,t,n){return this._parent._getFeature(e,t,n)}_getFeatures(e,t,n,r){return this._parent._getFeatures(e,t,n,r)}_featureFromCache(e){return this._parent._featureFromCache(e)}async executeSpatialRelationTest(e){var t;if(e.geometry===null)return!1;switch(this._relation){case"esriSpatialRelEnvelopeIntersects":{const n=U(this._relationGeom),r=U(e.geometry);return G(n,r)}case"esriSpatialRelIntersects":return G(this._relationGeom,e.geometry);case"esriSpatialRelContains":return oe(this._relationGeom,e.geometry);case"esriSpatialRelOverlaps":return ue(this._relationGeom,e.geometry);case"esriSpatialRelWithin":return le(this._relationGeom,e.geometry);case"esriSpatialRelTouches":return ie(this._relationGeom,e.geometry);case"esriSpatialRelCrosses":return ae(this._relationGeom,e.geometry);case"esriSpatialRelRelation":return se(this._relationGeom,e.geometry,(t=this._relationString)!=null?t:"")}}async _fetchAndRefineFeatures(e,t,n){var l;const r=new v([],e,!1,null),a=Math.min(t,e.length);await((l=this._parent)==null?void 0:l._getFeatures(r,-1,a,n)),this._checkCancelled(n);const i=[];for(let u=0;u