@arcgis/core 4.34.0-next.75 → 4.34.0-next.76

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.
Files changed (117) hide show
  1. package/applications/Components/arcadeEditorUtils.d.ts +4 -0
  2. package/applications/Components/arcadeEditorUtils.js +5 -0
  3. package/applications/Components/featureUtils.d.ts +1 -0
  4. package/applications/Components/featureUtils.js +1 -1
  5. package/arcade/Feature.js +1 -1
  6. package/arcade/Pixel.js +1 -1
  7. package/arcade/Voxel.js +1 -1
  8. package/arcade/arcadeAsyncRuntime.js +1 -1
  9. package/arcade/arcadeCompiler.js +1 -1
  10. package/arcade/arcadeRuntime.js +1 -1
  11. package/arcade/featureset/support/FeatureSetIterator.js +1 -1
  12. package/arcade/functions/feature.js +1 -1
  13. package/arcade/functions/featuresetbase.js +1 -1
  14. package/arcade/functions/geometry.js +1 -1
  15. package/assets/esri/core/workers/RemoteClient.js +1 -1
  16. package/assets/esri/core/workers/chunks/13de06e614adf92239fe.js +1 -0
  17. package/assets/esri/core/workers/chunks/14a22d1a0eefa970efa1.js +1 -0
  18. package/assets/esri/core/workers/chunks/16d66770ef841564ee3f.js +1 -0
  19. package/assets/esri/core/workers/chunks/17103e6542aae53c7301.js +1 -0
  20. package/assets/esri/core/workers/chunks/{5c30252c1bb8350cae5f.js → 1c52999a6392370844a6.js} +1 -1
  21. package/assets/esri/core/workers/chunks/21bfad7283620766d9cd.js +1 -0
  22. package/assets/esri/core/workers/chunks/3064320d54a9b48bd697.js +1 -0
  23. package/assets/esri/core/workers/chunks/3a5f0c759dd2f4638343.js +1 -0
  24. package/assets/esri/core/workers/chunks/4832faefd3b7edc17c84.js +1 -0
  25. package/assets/esri/core/workers/chunks/4d47187bc0821413492d.js +1 -0
  26. package/assets/esri/core/workers/chunks/5102c20645d9708c34b4.js +1 -0
  27. package/assets/esri/core/workers/chunks/58cc06ed86301f4cee75.js +1 -0
  28. package/assets/esri/core/workers/chunks/{e12e8d69c05c182b6a69.js → 61bb39597ccf89f99a72.js} +1 -1
  29. package/assets/esri/core/workers/chunks/{a25b75de1bca1dd21941.js → 70367da4ba916376f40c.js} +1 -1
  30. package/assets/esri/core/workers/chunks/7b73a808922b52755abd.js +1 -0
  31. package/assets/esri/core/workers/chunks/a0edff37fd4a3f2cb2eb.js +1 -0
  32. package/assets/esri/core/workers/chunks/a9f6054d86982b9e5a7c.js +1 -0
  33. package/assets/esri/core/workers/chunks/{10ec10ca361842efce92.js → ab005fe84952f0676020.js} +1 -1
  34. package/assets/esri/core/workers/chunks/b70d71144a060f7eeeeb.js +1 -0
  35. package/assets/esri/core/workers/chunks/b8d02f1b73c374767a5f.js +1 -0
  36. package/assets/esri/core/workers/chunks/ba6452acee3d6defb37e.js +1 -0
  37. package/assets/esri/core/workers/chunks/bfbbf180c2c8fdbb6731.js +1 -0
  38. package/assets/esri/core/workers/chunks/{356c96fad88558be9054.js → c6fecf2bbd2a711f15d3.js} +1 -1
  39. package/assets/esri/core/workers/chunks/c86f5bb199cf046b8952.js +1 -0
  40. package/assets/esri/core/workers/chunks/{b5f197e24982f6e14468.js → d1f181f91b36351f1d3b.js} +2 -2
  41. package/assets/esri/core/workers/chunks/{8e428b0f33ef4688415e.js → d95554f43694b4769675.js} +1 -1
  42. package/assets/esri/core/workers/chunks/dd587d51dad2d82708d1.js +1 -0
  43. package/assets/esri/core/workers/chunks/ecac5ca00c742bfb5898.js +1 -0
  44. package/assets/esri/core/workers/chunks/{0d946a226b846b3c0849.js → fc06014fb484fc8c697e.js} +1 -1
  45. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  46. package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
  47. package/chunks/Compositing.glsl.js +4 -3
  48. package/chunks/cameraUtilsSpherical.js +1 -1
  49. package/chunks/lyr3DMain.js +1 -1
  50. package/chunks/lyr3DWorker.js +1 -1
  51. package/config.js +1 -1
  52. package/core/sql.d.ts +1 -0
  53. package/geometry/support/heightModelInfoUtils.js +1 -1
  54. package/geometry/support/normalizeUtils.js +1 -1
  55. package/geometry/support/spatialReferenceUtils.js +1 -1
  56. package/interfaces.d.ts +45 -0
  57. package/kernel.js +1 -1
  58. package/layers/GaussianSplatLayer.js +1 -1
  59. package/layers/Lyr3DWasmPerSceneView.js +1 -1
  60. package/layers/Lyr3DWorkerHandle.js +1 -1
  61. package/layers/support/tiles3DUtils.js +1 -1
  62. package/networks/CircuitManager.js +1 -1
  63. package/networks/support/Circuit.js +1 -1
  64. package/networks/support/CircuitSection.js +1 -1
  65. package/networks/support/Subcircuit.js +1 -1
  66. package/package.json +1 -1
  67. package/support/arcadeUtils.js +1 -1
  68. package/support/modeUtils.js +1 -1
  69. package/support/revision.js +1 -1
  70. package/views/2d/layers/MediaLayerView2D.js +1 -1
  71. package/views/2d/layers/TileLayerView2D.js +1 -1
  72. package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
  73. package/views/3d/layers/Lyr3DWorker.js +1 -1
  74. package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
  75. package/views/3d/support/cameraUtils.js +1 -1
  76. package/views/3d/support/cameraUtilsSpherical.js +1 -1
  77. package/{layers/support/GaussianSplatAtlasPageAllocator.js → views/3d/support/gaussianSplatting/GaussianSplatAtlasPages.js} +1 -1
  78. package/views/3d/support/gaussianSplatting/GaussianSplatDataStore.js +5 -0
  79. package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +5 -0
  80. package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +5 -0
  81. package/views/3d/support/gaussianSplatting/GaussianTile.js +5 -0
  82. package/views/3d/terrain/OverlayManager.js +1 -1
  83. package/views/3d/terrain/TerrainSurface.js +1 -1
  84. package/views/3d/webgl-engine/core/shaderLibrary/shading/LineStipple.glsl.js +12 -13
  85. package/views/3d/webgl-engine/lib/CompositingHelper.js +1 -1
  86. package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
  87. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  88. package/views/3d/webgl-engine/lib/edgeRendering/strokes.js +1 -1
  89. package/views/3d/webgl-engine/materials/stippleTextureRepository.js +1 -1
  90. package/views/3d/webgl-engine/shaders/CompositingTechnique.js +1 -1
  91. package/views/3d/webgl-engine/shaders/CompositingTechniqueConfiguration.js +1 -1
  92. package/views/3d/webgl-engine/shaders/sources/edgeRenderer/LineOffset.glsl.js +10 -11
  93. package/views/VideoView.js +1 -1
  94. package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
  95. package/widgets/support/widget.js +1 -1
  96. package/assets/esri/core/workers/chunks/06bd58c219678315cf5c.js +0 -1
  97. package/assets/esri/core/workers/chunks/0751f539db31bdb5caec.js +0 -1
  98. package/assets/esri/core/workers/chunks/19228ab0fe7944c554e5.js +0 -1
  99. package/assets/esri/core/workers/chunks/2a19a4d7d1c580121065.js +0 -1
  100. package/assets/esri/core/workers/chunks/37ff19a9c5c99bd4e7c7.js +0 -1
  101. package/assets/esri/core/workers/chunks/3d2629357242492afcfa.js +0 -1
  102. package/assets/esri/core/workers/chunks/5c4ba165816809e06340.js +0 -1
  103. package/assets/esri/core/workers/chunks/5f239972cb95afdfa77a.js +0 -1
  104. package/assets/esri/core/workers/chunks/6963ded8428cc8d51d85.js +0 -1
  105. package/assets/esri/core/workers/chunks/6c3ae96c6ef764fb9552.js +0 -1
  106. package/assets/esri/core/workers/chunks/76ec3d2646ba64e3442f.js +0 -1
  107. package/assets/esri/core/workers/chunks/925ad2665c2fe0f47cc3.js +0 -1
  108. package/assets/esri/core/workers/chunks/93b2e0a300b2758a1ca4.js +0 -1
  109. package/assets/esri/core/workers/chunks/b03dcbc31bccb9fdf9fe.js +0 -1
  110. package/assets/esri/core/workers/chunks/b0de01f8c9b1c3182e0c.js +0 -1
  111. package/assets/esri/core/workers/chunks/c7ba8f2aca0fbd6ceded.js +0 -1
  112. package/assets/esri/core/workers/chunks/c908184d747d33366881.js +0 -1
  113. package/assets/esri/core/workers/chunks/d1711256493d55eca523.js +0 -1
  114. package/assets/esri/core/workers/chunks/e6e4e2fb9568319c6207.js +0 -1
  115. package/assets/esri/core/workers/chunks/ee391a41144855fc625d.js +0 -1
  116. package/assets/esri/core/workers/chunks/f060a52a9b69eb250d63.js +0 -1
  117. package/layers/support/gaussianSplatUtils.js +0 -5
@@ -0,0 +1,4 @@
1
+ import "../../interfaces";
2
+
3
+ export const getDeclaredPixelMembers: __esri.arcadeEditorUtils["getDeclaredPixelMembers"];
4
+ export const getDeclaredVoxelMembers: __esri.arcadeEditorUtils["getDeclaredVoxelMembers"];
@@ -0,0 +1,5 @@
1
+ /*
2
+ All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
+ */
5
+ async function t(t){const{Pixel:a}=await import("../../support/arcadeUtils.js");return await t.load(),a.getDeclaredMembers(t)}async function a(t){const{Voxel:a}=await import("../../support/arcadeUtils.js");return await t.load(),a.getDeclaredMembers(t)}export{t as getDeclaredPixelMembers,a as getDeclaredVoxelMembers};
@@ -1,6 +1,7 @@
1
1
  import "../../interfaces";
2
2
 
3
3
  export const findRelatedLayer: __esri.featureUtils["findRelatedLayer"];
4
+ export const findUtilityNetwork: __esri.featureUtils["findUtilityNetwork"];
4
5
  export const isFeatureSupportedLayer: __esri.featureUtils["isFeatureSupportedLayer"];
5
6
  export const isRelatableFeatureSupportedLayer: __esri.featureUtils["isRelatableFeatureSupportedLayer"];
