@arcgis/core 4.31.0-next.20240802 → 4.31.0-next.20240805
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/arcade/arcadeAsyncRuntime.js +1 -1
- package/arcade/arcadeCompiler.js +1 -1
- package/arcade/arcadeRuntime.js +1 -1
- package/arcade/featureSetUtils.js +1 -1
- package/arcade/featureset/actions/GroupBy.js +1 -1
- package/arcade/featureset/actions/OrderBy.js +1 -1
- package/arcade/functions/date.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/arcade/functions/featuresetgeom.js +1 -1
- package/arcade/functions/featuresetstats.js +1 -1
- package/arcade/functions/featuresetstring.js +1 -1
- package/arcade/functions/fieldStats.js +1 -1
- package/arcade/functions/geomasync.js +1 -1
- package/arcade/functions/geometry.js +1 -1
- package/arcade/functions/geomsync.js +1 -1
- package/arcade/functions/knowledgegraph.js +1 -1
- package/arcade/functions/maths.js +1 -1
- package/arcade/functions/stats.js +1 -1
- package/arcade/functions/string.js +1 -1
- package/arcade/languageUtils.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{b35ffe8e008d50c28269.js → 005c6f16812a926f189a.js} +1 -1
- package/assets/esri/core/workers/chunks/{8e643c941f3bfc8631ec.js → 22d13dc4696a16d1cad4.js} +1 -1
- package/assets/esri/core/workers/chunks/{902171c043e69d34d0a8.js → 2deb6f87caf8e4a67e2a.js} +1 -1
- package/assets/esri/core/workers/chunks/{36bef254edb4590fcab7.js → 33e890709c79708deeae.js} +1 -1
- package/assets/esri/core/workers/chunks/4801e6139b4b25909241.js +1 -0
- package/assets/esri/core/workers/chunks/4c280b36b95909cac555.js +1 -0
- package/assets/esri/core/workers/chunks/{a467a03cf97b02fc9487.js → 5e7729ba5fe536e7354b.js} +1 -1
- package/assets/esri/core/workers/chunks/680409b4c95a4a5eeb1b.js +1 -0
- package/assets/esri/core/workers/chunks/74b7775a83bf712ef4eb.js +1 -0
- package/assets/esri/core/workers/chunks/{0ad8e7b6cf36cbe6928a.js → 7a80d9d15b3c68790ddc.js} +1 -1
- package/assets/esri/core/workers/chunks/{1f6fcca67e69e25432e0.js → 903cb5960241ff716587.js} +1 -1
- package/assets/esri/core/workers/chunks/{037ebfa531b31f75133d.js → 9917c4ec97e36b9afdfa.js} +1 -1
- package/assets/esri/core/workers/chunks/{ce130ddf9eeafbd39a47.js → be0dc79b1ba23042f01d.js} +1 -1
- package/assets/esri/core/workers/chunks/{fd74973e45c54f6213cf.js → d025310e8e1e6c347323.js} +1 -1
- package/assets/esri/core/workers/chunks/e055f40564084684dd5e.js +1 -0
- package/assets/esri/core/workers/chunks/{8cd038cc8f9a35d265da.js → e9794bd46323a38f59c9.js} +1 -1
- package/assets/esri/core/workers/chunks/{8c0cf61373f9f2532da4.js → e9f69f3aa2621a60ef3f.js} +1 -1
- package/assets/esri/core/workers/chunks/{9cae4d1c24b0b164d1e9.js → f6fcfe739e5c8cc44e1d.js} +1 -1
- package/assets/esri/geometry/support/pe-wasm.wasm +0 -0
- package/chunks/array.js +1 -1
- package/chunks/languageUtils.js +1 -1
- package/chunks/pe-wasm.js +1 -1
- package/chunks/pe.js +1 -1
- package/geometry/pe.js +1 -1
- package/layers/support/rasterFunctionUtils.js +1 -1
- package/layers/support/rasterFunctions/ColormapToRGBFunction.js +5 -0
- package/layers/support/rasterFunctions/ColormapToRGBFunctionArguments.js +5 -0
- package/layers/support/rasterFunctions/creators/createDataManagementFunctions.js +1 -1
- package/layers/support/rasterFunctions/rasterFunctionHelper.js +1 -1
- package/package.json +1 -1
- package/smartMapping/renderers/size.js +1 -1
- package/support/revision.js +1 -1
- package/views/2d/engine/imagery/processor/colormapToRGBProcessor.js +5 -0
- package/views/2d/engine/imagery/processor/rasterProcessor.js +1 -1
- package/views/2d/engine/imagery/processor/utils.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/assets/esri/core/workers/chunks/2f5cc8fabb004beff962.js +0 -1
- package/assets/esri/core/workers/chunks/4d6ca297666d1d7d1f6d.js +0 -1
- package/assets/esri/core/workers/chunks/6d1d2c624d9cd2338d8d.js +0 -1
- package/assets/esri/core/workers/chunks/faba3dc5c317b554963f.js +0 -1
- package/assets/esri/core/workers/chunks/fba58487dbd184f3da52.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as n,geometryMember as r}from"./containerUtils.js";import o from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i,ensureArcadeExecutionError as l}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as c,ArcadeFunction as u,ScopeMarshalledFunction as f,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{H as w,a as d,F as h,D as m,B as g,C as y,i as v,c as b,z as S,o as x,q as I,r as F,u as C,b as R,g as A,A as M,j,E as L,G as k,x as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as O}from"../chunks/array.js";import{registerFunctions as B}from"./functions/date.js";import{registerFunctions as P}from"./functions/geomasync.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as G}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import Z from"../geometry/Geometry.js";import q from"../geometry/SpatialReference.js";const T=100;async function W(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await Y(e,t.arguments[r]));return n}async function V(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}class _ extends u{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new a(e,i.MaximumCallDepth,null);return Pe(this.definition,n,t,null)}}call(e,t){return H(e,t,((n,r,o)=>{const l={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(l.depthCounter.depth>64)throw new a(e,i.MaximumCallDepth,t);return Pe(this.definition,l,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!v(t)||t instanceof f?t:p(t,e,r))),p(await Pe(this.definition,l,i,t),n,r)}))}}class z extends e{constructor(e){super(e)}async global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=await Y(this.executingContext,t.node),t.valueset=!0),v(t.value)&&!(t.value instanceof f)){const e=new f;e.fn=t.value,e.parameterEvaluator=H,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(v(t))throw new a(null,i.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}async loadModule(e){let n=e.spatialReference;null==n&&(n=new q({wkid:102100})),this.moduleScope=Ge({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ue,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await Y(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}async function Y(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,Y(e,t,!0)}try{switch(t?.type){case"VariableDeclarator":return await xe(e,t);case"ImportDeclaration":return await ve(e,t);case"ExportNamedDeclaration":return await be(e,t);case"VariableDeclaration":return await Se(e,t,0);case"BlockStatement":case"Program":return await he(e,t);case"FunctionDeclaration":return await ye(e,t);case"ReturnStatement":return await ge(e,t);case"IfStatement":return await de(e,t);case"ExpressionStatement":return await we(e,t);case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await pe(e,t);case"ForStatement":return await ne(e,t);case"WhileStatement":return await X(e,t);case"ForInStatement":return await ce(e,t);case"BreakStatement":return y;case"EmptyStatement":return g;case"ContinueStatement":return m;case"TemplateElement":return await Le(e,t);case"TemplateLiteral":return await Ee(e,t);case"Identifier":return await Me(e,t);case"MemberExpression":return await Ie(e,t);case"Literal":return t.value;case"CallExpression":return await je(e,t);case"UnaryExpression":return await Fe(e,t);case"BinaryExpression":return await Re(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Ce(e,t);case"ObjectExpression":return await J(e,t);case"Property":return await Q(e,t);default:throw new a(e,i.Unrecognized,t)}}catch(r){throw l(e,t,r)}}async function J(e,t){const n=[];for(let o=0;o<t.properties.length;o++)n[o]=await Y(e,t.properties[o]);const r={},l=new Map;for(let o=0;o<n.length;o++){const s=n[o];if(v(s.value))throw new a(e,i.NoFunctionInDictionary,t);if(!1===b(s.key))throw new a(e,i.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();l.has(u)?c=l.get(u):l.set(u,c),s.value===g?r[c]=null:r[c]=s.value}const s=new o(r);return s.immutable=!1,s}async function Q(e,t){const n=await Y(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await Y(e,t.key),value:n}}async function X(e,t){const n={testResult:!0,lastAction:g};if(n.testResult=await Y(e,t.test),!1===n.testResult)return g;if(!0!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await Y(e,t.body),n.lastAction!==y)&&!(n.lastAction instanceof S);)if(n.testResult=await Y(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);return n.lastAction instanceof S?n.lastAction:g}async function $(e,t,n){const r=await Y(e,t.body);return n.lastAction=r,n.lastAction===y||n.lastAction instanceof S?(n.testResult=!1,n):null!==t.update?(await Y(e,t.update),n):n}async function ee(e,t,n){if(null!==t.test){const r=await Y(e,t.test);if(!0===e.abortSignal?.aborted)throw new a(e,i.Cancelled,t);if(n.testResult=r,!1===n.testResult)return n;if(!0!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);return $(e,t,n)}return $(e,t,n)}function te(e,t,n,r,o,a){try{ee(e,t,n).then((()=>{try{!0===n.testResult?++a>T?(a=0,setTimeout((()=>{te(e,t,n,r,o,a)}),0)):te(e,t,n,r,o,a):n.lastAction instanceof S?r(n.lastAction):r(g)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ne(e,t){try{return null!==t.init?Y(e,t.init).then((()=>new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:g},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:g},(e=>{n(e)}),(e=>{r(e)}),0)}))}catch(n){return Promise.reject(n)}}function re(e,t,n,r,o,a,i,l,s,c){try{if(r<=a)return void l(g);o.value="k"===i?n[a]:a,Y(e,t.body).then((u=>{try{u instanceof S?l(u):u===y?l(g):++c>T?(c=0,setTimeout((()=>{re(e,t,n,r,o,a+1,i,l,s,c)}),0)):re(e,t,n,r,o,a+1,i,l,s,c)}catch(f){s(f)}}),(e=>{s(e)}))}catch(u){s(u)}}function oe(e,t,n,r,o,a,i,l,s){try{if(n.length()<=o)return void i(g);r.value="k"===a?n.get(o):o,Y(e,t.body).then((c=>{c instanceof S?i(c):c===y?i(g):++s>T?(s=0,setTimeout((()=>{oe(e,t,n,r,o+1,a,i,l,s)}),0)):oe(e,t,n,r,o+1,a,i,l,s)}),(e=>{l(e)}))}catch(c){l(c)}}function ae(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(g);re(e,t,n,n.length,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ie(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(g);oe(e,t,n,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function le(e,t,n,r,o){try{ae(e,t,n.keys(),r,o,"k")}catch(a){r.reject(a)}}function se(e,t,n,r,o,a,i,l){try{e.next().then((c=>{try{if(null===c)a(g);else{const u=s.createFromGraphicLikeObject(c.geometry,c.attributes,r,t.timeZone);u._underlyingGraphic=c,o.value=u;Y(t,n.body).then((s=>{try{s===y?a(g):s instanceof S?a(s):++l>T?(l=0,setTimeout((()=>{se(e,t,n,r,o,a,i,l)}),0)):se(e,t,n,r,o,a,i,l)}catch(c){i(c)}}),(e=>{i(e)}))}}catch(u){i(u)}}),(e=>{i(e)}))}catch(c){i(c)}}async function ce(e,t){return new Promise(((n,r)=>{Y(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?Y(e,t.left):Promise.resolve(),s.then((()=>{try{let s="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(s=e.name)}else"Identifier"===t.left.type&&(s=t.left.name);if(!s)throw new a(e,i.InvalidIdentifier,t);s=s.toLowerCase();let c=null;if(null!=e.localScope&&void 0!==e.localScope[s]&&(c=e.localScope[s]),null===c&&void 0!==e.globalScope[s]&&(c=e.globalScope[s]),null===c)return void r(new a(e,i.InvalidIdentifier,t));x(l)||b(l)?ae(e,t,l,{reject:r,resolve:n},c):I(l)?ie(e,t,l,{reject:r,resolve:n},c):l instanceof o||F(l)?le(e,t,l,{reject:r,resolve:n},c):C(l)?se(l.iterator(e.abortSignal),e,t,l,c,(e=>{n(e)}),(e=>{r(e)}),0):ae(e,t,[],{reject:r,resolve:n},c)}catch(s){r(s)}}),r)}catch(s){r(s)}}),r)}))}async function ue(e,t){const n=t.argument;if("MemberExpression"===n.type){const r={t:null},l=await Y(e,n.object);let s=null;r.t=l,!0===n.computed?s=await Y(e,n.property):"Identifier"===n.property.type&&(s=n.property.name);const c=r.t;let u;if(x(c)){if(!R(s))throw new a(e,i.ArrayAccessorMustBeNumber,t);if(s<0&&(s=c.length+s),s<0||s>=c.length)throw new a(e,i.OutOfBounds,t);u=A(c[s]),c[s]="++"===t.operator?u+1:u-1}else if(c instanceof o){if(!1===b(s))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new a(e,i.FieldNotFound,t,{key:s});u=A(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}else if(c instanceof z){if(!1===b(s))throw new a(e,i.ModuleAccessorMustBeString,t);if(!0!==c.hasGlobal(s))throw new a(e,i.ModuleExportNotFound,t);u=A(await c.global(s)),c.setGlobal(s,"++"===t.operator?u+1:u-1)}else{if(!F(c))throw I(c)?new a(e,i.Immutable,t):new a(e,i.InvalidParameter,t);if(!1===b(s))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new a(e,i.FieldNotFound,t,{key:s});u=A(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}return!1===t.prefix?u:"++"===t.operator?u+1:u-1}const r="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!r)throw new a(e,i.InvalidIdentifier,t);let l;if(null!=e.localScope&&void 0!==e.localScope[r])return l=A(e.localScope[r].value),e.localScope[r]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[r])return l=A(e.globalScope[r].value),e.globalScope[r]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new a(e,i.InvalidIdentifier,t)}function fe(e,t,n,r,o){switch(t){case"=":return e===g?null:e;case"/=":return A(n)/A(e);case"*=":return A(n)*A(e);case"-=":return A(n)-A(e);case"+=":return b(n)||b(e)?j(n)+j(e):A(n)+A(e);case"%=":return A(n)%A(e);default:throw new a(o,i.UnsupportedOperator,r)}}async function pe(e,t){const n=t.left;if("MemberExpression"===n.type){const r=await Y(e,n.object);let l=null;if(!0===n.computed)l=await Y(e,n.property);else{if("Identifier"!==n.property.type)throw new a(e,i.InvalidIdentifier,t);l=n.property.name}const s=await Y(e,t.right);if(x(r)){if(!R(l))throw new a(e,i.ArrayAccessorMustBeNumber,t);if(l<0&&(l=r.length+l),l<0||l>r.length)throw new a(e,i.OutOfBounds,t);if(l===r.length){if("="!==t.operator)throw new a(e,i.OutOfBounds,t);r[l]=fe(s,t.operator,r[l],t,e)}else r[l]=fe(s,t.operator,r[l],t,e)}else if(r instanceof o){if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0===r.hasField(l))r.setField(l,fe(s,t.operator,r.field(l),t,e));else{if("="!==t.operator)throw new a(e,i.FieldNotFound,t,{key:l});r.setField(l,fe(s,t.operator,null,t,e))}}else if(r instanceof z){if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==r.hasGlobal(l))throw new a(e,i.ModuleExportNotFound,t);r.setGlobal(l,fe(s,t.operator,await r.global(l),t,e))}else{if(!F(r))throw I(r)?new a(e,i.Immutable,t):new a(e,i.InvalidParameter,t);if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0===r.hasField(l))r.setField(l,fe(s,t.operator,r.field(l),t,e));else{if("="!==t.operator)throw new a(e,i.FieldNotFound,t,{key:l});r.setField(l,fe(s,t.operator,null,t,e))}}return g}const r=n.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[r]){const n=await Y(e,t.right);return e.localScope[r]={value:fe(n,t.operator,e.localScope[r].value,t,e),valueset:!0,node:t.right},g}if(void 0!==e.globalScope[r]){const n=await Y(e,t.right);return e.globalScope[r]={value:fe(n,t.operator,e.globalScope[r].value,t,e),valueset:!0,node:t.right},g}throw new a(e,i.InvalidIdentifier,t)}async function we(e,t){if("AssignmentExpression"===t.expression.type)return Y(e,t.expression);if("CallExpression"===t.expression.type){const n=await Y(e,t.expression);return n===g?g:new M(n)}const n=await Y(e,t.expression);return n===g?g:new M(n)}async function de(e,t){const n=await Y(e,t.test);if(!0===n)return Y(e,t.consequent);if(!1===n)return null!==t.alternate?Y(e,t.alternate):g;throw new a(e,i.BooleanConditionRequired,t)}async function he(e,t){return me(e,t,0)}async function me(e,t,n){if(n>=t.body.length)return g;const r=await Y(e,t.body[n]);return r instanceof S||r===y||r===m||n===t.body.length-1?r:me(e,t,n+1)}async function ge(e,t){if(null===t.argument)return new S(g);const n=await Y(e,t.argument);return new S(n)}async function ye(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new _(t,e)},g}async function ve(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new z(r),await o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},g}async function be(e,t){if(await Y(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return g}async function Se(e,t,n){return n>=t.declarations.length?g:(await Y(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),g)}async function xe(e,t){let n=null;if(n=null===t.init?null:await Y(e,t.init),null!==e.localScope){if(n===g&&(n=null),"Identifier"!==t.id.type)throw new a(e,i.InvalidIdentifier,t);const r=t.id.name.toLowerCase();return null!=e.localScope&&(e.localScope[r]={value:n,valueset:!0,node:t.init}),g}if("Identifier"!==t.id.type)throw new a(e,i.InvalidIdentifier,t);const r=t.id.name.toLowerCase();return n===g&&(n=null),e.globalScope[r]={value:n,valueset:!0,node:t.init},g}async function Ie(e,t){const n=await Y(e,t.object);if(null===n)throw new a(e,i.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof o||F(n))return n.field(t.property.name);if(n instanceof Z)return r(n,t.property.name,e,t);if(n instanceof z){if(!n.hasGlobal(t.property.name))throw new a(e,i.InvalidIdentifier,t);return n.global(t.property.name)}throw new a(e,i.InvalidMemberAccessKey,t)}throw new a(e,i.InvalidMemberAccessKey,t)}let l=await Y(e,t.property);if(n instanceof o||F(n)){if(b(l))return n.field(l);throw new a(e,i.InvalidMemberAccessKey,t)}if(n instanceof z){if(b(l))return n.global(l);throw new a(e,i.InvalidMemberAccessKey,t)}if(n instanceof Z){if(b(l))return r(n,l,e,t);throw new a(e,i.InvalidMemberAccessKey,t)}if(x(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length+l),l>=n.length||l<0)throw new a(e,i.OutOfBounds,t);return n[l]}throw new a(e,i.InvalidMemberAccessKey,t)}if(I(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length()+l),l>=n.length()||l<0)throw new a(e,i.OutOfBounds,t);return n.get(l)}throw new a(e,i.InvalidMemberAccessKey,t)}if(b(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length+l),l>=n.length||l<0)throw new a(e,i.OutOfBounds,t);return n[l]}throw new a(e,i.InvalidMemberAccessKey,t)}throw new a(e,i.InvalidMemberAccessKey,t)}async function Fe(e,t){const n=await Y(e,t.argument);if(d(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*A(n);if("+"===t.operator)return 1*A(n);if("~"===t.operator)return~A(n);throw new a(e,i.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*A(n);if("+"===t.operator)return 1*A(n);if("~"===t.operator)return~A(n);throw new a(e,i.UnsupportedUnaryOperator,t)}async function Ce(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await Y(e,t.elements[r]));for(let r=0;r<n.length;r++){if(v(n[r]))throw new a(e,i.NoFunctionInArray,t);n[r]===g&&(n[r]=null)}return n}async function Re(e,t){const n=[];n[0]=await Y(e,t.left),n[1]=await Y(e,t.right);const r=n[0],o=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(A(r),A(o),t.operator);case"==":return h(r,o);case"!=":return!h(r,o);case"<":case">":case"<=":case">=":return L(r,o,t.operator);case"+":return b(r)||b(o)?j(r)+j(o):A(r)+A(o);case"-":return A(r)-A(o);case"*":return A(r)*A(o);case"/":return A(r)/A(o);case"%":return A(r)%A(o);default:throw new a(e,i.UnsupportedOperator,t)}}async function Ae(e,t){const n=await Y(e,t.left);let r=null;if(!d(n))throw new a(e,i.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":if(!0===n)return n;if(r=await Y(e,t.right),d(r))return r;throw new a(e,i.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(r=await Y(e,t.right),d(r))return r;throw new a(e,i.LogicExpressionOrAnd,t);default:throw new a(e,i.LogicExpressionOrAnd,t)}}async function Me(e,t){const n=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n]){const t=e.localScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}if(void 0!==e.globalScope[n]){const t=e.globalScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}throw new a(e,i.InvalidIdentifier,t)}async function je(e,t){if("MemberExpression"===t.callee.type){const n=await Y(e,t.callee.object);if(!(n instanceof z))throw new a(e,i.FunctionNotFound,t);const r=!1===t.callee.computed?t.callee.property.name:await Y(e,t.callee.property);if(!n.hasGlobal(r))throw new a(e,i.FunctionNotFound,t);const o=await n.global(r);if(!v(o))throw new a(e,i.CallNonFunction,t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new a(e,i.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(v(n.value))return n.value.call(e,t);throw new a(e,i.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(v(n.value))return n.value.call(e,t);throw new a(e,i.CallNonFunction,t)}throw new a(e,i.FunctionNotFound,t)}async function Le(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(v(e))throw new a(t,i.NoFunctionInTemplateLiteral,n);return e}async function Ee(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await Y(e,t.expressions[a]);n[a]=j(r)}let r="",o=0;for(const a of t.quasis)if(r+=a.value?a.value.cooked:"",!1===a.tail){r+=n[o]?ke(n[o],e,t):"",o++}return r}const Ne={};async function Oe(e,t,n,r){const o=await Y(e,t.arguments[n]);if(h(o,r))return Y(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?Y(e,t.arguments[n]):2===a?null:3===a?Y(e,t.arguments[n+2]):Oe(e,t,n+2,r)}async function Be(e,t,n,r){if(!0===r)return Y(e,t.arguments[n+1]);if(3===t.arguments.length-n)return Y(e,t.arguments[n+2]);const o=await Y(e,t.arguments[n+2]);if(!1===d(o))throw new a(e,i.ModuleExportNotFound,t.arguments[n+2]);return Be(e,t,n+2,o)}async function Pe(e,t,n,r){const o=e.body;if(n.length!==e.params.length)throw new a(t,i.WrongNumberOfParameters,null);for(let a=0;a<n.length;a++){const r=e.params[a];"Identifier"===r.type&&null!=t.localScope&&(t.localScope[r.name.toLowerCase()]={d:null,value:n[a],valueset:!0,node:null})}const l=await Y(t,o);if(l instanceof S)return l.value;if(l===y)throw new a(t,i.UnexpectedToken,r);if(l===m)throw new a(t,i.UnexpectedToken,r);return l instanceof M?l.value:l}B(Ne,V),U(Ne,V),D(Ne,V),K(Ne,V),G(Ne,V),P({functions:Ne,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:V,standardFunctionAsync:H}),Ne.iif=async function(e,t){w(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await Y(e,t.arguments[0]);if(!1===d(n))throw new a(e,i.BooleanConditionRequired,t);return Y(e,n?t.arguments[1]:t.arguments[2])},Ne.defaultvalue=async function(e,t){w(null===t.arguments?[]:t.arguments,2,3,e,t);const r=await Y(e,t.arguments[0]);if(3===t.arguments.length){const o=await Y(e,t.arguments[1]),a=n(r,o);return null!=a&&""!==a?a:Y(e,t.arguments[2])}return null==r||""===r?Y(e,t.arguments[1]):r},Ne.decode=async function(e,t){if(t.arguments.length<2)throw new a(e,i.WrongNumberOfParameters,t);if(2===t.arguments.length)return Y(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new a(e,i.WrongNumberOfParameters,t);return Oe(e,t,1,await Y(e,t.arguments[0]))},Ne.when=async function(e,t){if(t.arguments.length<3)throw new a(e,i.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new a(e,i.WrongNumberOfParameters,t);const n=await Y(e,t.arguments[0]);if(!1===d(n))throw new a(e,i.BooleanConditionRequired,t.arguments[0]);return Be(e,t,0,n)};const Ke={fixSpatialReference:E,parseArguments:W,standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(const We in Ne)Ne[We]={value:new c(Ne[We]),valueset:!0,node:null};const De=function(){};function Ge(e,t,n){const r=new De;null==e&&(e={}),null==t&&(t={});const a=new o({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,r.textformatting={value:a,valueset:!0,node:null};for(const o in t)r[o]={value:new c(t[o]),native:!0,valueset:!0,node:null};for(const o in e)e[o]&&"esri.Graphic"===e[o].declaredClass?r[o]={value:s.createFromGraphic(e[o],n),valueset:!0,node:null}:r[o]={value:e[o],valueset:!0,node:null};return r}function Ue(e){console.log(e)}De.prototype=Ne,De.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},De.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ze=Ke;function qe(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ne[n]={value:new c(t.functions[n]),valueset:!0,node:null},De.prototype[n]=Ne[n];for(let n=0;n<t.signatures.length;n++)N(t.signatures[n],"async")}async function Te(e,n){let r=n.spatialReference;null==r&&(r=new q({wkid:102100}));let o=null;e.usesModules&&(o=new t(new Map,e.loadedModules));const l=Ge(n.vars,n.customfunctions,n.timeZone),s={spatialReference:r,services:n.services,exports:{},libraryResolver:o,abortSignal:void 0===n.abortSignal||null===n.abortSignal?{aborted:!1}:n.abortSignal,globalScope:l,console:n.console??Ue,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let c=await Y(s,e);if(c instanceof S&&(c=c.value),c instanceof M&&(c=c.value),c===g&&(c=null),c===y)throw new a(s,i.IllegalResult,null);if(c===m)throw new a(s,i.IllegalResult,null);if(v(c))throw new a(s,i.IllegalResult,null);return c}qe([O]);export{Te as executeScript,qe as extend,Ze as functionHelper};
|
|
5
|
+
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as n,geometryMember as r}from"./containerUtils.js";import o from"./Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i,ensureArcadeExecutionError as l}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as c,ArcadeFunction as u,ScopeMarshalledFunction as f,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{I as w,a as d,G as h,D as m,B as g,C as y,i as v,c as b,z as S,o as x,q as I,r as F,u as C,b as R,g as A,A as M,j,F as L,H as k,x as N}from"../chunks/languageUtils.js";import{addFunctionDeclaration as O}from"./treeAnalysis.js";import{A as E}from"../chunks/array.js";import{registerFunctions as B}from"./functions/date.js";import{registerFunctions as P}from"./functions/geomasync.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as G}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import Z from"../geometry/Geometry.js";import q from"../geometry/SpatialReference.js";const T=100;async function W(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await Y(e,t.arguments[r]));return n}async function V(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}class _ extends u{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new a(e,i.MaximumCallDepth,null);return Pe(this.definition,n,t,null)}}call(e,t){return H(e,t,((n,r,o)=>{const l={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(l.depthCounter.depth>64)throw new a(e,i.MaximumCallDepth,t);return Pe(this.definition,l,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!v(t)||t instanceof f?t:p(t,e,r))),p(await Pe(this.definition,l,i,t),n,r)}))}}class z extends e{constructor(e){super(e)}async global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=await Y(this.executingContext,t.node),t.valueset=!0),v(t.value)&&!(t.value instanceof f)){const e=new f;e.fn=t.value,e.parameterEvaluator=H,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(v(t))throw new a(null,i.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}async loadModule(e){let n=e.spatialReference;null==n&&(n=new q({wkid:102100})),this.moduleScope=Ge({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ue,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await Y(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}async function Y(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,Y(e,t,!0)}try{switch(t?.type){case"VariableDeclarator":return await xe(e,t);case"ImportDeclaration":return await ve(e,t);case"ExportNamedDeclaration":return await be(e,t);case"VariableDeclaration":return await Se(e,t,0);case"BlockStatement":case"Program":return await he(e,t);case"FunctionDeclaration":return await ye(e,t);case"ReturnStatement":return await ge(e,t);case"IfStatement":return await de(e,t);case"ExpressionStatement":return await we(e,t);case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await pe(e,t);case"ForStatement":return await ne(e,t);case"WhileStatement":return await X(e,t);case"ForInStatement":return await ce(e,t);case"BreakStatement":return y;case"EmptyStatement":return g;case"ContinueStatement":return m;case"TemplateElement":return await Le(e,t);case"TemplateLiteral":return await Ne(e,t);case"Identifier":return await Me(e,t);case"MemberExpression":return await Ie(e,t);case"Literal":return t.value;case"CallExpression":return await je(e,t);case"UnaryExpression":return await Fe(e,t);case"BinaryExpression":return await Re(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Ce(e,t);case"ObjectExpression":return await J(e,t);case"Property":return await Q(e,t);default:throw new a(e,i.Unrecognized,t)}}catch(r){throw l(e,t,r)}}async function J(e,t){const n=[];for(let o=0;o<t.properties.length;o++)n[o]=await Y(e,t.properties[o]);const r={},l=new Map;for(let o=0;o<n.length;o++){const s=n[o];if(v(s.value))throw new a(e,i.NoFunctionInDictionary,t);if(!1===b(s.key))throw new a(e,i.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();l.has(u)?c=l.get(u):l.set(u,c),s.value===g?r[c]=null:r[c]=s.value}const s=new o(r);return s.immutable=!1,s}async function Q(e,t){const n=await Y(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await Y(e,t.key),value:n}}async function X(e,t){const n={testResult:!0,lastAction:g};if(n.testResult=await Y(e,t.test),!1===n.testResult)return g;if(!0!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await Y(e,t.body),n.lastAction!==y)&&!(n.lastAction instanceof S);)if(n.testResult=await Y(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);return n.lastAction instanceof S?n.lastAction:g}async function $(e,t,n){const r=await Y(e,t.body);return n.lastAction=r,n.lastAction===y||n.lastAction instanceof S?(n.testResult=!1,n):null!==t.update?(await Y(e,t.update),n):n}async function ee(e,t,n){if(null!==t.test){const r=await Y(e,t.test);if(!0===e.abortSignal?.aborted)throw new a(e,i.Cancelled,t);if(n.testResult=r,!1===n.testResult)return n;if(!0!==n.testResult)throw new a(e,i.BooleanConditionRequired,t);return $(e,t,n)}return $(e,t,n)}function te(e,t,n,r,o,a){try{ee(e,t,n).then((()=>{try{!0===n.testResult?++a>T?(a=0,setTimeout((()=>{te(e,t,n,r,o,a)}),0)):te(e,t,n,r,o,a):n.lastAction instanceof S?r(n.lastAction):r(g)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ne(e,t){try{return null!==t.init?Y(e,t.init).then((()=>new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:g},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:g},(e=>{n(e)}),(e=>{r(e)}),0)}))}catch(n){return Promise.reject(n)}}function re(e,t,n,r,o,a,i,l,s,c){try{if(r<=a)return void l(g);o.value="k"===i?n[a]:a,Y(e,t.body).then((u=>{try{u instanceof S?l(u):u===y?l(g):++c>T?(c=0,setTimeout((()=>{re(e,t,n,r,o,a+1,i,l,s,c)}),0)):re(e,t,n,r,o,a+1,i,l,s,c)}catch(f){s(f)}}),(e=>{s(e)}))}catch(u){s(u)}}function oe(e,t,n,r,o,a,i,l,s){try{if(n.length()<=o)return void i(g);r.value="k"===a?n.get(o):o,Y(e,t.body).then((c=>{c instanceof S?i(c):c===y?i(g):++s>T?(s=0,setTimeout((()=>{oe(e,t,n,r,o+1,a,i,l,s)}),0)):oe(e,t,n,r,o+1,a,i,l,s)}),(e=>{l(e)}))}catch(c){l(c)}}function ae(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(g);re(e,t,n,n.length,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ie(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(g);oe(e,t,n,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function le(e,t,n,r,o){try{ae(e,t,n.keys(),r,o,"k")}catch(a){r.reject(a)}}function se(e,t,n,r,o,a,i,l){try{e.next().then((c=>{try{if(null===c)a(g);else{const u=s.createFromGraphicLikeObject(c.geometry,c.attributes,r,t.timeZone);u._underlyingGraphic=c,o.value=u;Y(t,n.body).then((s=>{try{s===y?a(g):s instanceof S?a(s):++l>T?(l=0,setTimeout((()=>{se(e,t,n,r,o,a,i,l)}),0)):se(e,t,n,r,o,a,i,l)}catch(c){i(c)}}),(e=>{i(e)}))}}catch(u){i(u)}}),(e=>{i(e)}))}catch(c){i(c)}}async function ce(e,t){return new Promise(((n,r)=>{Y(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?Y(e,t.left):Promise.resolve(),s.then((()=>{try{let s="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(s=e.name)}else"Identifier"===t.left.type&&(s=t.left.name);if(!s)throw new a(e,i.InvalidIdentifier,t);s=s.toLowerCase();let c=null;if(null!=e.localScope&&void 0!==e.localScope[s]&&(c=e.localScope[s]),null===c&&void 0!==e.globalScope[s]&&(c=e.globalScope[s]),null===c)return void r(new a(e,i.InvalidIdentifier,t));x(l)||b(l)?ae(e,t,l,{reject:r,resolve:n},c):I(l)?ie(e,t,l,{reject:r,resolve:n},c):l instanceof o||F(l)?le(e,t,l,{reject:r,resolve:n},c):C(l)?se(l.iterator(e.abortSignal),e,t,l,c,(e=>{n(e)}),(e=>{r(e)}),0):ae(e,t,[],{reject:r,resolve:n},c)}catch(s){r(s)}}),r)}catch(s){r(s)}}),r)}))}async function ue(e,t){const n=t.argument;if("MemberExpression"===n.type){const r={t:null},l=await Y(e,n.object);let s=null;r.t=l,!0===n.computed?s=await Y(e,n.property):"Identifier"===n.property.type&&(s=n.property.name);const c=r.t;let u;if(x(c)){if(!R(s))throw new a(e,i.ArrayAccessorMustBeNumber,t);if(s<0&&(s=c.length+s),s<0||s>=c.length)throw new a(e,i.OutOfBounds,t);u=A(c[s]),c[s]="++"===t.operator?u+1:u-1}else if(c instanceof o){if(!1===b(s))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new a(e,i.FieldNotFound,t,{key:s});u=A(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}else if(c instanceof z){if(!1===b(s))throw new a(e,i.ModuleAccessorMustBeString,t);if(!0!==c.hasGlobal(s))throw new a(e,i.ModuleExportNotFound,t);u=A(await c.global(s)),c.setGlobal(s,"++"===t.operator?u+1:u-1)}else{if(!F(c))throw I(c)?new a(e,i.Immutable,t):new a(e,i.InvalidParameter,t);if(!1===b(s))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new a(e,i.FieldNotFound,t,{key:s});u=A(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}return!1===t.prefix?u:"++"===t.operator?u+1:u-1}const r="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!r)throw new a(e,i.InvalidIdentifier,t);let l;if(null!=e.localScope&&void 0!==e.localScope[r])return l=A(e.localScope[r].value),e.localScope[r]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[r])return l=A(e.globalScope[r].value),e.globalScope[r]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new a(e,i.InvalidIdentifier,t)}function fe(e,t,n,r,o){switch(t){case"=":return e===g?null:e;case"/=":return A(n)/A(e);case"*=":return A(n)*A(e);case"-=":return A(n)-A(e);case"+=":return b(n)||b(e)?j(n)+j(e):A(n)+A(e);case"%=":return A(n)%A(e);default:throw new a(o,i.UnsupportedOperator,r)}}async function pe(e,t){const n=t.left;if("MemberExpression"===n.type){const r=await Y(e,n.object);let l=null;if(!0===n.computed)l=await Y(e,n.property);else{if("Identifier"!==n.property.type)throw new a(e,i.InvalidIdentifier,t);l=n.property.name}const s=await Y(e,t.right);if(x(r)){if(!R(l))throw new a(e,i.ArrayAccessorMustBeNumber,t);if(l<0&&(l=r.length+l),l<0||l>r.length)throw new a(e,i.OutOfBounds,t);if(l===r.length){if("="!==t.operator)throw new a(e,i.OutOfBounds,t);r[l]=fe(s,t.operator,r[l],t,e)}else r[l]=fe(s,t.operator,r[l],t,e)}else if(r instanceof o){if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0===r.hasField(l))r.setField(l,fe(s,t.operator,r.field(l),t,e));else{if("="!==t.operator)throw new a(e,i.FieldNotFound,t,{key:l});r.setField(l,fe(s,t.operator,null,t,e))}}else if(r instanceof z){if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0!==r.hasGlobal(l))throw new a(e,i.ModuleExportNotFound,t);r.setGlobal(l,fe(s,t.operator,await r.global(l),t,e))}else{if(!F(r))throw I(r)?new a(e,i.Immutable,t):new a(e,i.InvalidParameter,t);if(!1===b(l))throw new a(e,i.KeyAccessorMustBeString,t);if(!0===r.hasField(l))r.setField(l,fe(s,t.operator,r.field(l),t,e));else{if("="!==t.operator)throw new a(e,i.FieldNotFound,t,{key:l});r.setField(l,fe(s,t.operator,null,t,e))}}return g}const r=n.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[r]){const n=await Y(e,t.right);return e.localScope[r]={value:fe(n,t.operator,e.localScope[r].value,t,e),valueset:!0,node:t.right},g}if(void 0!==e.globalScope[r]){const n=await Y(e,t.right);return e.globalScope[r]={value:fe(n,t.operator,e.globalScope[r].value,t,e),valueset:!0,node:t.right},g}throw new a(e,i.InvalidIdentifier,t)}async function we(e,t){if("AssignmentExpression"===t.expression.type)return Y(e,t.expression);if("CallExpression"===t.expression.type){const n=await Y(e,t.expression);return n===g?g:new M(n)}const n=await Y(e,t.expression);return n===g?g:new M(n)}async function de(e,t){const n=await Y(e,t.test);if(!0===n)return Y(e,t.consequent);if(!1===n)return null!==t.alternate?Y(e,t.alternate):g;throw new a(e,i.BooleanConditionRequired,t)}async function he(e,t){return me(e,t,0)}async function me(e,t,n){if(n>=t.body.length)return g;const r=await Y(e,t.body[n]);return r instanceof S||r===y||r===m||n===t.body.length-1?r:me(e,t,n+1)}async function ge(e,t){if(null===t.argument)return new S(g);const n=await Y(e,t.argument);return new S(n)}async function ye(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new _(t,e)},g}async function ve(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new z(r),await o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},g}async function be(e,t){if(await Y(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return g}async function Se(e,t,n){return n>=t.declarations.length?g:(await Y(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),g)}async function xe(e,t){let n=null;if(n=null===t.init?null:await Y(e,t.init),null!==e.localScope){if(n===g&&(n=null),"Identifier"!==t.id.type)throw new a(e,i.InvalidIdentifier,t);const r=t.id.name.toLowerCase();return null!=e.localScope&&(e.localScope[r]={value:n,valueset:!0,node:t.init}),g}if("Identifier"!==t.id.type)throw new a(e,i.InvalidIdentifier,t);const r=t.id.name.toLowerCase();return n===g&&(n=null),e.globalScope[r]={value:n,valueset:!0,node:t.init},g}async function Ie(e,t){const n=await Y(e,t.object);if(null===n)throw new a(e,i.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof o||F(n))return n.field(t.property.name);if(n instanceof Z)return r(n,t.property.name,e,t);if(n instanceof z){if(!n.hasGlobal(t.property.name))throw new a(e,i.InvalidIdentifier,t);return n.global(t.property.name)}throw new a(e,i.InvalidMemberAccessKey,t)}throw new a(e,i.InvalidMemberAccessKey,t)}let l=await Y(e,t.property);if(n instanceof o||F(n)){if(b(l))return n.field(l);throw new a(e,i.InvalidMemberAccessKey,t)}if(n instanceof z){if(b(l))return n.global(l);throw new a(e,i.InvalidMemberAccessKey,t)}if(n instanceof Z){if(b(l))return r(n,l,e,t);throw new a(e,i.InvalidMemberAccessKey,t)}if(x(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length+l),l>=n.length||l<0)throw new a(e,i.OutOfBounds,t);return n[l]}throw new a(e,i.InvalidMemberAccessKey,t)}if(I(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length()+l),l>=n.length()||l<0)throw new a(e,i.OutOfBounds,t);return n.get(l)}throw new a(e,i.InvalidMemberAccessKey,t)}if(b(n)){if(R(l)&&isFinite(l)&&Math.floor(l)===l){if(l<0&&(l=n.length+l),l>=n.length||l<0)throw new a(e,i.OutOfBounds,t);return n[l]}throw new a(e,i.InvalidMemberAccessKey,t)}throw new a(e,i.InvalidMemberAccessKey,t)}async function Fe(e,t){const n=await Y(e,t.argument);if(d(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*A(n);if("+"===t.operator)return 1*A(n);if("~"===t.operator)return~A(n);throw new a(e,i.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*A(n);if("+"===t.operator)return 1*A(n);if("~"===t.operator)return~A(n);throw new a(e,i.UnsupportedUnaryOperator,t)}async function Ce(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await Y(e,t.elements[r]));for(let r=0;r<n.length;r++){if(v(n[r]))throw new a(e,i.NoFunctionInArray,t);n[r]===g&&(n[r]=null)}return n}async function Re(e,t){const n=[];n[0]=await Y(e,t.left),n[1]=await Y(e,t.right);const r=n[0],o=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(A(r),A(o),t.operator);case"==":return h(r,o);case"!=":return!h(r,o);case"<":case">":case"<=":case">=":return L(r,o,t.operator);case"+":return b(r)||b(o)?j(r)+j(o):A(r)+A(o);case"-":return A(r)-A(o);case"*":return A(r)*A(o);case"/":return A(r)/A(o);case"%":return A(r)%A(o);default:throw new a(e,i.UnsupportedOperator,t)}}async function Ae(e,t){const n=await Y(e,t.left);let r=null;if(!d(n))throw new a(e,i.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":if(!0===n)return n;if(r=await Y(e,t.right),d(r))return r;throw new a(e,i.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(r=await Y(e,t.right),d(r))return r;throw new a(e,i.LogicExpressionOrAnd,t);default:throw new a(e,i.LogicExpressionOrAnd,t)}}async function Me(e,t){const n=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n]){const t=e.localScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}if(void 0!==e.globalScope[n]){const t=e.globalScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}throw new a(e,i.InvalidIdentifier,t)}async function je(e,t){if("MemberExpression"===t.callee.type){const n=await Y(e,t.callee.object);if(!(n instanceof z))throw new a(e,i.FunctionNotFound,t);const r=!1===t.callee.computed?t.callee.property.name:await Y(e,t.callee.property);if(!n.hasGlobal(r))throw new a(e,i.FunctionNotFound,t);const o=await n.global(r);if(!v(o))throw new a(e,i.CallNonFunction,t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new a(e,i.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(v(n.value))return n.value.call(e,t);throw new a(e,i.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(v(n.value))return n.value.call(e,t);throw new a(e,i.CallNonFunction,t)}throw new a(e,i.FunctionNotFound,t)}async function Le(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(v(e))throw new a(t,i.NoFunctionInTemplateLiteral,n);return e}async function Ne(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await Y(e,t.expressions[a]);n[a]=j(r)}let r="",o=0;for(const a of t.quasis)if(r+=a.value?a.value.cooked:"",!1===a.tail){r+=n[o]?ke(n[o],e,t):"",o++}return r}const Oe={};async function Ee(e,t,n,r){const o=await Y(e,t.arguments[n]);if(h(o,r))return Y(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?Y(e,t.arguments[n]):2===a?null:3===a?Y(e,t.arguments[n+2]):Ee(e,t,n+2,r)}async function Be(e,t,n,r){if(!0===r)return Y(e,t.arguments[n+1]);if(3===t.arguments.length-n)return Y(e,t.arguments[n+2]);const o=await Y(e,t.arguments[n+2]);if(!1===d(o))throw new a(e,i.ModuleExportNotFound,t.arguments[n+2]);return Be(e,t,n+2,o)}async function Pe(e,t,n,r){const o=e.body;if(n.length!==e.params.length)throw new a(t,i.WrongNumberOfParameters,null);for(let a=0;a<n.length;a++){const r=e.params[a];"Identifier"===r.type&&null!=t.localScope&&(t.localScope[r.name.toLowerCase()]={d:null,value:n[a],valueset:!0,node:null})}const l=await Y(t,o);if(l instanceof S)return l.value;if(l===y)throw new a(t,i.UnexpectedToken,r);if(l===m)throw new a(t,i.UnexpectedToken,r);return l instanceof M?l.value:l}B(Oe,V),U(Oe,V),D(Oe,V),K(Oe,V),G(Oe,V),P({functions:Oe,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:V,standardFunctionAsync:H}),Oe.iif=async function(e,t){w(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await Y(e,t.arguments[0]);if(!1===d(n))throw new a(e,i.BooleanConditionRequired,t);return Y(e,n?t.arguments[1]:t.arguments[2])},Oe.defaultvalue=async function(e,t){w(null===t.arguments?[]:t.arguments,2,3,e,t);const r=await Y(e,t.arguments[0]);if(3===t.arguments.length){const o=await Y(e,t.arguments[1]),a=n(r,o);return null!=a&&""!==a?a:Y(e,t.arguments[2])}return null==r||""===r?Y(e,t.arguments[1]):r},Oe.decode=async function(e,t){if(t.arguments.length<2)throw new a(e,i.WrongNumberOfParameters,t);if(2===t.arguments.length)return Y(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new a(e,i.WrongNumberOfParameters,t);return Ee(e,t,1,await Y(e,t.arguments[0]))},Oe.when=async function(e,t){if(t.arguments.length<3)throw new a(e,i.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new a(e,i.WrongNumberOfParameters,t);const n=await Y(e,t.arguments[0]);if(!1===d(n))throw new a(e,i.BooleanConditionRequired,t.arguments[0]);return Be(e,t,0,n)};const Ke={fixSpatialReference:N,parseArguments:W,standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(const We in Oe)Oe[We]={value:new c(Oe[We]),valueset:!0,node:null};const De=function(){};function Ge(e,t,n){const r=new De;null==e&&(e={}),null==t&&(t={});const a=new o({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,r.textformatting={value:a,valueset:!0,node:null};for(const o in t)r[o]={value:new c(t[o]),native:!0,valueset:!0,node:null};for(const o in e)e[o]&&"esri.Graphic"===e[o].declaredClass?r[o]={value:s.createFromGraphic(e[o],n),valueset:!0,node:null}:r[o]={value:e[o],valueset:!0,node:null};return r}function Ue(e){console.log(e)}De.prototype=Oe,De.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},De.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ze=Ke;function qe(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Oe[n]={value:new c(t.functions[n]),valueset:!0,node:null},De.prototype[n]=Oe[n];for(let n=0;n<t.signatures.length;n++)O(t.signatures[n],"async")}async function Te(e,n){let r=n.spatialReference;null==r&&(r=new q({wkid:102100}));let o=null;e.usesModules&&(o=new t(new Map,e.loadedModules));const l=Ge(n.vars,n.customfunctions,n.timeZone),s={spatialReference:r,services:n.services,exports:{},libraryResolver:o,abortSignal:void 0===n.abortSignal||null===n.abortSignal?{aborted:!1}:n.abortSignal,globalScope:l,console:n.console??Ue,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let c=await Y(s,e);if(c instanceof S&&(c=c.value),c instanceof M&&(c=c.value),c===g&&(c=null),c===y)throw new a(s,i.IllegalResult,null);if(c===m)throw new a(s,i.IllegalResult,null);if(v(c))throw new a(s,i.IllegalResult,null);return c}qe([E]);export{Te as executeScript,qe as extend,Ze as functionHelper};
|
package/arcade/arcadeCompiler.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{geometryMember as t,getNestedOptionalValue as o}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a,ArcadeCompilationError as s,ArcadeUncompilableError as i}from"./executionError.js";import c from"./Feature.js";import{NativeFunction as u,ArcadeFunction as p,ScopeMarshalledFunction as m,wrapModuleScopedResponse as g}from"./FunctionWrapper.js";import{i as d,x as f,y as h,z as y,A as b,B as w,C as S,D as v,b as x,o as M,q as F,r as C,c as I,v as A,p as _,j as O,a as $,g as k,E,F as G,G as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as j}from"./treeAnalysis.js";import{A as N}from"../chunks/array.js";import{registerFunctions as L}from"./functions/date.js";import{registerFunctions as R}from"./functions/geometry.js";import{registerFunctions as U}from"./functions/geomsync.js";import{registerFunctions as D}from"./functions/maths.js";import{registerFunctions as P}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import{isPromiseLike as K}from"../core/promiseUtils.js";import T from"../geometry/Geometry.js";import W from"../geometry/SpatialReference.js";class q extends p{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new r(e,a.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,o){return o(e,n,((n,l,r)=>{r=r.map((n=>!d(n)||n instanceof m?n:g(n,e,o)));const a=this.call(t,{arguments:r});return K(a)?a.then((e=>g(e,t,o))):a}))}}function V(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(J(e,n.arguments[o]));return t}function z(e,n,t){try{return t(e,null,n.arguments)}catch(o){throw o}}function J(e,n){try{switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclarator":return ge(e,n);case"VariableDeclaration":return me(e,n);case"BlockStatement":case"Program":return ae(e,n);case"FunctionDeclaration":return pe(e,n);case"ImportDeclaration":return ie(e,n);case"ExportNamedDeclaration":return ce(e,n);case"ReturnStatement":return se(e,n);case"IfStatement":return re(e,n);case"ExpressionStatement":return oe(e,n);case"AssignmentExpression":return te(e,n);case"UpdateExpression":return ee(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"TemplateLiteral":return ye(e,n);case"TemplateElement":return JSON.stringify(n.value?n.value.cooked:"");case"ForStatement":return X(e,n);case"ForInStatement":return Q(e,n);case"WhileStatement":return ne(e,n);case"Identifier":return Se(e,n);case"MemberExpression":return de(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return ve(e,n);case"UnaryExpression":return fe(e,n);case"BinaryExpression":return be(e,n);case"LogicalExpression":return we(e,n);case"ArrayExpression":return he(e,n);case"ObjectExpression":return Y(e,n);case"Property":return H(e,n);case"Array":throw new s(e,a.NeverReach,n);default:throw new s(e,a.Unrecognized,n)}}catch(t){throw t}}function Y(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];ue(l.key.name);o>0&&(t+=","),t+="lang.strCheck("+("Identifier"===l.key.type?"'"+l.key.name+"'":J(e,l.key))+",'ObjectExpression'),lang.aCheck("+J(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function H(e,n){throw new s(e,a.NeverReach,n)}function Q(e,n){const t=_e(e),o=_e(e),l=_e(e);let r="var "+t+" = "+J(e,n.right)+";\n";"VariableDeclaration"===n.left.type&&(r+=J(e,n.left));let a="VariableDeclaration"===n.left.type?n.left.declarations[0].id.name:n.left.name;a=a.toLowerCase(),ue(a);let s="";null!==e.localScope&&(void 0!==e.localScope[a]?s="lscope['"+a+"']":void 0!==e.localScope._SymbolsMap[a]&&(s="lscope['"+e.localScope._SymbolsMap[a]+"']"));let i="";if(""===s)if(void 0!==e.globalScope[a])s="gscope['"+a+"']";else if(void 0!==e.globalScope._SymbolsMap[a])s="gscope['"+e.globalScope._SymbolsMap[a]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(a))s="gscope['"+e.undeclaredGlobalsInFunctions.get(a).manglename+"']",i=e.undeclaredGlobalsInFunctions.get(a).manglename;else{const t={manglename:Ae(e),node:n.left};e.undeclaredGlobalsInFunctions.set(a,t),s="gscope['"+t.manglename+"']",i=t.manglename}return i&&(r+="lang.chkAssig('"+i+"',runtimeCtx); \n"),r+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",r+="else if (lc.isArray("+t+") || lc.isString("+t+")) {",r+="var "+o+"="+t+".length; \n",r+="for(var "+l+"=0; "+l+"<"+o+"; "+l+"++) {\n",r+=s+"="+l+";\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",r+="else if (lc.isImmutableArray("+t+")) {",r+="var "+o+"="+t+".length(); \n",r+="for(var "+l+"=0; "+l+"<"+o+"; "+l+"++) {\n",r+=s+"="+l+";\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",r+="else if (( "+t+" instanceof lang.Dictionary) || ( "+t+" instanceof lang.Feature)) {",r+="var "+o+"="+t+".keys(); \n",r+="for(var "+l+"=0; "+l+"<"+o+".length; "+l+"++) {\n",r+=s+"="+o+"["+l+"];\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",e.isAsync&&(r+="else if (lc.isFeatureSet("+t+")) {",r+="var "+o+"="+t+".iterator(runtimeCtx.abortSignal); \n",r+="for(var "+l+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx); "+l+"!=null; "+l+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx)) {\n",r+=s+"="+l+";\n",r+=J(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n"),r+="else { lastStatement = lc.voidOperation; } \n",r}function X(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&(t+=J(e,n.init)+"; ");const o=_e(e),l=_e(e);return t+="var "+o+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+o+"===false) {\n "+J(e,n.update)+" \n}\n "+o+"=false; \n"),null!==n.test&&(t+="var "+l+" = "+J(e,n.test)+"; ",t+="if ("+l+"===false) { break; } else if ("+l+"!==true) { lang.error('"+a.BooleanConditionRequired+"'); }\n"),t+=J(e,n.body),null!==n.update&&(t+="\n "+J(e,n.update)),t+="\n"+o+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function ee(e,n){let t=null,o="";if("MemberExpression"===n.argument.type)return t=J(e,n.argument.object),!0===n.argument.computed?o=J(e,n.argument.property):(o="'"+n.argument.property.name+"'",ue(n.argument.property.name)),"lang.memberupdate("+t+","+o+",'"+n.operator+"',"+n.prefix+")";if(t=n.argument.name.toLowerCase(),ue(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lang.update(lscope, '"+t+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.localScope._SymbolsMap[t])return"lang.update(lscope, '"+e.localScope._SymbolsMap[t]+"','"+n.operator+"',"+n.prefix+")"}if(void 0!==e.globalScope[t])return"lang.update(gscope, '"+t+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.globalScope._SymbolsMap[t])return"lang.update(gscope, '"+e.globalScope._SymbolsMap[t]+"','"+n.operator+"',"+n.prefix+")";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"lang.update(gscope,lang.chkAssig( '"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")";const o={manglename:Ae(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"lang.update(gscope, lang.chkAssig('"+o.manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")"}throw new r(e,a.InvalidIdentifier,n)}function ne(e,n){let t="lastStatement = lc.voidOperation; \n";const o=_e(e);return t+=`\n var ${o} = true;\n do {\n ${o} = ${J(e,n.test)};\n if (${o}==false) {\n break;\n }\n if (${o}!==true) {\n lang.error('${a.BooleanConditionRequired}');\n }\n ${J(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function te(e,n){const t=J(e,n.right);let o=null,l="";if("MemberExpression"===n.left.type)return o=J(e,n.left.object),!0===n.left.computed?l=J(e,n.left.property):(l="'"+n.left.property.name+"'",ue(n.left.property.name)),"lang.assignmember("+o+","+l+",'"+n.operator+"',"+t+")";if(o=n.left.name.toLowerCase(),ue(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+o+"'])";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+e.localScope._SymbolsMap[o]+"'])"}if(void 0!==e.globalScope[o])return"gscope['"+o+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+o+"'])";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+e.globalScope._SymbolsMap[o]+"'])";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+e.undeclaredGlobalsInFunctions.get(o).manglename+"'])";const l={manglename:Ae(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(o,l),"gscope[lang.chkAssig('"+l.manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+l.manglename+"'])"}throw new r(e,a.InvalidIdentifier,n)}function oe(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+J(e,n.expression)+"; \n ":(n.expression.type,"lastStatement = "+J(e,n.expression)+"; ")}function le(e,n){return"BlockStatement"===n.type?J(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?J(e,n)+"; ":"UpdateExpression"===n.type?"lastStatement = "+J(e,n)+"; ":"ExpressionStatement"===n.type?J(e,n):"ObjectExpression"===n.type?"lastStatement = "+J(e,n)+"; ":J(e,n)+"; "}function re(e,n){if("AssignmentExpression"===n.test.type||"UpdateExpression"===n.test.type)throw new s(e,a.BooleanConditionRequired,n);return`if (lang.mustBoolean(${J(e,n.test)}, runtimeCtx) === true) {\n ${le(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+re(e,n.alternate):` else {\n ${le(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function ae(e,n){let t="";for(let o=0;o<n.body.length;o++)"EmptyStatement"!==n.body[o].type&&("ReturnStatement"===n.body[o].type||"BreakStatement"===n.body[o].type||"ContinueStatement"===n.body[o].type?t+=J(e,n.body[o])+"; \n":"UpdateExpression"===n.body[o].type||"ObjectExpression"===n.body[o].type?t+="lastStatement = "+J(e,n.body[o])+"; \n":t+=J(e,n.body[o])+" \n");return t}function se(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+J(e,n.argument)}function ie(e,n){const t=n.specifiers[0].local.name.toLowerCase();ue(t);const o=e.libraryResolver?.loadLibrary(t),l=Ae(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=Te(o.syntax,{interceptor:e.interceptor,services:e.services,moduleFactory:e.moduleFactory,lrucache:e.lrucache,timeZone:e.timeZone??null,libraryResolver:e.libraryResolver,customfunctions:e.customfunctions,vars:{}},e.isAsync)),e.moduleFactoryMap[l]=o.uri;let r="";if(r=e.isAsync?"(yield lang.loadModule('"+l+"', runtimeCtx) ); ":"lang.loadModule('"+l+"', runtimeCtx); ",void 0!==e.globalScope[t])return"gscope['"+t+"']="+r;if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']="+r;let a="";return e.undeclaredGlobalsInFunctions.has(t)?(a=e.undeclaredGlobalsInFunctions.get(t).manglename,e.undeclaredGlobalsInFunctions.delete(t)):a=Ae(e),e.globalScope._SymbolsMap[t]=a,e.mangleMap[t]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+r}function ce(e,n){const t=J(e,n.declaration);if("FunctionDeclaration"===n.declaration.type)e.exports[n.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===n.declaration.type)for(const o of n.declaration.declarations)e.exports[o.id.name.toLowerCase()]="variable";return t}function ue(e){if("iif"===e)throw new i;if("decode"===e)throw new i;if("when"===e)throw new i;if("defaultvalue"===e)throw new i}function pe(e,n){const t=n.id.name.toLowerCase();ue(t);let o="",l=!1;void 0!==e.globalScope[t]?o=t:void 0!==e.globalScope._SymbolsMap[t]?o=e.globalScope._SymbolsMap[t]:e.undeclaredGlobalsInFunctions.has(t)?(o=e.undeclaredGlobalsInFunctions.get(t).manglename,e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o,e.undeclaredGlobalsInFunctions.delete(t),l=!0):(o=Ae(e),e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o);const r={isAsync:e.isAsync,console:e.console,exports:e.exports,undeclaredGlobalsInFunctions:e.undeclaredGlobalsInFunctions,customfunctions:e.customfunctions,moduleFactory:e.moduleFactory,moduleFactoryMap:e.moduleFactoryMap,libraryResolver:e.libraryResolver,lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,symbols:e.symbols,mangleMap:e.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:e.depthCounter,globalScope:e.globalScope};let a="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let s=0;s<n.params.length;s++){const t=n.params[s].name.toLowerCase();ue(t);const o=Ae(e);r.localScope._SymbolsMap[t]=o,r.mangleMap[t]=o,a+="lscope['"+o+"']=arguments["+s.toString()+"];\n"}return!0===e.isAsync?(a+="return lang.__awaiter(this, void 0, void 0, function* () {\n",a+=ae(r,n.body)+"\n return lastStatement; ",a+="}); }",a+=", runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"):(a+=ae(r,n.body)+"\n return lastStatement; }, runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"),l?"gscope[lang.setAssig('"+o+"', runtimeCtx)]="+a:"gscope['"+o+"']="+a}function me(e,n){const t=[];for(let o=0;o<n.declarations.length;o++)t.push(J(e,n.declarations[o]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function ge(e,n){let t=null===n.init?null:J(e,n.init);t===w&&(t=null);const o=n.id.name.toLowerCase();if(ue(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']="+t+"; ";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']="+t+"; ";{const n=Ae(e);return e.localScope._SymbolsMap[o]=n,e.mangleMap[o]=n,"lscope['"+n+"']="+t+"; "}}if(void 0!==e.globalScope[o])return"gscope['"+o+"']="+t+"; ";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']="+t+"; ";if(e.undeclaredGlobalsInFunctions.has(o)){const n=e.undeclaredGlobalsInFunctions.get(o).manglename;return e.globalScope._SymbolsMap[o]=n,e.mangleMap[o]=n,e.undeclaredGlobalsInFunctions.delete(o),"gscope[lang.setAssig('"+n+"', runtimeCtx)]="+t+"; "}const l=Ae(e);return e.globalScope._SymbolsMap[o]=l,e.mangleMap[o]=l,"gscope['"+l+"']="+t+"; "}function de(e,n){try{let t;return!0===n.computed?t=J(e,n.property):(t="'"+n.property.name+"'",ue(n.property.name)),"lang.member("+J(e,n.object)+","+t+")"}catch(t){throw t}}function fe(e,n){try{return"lang.unary("+J(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function he(e,n){try{const t=[];for(let o=0;o<n.elements.length;o++)"Literal"===n.elements[o].type?t.push(J(e,n.elements[o])):t.push("lang.aCheck("+J(e,n.elements[o])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function ye(e,n){try{const t=[];let o=0;for(const l of n.quasis)t.push(l.value?JSON.stringify(l.value.cooked):JSON.stringify("")),!1===l.tail&&(t.push(n.expressions[o]?"lang.castString(lang.aCheck("+J(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function be(e,n){try{return"lang.binary("+J(e,n.left)+","+J(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function we(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new s(e,a.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new s(e,a.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+J(e,n.left)+") "+n.operator+" lang.logicalCheck("+J(e,n.right)+"))";throw new s(null,a.LogicExpressionOrAnd,null)}catch(t){throw t}}function Se(e,n){try{const t=n.name.toLowerCase();if(ue(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lscope['"+t+"']";if(void 0!==e.localScope._SymbolsMap[t])return"lscope['"+e.localScope._SymbolsMap[t]+"']"}if(void 0!==e.globalScope[t])return"gscope['"+t+"']";if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";const o={manglename:Ae(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(t,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]"}throw new s(e,a.InvalidIdentifier,n)}catch(t){throw t}}function ve(e,n){try{if("MemberExpression"===n.callee.type){let t;!0===n.callee.computed?t=J(e,n.callee.property):(t="'"+n.callee.property.name+"'",ue(n.callee.property.name));let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=J(e,n.arguments[l]);return o+="]",e.isAsync?"(yield lang.callModuleFunction("+J(e,n.callee.object)+","+o+","+t+",runtimeCtx))":"lang.callModuleFunction("+J(e,n.callee.object)+","+o+","+t+",runtimeCtx)"}if("Identifier"!==n.callee.type)throw new s(e,a.FunctionNotFound,n);const t=n.callee.name.toLowerCase();if("iif"===t)return xe(e,n);if("when"===t)return Fe(e,n);if("defaultvalue"===t)return Me(e,n);if("decode"===t)return Ce(e,n);let o="";if(null!==e.localScope&&(void 0!==e.localScope[t]?o="lscope['"+t+"']":void 0!==e.localScope._SymbolsMap[t]&&(o="lscope['"+e.localScope._SymbolsMap[t]+"']")),""===o)if(void 0!==e.globalScope[t])o="gscope['"+t+"']";else if(void 0!==e.globalScope._SymbolsMap[t])o="gscope['"+e.globalScope._SymbolsMap[t]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(t))o="gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";else{const l={manglename:Ae(e),node:n.argument};e.undeclaredGlobalsInFunctions.set(t,l),o="gscope[lang.chkAssig('"+l.manglename+"',runtimeCtx)]"}if(""!==o){let t="[";for(let o=0;o<n.arguments.length;o++)o>0&&(t+=", "),t+=J(e,n.arguments[o]);return t+="]",e.isAsync?"(yield lang.callfunc("+o+","+t+",runtimeCtx) )":"lang.callfunc("+o+","+t+",runtimeCtx)"}throw new s(e,a.FunctionNotFound,n)}catch(t){throw t}}function xe(e,n){try{if(3!==n.arguments.length)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${J(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${J(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Me(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e),o=_e(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n var ${o} = ${J(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${o});\n return ${t} != null && ${t} !== "" ? ${t} : ${J(e,n.arguments[2])};\n ${e.isAsync?"})}()))":"}()"}`:`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n if (${t} === null) {\n return ${J(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${J(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${J(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Fe(e,n){try{if(n.arguments.length<3)throw new s(e,a.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${J(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${J(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${o}\n return ${J(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ce(e,n){try{if(n.arguments.length<2)throw new s(e,a.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${J(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new s(e,a.WrongNumberOfParameters,n);const t=_e(e),o=_e(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${o} = ${J(e,n.arguments[r])};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${J(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${J(e,n.arguments[0])};\n ${l}\n return ${J(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const Ie={};function Ae(e){return e.symbols.symbolCounter++,"_T"+e.symbols.symbolCounter.toString()}function _e(e){return e.symbols.symbolCounter++,"_Tvar"+e.symbols.symbolCounter.toString()}L(Ie,z),Z(Ie,z),D(Ie,z),R(Ie,z),P(Ie,z),Ie.iif=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},Ie.decode=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},Ie.when=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},Ie.defaultvalue=function(e,n){try{return z(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}};const Oe={};for(const We in Ie)Oe[We]=new u(Ie[We]);U(Ie,z);for(const We in Ie)Ie[We]=new u(Ie[We]);const $e=function(){};$e.prototype=Ie;const ke=function(){};function Ee(e,n,t){const o={};e||(e={}),t||(t={}),o._SymbolsMap={},o.textformatting=1,o.infinity=1,o.pi=1;for(const l in n)o[l]=1;for(const l in t)o[l]=1;for(const l in e)o[l]=1;return o}function Ge(e,n,t,o){const r=t?new ke:new $e;e||(e={}),n||(n={});const a=new l({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,r._SymbolsMap={textformatting:1,infinity:1,pi:1},r.textformatting=a,r.infinity=Number.POSITIVE_INFINITY,r.pi=Math.PI;for(const l in n)r[l]=n[l],r._SymbolsMap[l]=1;for(const l in e)r._SymbolsMap[l]=1,e[l]&&"esri.Graphic"===e[l].declaredClass?r[l]=c.createFromGraphic(e[l],o??null):r[l]=e[l];return r}ke.prototype=Oe;const Be={fixSpatialReference:f,parseArguments:V,standardFunction:z};function je(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:z,standardFunctionAsync:z,evaluateIdentifier:Le};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)Ie[e]=new u(t.functions[e]),$e.prototype[e]=Ie[e];for(let e=0;e<t.signatures.length;e++)j(t.signatures[e],"sync")}else{for(const e in t.functions)Oe[e]=new u(t.functions[e]),ke.prototype[e]=Oe[e];for(let e=0;e<t.signatures.length;e++)j(t.signatures[e],"async")}}function Ne(e,n){return e(n)}function Le(e,n){const t=n.name;if("_SymbolsMap"===t)throw new r(e,a.InvalidIdentifier,null);if(e.localStack.length>0){if(!t.toLowerCase().startsWith("_t")&&void 0!==e.localStack[e.localStack.length-1][t])return e.localStack[e.localStack.length-1][t];const n=e.mangleMap[t];if(void 0!==n&&void 0!==e.localStack[e.localStack.length-1][n])return e.localStack[e.localStack.length-1][n]}if(!t.toLowerCase().startsWith("_t")&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const o=e.mangleMap[t];return void 0!==o?e.globalScope[o]:void 0}je([N],"sync"),je([N],"async");let Re=0;const Ue={isNumber:e=>x(e),isArray:e=>M(e),isImmutableArray:e=>F(e),isFeature:e=>C(e),isString:e=>I(e),isDictionary:e=>A(e),isGeometry:e=>_(e),geometryMember:(e,n,o,l,r=1)=>t(e,n,o,l,r),error(e){throw new r(null,e,null)},__awaiter:(e,n,t,o)=>new Promise(((t,l)=>{function r(e){try{s(o.next(e))}catch(n){l(n)}}function a(e){try{s(o.throw(e))}catch(n){l(n)}}function s(e){e.done?t(e.value):e.value?.then?e.value.then(r,a):(Re++,Re%100==0?setTimeout((()=>{Re=0,r(e.value)}),0):r(e.value))}s((o=o.apply(e,n||[])).next())})),functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push([]),n.depthCounter.depth>64)throw new r(null,a.MaximumCallDepth,null);const t=e.apply(this,arguments);return K(t)?t.then((e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e))):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new r(n,a.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new r(n,a.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>O(e),aCheck(e,n){if(d(e)){if("ArrayExpression"===n)throw new r(null,a.NoFunctionInArray,null);if("ObjectExpression"===n)throw new r(null,a.NoFunctionInDictionary,null);throw new r(null,a.NoFunctionInTemplateLiteral,null)}return e===w?null:e},Dictionary:l,Feature:c,UserDefinedCompiledFunction:q,dictionary(e){const n={},t=new Map;for(let l=0;l<e.length;l+=2){if(d(e[l+1]))throw new r(null,a.NoFunctionInDictionary,null);if(!1===I(e[l]))throw new r(null,a.KeyMustBeString,null);let o=e[l].toString();const s=o.toLowerCase();t.has(s)?o=t.get(s):t.set(s,o),e[l+1]===w?n[o]=null:n[o]=e[l+1]}const o=new l(n);return o.immutable=!1,o},strCheck(e){if(!1===I(e))throw new r(null,a.KeyMustBeString,null);return e},unary(e,n){if($(e)){if("!"===n)return!e;if("-"===n)return-1*k(e);if("+"===n)return 1*k(e);if("~"===n)return~k(e);throw new r(null,a.UnsupportedUnaryOperator,null)}if("-"===n)return-1*k(e);if("+"===n)return 1*k(e);if("~"===n)return~k(e);throw new r(null,a.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===$(e))throw new r(null,a.LogicExpressionOrAnd,null);return e},logical(e,n,t){if($(e)&&$(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new r(null,a.LogicExpressionOrAnd,null)}throw new r(null,a.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return B(k(e),k(n),t);case"==":case"=":return G(e,n);case"!=":return!G(e,n);case"<":case">":case"<=":case">=":return E(e,n,t);case"+":return I(e)||I(n)?O(e)+O(n):k(e)+k(n);case"-":return k(e)-k(n);case"*":return k(e)*k(n);case"/":return k(e)/k(n);case"%":return k(e)%k(n);default:throw new r(null,a.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===w?null:e;case"/=":return k(t)/k(e);case"*=":return k(t)*k(e);case"-=":return k(t)-k(e);case"+=":return I(t)||I(e)?O(t)+O(e):k(t)+k(e);case"%=":return k(t)%k(e);default:throw new r(null,a.UnsupportedOperator,null)}},update(e,n,t,o){const l=k(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,n,t)=>null===e?null:c.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,o){let s;if(M(e)){if(!x(n))throw new r(null,a.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new r(null,a.OutOfBounds,null);s=k(e[n]),e[n]="++"===t?s+1:s-1}else if(e instanceof l){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new r(null,a.FieldNotFound,null,{key:n});s=k(e.field(n)),e.setField(n,"++"===t?s+1:s-1)}else if(C(e)){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new r(null,a.FieldNotFound,null);s=k(e.field(n)),e.setField(n,"++"===t?s+1:s-1)}else{if(F(e))throw new r(null,a.Immutable,null);if(!(e instanceof Ke))throw new r(null,a.InvalidIdentifier,null);if(!1===I(n))throw new r(null,a.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new r(null,a.ModuleExportNotFound,null);s=k(e.global(n)),e.setGlobal(n,"++"===t?s+1:s-1)}return!1===o?s:"++"===t?s+1:s-1},assignmember(e,n,t,o){if(M(e)){if(!x(n))throw new r(null,a.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new r(null,a.OutOfBounds,null);if(n===e.length){if("="!==t)throw new r(null,a.OutOfBounds,null);e[n]=this.assign(o,t,e[n])}else e[n]=this.assign(o,t,e[n])}else if(e instanceof l){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new r(null,a.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else if(C(e)){if(!1===I(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new r(null,a.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else{if(F(e))throw new r(null,a.Immutable,null);if(!(e instanceof Ke))throw new r(null,a.InvalidIdentifier,null);if(!1===I(n))throw new r(null,a.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new r(null,a.ModuleExportNotFound,null);e.setGlobal(n,this.assign(o,t,e.global(n)))}},member(e,n){if(null===e)throw new r(null,a.MemberOfNull,null);if(e instanceof l||C(e)){if(I(n))return e.field(n);throw new r(null,a.InvalidMemberAccessKey,null)}if(e instanceof T){if(I(n))return t(e,n,null,null);throw new r(null,a.InvalidMemberAccessKey,null)}if(M(e)){if(x(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new r(null,a.OutOfBounds,null);return e[n]}throw new r(null,a.InvalidMemberAccessKey,null)}if(I(e)){if(x(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new r(null,a.OutOfBounds,null);return e[n]}throw new r(null,a.InvalidMemberAccessKey,null)}if(F(e)){if(x(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new r(null,a.OutOfBounds,null);return e.get(n)}throw new r(null,a.InvalidMemberAccessKey,null)}if(e instanceof Ke){if(I(n))return e.global(n);throw new r(null,a.InvalidMemberAccessKey,null)}throw new r(null,a.InvalidMemberAccessKey,null)},callfunc:(e,n,t)=>e.call(t,{arguments:n,preparsed:!0}),loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const o=n.moduleFactory[t]({vars:{},moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,console:n.console,abortSignal:n.abortSignal,isAsync:n.isAsync,services:n.services,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,t,o){if(!(e instanceof Ke))throw new r(null,a.FunctionNotFound,null);const l=e.global(t);if(!1===d(l))throw new r(null,a.CallNonFunction,null);return l.call(o,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>o(e,n)};function De(e){console.log(e)}function Pe(e,t,o=!1){null===t&&(t={vars:{},customfunctions:{}});let l=null;e.usesModules&&(l=new n(null,e.loadedModules));const i={isAsync:o,globalScope:Ee(t.vars,o?Oe:Ie,t.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:t.customfunctions,libraryResolver:l,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:De,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let c=J(i,e);""===c&&(c="lc.voidOperation; "),i.undeclaredGlobalsInFunctions.size>0&&i.undeclaredGlobalsInFunctions.forEach((e=>{throw new s(t,a.InvalidIdentifier,e.node)}));let u="";u=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+c+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+c+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const p=i.moduleFactory,m=i.moduleFactoryMap,g=i.exports,f={};for(const n in g)f[n]=void 0!==i.mangleMap[n]?i.mangleMap[n]:n;const x={lc:h,lang:Ue,mangles:i.mangleMap,postProcess(e){if(e instanceof y&&(e=e.value),e instanceof b&&(e=e.value),e===w&&(e=null),e===S)throw new r(null,a.IllegalResult,null);if(e===v)throw new r(null,a.IllegalResult,null);if(d(e))throw new r(null,a.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=W.WebMercator);const o=Ge(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,moduleFactory:p,moduleFactoryMap:m,mangleMap:this.mangles,moduleSingletons:{},exports:g,gdefs:{},exportmangle:f,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??De,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",u).bind(x)}async function Ze(){return je([await import("./functions/geomasync.js")],"async"),!0}class Ke extends e{constructor(e){super(null),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,o=e.toLowerCase();if(d(n))throw new r(null,a.AssignModuleFunction,null);t[this.moduleContext.exportmangle[o]]=n}global(e){const n=this.moduleContext.globalScope;e=e.toLowerCase();const t=n[this.moduleContext.exportmangle[e]];if(void 0===t)throw new r(null,a.InvalidIdentifier,null);if(d(t)&&!(t instanceof m)){const o=new m;return o.fn=t,o.parameterEvaluator=z,o.context=this.moduleContext,n[this.moduleContext.exportmangle[e]]=o,o}return t}}function Te(e,t,o=!1){const l={isAsync:o,moduleFactory:t.moduleFactory,moduleFactoryMap:{},libraryResolver:new n(null,e.loadedModules),globalScope:Ee(t.vars,o?Oe:Ie,t.customfunctions),customfunctions:t.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:De,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let r=J(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+r+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+r+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const s=l.moduleFactory,i=l.moduleFactoryMap,c=l.exports,u={};for(const n in c)u[n]=void 0!==l.mangleMap[n]?l.mangleMap[n]:n;const p={lc:h,lang:Ue,mangles:l.mangleMap,prepareModule:e=>new Ke(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new W({wkid:102100}));const o=Ge(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,exports:c,exportmangle:u,gdefs:{},moduleFactory:s,moduleFactoryMap:i,moduleSingletons:e.moduleSingletons,mangleMap:this.mangles,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??De,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(p)}export{q as UserDefinedCompiledFunction,Pe as compileScript,Ze as enableAsyncSupport,Ne as executeScript,je as extend,Be as functionHelper};
|
|
5
|
+
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as n}from"./ArcadeModuleLoader.js";import{geometryMember as t,getNestedOptionalValue as o}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as a,ArcadeCompilationError as s,ArcadeUncompilableError as i}from"./executionError.js";import c from"./Feature.js";import{NativeFunction as u,ArcadeFunction as p,ScopeMarshalledFunction as m,wrapModuleScopedResponse as g}from"./FunctionWrapper.js";import{i as d,x as f,y as h,z as y,A as b,B as w,C as S,D as v,E as x,b as F,o as M,q as C,r as I,c as A,v as _,p as O,j as $,a as k,g as E,F as G,G as B,H as j}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as R}from"../chunks/array.js";import{registerFunctions as L}from"./functions/date.js";import{registerFunctions as D}from"./functions/geometry.js";import{registerFunctions as U}from"./functions/geomsync.js";import{registerFunctions as Z}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as P}from"./functions/string.js";import{isPromiseLike as W}from"../core/promiseUtils.js";import T from"../geometry/Geometry.js";import q from"../geometry/SpatialReference.js";class z extends p{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new r(e,a.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,o){return o(e,n,((n,l,r)=>{r=r.map((n=>!d(n)||n instanceof m?n:g(n,e,o)));const a=this.call(t,{arguments:r});return W(a)?a.then((e=>g(e,t,o))):a}))}}function V(e,n){const t=[];for(let o=0;o<n.arguments.length;o++)t.push(H(e,n.arguments[o]));return t}function J(e,n,t){try{return t(e,null,n.arguments)}catch(o){throw o}}function H(e,n){switch(n.type){case"AssignmentExpression":return le(e,n);case"UpdateExpression":return te(e,n);case"TemplateLiteral":return we(e,n);case"Identifier":return xe(e,n);case"MemberExpression":return he(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Fe(e,n);case"UnaryExpression":return ye(e,n);case"BinaryExpression":return Se(e,n);case"LogicalExpression":return ve(e,n);case"ArrayExpression":return be(e,n);case"ObjectExpression":return X(e,n);default:throw new s(e,a.Unrecognized,n)}}function Y(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return de(e,n);case"BlockStatement":return ie(e,n);case"FunctionDeclaration":return ge(e,n);case"ImportDeclaration":return ue(e,n);case"ExportNamedDeclaration":return pe(e,n);case"ReturnStatement":return ce(e,n);case"IfStatement":return se(e,n);case"ExpressionStatement":return re(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ne(e,n);case"ForInStatement":return ee(e,n);case"WhileStatement":return oe(e,n);default:throw new s(e,a.Unrecognized,n)}}function Q(e){return e.name.toLowerCase()}function X(e,n){let t="lang.dictionary([";for(let o=0;o<n.properties.length;o++){const l=n.properties[o];let r;"Identifier"===l.key.type?(me(l.key.name),r="'"+l.key.name+"'"):r=H(e,l.key);o>0&&(t+=","),t+="lang.strCheck("+r+",'ObjectExpression'),lang.aCheck("+H(e,l.value)+", 'ObjectExpression')"}return t+="])",t}function ee(e,n){const t=$e(e),o=$e(e),l=$e(e);let r="var "+t+" = "+H(e,n.right)+";\n";"VariableDeclaration"===n.left.type&&(r+=Y(e,n.left));const a=Q("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);me(a);let s="";null!==e.localScope&&(void 0!==e.localScope[a]?s="lscope['"+a+"']":void 0!==e.localScope._SymbolsMap[a]&&(s="lscope['"+e.localScope._SymbolsMap[a]+"']"));let i="";if(""===s)if(void 0!==e.globalScope[a])s="gscope['"+a+"']";else if(void 0!==e.globalScope._SymbolsMap[a])s="gscope['"+e.globalScope._SymbolsMap[a]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(a))s="gscope['"+e.undeclaredGlobalsInFunctions.get(a).manglename+"']",i=e.undeclaredGlobalsInFunctions.get(a).manglename;else{const t={manglename:Oe(e),node:n.left};e.undeclaredGlobalsInFunctions.set(a,t),s="gscope['"+t.manglename+"']",i=t.manglename}return i&&(r+="lang.chkAssig('"+i+"',runtimeCtx); \n"),r+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",r+="else if (lc.isArray("+t+") || lc.isString("+t+")) {",r+="var "+o+"="+t+".length; \n",r+="for(var "+l+"=0; "+l+"<"+o+"; "+l+"++) {\n",r+=s+"="+l+";\n",r+=Y(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",r+="else if (lc.isImmutableArray("+t+")) {",r+="var "+o+"="+t+".length(); \n",r+="for(var "+l+"=0; "+l+"<"+o+"; "+l+"++) {\n",r+=s+"="+l+";\n",r+=Y(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",r+="else if (( "+t+" instanceof lang.Dictionary) || ( "+t+" instanceof lang.Feature)) {",r+="var "+o+"="+t+".keys(); \n",r+="for(var "+l+"=0; "+l+"<"+o+".length; "+l+"++) {\n",r+=s+"="+o+"["+l+"];\n",r+=Y(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n",e.isAsync&&(r+="else if (lc.isFeatureSet("+t+")) {",r+="var "+o+"="+t+".iterator(runtimeCtx.abortSignal); \n",r+="for(var "+l+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx); "+l+"!=null; "+l+"=lang. graphicToFeature( yield "+o+".next(),"+t+", runtimeCtx)) {\n",r+=s+"="+l+";\n",r+=Y(e,n.body),r+="\n}\n",r+=" lastStatement = lc.voidOperation; \n",r+=" \n}\n"),r+="else { lastStatement = lc.voidOperation; } \n",r}function ne(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=Y(e,n.init):t+=H(e,n.init)+"; ");const o=$e(e),l=$e(e);return t+="var "+o+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+o+"===false) {\n "+H(e,n.update)+" \n}\n "+o+"=false; \n"),null!==n.test&&(t+="var "+l+" = "+H(e,n.test)+"; ",t+="if ("+l+"===false) { break; } else if ("+l+"!==true) { lang.error('"+a.BooleanConditionRequired+"'); }\n"),t+=Y(e,n.body),null!==n.update&&(t+="\n "+H(e,n.update)),t+="\n"+o+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function te(e,n){if("CallExpression"===n.argument.type)throw new s(e,a.NeverReach,n);let t;if("MemberExpression"===n.argument.type){const o=H(e,n.argument.object);return!0===n.argument.computed?t=H(e,n.argument.property):(me(n.argument.property.name),t="'"+n.argument.property.name+"'"),"lang.memberupdate("+o+","+t+",'"+n.operator+"',"+n.prefix+")"}const o=Q(n.argument);if(me(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lang.update(lscope, '"+o+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.localScope._SymbolsMap[o])return"lang.update(lscope, '"+e.localScope._SymbolsMap[o]+"','"+n.operator+"',"+n.prefix+")"}if(void 0!==e.globalScope[o])return"lang.update(gscope, '"+o+"','"+n.operator+"',"+n.prefix+")";if(void 0!==e.globalScope._SymbolsMap[o])return"lang.update(gscope, '"+e.globalScope._SymbolsMap[o]+"','"+n.operator+"',"+n.prefix+")";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"lang.update(gscope,lang.chkAssig( '"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")";const t={manglename:Oe(e),node:n.argument};return e.undeclaredGlobalsInFunctions.set(o,t),"lang.update(gscope, lang.chkAssig('"+t.manglename+"',runtimeCtx),'"+n.operator+"',"+n.prefix+")"}throw new r(e,a.InvalidIdentifier,n)}function oe(e,n){let t="lastStatement = lc.voidOperation; \n";const o=$e(e);return t+=`\n var ${o} = true;\n do {\n ${o} = ${H(e,n.test)};\n if (${o}==false) {\n break;\n }\n if (${o}!==true) {\n lang.error('${a.BooleanConditionRequired}');\n }\n ${Y(e,n.body)}\n }\n while (${o} !== false);\n lastStatement = lc.voidOperation;\n `,t}function le(e,n){const t=H(e,n.right);if("MemberExpression"===n.left.type){let o;const l=H(e,n.left.object);return!0===n.left.computed?o=H(e,n.left.property):(o="'"+n.left.property.name+"'",me(n.left.property.name)),"lang.assignmember("+l+","+o+",'"+n.operator+"',"+t+")"}const o=Q(n.left);if(me(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+o+"'])";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']=lang.assign("+t+",'"+n.operator+"', lscope['"+e.localScope._SymbolsMap[o]+"'])"}if(void 0!==e.globalScope[o])return"gscope['"+o+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+o+"'])";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']=lang.assign("+t+",'"+n.operator+"', gscope['"+e.globalScope._SymbolsMap[o]+"'])";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+e.undeclaredGlobalsInFunctions.get(o).manglename+"'])";const l={manglename:Oe(e),node:n.left};return e.undeclaredGlobalsInFunctions.set(o,l),"gscope[lang.chkAssig('"+l.manglename+"',runtimeCtx)]=lang.assign("+t+",'"+n.operator+"', gscope['"+l.manglename+"'])"}throw new r(e,a.InvalidIdentifier,n)}function re(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+H(e,n.expression)+"; \n ":"lastStatement = "+H(e,n.expression)+"; "}function ae(e,n){return"BlockStatement"===n.type?Y(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?Y(e,n)+"; ":"ExpressionStatement"===n.type?Y(e,n):Y(e,n)+"; "}function se(e,n){return`if (lang.mustBoolean(${H(e,n.test)}, runtimeCtx) === true) {\n ${ae(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+se(e,n.alternate):` else {\n ${ae(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function ie(e,n){let t="";for(let o=0;o<n.body.length;o++)"EmptyStatement"!==n.body[o].type&&("ReturnStatement"===n.body[o].type||"BreakStatement"===n.body[o].type||"ContinueStatement"===n.body[o].type?t+=Y(e,n.body[o])+"; \n":t+=Y(e,n.body[o])+" \n");return t}function ce(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+H(e,n.argument)}function ue(e,n){const t=Q(n.specifiers[0].local);me(t);const o=e.libraryResolver?.loadLibrary(t),l=Oe(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=qe(o.syntax,{interceptor:e.interceptor,services:e.services,moduleFactory:e.moduleFactory,lrucache:e.lrucache,timeZone:e.timeZone??null,libraryResolver:e.libraryResolver,customfunctions:e.customfunctions,vars:{}},e.isAsync)),e.moduleFactoryMap[l]=o.uri;let r,a="";return a=e.isAsync?"(yield lang.loadModule('"+l+"', runtimeCtx) ); ":"lang.loadModule('"+l+"', runtimeCtx); ",void 0!==e.globalScope[t]?"gscope['"+t+"']="+a:void 0!==e.globalScope._SymbolsMap[t]?"gscope['"+e.globalScope._SymbolsMap[t]+"']="+a:(e.undeclaredGlobalsInFunctions.has(t)?(r=e.undeclaredGlobalsInFunctions.get(t).manglename,e.undeclaredGlobalsInFunctions.delete(t)):r=Oe(e),e.globalScope._SymbolsMap[t]=r,e.mangleMap[t]=r,"gscope[lang.setAssig('"+r+"', runtimeCtx)]="+a)}function pe(e,n){const t=Y(e,n.declaration);if("FunctionDeclaration"===n.declaration.type)e.exports[Q(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const o of n.declaration.declarations)e.exports[Q(o.id)]="variable";return t}function me(e){if("iif"===e)throw new i;if("decode"===e)throw new i;if("when"===e)throw new i;if("defaultvalue"===e)throw new i}function ge(e,n){const t=Q(n.id);let o;me(t);let l=!1;void 0!==e.globalScope[t]?o=t:void 0!==e.globalScope._SymbolsMap[t]?o=e.globalScope._SymbolsMap[t]:e.undeclaredGlobalsInFunctions.has(t)?(o=e.undeclaredGlobalsInFunctions.get(t).manglename,e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o,e.undeclaredGlobalsInFunctions.delete(t),l=!0):(o=Oe(e),e.globalScope._SymbolsMap[t]=o,e.mangleMap[t]=o);const r={isAsync:e.isAsync,console:e.console,exports:e.exports,undeclaredGlobalsInFunctions:e.undeclaredGlobalsInFunctions,customfunctions:e.customfunctions,moduleFactory:e.moduleFactory,moduleFactoryMap:e.moduleFactoryMap,libraryResolver:e.libraryResolver,lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,symbols:e.symbols,mangleMap:e.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:e.depthCounter,globalScope:e.globalScope};let a="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let s=0;s<n.params.length;s++){const t=Q(n.params[s]);me(t);const o=Oe(e);r.localScope._SymbolsMap[t]=o,r.mangleMap[t]=o,a+="lscope['"+o+"']=arguments["+s.toString()+"];\n"}return!0===e.isAsync?(a+="return lang.__awaiter(this, void 0, void 0, function* () {\n",a+=ie(r,n.body)+"\n return lastStatement; ",a+="}); }",a+=", runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"):(a+=ie(r,n.body)+"\n return lastStatement; }, runtimeCtx),"+n.params.length+")",a+="\n lastStatement = lc.voidOperation; \n"),l?"gscope[lang.setAssig('"+o+"', runtimeCtx)]="+a:"gscope['"+o+"']="+a}function de(e,n){const t=[];for(let o=0;o<n.declarations.length;o++)t.push(fe(e,n.declarations[o]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function fe(e,n){const t=null===n.init?null:H(e,n.init),o=Q(n.id);if(me(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']="+t+"; ";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']="+t+"; ";const n=Oe(e);return e.localScope._SymbolsMap[o]=n,e.mangleMap[o]=n,"lscope['"+n+"']="+t+"; "}if(void 0!==e.globalScope[o])return"gscope['"+o+"']="+t+"; ";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']="+t+"; ";if(e.undeclaredGlobalsInFunctions.has(o)){const n=e.undeclaredGlobalsInFunctions.get(o).manglename;return e.globalScope._SymbolsMap[o]=n,e.mangleMap[o]=n,e.undeclaredGlobalsInFunctions.delete(o),"gscope[lang.setAssig('"+n+"', runtimeCtx)]="+t+"; "}const l=Oe(e);return e.globalScope._SymbolsMap[o]=l,e.mangleMap[o]=l,"gscope['"+l+"']="+t+"; "}function he(e,n){try{let t;return!0===n.computed?t=H(e,n.property):(me(n.property.name),t="'"+n.property.name+"'"),"lang.member("+H(e,n.object)+","+t+")"}catch(t){throw t}}function ye(e,n){try{return"lang.unary("+H(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function be(e,n){try{const t=[];for(let o=0;o<n.elements.length;o++)"Literal"===n.elements[o].type?t.push(H(e,n.elements[o])):t.push("lang.aCheck("+H(e,n.elements[o])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function we(e,n){try{const t=[];let o=0;for(const l of n.quasis)t.push(l.value?JSON.stringify(l.value.cooked):JSON.stringify("")),!1===l.tail&&(t.push(n.expressions[o]?"lang.castString(lang.aCheck("+H(e,n.expressions[o])+", 'TemplateLiteral'))":""),o++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function Se(e,n){try{return"lang.binary("+H(e,n.left)+","+H(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function ve(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new s(e,a.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new s(e,a.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+H(e,n.left)+") "+n.operator+" lang.logicalCheck("+H(e,n.right)+"))";throw new s(null,a.LogicExpressionOrAnd,null)}catch(t){throw t}}function xe(e,n){try{const t=Q(n);if(me(t),null!==e.localScope){if(void 0!==e.localScope[t])return"lscope['"+t+"']";if(void 0!==e.localScope._SymbolsMap[t])return"lscope['"+e.localScope._SymbolsMap[t]+"']"}if(void 0!==e.globalScope[t])return"gscope['"+t+"']";if(void 0!==e.globalScope._SymbolsMap[t])return"gscope['"+e.globalScope._SymbolsMap[t]+"']";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(t))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";const o={manglename:Oe(e),node:n};return e.undeclaredGlobalsInFunctions.set(t,o),"gscope[lang.chkAssig('"+o.manglename+"',runtimeCtx)]"}throw new s(e,a.InvalidIdentifier,n)}catch(t){throw t}}function Fe(e,n){try{if("MemberExpression"===n.callee.type){let t;!0===n.callee.computed?t=H(e,n.callee.property):(me(n.callee.property.name),t="'"+n.callee.property.name+"'");let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=H(e,n.arguments[l]);return o+="]",e.isAsync?"(yield lang.callModuleFunction("+H(e,n.callee.object)+","+o+","+t+",runtimeCtx))":"lang.callModuleFunction("+H(e,n.callee.object)+","+o+","+t+",runtimeCtx)"}if("Identifier"!==n.callee.type)throw new s(e,a.FunctionNotFound,n);const t=Q(n.callee);if("iif"===t)return Me(e,n);if("when"===t)return Ie(e,n);if("defaultvalue"===t)return Ce(e,n);if("decode"===t)return Ae(e,n);let o="";if(null!==e.localScope&&(void 0!==e.localScope[t]?o="lscope['"+t+"']":void 0!==e.localScope._SymbolsMap[t]&&(o="lscope['"+e.localScope._SymbolsMap[t]+"']")),""===o)if(void 0!==e.globalScope[t])o="gscope['"+t+"']";else if(void 0!==e.globalScope._SymbolsMap[t])o="gscope['"+e.globalScope._SymbolsMap[t]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(t))o="gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(t).manglename+"',runtimeCtx)]";else{const l={manglename:Oe(e),node:n.callee};e.undeclaredGlobalsInFunctions.set(t,l),o="gscope[lang.chkAssig('"+l.manglename+"',runtimeCtx)]"}if(""!==o){let t="[";for(let o=0;o<n.arguments.length;o++)o>0&&(t+=", "),t+=H(e,n.arguments[o]);return t+="]",e.isAsync?"(yield lang.callfunc("+o+","+t+",runtimeCtx) )":"lang.callfunc("+o+","+t+",runtimeCtx)"}throw new s(e,a.FunctionNotFound,n)}catch(t){throw t}}function Me(e,n){try{if(3!==n.arguments.length)throw new s(e,a.WrongNumberOfParameters,n);const t=$e(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${H(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${H(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ce(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new s(e,a.WrongNumberOfParameters,n);const t=$e(e),o=$e(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n var ${o} = ${H(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${o});\n return ${t} != null && ${t} !== "" ? ${t} : ${H(e,n.arguments[2])};\n ${e.isAsync?"})}()))":"}()"}`:`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n if (${t} === null) {\n return ${H(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${H(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${H(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ie(e,n){try{if(n.arguments.length<3)throw new s(e,a.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new s(e,a.WrongNumberOfParameters,n);const t=$e(e);let o="var ";for(let l=0;l<n.arguments.length-1;l+=2)o+=`${t} = lang.mustBoolean(${H(e,n.arguments[l])}, runtimeCtx);\n if (${t} === true ) {\n return ${H(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${o}\n return ${H(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ae(e,n){try{if(n.arguments.length<2)throw new s(e,a.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${H(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new s(e,a.WrongNumberOfParameters,n);const t=$e(e),o=$e(e);let l="var ";for(let r=1;r<n.arguments.length-1;r+=2)l+=`${o} = ${H(e,n.arguments[r])};\n if (lang.binary(${o}, ${t}, "==") === true ) {\n return ${H(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${H(e,n.arguments[0])};\n ${l}\n return ${H(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const _e={};function Oe(e){return e.symbols.symbolCounter++,`_T${e.symbols.symbolCounter}`}function $e(e){return e.symbols.symbolCounter++,`_Tvar${e.symbols.symbolCounter}`}L(_e,J),P(_e,J),Z(_e,J),D(_e,J),K(_e,J),_e.iif=function(e,n){try{return J(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},_e.decode=function(e,n){try{return J(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},_e.when=function(e,n){try{return J(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}},_e.defaultvalue=function(e,n){try{return J(e,n,((t,o,l)=>{throw new r(e,a.Unrecognized,n)}))}catch(t){throw t}};const ke={};for(const ze in _e)ke[ze]=new u(_e[ze]);U(_e,J);for(const ze in _e)_e[ze]=new u(_e[ze]);const Ee=function(){};Ee.prototype=_e;const Ge=function(){};function Be(e,n,t){const o={_SymbolsMap:{}};e||(e={}),t||(t={}),o.textformatting=1,o.infinity=1,o.pi=1;for(const l in n)o[l]=1;for(const l in t)o[l]=1;for(const l in e)o[l]=1;return o}function je(e,n,t,o){const r=t?new Ge:new Ee;e||(e={}),n||(n={});const a=new l({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,r._SymbolsMap={textformatting:1,infinity:1,pi:1},r.textformatting=a,r.infinity=Number.POSITIVE_INFINITY,r.pi=Math.PI;for(const l in n)r[l]=n[l],r._SymbolsMap[l]=1;for(const l in e){const n=e[l];r._SymbolsMap[l]=1,x(n)?r[l]=c.createFromGraphic(n,o??null):r[l]=n}return r}Ge.prototype=ke;const Ne={fixSpatialReference:f,parseArguments:V,standardFunction:J};function Re(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:J,standardFunctionAsync:J,evaluateIdentifier:De};for(let o=0;o<e.length;o++)e[o].registerFunctions(t);if("sync"===n){for(const e in t.functions)_e[e]=new u(t.functions[e]),Ee.prototype[e]=_e[e];for(let e=0;e<t.signatures.length;e++)N(t.signatures[e],"sync")}else{for(const e in t.functions)ke[e]=new u(t.functions[e]),Ge.prototype[e]=ke[e];for(let e=0;e<t.signatures.length;e++)N(t.signatures[e],"async")}}function Le(e,n){return e(n)}function De(e,n){const t=n.name;if("_SymbolsMap"===t)throw new r(e,a.InvalidIdentifier,null);if(e.localStack.length>0){if(!t.toLowerCase().startsWith("_t")&&void 0!==e.localStack[e.localStack.length-1][t])return e.localStack[e.localStack.length-1][t];const n=e.mangleMap[t];if(void 0!==n&&void 0!==e.localStack[e.localStack.length-1][n])return e.localStack[e.localStack.length-1][n]}if(!t.toLowerCase().startsWith("_t")&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const o=e.mangleMap[t];return void 0!==o?e.globalScope[o]:void 0}Re([R],"sync"),Re([R],"async");let Ue=0;const Ze={isNumber:e=>F(e),isArray:e=>M(e),isImmutableArray:e=>C(e),isFeature:e=>I(e),isString:e=>A(e),isDictionary:e=>_(e),isGeometry:e=>O(e),geometryMember:(e,n,o,l,r=1)=>t(e,n,o,l,r),error(e){throw new r(null,e,null)},__awaiter:(e,n,t,o)=>new Promise(((t,l)=>{function r(e){try{s(o.next(e))}catch(n){l(n)}}function a(e){try{s(o.throw(e))}catch(n){l(n)}}function s(e){e.done?t(e.value):e.value?.then?e.value.then(r,a):(Ue++,Ue%100==0?setTimeout((()=>{Ue=0,r(e.value)}),0):r(e.value))}s((o=o.apply(e,n||[])).next())})),functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new r(null,a.MaximumCallDepth,null);const t=e.apply(this,arguments);return W(t)?t.then((e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e))):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new r(n,a.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new r(n,a.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>$(e),aCheck(e,n){if(d(e)){if("ArrayExpression"===n)throw new r(null,a.NoFunctionInArray,null);if("ObjectExpression"===n)throw new r(null,a.NoFunctionInDictionary,null);throw new r(null,a.NoFunctionInTemplateLiteral,null)}return e===w?null:e},Dictionary:l,Feature:c,UserDefinedCompiledFunction:z,dictionary(e){const n={},t=new Map;for(let l=0;l<e.length;l+=2){if(d(e[l+1]))throw new r(null,a.NoFunctionInDictionary,null);if(!1===A(e[l]))throw new r(null,a.KeyMustBeString,null);let o=e[l].toString();const s=o.toLowerCase();t.has(s)?o=t.get(s):t.set(s,o),e[l+1]===w?n[o]=null:n[o]=e[l+1]}const o=new l(n);return o.immutable=!1,o},strCheck(e){if(!1===A(e))throw new r(null,a.KeyMustBeString,null);return e},unary(e,n){if(k(e)){if("!"===n)return!e;if("-"===n)return-1*E(e);if("+"===n)return 1*E(e);if("~"===n)return~E(e);throw new r(null,a.UnsupportedUnaryOperator,null)}if("-"===n)return-1*E(e);if("+"===n)return 1*E(e);if("~"===n)return~E(e);throw new r(null,a.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===k(e))throw new r(null,a.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(k(e)&&k(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new r(null,a.LogicExpressionOrAnd,null)}throw new r(null,a.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(E(e),E(n),t);case"==":case"=":return B(e,n);case"!=":return!B(e,n);case"<":case">":case"<=":case">=":return G(e,n,t);case"+":return A(e)||A(n)?$(e)+$(n):E(e)+E(n);case"-":return E(e)-E(n);case"*":return E(e)*E(n);case"/":return E(e)/E(n);case"%":return E(e)%E(n);default:throw new r(null,a.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===w?null:e;case"/=":return E(t)/E(e);case"*=":return E(t)*E(e);case"-=":return E(t)-E(e);case"+=":return A(t)||A(e)?$(t)+$(e):E(t)+E(e);case"%=":return E(t)%E(e);default:throw new r(null,a.UnsupportedOperator,null)}},update(e,n,t,o){const l=E(e[n]);return e[n]="++"===t?l+1:l-1,!1===o?l:"++"===t?l+1:l-1},graphicToFeature:(e,n,t)=>null===e?null:c.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,o){let s;if(M(e)){if(!F(n))throw new r(null,a.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new r(null,a.OutOfBounds,null);s=E(e[n]),e[n]="++"===t?s+1:s-1}else if(e instanceof l){if(!1===A(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new r(null,a.FieldNotFound,null,{key:n});s=E(e.field(n)),e.setField(n,"++"===t?s+1:s-1)}else if(I(e)){if(!1===A(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new r(null,a.FieldNotFound,null);s=E(e.field(n)),e.setField(n,"++"===t?s+1:s-1)}else{if(C(e))throw new r(null,a.Immutable,null);if(!(e instanceof Te))throw new r(null,a.InvalidIdentifier,null);if(!1===A(n))throw new r(null,a.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new r(null,a.ModuleExportNotFound,null);s=E(e.global(n)),e.setGlobal(n,"++"===t?s+1:s-1)}return!1===o?s:"++"===t?s+1:s-1},assignmember(e,n,t,o){if(M(e)){if(!F(n))throw new r(null,a.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new r(null,a.OutOfBounds,null);if(n===e.length){if("="!==t)throw new r(null,a.OutOfBounds,null);e[n]=this.assign(o,t,e[n])}else e[n]=this.assign(o,t,e[n])}else if(e instanceof l){if(!1===A(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new r(null,a.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else if(I(e)){if(!1===A(n))throw new r(null,a.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(o,t,e.field(n)));else{if("="!==t)throw new r(null,a.FieldNotFound,null);e.setField(n,this.assign(o,t,null))}}else{if(C(e))throw new r(null,a.Immutable,null);if(!(e instanceof Te))throw new r(null,a.InvalidIdentifier,null);if(!1===A(n))throw new r(null,a.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new r(null,a.ModuleExportNotFound,null);e.setGlobal(n,this.assign(o,t,e.global(n)))}},member(e,n){if(null===e)throw new r(null,a.MemberOfNull,null);if(e instanceof l||I(e)){if(A(n))return e.field(n);throw new r(null,a.InvalidMemberAccessKey,null)}if(e instanceof T){if(A(n))return t(e,n,null,null);throw new r(null,a.InvalidMemberAccessKey,null)}if(M(e)){if(F(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new r(null,a.OutOfBounds,null);return e[n]}throw new r(null,a.InvalidMemberAccessKey,null)}if(A(e)){if(F(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new r(null,a.OutOfBounds,null);return e[n]}throw new r(null,a.InvalidMemberAccessKey,null)}if(C(e)){if(F(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new r(null,a.OutOfBounds,null);return e.get(n)}throw new r(null,a.InvalidMemberAccessKey,null)}if(e instanceof Te){if(A(n))return e.global(n);throw new r(null,a.InvalidMemberAccessKey,null)}throw new r(null,a.InvalidMemberAccessKey,null)},callfunc:(e,n,t)=>e.call(t,{arguments:n,preparsed:!0}),loadModule(e,n){const t=n.moduleFactoryMap[e];if(n.moduleSingletons[t])return n.moduleSingletons[t];const o=n.moduleFactory[t]({vars:{},moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,console:n.console,abortSignal:n.abortSignal,isAsync:n.isAsync,services:n.services,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor},n.spatialReference);return n.moduleSingletons[t]=o,o},callModuleFunction(e,n,t,o){if(!(e instanceof Te))throw new r(null,a.FunctionNotFound,null);const l=e.global(t);if(!1===d(l))throw new r(null,a.CallNonFunction,null);return l.call(o,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>o(e,n)};function Ke(e){console.log(e)}function Pe(e,t,o=!1){null===t&&(t={vars:{},customfunctions:{}});let l=null;e.usesModules&&(l=new n(null,e.loadedModules));const i={isAsync:o,globalScope:Be(t.vars,o?ke:_e,t.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,customfunctions:t.customfunctions,libraryResolver:l,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},console:Ke,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let c=ie(i,e);""===c&&(c="lc.voidOperation; "),i.undeclaredGlobalsInFunctions.size>0&&i.undeclaredGlobalsInFunctions.forEach((e=>{throw new s(t,a.InvalidIdentifier,e.node)}));let u="";u=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+c+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+c+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const p=i.moduleFactory,m=i.moduleFactoryMap,g=i.exports,f={};let x;for(x in g)f[x]=i.mangleMap[x]??x;const F={lc:h,lang:Ze,mangles:i.mangleMap,postProcess(e){if(e instanceof y&&(e=e.value),e instanceof b&&(e=e.value),e===w&&(e=null),e===S)throw new r(null,a.IllegalResult,null);if(e===v)throw new r(null,a.IllegalResult,null);if(d(e))throw new r(null,a.IllegalResult,null);return e},prepare(e,n){let t=e.spatialReference;null==t&&(t=q.WebMercator);const o=je(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,moduleFactory:p,moduleFactoryMap:m,mangleMap:this.mangles,moduleSingletons:{},exports:g,gdefs:{},exportmangle:f,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??Ke,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:{depth:1}}}};return new Function("context","spatialReference",u).bind(F)}async function We(){return Re([await import("./functions/geomasync.js")],"async"),!0}class Te extends e{constructor(e){super(null),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,o=e.toLowerCase();if(d(n))throw new r(null,a.AssignModuleFunction,null);t[this.moduleContext.exportmangle[o]]=n}global(e){const n=this.moduleContext.globalScope,t=e.toLowerCase(),o=n[this.moduleContext.exportmangle[t]];if(void 0===o)throw new r(null,a.InvalidIdentifier,null);if(d(o)&&!(o instanceof m)){const e=new m;return e.fn=o,e.parameterEvaluator=J,e.context=this.moduleContext,n[this.moduleContext.exportmangle[t]]=e,e}return o}}function qe(e,t,o=!1){const l={isAsync:o,moduleFactory:t.moduleFactory,moduleFactoryMap:{},libraryResolver:new n(null,e.loadedModules),globalScope:Be(t.vars,o?ke:_e,t.customfunctions),customfunctions:t.customfunctions,localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},console:Ke,lrucache:t.lrucache,timeZone:t.timeZone??null,interceptor:t.interceptor,services:t.services,symbols:{symbolCounter:0}};let r=ie(l,e);""===r&&(r="lc.voidOperation; ");let a="";a=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+r+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+r+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const s=l.moduleFactory,i=l.moduleFactoryMap,c=l.exports,u={};let p;for(p in c)u[p]=l.mangleMap[p]??p;const m={lc:h,lang:Ze,mangles:l.mangleMap,prepareModule:e=>new Te(e),prepare(e,n){let t=e.spatialReference;null==t&&(t=new q({wkid:102100}));const o=je(e.vars,e.customfunctions,n,e.timeZone);return{localStack:[],isAsync:n,exports:c,exportmangle:u,gdefs:{},moduleFactory:s,moduleFactoryMap:i,moduleSingletons:e.moduleSingletons,mangleMap:this.mangles,spatialReference:t,globalScope:o,abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,localScope:null,services:e.services,console:e.console??Ke,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,symbols:{symbolCounter:0},depthCounter:e.depthCounter}}};return new Function("context","spatialReference",a).bind(m)}export{z as UserDefinedCompiledFunction,Pe as compileScript,We as enableAsyncSupport,Le as executeScript,Re as extend,Ne as functionHelper};
|
package/arcade/arcadeRuntime.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as n,geometryMember as o}from"./containerUtils.js";import r from"./Dictionary.js";import{ArcadeExecutionError as l,ExecutionErrorCodes as i,ensureArcadeExecutionError as a}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as c,ArcadeFunction as u,ScopeMarshalledFunction as f,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{H as d,a as h,F as w,D as m,C as g,B as v,i as y,c as b,o as x,z as S,q as I,r as F,b as C,g as R,A,j as M,E,G as L,x as N}from"../chunks/languageUtils.js";import{addFunctionDeclaration as O}from"./treeAnalysis.js";import{A as B}from"../chunks/array.js";import{registerFunctions as j}from"./functions/date.js";import{registerFunctions as k}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/geomsync.js";import{registerFunctions as U}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as q}from"./functions/string.js";import G from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";class P extends u{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,services:this.context.services,timeZone:this.context.timeZone??null,lrucache:this.context.lrucache,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new l(e,i.MaximumCallDepth,null);return Fe(this.definition,n,t,null)}}call(e,t){return V(e,t,((n,o,r)=>{const a={spatialReference:e.spatialReference,services:e.services,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,timeZone:e.timeZone??null,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter.depth>64)throw new l(e,i.MaximumCallDepth,t);return Fe(this.definition,a,r,t)}))}marshalledCall(e,t,n,o){return o(e,t,((r,l,i)=>{const a={spatialReference:e.spatialReference,globalScope:n.globalScope,services:e.services,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!y(t)||t instanceof f?t:p(t,e,o))),p(Fe(this.definition,a,i,t),n,o)}))}}class T extends e{constructor(e){super(e)}global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=_(this.executingContext,t.node),t.valueset=!0),y(t.value)&&!(t.value instanceof f)){const e=new f;e.fn=t.value,e.parameterEvaluator=V,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(y(t))throw new l(null,i.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}loadModule(e){let n=e.spatialReference;null==n&&(n=new Z({wkid:102100})),this.moduleScope=Re({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,globalScope:this.moduleScope,localScope:null,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:e.services,console:e.console??Me,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,depthCounter:{depth:1}},_(this.executingContext,this.source.syntax)}}function W(e,t){const n=[];for(let o=0;o<t.arguments.length;o++)n.push(_(e,t.arguments[o]));return n}function V(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,W(e,t))}catch(o){throw o}}function _(e,t){try{switch(t?.type){case"EmptyStatement":return v;case"VariableDeclarator":return ue(e,t);case"VariableDeclaration":return ce(e,t);case"ImportDeclaration":return ae(e,t);case"ExportNamedDeclaration":return se(e,t);case"BlockStatement":case"Program":return re(e,t);case"FunctionDeclaration":return ie(e,t);case"ReturnStatement":return le(e,t);case"IfStatement":return oe(e,t);case"ExpressionStatement":return ne(e,t);case"AssignmentExpression":return te(e,t);case"UpdateExpression":return $(e,t);case"BreakStatement":return g;case"ContinueStatement":return m;case"TemplateElement":return me(e,t);case"TemplateLiteral":return ve(e,t);case"ForStatement":return J(e,t);case"ForInStatement":return Y(e,t);case"WhileStatement":return Q(e,t);case"Identifier":return ye(e,t);case"MemberExpression":return fe(e,t);case"Literal":return t.value;case"CallExpression":return be(e,t);case"UnaryExpression":return pe(e,t);case"BinaryExpression":return he(e,t);case"LogicalExpression":return we(e,t);case"ArrayExpression":return de(e,t);case"ObjectExpression":return z(e,t);case"Property":return H(e,t);default:throw new l(e,i.Unrecognized,t)}}catch(n){throw a(e,t,n)}}function z(e,t){const n={},o=new Map;for(let r=0;r<t.properties.length;r++){const a=_(e,t.properties[r]);if(y(a.value))throw new l(e,i.NoFunctionInDictionary,t);if(!1===b(a.key))throw new l(e,i.KeyMustBeString,t);let s=a.key.toString();const c=s.toLowerCase();o.has(c)?s=o.get(c):o.set(c,s),a.value===v?n[s]=null:n[s]=a.value}const a=new r(n);return a.immutable=!1,a}function H(e,t){return{key:"Identifier"===t.key.type?t.key.name:_(e,t.key),value:_(e,t.value)}}function Y(e,t){const n=_(e,t.right);"VariableDeclaration"===t.left.type&&_(e,t.left);let o=null,a="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===t.left.type&&(a=t.left.name);if(!a)throw new l(e,i.InvalidIdentifier,t);if(a=a.toLowerCase(),null!=e.localScope&&void 0!==e.localScope[a]&&(o=e.localScope[a]),null===o&&void 0!==e.globalScope[a]&&(o=e.globalScope[a]),null===o)throw new l(e,i.InvalidIdentifier,t);if(x(n)||b(n)){const r=n.length;for(let n=0;n<r;n++){o.value=n;const r=_(e,t.body);if(r===g)break;if(r instanceof S)return r}return v}if(I(n)){for(let r=0;r<n.length();r++){o.value=r;const n=_(e,t.body);if(n===g)break;if(n instanceof S)return n}return v}if(!(n instanceof r||F(n)))return v;{const r=n.keys();for(let n=0;n<r.length;n++){o.value=r[n];const l=_(e,t.body);if(l===g)break;if(l instanceof S)return l}}}function J(e,t){null!==t.init&&_(e,t.init);const n={testResult:!0,lastAction:v};do{X(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof S?n.lastAction:v}function Q(e,t){const n={testResult:!0,lastAction:v};if(n.testResult=_(e,t.test),!1===n.testResult)return v;if(!0!==n.testResult)throw new l(e,i.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=_(e,t.body),n.lastAction!==g)&&!(n.lastAction instanceof S);)if(n.testResult=_(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new l(e,i.BooleanConditionRequired,t);return n.lastAction instanceof S?n.lastAction:v}function X(e,t,n){if(null!==t.test){if(n.testResult=_(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new l(e,i.BooleanConditionRequired,t)}n.lastAction=_(e,t.body),n.lastAction!==g?n.lastAction instanceof S?n.testResult=!1:null!==t.update&&_(e,t.update):n.testResult=!1}function $(e,t){let n,o=null,a="";if("MemberExpression"===t.argument.type){if(o=_(e,t.argument.object),!0===t.argument.computed?a=_(e,t.argument.property):"Identifier"===t.argument.property.type&&(a=t.argument.property.name),x(o)){if(!C(a))throw new l(e,i.ArrayAccessorMustBeNumber,t);if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new l(e,i.OutOfBounds,t);n=R(o[a]),o[a]="++"===t.operator?n+1:n-1}else if(o instanceof r){if(!1===b(a))throw new l(e,i.KeyAccessorMustBeString,t);if(!0!==o.hasField(a))throw new l(e,i.FieldNotFound,t);n=R(o.field(a)),o.setField(a,"++"===t.operator?n+1:n-1)}else if(F(o)){if(!1===b(a))throw new l(e,i.KeyAccessorMustBeString,t);if(!0!==o.hasField(a))throw new l(e,i.FieldNotFound,t);n=R(o.field(a)),o.setField(a,"++"===t.operator?n+1:n-1)}else{if(I(o))throw new l(e,i.Immutable,t);if(!(o instanceof T))throw new l(e,i.InvalidParameter,t);if(!1===b(a))throw new l(e,i.ModuleAccessorMustBeString,t);if(!0!==o.hasGlobal(a))throw new l(e,i.ModuleExportNotFound,t);n=R(o.global(a)),o.setGlobal(a,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}if(o="Identifier"===t.argument.type?t.argument.name.toLowerCase():"",!o)throw new l(e,i.InvalidIdentifier,t);if(null!=e.localScope&&void 0!==e.localScope[o])return n=R(e.localScope[o].value),e.localScope[o]={value:"++"===t.operator?n+1:n-1,valueset:!0,node:t},!1===t.prefix?n:"++"===t.operator?n+1:n-1;if(void 0!==e.globalScope[o])return n=R(e.globalScope[o].value),e.globalScope[o]={value:"++"===t.operator?n+1:n-1,valueset:!0,node:t},!1===t.prefix?n:"++"===t.operator?n+1:n-1;throw new l(e,i.InvalidIdentifier,t)}function ee(e,t,n,o,r){switch(t){case"=":return e===v?null:e;case"/=":return R(n)/R(e);case"*=":return R(n)*R(e);case"-=":return R(n)-R(e);case"+=":return b(n)||b(e)?M(n)+M(e):R(n)+R(e);case"%=":return R(n)%R(e);default:throw new l(r,i.UnsupportedOperator,o)}}function te(e,t){let n=null,o="";if("MemberExpression"===t.left.type){if(n=_(e,t.left.object),!0===t.left.computed)o=_(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new l(e,i.InvalidIdentifier,t);o=t.left.property.name}const a=_(e,t.right);if(x(n)){if(!C(o))throw new l(e,i.ArrayAccessorMustBeNumber,t);if(o<0&&(o=n.length+o),o<0||o>n.length)throw new l(e,i.OutOfBounds,t);if(o===n.length){if("="!==t.operator)throw new l(e,i.OutOfBounds,t);n[o]=ee(a,t.operator,n[o],t,e)}else n[o]=ee(a,t.operator,n[o],t,e)}else if(n instanceof r){if(!1===b(o))throw new l(e,i.KeyAccessorMustBeString,t);if(!0===n.hasField(o))n.setField(o,ee(a,t.operator,n.field(o),t,e));else{if("="!==t.operator)throw new l(e,i.FieldNotFound,t,{key:o});n.setField(o,ee(a,t.operator,null,t,e))}}else if(F(n)){if(!1===b(o))throw new l(e,i.KeyAccessorMustBeString,t);if(!0===n.hasField(o))n.setField(o,ee(a,t.operator,n.field(o),t,e));else{if("="!==t.operator)throw new l(e,i.FieldNotFound,t,{key:o});n.setField(o,ee(a,t.operator,null,t,e))}}else{if(I(n))throw new l(e,i.Immutable,t);if(!(n instanceof T))throw new l(e,i.InvalidIdentifier,t);if(!1===b(o))throw new l(e,i.ModuleAccessorMustBeString,t);if(!0!==n.hasGlobal(o))throw new l(e,i.ModuleExportNotFound,t);n.setGlobal(o,ee(a,t.operator,n.global(o),t,e))}return v}n=t.left.name.toLowerCase();const a=_(e,t.right);if(null!=e.localScope&&void 0!==e.localScope[n])return e.localScope[n]={value:ee(a,t.operator,e.localScope[n].value,t,e),valueset:!0,node:t.right},v;if(void 0!==e.globalScope[n])return e.globalScope[n]={value:ee(a,t.operator,e.globalScope[n].value,t,e),valueset:!0,node:t.right},v;throw new l(e,i.InvalidIdentifier,t)}function ne(e,t){if("AssignmentExpression"===t.expression.type||"UpdateExpression"===t.expression.type)return _(e,t.expression);if("CallExpression"===t.expression.type){const n=_(e,t.expression);return n===v?v:new A(n)}{const n=_(e,t.expression);return n===v?v:new A(n)}}function oe(e,t){const n=_(e,t.test);if(!0===n)return _(e,t.consequent);if(!1===n)return null!==t.alternate?_(e,t.alternate):v;throw new l(e,i.BooleanConditionRequired,t)}function re(e,t){let n=v;for(let o=0;o<t.body.length;o++)if(n=_(e,t.body[o]),n instanceof S||n===g||n===m)return n;return n}function le(e,t){if(null===t.argument)return new S(v);const n=_(e,t.argument);return new S(n)}function ie(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new P(t,e)},v}function ae(e,t){const n=t.specifiers[0].local.name.toLowerCase(),o=e.libraryResolver.loadLibrary(n);let r=null;return e.libraryResolver._moduleSingletons?.has(o.uri)?r=e.libraryResolver._moduleSingletons.get(o.uri):(r=new T(o),r.loadModule(e),e.libraryResolver._moduleSingletons?.set(o.uri,r)),e.globalScope[n]={value:r,valueset:!0,node:t},v}function se(e,t){if(_(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return v}function ce(e,t){for(let n=0;n<t.declarations.length;n++)_(e,t.declarations[n]);return v}function ue(e,t){let n=null===t.init?null:_(e,t.init);if(n===v&&(n=null),"Identifier"!==t.id.type)throw new l(e,i.InvalidIdentifier,t);const o=t.id.name.toLowerCase();return null!=e.localScope?e.localScope[o]={value:n,valueset:!0,node:t.init}:e.globalScope[o]={value:n,valueset:!0,node:t.init},v}function fe(e,t){try{const n=_(e,t.object);if(null===n)throw new l(e,i.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof r||F(n))return n.field(t.property.name);if(n instanceof G)return o(n,t.property.name,e,t);if(n instanceof T){if(!n.hasGlobal(t.property.name))throw new l(e,i.InvalidIdentifier,t);return n.global(t.property.name)}}throw new l(e,i.InvalidMemberAccessKey,t)}{let a=_(e,t.property);if(n instanceof r||F(n)){if(b(a))return n.field(a);throw new l(e,i.InvalidMemberAccessKey,t)}if(n instanceof T){if(b(a))return n.global(a);throw new l(e,i.InvalidMemberAccessKey,t)}if(n instanceof G){if(b(a))return o(n,a,e,t);throw new l(e,i.InvalidMemberAccessKey,t)}if(x(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length+a),a>=n.length||a<0)throw new l(e,i.OutOfBounds,t);return n[a]}throw new l(e,i.InvalidMemberAccessKey,t)}if(b(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length+a),a>=n.length||a<0)throw new l(e,i.OutOfBounds,t);return n[a]}throw new l(e,i.InvalidMemberAccessKey,t)}if(I(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length()+a),a>=n.length()||a<0)throw new l(e,i.OutOfBounds,t);return n.get(a)}throw new l(e,i.InvalidMemberAccessKey,t)}throw new l(e,i.InvalidMemberAccessKey,t)}}catch(n){throw n}}function pe(e,t){try{const n=_(e,t.argument);if(h(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*R(n);if("+"===t.operator)return 1*R(n);if("~"===t.operator)return~R(n);throw new l(e,i.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~R(n);if("-"===t.operator)return-1*R(n);if("+"===t.operator)return 1*R(n);throw new l(e,i.UnsupportedUnaryOperator,t)}catch(n){throw n}}function de(e,t){try{const n=[];for(let o=0;o<t.elements.length;o++){const r=_(e,t.elements[o]);if(y(r))throw new l(e,i.NoFunctionInArray,t);r===v?n.push(null):n.push(r)}return n}catch(n){throw n}}function he(e,t){try{const n=[_(e,t.left),_(e,t.right)],o=n[0],r=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return L(R(o),R(r),t.operator);case"==":return w(o,r);case"!=":return!w(o,r);case"<":case">":case"<=":case">=":return E(o,r,t.operator);case"+":return b(o)||b(r)?M(o)+M(r):R(o)+R(r);case"-":return R(o)-R(r);case"*":return R(o)*R(r);case"/":return R(o)/R(r);case"%":return R(o)%R(r);default:throw new l(e,i.UnsupportedOperator,t)}}catch(n){throw n}}function we(e,t){try{const n=_(e,t.left);if(h(n))switch(t.operator){case"||":if(!0===n)return n;{const n=_(e,t.right);if(h(n))return n;throw new l(e,i.LogicExpressionOrAnd,t)}case"&&":if(!1===n)return n;{const n=_(e,t.right);if(h(n))return n;throw new l(e,i.LogicExpressionOrAnd,t)}default:throw new l(e,i.LogicExpressionOrAnd,t)}throw new l(e,i.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function me(e,t){return t.value?t.value.cooked:""}function ge(e,t,n){if(y(e))throw new l(t,i.NoFunctionInTemplateLiteral,n);return e}function ve(e,t){let n="",o=0;for(const r of t.quasis)if(n+=r.value?r.value.cooked:"",!1===r.tail){n+=t.expressions[o]?M(ge(_(e,t.expressions[o]),e,t)):"",o++}return n}function ye(e,t){let n;try{const o=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[o])return n=e.localScope[o],!0===n.valueset||(n.value=_(e,n.node),n.valueset=!0),n.value;if(void 0!==e.globalScope[o])return n=e.globalScope[o],!0===n.valueset||(n.value=_(e,n.node),n.valueset=!0),n.value;throw new l(e,i.InvalidIdentifier,t)}catch(o){throw o}}function be(e,t){try{if("MemberExpression"===t.callee.type){const n=_(e,t.callee.object);if(!(n instanceof T))throw new l(e,i.FunctionNotFound,t);const o=!1===t.callee.computed?t.callee.property.name:_(e,t.callee.property);if(!n.hasGlobal(o))throw new l(e,i.FunctionNotFound,t);const r=n.global(o);if(!y(r))throw new l(e,i.CallNonFunction,t);return r.call(e,t)}if("Identifier"!==t.callee.type)throw new l(e,i.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(y(n.value))return n.value.call(e,t);throw new l(e,i.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(y(n.value))return n.value.call(e,t);throw new l(e,i.CallNonFunction,t)}throw new l(e,i.FunctionNotFound,t)}catch(n){throw n}}const xe={};function Se(e,t,n,o){try{const r=t.arguments,l=_(e,r[n]);if(w(l,o))return _(e,r[n+1]);{const l=r.length-n;return 1===l?_(e,r[n]):2===l?null:3===l?_(e,r[n+2]):Se(e,t,n+2,o)}}catch(r){throw r}}function Ie(e,t,n,o){try{const r=t.arguments;if(!0===o)return _(e,r[n+1]);if(3===r.length-n)return _(e,r[n+2]);{const o=_(e,r[n+2]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,r[n+2]);return Ie(e,t,n+2,o)}}catch(r){throw r}}function Fe(e,t,n,o){try{const r=e.body;if(n.length!==e.params.length)throw new l(t,i.WrongNumberOfParameters,o);if(null!=t.localScope)for(let o=0;o<n.length;o++)t.localScope[e.params[o].name.toLowerCase()]={value:n[o],valueset:!0,node:null};const a=_(t,r);if(a instanceof S)return a.value;if(a===g)throw new l(t,i.UnexpectedToken,o);if(a===m)throw new l(t,i.UnexpectedToken,o);return a instanceof A?a.value:a}catch(r){throw r}}j(xe,V),q(xe,V),U(xe,V),k(xe,V),K(xe,V),D(xe,V),xe.iif=function(e,t){try{const n=t.arguments;d(null===n?[]:n,3,3,e,t);const o=_(e,n[0]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,t);return _(e,!0===o?n[1]:n[2])}catch(n){throw n}},xe.defaultvalue=function(e,t){try{const o=t.arguments;d(null===o?[]:o,2,3,e,t);const r=_(e,o[0]);if(3===o.length){const t=_(e,o[1]),l=n(r,t);return null!=l&&""!==l?l:_(e,o[2])}return null===r||""===r||void 0===r?_(e,o[1]):r}catch(o){throw o}},xe.decode=function(e,t){try{const n=t.arguments;if(n.length<2)throw new l(e,i.WrongNumberOfParameters,t);if(2===n.length)return _(e,n[1]);{if((n.length-1)%2==0)throw new l(e,i.WrongNumberOfParameters,t);const o=_(e,n[0]);return Se(e,t,1,o)}}catch(n){throw n}},xe.when=function(e,t){try{const n=t.arguments;if(n.length<3)throw new l(e,i.WrongNumberOfParameters,t);if(n.length%2==0)throw new l(e,i.WrongNumberOfParameters,t);const o=_(e,n[0]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,n[0]);return Ie(e,t,0,o)}catch(n){throw n}};for(const Ne in xe)xe[Ne]={value:new c(xe[Ne]),valueset:!0,node:null};const Ce=function(){};function Re(e,t,n){const o=new Ce;e||(e={}),t||(t={});const l=new r({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});l.immutable=!1,o.textformatting={value:l,valueset:!0,node:null};for(const r in t)o[r]={value:new c(t[r]),native:!0,valueset:!0,node:null};for(const r in e)e[r]&&"esri.Graphic"===e[r].declaredClass?o[r]={value:s.createFromGraphic(e[r],n),valueset:!0,node:null}:o[r]={value:e[r],valueset:!0,node:null};return o}Ce.prototype=xe,Ce.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Ce.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ae={fixSpatialReference:N,parseArguments:W,standardFunction:V};function Me(e){console.log(e)}function Ee(e){const t={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:V,evaluateIdentifier:ye};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)xe[n]={value:new c(t.functions[n]),valueset:!0,node:null},Ce.prototype[n]=xe[n];for(let n=0;n<t.signatures.length;n++)O(t.signatures[n],"sync")}function Le(e,n){let o=n.spatialReference;null==o&&(o=new Z({wkid:102100}));let r=null;e.usesModules&&(r=new t(new Map,e.loadedModules));const a={spatialReference:o,globalScope:Re(n.vars,n.customfunctions,n.timeZone),localScope:null,services:n.services??null,exports:{},libraryResolver:r,console:n.console??Me,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,depthCounter:{depth:1}};let s=_(a,e);if(s instanceof S&&(s=s.value),s instanceof A&&(s=s.value),s===v&&(s=null),s===g)throw new l(a,i.IllegalResult,null);if(s===m)throw new l(a,i.IllegalResult,null);if(y(s))throw new l(a,i.IllegalResult,null);return s}Ee([B]);export{Le as executeScript,Ee as extend,Ae as functionHelper};
|
|
5
|
+
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import{getNestedOptionalValue as n,geometryMember as o}from"./containerUtils.js";import r from"./Dictionary.js";import{ArcadeExecutionError as l,ExecutionErrorCodes as i,ensureArcadeExecutionError as a}from"./executionError.js";import s from"./Feature.js";import{NativeFunction as c,ArcadeFunction as u,ScopeMarshalledFunction as f,wrapModuleScopedResponse as p}from"./FunctionWrapper.js";import{I as d,a as h,G as w,D as m,C as g,B as v,i as y,c as b,o as x,z as S,q as I,r as F,b as C,g as R,A,j as M,F as E,H as L,x as N}from"../chunks/languageUtils.js";import{addFunctionDeclaration as O}from"./treeAnalysis.js";import{A as B}from"../chunks/array.js";import{registerFunctions as j}from"./functions/date.js";import{registerFunctions as k}from"./functions/geometry.js";import{registerFunctions as D}from"./functions/geomsync.js";import{registerFunctions as U}from"./functions/maths.js";import{registerFunctions as K}from"./functions/stats.js";import{registerFunctions as q}from"./functions/string.js";import G from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";class P extends u{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,services:this.context.services,timeZone:this.context.timeZone??null,lrucache:this.context.lrucache,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new l(e,i.MaximumCallDepth,null);return Fe(this.definition,n,t,null)}}call(e,t){return V(e,t,((n,o,r)=>{const a={spatialReference:e.spatialReference,services:e.services,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,timeZone:e.timeZone??null,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};if(a.depthCounter.depth>64)throw new l(e,i.MaximumCallDepth,t);return Fe(this.definition,a,r,t)}))}marshalledCall(e,t,n,o){return o(e,t,((r,l,i)=>{const a={spatialReference:e.spatialReference,globalScope:n.globalScope,services:e.services,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!y(t)||t instanceof f?t:p(t,e,o))),p(Fe(this.definition,a,i,t),n,o)}))}}class T extends e{constructor(e){super(e)}global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=_(this.executingContext,t.node),t.valueset=!0),y(t.value)&&!(t.value instanceof f)){const e=new f;e.fn=t.value,e.parameterEvaluator=V,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(y(t))throw new l(null,i.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}loadModule(e){let n=e.spatialReference;null==n&&(n=new Z({wkid:102100})),this.moduleScope=Re({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,globalScope:this.moduleScope,localScope:null,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},services:e.services,console:e.console??Me,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,depthCounter:{depth:1}},_(this.executingContext,this.source.syntax)}}function W(e,t){const n=[];for(let o=0;o<t.arguments.length;o++)n.push(_(e,t.arguments[o]));return n}function V(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,W(e,t))}catch(o){throw o}}function _(e,t){try{switch(t?.type){case"EmptyStatement":return v;case"VariableDeclarator":return ue(e,t);case"VariableDeclaration":return ce(e,t);case"ImportDeclaration":return ae(e,t);case"ExportNamedDeclaration":return se(e,t);case"BlockStatement":case"Program":return re(e,t);case"FunctionDeclaration":return ie(e,t);case"ReturnStatement":return le(e,t);case"IfStatement":return oe(e,t);case"ExpressionStatement":return ne(e,t);case"AssignmentExpression":return te(e,t);case"UpdateExpression":return $(e,t);case"BreakStatement":return g;case"ContinueStatement":return m;case"TemplateElement":return me(e,t);case"TemplateLiteral":return ve(e,t);case"ForStatement":return J(e,t);case"ForInStatement":return Y(e,t);case"WhileStatement":return Q(e,t);case"Identifier":return ye(e,t);case"MemberExpression":return fe(e,t);case"Literal":return t.value;case"CallExpression":return be(e,t);case"UnaryExpression":return pe(e,t);case"BinaryExpression":return he(e,t);case"LogicalExpression":return we(e,t);case"ArrayExpression":return de(e,t);case"ObjectExpression":return z(e,t);case"Property":return H(e,t);default:throw new l(e,i.Unrecognized,t)}}catch(n){throw a(e,t,n)}}function z(e,t){const n={},o=new Map;for(let r=0;r<t.properties.length;r++){const a=_(e,t.properties[r]);if(y(a.value))throw new l(e,i.NoFunctionInDictionary,t);if(!1===b(a.key))throw new l(e,i.KeyMustBeString,t);let s=a.key.toString();const c=s.toLowerCase();o.has(c)?s=o.get(c):o.set(c,s),a.value===v?n[s]=null:n[s]=a.value}const a=new r(n);return a.immutable=!1,a}function H(e,t){return{key:"Identifier"===t.key.type?t.key.name:_(e,t.key),value:_(e,t.value)}}function Y(e,t){const n=_(e,t.right);"VariableDeclaration"===t.left.type&&_(e,t.left);let o=null,a="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(a=e.name)}else"Identifier"===t.left.type&&(a=t.left.name);if(!a)throw new l(e,i.InvalidIdentifier,t);if(a=a.toLowerCase(),null!=e.localScope&&void 0!==e.localScope[a]&&(o=e.localScope[a]),null===o&&void 0!==e.globalScope[a]&&(o=e.globalScope[a]),null===o)throw new l(e,i.InvalidIdentifier,t);if(x(n)||b(n)){const r=n.length;for(let n=0;n<r;n++){o.value=n;const r=_(e,t.body);if(r===g)break;if(r instanceof S)return r}return v}if(I(n)){for(let r=0;r<n.length();r++){o.value=r;const n=_(e,t.body);if(n===g)break;if(n instanceof S)return n}return v}if(!(n instanceof r||F(n)))return v;{const r=n.keys();for(let n=0;n<r.length;n++){o.value=r[n];const l=_(e,t.body);if(l===g)break;if(l instanceof S)return l}}}function J(e,t){null!==t.init&&_(e,t.init);const n={testResult:!0,lastAction:v};do{X(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof S?n.lastAction:v}function Q(e,t){const n={testResult:!0,lastAction:v};if(n.testResult=_(e,t.test),!1===n.testResult)return v;if(!0!==n.testResult)throw new l(e,i.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=_(e,t.body),n.lastAction!==g)&&!(n.lastAction instanceof S);)if(n.testResult=_(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new l(e,i.BooleanConditionRequired,t);return n.lastAction instanceof S?n.lastAction:v}function X(e,t,n){if(null!==t.test){if(n.testResult=_(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new l(e,i.BooleanConditionRequired,t)}n.lastAction=_(e,t.body),n.lastAction!==g?n.lastAction instanceof S?n.testResult=!1:null!==t.update&&_(e,t.update):n.testResult=!1}function $(e,t){let n,o=null,a="";if("MemberExpression"===t.argument.type){if(o=_(e,t.argument.object),!0===t.argument.computed?a=_(e,t.argument.property):"Identifier"===t.argument.property.type&&(a=t.argument.property.name),x(o)){if(!C(a))throw new l(e,i.ArrayAccessorMustBeNumber,t);if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new l(e,i.OutOfBounds,t);n=R(o[a]),o[a]="++"===t.operator?n+1:n-1}else if(o instanceof r){if(!1===b(a))throw new l(e,i.KeyAccessorMustBeString,t);if(!0!==o.hasField(a))throw new l(e,i.FieldNotFound,t);n=R(o.field(a)),o.setField(a,"++"===t.operator?n+1:n-1)}else if(F(o)){if(!1===b(a))throw new l(e,i.KeyAccessorMustBeString,t);if(!0!==o.hasField(a))throw new l(e,i.FieldNotFound,t);n=R(o.field(a)),o.setField(a,"++"===t.operator?n+1:n-1)}else{if(I(o))throw new l(e,i.Immutable,t);if(!(o instanceof T))throw new l(e,i.InvalidParameter,t);if(!1===b(a))throw new l(e,i.ModuleAccessorMustBeString,t);if(!0!==o.hasGlobal(a))throw new l(e,i.ModuleExportNotFound,t);n=R(o.global(a)),o.setGlobal(a,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}if(o="Identifier"===t.argument.type?t.argument.name.toLowerCase():"",!o)throw new l(e,i.InvalidIdentifier,t);if(null!=e.localScope&&void 0!==e.localScope[o])return n=R(e.localScope[o].value),e.localScope[o]={value:"++"===t.operator?n+1:n-1,valueset:!0,node:t},!1===t.prefix?n:"++"===t.operator?n+1:n-1;if(void 0!==e.globalScope[o])return n=R(e.globalScope[o].value),e.globalScope[o]={value:"++"===t.operator?n+1:n-1,valueset:!0,node:t},!1===t.prefix?n:"++"===t.operator?n+1:n-1;throw new l(e,i.InvalidIdentifier,t)}function ee(e,t,n,o,r){switch(t){case"=":return e===v?null:e;case"/=":return R(n)/R(e);case"*=":return R(n)*R(e);case"-=":return R(n)-R(e);case"+=":return b(n)||b(e)?M(n)+M(e):R(n)+R(e);case"%=":return R(n)%R(e);default:throw new l(r,i.UnsupportedOperator,o)}}function te(e,t){let n=null,o="";if("MemberExpression"===t.left.type){if(n=_(e,t.left.object),!0===t.left.computed)o=_(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new l(e,i.InvalidIdentifier,t);o=t.left.property.name}const a=_(e,t.right);if(x(n)){if(!C(o))throw new l(e,i.ArrayAccessorMustBeNumber,t);if(o<0&&(o=n.length+o),o<0||o>n.length)throw new l(e,i.OutOfBounds,t);if(o===n.length){if("="!==t.operator)throw new l(e,i.OutOfBounds,t);n[o]=ee(a,t.operator,n[o],t,e)}else n[o]=ee(a,t.operator,n[o],t,e)}else if(n instanceof r){if(!1===b(o))throw new l(e,i.KeyAccessorMustBeString,t);if(!0===n.hasField(o))n.setField(o,ee(a,t.operator,n.field(o),t,e));else{if("="!==t.operator)throw new l(e,i.FieldNotFound,t,{key:o});n.setField(o,ee(a,t.operator,null,t,e))}}else if(F(n)){if(!1===b(o))throw new l(e,i.KeyAccessorMustBeString,t);if(!0===n.hasField(o))n.setField(o,ee(a,t.operator,n.field(o),t,e));else{if("="!==t.operator)throw new l(e,i.FieldNotFound,t,{key:o});n.setField(o,ee(a,t.operator,null,t,e))}}else{if(I(n))throw new l(e,i.Immutable,t);if(!(n instanceof T))throw new l(e,i.InvalidIdentifier,t);if(!1===b(o))throw new l(e,i.ModuleAccessorMustBeString,t);if(!0!==n.hasGlobal(o))throw new l(e,i.ModuleExportNotFound,t);n.setGlobal(o,ee(a,t.operator,n.global(o),t,e))}return v}n=t.left.name.toLowerCase();const a=_(e,t.right);if(null!=e.localScope&&void 0!==e.localScope[n])return e.localScope[n]={value:ee(a,t.operator,e.localScope[n].value,t,e),valueset:!0,node:t.right},v;if(void 0!==e.globalScope[n])return e.globalScope[n]={value:ee(a,t.operator,e.globalScope[n].value,t,e),valueset:!0,node:t.right},v;throw new l(e,i.InvalidIdentifier,t)}function ne(e,t){if("AssignmentExpression"===t.expression.type||"UpdateExpression"===t.expression.type)return _(e,t.expression);if("CallExpression"===t.expression.type){const n=_(e,t.expression);return n===v?v:new A(n)}{const n=_(e,t.expression);return n===v?v:new A(n)}}function oe(e,t){const n=_(e,t.test);if(!0===n)return _(e,t.consequent);if(!1===n)return null!==t.alternate?_(e,t.alternate):v;throw new l(e,i.BooleanConditionRequired,t)}function re(e,t){let n=v;for(let o=0;o<t.body.length;o++)if(n=_(e,t.body[o]),n instanceof S||n===g||n===m)return n;return n}function le(e,t){if(null===t.argument)return new S(v);const n=_(e,t.argument);return new S(n)}function ie(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new P(t,e)},v}function ae(e,t){const n=t.specifiers[0].local.name.toLowerCase(),o=e.libraryResolver.loadLibrary(n);let r=null;return e.libraryResolver._moduleSingletons?.has(o.uri)?r=e.libraryResolver._moduleSingletons.get(o.uri):(r=new T(o),r.loadModule(e),e.libraryResolver._moduleSingletons?.set(o.uri,r)),e.globalScope[n]={value:r,valueset:!0,node:t},v}function se(e,t){if(_(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return v}function ce(e,t){for(let n=0;n<t.declarations.length;n++)_(e,t.declarations[n]);return v}function ue(e,t){let n=null===t.init?null:_(e,t.init);if(n===v&&(n=null),"Identifier"!==t.id.type)throw new l(e,i.InvalidIdentifier,t);const o=t.id.name.toLowerCase();return null!=e.localScope?e.localScope[o]={value:n,valueset:!0,node:t.init}:e.globalScope[o]={value:n,valueset:!0,node:t.init},v}function fe(e,t){try{const n=_(e,t.object);if(null===n)throw new l(e,i.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof r||F(n))return n.field(t.property.name);if(n instanceof G)return o(n,t.property.name,e,t);if(n instanceof T){if(!n.hasGlobal(t.property.name))throw new l(e,i.InvalidIdentifier,t);return n.global(t.property.name)}}throw new l(e,i.InvalidMemberAccessKey,t)}{let a=_(e,t.property);if(n instanceof r||F(n)){if(b(a))return n.field(a);throw new l(e,i.InvalidMemberAccessKey,t)}if(n instanceof T){if(b(a))return n.global(a);throw new l(e,i.InvalidMemberAccessKey,t)}if(n instanceof G){if(b(a))return o(n,a,e,t);throw new l(e,i.InvalidMemberAccessKey,t)}if(x(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length+a),a>=n.length||a<0)throw new l(e,i.OutOfBounds,t);return n[a]}throw new l(e,i.InvalidMemberAccessKey,t)}if(b(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length+a),a>=n.length||a<0)throw new l(e,i.OutOfBounds,t);return n[a]}throw new l(e,i.InvalidMemberAccessKey,t)}if(I(n)){if(C(a)&&isFinite(a)&&Math.floor(a)===a){if(a<0&&(a=n.length()+a),a>=n.length()||a<0)throw new l(e,i.OutOfBounds,t);return n.get(a)}throw new l(e,i.InvalidMemberAccessKey,t)}throw new l(e,i.InvalidMemberAccessKey,t)}}catch(n){throw n}}function pe(e,t){try{const n=_(e,t.argument);if(h(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*R(n);if("+"===t.operator)return 1*R(n);if("~"===t.operator)return~R(n);throw new l(e,i.UnsupportedUnaryOperator,t)}if("~"===t.operator)return~R(n);if("-"===t.operator)return-1*R(n);if("+"===t.operator)return 1*R(n);throw new l(e,i.UnsupportedUnaryOperator,t)}catch(n){throw n}}function de(e,t){try{const n=[];for(let o=0;o<t.elements.length;o++){const r=_(e,t.elements[o]);if(y(r))throw new l(e,i.NoFunctionInArray,t);r===v?n.push(null):n.push(r)}return n}catch(n){throw n}}function he(e,t){try{const n=[_(e,t.left),_(e,t.right)],o=n[0],r=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return L(R(o),R(r),t.operator);case"==":return w(o,r);case"!=":return!w(o,r);case"<":case">":case"<=":case">=":return E(o,r,t.operator);case"+":return b(o)||b(r)?M(o)+M(r):R(o)+R(r);case"-":return R(o)-R(r);case"*":return R(o)*R(r);case"/":return R(o)/R(r);case"%":return R(o)%R(r);default:throw new l(e,i.UnsupportedOperator,t)}}catch(n){throw n}}function we(e,t){try{const n=_(e,t.left);if(h(n))switch(t.operator){case"||":if(!0===n)return n;{const n=_(e,t.right);if(h(n))return n;throw new l(e,i.LogicExpressionOrAnd,t)}case"&&":if(!1===n)return n;{const n=_(e,t.right);if(h(n))return n;throw new l(e,i.LogicExpressionOrAnd,t)}default:throw new l(e,i.LogicExpressionOrAnd,t)}throw new l(e,i.LogicalExpressionOnlyBoolean,t)}catch(n){throw n}}function me(e,t){return t.value?t.value.cooked:""}function ge(e,t,n){if(y(e))throw new l(t,i.NoFunctionInTemplateLiteral,n);return e}function ve(e,t){let n="",o=0;for(const r of t.quasis)if(n+=r.value?r.value.cooked:"",!1===r.tail){n+=t.expressions[o]?M(ge(_(e,t.expressions[o]),e,t)):"",o++}return n}function ye(e,t){let n;try{const o=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[o])return n=e.localScope[o],!0===n.valueset||(n.value=_(e,n.node),n.valueset=!0),n.value;if(void 0!==e.globalScope[o])return n=e.globalScope[o],!0===n.valueset||(n.value=_(e,n.node),n.valueset=!0),n.value;throw new l(e,i.InvalidIdentifier,t)}catch(o){throw o}}function be(e,t){try{if("MemberExpression"===t.callee.type){const n=_(e,t.callee.object);if(!(n instanceof T))throw new l(e,i.FunctionNotFound,t);const o=!1===t.callee.computed?t.callee.property.name:_(e,t.callee.property);if(!n.hasGlobal(o))throw new l(e,i.FunctionNotFound,t);const r=n.global(o);if(!y(r))throw new l(e,i.CallNonFunction,t);return r.call(e,t)}if("Identifier"!==t.callee.type)throw new l(e,i.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(y(n.value))return n.value.call(e,t);throw new l(e,i.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(y(n.value))return n.value.call(e,t);throw new l(e,i.CallNonFunction,t)}throw new l(e,i.FunctionNotFound,t)}catch(n){throw n}}const xe={};function Se(e,t,n,o){try{const r=t.arguments,l=_(e,r[n]);if(w(l,o))return _(e,r[n+1]);{const l=r.length-n;return 1===l?_(e,r[n]):2===l?null:3===l?_(e,r[n+2]):Se(e,t,n+2,o)}}catch(r){throw r}}function Ie(e,t,n,o){try{const r=t.arguments;if(!0===o)return _(e,r[n+1]);if(3===r.length-n)return _(e,r[n+2]);{const o=_(e,r[n+2]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,r[n+2]);return Ie(e,t,n+2,o)}}catch(r){throw r}}function Fe(e,t,n,o){try{const r=e.body;if(n.length!==e.params.length)throw new l(t,i.WrongNumberOfParameters,o);if(null!=t.localScope)for(let o=0;o<n.length;o++)t.localScope[e.params[o].name.toLowerCase()]={value:n[o],valueset:!0,node:null};const a=_(t,r);if(a instanceof S)return a.value;if(a===g)throw new l(t,i.UnexpectedToken,o);if(a===m)throw new l(t,i.UnexpectedToken,o);return a instanceof A?a.value:a}catch(r){throw r}}j(xe,V),q(xe,V),U(xe,V),k(xe,V),K(xe,V),D(xe,V),xe.iif=function(e,t){try{const n=t.arguments;d(null===n?[]:n,3,3,e,t);const o=_(e,n[0]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,t);return _(e,!0===o?n[1]:n[2])}catch(n){throw n}},xe.defaultvalue=function(e,t){try{const o=t.arguments;d(null===o?[]:o,2,3,e,t);const r=_(e,o[0]);if(3===o.length){const t=_(e,o[1]),l=n(r,t);return null!=l&&""!==l?l:_(e,o[2])}return null===r||""===r||void 0===r?_(e,o[1]):r}catch(o){throw o}},xe.decode=function(e,t){try{const n=t.arguments;if(n.length<2)throw new l(e,i.WrongNumberOfParameters,t);if(2===n.length)return _(e,n[1]);{if((n.length-1)%2==0)throw new l(e,i.WrongNumberOfParameters,t);const o=_(e,n[0]);return Se(e,t,1,o)}}catch(n){throw n}},xe.when=function(e,t){try{const n=t.arguments;if(n.length<3)throw new l(e,i.WrongNumberOfParameters,t);if(n.length%2==0)throw new l(e,i.WrongNumberOfParameters,t);const o=_(e,n[0]);if(!1===h(o))throw new l(e,i.BooleanConditionRequired,n[0]);return Ie(e,t,0,o)}catch(n){throw n}};for(const Ne in xe)xe[Ne]={value:new c(xe[Ne]),valueset:!0,node:null};const Ce=function(){};function Re(e,t,n){const o=new Ce;e||(e={}),t||(t={});const l=new r({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});l.immutable=!1,o.textformatting={value:l,valueset:!0,node:null};for(const r in t)o[r]={value:new c(t[r]),native:!0,valueset:!0,node:null};for(const r in e)e[r]&&"esri.Graphic"===e[r].declaredClass?o[r]={value:s.createFromGraphic(e[r],n),valueset:!0,node:null}:o[r]={value:e[r],valueset:!0,node:null};return o}Ce.prototype=xe,Ce.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Ce.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ae={fixSpatialReference:N,parseArguments:W,standardFunction:V};function Me(e){console.log(e)}function Ee(e){const t={mode:"sync",compiled:!1,functions:{},signatures:[],standardFunction:V,evaluateIdentifier:ye};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)xe[n]={value:new c(t.functions[n]),valueset:!0,node:null},Ce.prototype[n]=xe[n];for(let n=0;n<t.signatures.length;n++)O(t.signatures[n],"sync")}function Le(e,n){let o=n.spatialReference;null==o&&(o=new Z({wkid:102100}));let r=null;e.usesModules&&(r=new t(new Map,e.loadedModules));const a={spatialReference:o,globalScope:Re(n.vars,n.customfunctions,n.timeZone),localScope:null,services:n.services??null,exports:{},libraryResolver:r,console:n.console??Me,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,depthCounter:{depth:1}};let s=_(a,e);if(s instanceof S&&(s=s.value),s instanceof A&&(s=s.value),s===v&&(s=null),s===g)throw new l(a,i.IllegalResult,null);if(s===m)throw new l(a,i.IllegalResult,null);if(y(s))throw new l(a,i.IllegalResult,null);return s}Ee([B]);export{Le as executeScript,Ee as extend,Ae as functionHelper};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../request.js";import t from"./featureSetCollection.js";import{u as a,$ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import l from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import f from"./featureset/support/cache.js";import{FeatureSetError as p,FeatureSetErrorCodes as m}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,extractServiceUrl as h,isSupportedLayer as w}from"./featureset/support/shared.js";import _ from"../core/Loadable.js";import{WhereClause as L}from"../core/sql/WhereClause.js";import I from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import C from"../portal/PortalItem.js";function F(){null===f.applicationCache&&(f.applicationCache=new f)}async function g(e,t,a){if(f.applicationCache){const a=f.applicationCache.getLayerInfo(e);if(a){const r=await a;return new I({url:e,outFields:t,sourceJSON:r})}const n=new I({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(f.applicationCache){f.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(r){throw f.applicationCache.clearLayerInfo(e),r}}return await i,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new I({url:e,outFields:t,sourceJSON:a})}const i=new I({url:e,outFields:t}),s=(async()=>(await i.load(),i.sourceJSON))();a.setCachedLayerMetadata(e,s);try{return await s,i}catch(n){throw a.removeCachedLayerMetadata(e,s),n}}return new I({url:e,outFields:t})}async function N(e,t,a,r,n,i=null){return T(await g(e,["*"],n),t,a,r,n,i)}function T(e,t=null,a=null,r=!0,n=null,i=null){if("catalog-footprint"===e.type)return T(e.parent,t,a,r,n,i);if("subtype-sublayer"===e.type){const s=T(e.parent,t,a,r,n,i);return s.filter(L.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),e.parent.fieldsIndex,s.dateFieldsTimeZoneDefaultUTC))}if(y(e)){const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!0==!(e.url||!e.source)?new c(s):new u(s)}throw new Error(`Unsupported layer type: ${e.type}`)}async function A(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function b(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new p(m.DataElementsNotFound)})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw f.applicationCache.clearLayerInfo(r),i}}return n}async function k(t,a){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw f.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(i){throw a.removeCachedServiceMetadata(t,r),i}}return r}async function O(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await k(e,null);if(a.metadata=r,void 0!==r.controllerDatasetLayers?.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await b(e,n);if(i){a.queryelem=i,a.queryelem?.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await A(e+"/"+n);if(void 0!==r.systemLayers?.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await N(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(L.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)",i.getFieldsIndex(),i.dateFieldsTimeZoneDefaultUTC)),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function E(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await N(o,r,n,i,s,l);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}n.registerAction(),i.registerAction(),s.registerAction(),l.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overridespref,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.title===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.id===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e={...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overridespref,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await k(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])s.name===e&&(i=s);if(!i)for(const s of n.tables??[])s.name===e&&(i=s);if(i){const e=await g(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await g(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function v(e,t,a=null,r=null){return new j(e,t,a,r)}function M(e,t,a=null,r=null){return new D(e,t,a,r)}function q(e,t,n,i,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return T(a,s,a.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(a,s,a.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return T(e.parent,s,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(e,s,e.parent.outFields,!0,n,i)}return null}return null}async function G(e,t,a,r,n,i,s,l=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return T(await g(h(e.url??"")+"/"+t,["*"],s),a,r,n,s,l)}}if(null!=s){const o=s.getCachedPortalItem(i.url,e);if(null!=o){const e=await o;return T(await g(h(e.url??"")+"/"+t,["*"],s),a,r,n,s,l)}}const o=new C({id:e,portal:i}).load();f.applicationCache?f.applicationCache.setLayerInfo(e+":"+i.url,o):null!=s&&s.setCachedPortalItem(i.url,e,o);try{const e=await o;return T(await g(h(e.url??"")+"/"+t,["*"],s),a,r,n,s,l)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),null!=s&&s.removeCachedPortalItem(i.url,e,o),u}}export{O as constructAssociationMetaDataFeatureSetFromUrl,T as constructFeatureSet,G as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,N as constructFeatureSetFromUrl,q as convertToFeatureSet,v as createFeatureSetCollectionFromMap,M as createFeatureSetCollectionFromService,F as initialiseMetaDataCache};
|
|
5
|
+
import e from"../request.js";import t from"./featureSetCollection.js";import{u as a,a0 as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import l from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import f from"./featureset/support/cache.js";import{FeatureSetError as p,FeatureSetErrorCodes as m}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,extractServiceUrl as h,isSupportedLayer as w}from"./featureset/support/shared.js";import _ from"../core/Loadable.js";import{WhereClause as L}from"../core/sql/WhereClause.js";import I from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import C from"../portal/PortalItem.js";function F(){null===f.applicationCache&&(f.applicationCache=new f)}async function g(e,t,a){if(f.applicationCache){const a=f.applicationCache.getLayerInfo(e);if(a){const r=await a;return new I({url:e,outFields:t,sourceJSON:r})}const n=new I({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(f.applicationCache){f.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(r){throw f.applicationCache.clearLayerInfo(e),r}}return await i,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new I({url:e,outFields:t,sourceJSON:a})}const i=new I({url:e,outFields:t}),s=(async()=>(await i.load(),i.sourceJSON))();a.setCachedLayerMetadata(e,s);try{return await s,i}catch(n){throw a.removeCachedLayerMetadata(e,s),n}}return new I({url:e,outFields:t})}async function N(e,t,a,r,n,i=null){return T(await g(e,["*"],n),t,a,r,n,i)}function T(e,t=null,a=null,r=!0,n=null,i=null){if("catalog-footprint"===e.type)return T(e.parent,t,a,r,n,i);if("subtype-sublayer"===e.type){const s=T(e.parent,t,a,r,n,i);return s.filter(L.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),e.parent.fieldsIndex,s.dateFieldsTimeZoneDefaultUTC))}if(y(e)){const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!0==!(e.url||!e.source)?new c(s):new u(s)}throw new Error(`Unsupported layer type: ${e.type}`)}async function A(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function b(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new p(m.DataElementsNotFound)})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw f.applicationCache.clearLayerInfo(r),i}}return n}async function k(t,a){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw f.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(i){throw a.removeCachedServiceMetadata(t,r),i}}return r}async function O(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await k(e,null);if(a.metadata=r,void 0!==r.controllerDatasetLayers?.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await b(e,n);if(i){a.queryelem=i,a.queryelem?.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await A(e+"/"+n);if(void 0!==r.systemLayers?.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await N(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(L.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)",i.getFieldsIndex(),i.dateFieldsTimeZoneDefaultUTC)),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function E(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await N(o,r,n,i,s,l);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}n.registerAction(),i.registerAction(),s.registerAction(),l.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overridespref,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.title===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.id===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e={...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overridespref,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await k(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])s.name===e&&(i=s);if(!i)for(const s of n.tables??[])s.name===e&&(i=s);if(i){const e=await g(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await g(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function v(e,t,a=null,r=null){return new j(e,t,a,r)}function M(e,t,a=null,r=null){return new D(e,t,a,r)}function q(e,t,n,i,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return T(a,s,a.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(a,s,a.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return T(e.parent,s,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(e,s,e.parent.outFields,!0,n,i)}return null}return null}async function G(e,t,a,r,n,i,s,l=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return T(await g(h(e.url??"")+"/"+t,["*"],s),a,r,n,s,l)}}if(null!=s){const o=s.getCachedPortalItem(i.url,e);if(null!=o){const e=await o;return T(await g(h(e.url??"")+"/"+t,["*"],s),a,r,n,s,l)}}const o=new C({id:e,portal:i}).load();f.applicationCache?f.applicationCache.setLayerInfo(e+":"+i.url,o):null!=s&&s.setCachedPortalItem(i.url,e,o);try{const e=await o;return T(await g(h(e.url??"")+"/"+t,["*"],s),a,r,n,s,l)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),null!=s&&s.removeCachedPortalItem(i.url,e,o),u}}export{O as constructAssociationMetaDataFeatureSetFromUrl,T as constructFeatureSet,G as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,N as constructFeatureSetFromUrl,q as convertToFeatureSet,v as createFeatureSetCollectionFromMap,M as createFeatureSetCollectionFromService,F as initialiseMetaDataCache};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.31/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{a0 as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as l,FeatureSetErrorCodes as o}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import{calculateStat as w}from"../support/stats.js";import F from"../support/StatsField.js";import{createMD5Hash as I,outputTypes as S}from"../../../core/MD5.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as k}from"../../../core/sql/TimeOnly.js";import{WhereClause as j}from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.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 O extends d{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(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new F;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new F;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=j.create(this._parent.objectIdField,this._parent.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new C;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new l(o.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new C;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new C;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new l(o.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,l){if(""!==e)return new u([],[],!0,null);let o=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(l),o=!0===d.nowhereclause?new u(n._candidates.slice().concat(n._known.slice()),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(),n._known.slice(),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),o}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return o}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const l=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:l};else{if(l!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:l},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(l){a(l)}}_calculateFieldStat(e,t,i){const s=[];for(let n=0;n<e.features.length;n++)if(null!==t.workingexpr){const i=t.workingexpr.calculateValue(e.features[n]);null!==i&&(i instanceof x||i instanceof k?s.push(i.toNumber()):i instanceof D?s.push(i.toMilliseconds()):s.push(i))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=w("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=w("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=w("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=w("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=w("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=w("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:j.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return I(t,S.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
|
|
5
|
+
import e from"../../../Graphic.js";import{a1 as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as l,FeatureSetErrorCodes as o}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import{calculateStat as w}from"../support/stats.js";import F from"../support/StatsField.js";import{createMD5Hash as I,outputTypes as S}from"../../../core/MD5.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as k}from"../../../core/sql/TimeOnly.js";import{WhereClause as j}from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.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 O extends d{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(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new F;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new F;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=j.create(this._parent.objectIdField,this._parent.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new C;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new l(o.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new C;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new C;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new l(o.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,l){if(""!==e)return new u([],[],!0,null);let o=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(l),o=!0===d.nowhereclause?new u(n._candidates.slice().concat(n._known.slice()),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(),n._known.slice(),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),o}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return o}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const l=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:l};else{if(l!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:l},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(l){a(l)}}_calculateFieldStat(e,t,i){const s=[];for(let n=0;n<e.features.length;n++)if(null!==t.workingexpr){const i=t.workingexpr.calculateValue(e.features[n]);null!==i&&(i instanceof x||i instanceof k?s.push(i.toNumber()):i instanceof D?s.push(i.toMilliseconds()):s.push(i))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=w("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=w("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=w("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=w("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=w("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=w("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:j.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return I(t,S.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
|