6
7
  export const isRelatableLayer: __esri.featureUtils["isRelatableLayer"];
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{findRelatedLayer as e,isRelatableFeatureSupportedLayer as a,isRelatableLayer as t,isFeatureSupportedLayer as r}from"../../widgets/Feature/support/featureUtils.js";const s=e,p=a,i=t,o=r;export{s as findRelatedLayer,o as isFeatureSupportedLayer,p as isRelatableFeatureSupportedLayer,i as isRelatableLayer};
5
+ import{findRelatedLayer as e,isRelatableFeatureSupportedLayer as a,isRelatableLayer as t,isFeatureSupportedLayer as r,findUtilityNetwork as s}from"../../widgets/Feature/support/featureUtils.js";const i=e,o=a,p=t,l=r,u=s;export{i as findRelatedLayer,u as findUtilityNetwork,l as isFeatureSupportedLayer,o as isRelatableFeatureSupportedLayer,p as isRelatableLayer};
package/arcade/Feature.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.34/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as e}from"./ArcadeDate.js";import{configureDeepClone as t}from"./deepClone.js";import i from"./Dictionary.js";import{ArcadeExecutionError as s}from"./executionError.js";import{m as r,c as o,t as n,g as a,f as l,e as u,d,a as m}from"../chunks/languageUtils.js";import{constructGeometryFromDictionary as f}from"./geometry/constructors.js";import{DateOnly as y}from"../core/sql/DateOnly.js";import{TimeOnly as h}from"../core/sql/TimeOnly.js";import c from"../geometry/Geometry.js";import{fromJSON as p}from"../geometry/support/jsonUtils.js";import{convertToGeometry as _}from"../layers/graphics/featureConversionUtils.js";import b from"../layers/support/FieldsIndex.js";import{isString as T,isNumber as g,isBoolean as F}from"../support/guards.js";class x{constructor(){this.arcadeDeclaredClass="esri.arcade.Feature",this._optimizedGeomDefinition=null,this._geometry=null,this.attributes=null,this._layer=null,this._fieldTypesFixed=!0,this.fieldsIndex=null,this.contextTimeZone=null,this.immutable=!0,this._fieldsToFixDataTypes=null,this.immutable=!0}static createFromGraphic(e,t){const i=new x;return i.contextTimeZone=t??null,i._geometry=null!=e.geometry?e.geometry:null,void 0===e.attributes||null===e.attributes?i.attributes={}:i.attributes=e.attributes,e._sourceLayer?(i._layer=e._sourceLayer,i._fieldTypesFixed=!1):e._layer?(i._layer=e._layer,i._fieldTypesFixed=!1):e.layer&&"fields"in e.layer?(i._layer=e.layer,i._fieldTypesFixed=!1):e.sourceLayer&&"fields"in e.sourceLayer&&(i._layer=e.sourceLayer,i._fieldTypesFixed=!1),i._layer&&!i._fieldTypesFixed&&(i.fieldsIndex=this.hydrateFieldsIndex(i._layer)),i}static createFromArcadeFeature(e){if(e instanceof x){const t=new x;return t._fieldTypesFixed=e._fieldTypesFixed,t.attributes=e.attributes,t._geometry=e._geometry,t._optimizedGeomDefinition=e._optimizedGeomDefinition,e._layer&&(t._layer=e._layer),t.fieldsIndex=e.fieldsIndex,t.contextTimeZone=e.contextTimeZone,t}const t={};for(const i of e.keys())t[i]=e.field(i);return x.createFromGraphicLikeObject(e.geometry(),t,e.fullSchema(),e.contextTimeZone)}static createFromOptimisedFeature(e,t,i){const s=new x;return s._geometry=e.geometry?{geometry:e.geometry}:null,s._optimizedGeomDefinition=i,s.attributes=e.attributes||{},s._layer=t,s._fieldTypesFixed=!1,s}static createFromArcadeDictionary(e,t){const s=new x;return s.attributes=e.field("attributes"),null!==s.attributes&&s.attributes instanceof i?(s.attributes=s.attributes.attributes,null===s.attributes&&(s.attributes={})):s.attributes={},s._geometry=e.field("geometry"),null!==s._geometry&&(s._geometry instanceof i?s._geometry=f(s._geometry,t):s._geometry instanceof c||(s._geometry=null)),s}static createFromGraphicLikeObject(e,t,i=null,s){const r=new x;return r.contextTimeZone=s??null,null===t&&(t={}),r.attributes=t,r._geometry=null!=e?e:null,r._layer=i,r._layer&&(r._fieldTypesFixed=!1,r.fieldsIndex=this.hydrateFieldsIndex(r._layer)),r}static hydrateFieldsIndex(e){return null===e?null:r(e)?e.getFieldsIndex():e.fieldsIndex?e.fieldsIndex:b.fromLayerJSON({datesInUnknownTimezone:e.datesInUnknownTimezone,fields:e.fields,timeInfo:e.timeInfo,editFieldsInfo:e.editFieldsInfo,dateFieldsTimeReference:e.dateFieldsTimeReference??{timeZone:"UTC",respectsDaylightSaving:!1}})}repurposeFromGraphicLikeObject(e,t,i=null){null===t&&(t={}),this.attributes=t,this._geometry=e??null,this._layer=i,this._layer?this._fieldTypesFixed=!1:this._fieldTypesFixed=!0}castToText(e=!1){!1===this._fieldTypesFixed&&this._fixFieldTypes();const t=o(this.attributes,{useNumbersForDates:e});return'{"geometry":'+(null===this.geometry()?"null":n(this.geometry()))+',"attributes":'+t+"}"}_fixFieldTypes(){if(this._fieldsToFixDataTypes&&this._fieldsToFixDataTypes?.length>0)return this._fixAllFields(this._fieldsToFixDataTypes),void(this._fieldTypesFixed=!0);const e=[],t=this._layer.fields;for(let i=0;i<(t?.length??0);i++){const s=t[i],{name:r,type:o}=s;switch(o){case"date":case"esriFieldTypeDate":e.push({field:r,dataType:"date"});break;case"date-only":case"esriFieldTypeDateOnly":e.push({field:r,dataType:"date-only"});break;case"time-only":case"esriFieldTypeTimeOnly":e.push({field:r,dataType:"time-only"});break;case"timestamp-offset":case"esriFieldTypeTimestampOffset":e.push({field:r,dataType:"timestamp-offset"});break;case"geometry":case"esriFieldTypeGeometry":e.push({field:r,dataType:"geometry"})}}this._fieldsToFixDataTypes=e,e.length>0&&this._fixAllFields(e),this._fieldTypesFixed=!0}isUnknownDateTimeField(e){return"unknown"===this.fieldsIndex?.getTimeZone(e)}_fixAllFields(t){this.attributes={...this.attributes};const i=this.contextTimeZone??"system";for(let s=0;s<t.length;s++){const r=t[s].field,o=t[s].dataType;let n=this.attributes[r];if(void 0===n){for(const t in this.attributes)if(t.toLowerCase()===r.toLowerCase()){if(n=this.attributes[t],null!==n){if("time-only"===o){a(n)||(this.attributes[t]=h.fromReader(n.toString()));break}if("date-only"===o){l(n)||(this.attributes[t]=y.fromReader(n.toString()));break}if("timestamp-offset"===o){u(n)||(this.attributes[t]=e.fromReaderAsTimeStampOffset(n.toString()));break}if("date"===o){const s=this.isUnknownDateTimeField(t);n instanceof Date?this.attributes[t]=s?e.unknownDateJSToArcadeDate(n):e.dateJSAndZoneToArcadeDate(n,i):u(n)||(this.attributes[t]=s?e.unknownEpochToArcadeDate(n):e.epochToArcadeDate(n,i))}"geometry"===o&&(this.attributes[t]=null)}break}}else if(null!==n){if("time-only"===o){a(n)?this.attributes[r]=n:this.attributes[r]=h.fromReader(n.toString());continue}if("date-only"===o){l(n)?this.attributes[r]=n:this.attributes[r]=y.fromReader(n.toString());continue}if("timestamp-offset"===o){u(n)?this.attributes[r]=n:this.attributes[r]=e.fromReaderAsTimeStampOffset(n.toString());continue}if("date"===o){const t=this.isUnknownDateTimeField(r);u(n)?this.attributes[r]=n:n instanceof Date?this.attributes[r]=t?e.unknownDateJSToArcadeDate(n):e.dateJSAndZoneToArcadeDate(n,i):this.attributes[r]=t?e.unknownEpochToArcadeDate(n):e.epochToArcadeDate(n,i);continue}if("geometry"===o){this.attributes[r]=null;continue}}}}geometry(){return null===this._geometry||this._geometry instanceof c||(this._optimizedGeomDefinition?(this._geometry=p(_(this._geometry,this._optimizedGeomDefinition.geometryType,this._optimizedGeomDefinition.hasZ,this._optimizedGeomDefinition.hasM)),this._geometry.spatialReference=this._optimizedGeomDefinition.spatialReference):this._geometry=p(this._geometry)),this._geometry}field(e){this._fieldTypesFixed||this._fixFieldTypes();const t=this.attributes[e];if(void 0!==t)return t;const i=e.toLowerCase();for(const s in this.attributes)if(s.toLowerCase()===i)return this.attributes[s];if(this._hasFieldDefinition(i))return null;throw new s(null,"FieldNotFound",null,{key:e})}_hasFieldDefinition(e){if(null===this._layer)return!1;for(let t=0;t<this._layer.fields.length;t++){if(this._layer.fields[t].name.toLowerCase()===e)return!0}return!1}setField(t,i){if(this.immutable)throw new s(null,"Immutable",null);if(i instanceof Date&&(i=this.isUnknownDateTimeField(t)?e.unknownDateJSToArcadeDate(i):e.dateJSToArcadeDate(i)),!1===d(i))throw new s(null,"TypeNotAllowedInFeature",null);const r=t.toLowerCase();if(void 0===this.attributes[t]){for(const e in this.attributes)if(e.toLowerCase()===r)return void(this.attributes[e]=i);this.attributes[t]=i}else this.attributes[t]=i}hasField(e){const t=e.toLowerCase();if(void 0!==this.attributes[e])return!0;for(const i in this.attributes)if(i.toLowerCase()===t)return!0;return!!this._hasFieldDefinition(t)}keys(){let e=[];const t={};for(const i in this.attributes)e.push(i),t[i.toLowerCase()]=1;if(null!==this._layer)for(let i=0;i<this._layer.fields.length;i++){const s=this._layer.fields[i];1!==t[s.name.toLowerCase()]&&e.push(s.name)}return e=e.sort(),e}static parseAttributesFromDictionary(e){const t={};for(const i in e.attributes){const r=e.attributes[i];if(!d(r))throw new s(null,"InvalidParameter",null);t[i]=r}return t}static fromJson(e,t){let i=null;null!==e.geometry&&void 0!==e.geometry&&(i=p(e.geometry));const r={};if(null!==e.attributes&&void 0!==e.attributes)for(const o in e.attributes){const t=e.attributes[o];if(null===t)r[o]=t;else{if(!(T(t)||g(t)||F(t)||u(t)||a(t)||l(t)))throw new s(null,"InvalidParameter",null);r[o]=t}}return x.createFromGraphicLikeObject(i,r,null,t??null)}fullSchema(){return this._layer}gdbVersion(){if(null===this._layer)return"";const e=this._layer.gdbVersion;return void 0===e?"":""===e&&this._layer.capabilities?.isVersioned?"SDE.DEFAULT":e}castAsJson(e){const t={attributes:{},geometry:!0===e?.keepGeometryType?this.geometry():this.geometry()?.toJSON()??null};for(const i in this.attributes){const s=this.attributes[i];void 0!==s&&(t.attributes[i]=m(s,e))}return t}async castAsJsonAsync(e=null,t){return this.castAsJson(t)}}t(x);export{x as default};
5
+ import{ArcadeDate as e}from"./ArcadeDate.js";import{configureDeepClone as t}from"./deepClone.js";import i from"./Dictionary.js";import{ArcadeExecutionError as s}from"./executionError.js";import{m as r,c as n,t as a,d as o,e as l,g as d,f as u,a as m}from"../chunks/languageUtils.js";import{constructGeometryFromDictionary as y}from"./geometry/constructors.js";import{DateOnly as c}from"../core/sql/DateOnly.js";import{TimeOnly as f}from"../core/sql/TimeOnly.js";import h from"../geometry/Geometry.js";import{fromJSON as p}from"../geometry/support/jsonUtils.js";import{convertToGeometry as _}from"../layers/graphics/featureConversionUtils.js";import T from"../layers/support/FieldsIndex.js";import{isString as g,isNumber as F,isBoolean as b,isDate as x}from"../support/guards.js";function D(e){switch(e.type){case"small-integer":case"esriFieldTypeSmallInteger":case"integer":case"esriFieldTypeInteger":case"single":case"esriFieldTypeSingle":case"double":case"esriFieldTypeDouble":case"big-integer":case"esriFieldTypeBigInteger":case"long":case"esriFieldTypeLong":case"oid":case"esriFieldTypeOID":return{name:e.name,type:"number"};case"global-id":case"esriFieldTypeGlobalID":case"guid":case"esriFieldTypeGUID":case"string":case"esriFieldTypeString":return{name:e.name,type:"text"};case"date":case"esriFieldTypeDate":case"timestamp-offset":case"esriFieldTypeTimestampOffset":return{name:e.name,type:"date"};case"date-only":case"esriFieldTypeDateOnly":return{name:e.name,type:"dateOnly"};case"time-only":case"esriFieldTypeTimeOnly":return{name:e.name,type:"time"};default:return null}}function w(t,i,s){if(null==t)return null;switch(i){case"time-only":return d(t)?t:f.fromReader(t.toString());case"date-only":return u(t)?t:c.fromReader(t.toString());case"timestamp-offset":return l(t)?t:e.fromReaderAsTimeStampOffset(t.toString());case"date":return l(t)?t:x(t)?e.dateJSAndZoneToArcadeDate(t,s):e.epochToArcadeDate(t,s);case"geometry":return null;default:return t}}class I{constructor(){this.arcadeDeclaredClass="esri.arcade.Feature",this._optimizedGeomDefinition=null,this._geometry=null,this.attributes=null,this._layer=null,this._fieldTypesFixed=!0,this.fieldsIndex=null,this.contextTimeZone=null,this.immutable=!0,this._fieldsToFixDataTypes=null,this.immutable=!0}static createFromGraphic(e,t){const i=new I;return i.contextTimeZone=t??null,i._geometry=null!=e.geometry?e.geometry:null,void 0===e.attributes||null===e.attributes?i.attributes={}:i.attributes=e.attributes,e._sourceLayer?(i._layer=e._sourceLayer,i._fieldTypesFixed=!1):e._layer?(i._layer=e._layer,i._fieldTypesFixed=!1):e.layer&&"fields"in e.layer?(i._layer=e.layer,i._fieldTypesFixed=!1):e.sourceLayer&&"fields"in e.sourceLayer&&(i._layer=e.sourceLayer,i._fieldTypesFixed=!1),i._layer&&!i._fieldTypesFixed&&(i.fieldsIndex=this.hydrateFieldsIndex(i._layer)),i}static createFromArcadeFeature(e){if(e instanceof I){const t=new I;return t._fieldTypesFixed=e._fieldTypesFixed,t.attributes=e.attributes,t._geometry=e._geometry,t._optimizedGeomDefinition=e._optimizedGeomDefinition,e._layer&&(t._layer=e._layer),t.fieldsIndex=e.fieldsIndex,t.contextTimeZone=e.contextTimeZone,t}const t={};for(const i of e.keys())t[i]=e.field(i);return I.createFromGraphicLikeObject(e.geometry(),t,e.fullSchema(),e.contextTimeZone)}static createFromOptimisedFeature(e,t,i){const s=new I;return s._geometry=e.geometry?{geometry:e.geometry}:null,s._optimizedGeomDefinition=i,s.attributes=e.attributes||{},s._layer=t,s._fieldTypesFixed=!1,s}static createFromArcadeDictionary(e,t){const s=new I;return s.attributes=e.field("attributes"),null!==s.attributes&&s.attributes instanceof i?(s.attributes=s.attributes.attributes,null===s.attributes&&(s.attributes={})):s.attributes={},s._geometry=e.field("geometry"),null!==s._geometry&&(s._geometry instanceof i?s._geometry=y(s._geometry,t):s._geometry instanceof h||(s._geometry=null)),s}static createFromGraphicLikeObject(e,t,i=null,s){const r=new I;return r.contextTimeZone=s??null,null===t&&(t={}),r.attributes=t,r._geometry=null!=e?e:null,r._layer=i,r._layer&&(r._fieldTypesFixed=!1,r.fieldsIndex=this.hydrateFieldsIndex(r._layer)),r}static hydrateFieldsIndex(e){return null===e?null:r(e)?e.getFieldsIndex():e.fieldsIndex?e.fieldsIndex:T.fromLayerJSON({datesInUnknownTimezone:e.datesInUnknownTimezone,fields:e.fields,timeInfo:e.timeInfo,editFieldsInfo:e.editFieldsInfo,dateFieldsTimeReference:e.dateFieldsTimeReference??{timeZone:"UTC",respectsDaylightSaving:!1}})}repurposeFromGraphicLikeObject(e,t,i=null){null===t&&(t={}),this.attributes=t,this._geometry=e??null,this._layer=i,this._layer?this._fieldTypesFixed=!1:this._fieldTypesFixed=!0}castToText(e=!1){!1===this._fieldTypesFixed&&this._fixFieldTypes();const t=n(this.attributes,{useNumbersForDates:e});return'{"geometry":'+(null===this.geometry()?"null":a(this.geometry()))+',"attributes":'+t+"}"}_fixFieldTypes(){if(this._fieldsToFixDataTypes&&this._fieldsToFixDataTypes?.length>0)return this._fixAllFields(this._fieldsToFixDataTypes),void(this._fieldTypesFixed=!0);const e=[],t=this._layer.fields;for(let i=0;i<(t?.length??0);i++){const s=t[i],{name:r,type:n}=s;switch(n){case"date":case"esriFieldTypeDate":e.push({field:r,dataType:"date"});break;case"date-only":case"esriFieldTypeDateOnly":e.push({field:r,dataType:"date-only"});break;case"time-only":case"esriFieldTypeTimeOnly":e.push({field:r,dataType:"time-only"});break;case"timestamp-offset":case"esriFieldTypeTimestampOffset":e.push({field:r,dataType:"timestamp-offset"});break;case"geometry":case"esriFieldTypeGeometry":e.push({field:r,dataType:"geometry"})}}this._fieldsToFixDataTypes=e,e.length>0&&this._fixAllFields(e),this._fieldTypesFixed=!0}isUnknownDateTimeField(e){return"unknown"===this.fieldsIndex?.getTimeZone(e)}_fixAllFields(e){this.attributes={...this.attributes};const t=this.contextTimeZone??"system";for(let i=0;i<e.length;i++){const s=e[i].field,r=e[i].dataType;let n=this.attributes[s];if(void 0===n){for(const e in this.attributes)if(e.toLowerCase()===s.toLowerCase()){n=this.attributes[e],this.attributes[e]=w(n,r,this.isUnknownDateTimeField(e)?"unknown":t);break}}else null!==n&&(this.attributes[s]=w(n,r,this.isUnknownDateTimeField(s)?"unknown":t))}}geometry(){return null===this._geometry||this._geometry instanceof h||(this._optimizedGeomDefinition?(this._geometry=p(_(this._geometry,this._optimizedGeomDefinition.geometryType,this._optimizedGeomDefinition.hasZ,this._optimizedGeomDefinition.hasM)),this._geometry.spatialReference=this._optimizedGeomDefinition.spatialReference):this._geometry=p(this._geometry)),this._geometry}field(e){this._fieldTypesFixed||this._fixFieldTypes();const t=this.attributes[e];if(void 0!==t)return t;const i=e.toLowerCase();for(const s in this.attributes)if(s.toLowerCase()===i)return this.attributes[s];if(this._hasFieldDefinition(i))return null;throw new s(null,"FieldNotFound",null,{key:e})}_hasFieldDefinition(e){if(null===this._layer)return!1;for(let t=0;t<this._layer.fields.length;t++){if(this._layer.fields[t].name.toLowerCase()===e)return!0}return!1}setField(t,i){if(this.immutable)throw new s(null,"Immutable",null);if(i instanceof Date&&(i=this.isUnknownDateTimeField(t)?e.unknownDateJSToArcadeDate(i):e.dateJSToArcadeDate(i)),!1===o(i))throw new s(null,"TypeNotAllowedInFeature",null);const r=t.toLowerCase();if(void 0===this.attributes[t]){for(const e in this.attributes)if(e.toLowerCase()===r)return void(this.attributes[e]=i);this.attributes[t]=i}else this.attributes[t]=i}hasField(e){const t=e.toLowerCase();if(void 0!==this.attributes[e])return!0;for(const i in this.attributes)if(i.toLowerCase()===t)return!0;return!!this._hasFieldDefinition(t)}keys(){let e=[];const t={};for(const i in this.attributes)e.push(i),t[i.toLowerCase()]=1;if(null!==this._layer)for(let i=0;i<this._layer.fields.length;i++){const s=this._layer.fields[i];1!==t[s.name.toLowerCase()]&&e.push(s.name)}return e=e.sort(),e}static parseAttributesFromDictionary(e){const t={};for(const i in e.attributes){const r=e.attributes[i];if(!o(r))throw new s(null,"InvalidParameter",null);t[i]=r}return t}static fromJson(e,t){let i=null;null!==e.geometry&&void 0!==e.geometry&&(i=p(e.geometry));const r={};if(null!==e.attributes&&void 0!==e.attributes)for(const n in e.attributes){const t=e.attributes[n];if(null===t)r[n]=t;else{if(!(g(t)||F(t)||b(t)||l(t)||d(t)||u(t)))throw new s(null,"InvalidParameter",null);r[n]=t}}return I.createFromGraphicLikeObject(i,r,null,t??null)}fullSchema(){return this._layer}gdbVersion(){if(null===this._layer)return"";const e=this._layer.gdbVersion;return void 0===e?"":""===e&&this._layer.capabilities?.isVersioned?"SDE.DEFAULT":e}castAsJson(e){const t={attributes:{},geometry:!0===e?.keepGeometryType?this.geometry():this.geometry()?.toJSON()??null};for(const i in this.attributes){const s=this.attributes[i];void 0!==s&&(t.attributes[i]=m(s,e))}return t}async castAsJsonAsync(e=null,t){return this.castAsJson(t)}}t(I);export{I as Feature,w as convertAttributeToArcadeValue,D as getArcadeVariableForField};
package/arcade/Pixel.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.34/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as r}from"./ArcadeDate.js";import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeExecutionError as t}from"./executionError.js";import s from"./ImmutableArray.js";import{d as i,c as a}from"../chunks/languageUtils.js";import o from"../core/Logger.js";import{getOrCreateMapValue as n}from"../core/MapUtils.js";import{isImageryGraphicOrigin as m}from"../graphic/isImageryGraphicOrigin.js";import{isImageryTileGraphicOrigin as l}from"../graphic/isImageryTileGraphicOrigin.js";import{isRasterPixelValueField as p}from"../layers/support/fieldUtils.js";import{rasterFieldPrefix as u}from"../layers/support/rasterFieldUtils.js";import{isDate as c}from"../support/guards.js";const f=()=>o.getLogger("esri.arcade.Pixel");class d{constructor(r,t,s){this._graphic=t,this._timeZone=s,this.arcadeDeclaredClass="esri.arcade.Pixel",this._values=new Map,this._fields=new Map(r.map(r=>[e(r.name),r]))}static fromImageryGraphic(r,e){if(!m(r.origin)&&!l(r.origin))throw new t(null,"InvalidParameter",null);const s=r.origin.layer.rasterFields.filter(r=>r.name.startsWith(u));return new d(s,r,e)}keys(){return Array.from(this._fields.values()).map(r=>r.name).sort()}hasField(r){return this._fields.has(e(r))}field(a){const o=this._fields.get(e(a));if(null==o)throw new t(null,"FieldNotFound",null,{key:a});return n(this._values,o.name,()=>{const e=this._graphic.getAttribute(o.name);return p(o.name)&&"string"==typeof e?new s(e.split(/,\s*|\s+/)):c(e)?r.dateJSAndZoneToArcadeDate(e,this._timeZone??"system"):i(e)?e:(f().warn(`Unsupported type for attribute: ${o.name}. Ignoring value.`),null)})}castToText(r=!1){const e={};for(const t of this._fields.values())e[t.name]=this.field(t.name);return a(e,{useNumbersForDates:r})}}export{d as Pixel};
5
+ import{toSymbolId as r}from"./arcadeEnvironment.js";import{ArcadeExecutionError as e}from"./executionError.js";import{getArcadeVariableForField as t,convertAttributeToArcadeValue as s}from"./Feature.js";import i from"./ImmutableArray.js";import{d as a,c as n}from"../chunks/languageUtils.js";import o from"../core/Logger.js";import{getOrCreateMapValue as l}from"../core/MapUtils.js";import{isImageryGraphicOrigin as m}from"../graphic/isImageryGraphicOrigin.js";import{isImageryTileGraphicOrigin as p}from"../graphic/isImageryTileGraphicOrigin.js";import{isRasterPixelValueField as u}from"../layers/support/fieldUtils.js";import{rasterFieldPrefix as f}from"../layers/support/rasterFieldUtils.js";import{isDate as c}from"../support/guards.js";const g=()=>o.getLogger("esri.arcade.Pixel");function h(r){return r.rasterFields.filter(r=>r.name.startsWith(f))}class d{constructor(e,t,s){this._graphic=t,this._timeZone=s,this.arcadeDeclaredClass="esri.arcade.Pixel",this._values=new Map,this._fields=new Map(e.map(e=>[r(e.name),e]))}static fromImageryGraphic(r,t){if(!m(r.origin)&&!p(r.origin))throw new e(null,"InvalidParameter",null);return new d(h(r.origin.layer),r,t)}static getDeclaredMembers(r){return h(r).map(r=>u(r.name)&&"string"===r.type?{name:r.name,type:"array",elementType:{type:"text"}}:t(r)).filter(r=>null!=r)}keys(){return Array.from(this._fields.values()).map(r=>r.name).sort()}hasField(e){return this._fields.has(r(e))}field(t){const n=this._fields.get(r(t));if(null==n)throw new e(null,"FieldNotFound",null,{key:t});return l(this._values,n.name,()=>{const r=this._graphic.getAttribute(n.name);return null==r?null:u(n.name)&&"string"==typeof r?new i(r.split(/,\s*|\s+/)):c(r)||a(r)?s(r,n.type,this._timeZone??"system"):(g().warn(`Unsupported type for attribute: ${n.name}. Ignoring value.`),null)})}castToText(r=!1){const e={};for(const t of this._fields.values())e[t.name]=this.field(t.name);return n(e,{useNumbersForDates:r})}}export{d as Pixel};
package/arcade/Voxel.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.34/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as t}from"./ArcadeDate.js";import{ArcadeExecutionError as e}from"./executionError.js";import r from"./ImmutableArray.js";import{c as i}from"../chunks/languageUtils.js";import{isDate as s}from"../support/guards.js";const o="Voxel.Position",n="Voxel.LocalTime";function a(t){const i=t.getAttribute(o);if("string"!=typeof i)throw new e(null,"InvalidParameter",null);const s=JSON.parse(i);if(!Array.isArray(s)||"number"!=typeof s[0]||"number"!=typeof s[1]||"number"!=typeof s[2])throw new e(null,"InvalidParameter",null);return new r(s)}function l(r,i){const o=r.getAttribute(n);if(null==o)return null;if(!s(o))throw new e(null,"InvalidParameter",null);return t.dateJSAndZoneToArcadeDate(o,i)}class u{constructor(t,e){this._graphic=t,this._timeZone=e,this.arcadeDeclaredClass="esri.arcade.Voxel",this._layer=t.sourceLayer}getPosition(){return void 0!==this._position?this._position:this._position=a(this._graphic)}getLocalTime(){return void 0!==this._localTime?this._localTime:this._localTime=l(this._graphic,this._timeZone??"system")}keys(){return this._layer.fields.map(t=>t.name).sort()}hasField(t){return this._layer.fieldsIndex.has(t)}field(t){const r=this._layer.fieldsIndex?.get(t)?.name;if(null==r)throw new e(null,"FieldNotFound",null,{key:t});switch(r){case o:return this.getPosition();case n:return this.getLocalTime()}return this._graphic.attributes[r]??null}castToText(t=!1){const e={...this._graphic.attributes};e[o]=this.getPosition(),n in e&&(e[n]=this.getLocalTime());for(const r of Object.keys(e))this._layer.fieldsIndex?.has(r)||delete e[r];return i(e,{useNumbersForDates:t})}}export{u as Voxel};
5
+ import{ArcadeDate as e}from"./ArcadeDate.js";import{ArcadeExecutionError as t}from"./executionError.js";import r from"./ImmutableArray.js";import{c as i}from"../chunks/languageUtils.js";import{isDate as n}from"../support/guards.js";const s="Voxel.Position",a="Voxel.LocalTime";function o(e){const i=e.getAttribute(s);if("string"!=typeof i)throw new t(null,"InvalidParameter",null);const n=JSON.parse(i);if(!Array.isArray(n)||"number"!=typeof n[0]||"number"!=typeof n[1]||"number"!=typeof n[2])throw new t(null,"InvalidParameter",null);return new r(n)}function l(r,i){const s=r.getAttribute(a);if(null==s)return null;if(!n(s))throw new t(null,"InvalidParameter",null);return e.dateJSAndZoneToArcadeDate(s,i)}class u{constructor(e,t){this._graphic=e,this._timeZone=t,this.arcadeDeclaredClass="esri.arcade.Voxel",this._layer=e.sourceLayer}static getDeclaredMembers(e){return e.fields.map(e=>{switch(e.name){case s:return{name:e.name,type:"array",elementType:{type:"number"}};case a:return{name:e.name,type:"date"};default:switch(e.type){case"string":return{name:e.name,type:"text"};case"double":return{name:e.name,type:"number"}}return null}}).filter(e=>null!=e)}getPosition(){return void 0!==this._position?this._position:this._position=o(this._graphic)}getLocalTime(){return void 0!==this._localTime?this._localTime:this._localTime=l(this._graphic,this._timeZone??"system")}keys(){return this._layer.fields.map(e=>e.name).sort()}hasField(e){return this._layer.fieldsIndex.has(e)}field(e){const r=this._layer.fieldsIndex?.get(e)?.name;if(null==r)throw new t(null,"FieldNotFound",null,{key:e});switch(r){case s:return this.getPosition();case a:return this.getLocalTime()}return this._graphic.attributes[r]??null}castToText(e=!1){const t={...this._graphic.attributes};t[s]=this.getPosition(),a in t&&(t[a]=this.getLocalTime());for(const r of Object.keys(t))this._layer.fieldsIndex?.has(r)||delete t[r];return i(t,{useNumbersForDates:e})}}export{u as Voxel};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as a}from"./compilerUtils.js";import{getNestedOptionalValue as i,geometryMember as s,getGeometryKeys as c}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as u,ensureArcadeExecutionError as f}from"./executionError.js";import p from"./Feature.js";import{NativeFunction as w,ScopeMarshalledFunction as d,ArcadeFunction as h,wrapModuleScopedResponse as m}from"./FunctionWrapper.js";import{R as g,I as y,q as b,i as v,z as x,A as S,B as F,v as k,x as I,s as j,u as O,w as M,y as R,r as A,j as N,k as C,m as E,h as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as G}from"./treeAnalysis.js";import{A as U}from"../chunks/aiServices.js";import{A as K}from"../chunks/array.js";import{registerFunctions as L}from"./functions/date.js";import{registerFunctions as _}from"./functions/feature.js";import{registerFunctions as D}from"./functions/geomasync.js";import{registerFunctions as Z}from"./functions/geometry.js";import{registerFunctions as z}from"./functions/maths.js";import{registerFunctions as q}from"./functions/stats.js";import{registerFunctions as P}from"./functions/string.js";import{registerFunctions as W}from"./functions/track.js";import"../core/has.js";import V from"../core/Logger.js";import T from"../geometry/Geometry.js";import Y from"../geometry/SpatialReference.js";import{isGraphic as $,isBoolean as H,isString as J,isArray as Q,isNumber as X}from"../support/guards.js";const ee=()=>V.getLogger("esri.arcade.arcadeAsyncRuntime"),te=Symbol("uninitialized");function ne(e){if(e===te)throw new u(null,"InvalidIdentifier",null)}function re(e){return ne(e),e}function oe(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new u(t,"InvalidIdentifier",n)}function ae(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return ne(e),e.value}const a=t.globalScope[o];if(void 0!==a)return ne(a),a.value;throw new u(t,r,n)}const ie=function(){};async function se(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await we(e,t.arguments[r]));return n}async function ce(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await se(e,t))}ie.prototype=Object.freeze(Object.create(null));class le extends h{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}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,services:this.context.services,abortSignal:this.context.abortSignal,localScope:new ie,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",null);return ue(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return pe(e,t,(n,r,o)=>{const a={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:new ie,abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},track:e.track};if(a.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",t);return ue(a,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,async(o,a,i)=>{const s={spatialReference:e.spatialReference,services:e.services,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:new ie,track:e.track};return i=i.map(t=>!v(t)||t instanceof d?t:m(t,e,r)),m(await ue(s,this.definition.body,this._params,this._locals,i,t),n,r)})}}async function ue(e,t,n,r,o,a){if(n.length!==o.length)throw new u(e,"WrongNumberOfParameters",a);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=te}const i=await de(e,t);if(i instanceof g)return i.value;if(i===x)throw new u(e,"UnexpectedToken",a);if(i===S)throw new u(e,"UnexpectedToken",a);return i instanceof y?i.value:i}class fe extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t),r=this.moduleGlobalContext.globalScope[n];if(ne(r),v(r.value)&&!(r.value instanceof d)){const e=new d;return e.fn=r.value,e.parameterEvaluator=ce,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(v(n))throw new u(null,"AssignModuleFunction",null);const r=e(t);if(void 0===this.moduleGlobalContext.globalScope[r])throw new u(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static async load(e,n){const{globals:a,exports:i}=o(n),s=new Xe;for(const t of a)t in s||(s[t]=te);const c=e.spatialReference??Y.WebMercator,l={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??tt,abortSignal:e.abortSignal??t,timeZone:e.timeZone??null,spatialReference:c,track:null,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:i,localScope:null,globalScope:s};return await Ae(l,n),new fe(l)}}async function pe(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await se(e,t))}async function we(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await Ie(e,t);case"AssignmentExpression":return await Oe(e,t);case"TemplateLiteral":return await We(e,t);case"Identifier":return qe(e,t);case"MemberExpression":return await Le(e,t);case"Literal":return t.value;case"CallExpression":return await Pe(e,t);case"UnaryExpression":return await _e(e,t);case"BinaryExpression":return await Ze(e,t);case"LogicalExpression":return await ze(e,t);case"ArrayExpression":return await De(e,t);case"ObjectExpression":return await he(e,t);default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}async function de(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await Be(e,t);case"ExportNamedDeclaration":return await Ge(e,t);case"VariableDeclaration":return await Ue(e,t);case"BlockStatement":return await Ae(e,t);case"FunctionDeclaration":return await Ee(e,t);case"ReturnStatement":return await Ce(e,t);case"IfStatement":return await Re(e,t);case"ExpressionStatement":return await Me(e,t);case"ForStatement":return await ge(e,t);case"WhileStatement":return await me(e,t);case"ForInStatement":return await Fe(e,t);case"ForOfStatement":return await ke(e,t);case"BreakStatement":return x;case"EmptyStatement":return k;case"ContinueStatement":return S;default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}async function he(e,t){const n=[];for(let i=0;i<t.properties.length;i++){const r=t.properties[i],o=await we(e,r.value),a="Identifier"===r.key.type?r.key.name:await we(e,r.key);n[i]={key:a,value:o}}const r=Object.create(null),o=new Map;for(let i=0;i<n.length;i++){const a=n[i];if(v(a.value))throw new u(e,"NoFunctionInDictionary",t);if(!1===J(a.key))throw new u(e,"KeyMustBeString",t);let s=a.key.toString();const c=s.toLowerCase();o.has(c)?s=o.get(c):o.set(c,s),a.value===k?r[s]=null:r[s]=a.value}const a=new l(r);return a.immutable=!1,a}async function me(e,t){let n=await we(e,t.test);if(!1===n)return k;if(!0!==n)throw new u(e,"BooleanConditionRequired",t);for(;!0===n;){const r=await de(e,t.body);if(r===x)break;if(r instanceof g)return r;if(n=await we(e,t.test),!0!==n&&!1!==n)throw new u(e,"BooleanConditionRequired",t)}return k}async function ge(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await de(e,t.init):await we(e,t.init));;){if(null!==t.test){const n=await we(e,t.test);if(!0===e.abortSignal?.aborted)throw new u(e,"Cancelled",t);if(!1===n)break;if(!0!==n)throw new u(e,"BooleanConditionRequired",t)}const n=await de(e,t.body);if(n===x)break;if(n instanceof g)return n;null!==t.update&&await we(e,t.update)}return k}catch(n){throw n}}async function ye(e,t,n,r,o="i"){const a=n.length;for(let i=0;i<a;i++){if("k"===o){if(i>=n.length)throw new u(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]}}else r.scope[r.id]={value:i};const a=await de(e,t.body);if(a===x)break;if(a instanceof g)return a}return k}async function be(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.scope[r.id]="k"===o?{value:n.get(i)}:{value:i};const a=await de(e,t.body);if(a===x)break;if(a instanceof g)return a}return k}async function ve(e,t,n,r){const o=n.iterator(e.abortSignal);let a;for(;null!=(a=await o.next());){const o=p.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone);o._underlyingGraphic=a,r.scope[r.id]={value:o};const i=await de(e,t.body);if(i===x)break;if(i instanceof g)return i}return k}async function xe(e,t,n,r){for(const o of n.keys()){const a=n.field(o);r.scope[r.id]={value:l.containerEntry(o,a)};const i=await de(e,t.body);if(i===x)break;if(i instanceof g)return i}return k}async function Se(e,t,n,r){for(const o of c(n)){const a=s(n,o,e,t,1);r.scope[r.id]={value:l.containerEntry(o,a)};const i=await de(e,t.body);if(i===x)break;if(i instanceof g)return i}return k}async function Fe(e,t){const n=await we(e,t.right);"VariableDeclaration"===t.left.type&&await de(e,t.left);const r=oe(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);return Q(n)||J(n)?await ye(e,t,n,r):N(n)?await be(e,t,n,r):n instanceof l||A(n)?await ye(e,t,n.keys(),r,"k"):E(n)?await ve(e,t,n,r):B(n)?await ye(e,t,c(n),r,"k"):k}async function ke(e,t){const n=await we(e,t.right);"VariableDeclaration"===t.left.type&&await de(e,t.left);const r=oe(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);return Q(n)||J(n)?await ye(e,t,n,r,"k"):N(n)?await be(e,t,n,r,"k"):n instanceof l||A(n)?await xe(e,t,n,r):E(n)?await ve(e,t,n,r):B(n)?await Se(e,t,n,r):k}async function Ie(e,t){const n=t.argument;if("CallExpression"===n.type)throw new u(e,"NeverReach",t);if("MemberExpression"===n.type){const r=await we(e,n.object);let o,a;if(!0===n.computed)o=await we(e,n.property);else{if("Identifier"!==n.property.type)throw new u(e,"Unrecognized",t);o=n.property.name}if(Q(r)){if(!X(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new u(e,"OutOfBounds",t);a=j(r[o]),r[o]="++"===t.operator?a+1:a-1}else if(r instanceof l){if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t,{key:o});a=j(r.field(o)),r.setField(o,"++"===t.operator?a+1:a-1)}else if(r instanceof fe){if(!1===J(o))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);a=j(r.global(o)),r.setGlobal(o,"++"===t.operator?a+1:a-1)}else{if(!C(r))throw N(r)?new u(e,"Immutable",t):new u(e,"InvalidParameter",t);if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t,{key:o});a=j(r.field(o)),r.setField(o,"++"===t.operator?a+1:a-1)}return!1===t.prefix?a:"++"===t.operator?a+1:a-1}const r=oe(e,n),o=j(re(r.var).value),a="++"===t.operator?o+1:o-1;return r.scope[r.id]={value:a},!1===t.prefix?o:"++"===t.operator?o+1:o-1}function je(e,t,n,r,o){switch(t){case"=":return e===k?null:e;case"/=":return j(n)/j(e);case"*=":return j(n)*j(e);case"-=":return j(n)-j(e);case"+=":return J(n)||J(e)?O(n)+O(e):j(n)+j(e);case"%=":return j(n)%j(e);default:throw new u(o,"UnsupportedOperator",r)}}async function Oe(e,t){const n=t.left;if("MemberExpression"===n.type){const r=await we(e,n.object);let o;if(!0===n.computed)o=await we(e,n.property);else{if("Identifier"!==n.property.type)throw new u(e,"InvalidIdentifier",t);o=n.property.name}const a=await we(e,t.right);if(Q(r)){if(!X(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>r.length)throw new u(e,"OutOfBounds",t);if(o===r.length){if("="!==t.operator)throw new u(e,"OutOfBounds",t);r[o]=je(a,t.operator,r[o],t,e)}else r[o]=je(a,t.operator,r[o],t,e)}else if(r instanceof l){if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0===r.hasField(o))r.setField(o,je(a,t.operator,r.field(o),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:o});r.setField(o,je(a,t.operator,null,t,e))}}else if(r instanceof fe){if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);r.setGlobal(o,je(a,t.operator,r.global(o),t,e))}else{if(!C(r))throw N(r)?new u(e,"Immutable",t):new u(e,"InvalidParameter",t);if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0===r.hasField(o))r.setField(o,je(a,t.operator,r.field(o),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:o});r.setField(o,je(a,t.operator,null,t,e))}}return k}const r=oe(e,n),o=await we(e,t.right);return r.scope[r.id]={value:je(o,t.operator,"="!==t.operator?re(r.var).value:null,t,e)},k}async function Me(e,t){const n=await we(e,t.expression);return n===k?k:new y(n)}async function Re(e,t){const n=await we(e,t.test);if(!0===n)return de(e,t.consequent);if(!1===n)return null!==t.alternate?de(e,t.alternate):k;throw new u(e,"BooleanConditionRequired",t)}async function Ae(e,t){return Ne(e,t,0)}async function Ne(e,t,n){if(n>=t.body.length)return k;const r=await de(e,t.body[n]);return r instanceof g||r===x||r===S||n===t.body.length-1?r:Ne(e,t,n+1)}async function Ce(e,t){if(null===t.argument)return new g(k);const n=await we(e,t.argument);return new g(n)}async function Ee(t,n){if(null!=t.localScope)throw ee().error("Function declarations are only valid in global scope."),new u(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw ee().error(`Function "${r}" not declared.`),new u(t,"NeverReach",n);const o=a(n),i=n.params.map(t=>e(t)),s=Array.from(o).filter(e=>!i.includes(e));return t.globalScope[r]={value:new le(n,t,i,s)},k}async function Be(e,t){const n=oe(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw ee().error("Internal error: module loader not initialized"),new u(e,"NeverReach",t);const o=r.loadLibrary(n.id);let a;return r._moduleSingletons?.has(o.uri)?a=r._moduleSingletons.get(o.uri):(a=await fe.load(e,o.syntax),r._moduleSingletons?.set(o.uri,a)),n.scope[n.id]={value:a},k}async function Ge(e,t){return await de(e,t.declaration),k}async function Ue(e,t){for(const n of t.declarations)await Ke(e,n);return k}async function Ke(e,t){let n=null;n=null===t.init?null:await we(e,t.init),n===k&&(n=null);const r=oe(e,t.id);r.scope[r.id]={value:n}}async function Le(e,t){const n=await we(e,t.object);if(null===n)throw new u(e,"MemberOfNull",t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof l||A(n))return n.field(t.property.name);if(n instanceof T)return s(n,t.property.name,e,t);if(n instanceof fe){if(!n.hasGlobal(t.property.name))throw new u(e,"InvalidIdentifier",t);return n.global(t.property.name)}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}let r=await we(e,t.property);if(n instanceof l||A(n)){if(J(r))return n.field(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof fe){if(J(r))return n.global(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof T){if(J(r))return s(n,r,e,t);throw new u(e,"InvalidMemberAccessKey",t)}if(Q(n)){if(X(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(N(n)){if(X(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new u(e,"OutOfBounds",t);return n.get(r)}throw new u(e,"InvalidMemberAccessKey",t)}if(J(n)){if(X(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}async function _e(e,t){const n=await we(e,t.argument);if(H(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*j(n);if("+"===t.operator)return 1*j(n);if("~"===t.operator)return~j(n);throw new u(e,"UnsupportUnaryOperator",t)}if("-"===t.operator)return-1*j(n);if("+"===t.operator)return 1*j(n);if("~"===t.operator)return~j(n);throw new u(e,"UnsupportUnaryOperator",t)}async function De(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await we(e,t.elements[r]));for(let r=0;r<n.length;r++){if(v(n[r]))throw new u(e,"NoFunctionInArray",t);n[r]===k&&(n[r]=null)}return n}async function Ze(e,t){const n=await we(e,t.left),r=await we(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return R(j(n),j(r),t.operator);case"==":return I(n,r);case"!=":return!I(n,r);case"<":case">":case"<=":case">=":return M(n,r,t.operator);case"+":return J(n)||J(r)?O(n)+O(r):j(n)+j(r);case"-":return j(n)-j(r);case"*":return j(n)*j(r);case"/":return j(n)/j(r);case"%":return j(n)%j(r);default:throw new u(e,"UnsupportedOperator",t)}}async function ze(e,t){const n=await we(e,t.left);if(!H(n))throw new u(e,"LogicalExpressionOnlyBoolean",t);switch(t.operator){case"||":{if(!0===n)return n;const r=await we(e,t.right);if(H(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=await we(e,t.right);if(H(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}default:throw new u(e,"LogicExpressionOrAnd",t)}}function qe(e,t){return ae(e,t)}async function Pe(e,t){if("MemberExpression"===t.callee.type){const n=await we(e,t.callee.object);if(!(n instanceof fe))throw new u(e,"FunctionNotFound",t);const r=!1===t.callee.computed?t.callee.property.name:await we(e,t.callee.property);if(!n.hasGlobal(r))throw new u(e,"FunctionNotFound",t);const o=n.global(r);if(!v(o))throw new u(e,"CallNonFunction",t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new u(e,"FunctionNotFound",t);const n=ae(e,t.callee,"FunctionNotFound");if(v(n))return n.call(e,t);throw new u(e,"CallNonFunction",t)}async function We(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){if(t.expressions[r]){const o=await we(e,t.expressions[r]);if(v(o))throw new u(e,"NoFunctionInTemplateLiteral",t);n+=O(o)}r++}return n}async function Ve(e,t){F(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await we(e,t.arguments[0]);if(!1===H(n))throw new u(e,"BooleanConditionRequired",t);return we(e,n?t.arguments[1]:t.arguments[2])}async function Te(e,t){F(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await we(e,t.arguments[0]);if(3===t.arguments.length){const r=await we(e,t.arguments[1]),o=i(n,r);return null!=o&&""!==o?o:we(e,t.arguments[2])}return null==n||""===n?we(e,t.arguments[1]):n}async function Ye(e,t){if(t.arguments.length<2)throw new u(e,"WrongNumberOfParameters",t);if(2===t.arguments.length)return we(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new u(e,"WrongNumberOfParameters",t);return $e(e,t,1,await we(e,t.arguments[0]))}async function $e(e,t,n,r){const o=await we(e,t.arguments[n]);if(I(o,r))return we(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?we(e,t.arguments[n]):2===a?null:3===a?we(e,t.arguments[n+2]):$e(e,t,n+2,r)}async function He(e,t){if(t.arguments.length<3)throw new u(e,"WrongNumberOfParameters",t);if(t.arguments.length%2==0)throw new u(e,"WrongNumberOfParameters",t);const n=await we(e,t.arguments[0]);if(!1===H(n))throw new u(e,"BooleanConditionRequired",t.arguments[0]);return Je(e,t,0,n)}async function Je(e,t,n,r){if(!0===r)return we(e,t.arguments[n+1]);if(3===t.arguments.length-n)return we(e,t.arguments[n+2]);const o=await we(e,t.arguments[n+2]);if(!1===H(o))throw new u(e,"ModuleExportNotFound",t.arguments[n+2]);return Je(e,t,n+2,o)}function Qe(){const e=Object.create(null);L(e,ce),P(e,ce),_(e,ce,qe),z(e,ce),Z(e,ce),q(e,ce),W(e,ce),D({functions:e,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:ce,standardFunctionAsync:pe}),e.iif=Ve,e.defaultvalue=Te,e.decode=Ye,e.when=He;const t=function(){this.textformatting={value:l.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new w(r)});return t}const Xe=Qe();function et(e){const t={mode:"async",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ce,standardFunctionAsync:pe,evaluateIdentifier:qe};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Xe.prototype[n]=Object.freeze({value:new w(r)});for(let n=0;n<t.signatures.length;n++)G(t.signatures[n],"async")}function tt(e){console.log(e)}function nt(n,a){const i=new Set(Object.keys(a?.vars||{}).map(t=>e(t))),s=new Set(Object.keys(a?.customfunctions||{}).map(t=>e(t))),{globals:c,exports:l}=o(n);return async e=>{const o=e.spatialReference??Y.WebMercator;let a=null;n.usesModules&&(a=new r(new Map,n.loadedModules));const f=new Xe;for(const t of s)null!=e.customfunctions&&t in e.customfunctions?f[t]={value:new w(e.customfunctions[t])}:f[t]=te;for(const t of i){if(null==e.vars||!(t in e.vars)){t in f||(f[t]=te);continue}const n=e.vars[t]??null;$(n)?f[t]={value:p.createFromGraphic(n,e.timeZone??null)}:f[t]={value:n}}for(const t of c)t in f||(f[t]=te);const d={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??tt,abortSignal:e.abortSignal??t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:a,exports:l,localScope:null,globalScope:f},h=await Ae(d,n);if(h instanceof g||h instanceof y){const e=h.value;if(b(e))return null;if(v(e))throw new u(d,"IllegalResult",null);return e}if(b(h))return null;if(h===x)throw new u(d,"IllegalResult",null);if(h===S)throw new u(d,"IllegalResult",null);throw new u(d,"NeverReach",null)}}function rt(e,t){return nt(e,t)(t)}et([K]),et([U]);export{rt as executeScript,et as extend,nt as prepareScript};
5
+ import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as a}from"./compilerUtils.js";import{getNestedOptionalValue as i,geometryMember as s,getGeometryKeys as c}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as u,ensureArcadeExecutionError as f}from"./executionError.js";import{Feature as p}from"./Feature.js";import{NativeFunction as w,ScopeMarshalledFunction as d,ArcadeFunction as h,wrapModuleScopedResponse as m}from"./FunctionWrapper.js";import{R as g,I as y,q as b,i as v,z as x,A as S,B as F,v as k,x as I,s as j,u as O,w as M,y as R,r as A,j as N,k as C,m as E,h as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as G}from"./treeAnalysis.js";import{A as U}from"../chunks/aiServices.js";import{A as K}from"../chunks/array.js";import{registerFunctions as L}from"./functions/date.js";import{registerFunctions as _}from"./functions/feature.js";import{registerFunctions as D}from"./functions/geomasync.js";import{registerFunctions as Z}from"./functions/geometry.js";import{registerFunctions as z}from"./functions/maths.js";import{registerFunctions as q}from"./functions/stats.js";import{registerFunctions as P}from"./functions/string.js";import{registerFunctions as W}from"./functions/track.js";import"../core/has.js";import V from"../core/Logger.js";import T from"../geometry/Geometry.js";import Y from"../geometry/SpatialReference.js";import{isGraphic as $,isBoolean as H,isString as J,isArray as Q,isNumber as X}from"../support/guards.js";const ee=()=>V.getLogger("esri.arcade.arcadeAsyncRuntime"),te=Symbol("uninitialized");function ne(e){if(e===te)throw new u(null,"InvalidIdentifier",null)}function re(e){return ne(e),e}function oe(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new u(t,"InvalidIdentifier",n)}function ae(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return ne(e),e.value}const a=t.globalScope[o];if(void 0!==a)return ne(a),a.value;throw new u(t,r,n)}const ie=function(){};async function se(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await we(e,t.arguments[r]));return n}async function ce(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await se(e,t))}ie.prototype=Object.freeze(Object.create(null));class le extends h{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}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,services:this.context.services,abortSignal:this.context.abortSignal,localScope:new ie,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",null);return ue(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return pe(e,t,(n,r,o)=>{const a={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:new ie,abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},track:e.track};if(a.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",t);return ue(a,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,async(o,a,i)=>{const s={spatialReference:e.spatialReference,services:e.services,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:new ie,track:e.track};return i=i.map(t=>!v(t)||t instanceof d?t:m(t,e,r)),m(await ue(s,this.definition.body,this._params,this._locals,i,t),n,r)})}}async function ue(e,t,n,r,o,a){if(n.length!==o.length)throw new u(e,"WrongNumberOfParameters",a);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=te}const i=await de(e,t);if(i instanceof g)return i.value;if(i===x)throw new u(e,"UnexpectedToken",a);if(i===S)throw new u(e,"UnexpectedToken",a);return i instanceof y?i.value:i}class fe extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t),r=this.moduleGlobalContext.globalScope[n];if(ne(r),v(r.value)&&!(r.value instanceof d)){const e=new d;return e.fn=r.value,e.parameterEvaluator=ce,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(v(n))throw new u(null,"AssignModuleFunction",null);const r=e(t);if(void 0===this.moduleGlobalContext.globalScope[r])throw new u(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static async load(e,n){const{globals:a,exports:i}=o(n),s=new Xe;for(const t of a)t in s||(s[t]=te);const c=e.spatialReference??Y.WebMercator,l={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??tt,abortSignal:e.abortSignal??t,timeZone:e.timeZone??null,spatialReference:c,track:null,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:i,localScope:null,globalScope:s};return await Ae(l,n),new fe(l)}}async function pe(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await se(e,t))}async function we(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await Ie(e,t);case"AssignmentExpression":return await Oe(e,t);case"TemplateLiteral":return await We(e,t);case"Identifier":return qe(e,t);case"MemberExpression":return await Le(e,t);case"Literal":return t.value;case"CallExpression":return await Pe(e,t);case"UnaryExpression":return await _e(e,t);case"BinaryExpression":return await Ze(e,t);case"LogicalExpression":return await ze(e,t);case"ArrayExpression":return await De(e,t);case"ObjectExpression":return await he(e,t);default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}async function de(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await Be(e,t);case"ExportNamedDeclaration":return await Ge(e,t);case"VariableDeclaration":return await Ue(e,t);case"BlockStatement":return await Ae(e,t);case"FunctionDeclaration":return await Ee(e,t);case"ReturnStatement":return await Ce(e,t);case"IfStatement":return await Re(e,t);case"ExpressionStatement":return await Me(e,t);case"ForStatement":return await ge(e,t);case"WhileStatement":return await me(e,t);case"ForInStatement":return await Fe(e,t);case"ForOfStatement":return await ke(e,t);case"BreakStatement":return x;case"EmptyStatement":return k;case"ContinueStatement":return S;default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}async function he(e,t){const n=[];for(let i=0;i<t.properties.length;i++){const r=t.properties[i],o=await we(e,r.value),a="Identifier"===r.key.type?r.key.name:await we(e,r.key);n[i]={key:a,value:o}}const r=Object.create(null),o=new Map;for(let i=0;i<n.length;i++){const a=n[i];if(v(a.value))throw new u(e,"NoFunctionInDictionary",t);if(!1===J(a.key))throw new u(e,"KeyMustBeString",t);let s=a.key.toString();const c=s.toLowerCase();o.has(c)?s=o.get(c):o.set(c,s),a.value===k?r[s]=null:r[s]=a.value}const a=new l(r);return a.immutable=!1,a}async function me(e,t){let n=await we(e,t.test);if(!1===n)return k;if(!0!==n)throw new u(e,"BooleanConditionRequired",t);for(;!0===n;){const r=await de(e,t.body);if(r===x)break;if(r instanceof g)return r;if(n=await we(e,t.test),!0!==n&&!1!==n)throw new u(e,"BooleanConditionRequired",t)}return k}async function ge(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await de(e,t.init):await we(e,t.init));;){if(null!==t.test){const n=await we(e,t.test);if(!0===e.abortSignal?.aborted)throw new u(e,"Cancelled",t);if(!1===n)break;if(!0!==n)throw new u(e,"BooleanConditionRequired",t)}const n=await de(e,t.body);if(n===x)break;if(n instanceof g)return n;null!==t.update&&await we(e,t.update)}return k}catch(n){throw n}}async function ye(e,t,n,r,o="i"){const a=n.length;for(let i=0;i<a;i++){if("k"===o){if(i>=n.length)throw new u(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]}}else r.scope[r.id]={value:i};const a=await de(e,t.body);if(a===x)break;if(a instanceof g)return a}return k}async function be(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.scope[r.id]="k"===o?{value:n.get(i)}:{value:i};const a=await de(e,t.body);if(a===x)break;if(a instanceof g)return a}return k}async function ve(e,t,n,r){const o=n.iterator(e.abortSignal);let a;for(;null!=(a=await o.next());){const o=p.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone);o._underlyingGraphic=a,r.scope[r.id]={value:o};const i=await de(e,t.body);if(i===x)break;if(i instanceof g)return i}return k}async function xe(e,t,n,r){for(const o of n.keys()){const a=n.field(o);r.scope[r.id]={value:l.containerEntry(o,a)};const i=await de(e,t.body);if(i===x)break;if(i instanceof g)return i}return k}async function Se(e,t,n,r){for(const o of c(n)){const a=s(n,o,e,t,1);r.scope[r.id]={value:l.containerEntry(o,a)};const i=await de(e,t.body);if(i===x)break;if(i instanceof g)return i}return k}async function Fe(e,t){const n=await we(e,t.right);"VariableDeclaration"===t.left.type&&await de(e,t.left);const r=oe(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);return Q(n)||J(n)?await ye(e,t,n,r):N(n)?await be(e,t,n,r):n instanceof l||A(n)?await ye(e,t,n.keys(),r,"k"):E(n)?await ve(e,t,n,r):B(n)?await ye(e,t,c(n),r,"k"):k}async function ke(e,t){const n=await we(e,t.right);"VariableDeclaration"===t.left.type&&await de(e,t.left);const r=oe(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);return Q(n)||J(n)?await ye(e,t,n,r,"k"):N(n)?await be(e,t,n,r,"k"):n instanceof l||A(n)?await xe(e,t,n,r):E(n)?await ve(e,t,n,r):B(n)?await Se(e,t,n,r):k}async function Ie(e,t){const n=t.argument;if("CallExpression"===n.type)throw new u(e,"NeverReach",t);if("MemberExpression"===n.type){const r=await we(e,n.object);let o,a;if(!0===n.computed)o=await we(e,n.property);else{if("Identifier"!==n.property.type)throw new u(e,"Unrecognized",t);o=n.property.name}if(Q(r)){if(!X(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new u(e,"OutOfBounds",t);a=j(r[o]),r[o]="++"===t.operator?a+1:a-1}else if(r instanceof l){if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t,{key:o});a=j(r.field(o)),r.setField(o,"++"===t.operator?a+1:a-1)}else if(r instanceof fe){if(!1===J(o))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);a=j(r.global(o)),r.setGlobal(o,"++"===t.operator?a+1:a-1)}else{if(!C(r))throw N(r)?new u(e,"Immutable",t):new u(e,"InvalidParameter",t);if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t,{key:o});a=j(r.field(o)),r.setField(o,"++"===t.operator?a+1:a-1)}return!1===t.prefix?a:"++"===t.operator?a+1:a-1}const r=oe(e,n),o=j(re(r.var).value),a="++"===t.operator?o+1:o-1;return r.scope[r.id]={value:a},!1===t.prefix?o:"++"===t.operator?o+1:o-1}function je(e,t,n,r,o){switch(t){case"=":return e===k?null:e;case"/=":return j(n)/j(e);case"*=":return j(n)*j(e);case"-=":return j(n)-j(e);case"+=":return J(n)||J(e)?O(n)+O(e):j(n)+j(e);case"%=":return j(n)%j(e);default:throw new u(o,"UnsupportedOperator",r)}}async function Oe(e,t){const n=t.left;if("MemberExpression"===n.type){const r=await we(e,n.object);let o;if(!0===n.computed)o=await we(e,n.property);else{if("Identifier"!==n.property.type)throw new u(e,"InvalidIdentifier",t);o=n.property.name}const a=await we(e,t.right);if(Q(r)){if(!X(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>r.length)throw new u(e,"OutOfBounds",t);if(o===r.length){if("="!==t.operator)throw new u(e,"OutOfBounds",t);r[o]=je(a,t.operator,r[o],t,e)}else r[o]=je(a,t.operator,r[o],t,e)}else if(r instanceof l){if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0===r.hasField(o))r.setField(o,je(a,t.operator,r.field(o),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:o});r.setField(o,je(a,t.operator,null,t,e))}}else if(r instanceof fe){if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);r.setGlobal(o,je(a,t.operator,r.global(o),t,e))}else{if(!C(r))throw N(r)?new u(e,"Immutable",t):new u(e,"InvalidParameter",t);if(!1===J(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0===r.hasField(o))r.setField(o,je(a,t.operator,r.field(o),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:o});r.setField(o,je(a,t.operator,null,t,e))}}return k}const r=oe(e,n),o=await we(e,t.right);return r.scope[r.id]={value:je(o,t.operator,"="!==t.operator?re(r.var).value:null,t,e)},k}async function Me(e,t){const n=await we(e,t.expression);return n===k?k:new y(n)}async function Re(e,t){const n=await we(e,t.test);if(!0===n)return de(e,t.consequent);if(!1===n)return null!==t.alternate?de(e,t.alternate):k;throw new u(e,"BooleanConditionRequired",t)}async function Ae(e,t){return Ne(e,t,0)}async function Ne(e,t,n){if(n>=t.body.length)return k;const r=await de(e,t.body[n]);return r instanceof g||r===x||r===S||n===t.body.length-1?r:Ne(e,t,n+1)}async function Ce(e,t){if(null===t.argument)return new g(k);const n=await we(e,t.argument);return new g(n)}async function Ee(t,n){if(null!=t.localScope)throw ee().error("Function declarations are only valid in global scope."),new u(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw ee().error(`Function "${r}" not declared.`),new u(t,"NeverReach",n);const o=a(n),i=n.params.map(t=>e(t)),s=Array.from(o).filter(e=>!i.includes(e));return t.globalScope[r]={value:new le(n,t,i,s)},k}async function Be(e,t){const n=oe(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw ee().error("Internal error: module loader not initialized"),new u(e,"NeverReach",t);const o=r.loadLibrary(n.id);let a;return r._moduleSingletons?.has(o.uri)?a=r._moduleSingletons.get(o.uri):(a=await fe.load(e,o.syntax),r._moduleSingletons?.set(o.uri,a)),n.scope[n.id]={value:a},k}async function Ge(e,t){return await de(e,t.declaration),k}async function Ue(e,t){for(const n of t.declarations)await Ke(e,n);return k}async function Ke(e,t){let n=null;n=null===t.init?null:await we(e,t.init),n===k&&(n=null);const r=oe(e,t.id);r.scope[r.id]={value:n}}async function Le(e,t){const n=await we(e,t.object);if(null===n)throw new u(e,"MemberOfNull",t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof l||A(n))return n.field(t.property.name);if(n instanceof T)return s(n,t.property.name,e,t);if(n instanceof fe){if(!n.hasGlobal(t.property.name))throw new u(e,"InvalidIdentifier",t);return n.global(t.property.name)}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}let r=await we(e,t.property);if(n instanceof l||A(n)){if(J(r))return n.field(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof fe){if(J(r))return n.global(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof T){if(J(r))return s(n,r,e,t);throw new u(e,"InvalidMemberAccessKey",t)}if(Q(n)){if(X(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(N(n)){if(X(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new u(e,"OutOfBounds",t);return n.get(r)}throw new u(e,"InvalidMemberAccessKey",t)}if(J(n)){if(X(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}async function _e(e,t){const n=await we(e,t.argument);if(H(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*j(n);if("+"===t.operator)return 1*j(n);if("~"===t.operator)return~j(n);throw new u(e,"UnsupportUnaryOperator",t)}if("-"===t.operator)return-1*j(n);if("+"===t.operator)return 1*j(n);if("~"===t.operator)return~j(n);throw new u(e,"UnsupportUnaryOperator",t)}async function De(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await we(e,t.elements[r]));for(let r=0;r<n.length;r++){if(v(n[r]))throw new u(e,"NoFunctionInArray",t);n[r]===k&&(n[r]=null)}return n}async function Ze(e,t){const n=await we(e,t.left),r=await we(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return R(j(n),j(r),t.operator);case"==":return I(n,r);case"!=":return!I(n,r);case"<":case">":case"<=":case">=":return M(n,r,t.operator);case"+":return J(n)||J(r)?O(n)+O(r):j(n)+j(r);case"-":return j(n)-j(r);case"*":return j(n)*j(r);case"/":return j(n)/j(r);case"%":return j(n)%j(r);default:throw new u(e,"UnsupportedOperator",t)}}async function ze(e,t){const n=await we(e,t.left);if(!H(n))throw new u(e,"LogicalExpressionOnlyBoolean",t);switch(t.operator){case"||":{if(!0===n)return n;const r=await we(e,t.right);if(H(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=await we(e,t.right);if(H(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}default:throw new u(e,"LogicExpressionOrAnd",t)}}function qe(e,t){return ae(e,t)}async function Pe(e,t){if("MemberExpression"===t.callee.type){const n=await we(e,t.callee.object);if(!(n instanceof fe))throw new u(e,"FunctionNotFound",t);const r=!1===t.callee.computed?t.callee.property.name:await we(e,t.callee.property);if(!n.hasGlobal(r))throw new u(e,"FunctionNotFound",t);const o=n.global(r);if(!v(o))throw new u(e,"CallNonFunction",t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new u(e,"FunctionNotFound",t);const n=ae(e,t.callee,"FunctionNotFound");if(v(n))return n.call(e,t);throw new u(e,"CallNonFunction",t)}async function We(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){if(t.expressions[r]){const o=await we(e,t.expressions[r]);if(v(o))throw new u(e,"NoFunctionInTemplateLiteral",t);n+=O(o)}r++}return n}async function Ve(e,t){F(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await we(e,t.arguments[0]);if(!1===H(n))throw new u(e,"BooleanConditionRequired",t);return we(e,n?t.arguments[1]:t.arguments[2])}async function Te(e,t){F(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await we(e,t.arguments[0]);if(3===t.arguments.length){const r=await we(e,t.arguments[1]),o=i(n,r);return null!=o&&""!==o?o:we(e,t.arguments[2])}return null==n||""===n?we(e,t.arguments[1]):n}async function Ye(e,t){if(t.arguments.length<2)throw new u(e,"WrongNumberOfParameters",t);if(2===t.arguments.length)return we(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new u(e,"WrongNumberOfParameters",t);return $e(e,t,1,await we(e,t.arguments[0]))}async function $e(e,t,n,r){const o=await we(e,t.arguments[n]);if(I(o,r))return we(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?we(e,t.arguments[n]):2===a?null:3===a?we(e,t.arguments[n+2]):$e(e,t,n+2,r)}async function He(e,t){if(t.arguments.length<3)throw new u(e,"WrongNumberOfParameters",t);if(t.arguments.length%2==0)throw new u(e,"WrongNumberOfParameters",t);const n=await we(e,t.arguments[0]);if(!1===H(n))throw new u(e,"BooleanConditionRequired",t.arguments[0]);return Je(e,t,0,n)}async function Je(e,t,n,r){if(!0===r)return we(e,t.arguments[n+1]);if(3===t.arguments.length-n)return we(e,t.arguments[n+2]);const o=await we(e,t.arguments[n+2]);if(!1===H(o))throw new u(e,"ModuleExportNotFound",t.arguments[n+2]);return Je(e,t,n+2,o)}function Qe(){const e=Object.create(null);L(e,ce),P(e,ce),_(e,ce,qe),z(e,ce),Z(e,ce),q(e,ce),W(e,ce),D({functions:e,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:ce,standardFunctionAsync:pe}),e.iif=Ve,e.defaultvalue=Te,e.decode=Ye,e.when=He;const t=function(){this.textformatting={value:l.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new w(r)});return t}const Xe=Qe();function et(e){const t={mode:"async",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ce,standardFunctionAsync:pe,evaluateIdentifier:qe};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Xe.prototype[n]=Object.freeze({value:new w(r)});for(let n=0;n<t.signatures.length;n++)G(t.signatures[n],"async")}function tt(e){console.log(e)}function nt(n,a){const i=new Set(Object.keys(a?.vars||{}).map(t=>e(t))),s=new Set(Object.keys(a?.customfunctions||{}).map(t=>e(t))),{globals:c,exports:l}=o(n);return async e=>{const o=e.spatialReference??Y.WebMercator;let a=null;n.usesModules&&(a=new r(new Map,n.loadedModules));const f=new Xe;for(const t of s)null!=e.customfunctions&&t in e.customfunctions?f[t]={value:new w(e.customfunctions[t])}:f[t]=te;for(const t of i){if(null==e.vars||!(t in e.vars)){t in f||(f[t]=te);continue}const n=e.vars[t]??null;$(n)?f[t]={value:p.createFromGraphic(n,e.timeZone??null)}:f[t]={value:n}}for(const t of c)t in f||(f[t]=te);const d={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??tt,abortSignal:e.abortSignal??t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:a,exports:l,localScope:null,globalScope:f},h=await Ae(d,n);if(h instanceof g||h instanceof y){const e=h.value;if(b(e))return null;if(v(e))throw new u(d,"IllegalResult",null);return e}if(b(h))return null;if(h===x)throw new u(d,"IllegalResult",null);if(h===S)throw new u(d,"IllegalResult",null);throw new u(d,"NeverReach",null)}}function rt(e,t){return nt(e,t)(t)}et([K]),et([U]);export{rt as executeScript,et as extend,nt as prepareScript};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{toSymbolId as e,neverAbortedSignal as n}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as l}from"./compilerUtils.js";import{getNestedOptionalValue as a,geometryMember as s,getGeometryKeys as i}from"./containerUtils.js";import u from"./Dictionary.js";import{ArcadeExecutionError as c,ArcadeCompilationError as m,ArcadeUncompilableError as f}from"./executionError.js";import p from"./Feature.js";import{NativeFunction as d,ArcadeFunction as g,ScopeMarshalledFunction as h,wrapModuleScopedResponse as y}from"./FunctionWrapper.js";import{p as w,q as b,i as v,r as $,j as S,k as x,s as F,u as M,v as I,w as O,x as C,y as j,h as A,n as k}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as E}from"../chunks/aiServices.js";import{A as B}from"../chunks/array.js";import{registerFunctions as _}from"./functions/date.js";import{registerFunctions as V}from"./functions/feature.js";import{registerFunctions as R}from"./functions/geometry.js";import{registerFunctions as L}from"./functions/geomsync.js";import{registerFunctions as T}from"./functions/maths.js";import{registerFunctions as D}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import{registerFunctions as G}from"./functions/track.js";import{neverReached as K}from"../core/compilerUtils.js";import q from"../core/Logger.js";import{isPromiseLike as P}from"../core/promiseUtils.js";import{addMany as z}from"../core/SetUtils.js";import W from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";import{isGraphic as J,isString as Y,isArray as H,isNumber as Q,isBoolean as X}from"../support/guards.js";const ee=()=>q.getLogger("esri.arcade.arcadeCompiler");class ne{constructor(){this._symbolCounter=0}nextVarId(){return this._symbolCounter+=1,`_T${this._symbolCounter}`}nextTempVarId(){return this._symbolCounter+=1,`_Tvar${this._symbolCounter}`}nextLocalsSymbolMapId(){return this._symbolCounter+=1,`_Locals${this._symbolCounter}`}}function te(e,n){const t=e.localScope?.get(n);if(null!=t)return{scope:"local",name:n,var:t};const r=e.globalScope.get(n);return null!=r?{scope:"global",name:n,var:r}:e.standardGlobals.has(n)?{scope:"global",name:n,var:n}:null}function re(n,t,r="InvalidIdentifier"){const o=te(n,e(t));if(null!=o)return o;throw new m(null,r,t)}function oe(n,t,r){const o=te(n,e(t));if(null==o)throw ee().error(`Internal error: Symbol "${t.name}" not declared.`),new m(null,"NeverReach",t);if(null!=r&&o.scope!==r)throw ee().error(`Internal error: Expected to resolve "${t.name}" in the ${r} scope but is in the ${o.scope} scope.`),new m(null,"NeverReach",t);return o}function le(n,t){const r=e(t),o=n.symbolMetadata;if(n.localStack.length>0){const e=n.localStack[n.localStack.length-1],t=o.locals.get(e._SymbolsMapId);if(null==t)return void ee().error(`Internal error: no reflection metadata for ${e._SymbolsMapId}`);const l=t.get(r);if(null!=l)return Qe.requireInitialized(e[l])}const l=o.globals.get(r);if(null!=l)return Qe.requireInitialized(n.globalScope[l]);if(o.standardGlobals.has(r))return Qe.requireInitialized(n.globalScope[r]);throw new c(null,"InvalidIdentifier",null)}class ae extends g{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new c(e,"WrongNumberOfParameters",null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,r){return r(e,n,(n,o,l)=>{l=l.map(n=>!v(n)||n instanceof h?n:y(n,e,r));const a=this.call(t,{arguments:l});return P(a)?a.then(e=>y(e,t,r)):a})}}function se(e,n,t){try{return t(e,null,n.arguments)}catch(r){throw r}}function ie(e,n,t,r,l,a){const{globals:s,exports:i}=o(e);z(s,t);const u=new ne,c=[],m=new Map;for(const o of s)if(t.has(o)||n.has(o))m.set(o,o);else{const e=u.nextVarId();m.set(o,e),c.push(`gscope[${JSON.stringify(e)}] = ${Ye};`)}const f=new Map,p=Object.create(null),d={isAsync:r,symbols:u,standardGlobals:n,globalScope:m,exports:i,localScope:null,allLocalSymbolMetadata:f,moduleFactory:a,moduleFactoryMap:p,libraryResolver:l};return{body:[...c,"var lastStatement = lc.voidOperation;",Fe(d,e),"return lastStatement;"].join("\n"),symbolMetadata:{standardGlobals:n,exports:i,globals:m,locals:f},moduleFactoryMap:p}}function ue(e,n){switch(n.type){case"AssignmentExpression":return ve(e,n);case"UpdateExpression":return we(e,n);case"TemplateLiteral":return Be(e,n);case"Identifier":return Re(e,n);case"MemberExpression":return ke(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Le(e,n);case"UnaryExpression":return Ne(e,n);case"BinaryExpression":return _e(e,n);case"LogicalExpression":return Ve(e,n);case"ArrayExpression":return Ee(e,n);case"ObjectExpression":return me(e,n);default:throw new m(null,"Unrecognized",n)}}function ce(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return je(e,n);case"BlockStatement":return Fe(e,n);case"FunctionDeclaration":return Ce(e,n);case"ImportDeclaration":return Ie(e,n);case"ExportNamedDeclaration":return ce(e,n.declaration);case"ReturnStatement":return Me(e,n);case"IfStatement":return xe(e,n);case"ExpressionStatement":return $e(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ye(e,n);case"ForInStatement":return ge(e,n);case"ForOfStatement":return he(e,n);case"WhileStatement":return be(e,n);default:throw new m(null,"Unrecognized",n)}}function me(e,n){let t="lang.dictionary([";for(let r=0;r<n.properties.length;r++){const o=n.properties[r];let l;l="Identifier"===o.key.type?"'"+o.key.name+"'":ue(e,o.key);r>0&&(t+=","),t+="lang.strCheck("+l+",'ObjectExpression'),lang.aCheck("+ue(e,o.value)+", 'ObjectExpression')"}return t+="])",t}function fe(e,n,t,r,o=(e,n)=>`${e} = ${n}`){const l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId();return[`var ${l} = ${t};`,`for (var ${a} = 0; ${a} < ${l}; ${a}++) {`,` ${o(n,a)}`,` ${ce(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function pe(e,n,t,r,o=e=>e){const l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId();return[`var ${l} = ${t};`,`for (var ${a} of ${l}) {`,` ${n} = ${o(a)};`,` ${ce(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function de(e,n,t,r){const o=e.symbols.nextTempVarId();return[`var ${o} = ${t}.iterator(runtimeCtx.abortSignal);`,`while ((${n} = lang.graphicToFeature(yield ${o}.next(), ${t}, runtimeCtx)) != null) {`,` ${ce(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function ge(e,n){const t=e.symbols.nextTempVarId();let r,o,l="var "+t+" = "+ue(e,n.right)+";\n";switch("VariableDeclaration"===n.left.type?(r=oe(e,n.left.declarations[0].id),l+=ce(e,n.left)):r=re(e,n.left),r.scope){case"local":o=`lscope['${r.var}']`;break;case"global":o=`gscope['${r.var}']`;break;default:throw K(r.scope),new m(null,"NeverReach",n.left)}return l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {\n",l+=fe(e,o,`${t}.length`,n.body),l+="}\n",l+="else if (lc.isImmutableArray("+t+")) {\n",l+=fe(e,o,`${t}.length()`,n.body),l+="}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || lc.isDictionaryLike("+t+")) {\n",l+=pe(e,o,`${t}.keys()`,n.body),l+="}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {\n",l+=de(e,o,t,n.body),l+="}\n"),l+=`else if (lc.isGeometry(${t})) {\n`,l+=pe(e,o,`lang.getGeometryKeys(${t})`,n.body),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function he(e,n){const t=e.symbols.nextTempVarId();let r,o,l="var "+t+" = "+ue(e,n.right)+";\n";switch("VariableDeclaration"===n.left.type?(r=oe(e,n.left.declarations[0].id),l+=ce(e,n.left)):r=re(e,n.left),r.scope){case"local":o=`lscope['${r.var}']`;break;case"global":o=`gscope['${r.var}']`;break;default:throw K(r.scope),new m(null,"NeverReach",n.left)}return l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {\n",l+=fe(e,o,`${t}.length`,n.body,(e,n)=>[`if (${n} >= ${t}.length) {`," lang.error('OutOfBounds');","}",`${e} = ${t}[${n}];`].join("\n")),l+="}\n",l+="else if (lc.isImmutableArray("+t+")) {\n",l+=fe(e,o,`${t}.length()`,n.body,(e,n)=>`${e} = ${t}.get(${n});`),l+="}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || lc.isDictionaryLike("+t+")) {\n",l+=pe(e,o,`${t}.keys()`,n.body,e=>`lang.entry(${e}, ${t}.field(${e}))`),l+="}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {\n",l+=de(e,o,t,n.body),l+="}\n"),l+=`else if (lc.isGeometry(${t})) {\n`,l+=pe(e,o,`lang.getGeometryKeys(${t})`,n.body,e=>`lang.entry(${e}, lang.geometryMember(${t}, ${e}, runtimeCtx, null, 1))`),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function ye(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=ce(e,n.init):t+=ue(e,n.init)+"; ");const r=e.symbols.nextTempVarId(),o=e.symbols.nextTempVarId();return t+="var "+r+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+r+"===false) {\n "+ue(e,n.update)+" \n}\n "+r+"=false; \n"),null!==n.test&&(t+="var "+o+" = "+ue(e,n.test)+"; ",t+="if ("+o+"===false) { break; } else if ("+o+"!==true) { lang.error('BooleanConditionRequired'); }\n"),t+=ce(e,n.body),null!==n.update&&(t+="\n "+ue(e,n.update)),t+="\n"+r+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function we(e,n){if("CallExpression"===n.argument.type)throw new m(null,"NeverReach",n);let t;if("MemberExpression"===n.argument.type){const r=ue(e,n.argument.object);return t=!0===n.argument.computed?ue(e,n.argument.property):"'"+n.argument.property.name+"'","lang.memberupdate("+r+","+t+",'"+n.operator+"',"+n.prefix+")"}const r=re(e,n.argument);switch(Oe(r),r.scope){case"local":return`lang.update(lscope, '${r.var}', '${n.operator}', ${n.prefix})`;case"global":return`lang.update(gscope, '${r.var}', '${n.operator}', ${n.prefix})`;default:throw K(r.scope),new m(null,"NeverReach",n.argument)}}function be(e,n){let t="lastStatement = lc.voidOperation; \n";const r=e.symbols.nextTempVarId();return t+=`\n var ${r} = true;\n do {\n ${r} = ${ue(e,n.test)};\n if (${r}==false) {\n break;\n }\n if (${r}!==true) {\n lang.error('BooleanConditionRequired');\n }\n ${ce(e,n.body)}\n }\n while (${r} !== false);\n lastStatement = lc.voidOperation;\n `,t}function ve(e,n){const t=ue(e,n.right);if("MemberExpression"===n.left.type){let r;const o=ue(e,n.left.object);return r=!0===n.left.computed?ue(e,n.left.property):"'"+n.left.property.name+"'","lang.assignmember("+o+","+r+",'"+n.operator+"',"+t+")"}const r=re(e,n.left);switch(Oe(r),r.scope){case"local":return`lscope['${r.var}']=lang.assign(${t},'${n.operator}', ${"="===n.operator?"null":He(`lscope['${r.var}']`)})`;case"global":return`gscope['${r.var}']=lang.assign(${t},'${n.operator}', ${"="===n.operator?"null":He(`gscope['${r.var}']`)})`;default:throw K(r.scope),new m(null,"NeverReach",n.left)}}function $e(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+ue(e,n.expression)+"; \n ":"lastStatement = "+ue(e,n.expression)+"; "}function Se(e,n){return"BlockStatement"===n.type?ce(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?ce(e,n)+"; ":"ExpressionStatement"===n.type?ce(e,n):ce(e,n)+"; "}function xe(e,n){return`if (lang.mustBoolean(${ue(e,n.test)}, runtimeCtx) === true) {\n ${Se(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+xe(e,n.alternate):` else {\n ${Se(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function Fe(e,n){let t="";for(let r=0;r<n.body.length;r++)"EmptyStatement"!==n.body[r].type&&("ReturnStatement"===n.body[r].type||"BreakStatement"===n.body[r].type||"ContinueStatement"===n.body[r].type?t+=ce(e,n.body[r])+"; \n":t+=ce(e,n.body[r])+" \n");return t}function Me(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+ue(e,n.argument)}function Ie(e,n){const t=oe(e,n.specifiers[0].local,"global"),r=e.libraryResolver?.loadLibrary(t.name),o=e.symbols.nextVarId();void 0===e.moduleFactory[r.uri]&&(e.moduleFactory[r.uri]=rn(r.syntax,e.moduleFactory,e.isAsync)),e.moduleFactoryMap[o]=r.uri;let l="";return l=e.isAsync?"(yield lang.loadModule('"+o+"', runtimeCtx) ); ":"lang.loadModule('"+o+"', runtimeCtx); ",Oe(t),`gscope['${t.var}']=${l}`}function Oe(e){if("global"===e.scope)switch(e.name){case"iif":case"when":case"defaultvalue":case"decode":throw new f}}function Ce(n,t){const r=new Set(t.params.map(n=>e(n))),o=l(t);z(o,r);const a=n.symbols,s=new Map;for(const e of o)s.set(e,a.nextVarId());const i=a.nextLocalsSymbolMapId();n.allLocalSymbolMetadata.set(i,s);const u={...n,localScope:s},c=[`lscope._SymbolsMapId = ${JSON.stringify(i)};`];for(let e=0;e<t.params.length;e++){const n=oe(u,t.params[e],"local");Oe(n),c.push(`lscope['${n.var}'] = arguments[${e}];`)}for(const[e,l]of s)r.has(e)||c.push(`lscope['${l}'] = ${Ye};`);const m=Fe(u,t.body),f=!0===n.isAsync?["return lang.__awaiter(this, void 0, void 0, function* () {",` ${m}`," return lastStatement;","});"]:[m,"return lastStatement;"],p=["new lang.UserDefinedCompiledFunction("," lang.functionDepthchecker("," function() {"," var lastStatement = lc.voidOperation;"," var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];",...c,...f," },"," runtimeCtx,"," ),",` ${t.params.length},`,")"].join("\n"),d=oe(n,t.id,"global");return Oe(d),`gscope['${d.var}']=${p}; lastStatement = lc.voidOperation;`}function je(e,n){const t=[];for(let r=0;r<n.declarations.length;r++)t.push(Ae(e,n.declarations[r]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function Ae(e,n){const t=null===n.init?"null":ue(e,n.init),r=oe(e,n.id);switch(Oe(r),r.scope){case"local":return`lscope['${r.var}']=${t};`;case"global":return`gscope['${r.var}']=${t};`;default:throw K(r.scope),new m(null,"NeverReach",n.id)}}function ke(e,n){try{let t;return t=!0===n.computed?ue(e,n.property):"'"+n.property.name+"'","lang.member("+ue(e,n.object)+","+t+")"}catch(t){throw t}}function Ne(e,n){try{return"lang.unary("+ue(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function Ee(e,n){try{const t=[];for(let r=0;r<n.elements.length;r++)"Literal"===n.elements[r].type?t.push(ue(e,n.elements[r])):t.push("lang.aCheck("+ue(e,n.elements[r])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function Be(e,n){try{const t=[];let r=0;for(const o of n.quasis)t.push(o.value?JSON.stringify(o.value.cooked):JSON.stringify("")),!1===o.tail&&(t.push(n.expressions[r]?"lang.castString(lang.aCheck("+ue(e,n.expressions[r])+", 'TemplateLiteral'))":""),r++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function _e(e,n){try{return"lang.binary("+ue(e,n.left)+","+ue(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 m(null,"LogicalExpressionOnlyBoolean",n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new m(null,"LogicalExpressionOnlyBoolean",n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+ue(e,n.left)+") "+n.operator+" lang.logicalCheck("+ue(e,n.right)+"))";throw new m(null,"LogicExpressionOrAnd",null)}catch(t){throw t}}function Re(e,n){const t=re(e,n);switch(Oe(t),t.scope){case"local":return He(`lscope['${t.var}']`);case"global":return He(`gscope['${t.var}']`);default:throw K(t.scope),new m(null,"NeverReach",n)}}function Le(e,n){try{if("MemberExpression"===n.callee.type){let t;t=!0===n.callee.computed?ue(e,n.callee.property):"'"+n.callee.property.name+"'";let r="[";for(let o=0;o<n.arguments.length;o++)o>0&&(r+=", "),r+=ue(e,n.arguments[o]);return r+="]",e.isAsync?"(yield lang.callModuleFunction("+ue(e,n.callee.object)+","+r+","+t+",runtimeCtx))":"lang.callModuleFunction("+ue(e,n.callee.object)+","+r+","+t+",runtimeCtx)"}if("Identifier"!==n.callee.type)throw new m(null,"FunctionNotFound",n);const t=re(e,n.callee,"FunctionNotFound");if("global"===t.scope)switch(t.name){case"iif":return Te(e,n);case"when":return Ue(e,n);case"defaultvalue":return De(e,n);case"decode":return Ge(e,n)}let r;switch(t.scope){case"local":r=He(`lscope['${t.var}']`);break;case"global":r=He(`gscope['${t.var}']`);break;default:throw K(t.scope),new m(null,"NeverReach",n.callee)}let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=ue(e,n.arguments[l]);return o+="]",e.isAsync?"(yield lang.callfunc("+r+","+o+",runtimeCtx) )":"lang.callfunc("+r+","+o+",runtimeCtx)"}catch(t){throw t}}function Te(e,n){try{if(3!==n.arguments.length)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ue(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${ue(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${ue(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function De(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId(),r=e.symbols.nextTempVarId();return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ue(e,n.arguments[0])};\n var ${r} = ${ue(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${r});\n return ${t} != null && ${t} !== "" ? ${t} : ${ue(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} = ${ue(e,n.arguments[0])};\n if (${t} === null) {\n return ${ue(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${ue(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${ue(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ue(e,n){try{if(n.arguments.length<3)throw new m(null,"WrongNumberOfParameters",n);if(n.arguments.length%2==0)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();let r="var ";for(let o=0;o<n.arguments.length-1;o+=2)r+=`${t} = lang.mustBoolean(${ue(e,n.arguments[o])}, runtimeCtx);\n if (${t} === true ) {\n return ${ue(e,n.arguments[o+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${r}\n return ${ue(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ge(e,n){try{if(n.arguments.length<2)throw new m(null,"WrongNumberOfParameters",n);if(2===n.arguments.length)return`(${ue(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId(),r=e.symbols.nextTempVarId();let o="var ";for(let l=1;l<n.arguments.length-1;l+=2)o+=`${r} = ${ue(e,n.arguments[l])};\n if (lang.binary(${r}, ${t}, "==") === true ) {\n return ${ue(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ue(e,n.arguments[0])};\n ${o}\n return ${ue(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ke(e,n){try{return se(e,n,(e,n)=>{throw new c(e,"Unrecognized",n)})}catch(t){throw t}}function qe(e){const n=function(){this.textformatting=u.textFormatting()};n.prototype=Object.create(null),n.provided=new Set(["textformatting","infinity","pi"]),n.prototype.infinity=Number.POSITIVE_INFINITY,n.prototype.pi=Math.PI;for(const[t,r]of Object.entries(e))n.prototype[t]=new d(r),n.provided.add(t);return n}function Pe(){const e=Object.create(null);_(e,se),U(e,se),V(e,se,le),T(e,se),R(e,se),D(e,se),G(e,se),e.iif=Ke,e.decode=Ke,e.when=Ke,e.defaultvalue=Ke;const n=qe(e);L(e,se);return{ScopeSync:qe(e),ScopeAsync:n}}const{ScopeSync:ze,ScopeAsync:We}=Pe();function Ze(e,n){const t={mode:n,compiled:!0,functions:Object.create(null),signatures:[],standardFunction:se,standardFunctionAsync:se,evaluateIdentifier:le};for(const r of e)r.registerFunctions(t);if("sync"===n)for(const[r,o]of Object.entries(t.functions))ze.prototype[r]=new d(o),ze.provided.add(r);else for(const[r,o]of Object.entries(t.functions))We.prototype[r]=new d(o),We.provided.add(r);for(const r of t.signatures)N(r,n)}Ze([B],"sync"),Ze([B],"async"),Ze([E],"async");const Je=Symbol("uninitialized"),Ye="lang.uninitialized";function He(e){return`lang.requireInitialized(${e})`}const Qe={uninitialized:Je,requireInitialized(e){if(e===Je)throw new c(null,"InvalidIdentifier",null);return e},isNumber:e=>Q(e),isArray:e=>H(e),isImmutableArray:e=>S(e),isDictionaryLike:e=>$(e),isString:e=>Y(e),isDictionary:e=>k(e),isGeometry:e=>A(e),getGeometryKeys:e=>i(e),geometryMember:(e,n,t,r,o=1)=>s(e,n,t,r,o),error(e){throw new c(null,e,null)},__awaiter(e,n,t,r){const o=r.apply(e,n||[]);let l=o.next();for(;!l.done&&!P(l.value);)l=o.next(l.value);return l.done?l.value:new Promise((e,n)=>{function t(r){for(;!r.done;){if(P(r.value))return void Promise.resolve(r.value).then(e=>{try{t(o.next(e))}catch(r){n(r)}},e=>{try{t(o.throw(e))}catch(r){n(r)}});try{r=o.next(r.value)}catch(l){return void n(l)}}e(r.value)}t(l)})},functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new c(null,"MaximumCallDepth",null);const t=e.apply(this,arguments);return P(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)},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new c(n,"BooleanConditionRequired",null)},castString:e=>M(e),aCheck(e,n){if(v(e)){if("ArrayExpression"===n)throw new c(null,"NoFunctionInArray",null);if("ObjectExpression"===n)throw new c(null,"NoFunctionInDictionary",null);throw new c(null,"NoFunctionInTemplateLiteral",null)}return e===I?null:e},Dictionary:u,Feature:p,UserDefinedCompiledFunction:ae,dictionary(e){const n=Object.create(null),t=new Map;for(let o=0;o<e.length;o+=2){if(v(e[o+1]))throw new c(null,"NoFunctionInDictionary",null);if(!1===Y(e[o]))throw new c(null,"KeyMustBeString",null);let r=e[o].toString();const l=r.toLowerCase();t.has(l)?r=t.get(l):t.set(l,r),e[o+1]===I?n[r]=null:n[r]=e[o+1]}const r=new u(n);return r.immutable=!1,r},entry:(e,n)=>u.containerEntry(e,n),strCheck(e){if(!1===Y(e))throw new c(null,"KeyMustBeString",null);return e},unary(e,n){if(X(e)){if("!"===n)return!e;if("-"===n)return-1*F(e);if("+"===n)return 1*F(e);if("~"===n)return~F(e);throw new c(null,"UnsupportUnaryOperator",null)}if("-"===n)return-1*F(e);if("+"===n)return 1*F(e);if("~"===n)return~F(e);throw new c(null,"UnsupportUnaryOperator",null)},logicalCheck(e){if(!1===X(e))throw new c(null,"LogicExpressionOrAnd",null);return e},logical(e,n,t){if(X(e)&&X(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new c(null,"LogicExpressionOrAnd",null)}throw new c(null,"LogicExpressionOrAnd",null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(F(e),F(n),t);case"==":case"=":return C(e,n);case"!=":return!C(e,n);case"<":case">":case"<=":case">=":return O(e,n,t);case"+":return Y(e)||Y(n)?M(e)+M(n):F(e)+F(n);case"-":return F(e)-F(n);case"*":return F(e)*F(n);case"/":return F(e)/F(n);case"%":return F(e)%F(n);default:throw new c(null,"UnsupportedOperator",null)}},assign(e,n,t){switch(n){case"=":return e===I?null:e;case"/=":return F(t)/F(e);case"*=":return F(t)*F(e);case"-=":return F(t)-F(e);case"+=":return Y(t)||Y(e)?M(t)+M(e):F(t)+F(e);case"%=":return F(t)%F(e);default:throw new c(null,"UnsupportedOperator",null)}},update(e,n,t,r){const o=F(this.requireInitialized(e[n]));return e[n]="++"===t?o+1:o-1,!1===r?o:"++"===t?o+1:o-1},graphicToFeature:(e,n,t)=>null===e?null:p.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,r){let o;if(H(e)){if(!Q(n))throw new c(null,"ArrayAccessMustBeNumber",null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new c(null,"OutOfBounds",null);o=F(e[n]),e[n]="++"===t?o+1:o-1}else if(e instanceof u){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0!==e.hasField(n))throw new c(null,"FieldNotFound",null,{key:n});o=F(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else if(x(e)){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0!==e.hasField(n))throw new c(null,"FieldNotFound",null);o=F(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else{if(S(e))throw new c(null,"Immutable",null);if(!(e instanceof tn))throw new c(null,"InvalidIdentifier",null);if(!1===Y(n))throw new c(null,"ModuleAccessorMustBeString",null);if(!0!==e.hasGlobal(n))throw new c(null,"ModuleExportNotFound",null);o=F(e.global(n)),e.setGlobal(n,"++"===t?o+1:o-1)}return!1===r?o:"++"===t?o+1:o-1},assignmember(e,n,t,r){if(H(e)){if(!Q(n))throw new c(null,"ArrayAccessMustBeNumber",null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new c(null,"OutOfBounds",null);if(n===e.length){if("="!==t)throw new c(null,"OutOfBounds",null);e[n]=this.assign(r,t,e[n])}else e[n]=this.assign(r,t,e[n])}else if(e instanceof u){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0===e.hasField(n))e.setField(n,this.assign(r,t,e.field(n)));else{if("="!==t)throw new c(null,"FieldNotFound",null);e.setField(n,this.assign(r,t,null))}}else if(x(e)){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0===e.hasField(n))e.setField(n,this.assign(r,t,e.field(n)));else{if("="!==t)throw new c(null,"FieldNotFound",null);e.setField(n,this.assign(r,t,null))}}else{if(S(e))throw new c(null,"Immutable",null);if(!(e instanceof tn))throw new c(null,"InvalidIdentifier",null);if(!1===Y(n))throw new c(null,"ModuleAccessorMustBeString",null);if(!e.hasGlobal(n))throw new c(null,"ModuleExportNotFound",null);e.setGlobal(n,this.assign(r,t,e.global(n)))}},member(e,n){if(null===e)throw new c(null,"MemberOfNull",null);if(e instanceof u||$(e)){if(Y(n))return e.field(n);throw new c(null,"InvalidMemberAccessKey",null)}if(e instanceof W){if(Y(n))return s(e,n,null,null);throw new c(null,"InvalidMemberAccessKey",null)}if(H(e)){if(Q(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new c(null,"OutOfBounds",null);return e[n]}throw new c(null,"InvalidMemberAccessKey",null)}if(Y(e)){if(Q(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new c(null,"OutOfBounds",null);return e[n]}throw new c(null,"InvalidMemberAccessKey",null)}if(S(e)){if(Q(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new c(null,"OutOfBounds",null);return e.get(n)}throw new c(null,"InvalidMemberAccessKey",null)}if(e instanceof tn){if(Y(n))return e.global(n);throw new c(null,"InvalidMemberAccessKey",null)}throw new c(null,"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 r=n.moduleFactory[t]({moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,lrucache:n.lrucache,interceptor:n.interceptor,services:n.services,console:n.console,abortSignal:n.abortSignal,timeZone:n.timeZone??null,spatialReference:n.spatialReference});return n.moduleSingletons[t]=r,r},callModuleFunction(e,n,t,r){if(!(e instanceof tn))throw new c(null,"FunctionNotFound",null);const o=e.global(t);if(!1===v(o))throw new c(null,"CallNonFunction",null);return o.call(r,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>a(e,n)};function Xe(e){console.log(e)}function en(t,o,l=!1){let a=null;t.usesModules&&(a=new r(null,t.loadedModules));const s=Object.create(null),i=new Set(Object.keys(o?.vars||{}).map(n=>e(n))),u=new Set(Object.keys(o?.customfunctions||{}).map(n=>e(n))),m=ie(t,l?We.provided:ze.provided,new Set([...i,...u]),l,a,s);let f;f=l?["var runtimeCtx = this.prepare(context, true);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","return lang.__awaiter(this, void 0, void 0, function* () {"," function mainBody() {"," return lang.__awaiter(this, void 0, void 0, function* () {",` ${m.body}`," });"," }"," return this.postProcess(yield mainBody());","});"].join("\n"):["var runtimeCtx = this.prepare(context, false);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","function mainBody() {",` ${m.body}`,"}","return this.postProcess(mainBody());"].join("\n");const{symbolMetadata:d,moduleFactoryMap:g}=m,h={lc:w,lang:Qe,postProcess(e){if(b(e))return null;if(v(e))throw new c(null,"IllegalResult",null);return e},prepare(e,t){const r=e.spatialReference??Z.WebMercator,o=t?new We:new ze;for(const n of u)null!=e.customfunctions&&n in e.customfunctions?o[n]=e.customfunctions[n]??null:o[n]=Je;for(const n of i){if(null==e.vars||!(n in e.vars)){n in o||(o[n]=Je);continue}const t=e.vars[n]??null;J(t)?o[n]=p.createFromGraphic(t,e.timeZone??null):o[n]=t}return{lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Xe,abortSignal:e.abortSignal??n,timeZone:e.timeZone??null,spatialReference:r,track:e.track,globalScope:o,localStack:[],depthCounter:{depth:1},symbolMetadata:d,moduleFactory:s,moduleFactoryMap:g,moduleSingletons:Object.create(null)}}};return new Function("context",f).bind(h)}async function nn(){return Ze([await import("./functions/geomasync.js")],"async"),!0}class tn extends t{constructor(e){super(),this.moduleContext=e}hasGlobal(n){const t=this.moduleContext.symbolMetadata.exports;return t.has(n)||t.has(e(n))}setGlobal(n,t){if(v(t))throw new c(null,"AssignModuleFunction",null);const r=this.moduleContext.symbolMetadata.globals.get(e(n));if(null==r)throw new c(null,"ModuleExportNotFound",null);this.moduleContext.globalScope[r]=t}global(n){const t=this.moduleContext.symbolMetadata.globals.get(e(n));if(null==t)throw new c(null,"ModuleExportNotFound",null);const r=this.moduleContext.globalScope,o=Qe.requireInitialized(r[t]);if(v(o)&&!(o instanceof h)){const e=new h;return e.fn=o,e.parameterEvaluator=se,e.context=this.moduleContext,r[t]=e,e}return o}}function rn(e,t,o){const l=new r(null,e.loadedModules),a=ie(e,o?We.provided:ze.provided,new Set,o,l,t);let s;s=o?["var runtimeCtx = this.prepare(context, true);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","return lang.__awaiter(this, void 0, void 0, function* () {"," function mainBody() {"," return lang.__awaiter(this, void 0, void 0, function* () {",` ${a.body}`," });"," }"," yield mainBody();"," return this.prepareModule(runtimeCtx);","});"].join("\n"):["var runtimeCtx = this.prepare(context, false);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","function mainBody() {",` ${a.body}`,"}","mainBody();","return this.prepareModule(runtimeCtx);"].join("\n");const{symbolMetadata:i,moduleFactoryMap:u}=a,c={lc:w,lang:Qe,prepareModule:e=>new tn(e),prepare(e,r){const o=e.spatialReference??Z.WebMercator,l=r?new We:new ze;return{lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Xe,abortSignal:e.abortSignal??n,timeZone:e.timeZone??null,spatialReference:o,track:null,globalScope:l,localStack:[],depthCounter:e.depthCounter,symbolMetadata:i,moduleFactory:t,moduleFactoryMap:u,moduleSingletons:e.moduleSingletons}}};return new Function("context",s).bind(c)}export{ae as UserDefinedCompiledFunction,en as compileScript,nn as enableAsyncSupport,Ze as extend};
5
+ import{toSymbolId as e,neverAbortedSignal as n}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as l}from"./compilerUtils.js";import{getNestedOptionalValue as a,geometryMember as s,getGeometryKeys as i}from"./containerUtils.js";import u from"./Dictionary.js";import{ArcadeExecutionError as c,ArcadeCompilationError as m,ArcadeUncompilableError as f}from"./executionError.js";import{Feature as p}from"./Feature.js";import{NativeFunction as d,ArcadeFunction as g,ScopeMarshalledFunction as h,wrapModuleScopedResponse as y}from"./FunctionWrapper.js";import{p as w,q as b,i as v,r as $,j as S,k as x,s as F,u as M,v as I,w as O,x as C,y as j,h as A,n as k}from"../chunks/languageUtils.js";import{addFunctionDeclaration as N}from"./treeAnalysis.js";import{A as E}from"../chunks/aiServices.js";import{A as B}from"../chunks/array.js";import{registerFunctions as _}from"./functions/date.js";import{registerFunctions as V}from"./functions/feature.js";import{registerFunctions as R}from"./functions/geometry.js";import{registerFunctions as L}from"./functions/geomsync.js";import{registerFunctions as T}from"./functions/maths.js";import{registerFunctions as D}from"./functions/stats.js";import{registerFunctions as U}from"./functions/string.js";import{registerFunctions as G}from"./functions/track.js";import{neverReached as K}from"../core/compilerUtils.js";import q from"../core/Logger.js";import{isPromiseLike as P}from"../core/promiseUtils.js";import{addMany as z}from"../core/SetUtils.js";import W from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";import{isGraphic as J,isString as Y,isArray as H,isNumber as Q,isBoolean as X}from"../support/guards.js";const ee=()=>q.getLogger("esri.arcade.arcadeCompiler");class ne{constructor(){this._symbolCounter=0}nextVarId(){return this._symbolCounter+=1,`_T${this._symbolCounter}`}nextTempVarId(){return this._symbolCounter+=1,`_Tvar${this._symbolCounter}`}nextLocalsSymbolMapId(){return this._symbolCounter+=1,`_Locals${this._symbolCounter}`}}function te(e,n){const t=e.localScope?.get(n);if(null!=t)return{scope:"local",name:n,var:t};const r=e.globalScope.get(n);return null!=r?{scope:"global",name:n,var:r}:e.standardGlobals.has(n)?{scope:"global",name:n,var:n}:null}function re(n,t,r="InvalidIdentifier"){const o=te(n,e(t));if(null!=o)return o;throw new m(null,r,t)}function oe(n,t,r){const o=te(n,e(t));if(null==o)throw ee().error(`Internal error: Symbol "${t.name}" not declared.`),new m(null,"NeverReach",t);if(null!=r&&o.scope!==r)throw ee().error(`Internal error: Expected to resolve "${t.name}" in the ${r} scope but is in the ${o.scope} scope.`),new m(null,"NeverReach",t);return o}function le(n,t){const r=e(t),o=n.symbolMetadata;if(n.localStack.length>0){const e=n.localStack[n.localStack.length-1],t=o.locals.get(e._SymbolsMapId);if(null==t)return void ee().error(`Internal error: no reflection metadata for ${e._SymbolsMapId}`);const l=t.get(r);if(null!=l)return Qe.requireInitialized(e[l])}const l=o.globals.get(r);if(null!=l)return Qe.requireInitialized(n.globalScope[l]);if(o.standardGlobals.has(r))return Qe.requireInitialized(n.globalScope[r]);throw new c(null,"InvalidIdentifier",null)}class ae extends g{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new c(e,"WrongNumberOfParameters",null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,r){return r(e,n,(n,o,l)=>{l=l.map(n=>!v(n)||n instanceof h?n:y(n,e,r));const a=this.call(t,{arguments:l});return P(a)?a.then(e=>y(e,t,r)):a})}}function se(e,n,t){try{return t(e,null,n.arguments)}catch(r){throw r}}function ie(e,n,t,r,l,a){const{globals:s,exports:i}=o(e);z(s,t);const u=new ne,c=[],m=new Map;for(const o of s)if(t.has(o)||n.has(o))m.set(o,o);else{const e=u.nextVarId();m.set(o,e),c.push(`gscope[${JSON.stringify(e)}] = ${Ye};`)}const f=new Map,p=Object.create(null),d={isAsync:r,symbols:u,standardGlobals:n,globalScope:m,exports:i,localScope:null,allLocalSymbolMetadata:f,moduleFactory:a,moduleFactoryMap:p,libraryResolver:l};return{body:[...c,"var lastStatement = lc.voidOperation;",Fe(d,e),"return lastStatement;"].join("\n"),symbolMetadata:{standardGlobals:n,exports:i,globals:m,locals:f},moduleFactoryMap:p}}function ue(e,n){switch(n.type){case"AssignmentExpression":return ve(e,n);case"UpdateExpression":return we(e,n);case"TemplateLiteral":return Be(e,n);case"Identifier":return Re(e,n);case"MemberExpression":return ke(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Le(e,n);case"UnaryExpression":return Ne(e,n);case"BinaryExpression":return _e(e,n);case"LogicalExpression":return Ve(e,n);case"ArrayExpression":return Ee(e,n);case"ObjectExpression":return me(e,n);default:throw new m(null,"Unrecognized",n)}}function ce(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return je(e,n);case"BlockStatement":return Fe(e,n);case"FunctionDeclaration":return Ce(e,n);case"ImportDeclaration":return Ie(e,n);case"ExportNamedDeclaration":return ce(e,n.declaration);case"ReturnStatement":return Me(e,n);case"IfStatement":return xe(e,n);case"ExpressionStatement":return $e(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ye(e,n);case"ForInStatement":return ge(e,n);case"ForOfStatement":return he(e,n);case"WhileStatement":return be(e,n);default:throw new m(null,"Unrecognized",n)}}function me(e,n){let t="lang.dictionary([";for(let r=0;r<n.properties.length;r++){const o=n.properties[r];let l;l="Identifier"===o.key.type?"'"+o.key.name+"'":ue(e,o.key);r>0&&(t+=","),t+="lang.strCheck("+l+",'ObjectExpression'),lang.aCheck("+ue(e,o.value)+", 'ObjectExpression')"}return t+="])",t}function fe(e,n,t,r,o=(e,n)=>`${e} = ${n}`){const l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId();return[`var ${l} = ${t};`,`for (var ${a} = 0; ${a} < ${l}; ${a}++) {`,` ${o(n,a)}`,` ${ce(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function pe(e,n,t,r,o=e=>e){const l=e.symbols.nextTempVarId(),a=e.symbols.nextTempVarId();return[`var ${l} = ${t};`,`for (var ${a} of ${l}) {`,` ${n} = ${o(a)};`,` ${ce(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function de(e,n,t,r){const o=e.symbols.nextTempVarId();return[`var ${o} = ${t}.iterator(runtimeCtx.abortSignal);`,`while ((${n} = lang.graphicToFeature(yield ${o}.next(), ${t}, runtimeCtx)) != null) {`,` ${ce(e,r)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function ge(e,n){const t=e.symbols.nextTempVarId();let r,o,l="var "+t+" = "+ue(e,n.right)+";\n";switch("VariableDeclaration"===n.left.type?(r=oe(e,n.left.declarations[0].id),l+=ce(e,n.left)):r=re(e,n.left),r.scope){case"local":o=`lscope['${r.var}']`;break;case"global":o=`gscope['${r.var}']`;break;default:throw K(r.scope),new m(null,"NeverReach",n.left)}return l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {\n",l+=fe(e,o,`${t}.length`,n.body),l+="}\n",l+="else if (lc.isImmutableArray("+t+")) {\n",l+=fe(e,o,`${t}.length()`,n.body),l+="}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || lc.isDictionaryLike("+t+")) {\n",l+=pe(e,o,`${t}.keys()`,n.body),l+="}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {\n",l+=de(e,o,t,n.body),l+="}\n"),l+=`else if (lc.isGeometry(${t})) {\n`,l+=pe(e,o,`lang.getGeometryKeys(${t})`,n.body),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function he(e,n){const t=e.symbols.nextTempVarId();let r,o,l="var "+t+" = "+ue(e,n.right)+";\n";switch("VariableDeclaration"===n.left.type?(r=oe(e,n.left.declarations[0].id),l+=ce(e,n.left)):r=re(e,n.left),r.scope){case"local":o=`lscope['${r.var}']`;break;case"global":o=`gscope['${r.var}']`;break;default:throw K(r.scope),new m(null,"NeverReach",n.left)}return l+="if ("+t+"===null) { lastStatement = lc.voidOperation; }\n ",l+="else if (lc.isArray("+t+") || lc.isString("+t+")) {\n",l+=fe(e,o,`${t}.length`,n.body,(e,n)=>[`if (${n} >= ${t}.length) {`," lang.error('OutOfBounds');","}",`${e} = ${t}[${n}];`].join("\n")),l+="}\n",l+="else if (lc.isImmutableArray("+t+")) {\n",l+=fe(e,o,`${t}.length()`,n.body,(e,n)=>`${e} = ${t}.get(${n});`),l+="}\n",l+="else if (( "+t+" instanceof lang.Dictionary) || lc.isDictionaryLike("+t+")) {\n",l+=pe(e,o,`${t}.keys()`,n.body,e=>`lang.entry(${e}, ${t}.field(${e}))`),l+="}\n",e.isAsync&&(l+="else if (lc.isFeatureSet("+t+")) {\n",l+=de(e,o,t,n.body),l+="}\n"),l+=`else if (lc.isGeometry(${t})) {\n`,l+=pe(e,o,`lang.getGeometryKeys(${t})`,n.body,e=>`lang.entry(${e}, lang.geometryMember(${t}, ${e}, runtimeCtx, null, 1))`),l+="}\n",l+="else { lastStatement = lc.voidOperation; } \n",l}function ye(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=ce(e,n.init):t+=ue(e,n.init)+"; ");const r=e.symbols.nextTempVarId(),o=e.symbols.nextTempVarId();return t+="var "+r+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+r+"===false) {\n "+ue(e,n.update)+" \n}\n "+r+"=false; \n"),null!==n.test&&(t+="var "+o+" = "+ue(e,n.test)+"; ",t+="if ("+o+"===false) { break; } else if ("+o+"!==true) { lang.error('BooleanConditionRequired'); }\n"),t+=ce(e,n.body),null!==n.update&&(t+="\n "+ue(e,n.update)),t+="\n"+r+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function we(e,n){if("CallExpression"===n.argument.type)throw new m(null,"NeverReach",n);let t;if("MemberExpression"===n.argument.type){const r=ue(e,n.argument.object);return t=!0===n.argument.computed?ue(e,n.argument.property):"'"+n.argument.property.name+"'","lang.memberupdate("+r+","+t+",'"+n.operator+"',"+n.prefix+")"}const r=re(e,n.argument);switch(Oe(r),r.scope){case"local":return`lang.update(lscope, '${r.var}', '${n.operator}', ${n.prefix})`;case"global":return`lang.update(gscope, '${r.var}', '${n.operator}', ${n.prefix})`;default:throw K(r.scope),new m(null,"NeverReach",n.argument)}}function be(e,n){let t="lastStatement = lc.voidOperation; \n";const r=e.symbols.nextTempVarId();return t+=`\n var ${r} = true;\n do {\n ${r} = ${ue(e,n.test)};\n if (${r}==false) {\n break;\n }\n if (${r}!==true) {\n lang.error('BooleanConditionRequired');\n }\n ${ce(e,n.body)}\n }\n while (${r} !== false);\n lastStatement = lc.voidOperation;\n `,t}function ve(e,n){const t=ue(e,n.right);if("MemberExpression"===n.left.type){let r;const o=ue(e,n.left.object);return r=!0===n.left.computed?ue(e,n.left.property):"'"+n.left.property.name+"'","lang.assignmember("+o+","+r+",'"+n.operator+"',"+t+")"}const r=re(e,n.left);switch(Oe(r),r.scope){case"local":return`lscope['${r.var}']=lang.assign(${t},'${n.operator}', ${"="===n.operator?"null":He(`lscope['${r.var}']`)})`;case"global":return`gscope['${r.var}']=lang.assign(${t},'${n.operator}', ${"="===n.operator?"null":He(`gscope['${r.var}']`)})`;default:throw K(r.scope),new m(null,"NeverReach",n.left)}}function $e(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+ue(e,n.expression)+"; \n ":"lastStatement = "+ue(e,n.expression)+"; "}function Se(e,n){return"BlockStatement"===n.type?ce(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?ce(e,n)+"; ":"ExpressionStatement"===n.type?ce(e,n):ce(e,n)+"; "}function xe(e,n){return`if (lang.mustBoolean(${ue(e,n.test)}, runtimeCtx) === true) {\n ${Se(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+xe(e,n.alternate):` else {\n ${Se(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function Fe(e,n){let t="";for(let r=0;r<n.body.length;r++)"EmptyStatement"!==n.body[r].type&&("ReturnStatement"===n.body[r].type||"BreakStatement"===n.body[r].type||"ContinueStatement"===n.body[r].type?t+=ce(e,n.body[r])+"; \n":t+=ce(e,n.body[r])+" \n");return t}function Me(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+ue(e,n.argument)}function Ie(e,n){const t=oe(e,n.specifiers[0].local,"global"),r=e.libraryResolver?.loadLibrary(t.name),o=e.symbols.nextVarId();void 0===e.moduleFactory[r.uri]&&(e.moduleFactory[r.uri]=rn(r.syntax,e.moduleFactory,e.isAsync)),e.moduleFactoryMap[o]=r.uri;let l="";return l=e.isAsync?"(yield lang.loadModule('"+o+"', runtimeCtx) ); ":"lang.loadModule('"+o+"', runtimeCtx); ",Oe(t),`gscope['${t.var}']=${l}`}function Oe(e){if("global"===e.scope)switch(e.name){case"iif":case"when":case"defaultvalue":case"decode":throw new f}}function Ce(n,t){const r=new Set(t.params.map(n=>e(n))),o=l(t);z(o,r);const a=n.symbols,s=new Map;for(const e of o)s.set(e,a.nextVarId());const i=a.nextLocalsSymbolMapId();n.allLocalSymbolMetadata.set(i,s);const u={...n,localScope:s},c=[`lscope._SymbolsMapId = ${JSON.stringify(i)};`];for(let e=0;e<t.params.length;e++){const n=oe(u,t.params[e],"local");Oe(n),c.push(`lscope['${n.var}'] = arguments[${e}];`)}for(const[e,l]of s)r.has(e)||c.push(`lscope['${l}'] = ${Ye};`);const m=Fe(u,t.body),f=!0===n.isAsync?["return lang.__awaiter(this, void 0, void 0, function* () {",` ${m}`," return lastStatement;","});"]:[m,"return lastStatement;"],p=["new lang.UserDefinedCompiledFunction("," lang.functionDepthchecker("," function() {"," var lastStatement = lc.voidOperation;"," var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];",...c,...f," },"," runtimeCtx,"," ),",` ${t.params.length},`,")"].join("\n"),d=oe(n,t.id,"global");return Oe(d),`gscope['${d.var}']=${p}; lastStatement = lc.voidOperation;`}function je(e,n){const t=[];for(let r=0;r<n.declarations.length;r++)t.push(Ae(e,n.declarations[r]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function Ae(e,n){const t=null===n.init?"null":ue(e,n.init),r=oe(e,n.id);switch(Oe(r),r.scope){case"local":return`lscope['${r.var}']=${t};`;case"global":return`gscope['${r.var}']=${t};`;default:throw K(r.scope),new m(null,"NeverReach",n.id)}}function ke(e,n){try{let t;return t=!0===n.computed?ue(e,n.property):"'"+n.property.name+"'","lang.member("+ue(e,n.object)+","+t+")"}catch(t){throw t}}function Ne(e,n){try{return"lang.unary("+ue(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function Ee(e,n){try{const t=[];for(let r=0;r<n.elements.length;r++)"Literal"===n.elements[r].type?t.push(ue(e,n.elements[r])):t.push("lang.aCheck("+ue(e,n.elements[r])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function Be(e,n){try{const t=[];let r=0;for(const o of n.quasis)t.push(o.value?JSON.stringify(o.value.cooked):JSON.stringify("")),!1===o.tail&&(t.push(n.expressions[r]?"lang.castString(lang.aCheck("+ue(e,n.expressions[r])+", 'TemplateLiteral'))":""),r++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function _e(e,n){try{return"lang.binary("+ue(e,n.left)+","+ue(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 m(null,"LogicalExpressionOnlyBoolean",n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new m(null,"LogicalExpressionOnlyBoolean",n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+ue(e,n.left)+") "+n.operator+" lang.logicalCheck("+ue(e,n.right)+"))";throw new m(null,"LogicExpressionOrAnd",null)}catch(t){throw t}}function Re(e,n){const t=re(e,n);switch(Oe(t),t.scope){case"local":return He(`lscope['${t.var}']`);case"global":return He(`gscope['${t.var}']`);default:throw K(t.scope),new m(null,"NeverReach",n)}}function Le(e,n){try{if("MemberExpression"===n.callee.type){let t;t=!0===n.callee.computed?ue(e,n.callee.property):"'"+n.callee.property.name+"'";let r="[";for(let o=0;o<n.arguments.length;o++)o>0&&(r+=", "),r+=ue(e,n.arguments[o]);return r+="]",e.isAsync?"(yield lang.callModuleFunction("+ue(e,n.callee.object)+","+r+","+t+",runtimeCtx))":"lang.callModuleFunction("+ue(e,n.callee.object)+","+r+","+t+",runtimeCtx)"}if("Identifier"!==n.callee.type)throw new m(null,"FunctionNotFound",n);const t=re(e,n.callee,"FunctionNotFound");if("global"===t.scope)switch(t.name){case"iif":return Te(e,n);case"when":return Ue(e,n);case"defaultvalue":return De(e,n);case"decode":return Ge(e,n)}let r;switch(t.scope){case"local":r=He(`lscope['${t.var}']`);break;case"global":r=He(`gscope['${t.var}']`);break;default:throw K(t.scope),new m(null,"NeverReach",n.callee)}let o="[";for(let l=0;l<n.arguments.length;l++)l>0&&(o+=", "),o+=ue(e,n.arguments[l]);return o+="]",e.isAsync?"(yield lang.callfunc("+r+","+o+",runtimeCtx) )":"lang.callfunc("+r+","+o+",runtimeCtx)"}catch(t){throw t}}function Te(e,n){try{if(3!==n.arguments.length)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ue(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${ue(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${ue(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function De(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId(),r=e.symbols.nextTempVarId();return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ue(e,n.arguments[0])};\n var ${r} = ${ue(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${r});\n return ${t} != null && ${t} !== "" ? ${t} : ${ue(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} = ${ue(e,n.arguments[0])};\n if (${t} === null) {\n return ${ue(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${ue(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${ue(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ue(e,n){try{if(n.arguments.length<3)throw new m(null,"WrongNumberOfParameters",n);if(n.arguments.length%2==0)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId();let r="var ";for(let o=0;o<n.arguments.length-1;o+=2)r+=`${t} = lang.mustBoolean(${ue(e,n.arguments[o])}, runtimeCtx);\n if (${t} === true ) {\n return ${ue(e,n.arguments[o+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${r}\n return ${ue(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ge(e,n){try{if(n.arguments.length<2)throw new m(null,"WrongNumberOfParameters",n);if(2===n.arguments.length)return`(${ue(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new m(null,"WrongNumberOfParameters",n);const t=e.symbols.nextTempVarId(),r=e.symbols.nextTempVarId();let o="var ";for(let l=1;l<n.arguments.length-1;l+=2)o+=`${r} = ${ue(e,n.arguments[l])};\n if (lang.binary(${r}, ${t}, "==") === true ) {\n return ${ue(e,n.arguments[l+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ue(e,n.arguments[0])};\n ${o}\n return ${ue(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ke(e,n){try{return se(e,n,(e,n)=>{throw new c(e,"Unrecognized",n)})}catch(t){throw t}}function qe(e){const n=function(){this.textformatting=u.textFormatting()};n.prototype=Object.create(null),n.provided=new Set(["textformatting","infinity","pi"]),n.prototype.infinity=Number.POSITIVE_INFINITY,n.prototype.pi=Math.PI;for(const[t,r]of Object.entries(e))n.prototype[t]=new d(r),n.provided.add(t);return n}function Pe(){const e=Object.create(null);_(e,se),U(e,se),V(e,se,le),T(e,se),R(e,se),D(e,se),G(e,se),e.iif=Ke,e.decode=Ke,e.when=Ke,e.defaultvalue=Ke;const n=qe(e);L(e,se);return{ScopeSync:qe(e),ScopeAsync:n}}const{ScopeSync:ze,ScopeAsync:We}=Pe();function Ze(e,n){const t={mode:n,compiled:!0,functions:Object.create(null),signatures:[],standardFunction:se,standardFunctionAsync:se,evaluateIdentifier:le};for(const r of e)r.registerFunctions(t);if("sync"===n)for(const[r,o]of Object.entries(t.functions))ze.prototype[r]=new d(o),ze.provided.add(r);else for(const[r,o]of Object.entries(t.functions))We.prototype[r]=new d(o),We.provided.add(r);for(const r of t.signatures)N(r,n)}Ze([B],"sync"),Ze([B],"async"),Ze([E],"async");const Je=Symbol("uninitialized"),Ye="lang.uninitialized";function He(e){return`lang.requireInitialized(${e})`}const Qe={uninitialized:Je,requireInitialized(e){if(e===Je)throw new c(null,"InvalidIdentifier",null);return e},isNumber:e=>Q(e),isArray:e=>H(e),isImmutableArray:e=>S(e),isDictionaryLike:e=>$(e),isString:e=>Y(e),isDictionary:e=>k(e),isGeometry:e=>A(e),getGeometryKeys:e=>i(e),geometryMember:(e,n,t,r,o=1)=>s(e,n,t,r,o),error(e){throw new c(null,e,null)},__awaiter(e,n,t,r){const o=r.apply(e,n||[]);let l=o.next();for(;!l.done&&!P(l.value);)l=o.next(l.value);return l.done?l.value:new Promise((e,n)=>{function t(r){for(;!r.done;){if(P(r.value))return void Promise.resolve(r.value).then(e=>{try{t(o.next(e))}catch(r){n(r)}},e=>{try{t(o.throw(e))}catch(r){n(r)}});try{r=o.next(r.value)}catch(l){return void n(l)}}e(r.value)}t(l)})},functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new c(null,"MaximumCallDepth",null);const t=e.apply(this,arguments);return P(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)},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new c(n,"BooleanConditionRequired",null)},castString:e=>M(e),aCheck(e,n){if(v(e)){if("ArrayExpression"===n)throw new c(null,"NoFunctionInArray",null);if("ObjectExpression"===n)throw new c(null,"NoFunctionInDictionary",null);throw new c(null,"NoFunctionInTemplateLiteral",null)}return e===I?null:e},Dictionary:u,Feature:p,UserDefinedCompiledFunction:ae,dictionary(e){const n=Object.create(null),t=new Map;for(let o=0;o<e.length;o+=2){if(v(e[o+1]))throw new c(null,"NoFunctionInDictionary",null);if(!1===Y(e[o]))throw new c(null,"KeyMustBeString",null);let r=e[o].toString();const l=r.toLowerCase();t.has(l)?r=t.get(l):t.set(l,r),e[o+1]===I?n[r]=null:n[r]=e[o+1]}const r=new u(n);return r.immutable=!1,r},entry:(e,n)=>u.containerEntry(e,n),strCheck(e){if(!1===Y(e))throw new c(null,"KeyMustBeString",null);return e},unary(e,n){if(X(e)){if("!"===n)return!e;if("-"===n)return-1*F(e);if("+"===n)return 1*F(e);if("~"===n)return~F(e);throw new c(null,"UnsupportUnaryOperator",null)}if("-"===n)return-1*F(e);if("+"===n)return 1*F(e);if("~"===n)return~F(e);throw new c(null,"UnsupportUnaryOperator",null)},logicalCheck(e){if(!1===X(e))throw new c(null,"LogicExpressionOrAnd",null);return e},logical(e,n,t){if(X(e)&&X(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new c(null,"LogicExpressionOrAnd",null)}throw new c(null,"LogicExpressionOrAnd",null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(F(e),F(n),t);case"==":case"=":return C(e,n);case"!=":return!C(e,n);case"<":case">":case"<=":case">=":return O(e,n,t);case"+":return Y(e)||Y(n)?M(e)+M(n):F(e)+F(n);case"-":return F(e)-F(n);case"*":return F(e)*F(n);case"/":return F(e)/F(n);case"%":return F(e)%F(n);default:throw new c(null,"UnsupportedOperator",null)}},assign(e,n,t){switch(n){case"=":return e===I?null:e;case"/=":return F(t)/F(e);case"*=":return F(t)*F(e);case"-=":return F(t)-F(e);case"+=":return Y(t)||Y(e)?M(t)+M(e):F(t)+F(e);case"%=":return F(t)%F(e);default:throw new c(null,"UnsupportedOperator",null)}},update(e,n,t,r){const o=F(this.requireInitialized(e[n]));return e[n]="++"===t?o+1:o-1,!1===r?o:"++"===t?o+1:o-1},graphicToFeature:(e,n,t)=>null===e?null:p.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,r){let o;if(H(e)){if(!Q(n))throw new c(null,"ArrayAccessMustBeNumber",null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new c(null,"OutOfBounds",null);o=F(e[n]),e[n]="++"===t?o+1:o-1}else if(e instanceof u){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0!==e.hasField(n))throw new c(null,"FieldNotFound",null,{key:n});o=F(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else if(x(e)){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0!==e.hasField(n))throw new c(null,"FieldNotFound",null);o=F(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else{if(S(e))throw new c(null,"Immutable",null);if(!(e instanceof tn))throw new c(null,"InvalidIdentifier",null);if(!1===Y(n))throw new c(null,"ModuleAccessorMustBeString",null);if(!0!==e.hasGlobal(n))throw new c(null,"ModuleExportNotFound",null);o=F(e.global(n)),e.setGlobal(n,"++"===t?o+1:o-1)}return!1===r?o:"++"===t?o+1:o-1},assignmember(e,n,t,r){if(H(e)){if(!Q(n))throw new c(null,"ArrayAccessMustBeNumber",null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new c(null,"OutOfBounds",null);if(n===e.length){if("="!==t)throw new c(null,"OutOfBounds",null);e[n]=this.assign(r,t,e[n])}else e[n]=this.assign(r,t,e[n])}else if(e instanceof u){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0===e.hasField(n))e.setField(n,this.assign(r,t,e.field(n)));else{if("="!==t)throw new c(null,"FieldNotFound",null);e.setField(n,this.assign(r,t,null))}}else if(x(e)){if(!1===Y(n))throw new c(null,"KeyAccessorMustBeString",null);if(!0===e.hasField(n))e.setField(n,this.assign(r,t,e.field(n)));else{if("="!==t)throw new c(null,"FieldNotFound",null);e.setField(n,this.assign(r,t,null))}}else{if(S(e))throw new c(null,"Immutable",null);if(!(e instanceof tn))throw new c(null,"InvalidIdentifier",null);if(!1===Y(n))throw new c(null,"ModuleAccessorMustBeString",null);if(!e.hasGlobal(n))throw new c(null,"ModuleExportNotFound",null);e.setGlobal(n,this.assign(r,t,e.global(n)))}},member(e,n){if(null===e)throw new c(null,"MemberOfNull",null);if(e instanceof u||$(e)){if(Y(n))return e.field(n);throw new c(null,"InvalidMemberAccessKey",null)}if(e instanceof W){if(Y(n))return s(e,n,null,null);throw new c(null,"InvalidMemberAccessKey",null)}if(H(e)){if(Q(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new c(null,"OutOfBounds",null);return e[n]}throw new c(null,"InvalidMemberAccessKey",null)}if(Y(e)){if(Q(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new c(null,"OutOfBounds",null);return e[n]}throw new c(null,"InvalidMemberAccessKey",null)}if(S(e)){if(Q(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new c(null,"OutOfBounds",null);return e.get(n)}throw new c(null,"InvalidMemberAccessKey",null)}if(e instanceof tn){if(Y(n))return e.global(n);throw new c(null,"InvalidMemberAccessKey",null)}throw new c(null,"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 r=n.moduleFactory[t]({moduleSingletons:n.moduleSingletons,depthCounter:n.depthCounter,lrucache:n.lrucache,interceptor:n.interceptor,services:n.services,console:n.console,abortSignal:n.abortSignal,timeZone:n.timeZone??null,spatialReference:n.spatialReference});return n.moduleSingletons[t]=r,r},callModuleFunction(e,n,t,r){if(!(e instanceof tn))throw new c(null,"FunctionNotFound",null);const o=e.global(t);if(!1===v(o))throw new c(null,"CallNonFunction",null);return o.call(r,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>a(e,n)};function Xe(e){console.log(e)}function en(t,o,l=!1){let a=null;t.usesModules&&(a=new r(null,t.loadedModules));const s=Object.create(null),i=new Set(Object.keys(o?.vars||{}).map(n=>e(n))),u=new Set(Object.keys(o?.customfunctions||{}).map(n=>e(n))),m=ie(t,l?We.provided:ze.provided,new Set([...i,...u]),l,a,s);let f;f=l?["var runtimeCtx = this.prepare(context, true);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","return lang.__awaiter(this, void 0, void 0, function* () {"," function mainBody() {"," return lang.__awaiter(this, void 0, void 0, function* () {",` ${m.body}`," });"," }"," return this.postProcess(yield mainBody());","});"].join("\n"):["var runtimeCtx = this.prepare(context, false);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","function mainBody() {",` ${m.body}`,"}","return this.postProcess(mainBody());"].join("\n");const{symbolMetadata:d,moduleFactoryMap:g}=m,h={lc:w,lang:Qe,postProcess(e){if(b(e))return null;if(v(e))throw new c(null,"IllegalResult",null);return e},prepare(e,t){const r=e.spatialReference??Z.WebMercator,o=t?new We:new ze;for(const n of u)null!=e.customfunctions&&n in e.customfunctions?o[n]=e.customfunctions[n]??null:o[n]=Je;for(const n of i){if(null==e.vars||!(n in e.vars)){n in o||(o[n]=Je);continue}const t=e.vars[n]??null;J(t)?o[n]=p.createFromGraphic(t,e.timeZone??null):o[n]=t}return{lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Xe,abortSignal:e.abortSignal??n,timeZone:e.timeZone??null,spatialReference:r,track:e.track,globalScope:o,localStack:[],depthCounter:{depth:1},symbolMetadata:d,moduleFactory:s,moduleFactoryMap:g,moduleSingletons:Object.create(null)}}};return new Function("context",f).bind(h)}async function nn(){return Ze([await import("./functions/geomasync.js")],"async"),!0}class tn extends t{constructor(e){super(),this.moduleContext=e}hasGlobal(n){const t=this.moduleContext.symbolMetadata.exports;return t.has(n)||t.has(e(n))}setGlobal(n,t){if(v(t))throw new c(null,"AssignModuleFunction",null);const r=this.moduleContext.symbolMetadata.globals.get(e(n));if(null==r)throw new c(null,"ModuleExportNotFound",null);this.moduleContext.globalScope[r]=t}global(n){const t=this.moduleContext.symbolMetadata.globals.get(e(n));if(null==t)throw new c(null,"ModuleExportNotFound",null);const r=this.moduleContext.globalScope,o=Qe.requireInitialized(r[t]);if(v(o)&&!(o instanceof h)){const e=new h;return e.fn=o,e.parameterEvaluator=se,e.context=this.moduleContext,r[t]=e,e}return o}}function rn(e,t,o){const l=new r(null,e.loadedModules),a=ie(e,o?We.provided:ze.provided,new Set,o,l,t);let s;s=o?["var runtimeCtx = this.prepare(context, true);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","return lang.__awaiter(this, void 0, void 0, function* () {"," function mainBody() {"," return lang.__awaiter(this, void 0, void 0, function* () {",` ${a.body}`," });"," }"," yield mainBody();"," return this.prepareModule(runtimeCtx);","});"].join("\n"):["var runtimeCtx = this.prepare(context, false);","var lc = this.lc;","var lang = this.lang;","var gscope = runtimeCtx.globalScope;","function mainBody() {",` ${a.body}`,"}","mainBody();","return this.prepareModule(runtimeCtx);"].join("\n");const{symbolMetadata:i,moduleFactoryMap:u}=a,c={lc:w,lang:Qe,prepareModule:e=>new tn(e),prepare(e,r){const o=e.spatialReference??Z.WebMercator,l=r?new We:new ze;return{lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Xe,abortSignal:e.abortSignal??n,timeZone:e.timeZone??null,spatialReference:o,track:null,globalScope:l,localStack:[],depthCounter:e.depthCounter,symbolMetadata:i,moduleFactory:t,moduleFactoryMap:u,moduleSingletons:e.moduleSingletons}}};return new Function("context",s).bind(c)}export{ae as UserDefinedCompiledFunction,en as compileScript,nn as enableAsyncSupport,Ze as extend};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as i}from"./compilerUtils.js";import{getNestedOptionalValue as s,getGeometryKeys as l,geometryMember as a}from"./containerUtils.js";import c from"./Dictionary.js";import{ArcadeExecutionError as u,ensureArcadeExecutionError as f}from"./executionError.js";import p from"./Feature.js";import{NativeFunction as h,ArcadeFunction as d,ScopeMarshalledFunction as w,wrapModuleScopedResponse as m}from"./FunctionWrapper.js";import{R as g,I as b,q as y,i as v,z as x,A as S,v as F,B as R,x as I,j,r as O,h as A,s as M,u as N,w as k,y as C,k as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as G}from"../chunks/array.js";import{registerFunctions as U}from"./functions/date.js";import{registerFunctions as D}from"./functions/feature.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as L}from"./functions/geomsync.js";import{registerFunctions as _}from"./functions/maths.js";import{registerFunctions as z}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import{registerFunctions as q}from"./functions/track.js";import"../core/has.js";import W from"../core/Logger.js";import P from"../geometry/Geometry.js";import V from"../geometry/SpatialReference.js";import{isGraphic as T,isBoolean as Y,isArray as $,isString as H,isNumber as J}from"../support/guards.js";const Q=()=>W.getLogger("esri.arcade.arcadeRuntime"),X=Symbol("uninitialized");function ee(e){if(e===X)throw new u(null,"InvalidIdentifier",null)}function te(e){return ee(e),e}function ne(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new u(t,"InvalidIdentifier",n)}function re(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return ee(e),e.value}const i=t.globalScope[o];if(void 0!==i)return ee(i),i.value;throw new u(t,r,n)}const oe=function(){};oe.prototype=Object.freeze(Object.create(null));class ie extends d{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}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,abortSignal:this.context.abortSignal,localScope:new oe,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",null);return se(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return ce(e,t,(n,r,o)=>{const i={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,abortSignal:e.abortSignal,localScope:new oe,track:e.track};if(i.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",t);return se(i,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,(o,i,s)=>{const l={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,abortSignal:e.abortSignal,localScope:new oe,track:e.track};return s=s.map(t=>!v(t)||t instanceof w?t:m(t,e,r)),m(se(l,this.definition.body,this._params,this._locals,s,t),n,r)})}}function se(e,t,n,r,o,i){try{if(n.length!==o.length)throw new u(e,"WrongNumberOfParameters",i);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=X}const s=fe(e,t);if(s instanceof g)return s.value;if(s===x)throw new u(e,"UnexpectedToken",i);if(s===S)throw new u(e,"UnexpectedToken",i);return s instanceof b?s.value:s}catch(s){throw s}}class le extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t),r=this.moduleGlobalContext.globalScope[n];if(ee(r),v(r.value)&&!(r.value instanceof w)){const e=new w;return e.fn=r.value,e.parameterEvaluator=ce,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(v(n))throw new u(null,"AssignModuleFunction",null);const r=e(t);if(void 0===this.moduleGlobalContext.globalScope[r])throw new u(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static load(e,n){const{globals:i,exports:s}=o(n),l=new Ve;for(const t of i)t in l||(l[t]=X);const a=e.spatialReference??V.WebMercator,c={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:a,track:e.track,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:s,localScope:null,globalScope:l};return Fe(c,n),new le(c)}}function ae(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(ue(e,t.arguments[r]));return n}function ce(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,ae(e,t))}catch(r){throw r}}function ue(e,t){try{switch(t.type){case"AssignmentExpression":return ve(e,t);case"UpdateExpression":return be(e,t);case"TemplateLiteral":return Ue(e,t);case"Identifier":return De(e,t);case"MemberExpression":return Ne(e,t);case"Literal":return t.value;case"CallExpression":return Ke(e,t);case"UnaryExpression":return ke(e,t);case"BinaryExpression":return Ee(e,t);case"LogicalExpression":return Be(e,t);case"ArrayExpression":return Ce(e,t);case"ObjectExpression":return pe(e,t);default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}function fe(e,t){switch(t.type){case"EmptyStatement":return F;case"VariableDeclaration":return Ae(e,t);case"ImportDeclaration":return je(e,t);case"ExportNamedDeclaration":return Oe(e,t);case"BlockStatement":return Fe(e,t);case"FunctionDeclaration":return Ie(e,t);case"ReturnStatement":return Re(e,t);case"IfStatement":return Se(e,t);case"ExpressionStatement":return xe(e,t);case"BreakStatement":return x;case"ContinueStatement":return S;case"ForStatement":return we(e,t);case"ForInStatement":return he(e,t);case"ForOfStatement":return de(e,t);case"WhileStatement":return me(e,t);default:throw new u(e,"Unrecognized",t)}}function pe(e,t){const n=Object.create(null),r=new Map;for(let i=0;i<t.properties.length;i++){const o=t.properties[i],s="Identifier"===o.key.type?o.key.name:ue(e,o.key),l=ue(e,o.value);if(v(l))throw new u(e,"NoFunctionInDictionary",t);if(!1===H(s))throw new u(e,"KeyMustBeString",t);let a=s.toString();const c=a.toLowerCase();r.has(c)?a=r.get(c):r.set(c,a),n[a]=l===F?null:l}const o=new c(n);return o.immutable=!1,o}function he(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&Ae(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let n=0;n<o;n++){r.scope[r.id]={value:n};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}if(n instanceof c||O(n)){const o=n.keys();for(let n=0;n<o.length;n++){r.scope[r.id]={value:o[n]};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(A(n)){for(const o of l(n)){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}return F}function de(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&fe(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let i=0;i<o;i++){if(i>=n.length)throw new u(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:n.get(o)};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(n instanceof c||O(n)){for(const o of n.keys()){const i=n.field(o);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}if(A(n)){for(const o of l(n)){const i=a(n,o,e,t,1);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}return F}function we(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?fe(e,t.init):ue(e,t.init));const n={testResult:!0,lastAction:F};do{ge(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof g?n.lastAction:F}function me(e,t){const n={testResult:!0,lastAction:F};if(n.testResult=ue(e,t.test),!1===n.testResult)return F;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t);for(;!0===n.testResult&&(n.lastAction=fe(e,t.body),n.lastAction!==x)&&!(n.lastAction instanceof g);)if(n.testResult=ue(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new u(e,"BooleanConditionRequired",t);return n.lastAction instanceof g?n.lastAction:F}function ge(e,t,n){if(null!==t.test){if(n.testResult=ue(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t)}n.lastAction=fe(e,t.body),n.lastAction!==x?n.lastAction instanceof g?n.testResult=!1:null!==t.update&&ue(e,t.update):n.testResult=!1}function be(e,t){if("CallExpression"===t.argument.type)throw new u(e,"NeverReach",t);let n;if("MemberExpression"===t.argument.type){const r=ue(e,t.argument.object);let o;if(!0===t.argument.computed)o=ue(e,t.argument.property);else{if("Identifier"!==t.argument.property.type)throw new u(e,"Unrecognized",t);o=t.argument.property.name}if($(r)){if(!J(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new u(e,"OutOfBounds",t);n=M(r[o]),r[o]="++"===t.operator?n+1:n-1}else if(r instanceof c){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else if(E(r)){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else{if(j(r))throw new u(e,"Immutable",t);if(!(r instanceof le))throw new u(e,"InvalidParameter",t);if(!1===H(o))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);n=M(r.global(o)),r.setGlobal(o,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}const r=ne(e,t.argument);n=M(te(r.var).value);const o="++"===t.operator?n+1:n-1;return r.scope[r.id]={value:o},!1===t.prefix?n:"++"===t.operator?n+1:n-1}function ye(e,t,n,r,o){switch(t){case"=":return e===F?null:e;case"/=":return M(n)/M(e);case"*=":return M(n)*M(e);case"-=":return M(n)-M(e);case"+=":return H(n)||H(e)?N(n)+N(e):M(n)+M(e);case"%=":return M(n)%M(e);default:throw new u(o,"UnsupportedOperator",r)}}function ve(e,t){if("MemberExpression"===t.left.type){const n=ue(e,t.left.object);let r;if(!0===t.left.computed)r=ue(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new u(e,"InvalidIdentifier",t);r=t.left.property.name}const o=ue(e,t.right);if($(n)){if(!J(r))throw new u(e,"ArrayAccessMustBeNumber",t);if(r<0&&(r=n.length+r),r<0||r>n.length)throw new u(e,"OutOfBounds",t);if(r===n.length){if("="!==t.operator)throw new u(e,"OutOfBounds",t);n[r]=ye(o,t.operator,n[r],t,e)}else n[r]=ye(o,t.operator,n[r],t,e)}else if(n instanceof c){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else if(E(n)){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else{if(j(n))throw new u(e,"Immutable",t);if(!(n instanceof le))throw new u(e,"InvalidIdentifier",t);if(!1===H(r))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==n.hasGlobal(r))throw new u(e,"ModuleExportNotFound",t);n.setGlobal(r,ye(o,t.operator,n.global(r),t,e))}return F}const n=ne(e,t.left),r=ue(e,t.right);return n.scope[n.id]={value:ye(r,t.operator,"="!==t.operator?te(n.var).value:null,t,e)},F}function xe(e,t){const n=ue(e,t.expression);return n===F?F:new b(n)}function Se(e,t){const n=ue(e,t.test);if(!0===n)return fe(e,t.consequent);if(!1===n)return null!==t.alternate?fe(e,t.alternate):F;throw new u(e,"BooleanConditionRequired",t)}function Fe(e,t){let n=F;for(let r=0;r<t.body.length;r++)if(n=fe(e,t.body[r]),n instanceof g||n===x||n===S)return n;return n}function Re(e,t){if(null===t.argument)return new g(F);const n=ue(e,t.argument);return new g(n)}function Ie(t,n){if(null!=t.localScope)throw Q().error("Function declarations are only valid in global scope."),new u(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw Q().error(`Function "${r}" not declared.`),new u(t,"NeverReach",n);const o=i(n),s=n.params.map(t=>e(t)),l=Array.from(o).filter(e=>!s.includes(e));return t.globalScope[r]={value:new ie(n,t,s,l)},F}function je(e,t){const n=ne(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw Q().error("Internal error: module loader not initialized"),new u(e,"NeverReach",t);const o=r.loadLibrary(n.id);let i;return r._moduleSingletons?.has(o.uri)?i=r._moduleSingletons.get(o.uri):(i=le.load(e,o.syntax),r._moduleSingletons?.set(o.uri,i)),n.scope[n.id]={value:i},F}function Oe(e,t){return fe(e,t.declaration),F}function Ae(e,t){for(let n=0;n<t.declarations.length;n++)Me(e,t.declarations[n]);return F}function Me(e,t){let n=null===t.init?null:ue(e,t.init);if(n===F&&(n=null),"Identifier"!==t.id.type)throw new u(e,"InvalidIdentifier",t);const r=ne(e,t.id);r.scope[r.id]={value:n}}function Ne(e,t){try{const n=ue(e,t.object);if(null===n)throw new u(e,"MemberOfNull",t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof c||O(n))return n.field(t.property.name);if(n instanceof P)return a(n,t.property.name,e,t);if(n instanceof le){if(!n.hasGlobal(t.property.name))throw new u(e,"InvalidIdentifier",t);return n.global(t.property.name)}}throw new u(e,"InvalidMemberAccessKey",t)}let r=ue(e,t.property);if(n instanceof c||O(n)){if(H(r))return n.field(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof le){if(H(r))return n.global(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof P){if(H(r))return a(n,r,e,t);throw new u(e,"InvalidMemberAccessKey",t)}if($(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(H(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(j(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new u(e,"OutOfBounds",t);return n.get(r)}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}catch(n){throw n}}function ke(e,t){try{const n=ue(e,t.argument);if(Y(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);if("~"===t.operator)return~M(n);throw new u(e,"UnsupportUnaryOperator",t)}if("~"===t.operator)return~M(n);if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);throw new u(e,"UnsupportUnaryOperator",t)}catch(n){throw n}}function Ce(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=ue(e,t.elements[r]);if(v(o))throw new u(e,"NoFunctionInArray",t);o===F?n.push(null):n.push(o)}return n}catch(n){throw n}}function Ee(e,t){try{const n=ue(e,t.left),r=ue(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return C(M(n),M(r),t.operator);case"==":return I(n,r);case"!=":return!I(n,r);case"<":case">":case"<=":case">=":return k(n,r,t.operator);case"+":return H(n)||H(r)?N(n)+N(r):M(n)+M(r);case"-":return M(n)-M(r);case"*":return M(n)*M(r);case"/":return M(n)/M(r);case"%":return M(n)%M(r);default:throw new u(e,"UnsupportedOperator",t)}}catch(n){throw n}}function Be(e,t){try{const n=ue(e,t.left);if(Y(n))switch(t.operator){case"||":{if(!0===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}default:throw new u(e,"LogicExpressionOrAnd",t)}throw new u(e,"LogicalExpressionOnlyBoolean",t)}catch(n){throw n}}function Ge(e,t,n){if(v(e))throw new u(t,"NoFunctionInTemplateLiteral",n);return e}function Ue(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){n+=t.expressions[r]?N(Ge(ue(e,t.expressions[r]),e,t)):"",r++}return n}function De(e,t){return re(e,t)}function Ke(e,t){try{if("MemberExpression"===t.callee.type){const n=ue(e,t.callee.object);if(!(n instanceof le))throw new u(e,"FunctionNotFound",t);const r=!1===t.callee.computed?t.callee.property.name:ue(e,t.callee.property);if(!n.hasGlobal(r))throw new u(e,"FunctionNotFound",t);const o=n.global(r);if(!v(o))throw new u(e,"CallNonFunction",t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new u(e,"FunctionNotFound",t);const n=re(e,t.callee,"FunctionNotFound");if(v(n))return n.call(e,t);throw new u(e,"CallNonFunction",t)}catch(n){throw n}}function Le(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,3,3,e,t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",t);return ue(e,!0===r?n[1]:n[2])}catch(n){throw n}}function _e(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,2,3,e,t);const r=ue(e,n[0]);if(3===n.length){const t=ue(e,n[1]),o=s(r,t);return null!=o&&""!==o?o:ue(e,n[2])}return null===r||""===r||void 0===r?ue(e,n[1]):r}catch(n){throw n}}function ze(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<2)throw new u(e,"WrongNumberOfParameters",t);if(2===n.length)return ue(e,n[1]);{if((n.length-1)%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);return Ze(e,t,1,r)}}catch(n){throw n}}function Ze(e,t,n,r){try{const o=t.arguments,i=ue(e,o[n]);if(I(i,r))return ue(e,o[n+1]);{const i=o.length-n;return 1===i?ue(e,o[n]):2===i?null:3===i?ue(e,o[n+2]):Ze(e,t,n+2,r)}}catch(o){throw o}}function qe(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<3)throw new u(e,"WrongNumberOfParameters",t);if(n.length%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",n[0]);return We(e,t,0,r)}catch(n){throw n}}function We(e,t,n,r){try{const o=t.arguments;if(!0===r)return ue(e,o[n+1]);if(3===o.length-n)return ue(e,o[n+2]);{const r=ue(e,o[n+2]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",o[n+2]);return We(e,t,n+2,r)}}catch(o){throw o}}function Pe(){const e=Object.create(null);U(e,ce),Z(e,ce),D(e,ce,De),_(e,ce),K(e,ce),z(e,ce),L(e,ce),q(e,ce),e.iif=Le,e.defaultvalue=_e,e.decode=ze,e.when=qe;const t=function(){this.textformatting={value:c.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new h(r)});return t}const Ve=Pe();function Te(e){const t={mode:"sync",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ce,evaluateIdentifier:De};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Ve.prototype[n]=Object.freeze({value:new h(r)});for(let n=0;n<t.signatures.length;n++)B(t.signatures[n],"sync")}function Ye(e){console.log(e)}function $e(n,i){const s=new Set(Object.keys(i?.vars||{}).map(t=>e(t))),l=new Set(Object.keys(i?.customfunctions||{}).map(t=>e(t))),{globals:a,exports:c}=o(n);return e=>{const o=e.spatialReference??V.WebMercator;let i=null;n.usesModules&&(i=new r(new Map,n.loadedModules));const f=new Ve;for(const t of l)null!=e.customfunctions&&t in e.customfunctions?f[t]={value:new h(e.customfunctions[t])}:f[t]=X;for(const t of s){if(null==e.vars||!(t in e.vars)){t in f||(f[t]=X);continue}const n=e.vars[t]??null;T(n)?f[t]={value:p.createFromGraphic(n,e.timeZone??null)}:f[t]={value:n}}for(const t of a)t in f||(f[t]=X);const d={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:i,exports:c,localScope:null,globalScope:f},w=Fe(d,n);if(w instanceof g||w instanceof b){const e=w.value;if(y(e))return null;if(v(e))throw new u(d,"IllegalResult",null);return e}if(y(w))return null;if(w===x)throw new u(d,"IllegalResult",null);if(w===S)throw new u(d,"IllegalResult",null);throw new u(d,"NeverReach",null)}}function He(e,t){return $e(e,t)(t)}Te([G]);export{He as executeScript,Te as extend,$e as prepareScript};
5
+ import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as i}from"./compilerUtils.js";import{getNestedOptionalValue as s,getGeometryKeys as l,geometryMember as a}from"./containerUtils.js";import c from"./Dictionary.js";import{ArcadeExecutionError as u,ensureArcadeExecutionError as f}from"./executionError.js";import{Feature as p}from"./Feature.js";import{NativeFunction as h,ArcadeFunction as d,ScopeMarshalledFunction as w,wrapModuleScopedResponse as m}from"./FunctionWrapper.js";import{R as g,I as b,q as y,i as v,z as x,A as S,v as F,B as R,x as I,j,r as O,h as A,s as M,u as N,w as k,y as C,k as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as G}from"../chunks/array.js";import{registerFunctions as U}from"./functions/date.js";import{registerFunctions as D}from"./functions/feature.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as L}from"./functions/geomsync.js";import{registerFunctions as _}from"./functions/maths.js";import{registerFunctions as z}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import{registerFunctions as q}from"./functions/track.js";import"../core/has.js";import W from"../core/Logger.js";import P from"../geometry/Geometry.js";import V from"../geometry/SpatialReference.js";import{isGraphic as T,isBoolean as Y,isArray as $,isString as H,isNumber as J}from"../support/guards.js";const Q=()=>W.getLogger("esri.arcade.arcadeRuntime"),X=Symbol("uninitialized");function ee(e){if(e===X)throw new u(null,"InvalidIdentifier",null)}function te(e){return ee(e),e}function ne(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new u(t,"InvalidIdentifier",n)}function re(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return ee(e),e.value}const i=t.globalScope[o];if(void 0!==i)return ee(i),i.value;throw new u(t,r,n)}const oe=function(){};oe.prototype=Object.freeze(Object.create(null));class ie extends d{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}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,abortSignal:this.context.abortSignal,localScope:new oe,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",null);return se(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return ce(e,t,(n,r,o)=>{const i={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,abortSignal:e.abortSignal,localScope:new oe,track:e.track};if(i.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",t);return se(i,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,(o,i,s)=>{const l={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,abortSignal:e.abortSignal,localScope:new oe,track:e.track};return s=s.map(t=>!v(t)||t instanceof w?t:m(t,e,r)),m(se(l,this.definition.body,this._params,this._locals,s,t),n,r)})}}function se(e,t,n,r,o,i){try{if(n.length!==o.length)throw new u(e,"WrongNumberOfParameters",i);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=X}const s=fe(e,t);if(s instanceof g)return s.value;if(s===x)throw new u(e,"UnexpectedToken",i);if(s===S)throw new u(e,"UnexpectedToken",i);return s instanceof b?s.value:s}catch(s){throw s}}class le extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t),r=this.moduleGlobalContext.globalScope[n];if(ee(r),v(r.value)&&!(r.value instanceof w)){const e=new w;return e.fn=r.value,e.parameterEvaluator=ce,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(v(n))throw new u(null,"AssignModuleFunction",null);const r=e(t);if(void 0===this.moduleGlobalContext.globalScope[r])throw new u(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static load(e,n){const{globals:i,exports:s}=o(n),l=new Ve;for(const t of i)t in l||(l[t]=X);const a=e.spatialReference??V.WebMercator,c={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:a,track:e.track,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:s,localScope:null,globalScope:l};return Fe(c,n),new le(c)}}function ae(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(ue(e,t.arguments[r]));return n}function ce(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,ae(e,t))}catch(r){throw r}}function ue(e,t){try{switch(t.type){case"AssignmentExpression":return ve(e,t);case"UpdateExpression":return be(e,t);case"TemplateLiteral":return Ue(e,t);case"Identifier":return De(e,t);case"MemberExpression":return Ne(e,t);case"Literal":return t.value;case"CallExpression":return Ke(e,t);case"UnaryExpression":return ke(e,t);case"BinaryExpression":return Ee(e,t);case"LogicalExpression":return Be(e,t);case"ArrayExpression":return Ce(e,t);case"ObjectExpression":return pe(e,t);default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}function fe(e,t){switch(t.type){case"EmptyStatement":return F;case"VariableDeclaration":return Ae(e,t);case"ImportDeclaration":return je(e,t);case"ExportNamedDeclaration":return Oe(e,t);case"BlockStatement":return Fe(e,t);case"FunctionDeclaration":return Ie(e,t);case"ReturnStatement":return Re(e,t);case"IfStatement":return Se(e,t);case"ExpressionStatement":return xe(e,t);case"BreakStatement":return x;case"ContinueStatement":return S;case"ForStatement":return we(e,t);case"ForInStatement":return he(e,t);case"ForOfStatement":return de(e,t);case"WhileStatement":return me(e,t);default:throw new u(e,"Unrecognized",t)}}function pe(e,t){const n=Object.create(null),r=new Map;for(let i=0;i<t.properties.length;i++){const o=t.properties[i],s="Identifier"===o.key.type?o.key.name:ue(e,o.key),l=ue(e,o.value);if(v(l))throw new u(e,"NoFunctionInDictionary",t);if(!1===H(s))throw new u(e,"KeyMustBeString",t);let a=s.toString();const c=a.toLowerCase();r.has(c)?a=r.get(c):r.set(c,a),n[a]=l===F?null:l}const o=new c(n);return o.immutable=!1,o}function he(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&Ae(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let n=0;n<o;n++){r.scope[r.id]={value:n};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}if(n instanceof c||O(n)){const o=n.keys();for(let n=0;n<o.length;n++){r.scope[r.id]={value:o[n]};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(A(n)){for(const o of l(n)){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}return F}function de(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&fe(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let i=0;i<o;i++){if(i>=n.length)throw new u(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:n.get(o)};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(n instanceof c||O(n)){for(const o of n.keys()){const i=n.field(o);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}if(A(n)){for(const o of l(n)){const i=a(n,o,e,t,1);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}return F}function we(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?fe(e,t.init):ue(e,t.init));const n={testResult:!0,lastAction:F};do{ge(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof g?n.lastAction:F}function me(e,t){const n={testResult:!0,lastAction:F};if(n.testResult=ue(e,t.test),!1===n.testResult)return F;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t);for(;!0===n.testResult&&(n.lastAction=fe(e,t.body),n.lastAction!==x)&&!(n.lastAction instanceof g);)if(n.testResult=ue(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new u(e,"BooleanConditionRequired",t);return n.lastAction instanceof g?n.lastAction:F}function ge(e,t,n){if(null!==t.test){if(n.testResult=ue(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t)}n.lastAction=fe(e,t.body),n.lastAction!==x?n.lastAction instanceof g?n.testResult=!1:null!==t.update&&ue(e,t.update):n.testResult=!1}function be(e,t){if("CallExpression"===t.argument.type)throw new u(e,"NeverReach",t);let n;if("MemberExpression"===t.argument.type){const r=ue(e,t.argument.object);let o;if(!0===t.argument.computed)o=ue(e,t.argument.property);else{if("Identifier"!==t.argument.property.type)throw new u(e,"Unrecognized",t);o=t.argument.property.name}if($(r)){if(!J(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new u(e,"OutOfBounds",t);n=M(r[o]),r[o]="++"===t.operator?n+1:n-1}else if(r instanceof c){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else if(E(r)){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else{if(j(r))throw new u(e,"Immutable",t);if(!(r instanceof le))throw new u(e,"InvalidParameter",t);if(!1===H(o))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);n=M(r.global(o)),r.setGlobal(o,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}const r=ne(e,t.argument);n=M(te(r.var).value);const o="++"===t.operator?n+1:n-1;return r.scope[r.id]={value:o},!1===t.prefix?n:"++"===t.operator?n+1:n-1}function ye(e,t,n,r,o){switch(t){case"=":return e===F?null:e;case"/=":return M(n)/M(e);case"*=":return M(n)*M(e);case"-=":return M(n)-M(e);case"+=":return H(n)||H(e)?N(n)+N(e):M(n)+M(e);case"%=":return M(n)%M(e);default:throw new u(o,"UnsupportedOperator",r)}}function ve(e,t){if("MemberExpression"===t.left.type){const n=ue(e,t.left.object);let r;if(!0===t.left.computed)r=ue(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new u(e,"InvalidIdentifier",t);r=t.left.property.name}const o=ue(e,t.right);if($(n)){if(!J(r))throw new u(e,"ArrayAccessMustBeNumber",t);if(r<0&&(r=n.length+r),r<0||r>n.length)throw new u(e,"OutOfBounds",t);if(r===n.length){if("="!==t.operator)throw new u(e,"OutOfBounds",t);n[r]=ye(o,t.operator,n[r],t,e)}else n[r]=ye(o,t.operator,n[r],t,e)}else if(n instanceof c){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else if(E(n)){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else{if(j(n))throw new u(e,"Immutable",t);if(!(n instanceof le))throw new u(e,"InvalidIdentifier",t);if(!1===H(r))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==n.hasGlobal(r))throw new u(e,"ModuleExportNotFound",t);n.setGlobal(r,ye(o,t.operator,n.global(r),t,e))}return F}const n=ne(e,t.left),r=ue(e,t.right);return n.scope[n.id]={value:ye(r,t.operator,"="!==t.operator?te(n.var).value:null,t,e)},F}function xe(e,t){const n=ue(e,t.expression);return n===F?F:new b(n)}function Se(e,t){const n=ue(e,t.test);if(!0===n)return fe(e,t.consequent);if(!1===n)return null!==t.alternate?fe(e,t.alternate):F;throw new u(e,"BooleanConditionRequired",t)}function Fe(e,t){let n=F;for(let r=0;r<t.body.length;r++)if(n=fe(e,t.body[r]),n instanceof g||n===x||n===S)return n;return n}function Re(e,t){if(null===t.argument)return new g(F);const n=ue(e,t.argument);return new g(n)}function Ie(t,n){if(null!=t.localScope)throw Q().error("Function declarations are only valid in global scope."),new u(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw Q().error(`Function "${r}" not declared.`),new u(t,"NeverReach",n);const o=i(n),s=n.params.map(t=>e(t)),l=Array.from(o).filter(e=>!s.includes(e));return t.globalScope[r]={value:new ie(n,t,s,l)},F}function je(e,t){const n=ne(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw Q().error("Internal error: module loader not initialized"),new u(e,"NeverReach",t);const o=r.loadLibrary(n.id);let i;return r._moduleSingletons?.has(o.uri)?i=r._moduleSingletons.get(o.uri):(i=le.load(e,o.syntax),r._moduleSingletons?.set(o.uri,i)),n.scope[n.id]={value:i},F}function Oe(e,t){return fe(e,t.declaration),F}function Ae(e,t){for(let n=0;n<t.declarations.length;n++)Me(e,t.declarations[n]);return F}function Me(e,t){let n=null===t.init?null:ue(e,t.init);if(n===F&&(n=null),"Identifier"!==t.id.type)throw new u(e,"InvalidIdentifier",t);const r=ne(e,t.id);r.scope[r.id]={value:n}}function Ne(e,t){try{const n=ue(e,t.object);if(null===n)throw new u(e,"MemberOfNull",t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof c||O(n))return n.field(t.property.name);if(n instanceof P)return a(n,t.property.name,e,t);if(n instanceof le){if(!n.hasGlobal(t.property.name))throw new u(e,"InvalidIdentifier",t);return n.global(t.property.name)}}throw new u(e,"InvalidMemberAccessKey",t)}let r=ue(e,t.property);if(n instanceof c||O(n)){if(H(r))return n.field(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof le){if(H(r))return n.global(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof P){if(H(r))return a(n,r,e,t);throw new u(e,"InvalidMemberAccessKey",t)}if($(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(H(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(j(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new u(e,"OutOfBounds",t);return n.get(r)}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}catch(n){throw n}}function ke(e,t){try{const n=ue(e,t.argument);if(Y(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);if("~"===t.operator)return~M(n);throw new u(e,"UnsupportUnaryOperator",t)}if("~"===t.operator)return~M(n);if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);throw new u(e,"UnsupportUnaryOperator",t)}catch(n){throw n}}function Ce(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=ue(e,t.elements[r]);if(v(o))throw new u(e,"NoFunctionInArray",t);o===F?n.push(null):n.push(o)}return n}catch(n){throw n}}function Ee(e,t){try{const n=ue(e,t.left),r=ue(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return C(M(n),M(r),t.operator);case"==":return I(n,r);case"!=":return!I(n,r);case"<":case">":case"<=":case">=":return k(n,r,t.operator);case"+":return H(n)||H(r)?N(n)+N(r):M(n)+M(r);case"-":return M(n)-M(r);case"*":return M(n)*M(r);case"/":return M(n)/M(r);case"%":return M(n)%M(r);default:throw new u(e,"UnsupportedOperator",t)}}catch(n){throw n}}function Be(e,t){try{const n=ue(e,t.left);if(Y(n))switch(t.operator){case"||":{if(!0===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}default:throw new u(e,"LogicExpressionOrAnd",t)}throw new u(e,"LogicalExpressionOnlyBoolean",t)}catch(n){throw n}}function Ge(e,t,n){if(v(e))throw new u(t,"NoFunctionInTemplateLiteral",n);return e}function Ue(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){n+=t.expressions[r]?N(Ge(ue(e,t.expressions[r]),e,t)):"",r++}return n}function De(e,t){return re(e,t)}function Ke(e,t){try{if("MemberExpression"===t.callee.type){const n=ue(e,t.callee.object);if(!(n instanceof le))throw new u(e,"FunctionNotFound",t);const r=!1===t.callee.computed?t.callee.property.name:ue(e,t.callee.property);if(!n.hasGlobal(r))throw new u(e,"FunctionNotFound",t);const o=n.global(r);if(!v(o))throw new u(e,"CallNonFunction",t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new u(e,"FunctionNotFound",t);const n=re(e,t.callee,"FunctionNotFound");if(v(n))return n.call(e,t);throw new u(e,"CallNonFunction",t)}catch(n){throw n}}function Le(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,3,3,e,t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",t);return ue(e,!0===r?n[1]:n[2])}catch(n){throw n}}function _e(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,2,3,e,t);const r=ue(e,n[0]);if(3===n.length){const t=ue(e,n[1]),o=s(r,t);return null!=o&&""!==o?o:ue(e,n[2])}return null===r||""===r||void 0===r?ue(e,n[1]):r}catch(n){throw n}}function ze(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<2)throw new u(e,"WrongNumberOfParameters",t);if(2===n.length)return ue(e,n[1]);{if((n.length-1)%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);return Ze(e,t,1,r)}}catch(n){throw n}}function Ze(e,t,n,r){try{const o=t.arguments,i=ue(e,o[n]);if(I(i,r))return ue(e,o[n+1]);{const i=o.length-n;return 1===i?ue(e,o[n]):2===i?null:3===i?ue(e,o[n+2]):Ze(e,t,n+2,r)}}catch(o){throw o}}function qe(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<3)throw new u(e,"WrongNumberOfParameters",t);if(n.length%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",n[0]);return We(e,t,0,r)}catch(n){throw n}}function We(e,t,n,r){try{const o=t.arguments;if(!0===r)return ue(e,o[n+1]);if(3===o.length-n)return ue(e,o[n+2]);{const r=ue(e,o[n+2]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",o[n+2]);return We(e,t,n+2,r)}}catch(o){throw o}}function Pe(){const e=Object.create(null);U(e,ce),Z(e,ce),D(e,ce,De),_(e,ce),K(e,ce),z(e,ce),L(e,ce),q(e,ce),e.iif=Le,e.defaultvalue=_e,e.decode=ze,e.when=qe;const t=function(){this.textformatting={value:c.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new h(r)});return t}const Ve=Pe();function Te(e){const t={mode:"sync",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ce,evaluateIdentifier:De};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Ve.prototype[n]=Object.freeze({value:new h(r)});for(let n=0;n<t.signatures.length;n++)B(t.signatures[n],"sync")}function Ye(e){console.log(e)}function $e(n,i){const s=new Set(Object.keys(i?.vars||{}).map(t=>e(t))),l=new Set(Object.keys(i?.customfunctions||{}).map(t=>e(t))),{globals:a,exports:c}=o(n);return e=>{const o=e.spatialReference??V.WebMercator;let i=null;n.usesModules&&(i=new r(new Map,n.loadedModules));const f=new Ve;for(const t of l)null!=e.customfunctions&&t in e.customfunctions?f[t]={value:new h(e.customfunctions[t])}:f[t]=X;for(const t of s){if(null==e.vars||!(t in e.vars)){t in f||(f[t]=X);continue}const n=e.vars[t]??null;T(n)?f[t]={value:p.createFromGraphic(n,e.timeZone??null)}:f[t]={value:n}}for(const t of a)t in f||(f[t]=X);const d={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:i,exports:c,localScope:null,globalScope:f},w=Fe(d,n);if(w instanceof g||w instanceof b){const e=w.value;if(y(e))return null;if(v(e))throw new u(d,"IllegalResult",null);return e}if(y(w))return null;if(w===x)throw new u(d,"IllegalResult",null);if(w===S)throw new u(d,"IllegalResult",null);throw new u(d,"NeverReach",null)}}function He(e,t){return $e(e,t)(t)}Te([G]);export{He as executeScript,Te as extend,$e as prepareScript};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import t from"../../Feature.js";class e{constructor(t,e){this._lastId=-1,this._progress=e,this._parent=t}reset(){this._lastId=-1}async nextBatchAsArcadeFeatures(e,s){const n=await this.nextBatch(e);return null===n?n:n.map(e=>t.createFromGraphicLikeObject(e.geometry,e.attributes,this._parent,s))}nextBatch(t){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then(e=>this.nextBatch(t),e=>this.nextBatch(t));const e={returnpromise:null,hasset:!1},s=[];return e.returnpromise=new Promise((n,a)=>{this._parent._getSet(this._progress).then(r=>{const i=r._known;let h=i.length-1;if("GETPAGES"===i[i.length-1]&&(h-=1),this._lastId+t>h&&i.length>0&&"GETPAGES"===i[i.length-1])return void this._parent._expandPagedSet(r,this._parent._maxQueryRate(),0,0,this._progress).then(s=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(n,a)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)});const _=r._candidates;if(h>=this._lastId+t||0===_.length){for(let e=0;e<t;e++){const t=e+this._lastId+1;if(t>=i.length)break;s[e]=i[t]}return this._lastId+=s.length,0===s.length&&(e.hasset=!0,this._parent._mainSetInUse=null,n([])),void this._parent._getFeatureBatch(s,this._progress).then(t=>{e.hasset=!0,this._parent._mainSetInUse=null,n(t)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})}this._parent._refineSetBlock(r,this._parent._maxProcessingRate(),this._progress).then(()=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(n,a)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})}),!1===e.hasset&&(this._parent._mainSetInUse=e.returnpromise,e.hasset=!0),e.returnpromise}next(){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then(t=>this.next(),t=>this.next());const t={returnpromise:null,hasset:!1};return t.returnpromise=new Promise((e,s)=>{this._parent._getSet(this._progress).then(n=>{const a=n._known;if(this._lastId<a.length-1)"GETPAGES"===a[this._lastId+1]?this._parent._expandPagedSet(n,this._parent._maxQueryRate(),0,0,this._progress).then(e=>(t.hasset=!0,this._parent._mainSetInUse=null,this.next())).then(e,s):(this._lastId+=1,this._parent._getFeature(n,a[this._lastId],this._progress).then(s=>{t.hasset=!0,this._parent._mainSetInUse=null,e(s)},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)}));else{n._candidates.length>0?this._parent._refineSetBlock(n,this._parent._maxProcessingRate(),this._progress).then(()=>{t.hasset=!0,this._parent._mainSetInUse=null,this.next().then(e,s)},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)}):(t.hasset=!0,this._parent._mainSetInUse=null,e(null))}},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)})}),!1===t.hasset&&(this._parent._mainSetInUse=t.returnpromise,t.hasset=!0),t.returnpromise}async count(){if(-1!==this._parent._totalCount)return this._parent._totalCount;const t=await this._parent._getSet(this._progress),e=await this._refineAllSets(t);return this._parent._totalCount=e._known.length,this._parent._totalCount}async _refineAllSets(t){if(t._known.length>0&&"GETPAGES"===t._known[t._known.length-1])return await this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,1,this._progress),this._refineAllSets(t);if(t._candidates.length>0){if("GETPAGES"===t._known[t._candidates.length-1])return await this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,2,this._progress),this._refineAllSets(t);const e=await this._parent._refineSetBlock(t,this._parent._maxProcessingRate(),this._progress);return e._candidates.length>0?this._refineAllSets(e):e}return t}}export{e as default};
5
+ import{Feature as t}from"../../Feature.js";class e{constructor(t,e){this._lastId=-1,this._progress=e,this._parent=t}reset(){this._lastId=-1}async nextBatchAsArcadeFeatures(e,s){const n=await this.nextBatch(e);return null===n?n:n.map(e=>t.createFromGraphicLikeObject(e.geometry,e.attributes,this._parent,s))}nextBatch(t){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then(e=>this.nextBatch(t),e=>this.nextBatch(t));const e={returnpromise:null,hasset:!1},s=[];return e.returnpromise=new Promise((n,a)=>{this._parent._getSet(this._progress).then(r=>{const i=r._known;let h=i.length-1;if("GETPAGES"===i[i.length-1]&&(h-=1),this._lastId+t>h&&i.length>0&&"GETPAGES"===i[i.length-1])return void this._parent._expandPagedSet(r,this._parent._maxQueryRate(),0,0,this._progress).then(s=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(n,a)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)});const _=r._candidates;if(h>=this._lastId+t||0===_.length){for(let e=0;e<t;e++){const t=e+this._lastId+1;if(t>=i.length)break;s[e]=i[t]}return this._lastId+=s.length,0===s.length&&(e.hasset=!0,this._parent._mainSetInUse=null,n([])),void this._parent._getFeatureBatch(s,this._progress).then(t=>{e.hasset=!0,this._parent._mainSetInUse=null,n(t)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})}this._parent._refineSetBlock(r,this._parent._maxProcessingRate(),this._progress).then(()=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(n,a)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})}),!1===e.hasset&&(this._parent._mainSetInUse=e.returnpromise,e.hasset=!0),e.returnpromise}next(){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then(t=>this.next(),t=>this.next());const t={returnpromise:null,hasset:!1};return t.returnpromise=new Promise((e,s)=>{this._parent._getSet(this._progress).then(n=>{const a=n._known;if(this._lastId<a.length-1)"GETPAGES"===a[this._lastId+1]?this._parent._expandPagedSet(n,this._parent._maxQueryRate(),0,0,this._progress).then(e=>(t.hasset=!0,this._parent._mainSetInUse=null,this.next())).then(e,s):(this._lastId+=1,this._parent._getFeature(n,a[this._lastId],this._progress).then(s=>{t.hasset=!0,this._parent._mainSetInUse=null,e(s)},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)}));else{n._candidates.length>0?this._parent._refineSetBlock(n,this._parent._maxProcessingRate(),this._progress).then(()=>{t.hasset=!0,this._parent._mainSetInUse=null,this.next().then(e,s)},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)}):(t.hasset=!0,this._parent._mainSetInUse=null,e(null))}},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)})}),!1===t.hasset&&(this._parent._mainSetInUse=t.returnpromise,t.hasset=!0),t.returnpromise}async count(){if(-1!==this._parent._totalCount)return this._parent._totalCount;const t=await this._parent._getSet(this._progress),e=await this._refineAllSets(t);return this._parent._totalCount=e._known.length,this._parent._totalCount}async _refineAllSets(t){if(t._known.length>0&&"GETPAGES"===t._known[t._known.length-1])return await this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,1,this._progress),this._refineAllSets(t);if(t._candidates.length>0){if("GETPAGES"===t._known[t._candidates.length-1])return await this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,2,this._progress),this._refineAllSets(t);const e=await this._parent._refineSetBlock(t,this._parent._maxProcessingRate(),this._progress);return e._candidates.length>0?this._refineAllSets(e):e}return t}}export{e as default};