@arcgis/core 4.33.0-next.20250306 → 4.33.0-next.20250308

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 (246) hide show
  1. package/arcade/arcadeAsyncRuntime.js +1 -1
  2. package/arcade/arcadeCompiler.js +1 -1
  3. package/arcade/featureSetUtils.js +1 -1
  4. package/arcade/featureset/actions/GroupBy.js +1 -1
  5. package/arcade/featureset/actions/OrderBy.js +1 -1
  6. package/arcade/functions/aiServices.js +5 -0
  7. package/arcade/functions/date.js +1 -1
  8. package/arcade/functions/feature.js +1 -1
  9. package/arcade/functions/featuresetbase.js +1 -1
  10. package/arcade/functions/featuresetstring.js +1 -1
  11. package/arcade/functions/fieldStats.js +1 -1
  12. package/arcade/functions/geometry.js +1 -1
  13. package/arcade/functions/maths.js +1 -1
  14. package/arcade/functions/string.js +1 -1
  15. package/arcade/languageUtils.js +1 -1
  16. package/arcade/treeAnalysis.js +1 -1
  17. package/arcade.js +1 -1
  18. package/assets/esri/core/workers/RemoteClient.js +1 -1
  19. package/assets/esri/core/workers/chunks/028e2e0fa6971aaaaae8.js +1 -0
  20. package/assets/esri/core/workers/chunks/0576b035c1654a43ad5c.js +1 -0
  21. package/assets/esri/core/workers/chunks/081699532b183db1e7c2.js +1 -0
  22. package/assets/esri/core/workers/chunks/087a09b4c41abef6b516.js +1 -0
  23. package/assets/esri/core/workers/chunks/{7ec2f531217718e76469.js → 0b4e63e705db09dbe171.js} +1 -1
  24. package/assets/esri/core/workers/chunks/0c9e933b392616460e62.js +1 -0
  25. package/assets/esri/core/workers/chunks/{c3d23c45db427a29d596.js → 0f4a2bdf5bb2f4303b7f.js} +1 -1
  26. package/assets/esri/core/workers/chunks/{f995a74bd9b58c069c07.js → 10631680abe7607616ca.js} +1 -1
  27. package/assets/esri/core/workers/chunks/{567aa24d7e99e0b5a6cb.js → 1263391920fbb8926ced.js} +1 -1
  28. package/assets/esri/core/workers/chunks/186387a561364a11e574.js +1 -0
  29. package/assets/esri/core/workers/chunks/1cc7bbd0f4a8cf06050a.js +1 -0
  30. package/assets/esri/core/workers/chunks/1d0473dd43c88ab5776d.js +1 -0
  31. package/assets/esri/core/workers/chunks/{ef46613c3aa363dc1cfc.js → 285e573aa6f3acf70b32.js} +1 -1
  32. package/assets/esri/core/workers/chunks/2bb508701ad8ccc3d6ab.js +1 -0
  33. package/assets/esri/core/workers/chunks/36fe6b8228e622407ec2.js +1 -0
  34. package/assets/esri/core/workers/chunks/37a3533f004bf2e888da.js +1 -0
  35. package/assets/esri/core/workers/chunks/3be465c653236d6d8c1f.js +1 -0
  36. package/assets/esri/core/workers/chunks/3e4204502f6e09483c60.js +1 -0
  37. package/assets/esri/core/workers/chunks/3e9cd82325c473ddbf1f.js +1 -0
  38. package/assets/esri/core/workers/chunks/{1e7a70a1871fea29169e.js → 400951e3e742452a5fe2.js} +16 -16
  39. package/assets/esri/core/workers/chunks/{370ab4b33fb7292bb3b8.js → 424e2058228e5f6a183d.js} +1 -1
  40. package/assets/esri/core/workers/chunks/4496ef270c700078df0c.js +1 -0
  41. package/assets/esri/core/workers/chunks/458f4c6c8820c1f62f69.js +1 -0
  42. package/assets/esri/core/workers/chunks/49c346d2fb8538990f45.js +1 -0
  43. package/assets/esri/core/workers/chunks/4bb65ef7b3a02ebe416e.js +1 -0
  44. package/assets/esri/core/workers/chunks/4c765464288b6d096d08.js +1 -0
  45. package/assets/esri/core/workers/chunks/4eb1a2433f675bde12ad.js +1 -0
  46. package/assets/esri/core/workers/chunks/4ffdff269aae8c293cb4.js +1 -0
  47. package/assets/esri/core/workers/chunks/55f7b1de8882569861c0.js +1 -0
  48. package/assets/esri/core/workers/chunks/564cc81c232c97646833.js +1 -0
  49. package/assets/esri/core/workers/chunks/5a6f7360183693f8490d.js +1 -0
  50. package/assets/esri/core/workers/chunks/5f8028928ae8e5d27dda.js +1 -0
  51. package/assets/esri/core/workers/chunks/{c03e6e35082beaec02a6.js → 5fa5bfc70512994f5ec1.js} +1 -1
  52. package/assets/esri/core/workers/chunks/605eddec7aac891ed141.js +1 -0
  53. package/assets/esri/core/workers/chunks/66cba22c09f595bba3bf.js +1 -0
  54. package/assets/esri/core/workers/chunks/6cb5ce0a6bb85c624a21.js +1 -0
  55. package/assets/esri/core/workers/chunks/{bf9b45604249520b596a.js → 74c01de62ccaed0666e0.js} +1 -1
  56. package/assets/esri/core/workers/chunks/7a4413a188a8f1affb2f.js +1 -0
  57. package/assets/esri/core/workers/chunks/{b66e8a48ce7098ca43d5.js → 7c3cd6aefd16fcc1a7fd.js} +1 -1
  58. package/assets/esri/core/workers/chunks/7e0e9ca84490a0c67197.js +1 -0
  59. package/assets/esri/core/workers/chunks/{3315de71eb8791189c05.js → 835fa4484c58d9b31c78.js} +1 -1
  60. package/assets/esri/core/workers/chunks/88a7780b1c689afff8bd.js +1 -0
  61. package/assets/esri/core/workers/chunks/8d636075e5aa053940fc.js +1 -0
  62. package/assets/esri/core/workers/chunks/{7ca33e03a2fd217b9443.js → 9dfdd8e91897d166d888.js} +1 -1
  63. package/assets/esri/core/workers/chunks/{790f86ddf57be50e0dd5.js → 9ef509e0853ad41f7690.js} +1 -1
  64. package/assets/esri/core/workers/chunks/a2377969f76640f1d6fe.js +1 -0
  65. package/assets/esri/core/workers/chunks/aa3a45e8228216c1739b.js +1 -0
  66. package/assets/esri/core/workers/chunks/b2289c18c02c868a2939.js +1 -0
  67. package/assets/esri/core/workers/chunks/b5f44cf03c4e5cc07bc4.js +1 -0
  68. package/assets/esri/core/workers/chunks/b948fe33b4d650eea796.js +1 -0
  69. package/assets/esri/core/workers/chunks/bdeac9196f28aff93e68.js +1 -0
  70. package/assets/esri/core/workers/chunks/c591527543fd75a917d4.js +1 -0
  71. package/assets/esri/core/workers/chunks/{ca4af35af02e3804042e.js → c6580fdcdc33153008b0.js} +1 -1
  72. package/assets/esri/core/workers/chunks/{fe8ee1938d196a70d809.js → ca0572fe5614005acceb.js} +1 -1
  73. package/assets/esri/core/workers/chunks/{67c1e2c17ea3ca27248c.js → cbbbaccc0d3683e1c0fe.js} +1 -1
  74. package/assets/esri/core/workers/chunks/ccc6f6f7052985bebdab.js +1 -0
  75. package/assets/esri/core/workers/chunks/d72d993b36daf6ec2a10.js +1 -0
  76. package/assets/esri/core/workers/chunks/eb9d2bb8b44a93347274.js +1 -0
  77. package/assets/esri/core/workers/chunks/f809cbfb744adb4fad29.js +1 -0
  78. package/assets/esri/core/workers/chunks/fa011ad649c05201e92a.js +1 -0
  79. package/assets/esri/core/workers/chunks/fa7ddf3c89cdb8052b26.js +1 -0
  80. package/assets/esri/core/workers/chunks/fdc9bd8f309af610fa62.js +1 -0
  81. package/assets/esri/themes/base/widgets/_ElevationProfile.scss +2 -2
  82. package/assets/esri/themes/dark/main.css +1 -1
  83. package/assets/esri/themes/light/main.css +1 -1
  84. package/assets/esri/themes/light/view.css +1 -1
  85. package/chunks/LineMarker.glsl.js +2 -2
  86. package/chunks/aiServices.js +5 -0
  87. package/chunks/array.js +1 -1
  88. package/chunks/languageUtils.js +1 -1
  89. package/copyright.txt +38 -0
  90. package/core/MapUtils.js +1 -1
  91. package/editing/sharedTemplates/executor/createTemplateExecutor.js +1 -1
  92. package/interfaces.d.ts +11 -3
  93. package/layers/graphics/controllers/FeatureTileController3D.js +1 -1
  94. package/layers/graphics/data/AttributesBuilder.js +1 -1
  95. package/layers/graphics/data/QueryEngineResult.js +1 -1
  96. package/layers/graphics/data/queryValidationUtils.js +1 -1
  97. package/layers/graphics/editingSupport.js +1 -1
  98. package/layers/support/TitleCreator.js +1 -1
  99. package/layers/support/fieldUtils.js +1 -1
  100. package/layers/support/labelFormatUtils.js +1 -1
  101. package/package.json +1 -1
  102. package/renderers/ClassBreaksRenderer.js +1 -1
  103. package/renderers/DictionaryRenderer.js +1 -1
  104. package/renderers/UniqueValueRenderer.js +1 -1
  105. package/renderers/support/DictionaryControlString.js +5 -0
  106. package/renderers/support/DictionaryLoader.js +1 -1
  107. package/renderers/support/DictionaryScriptEvaluator.js +5 -0
  108. package/rest/featureService/FeatureService.js +1 -1
  109. package/rest/print.js +1 -1
  110. package/rest/support/TranslateContent.js +5 -0
  111. package/rest/support/TranslateParameters.js +5 -0
  112. package/rest/support/TranslateResult.js +5 -0
  113. package/rest/translate.js +5 -0
  114. package/rest/utils.js +1 -1
  115. package/smartMapping/statistics/support/attributeDensity.js +1 -1
  116. package/smartMapping/statistics/support/utils.js +1 -1
  117. package/smartMapping/support/adapters/InMemoryLayerAdapter.js +1 -1
  118. package/smartMapping/support/utils.js +1 -1
  119. package/support/ArcadeExpression.js +5 -0
  120. package/support/loadArcade.js +5 -0
  121. package/support/revision.js +1 -1
  122. package/symbols/cim/OverrideHelper.js +1 -1
  123. package/symbols/cim/cimAnalyzer.js +1 -1
  124. package/symbols/cim/utils.js +1 -1
  125. package/symbols/support/symbolUtils.js +1 -1
  126. package/views/2d/arcade/callExpressionWithCursor.js +1 -1
  127. package/views/2d/arcade/callExpressionWithFeature.js +1 -1
  128. package/views/2d/engine/webgl/mesh/factories/ResourceProxy.js +1 -1
  129. package/views/2d/engine/webgl/shaderGraph/techniques/GraphicInstanceStore.js +1 -1
  130. package/views/2d/engine/webgl/shaderGraph/techniques/createGraphicSymbolMeshSchemas.js +1 -1
  131. package/views/2d/engine/webgl/shaderGraph/techniques/mesh/MeshWriterInputEvaluator.js +1 -1
  132. package/views/2d/engine/webgl/shaderGraph/techniques/mesh/MeshWriterRegistry.js +1 -1
  133. package/views/2d/engine/webgl/util/DictionaryMatcher.js +1 -1
  134. package/views/2d/engine/webgl/util/MatcherContext.js +1 -1
  135. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  136. package/views/2d/layers/MediaLayerView2D.js +1 -1
  137. package/views/2d/layers/TileLayerView2D.js +1 -1
  138. package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
  139. package/views/2d/layers/features/Processor.js +1 -1
  140. package/views/2d/layers/features/processor/AAggregateStrategy.js +1 -1
  141. package/views/2d/layers/features/processor/AProcessorStrategy.js +1 -1
  142. package/views/2d/layers/features/processor/TrackStrategy.js +1 -1
  143. package/views/2d/layers/features/schema/processor/MatcherSchema.js +1 -1
  144. package/views/2d/layers/features/schema/processor/symbols/ComplexSymbolSchema.js +1 -1
  145. package/views/2d/layers/features/schema/processor/symbols/SymbolSchema.js +1 -1
  146. package/views/2d/layers/features/sources/FeatureSource.js +1 -1
  147. package/views/2d/layers/features/sources/strategies/StreamLoadStrategy.js +1 -1
  148. package/views/2d/layers/features/support/AttributeStore.js +1 -1
  149. package/views/2d/layers/features/support/ComputedAttributeStorage.js +1 -1
  150. package/views/2d/layers/features/support/ComputedExpression.js +1 -1
  151. package/views/2d/layers/features/support/DictionaryTemplate.js +5 -0
  152. package/views/2d/layers/graphics/GraphicsView2D.js +1 -1
  153. package/views/3d/environment/EnvironmentManager.js +1 -1
  154. package/views/3d/environment/Precipitation.js +1 -1
  155. package/views/3d/layers/DynamicLayerView3D.js +1 -1
  156. package/views/3d/layers/FeatureLikeLayerView3D.js +1 -1
  157. package/views/3d/layers/GraphicsLayerView3D.js +1 -1
  158. package/views/3d/layers/I3SMeshView3D.js +1 -1
  159. package/views/3d/layers/RouteLayerView3D.js +1 -1
  160. package/views/3d/layers/SceneLayerView3D.js +1 -1
  161. package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
  162. package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
  163. package/views/3d/layers/graphics/Graphics3DPathSymbolLayer.js +1 -1
  164. package/views/3d/layers/graphics/featureExpressionInfoUtils.js +1 -1
  165. package/views/3d/layers/graphics/queryForSymbologySnapping.js +1 -1
  166. package/views/3d/layers/i3s/I3SIndex.js +1 -1
  167. package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
  168. package/views/3d/webgl-engine/core/shaderLibrary/shading/PhysicallyBasedRenderingParameters.glsl.js +7 -7
  169. package/views/3d/webgl-engine/lib/GLTextureMaterial.js +1 -1
  170. package/views/3d/webgl-engine/lib/PathBuilder.js +1 -1
  171. package/views/3d/webgl-engine/lib/PathGeometryData.js +1 -1
  172. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  173. package/views/3d/webgl-engine/materials/PathMaterial.js +1 -1
  174. package/views/3d/webgl-engine/materials/PathTechnique.js +1 -1
  175. package/views/VideoView.js +1 -1
  176. package/views/layers/FeatureLayerView.js +1 -1
  177. package/views/layers/support/MapServiceLayerViewHelper.js +1 -1
  178. package/views/overlay/CrosshairOverlayItem.js +1 -1
  179. package/views/support/projectionUtils.js +1 -1
  180. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  181. package/widgets/Editor/CreateFeaturesWorkflowData.js +1 -1
  182. package/widgets/Editor/EditorViewModel.js +1 -1
  183. package/widgets/Editor/Edits.js +1 -1
  184. package/widgets/Editor/UpdateWorkflow.js +1 -1
  185. package/widgets/Editor/components/PendingFeatureList.js +1 -1
  186. package/widgets/Editor/components/UpdateFeaturePanelContent.js +1 -1
  187. package/widgets/Editor/support/dependencySort.js +5 -0
  188. package/widgets/Editor/workflowUtils.js +1 -1
  189. package/widgets/Feature/FeatureRelationship/FeatureRelationshipViewModel.js +1 -1
  190. package/widgets/Feature/FeatureRelationship.js +1 -1
  191. package/widgets/Feature/support/featureUtils.js +1 -1
  192. package/widgets/FeatureForm/FeatureFormViewModel.js +1 -1
  193. package/widgets/FeatureForm/RelationshipInput.js +1 -1
  194. package/widgets/FeatureForm.js +1 -1
  195. package/widgets/FeatureTemplates/FeatureTemplatesViewModel.js +1 -1
  196. package/widgets/OrientedImageryViewer/adapters/sketch/MeasurementAdapter.js +1 -1
  197. package/widgets/Popup.js +1 -1
  198. package/widgets/Print.js +1 -1
  199. package/widgets/Sketch.js +1 -1
  200. package/widgets/support/LabeledSwitch.js +1 -1
  201. package/assets/esri/core/workers/chunks/0121702bc9a1f3a85f1f.js +0 -1
  202. package/assets/esri/core/workers/chunks/05b7c739115be0490583.js +0 -1
  203. package/assets/esri/core/workers/chunks/0ce1bfcdcccb679569f8.js +0 -1
  204. package/assets/esri/core/workers/chunks/1007c1a908b6e503e0db.js +0 -1
  205. package/assets/esri/core/workers/chunks/1439f1d84e21e6295e3f.js +0 -1
  206. package/assets/esri/core/workers/chunks/1912d25f8007685c7aee.js +0 -1
  207. package/assets/esri/core/workers/chunks/1bd58eaac6f4906bbdae.js +0 -1
  208. package/assets/esri/core/workers/chunks/2c091edee3601f345f5f.js +0 -1
  209. package/assets/esri/core/workers/chunks/2e40f2527345ad85d800.js +0 -1
  210. package/assets/esri/core/workers/chunks/30f271bbc34f66cbfc23.js +0 -1
  211. package/assets/esri/core/workers/chunks/36b406131cd864567033.js +0 -1
  212. package/assets/esri/core/workers/chunks/4395b7263a299a8020d4.js +0 -1
  213. package/assets/esri/core/workers/chunks/4c15de6b2b8eefd76b61.js +0 -1
  214. package/assets/esri/core/workers/chunks/4c596cb20baaae5166de.js +0 -1
  215. package/assets/esri/core/workers/chunks/4d16b1e50caad0da7838.js +0 -1
  216. package/assets/esri/core/workers/chunks/5802406d0a239a27a9a3.js +0 -1
  217. package/assets/esri/core/workers/chunks/5c86df2a5e16877ba614.js +0 -1
  218. package/assets/esri/core/workers/chunks/62c9171a58160ea099f8.js +0 -1
  219. package/assets/esri/core/workers/chunks/6a4731b47629604a9ca0.js +0 -1
  220. package/assets/esri/core/workers/chunks/7975ada96e4540a37c83.js +0 -1
  221. package/assets/esri/core/workers/chunks/81c507c0d901448835f4.js +0 -1
  222. package/assets/esri/core/workers/chunks/8278d9263e9b7e3bf2d1.js +0 -1
  223. package/assets/esri/core/workers/chunks/8926f672397620591740.js +0 -1
  224. package/assets/esri/core/workers/chunks/8bf623f560b1ed440004.js +0 -1
  225. package/assets/esri/core/workers/chunks/924176d9ab2e070248a8.js +0 -1
  226. package/assets/esri/core/workers/chunks/988efc508c33ca341e49.js +0 -1
  227. package/assets/esri/core/workers/chunks/98cbfc72430a378a9451.js +0 -1
  228. package/assets/esri/core/workers/chunks/9fde9309cb64f1a9301c.js +0 -1
  229. package/assets/esri/core/workers/chunks/a901c445d36f1a9e7df8.js +0 -1
  230. package/assets/esri/core/workers/chunks/ab525991f71240d68471.js +0 -1
  231. package/assets/esri/core/workers/chunks/af27a3f646a4404d3b8d.js +0 -1
  232. package/assets/esri/core/workers/chunks/c15c3fec95f365580902.js +0 -1
  233. package/assets/esri/core/workers/chunks/c1e343cdf85da40ac10e.js +0 -1
  234. package/assets/esri/core/workers/chunks/c3806be4a760735e6082.js +0 -1
  235. package/assets/esri/core/workers/chunks/c3dc8d1958ddc71e1129.js +0 -1
  236. package/assets/esri/core/workers/chunks/c7b0f58550e63ce6ad5b.js +0 -1
  237. package/assets/esri/core/workers/chunks/ccf8a423eee7ef4ffe4c.js +0 -1
  238. package/assets/esri/core/workers/chunks/d24321b1eeabe9ec553c.js +0 -1
  239. package/assets/esri/core/workers/chunks/dd913cb7cf3bb172b34c.js +0 -1
  240. package/assets/esri/core/workers/chunks/e3e049311bced533c853.js +0 -1
  241. package/assets/esri/core/workers/chunks/e3e5a215dcd531b1196f.js +0 -1
  242. package/assets/esri/core/workers/chunks/e8a19f9144df8f155e30.js +0 -1
  243. package/assets/esri/core/workers/chunks/f31986ea5cadfade8344.js +0 -1
  244. package/assets/esri/core/workers/chunks/f350aefc5e348ebad1da.js +0 -1
  245. package/support/arcadeOnDemand.js +0 -5
  246. package/views/3d/layers/support/projectExtentUtils.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/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{getNestedOptionalValue as o,geometryMember as a,getGeometryKeys as i}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as s,ExecutionErrorCodes as c,ensureArcadeExecutionError as u}from"./executionError.js";import f from"./Feature.js";import{NativeFunction as p,ScopeMarshalledFunction as w,ArcadeFunction as d,wrapModuleScopedResponse as h}from"./FunctionWrapper.js";import{D as m,B as g,i as y,w as b,t as v,n as S,m as x,z as F,f as I,A as M,C as k,R,I as A,E as C,x as O,y as N,u as E,p as j,l as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as D}from"./treeAnalysis.js";import{A as K}from"../chunks/array.js";import{registerFunctions as U}from"./functions/date.js";import{registerFunctions as Z}from"./functions/feature.js";import{registerFunctions as G}from"./functions/geomasync.js";import{registerFunctions as L}from"./functions/geometry.js";import{registerFunctions as q}from"./functions/maths.js";import{registerFunctions as P}from"./functions/stats.js";import{registerFunctions as W}from"./functions/string.js";import V from"../geometry/Geometry.js";import T from"../geometry/SpatialReference.js";import{isBoolean as _,isString as z,isArray as Y,isNumber as H,isGraphic as J}from"../support/guards.js";async function Q(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await ne(e,t.arguments[r]));return n}async function X(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await Q(e,t))}class $ extends d{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,services:this.context.services,abortSignal:this.context.abortSignal,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new s(e,c.MaximumCallDepth,null);return Ze(this.definition,n,t,null)}}call(e,t){return te(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:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(a.depthCounter.depth>64)throw new s(e,c.MaximumCallDepth,t);return Ze(this.definition,a,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={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:{}};return i=i.map((t=>!y(t)||t instanceof w?t:h(t,e,r))),h(await Ze(this.definition,l,i,t),n,r)}))}}class ee extends n{constructor(e){super(),this.source=e}global(t){const n=this.executingContext.globalScope[e(t)];if(y(n.value)&&!(n.value instanceof w)){const e=new w;e.fn=n.value,e.parameterEvaluator=te,e.context=this.executingContext,n.value=e}return n.value}setGlobal(t,n){if(y(n))throw new s(null,c.AssignModuleFunction,null);this.executingContext.globalScope[e(t)]={value:n}}hasGlobal(t){return void 0===this.executingContext.exports[t]&&(t=e(t)),void 0!==this.executingContext.exports[t]}async loadModule(e){const n=e.spatialReference??T.WebMercator;this.moduleScope=qe(null,null,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new r(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:e.abortSignal??t,globalScope:this.moduleScope,console:e.console??Pe,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await be(this.executingContext,this.source.syntax)}}async function te(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await Q(e,t))}async function ne(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await de(e,t);case"AssignmentExpression":return await me(e,t);case"TemplateLiteral":return await Be(e,t);case"Identifier":return Ee(e,t);case"MemberExpression":return await Re(e,t);case"Literal":return t.value;case"CallExpression":return await je(e,t);case"UnaryExpression":return await Ae(e,t);case"BinaryExpression":return await Oe(e,t);case"LogicalExpression":return await Ne(e,t);case"ArrayExpression":return await Ce(e,t);case"ObjectExpression":return await oe(e,t);default:throw new s(e,c.Unrecognized,t)}}catch(n){throw u(e,t,n)}}async function re(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await Fe(e,t);case"ExportNamedDeclaration":return await Ie(e,t);case"VariableDeclaration":return await Me(e,t,0);case"BlockStatement":return await be(e,t);case"FunctionDeclaration":return await xe(e,t);case"ReturnStatement":return await Se(e,t);case"IfStatement":return await ye(e,t);case"ExpressionStatement":return await ge(e,t);case"ForStatement":return await ie(e,t);case"WhileStatement":return await ae(e,t);case"ForInStatement":return await pe(e,t);case"ForOfStatement":return await we(e,t);case"BreakStatement":return O;case"EmptyStatement":return b;case"ContinueStatement":return N;default:throw new s(e,c.Unrecognized,t)}}catch(n){throw u(e,t,n)}}async function oe(e,t){const n=[];for(let i=0;i<t.properties.length;i++){const r=t.properties[i],o=await ne(e,r.value),a="Identifier"===r.key.type?r.key.name:await ne(e,r.key);n[i]={key:a,value:o}}const r={},o=new Map;for(let i=0;i<n.length;i++){const a=n[i];if(y(a.value))throw new s(e,c.NoFunctionInDictionary,t);if(!1===z(a.key))throw new s(e,c.KeyMustBeString,t);let l=a.key.toString();const u=l.toLowerCase();o.has(u)?l=o.get(u):o.set(u,l),a.value===b?r[l]=null:r[l]=a.value}const a=new l(r);return a.immutable=!1,a}async function ae(e,t){let n=await ne(e,t.test);if(!1===n)return b;if(!0!==n)throw new s(e,c.BooleanConditionRequired,t);for(;!0===n;){const r=await re(e,t.body);if(r===O)break;if(r instanceof R)return r;if(n=await ne(e,t.test),!0!==n&&!1!==n)throw new s(e,c.BooleanConditionRequired,t)}return b}async function ie(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await re(e,t.init):await ne(e,t.init));;){if(null!==t.test){const n=await ne(e,t.test);if(!0===e.abortSignal?.aborted)throw new s(e,c.Cancelled,t);if(!1===n)break;if(!0!==n)throw new s(e,c.BooleanConditionRequired,t)}const n=await re(e,t.body);if(n===O)break;if(n instanceof R)return n;null!==t.update&&await ne(e,t.update)}return b}catch(n){throw n}}async function le(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 s(e,c.OutOfBounds,t);r.value=n[i]}else r.value=i;const a=await re(e,t.body);if(a===O)break;if(a instanceof R)return a}return b}async function se(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.value="k"===o?n.get(i):i;const a=await re(e,t.body);if(a===O)break;if(a instanceof R)return a}return b}async function ce(e,t,n,r){const o=n.iterator(e.abortSignal);let a;for(;null!=(a=await o.next());){const o=f.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone);o._underlyingGraphic=a,r.value=o;const i=await re(e,t.body);if(i===O)break;if(i instanceof R)return i}return b}async function ue(e,t,n,r){for(const o of n.keys()){const a=n.field(o);r.value=new l({key:o,value:a});const i=await re(e,t.body);if(i===O)break;if(i instanceof R)return i}return b}async function fe(e,t,n,r){for(const o of i(n)){const i=a(n,o,e,t,1);r.value=new l({key:o,value:i});const s=await re(e,t.body);if(s===O)break;if(s instanceof R)return s}return b}async function pe(t,n){const r=await ne(t,n.right);"VariableDeclaration"===n.left.type&&await re(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let a=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(a=t.localScope[o]),null===a&&void 0!==t.globalScope[o]&&(a=t.globalScope[o]),null===a)throw new s(t,c.InvalidIdentifier,n);return Y(r)||z(r)?await le(t,n,r,a):x(r)?await se(t,n,r,a):r instanceof l||F(r)?await le(t,n,r.keys(),a,"k"):j(r)?await ce(t,n,r,a):B(r)?await le(t,n,i(r),a,"k"):b}async function we(t,n){const r=await ne(t,n.right);"VariableDeclaration"===n.left.type&&await re(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let a=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(a=t.localScope[o]),null===a&&void 0!==t.globalScope[o]&&(a=t.globalScope[o]),null===a)throw new s(t,c.InvalidIdentifier,n);return Y(r)||z(r)?await le(t,n,r,a,"k"):x(r)?await se(t,n,r,a,"k"):r instanceof l||F(r)?await ue(t,n,r,a):j(r)?await ce(t,n,r,a):B(r)?await fe(t,n,r,a):b}async function de(t,n){const r=n.argument;if("CallExpression"===r.type)throw new s(t,c.NeverReach,n);if("MemberExpression"===r.type){const e=await ne(t,r.object);let o,a;if(!0===r.computed)o=await ne(t,r.property);else{if("Identifier"!==r.property.type)throw new s(t,c.Unrecognized,n);o=r.property.name}if(Y(e)){if(!H(o))throw new s(t,c.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>=e.length)throw new s(t,c.OutOfBounds,n);a=v(e[o]),e[o]="++"===n.operator?a+1:a-1}else if(e instanceof l){if(!1===z(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new s(t,c.FieldNotFound,n,{key:o});a=v(e.field(o)),e.setField(o,"++"===n.operator?a+1:a-1)}else if(e instanceof ee){if(!1===z(o))throw new s(t,c.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new s(t,c.ModuleExportNotFound,n);a=v(e.global(o)),e.setGlobal(o,"++"===n.operator?a+1:a-1)}else{if(!S(e))throw x(e)?new s(t,c.Immutable,n):new s(t,c.InvalidParameter,n);if(!1===z(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new s(t,c.FieldNotFound,n,{key:o});a=v(e.field(o)),e.setField(o,"++"===n.operator?a+1:a-1)}return!1===n.prefix?a:"++"===n.operator?a+1:a-1}const o=e(r);let a;if(null!=t.localScope&&void 0!==t.localScope[o])return a=v(t.localScope[o].value),t.localScope[o]={value:"++"===n.operator?a+1:a-1},!1===n.prefix?a:"++"===n.operator?a+1:a-1;if(void 0!==t.globalScope[o])return a=v(t.globalScope[o].value),t.globalScope[o]={value:"++"===n.operator?a+1:a-1},!1===n.prefix?a:"++"===n.operator?a+1:a-1;throw new s(t,c.InvalidIdentifier,n)}function he(e,t,n,r,o){switch(t){case"=":return e===b?null:e;case"/=":return v(n)/v(e);case"*=":return v(n)*v(e);case"-=":return v(n)-v(e);case"+=":return z(n)||z(e)?I(n)+I(e):v(n)+v(e);case"%=":return v(n)%v(e);default:throw new s(o,c.UnsupportedOperator,r)}}async function me(t,n){const r=n.left;if("MemberExpression"===r.type){const e=await ne(t,r.object);let o;if(!0===r.computed)o=await ne(t,r.property);else{if("Identifier"!==r.property.type)throw new s(t,c.InvalidIdentifier,n);o=r.property.name}const a=await ne(t,n.right);if(Y(e)){if(!H(o))throw new s(t,c.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>e.length)throw new s(t,c.OutOfBounds,n);if(o===e.length){if("="!==n.operator)throw new s(t,c.OutOfBounds,n);e[o]=he(a,n.operator,e[o],n,t)}else e[o]=he(a,n.operator,e[o],n,t)}else if(e instanceof l){if(!1===z(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,he(a,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new s(t,c.FieldNotFound,n,{key:o});e.setField(o,he(a,n.operator,null,n,t))}}else if(e instanceof ee){if(!1===z(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new s(t,c.ModuleExportNotFound,n);e.setGlobal(o,he(a,n.operator,e.global(o),n,t))}else{if(!S(e))throw x(e)?new s(t,c.Immutable,n):new s(t,c.InvalidParameter,n);if(!1===z(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,he(a,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new s(t,c.FieldNotFound,n,{key:o});e.setField(o,he(a,n.operator,null,n,t))}}return b}const o=e(r);if(null!=t.localScope&&void 0!==t.localScope[o]){const e=await ne(t,n.right);return t.localScope[o]={value:he(e,n.operator,t.localScope[o].value,n,t)},b}if(void 0!==t.globalScope[o]){const e=await ne(t,n.right);return t.globalScope[o]={value:he(e,n.operator,t.globalScope[o].value,n,t)},b}throw new s(t,c.InvalidIdentifier,n)}async function ge(e,t){const n=await ne(e,t.expression);return n===b?b:new A(n)}async function ye(e,t){const n=await ne(e,t.test);if(!0===n)return re(e,t.consequent);if(!1===n)return null!==t.alternate?re(e,t.alternate):b;throw new s(e,c.BooleanConditionRequired,t)}async function be(e,t){return ve(e,t,0)}async function ve(e,t,n){if(n>=t.body.length)return b;const r=await re(e,t.body[n]);return r instanceof R||r===O||r===N||n===t.body.length-1?r:ve(e,t,n+1)}async function Se(e,t){if(null===t.argument)return new R(b);const n=await ne(e,t.argument);return new R(n)}async function xe(t,n){const r=e(n.id);return t.globalScope[r]={value:new $(n,t)},b}async function Fe(t,n){const r=e(n.specifiers[0].local),o=t.libraryResolver.loadLibrary(r);let a;return t.libraryResolver._moduleSingletons?.has(o.uri)?a=t.libraryResolver._moduleSingletons.get(o.uri):(a=new ee(o),await a.loadModule(t),t.libraryResolver._moduleSingletons?.set(o.uri,a)),t.globalScope[r]={value:a},b}async function Ie(t,n){if(await re(t,n.declaration),"FunctionDeclaration"===n.declaration.type)t.exports[e(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)t.exports[e(r.id)]="variable";return b}async function Me(e,t,n){return n>=t.declarations.length?b:(await ke(e,t.declarations[n]),n===t.declarations.length-1||await Me(e,t,n+1),b)}async function ke(t,n){let r=null;if(r=null===n.init?null:await ne(t,n.init),null!==t.localScope){if(r===b&&(r=null),"Identifier"!==n.id.type)throw new s(t,c.InvalidIdentifier,n);const o=e(n.id);return void(null!=t.localScope&&(t.localScope[o]={value:r}))}if("Identifier"!==n.id.type)throw new s(t,c.InvalidIdentifier,n);const o=e(n.id);r===b&&(r=null),t.globalScope[o]={value:r}}async function Re(e,t){const n=await ne(e,t.object);if(null===n)throw new s(e,c.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof l||F(n))return n.field(t.property.name);if(n instanceof V)return a(n,t.property.name,e,t);if(n instanceof ee){if(!n.hasGlobal(t.property.name))throw new s(e,c.InvalidIdentifier,t);return n.global(t.property.name)}throw new s(e,c.InvalidMemberAccessKey,t)}throw new s(e,c.InvalidMemberAccessKey,t)}let r=await ne(e,t.property);if(n instanceof l||F(n)){if(z(r))return n.field(r);throw new s(e,c.InvalidMemberAccessKey,t)}if(n instanceof ee){if(z(r))return n.global(r);throw new s(e,c.InvalidMemberAccessKey,t)}if(n instanceof V){if(z(r))return a(n,r,e,t);throw new s(e,c.InvalidMemberAccessKey,t)}if(Y(n)){if(H(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new s(e,c.OutOfBounds,t);return n[r]}throw new s(e,c.InvalidMemberAccessKey,t)}if(x(n)){if(H(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new s(e,c.OutOfBounds,t);return n.get(r)}throw new s(e,c.InvalidMemberAccessKey,t)}if(z(n)){if(H(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new s(e,c.OutOfBounds,t);return n[r]}throw new s(e,c.InvalidMemberAccessKey,t)}throw new s(e,c.InvalidMemberAccessKey,t)}async function Ae(e,t){const n=await ne(e,t.argument);if(_(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*v(n);if("+"===t.operator)return 1*v(n);if("~"===t.operator)return~v(n);throw new s(e,c.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*v(n);if("+"===t.operator)return 1*v(n);if("~"===t.operator)return~v(n);throw new s(e,c.UnsupportedUnaryOperator,t)}async function Ce(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await ne(e,t.elements[r]));for(let r=0;r<n.length;r++){if(y(n[r]))throw new s(e,c.NoFunctionInArray,t);n[r]===b&&(n[r]=null)}return n}async function Oe(e,t){const n=await ne(e,t.left),r=await ne(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(v(n),v(r),t.operator);case"==":return g(n,r);case"!=":return!g(n,r);case"<":case">":case"<=":case">=":return M(n,r,t.operator);case"+":return z(n)||z(r)?I(n)+I(r):v(n)+v(r);case"-":return v(n)-v(r);case"*":return v(n)*v(r);case"/":return v(n)/v(r);case"%":return v(n)%v(r);default:throw new s(e,c.UnsupportedOperator,t)}}async function Ne(e,t){const n=await ne(e,t.left);if(!_(n))throw new s(e,c.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":{if(!0===n)return n;const r=await ne(e,t.right);if(_(r))return r;throw new s(e,c.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=await ne(e,t.right);if(_(r))return r;throw new s(e,c.LogicExpressionOrAnd,t)}default:throw new s(e,c.LogicExpressionOrAnd,t)}}function Ee(t,n){const r=e(n);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r].value;if(void 0!==t.globalScope[r])return t.globalScope[r].value;throw new s(t,c.InvalidIdentifier,n)}async function je(t,n){if("MemberExpression"===n.callee.type){const e=await ne(t,n.callee.object);if(!(e instanceof ee))throw new s(t,c.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:await ne(t,n.callee.property);if(!e.hasGlobal(r))throw new s(t,c.FunctionNotFound,n);const o=e.global(r);if(!y(o))throw new s(t,c.CallNonFunction,n);return o.call(t,n)}if("Identifier"!==n.callee.type)throw new s(t,c.FunctionNotFound,n);const r=e(n.callee);if(null!=t.localScope&&void 0!==t.localScope[r]){const e=t.localScope[r];if(y(e.value))return e.value.call(t,n);throw new s(t,c.CallNonFunction,n)}if(void 0!==t.globalScope[r]){const e=t.globalScope[r];if(y(e.value))return e.value.call(t,n);throw new s(t,c.CallNonFunction,n)}throw new s(t,c.FunctionNotFound,n)}async function Be(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 ne(e,t.expressions[r]);if(y(o))throw new s(e,c.NoFunctionInTemplateLiteral,t);n+=I(o)}r++}return n}const De={};async function Ke(e,t,n,r){const o=await ne(e,t.arguments[n]);if(g(o,r))return ne(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?ne(e,t.arguments[n]):2===a?null:3===a?ne(e,t.arguments[n+2]):Ke(e,t,n+2,r)}async function Ue(e,t,n,r){if(!0===r)return ne(e,t.arguments[n+1]);if(3===t.arguments.length-n)return ne(e,t.arguments[n+2]);const o=await ne(e,t.arguments[n+2]);if(!1===_(o))throw new s(e,c.ModuleExportNotFound,t.arguments[n+2]);return Ue(e,t,n+2,o)}async function Ze(t,n,r,o){const a=t.body;if(r.length!==t.params.length)throw new s(n,c.WrongNumberOfParameters,null);for(let l=0;l<r.length;l++){const o=t.params[l];"Identifier"===o.type&&null!=n.localScope&&(n.localScope[e(o)]={value:r[l]})}const i=await re(n,a);if(i instanceof R)return i.value;if(i===O)throw new s(n,c.UnexpectedToken,o);if(i===N)throw new s(n,c.UnexpectedToken,o);return i instanceof A?i.value:i}U(De,X),W(De,X),Z(De,X,Ee),q(De,X),L(De,X),P(De,X),G({functions:De,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:X,standardFunctionAsync:te}),De.iif=async function(e,t){m(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await ne(e,t.arguments[0]);if(!1===_(n))throw new s(e,c.BooleanConditionRequired,t);return ne(e,n?t.arguments[1]:t.arguments[2])},De.defaultvalue=async function(e,t){m(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await ne(e,t.arguments[0]);if(3===t.arguments.length){const r=await ne(e,t.arguments[1]),a=o(n,r);return null!=a&&""!==a?a:ne(e,t.arguments[2])}return null==n||""===n?ne(e,t.arguments[1]):n},De.decode=async function(e,t){if(t.arguments.length<2)throw new s(e,c.WrongNumberOfParameters,t);if(2===t.arguments.length)return ne(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new s(e,c.WrongNumberOfParameters,t);return Ke(e,t,1,await ne(e,t.arguments[0]))},De.when=async function(e,t){if(t.arguments.length<3)throw new s(e,c.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new s(e,c.WrongNumberOfParameters,t);const n=await ne(e,t.arguments[0]);if(!1===_(n))throw new s(e,c.BooleanConditionRequired,t.arguments[0]);return Ue(e,t,0,n)};const Ge={fixSpatialReference:E,parseArguments:Q,standardFunction:X,standardFunctionAsync:te,evaluateIdentifier:Ee};for(const _e in De)De[_e]={value:new p(De[_e])};const Le=function(){};function qe(e,t,n){const r=new Le;null==e&&(e={}),null==t&&(t={});const o=new l({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});o.immutable=!1,r.textformatting={value:o};for(const a in t)r[a]={value:new p(t[a])};for(const a in e)r[a]={value:J(e[a])?f.createFromGraphic(e[a],n):e[a]};return r}function Pe(e){console.log(e)}Le.prototype=De,Le.prototype.infinity={value:Number.POSITIVE_INFINITY},Le.prototype.pi={value:Math.PI};const We=Ge;function Ve(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:X,standardFunctionAsync:te,evaluateIdentifier:Ee};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)De[n]={value:new p(t.functions[n])},Le.prototype[n]=De[n];for(let n=0;n<t.signatures.length;n++)D(t.signatures[n],"async")}async function Te(e,n){const o=n.spatialReference??T.WebMercator;let a=null;e.usesModules&&(a=new r(new Map,e.loadedModules));const i=qe(n.vars,n.customfunctions,n.timeZone),l={spatialReference:o,services:n.services,exports:{},libraryResolver:a,abortSignal:n.abortSignal??t,globalScope:i,console:n.console??Pe,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}},u=await be(l,e);if(u instanceof R||u instanceof A){const e=u.value;if(C(e))return null;if(y(e))throw new s(l,c.IllegalResult,null);return e}if(C(u))return null;if(u===O)throw new s(l,c.IllegalResult,null);if(u===N)throw new s(l,c.IllegalResult,null);throw new s(l,c.NeverReach,null)}Ve([K]);export{Te as executeScript,Ve as extend,We as functionHelper};
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{getNestedOptionalValue as o,geometryMember as a,getGeometryKeys as i}from"./containerUtils.js";import l from"./Dictionary.js";import{ArcadeExecutionError as s,ExecutionErrorCodes as c,ensureArcadeExecutionError as u}from"./executionError.js";import f from"./Feature.js";import{NativeFunction as p,ScopeMarshalledFunction as w,ArcadeFunction as d,wrapModuleScopedResponse as h}from"./FunctionWrapper.js";import{D as m,B as g,i as y,w as b,t as v,n as S,m as x,z as F,f as I,A as M,C as k,R,I as A,E as C,x as O,y as N,u as j,p as E,l as B}from"../chunks/languageUtils.js";import{addFunctionDeclaration as D}from"./treeAnalysis.js";import{A as K}from"../chunks/aiServices.js";import{A as U}from"../chunks/array.js";import{registerFunctions as Z}from"./functions/date.js";import{registerFunctions as G}from"./functions/feature.js";import{registerFunctions as L}from"./functions/geomasync.js";import{registerFunctions as q}from"./functions/geometry.js";import{registerFunctions as P}from"./functions/maths.js";import{registerFunctions as W}from"./functions/stats.js";import{registerFunctions as V}from"./functions/string.js";import T from"../geometry/Geometry.js";import _ from"../geometry/SpatialReference.js";import{isBoolean as z,isString as Y,isArray as H,isNumber as J,isGraphic as Q}from"../support/guards.js";async function X(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await re(e,t.arguments[r]));return n}async function $(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await X(e,t))}class ee extends d{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,services:this.context.services,abortSignal:this.context.abortSignal,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new s(e,c.MaximumCallDepth,null);return Ge(this.definition,n,t,null)}}call(e,t){return ne(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:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(a.depthCounter.depth>64)throw new s(e,c.MaximumCallDepth,t);return Ge(this.definition,a,o,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={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:{}};return i=i.map((t=>!y(t)||t instanceof w?t:h(t,e,r))),h(await Ge(this.definition,l,i,t),n,r)}))}}class te extends n{constructor(e){super(),this.source=e}global(t){const n=this.executingContext.globalScope[e(t)];if(y(n.value)&&!(n.value instanceof w)){const e=new w;e.fn=n.value,e.parameterEvaluator=ne,e.context=this.executingContext,n.value=e}return n.value}setGlobal(t,n){if(y(n))throw new s(null,c.AssignModuleFunction,null);this.executingContext.globalScope[e(t)]={value:n}}hasGlobal(t){return void 0===this.executingContext.exports[t]&&(t=e(t)),void 0!==this.executingContext.exports[t]}async loadModule(e){const n=e.spatialReference??_.WebMercator;this.moduleScope=Pe(null,null,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new r(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:e.abortSignal??t,globalScope:this.moduleScope,console:e.console??We,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await ve(this.executingContext,this.source.syntax)}}async function ne(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await X(e,t))}async function re(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"UpdateExpression":return await he(e,t);case"AssignmentExpression":return await ge(e,t);case"TemplateLiteral":return await De(e,t);case"Identifier":return Ee(e,t);case"MemberExpression":return await Ae(e,t);case"Literal":return t.value;case"CallExpression":return await Be(e,t);case"UnaryExpression":return await Ce(e,t);case"BinaryExpression":return await Ne(e,t);case"LogicalExpression":return await je(e,t);case"ArrayExpression":return await Oe(e,t);case"ObjectExpression":return await ae(e,t);default:throw new s(e,c.Unrecognized,t)}}catch(n){throw u(e,t,n)}}async function oe(e,t){t.breakpoint&&await t.breakpoint();try{switch(t.type){case"ImportDeclaration":return await Ie(e,t);case"ExportNamedDeclaration":return await Me(e,t);case"VariableDeclaration":return await ke(e,t,0);case"BlockStatement":return await ve(e,t);case"FunctionDeclaration":return await Fe(e,t);case"ReturnStatement":return await xe(e,t);case"IfStatement":return await be(e,t);case"ExpressionStatement":return await ye(e,t);case"ForStatement":return await le(e,t);case"WhileStatement":return await ie(e,t);case"ForInStatement":return await we(e,t);case"ForOfStatement":return await de(e,t);case"BreakStatement":return O;case"EmptyStatement":return b;case"ContinueStatement":return N;default:throw new s(e,c.Unrecognized,t)}}catch(n){throw u(e,t,n)}}async function ae(e,t){const n=[];for(let i=0;i<t.properties.length;i++){const r=t.properties[i],o=await re(e,r.value),a="Identifier"===r.key.type?r.key.name:await re(e,r.key);n[i]={key:a,value:o}}const r={},o=new Map;for(let i=0;i<n.length;i++){const a=n[i];if(y(a.value))throw new s(e,c.NoFunctionInDictionary,t);if(!1===Y(a.key))throw new s(e,c.KeyMustBeString,t);let l=a.key.toString();const u=l.toLowerCase();o.has(u)?l=o.get(u):o.set(u,l),a.value===b?r[l]=null:r[l]=a.value}const a=new l(r);return a.immutable=!1,a}async function ie(e,t){let n=await re(e,t.test);if(!1===n)return b;if(!0!==n)throw new s(e,c.BooleanConditionRequired,t);for(;!0===n;){const r=await oe(e,t.body);if(r===O)break;if(r instanceof R)return r;if(n=await re(e,t.test),!0!==n&&!1!==n)throw new s(e,c.BooleanConditionRequired,t)}return b}async function le(e,t){try{for(null!==t.init&&("VariableDeclaration"===t.init.type?await oe(e,t.init):await re(e,t.init));;){if(null!==t.test){const n=await re(e,t.test);if(!0===e.abortSignal?.aborted)throw new s(e,c.Cancelled,t);if(!1===n)break;if(!0!==n)throw new s(e,c.BooleanConditionRequired,t)}const n=await oe(e,t.body);if(n===O)break;if(n instanceof R)return n;null!==t.update&&await re(e,t.update)}return b}catch(n){throw n}}async function se(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 s(e,c.OutOfBounds,t);r.value=n[i]}else r.value=i;const a=await oe(e,t.body);if(a===O)break;if(a instanceof R)return a}return b}async function ce(e,t,n,r,o="i"){const a=n.length();for(let i=0;i<a;i++){r.value="k"===o?n.get(i):i;const a=await oe(e,t.body);if(a===O)break;if(a instanceof R)return a}return b}async function ue(e,t,n,r){const o=n.iterator(e.abortSignal);let a;for(;null!=(a=await o.next());){const o=f.createFromGraphicLikeObject(a.geometry,a.attributes,n,e.timeZone);o._underlyingGraphic=a,r.value=o;const i=await oe(e,t.body);if(i===O)break;if(i instanceof R)return i}return b}async function fe(e,t,n,r){for(const o of n.keys()){const a=n.field(o);r.value=new l({key:o,value:a});const i=await oe(e,t.body);if(i===O)break;if(i instanceof R)return i}return b}async function pe(e,t,n,r){for(const o of i(n)){const i=a(n,o,e,t,1);r.value=new l({key:o,value:i});const s=await oe(e,t.body);if(s===O)break;if(s instanceof R)return s}return b}async function we(t,n){const r=await re(t,n.right);"VariableDeclaration"===n.left.type&&await oe(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let a=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(a=t.localScope[o]),null===a&&void 0!==t.globalScope[o]&&(a=t.globalScope[o]),null===a)throw new s(t,c.InvalidIdentifier,n);return H(r)||Y(r)?await se(t,n,r,a):x(r)?await ce(t,n,r,a):r instanceof l||F(r)?await se(t,n,r.keys(),a,"k"):E(r)?await ue(t,n,r,a):B(r)?await se(t,n,i(r),a,"k"):b}async function de(t,n){const r=await re(t,n.right);"VariableDeclaration"===n.left.type&&await oe(t,n.left);const o=e("VariableDeclaration"===n.left.type?n.left.declarations[0].id:n.left);let a=null;if(null!=t.localScope&&void 0!==t.localScope[o]&&(a=t.localScope[o]),null===a&&void 0!==t.globalScope[o]&&(a=t.globalScope[o]),null===a)throw new s(t,c.InvalidIdentifier,n);return H(r)||Y(r)?await se(t,n,r,a,"k"):x(r)?await ce(t,n,r,a,"k"):r instanceof l||F(r)?await fe(t,n,r,a):E(r)?await ue(t,n,r,a):B(r)?await pe(t,n,r,a):b}async function he(t,n){const r=n.argument;if("CallExpression"===r.type)throw new s(t,c.NeverReach,n);if("MemberExpression"===r.type){const e=await re(t,r.object);let o,a;if(!0===r.computed)o=await re(t,r.property);else{if("Identifier"!==r.property.type)throw new s(t,c.Unrecognized,n);o=r.property.name}if(H(e)){if(!J(o))throw new s(t,c.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>=e.length)throw new s(t,c.OutOfBounds,n);a=v(e[o]),e[o]="++"===n.operator?a+1:a-1}else if(e instanceof l){if(!1===Y(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new s(t,c.FieldNotFound,n,{key:o});a=v(e.field(o)),e.setField(o,"++"===n.operator?a+1:a-1)}else if(e instanceof te){if(!1===Y(o))throw new s(t,c.ModuleAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new s(t,c.ModuleExportNotFound,n);a=v(e.global(o)),e.setGlobal(o,"++"===n.operator?a+1:a-1)}else{if(!S(e))throw x(e)?new s(t,c.Immutable,n):new s(t,c.InvalidParameter,n);if(!1===Y(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0!==e.hasField(o))throw new s(t,c.FieldNotFound,n,{key:o});a=v(e.field(o)),e.setField(o,"++"===n.operator?a+1:a-1)}return!1===n.prefix?a:"++"===n.operator?a+1:a-1}const o=e(r);let a;if(null!=t.localScope&&void 0!==t.localScope[o])return a=v(t.localScope[o].value),t.localScope[o]={value:"++"===n.operator?a+1:a-1},!1===n.prefix?a:"++"===n.operator?a+1:a-1;if(void 0!==t.globalScope[o])return a=v(t.globalScope[o].value),t.globalScope[o]={value:"++"===n.operator?a+1:a-1},!1===n.prefix?a:"++"===n.operator?a+1:a-1;throw new s(t,c.InvalidIdentifier,n)}function me(e,t,n,r,o){switch(t){case"=":return e===b?null:e;case"/=":return v(n)/v(e);case"*=":return v(n)*v(e);case"-=":return v(n)-v(e);case"+=":return Y(n)||Y(e)?I(n)+I(e):v(n)+v(e);case"%=":return v(n)%v(e);default:throw new s(o,c.UnsupportedOperator,r)}}async function ge(t,n){const r=n.left;if("MemberExpression"===r.type){const e=await re(t,r.object);let o;if(!0===r.computed)o=await re(t,r.property);else{if("Identifier"!==r.property.type)throw new s(t,c.InvalidIdentifier,n);o=r.property.name}const a=await re(t,n.right);if(H(e)){if(!J(o))throw new s(t,c.ArrayAccessorMustBeNumber,n);if(o<0&&(o=e.length+o),o<0||o>e.length)throw new s(t,c.OutOfBounds,n);if(o===e.length){if("="!==n.operator)throw new s(t,c.OutOfBounds,n);e[o]=me(a,n.operator,e[o],n,t)}else e[o]=me(a,n.operator,e[o],n,t)}else if(e instanceof l){if(!1===Y(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,me(a,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new s(t,c.FieldNotFound,n,{key:o});e.setField(o,me(a,n.operator,null,n,t))}}else if(e instanceof te){if(!1===Y(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0!==e.hasGlobal(o))throw new s(t,c.ModuleExportNotFound,n);e.setGlobal(o,me(a,n.operator,e.global(o),n,t))}else{if(!S(e))throw x(e)?new s(t,c.Immutable,n):new s(t,c.InvalidParameter,n);if(!1===Y(o))throw new s(t,c.KeyAccessorMustBeString,n);if(!0===e.hasField(o))e.setField(o,me(a,n.operator,e.field(o),n,t));else{if("="!==n.operator)throw new s(t,c.FieldNotFound,n,{key:o});e.setField(o,me(a,n.operator,null,n,t))}}return b}const o=e(r);if(null!=t.localScope&&void 0!==t.localScope[o]){const e=await re(t,n.right);return t.localScope[o]={value:me(e,n.operator,t.localScope[o].value,n,t)},b}if(void 0!==t.globalScope[o]){const e=await re(t,n.right);return t.globalScope[o]={value:me(e,n.operator,t.globalScope[o].value,n,t)},b}throw new s(t,c.InvalidIdentifier,n)}async function ye(e,t){const n=await re(e,t.expression);return n===b?b:new A(n)}async function be(e,t){const n=await re(e,t.test);if(!0===n)return oe(e,t.consequent);if(!1===n)return null!==t.alternate?oe(e,t.alternate):b;throw new s(e,c.BooleanConditionRequired,t)}async function ve(e,t){return Se(e,t,0)}async function Se(e,t,n){if(n>=t.body.length)return b;const r=await oe(e,t.body[n]);return r instanceof R||r===O||r===N||n===t.body.length-1?r:Se(e,t,n+1)}async function xe(e,t){if(null===t.argument)return new R(b);const n=await re(e,t.argument);return new R(n)}async function Fe(t,n){const r=e(n.id);return t.globalScope[r]={value:new ee(n,t)},b}async function Ie(t,n){const r=e(n.specifiers[0].local),o=t.libraryResolver.loadLibrary(r);let a;return t.libraryResolver._moduleSingletons?.has(o.uri)?a=t.libraryResolver._moduleSingletons.get(o.uri):(a=new te(o),await a.loadModule(t),t.libraryResolver._moduleSingletons?.set(o.uri,a)),t.globalScope[r]={value:a},b}async function Me(t,n){if(await oe(t,n.declaration),"FunctionDeclaration"===n.declaration.type)t.exports[e(n.declaration.id)]="function";else if("VariableDeclaration"===n.declaration.type)for(const r of n.declaration.declarations)t.exports[e(r.id)]="variable";return b}async function ke(e,t,n){return n>=t.declarations.length?b:(await Re(e,t.declarations[n]),n===t.declarations.length-1||await ke(e,t,n+1),b)}async function Re(t,n){let r=null;if(r=null===n.init?null:await re(t,n.init),null!==t.localScope){if(r===b&&(r=null),"Identifier"!==n.id.type)throw new s(t,c.InvalidIdentifier,n);const o=e(n.id);return void(null!=t.localScope&&(t.localScope[o]={value:r}))}if("Identifier"!==n.id.type)throw new s(t,c.InvalidIdentifier,n);const o=e(n.id);r===b&&(r=null),t.globalScope[o]={value:r}}async function Ae(e,t){const n=await re(e,t.object);if(null===n)throw new s(e,c.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof l||F(n))return n.field(t.property.name);if(n instanceof T)return a(n,t.property.name,e,t);if(n instanceof te){if(!n.hasGlobal(t.property.name))throw new s(e,c.InvalidIdentifier,t);return n.global(t.property.name)}throw new s(e,c.InvalidMemberAccessKey,t)}throw new s(e,c.InvalidMemberAccessKey,t)}let r=await re(e,t.property);if(n instanceof l||F(n)){if(Y(r))return n.field(r);throw new s(e,c.InvalidMemberAccessKey,t)}if(n instanceof te){if(Y(r))return n.global(r);throw new s(e,c.InvalidMemberAccessKey,t)}if(n instanceof T){if(Y(r))return a(n,r,e,t);throw new s(e,c.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 s(e,c.OutOfBounds,t);return n[r]}throw new s(e,c.InvalidMemberAccessKey,t)}if(x(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new s(e,c.OutOfBounds,t);return n.get(r)}throw new s(e,c.InvalidMemberAccessKey,t)}if(Y(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new s(e,c.OutOfBounds,t);return n[r]}throw new s(e,c.InvalidMemberAccessKey,t)}throw new s(e,c.InvalidMemberAccessKey,t)}async function Ce(e,t){const n=await re(e,t.argument);if(z(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*v(n);if("+"===t.operator)return 1*v(n);if("~"===t.operator)return~v(n);throw new s(e,c.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*v(n);if("+"===t.operator)return 1*v(n);if("~"===t.operator)return~v(n);throw new s(e,c.UnsupportedUnaryOperator,t)}async function Oe(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await re(e,t.elements[r]));for(let r=0;r<n.length;r++){if(y(n[r]))throw new s(e,c.NoFunctionInArray,t);n[r]===b&&(n[r]=null)}return n}async function Ne(e,t){const n=await re(e,t.left),r=await re(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return k(v(n),v(r),t.operator);case"==":return g(n,r);case"!=":return!g(n,r);case"<":case">":case"<=":case">=":return M(n,r,t.operator);case"+":return Y(n)||Y(r)?I(n)+I(r):v(n)+v(r);case"-":return v(n)-v(r);case"*":return v(n)*v(r);case"/":return v(n)/v(r);case"%":return v(n)%v(r);default:throw new s(e,c.UnsupportedOperator,t)}}async function je(e,t){const n=await re(e,t.left);if(!z(n))throw new s(e,c.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":{if(!0===n)return n;const r=await re(e,t.right);if(z(r))return r;throw new s(e,c.LogicExpressionOrAnd,t)}case"&&":{if(!1===n)return n;const r=await re(e,t.right);if(z(r))return r;throw new s(e,c.LogicExpressionOrAnd,t)}default:throw new s(e,c.LogicExpressionOrAnd,t)}}function Ee(t,n){const r=e(n);if(null!=t.localScope&&void 0!==t.localScope[r])return t.localScope[r].value;if(void 0!==t.globalScope[r])return t.globalScope[r].value;throw new s(t,c.InvalidIdentifier,n)}async function Be(t,n){if("MemberExpression"===n.callee.type){const e=await re(t,n.callee.object);if(!(e instanceof te))throw new s(t,c.FunctionNotFound,n);const r=!1===n.callee.computed?n.callee.property.name:await re(t,n.callee.property);if(!e.hasGlobal(r))throw new s(t,c.FunctionNotFound,n);const o=e.global(r);if(!y(o))throw new s(t,c.CallNonFunction,n);return o.call(t,n)}if("Identifier"!==n.callee.type)throw new s(t,c.FunctionNotFound,n);const r=e(n.callee);if(null!=t.localScope&&void 0!==t.localScope[r]){const e=t.localScope[r];if(y(e.value))return e.value.call(t,n);throw new s(t,c.CallNonFunction,n)}if(void 0!==t.globalScope[r]){const e=t.globalScope[r];if(y(e.value))return e.value.call(t,n);throw new s(t,c.CallNonFunction,n)}throw new s(t,c.FunctionNotFound,n)}async function De(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 re(e,t.expressions[r]);if(y(o))throw new s(e,c.NoFunctionInTemplateLiteral,t);n+=I(o)}r++}return n}const Ke={};async function Ue(e,t,n,r){const o=await re(e,t.arguments[n]);if(g(o,r))return re(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?re(e,t.arguments[n]):2===a?null:3===a?re(e,t.arguments[n+2]):Ue(e,t,n+2,r)}async function Ze(e,t,n,r){if(!0===r)return re(e,t.arguments[n+1]);if(3===t.arguments.length-n)return re(e,t.arguments[n+2]);const o=await re(e,t.arguments[n+2]);if(!1===z(o))throw new s(e,c.ModuleExportNotFound,t.arguments[n+2]);return Ze(e,t,n+2,o)}async function Ge(t,n,r,o){const a=t.body;if(r.length!==t.params.length)throw new s(n,c.WrongNumberOfParameters,null);for(let l=0;l<r.length;l++){const o=t.params[l];"Identifier"===o.type&&null!=n.localScope&&(n.localScope[e(o)]={value:r[l]})}const i=await oe(n,a);if(i instanceof R)return i.value;if(i===O)throw new s(n,c.UnexpectedToken,o);if(i===N)throw new s(n,c.UnexpectedToken,o);return i instanceof A?i.value:i}Z(Ke,$),V(Ke,$),G(Ke,$,Ee),P(Ke,$),q(Ke,$),W(Ke,$),L({functions:Ke,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:$,standardFunctionAsync:ne}),Ke.iif=async function(e,t){m(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await re(e,t.arguments[0]);if(!1===z(n))throw new s(e,c.BooleanConditionRequired,t);return re(e,n?t.arguments[1]:t.arguments[2])},Ke.defaultvalue=async function(e,t){m(null===t.arguments?[]:t.arguments,2,3,e,t);const n=await re(e,t.arguments[0]);if(3===t.arguments.length){const r=await re(e,t.arguments[1]),a=o(n,r);return null!=a&&""!==a?a:re(e,t.arguments[2])}return null==n||""===n?re(e,t.arguments[1]):n},Ke.decode=async function(e,t){if(t.arguments.length<2)throw new s(e,c.WrongNumberOfParameters,t);if(2===t.arguments.length)return re(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new s(e,c.WrongNumberOfParameters,t);return Ue(e,t,1,await re(e,t.arguments[0]))},Ke.when=async function(e,t){if(t.arguments.length<3)throw new s(e,c.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new s(e,c.WrongNumberOfParameters,t);const n=await re(e,t.arguments[0]);if(!1===z(n))throw new s(e,c.BooleanConditionRequired,t.arguments[0]);return Ze(e,t,0,n)};const Le={fixSpatialReference:j,parseArguments:X,standardFunction:$,standardFunctionAsync:ne,evaluateIdentifier:Ee};for(const ze in Ke)Ke[ze]={value:new p(Ke[ze])};const qe=function(){};function Pe(e,t,n){const r=new qe;null==e&&(e={}),null==t&&(t={});const o=new l({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});o.immutable=!1,r.textformatting={value:o};for(const a in t)r[a]={value:new p(t[a])};for(const a in e)r[a]={value:Q(e[a])?f.createFromGraphic(e[a],n):e[a]};return r}function We(e){console.log(e)}qe.prototype=Ke,qe.prototype.infinity={value:Number.POSITIVE_INFINITY},qe.prototype.pi={value:Math.PI};const Ve=Le;function Te(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:$,standardFunctionAsync:ne,evaluateIdentifier:Ee};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ke[n]={value:new p(t.functions[n])},qe.prototype[n]=Ke[n];for(let n=0;n<t.signatures.length;n++)D(t.signatures[n],"async")}async function _e(e,n){const o=n.spatialReference??_.WebMercator;let a=null;e.usesModules&&(a=new r(new Map,e.loadedModules));const i=Pe(n.vars,n.customfunctions,n.timeZone),l={spatialReference:o,services:n.services,exports:{},libraryResolver:a,abortSignal:n.abortSignal??t,globalScope:i,console:n.console??We,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}},u=await ve(l,e);if(u instanceof R||u instanceof A){const e=u.value;if(C(e))return null;if(y(e))throw new s(l,c.IllegalResult,null);return e}if(C(u))return null;if(u===O)throw new s(l,c.IllegalResult,null);if(u===N)throw new s(l,c.IllegalResult,null);throw new s(l,c.NeverReach,null)}Te([U]),Te([K]);export{_e as executeScript,Te as extend,Ve as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{neverAbortedSignal as e,toSymbolId as n}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as l}from"./ArcadeModuleLoader.js";import{getGeometryKeys as o,geometryMember as r,getNestedOptionalValue as a}from"./containerUtils.js";import s from"./Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as c,ArcadeCompilationError as u,ArcadeUncompilableError as p}from"./executionError.js";import m from"./Feature.js";import{NativeFunction as g,ArcadeFunction as d,ScopeMarshalledFunction as f,wrapModuleScopedResponse as h}from"./FunctionWrapper.js";import{i as y,u as b,v as w,R as S,I as v,w as x,x as M,y as F,m as $,z as C,q as I,l as A,f as _,t as O,A as k,B as G,C as E,n as j}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as N}from"../chunks/array.js";import{registerFunctions as R}from"./functions/date.js";import{registerFunctions as D}from"./functions/feature.js";import{registerFunctions as L}from"./functions/geometry.js";import{registerFunctions as U}from"./functions/geomsync.js";import{registerFunctions as K}from"./functions/maths.js";import{registerFunctions as P}from"./functions/stats.js";import{registerFunctions as W}from"./functions/string.js";import{isPromiseLike as V}from"../core/promiseUtils.js";import q from"../geometry/Geometry.js";import T from"../geometry/SpatialReference.js";import{isGraphic as Z,isNumber as z,isArray as J,isString as Y,isBoolean as H}from"../support/guards.js";class Q extends d{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new i(e,c.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,l){return l(e,n,((n,o,r)=>{r=r.map((n=>!y(n)||n instanceof f?n:h(n,e,l)));const a=this.call(t,{arguments:r});return V(a)?a.then((e=>h(e,t,l))):a}))}}function X(e,n){const t=[];for(let l=0;l<n.arguments.length;l++)t.push(ne(e,n.arguments[l]));return t}function ee(e,n,t){try{return t(e,null,n.arguments)}catch(l){throw l}}function ne(e,n){switch(n.type){case"AssignmentExpression":return me(e,n);case"UpdateExpression":return ue(e,n);case"TemplateLiteral":return Ie(e,n);case"Identifier":return Oe(e,n);case"MemberExpression":return Fe(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return ke(e,n);case"UnaryExpression":return $e(e,n);case"BinaryExpression":return Ae(e,n);case"LogicalExpression":return _e(e,n);case"ArrayExpression":return Ce(e,n);case"ObjectExpression":return le(e,n);default:throw new u(null,c.Unrecognized,n)}}function te(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return xe(e,n);case"BlockStatement":return he(e,n);case"FunctionDeclaration":return ve(e,n);case"ImportDeclaration":return be(e,n);case"ExportNamedDeclaration":return we(e,n);case"ReturnStatement":return ye(e,n);case"IfStatement":return fe(e,n);case"ExpressionStatement":return ge(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ce(e,n);case"ForInStatement":return se(e,n);case"ForOfStatement":return ie(e,n);case"WhileStatement":return pe(e,n);default:throw new u(null,c.Unrecognized,n)}}function le(e,n){let t="lang.dictionary([";for(let l=0;l<n.properties.length;l++){const o=n.properties[l];let r;"Identifier"===o.key.type?(Se(o.key.name),r="'"+o.key.name+"'"):r=ne(e,o.key);l>0&&(t+=","),t+="lang.strCheck("+r+",'ObjectExpression'),lang.aCheck("+ne(e,o.value)+", 'ObjectExpression')"}return t+="])",t}function oe(e,n,t,l,o=(e,n)=>`${e} = ${n}`){const r=De(e),a=De(e);return[`var ${r} = ${t};`,`for (var ${a} = 0; ${a} < ${r}; ${a}++) {`,` ${o(n,a)}`,` ${te(e,l)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function re(e,n,t,l,o=e=>e){const r=De(e),a=De(e);return[`var ${r} = ${t};`,`for (var ${a} of ${r}) {`,` ${n} = ${o(a)};`,` ${te(e,l)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function ae(e,n,t,l){const o=De(e);return[`var ${o} = ${t}.iterator(runtimeCtx.abortSignal);`,`while ((${n} = lang.graphicToFeature(yield ${o}.next(), ${t}, runtimeCtx)) != null) {`,` ${te(e,l)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function se(e,t){const l=De(e);let o="var "+l+" = "+ne(e,t.right)+";\n";"VariableDeclaration"===t.left.type&&(o+=te(e,t.left));const r=n("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);Se(r);let a="";null!==e.localScope&&(void 0!==e.localScope[r]?a="lscope['"+r+"']":void 0!==e.localScope._SymbolsMap[r]&&(a="lscope['"+e.localScope._SymbolsMap[r]+"']"));let s="";if(""===a)if(void 0!==e.globalScope[r])a="gscope['"+r+"']";else if(void 0!==e.globalScope._SymbolsMap[r])a="gscope['"+e.globalScope._SymbolsMap[r]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(r))a="gscope['"+e.undeclaredGlobalsInFunctions.get(r).manglename+"']",s=e.undeclaredGlobalsInFunctions.get(r).manglename;else{const n={manglename:Re(e),node:t.left};e.undeclaredGlobalsInFunctions.set(r,n),a="gscope['"+n.manglename+"']",s=n.manglename}return s&&(o+="lang.chkAssig('"+s+"',runtimeCtx); \n"),o+="if ("+l+"===null) { lastStatement = lc.voidOperation; }\n ",o+="else if (lc.isArray("+l+") || lc.isString("+l+")) {\n",o+=oe(e,a,`${l}.length`,t.body),o+="}\n",o+="else if (lc.isImmutableArray("+l+")) {\n",o+=oe(e,a,`${l}.length()`,t.body),o+="}\n",o+="else if (( "+l+" instanceof lang.Dictionary) || lc.isDictionaryLike("+l+")) {\n",o+=re(e,a,`${l}.keys()`,t.body),o+="}\n",e.isAsync&&(o+="else if (lc.isFeatureSet("+l+")) {\n",o+=ae(e,a,l,t.body),o+="}\n"),o+=`else if (lc.isGeometry(${l})) {\n`,o+=re(e,a,`lang.getGeometryKeys(${l})`,t.body),o+="}\n",o+="else { lastStatement = lc.voidOperation; } \n",o}function ie(e,t){const l=De(e);let o="var "+l+" = "+ne(e,t.right)+";\n";"VariableDeclaration"===t.left.type&&(o+=te(e,t.left));const r=n("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);Se(r);let a="";null!==e.localScope&&(void 0!==e.localScope[r]?a="lscope['"+r+"']":void 0!==e.localScope._SymbolsMap[r]&&(a="lscope['"+e.localScope._SymbolsMap[r]+"']"));let s="";if(""===a)if(void 0!==e.globalScope[r])a="gscope['"+r+"']";else if(void 0!==e.globalScope._SymbolsMap[r])a="gscope['"+e.globalScope._SymbolsMap[r]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(r))a="gscope['"+e.undeclaredGlobalsInFunctions.get(r).manglename+"']",s=e.undeclaredGlobalsInFunctions.get(r).manglename;else{const n={manglename:Re(e),node:t.left};e.undeclaredGlobalsInFunctions.set(r,n),a="gscope['"+n.manglename+"']",s=n.manglename}return s&&(o+="lang.chkAssig('"+s+"',runtimeCtx); \n"),o+="if ("+l+"===null) { lastStatement = lc.voidOperation; }\n ",o+="else if (lc.isArray("+l+") || lc.isString("+l+")) {\n",o+=oe(e,a,`${l}.length`,t.body,((e,n)=>[`if (${n} >= ${l}.length) {`,` lang.error('${c.OutOfBounds}');`,"}",`${e} = ${l}[${n}];`].join("\n"))),o+="}\n",o+="else if (lc.isImmutableArray("+l+")) {\n",o+=oe(e,a,`${l}.length()`,t.body,((e,n)=>`${e} = ${l}.get(${n});`)),o+="}\n",o+="else if (( "+l+" instanceof lang.Dictionary) || lc.isDictionaryLike("+l+")) {\n",o+=re(e,a,`${l}.keys()`,t.body,(e=>`lang.entry(${e}, ${l}.field(${e}))`)),o+="}\n",e.isAsync&&(o+="else if (lc.isFeatureSet("+l+")) {\n",o+=ae(e,a,l,t.body),o+="}\n"),o+=`else if (lc.isGeometry(${l})) {\n`,o+=re(e,a,`lang.getGeometryKeys(${l})`,t.body,(e=>`lang.entry(${e}, lang.geometryMember(${l}, ${e}, runtimeCtx, null, 1))`)),o+="}\n",o+="else { lastStatement = lc.voidOperation; } \n",o}function ce(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=te(e,n.init):t+=ne(e,n.init)+"; ");const l=De(e),o=De(e);return t+="var "+l+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+l+"===false) {\n "+ne(e,n.update)+" \n}\n "+l+"=false; \n"),null!==n.test&&(t+="var "+o+" = "+ne(e,n.test)+"; ",t+="if ("+o+"===false) { break; } else if ("+o+"!==true) { lang.error('"+c.BooleanConditionRequired+"'); }\n"),t+=te(e,n.body),null!==n.update&&(t+="\n "+ne(e,n.update)),t+="\n"+l+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function ue(e,t){if("CallExpression"===t.argument.type)throw new u(null,c.NeverReach,t);let l;if("MemberExpression"===t.argument.type){const n=ne(e,t.argument.object);return!0===t.argument.computed?l=ne(e,t.argument.property):(Se(t.argument.property.name),l="'"+t.argument.property.name+"'"),"lang.memberupdate("+n+","+l+",'"+t.operator+"',"+t.prefix+")"}const o=n(t.argument);if(Se(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lang.update(lscope, '"+o+"','"+t.operator+"',"+t.prefix+")";if(void 0!==e.localScope._SymbolsMap[o])return"lang.update(lscope, '"+e.localScope._SymbolsMap[o]+"','"+t.operator+"',"+t.prefix+")"}if(void 0!==e.globalScope[o])return"lang.update(gscope, '"+o+"','"+t.operator+"',"+t.prefix+")";if(void 0!==e.globalScope._SymbolsMap[o])return"lang.update(gscope, '"+e.globalScope._SymbolsMap[o]+"','"+t.operator+"',"+t.prefix+")";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"lang.update(gscope,lang.chkAssig( '"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")";const n={manglename:Re(e),node:t.argument};return e.undeclaredGlobalsInFunctions.set(o,n),"lang.update(gscope, lang.chkAssig('"+n.manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")"}throw new u(null,c.InvalidIdentifier,t)}function pe(e,n){let t="lastStatement = lc.voidOperation; \n";const l=De(e);return t+=`\n var ${l} = true;\n do {\n ${l} = ${ne(e,n.test)};\n if (${l}==false) {\n break;\n }\n if (${l}!==true) {\n lang.error('${c.BooleanConditionRequired}');\n }\n ${te(e,n.body)}\n }\n while (${l} !== false);\n lastStatement = lc.voidOperation;\n `,t}function me(e,t){const l=ne(e,t.right);if("MemberExpression"===t.left.type){let n;const o=ne(e,t.left.object);return!0===t.left.computed?n=ne(e,t.left.property):(n="'"+t.left.property.name+"'",Se(t.left.property.name)),"lang.assignmember("+o+","+n+",'"+t.operator+"',"+l+")"}const o=n(t.left);if(Se(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']=lang.assign("+l+",'"+t.operator+"', lscope['"+o+"'])";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']=lang.assign("+l+",'"+t.operator+"', lscope['"+e.localScope._SymbolsMap[o]+"'])"}if(void 0!==e.globalScope[o])return"gscope['"+o+"']=lang.assign("+l+",'"+t.operator+"', gscope['"+o+"'])";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']=lang.assign("+l+",'"+t.operator+"', gscope['"+e.globalScope._SymbolsMap[o]+"'])";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]=lang.assign("+l+",'"+t.operator+"', gscope['"+e.undeclaredGlobalsInFunctions.get(o).manglename+"'])";const n={manglename:Re(e),node:t.left};return e.undeclaredGlobalsInFunctions.set(o,n),"gscope[lang.chkAssig('"+n.manglename+"',runtimeCtx)]=lang.assign("+l+",'"+t.operator+"', gscope['"+n.manglename+"'])"}throw new u(null,c.InvalidIdentifier,t)}function ge(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+ne(e,n.expression)+"; \n ":"lastStatement = "+ne(e,n.expression)+"; "}function de(e,n){return"BlockStatement"===n.type?te(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?te(e,n)+"; ":"ExpressionStatement"===n.type?te(e,n):te(e,n)+"; "}function fe(e,n){return`if (lang.mustBoolean(${ne(e,n.test)}, runtimeCtx) === true) {\n ${de(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+fe(e,n.alternate):` else {\n ${de(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function he(e,n){let t="";for(let l=0;l<n.body.length;l++)"EmptyStatement"!==n.body[l].type&&("ReturnStatement"===n.body[l].type||"BreakStatement"===n.body[l].type||"ContinueStatement"===n.body[l].type?t+=te(e,n.body[l])+"; \n":t+=te(e,n.body[l])+" \n");return t}function ye(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+ne(e,n.argument)}function be(e,t){const l=n(t.specifiers[0].local);Se(l);const o=e.libraryResolver?.loadLibrary(l),r=Re(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=Xe(o.syntax,{moduleFactory:e.moduleFactory,libraryResolver:e.libraryResolver},e.isAsync)),e.moduleFactoryMap[r]=o.uri;let a,s="";return s=e.isAsync?"(yield lang.loadModule('"+r+"', runtimeCtx) ); ":"lang.loadModule('"+r+"', runtimeCtx); ",void 0!==e.globalScope[l]?"gscope['"+l+"']="+s:void 0!==e.globalScope._SymbolsMap[l]?"gscope['"+e.globalScope._SymbolsMap[l]+"']="+s:(e.undeclaredGlobalsInFunctions.has(l)?(a=e.undeclaredGlobalsInFunctions.get(l).manglename,e.undeclaredGlobalsInFunctions.delete(l)):a=Re(e),e.globalScope._SymbolsMap[l]=a,e.mangleMap[l]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+s)}function we(e,t){const l=te(e,t.declaration);if("FunctionDeclaration"===t.declaration.type)e.exports[n(t.declaration.id)]="function";else if("VariableDeclaration"===t.declaration.type)for(const o of t.declaration.declarations)e.exports[n(o.id)]="variable";return l}function Se(e){if("iif"===e)throw new p;if("decode"===e)throw new p;if("when"===e)throw new p;if("defaultvalue"===e)throw new p}function ve(e,t){const l=n(t.id);let o;Se(l);let r=!1;void 0!==e.globalScope[l]?o=l:void 0!==e.globalScope._SymbolsMap[l]?o=e.globalScope._SymbolsMap[l]:e.undeclaredGlobalsInFunctions.has(l)?(o=e.undeclaredGlobalsInFunctions.get(l).manglename,e.globalScope._SymbolsMap[l]=o,e.mangleMap[l]=o,e.undeclaredGlobalsInFunctions.delete(l),r=!0):(o=Re(e),e.globalScope._SymbolsMap[l]=o,e.mangleMap[l]=o);const a={isAsync:e.isAsync,exports:e.exports,undeclaredGlobalsInFunctions:e.undeclaredGlobalsInFunctions,moduleFactory:e.moduleFactory,moduleFactoryMap:e.moduleFactoryMap,libraryResolver:e.libraryResolver,symbols:e.symbols,mangleMap:e.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:e.depthCounter,globalScope:e.globalScope};let s="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let i=0;i<t.params.length;i++){const l=n(t.params[i]);Se(l);const o=Re(e);a.localScope._SymbolsMap[l]=o,a.mangleMap[l]=o,s+="lscope['"+o+"']=arguments["+i.toString()+"];\n"}return!0===e.isAsync?(s+="return lang.__awaiter(this, void 0, void 0, function* () {\n",s+=he(a,t.body)+"\n return lastStatement; ",s+="}); }",s+=", runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"):(s+=he(a,t.body)+"\n return lastStatement; }, runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"),r?"gscope[lang.setAssig('"+o+"', runtimeCtx)]="+s:"gscope['"+o+"']="+s}function xe(e,n){const t=[];for(let l=0;l<n.declarations.length;l++)t.push(Me(e,n.declarations[l]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function Me(e,t){const l=null===t.init?null:ne(e,t.init),o=n(t.id);if(Se(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']="+l+"; ";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']="+l+"; ";const n=Re(e);return e.localScope._SymbolsMap[o]=n,e.mangleMap[o]=n,"lscope['"+n+"']="+l+"; "}if(void 0!==e.globalScope[o])return"gscope['"+o+"']="+l+"; ";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']="+l+"; ";if(e.undeclaredGlobalsInFunctions.has(o)){const n=e.undeclaredGlobalsInFunctions.get(o).manglename;return e.globalScope._SymbolsMap[o]=n,e.mangleMap[o]=n,e.undeclaredGlobalsInFunctions.delete(o),"gscope[lang.setAssig('"+n+"', runtimeCtx)]="+l+"; "}const r=Re(e);return e.globalScope._SymbolsMap[o]=r,e.mangleMap[o]=r,"gscope['"+r+"']="+l+"; "}function Fe(e,n){try{let t;return!0===n.computed?t=ne(e,n.property):(Se(n.property.name),t="'"+n.property.name+"'"),"lang.member("+ne(e,n.object)+","+t+")"}catch(t){throw t}}function $e(e,n){try{return"lang.unary("+ne(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function Ce(e,n){try{const t=[];for(let l=0;l<n.elements.length;l++)"Literal"===n.elements[l].type?t.push(ne(e,n.elements[l])):t.push("lang.aCheck("+ne(e,n.elements[l])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function Ie(e,n){try{const t=[];let l=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[l]?"lang.castString(lang.aCheck("+ne(e,n.expressions[l])+", 'TemplateLiteral'))":""),l++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function Ae(e,n){try{return"lang.binary("+ne(e,n.left)+","+ne(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function _e(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new u(null,c.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new u(null,c.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+ne(e,n.left)+") "+n.operator+" lang.logicalCheck("+ne(e,n.right)+"))";throw new u(null,c.LogicExpressionOrAnd,null)}catch(t){throw t}}function Oe(e,t){try{const l=n(t);if(Se(l),null!==e.localScope){if(void 0!==e.localScope[l])return"lscope['"+l+"']";if(void 0!==e.localScope._SymbolsMap[l])return"lscope['"+e.localScope._SymbolsMap[l]+"']"}if(void 0!==e.globalScope[l])return"gscope['"+l+"']";if(void 0!==e.globalScope._SymbolsMap[l])return"gscope['"+e.globalScope._SymbolsMap[l]+"']";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(l))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]";const n={manglename:Re(e),node:t};return e.undeclaredGlobalsInFunctions.set(l,n),"gscope[lang.chkAssig('"+n.manglename+"',runtimeCtx)]"}throw new u(null,c.InvalidIdentifier,t)}catch(l){throw l}}function ke(e,t){try{if("MemberExpression"===t.callee.type){let n;!0===t.callee.computed?n=ne(e,t.callee.property):(Se(t.callee.property.name),n="'"+t.callee.property.name+"'");let l="[";for(let o=0;o<t.arguments.length;o++)o>0&&(l+=", "),l+=ne(e,t.arguments[o]);return l+="]",e.isAsync?"(yield lang.callModuleFunction("+ne(e,t.callee.object)+","+l+","+n+",runtimeCtx))":"lang.callModuleFunction("+ne(e,t.callee.object)+","+l+","+n+",runtimeCtx)"}if("Identifier"!==t.callee.type)throw new u(null,c.FunctionNotFound,t);const l=n(t.callee);if("iif"===l)return Ge(e,t);if("when"===l)return je(e,t);if("defaultvalue"===l)return Ee(e,t);if("decode"===l)return Be(e,t);let o="";if(null!==e.localScope&&(void 0!==e.localScope[l]?o="lscope['"+l+"']":void 0!==e.localScope._SymbolsMap[l]&&(o="lscope['"+e.localScope._SymbolsMap[l]+"']")),""===o)if(void 0!==e.globalScope[l])o="gscope['"+l+"']";else if(void 0!==e.globalScope._SymbolsMap[l])o="gscope['"+e.globalScope._SymbolsMap[l]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(l))o="gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]";else{const n={manglename:Re(e),node:t.callee};e.undeclaredGlobalsInFunctions.set(l,n),o="gscope[lang.chkAssig('"+n.manglename+"',runtimeCtx)]"}if(""!==o){let n="[";for(let l=0;l<t.arguments.length;l++)l>0&&(n+=", "),n+=ne(e,t.arguments[l]);return n+="]",e.isAsync?"(yield lang.callfunc("+o+","+n+",runtimeCtx) )":"lang.callfunc("+o+","+n+",runtimeCtx)"}throw new u(null,c.FunctionNotFound,t)}catch(l){throw l}}function Ge(e,n){try{if(3!==n.arguments.length)throw new u(null,c.WrongNumberOfParameters,n);const t=De(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ne(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${ne(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${ne(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ee(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new u(null,c.WrongNumberOfParameters,n);const t=De(e),l=De(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ne(e,n.arguments[0])};\n var ${l} = ${ne(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${l});\n return ${t} != null && ${t} !== "" ? ${t} : ${ne(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} = ${ne(e,n.arguments[0])};\n if (${t} === null) {\n return ${ne(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${ne(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${ne(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function je(e,n){try{if(n.arguments.length<3)throw new u(null,c.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new u(null,c.WrongNumberOfParameters,n);const t=De(e);let l="var ";for(let o=0;o<n.arguments.length-1;o+=2)l+=`${t} = lang.mustBoolean(${ne(e,n.arguments[o])}, runtimeCtx);\n if (${t} === true ) {\n return ${ne(e,n.arguments[o+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${l}\n return ${ne(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Be(e,n){try{if(n.arguments.length<2)throw new u(null,c.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${ne(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new u(null,c.WrongNumberOfParameters,n);const t=De(e),l=De(e);let o="var ";for(let r=1;r<n.arguments.length-1;r+=2)o+=`${l} = ${ne(e,n.arguments[r])};\n if (lang.binary(${l}, ${t}, "==") === true ) {\n return ${ne(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${ne(e,n.arguments[0])};\n ${o}\n return ${ne(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const Ne={};function Re(e){return e.symbols.symbolCounter++,`_T${e.symbols.symbolCounter}`}function De(e){return e.symbols.symbolCounter++,`_Tvar${e.symbols.symbolCounter}`}R(Ne,ee),W(Ne,ee),D(Ne,ee,Ze),K(Ne,ee),L(Ne,ee),P(Ne,ee),Ne.iif=function(e,n){try{return ee(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}},Ne.decode=function(e,n){try{return ee(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}},Ne.when=function(e,n){try{return ee(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}},Ne.defaultvalue=function(e,n){try{return ee(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}};const Le={};for(const en in Ne)Le[en]=new g(Ne[en]);U(Ne,ee);for(const en in Ne)Ne[en]=new g(Ne[en]);const Ue=function(){};Ue.prototype=Ne;const Ke=function(){};function Pe(e,n,t){const l={_SymbolsMap:{}};e||(e={}),t||(t={}),l.textformatting=1,l.infinity=1,l.pi=1;for(const o in n)l[o]=1;for(const o in t)l[o]=1;for(const o in e)l[o]=1;return l}function We(e,n,t,l){const o=t?new Ke:new Ue;e||(e={}),n||(n={});const r=new s({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});r.immutable=!1,o._SymbolsMap={textformatting:1,infinity:1,pi:1},o.textformatting=r,o.infinity=Number.POSITIVE_INFINITY,o.pi=Math.PI;for(const a in n)o[a]=n[a],o._SymbolsMap[a]=1;for(const a in e){const n=e[a];o._SymbolsMap[a]=1,Z(n)?o[a]=m.createFromGraphic(n,l??null):o[a]=n}return o}Ke.prototype=Le;const Ve={fixSpatialReference:b,parseArguments:X,standardFunction:ee};function qe(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:ee,standardFunctionAsync:ee,evaluateIdentifier:Ze};for(let l=0;l<e.length;l++)e[l].registerFunctions(t);if("sync"===n){for(const e in t.functions)Ne[e]=new g(t.functions[e]),Ue.prototype[e]=Ne[e];for(let e=0;e<t.signatures.length;e++)B(t.signatures[e],"sync")}else{for(const e in t.functions)Le[e]=new g(t.functions[e]),Ke.prototype[e]=Le[e];for(let e=0;e<t.signatures.length;e++)B(t.signatures[e],"async")}}function Te(e,n){return e(n)}function Ze(e,n){const t=n.name;if("_SymbolsMap"===t)throw new i(e,c.InvalidIdentifier,null);if(e.localStack.length>0){const n=e.localStack[e.localStack.length-1];if(!t.toLowerCase().startsWith("_t")&&void 0!==n[t])return n[t];const l=e.mangleMap[t];if(void 0!==l&&void 0!==n[l])return n[l]}if(!t.toLowerCase().startsWith("_t")&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const l=e.mangleMap[t];return void 0!==l?e.globalScope[l]:void 0}qe([N],"sync"),qe([N],"async");const ze={isNumber:e=>z(e),isArray:e=>J(e),isImmutableArray:e=>$(e),isDictionaryLike:e=>C(e),isString:e=>Y(e),isDictionary:e=>I(e),isGeometry:e=>A(e),getGeometryKeys:e=>o(e),geometryMember:(e,n,t,l,o=1)=>r(e,n,t,l,o),error(e){throw new i(null,e,null)},__awaiter(e,n,t,l){const o=l.apply(e,n||[]);let r=o.next();for(;!r.done&&!V(r.value);)r=o.next(r.value);return r.done?r.value:new Promise(((e,n)=>{function t(l){for(;!l.done;){if(V(l.value))return void Promise.resolve(l.value).then((e=>{try{t(o.next(e))}catch(l){n(l)}}),(e=>{try{t(o.throw(e))}catch(l){n(l)}}));try{l=o.next(l.value)}catch(r){return void n(r)}}e(l.value)}t(r)}))},functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new i(null,c.MaximumCallDepth,null);const t=e.apply(this,arguments);return V(t)?t.then((e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e))):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new i(n,c.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new i(n,c.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>_(e),aCheck(e,n){if(y(e)){if("ArrayExpression"===n)throw new i(null,c.NoFunctionInArray,null);if("ObjectExpression"===n)throw new i(null,c.NoFunctionInDictionary,null);throw new i(null,c.NoFunctionInTemplateLiteral,null)}return e===x?null:e},Dictionary:s,Feature:m,UserDefinedCompiledFunction:Q,dictionary(e){const n={},t=new Map;for(let o=0;o<e.length;o+=2){if(y(e[o+1]))throw new i(null,c.NoFunctionInDictionary,null);if(!1===Y(e[o]))throw new i(null,c.KeyMustBeString,null);let l=e[o].toString();const r=l.toLowerCase();t.has(r)?l=t.get(r):t.set(r,l),e[o+1]===x?n[l]=null:n[l]=e[o+1]}const l=new s(n);return l.immutable=!1,l},entry:(e,n)=>new s({key:e,value:n}),strCheck(e){if(!1===Y(e))throw new i(null,c.KeyMustBeString,null);return e},unary(e,n){if(H(e)){if("!"===n)return!e;if("-"===n)return-1*O(e);if("+"===n)return 1*O(e);if("~"===n)return~O(e);throw new i(null,c.UnsupportedUnaryOperator,null)}if("-"===n)return-1*O(e);if("+"===n)return 1*O(e);if("~"===n)return~O(e);throw new i(null,c.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===H(e))throw new i(null,c.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(H(e)&&H(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new i(null,c.LogicExpressionOrAnd,null)}throw new i(null,c.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return E(O(e),O(n),t);case"==":case"=":return G(e,n);case"!=":return!G(e,n);case"<":case">":case"<=":case">=":return k(e,n,t);case"+":return Y(e)||Y(n)?_(e)+_(n):O(e)+O(n);case"-":return O(e)-O(n);case"*":return O(e)*O(n);case"/":return O(e)/O(n);case"%":return O(e)%O(n);default:throw new i(null,c.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===x?null:e;case"/=":return O(t)/O(e);case"*=":return O(t)*O(e);case"-=":return O(t)-O(e);case"+=":return Y(t)||Y(e)?_(t)+_(e):O(t)+O(e);case"%=":return O(t)%O(e);default:throw new i(null,c.UnsupportedOperator,null)}},update(e,n,t,l){const o=O(e[n]);return e[n]="++"===t?o+1:o-1,!1===l?o:"++"===t?o+1:o-1},graphicToFeature:(e,n,t)=>null===e?null:m.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,l){let o;if(J(e)){if(!z(n))throw new i(null,c.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new i(null,c.OutOfBounds,null);o=O(e[n]),e[n]="++"===t?o+1:o-1}else if(e instanceof s){if(!1===Y(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new i(null,c.FieldNotFound,null,{key:n});o=O(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else if(j(e)){if(!1===Y(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new i(null,c.FieldNotFound,null);o=O(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else{if($(e))throw new i(null,c.Immutable,null);if(!(e instanceof Qe))throw new i(null,c.InvalidIdentifier,null);if(!1===Y(n))throw new i(null,c.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new i(null,c.ModuleExportNotFound,null);o=O(e.global(n)),e.setGlobal(n,"++"===t?o+1:o-1)}return!1===l?o:"++"===t?o+1:o-1},assignmember(e,n,t,l){if(J(e)){if(!z(n))throw new i(null,c.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new i(null,c.OutOfBounds,null);if(n===e.length){if("="!==t)throw new i(null,c.OutOfBounds,null);e[n]=this.assign(l,t,e[n])}else e[n]=this.assign(l,t,e[n])}else if(e instanceof s){if(!1===Y(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(l,t,e.field(n)));else{if("="!==t)throw new i(null,c.FieldNotFound,null);e.setField(n,this.assign(l,t,null))}}else if(j(e)){if(!1===Y(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(l,t,e.field(n)));else{if("="!==t)throw new i(null,c.FieldNotFound,null);e.setField(n,this.assign(l,t,null))}}else{if($(e))throw new i(null,c.Immutable,null);if(!(e instanceof Qe))throw new i(null,c.InvalidIdentifier,null);if(!1===Y(n))throw new i(null,c.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new i(null,c.ModuleExportNotFound,null);e.setGlobal(n,this.assign(l,t,e.global(n)))}},member(e,n){if(null===e)throw new i(null,c.MemberOfNull,null);if(e instanceof s||C(e)){if(Y(n))return e.field(n);throw new i(null,c.InvalidMemberAccessKey,null)}if(e instanceof q){if(Y(n))return r(e,n,null,null);throw new i(null,c.InvalidMemberAccessKey,null)}if(J(e)){if(z(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new i(null,c.OutOfBounds,null);return e[n]}throw new i(null,c.InvalidMemberAccessKey,null)}if(Y(e)){if(z(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new i(null,c.OutOfBounds,null);return e[n]}throw new i(null,c.InvalidMemberAccessKey,null)}if($(e)){if(z(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new i(null,c.OutOfBounds,null);return e.get(n)}throw new i(null,c.InvalidMemberAccessKey,null)}if(e instanceof Qe){if(Y(n))return e.global(n);throw new i(null,c.InvalidMemberAccessKey,null)}throw new i(null,c.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 l=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]=l,l},callModuleFunction(e,n,t,l){if(!(e instanceof Qe))throw new i(null,c.FunctionNotFound,null);const o=e.global(t);if(!1===y(o))throw new i(null,c.CallNonFunction,null);return o.call(l,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>a(e,n)};function Je(e){console.log(e)}function Ye(n,t,o=!1){null==t&&(t={vars:{},customfunctions:{}});let r=null;n.usesModules&&(r=new l(null,n.loadedModules));const a={isAsync:o,globalScope:Pe(t.vars,o?Le:Ne,t.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,libraryResolver:r,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},symbols:{symbolCounter:0}};let s=he(a,n);""===s&&(s="lc.voidOperation; "),a.undeclaredGlobalsInFunctions.size>0&&a.undeclaredGlobalsInFunctions.forEach((e=>{throw new u(null,c.InvalidIdentifier,e.node)}));let p="";p=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+s+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+s+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const m=a.moduleFactory,g=a.moduleFactoryMap,d=a.exports,f={};let h;for(h in d)f[h]=a.mangleMap[h]??h;const b={lc:w,lang:ze,mangles:a.mangleMap,postProcess(e){if(e instanceof S&&(e=e.value),e instanceof v&&(e=e.value),e===x&&(e=null),e===M)throw new i(null,c.IllegalResult,null);if(e===F)throw new i(null,c.IllegalResult,null);if(y(e))throw new i(null,c.IllegalResult,null);return e},prepare(n,t){const l=n.spatialReference??T.WebMercator,o=We(n.vars,n.customfunctions,t,n.timeZone);return{localStack:[],moduleFactory:m,moduleFactoryMap:g,mangleMap:this.mangles,moduleSingletons:{},exports:d,gdefs:{},exportmangle:f,spatialReference:l,globalScope:o,abortSignal:n.abortSignal??e,services:n.services,console:n.console??Je,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,depthCounter:{depth:1}}}};return new Function("context",p).bind(b)}async function He(){return qe([await import("./functions/geomasync.js")],"async"),!0}class Qe extends t{constructor(e){super(),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,l=e.toLowerCase();if(y(n))throw new i(null,c.AssignModuleFunction,null);t[this.moduleContext.exportmangle[l]]=n}global(e){const n=this.moduleContext.globalScope,t=e.toLowerCase(),l=n[this.moduleContext.exportmangle[t]];if(void 0===l)throw new i(null,c.InvalidIdentifier,null);if(y(l)&&!(l instanceof f)){const e=new f;return e.fn=l,e.parameterEvaluator=ee,e.context=this.moduleContext,n[this.moduleContext.exportmangle[t]]=e,e}return l}}function Xe(n,t,o){const r={isAsync:o,moduleFactory:t.moduleFactory,moduleFactoryMap:{},libraryResolver:new l(null,n.loadedModules),globalScope:Pe(null,o?Le:Ne,null),localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},symbols:{symbolCounter:0}};let a=he(r,n);""===a&&(a="lc.voidOperation; ");let s="";s=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+a+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+a+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const i=r.moduleFactory,c=r.moduleFactoryMap,u=r.exports,p={};let m;for(m in u)p[m]=r.mangleMap[m]??m;const g={lc:w,lang:ze,mangles:r.mangleMap,prepareModule:e=>new Qe(e),prepare(n,t){const l=n.spatialReference??T.WebMercator,o=We(null,null,t,n.timeZone);return{localStack:[],exports:u,exportmangle:p,gdefs:{},moduleFactory:i,moduleFactoryMap:c,moduleSingletons:n.moduleSingletons,mangleMap:this.mangles,spatialReference:l,globalScope:o,abortSignal:n.abortSignal??e,services:n.services,console:n.console??Je,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,depthCounter:n.depthCounter}}};return new Function("context",s).bind(g)}export{Q as UserDefinedCompiledFunction,Ye as compileScript,He as enableAsyncSupport,Te as executeScript,qe as extend,Ve as functionHelper};
5
+ import{neverAbortedSignal as e,toSymbolId as n}from"./arcadeEnvironment.js";import{ArcadeModule as t}from"./ArcadeModule.js";import{ArcadeModuleLoader as l}from"./ArcadeModuleLoader.js";import{getGeometryKeys as o,geometryMember as r,getNestedOptionalValue as a}from"./containerUtils.js";import s from"./Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as c,ArcadeCompilationError as u,ArcadeUncompilableError as p}from"./executionError.js";import m from"./Feature.js";import{NativeFunction as g,ArcadeFunction as d,ScopeMarshalledFunction as f,wrapModuleScopedResponse as h}from"./FunctionWrapper.js";import{i as y,u as b,v as w,R as S,I as v,w as x,x as M,y as F,m as $,z as C,q as I,l as A,f as _,t as O,A as k,B as G,C as E,n as j}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as N}from"../chunks/aiServices.js";import{A as R}from"../chunks/array.js";import{registerFunctions as D}from"./functions/date.js";import{registerFunctions as L}from"./functions/feature.js";import{registerFunctions as U}from"./functions/geometry.js";import{registerFunctions as K}from"./functions/geomsync.js";import{registerFunctions as P}from"./functions/maths.js";import{registerFunctions as W}from"./functions/stats.js";import{registerFunctions as V}from"./functions/string.js";import{isPromiseLike as q}from"../core/promiseUtils.js";import T from"../geometry/Geometry.js";import Z from"../geometry/SpatialReference.js";import{isGraphic as z,isNumber as J,isArray as Y,isString as H,isBoolean as Q}from"../support/guards.js";class X extends d{constructor(e,n){super(),this.paramCount=n,this.fn=e}createFunction(e){return(...n)=>{if(n.length!==this.paramCount)throw new i(e,c.WrongNumberOfParameters,null);return this.fn(...n)}}call(e,n){return this.fn(...n.arguments)}marshalledCall(e,n,t,l){return l(e,n,((n,o,r)=>{r=r.map((n=>!y(n)||n instanceof f?n:h(n,e,l)));const a=this.call(t,{arguments:r});return q(a)?a.then((e=>h(e,t,l))):a}))}}function ee(e,n){const t=[];for(let l=0;l<n.arguments.length;l++)t.push(te(e,n.arguments[l]));return t}function ne(e,n,t){try{return t(e,null,n.arguments)}catch(l){throw l}}function te(e,n){switch(n.type){case"AssignmentExpression":return ge(e,n);case"UpdateExpression":return pe(e,n);case"TemplateLiteral":return Ae(e,n);case"Identifier":return ke(e,n);case"MemberExpression":return $e(e,n);case"Literal":return null===n.value||void 0===n.value?"null":JSON.stringify(n.value);case"CallExpression":return Ge(e,n);case"UnaryExpression":return Ce(e,n);case"BinaryExpression":return _e(e,n);case"LogicalExpression":return Oe(e,n);case"ArrayExpression":return Ie(e,n);case"ObjectExpression":return oe(e,n);default:throw new u(null,c.Unrecognized,n)}}function le(e,n){switch(n.type){case"EmptyStatement":return"lc.voidOperation";case"VariableDeclaration":return Me(e,n);case"BlockStatement":return ye(e,n);case"FunctionDeclaration":return xe(e,n);case"ImportDeclaration":return we(e,n);case"ExportNamedDeclaration":return Se(e,n);case"ReturnStatement":return be(e,n);case"IfStatement":return he(e,n);case"ExpressionStatement":return de(e,n);case"BreakStatement":return"break";case"ContinueStatement":return"continue";case"ForStatement":return ue(e,n);case"ForInStatement":return ie(e,n);case"ForOfStatement":return ce(e,n);case"WhileStatement":return me(e,n);default:throw new u(null,c.Unrecognized,n)}}function oe(e,n){let t="lang.dictionary([";for(let l=0;l<n.properties.length;l++){const o=n.properties[l];let r;"Identifier"===o.key.type?(ve(o.key.name),r="'"+o.key.name+"'"):r=te(e,o.key);l>0&&(t+=","),t+="lang.strCheck("+r+",'ObjectExpression'),lang.aCheck("+te(e,o.value)+", 'ObjectExpression')"}return t+="])",t}function re(e,n,t,l,o=(e,n)=>`${e} = ${n}`){const r=Le(e),a=Le(e);return[`var ${r} = ${t};`,`for (var ${a} = 0; ${a} < ${r}; ${a}++) {`,` ${o(n,a)}`,` ${le(e,l)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function ae(e,n,t,l,o=e=>e){const r=Le(e),a=Le(e);return[`var ${r} = ${t};`,`for (var ${a} of ${r}) {`,` ${n} = ${o(a)};`,` ${le(e,l)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function se(e,n,t,l){const o=Le(e);return[`var ${o} = ${t}.iterator(runtimeCtx.abortSignal);`,`while ((${n} = lang.graphicToFeature(yield ${o}.next(), ${t}, runtimeCtx)) != null) {`,` ${le(e,l)}`,"}","lastStatement = lc.voidOperation;"].join("\n")}function ie(e,t){const l=Le(e);let o="var "+l+" = "+te(e,t.right)+";\n";"VariableDeclaration"===t.left.type&&(o+=le(e,t.left));const r=n("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);ve(r);let a="";null!==e.localScope&&(void 0!==e.localScope[r]?a="lscope['"+r+"']":void 0!==e.localScope._SymbolsMap[r]&&(a="lscope['"+e.localScope._SymbolsMap[r]+"']"));let s="";if(""===a)if(void 0!==e.globalScope[r])a="gscope['"+r+"']";else if(void 0!==e.globalScope._SymbolsMap[r])a="gscope['"+e.globalScope._SymbolsMap[r]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(r))a="gscope['"+e.undeclaredGlobalsInFunctions.get(r).manglename+"']",s=e.undeclaredGlobalsInFunctions.get(r).manglename;else{const n={manglename:De(e),node:t.left};e.undeclaredGlobalsInFunctions.set(r,n),a="gscope['"+n.manglename+"']",s=n.manglename}return s&&(o+="lang.chkAssig('"+s+"',runtimeCtx); \n"),o+="if ("+l+"===null) { lastStatement = lc.voidOperation; }\n ",o+="else if (lc.isArray("+l+") || lc.isString("+l+")) {\n",o+=re(e,a,`${l}.length`,t.body),o+="}\n",o+="else if (lc.isImmutableArray("+l+")) {\n",o+=re(e,a,`${l}.length()`,t.body),o+="}\n",o+="else if (( "+l+" instanceof lang.Dictionary) || lc.isDictionaryLike("+l+")) {\n",o+=ae(e,a,`${l}.keys()`,t.body),o+="}\n",e.isAsync&&(o+="else if (lc.isFeatureSet("+l+")) {\n",o+=se(e,a,l,t.body),o+="}\n"),o+=`else if (lc.isGeometry(${l})) {\n`,o+=ae(e,a,`lang.getGeometryKeys(${l})`,t.body),o+="}\n",o+="else { lastStatement = lc.voidOperation; } \n",o}function ce(e,t){const l=Le(e);let o="var "+l+" = "+te(e,t.right)+";\n";"VariableDeclaration"===t.left.type&&(o+=le(e,t.left));const r=n("VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);ve(r);let a="";null!==e.localScope&&(void 0!==e.localScope[r]?a="lscope['"+r+"']":void 0!==e.localScope._SymbolsMap[r]&&(a="lscope['"+e.localScope._SymbolsMap[r]+"']"));let s="";if(""===a)if(void 0!==e.globalScope[r])a="gscope['"+r+"']";else if(void 0!==e.globalScope._SymbolsMap[r])a="gscope['"+e.globalScope._SymbolsMap[r]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(r))a="gscope['"+e.undeclaredGlobalsInFunctions.get(r).manglename+"']",s=e.undeclaredGlobalsInFunctions.get(r).manglename;else{const n={manglename:De(e),node:t.left};e.undeclaredGlobalsInFunctions.set(r,n),a="gscope['"+n.manglename+"']",s=n.manglename}return s&&(o+="lang.chkAssig('"+s+"',runtimeCtx); \n"),o+="if ("+l+"===null) { lastStatement = lc.voidOperation; }\n ",o+="else if (lc.isArray("+l+") || lc.isString("+l+")) {\n",o+=re(e,a,`${l}.length`,t.body,((e,n)=>[`if (${n} >= ${l}.length) {`,` lang.error('${c.OutOfBounds}');`,"}",`${e} = ${l}[${n}];`].join("\n"))),o+="}\n",o+="else if (lc.isImmutableArray("+l+")) {\n",o+=re(e,a,`${l}.length()`,t.body,((e,n)=>`${e} = ${l}.get(${n});`)),o+="}\n",o+="else if (( "+l+" instanceof lang.Dictionary) || lc.isDictionaryLike("+l+")) {\n",o+=ae(e,a,`${l}.keys()`,t.body,(e=>`lang.entry(${e}, ${l}.field(${e}))`)),o+="}\n",e.isAsync&&(o+="else if (lc.isFeatureSet("+l+")) {\n",o+=se(e,a,l,t.body),o+="}\n"),o+=`else if (lc.isGeometry(${l})) {\n`,o+=ae(e,a,`lang.getGeometryKeys(${l})`,t.body,(e=>`lang.entry(${e}, lang.geometryMember(${l}, ${e}, runtimeCtx, null, 1))`)),o+="}\n",o+="else { lastStatement = lc.voidOperation; } \n",o}function ue(e,n){let t="lastStatement = lc.voidOperation; \n";null!==n.init&&("VariableDeclaration"===n.init.type?t+=le(e,n.init):t+=te(e,n.init)+"; ");const l=Le(e),o=Le(e);return t+="var "+l+" = true; ",t+="\n do { ",null!==n.update&&(t+=" if ("+l+"===false) {\n "+te(e,n.update)+" \n}\n "+l+"=false; \n"),null!==n.test&&(t+="var "+o+" = "+te(e,n.test)+"; ",t+="if ("+o+"===false) { break; } else if ("+o+"!==true) { lang.error('"+c.BooleanConditionRequired+"'); }\n"),t+=le(e,n.body),null!==n.update&&(t+="\n "+te(e,n.update)),t+="\n"+l+" = true; \n} while(true); lastStatement = lc.voidOperation; ",t}function pe(e,t){if("CallExpression"===t.argument.type)throw new u(null,c.NeverReach,t);let l;if("MemberExpression"===t.argument.type){const n=te(e,t.argument.object);return!0===t.argument.computed?l=te(e,t.argument.property):(ve(t.argument.property.name),l="'"+t.argument.property.name+"'"),"lang.memberupdate("+n+","+l+",'"+t.operator+"',"+t.prefix+")"}const o=n(t.argument);if(ve(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lang.update(lscope, '"+o+"','"+t.operator+"',"+t.prefix+")";if(void 0!==e.localScope._SymbolsMap[o])return"lang.update(lscope, '"+e.localScope._SymbolsMap[o]+"','"+t.operator+"',"+t.prefix+")"}if(void 0!==e.globalScope[o])return"lang.update(gscope, '"+o+"','"+t.operator+"',"+t.prefix+")";if(void 0!==e.globalScope._SymbolsMap[o])return"lang.update(gscope, '"+e.globalScope._SymbolsMap[o]+"','"+t.operator+"',"+t.prefix+")";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"lang.update(gscope,lang.chkAssig( '"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")";const n={manglename:De(e),node:t.argument};return e.undeclaredGlobalsInFunctions.set(o,n),"lang.update(gscope, lang.chkAssig('"+n.manglename+"',runtimeCtx),'"+t.operator+"',"+t.prefix+")"}throw new u(null,c.InvalidIdentifier,t)}function me(e,n){let t="lastStatement = lc.voidOperation; \n";const l=Le(e);return t+=`\n var ${l} = true;\n do {\n ${l} = ${te(e,n.test)};\n if (${l}==false) {\n break;\n }\n if (${l}!==true) {\n lang.error('${c.BooleanConditionRequired}');\n }\n ${le(e,n.body)}\n }\n while (${l} !== false);\n lastStatement = lc.voidOperation;\n `,t}function ge(e,t){const l=te(e,t.right);if("MemberExpression"===t.left.type){let n;const o=te(e,t.left.object);return!0===t.left.computed?n=te(e,t.left.property):(n="'"+t.left.property.name+"'",ve(t.left.property.name)),"lang.assignmember("+o+","+n+",'"+t.operator+"',"+l+")"}const o=n(t.left);if(ve(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']=lang.assign("+l+",'"+t.operator+"', lscope['"+o+"'])";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']=lang.assign("+l+",'"+t.operator+"', lscope['"+e.localScope._SymbolsMap[o]+"'])"}if(void 0!==e.globalScope[o])return"gscope['"+o+"']=lang.assign("+l+",'"+t.operator+"', gscope['"+o+"'])";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']=lang.assign("+l+",'"+t.operator+"', gscope['"+e.globalScope._SymbolsMap[o]+"'])";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(o))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(o).manglename+"',runtimeCtx)]=lang.assign("+l+",'"+t.operator+"', gscope['"+e.undeclaredGlobalsInFunctions.get(o).manglename+"'])";const n={manglename:De(e),node:t.left};return e.undeclaredGlobalsInFunctions.set(o,n),"gscope[lang.chkAssig('"+n.manglename+"',runtimeCtx)]=lang.assign("+l+",'"+t.operator+"', gscope['"+n.manglename+"'])"}throw new u(null,c.InvalidIdentifier,t)}function de(e,n){return"AssignmentExpression"===n.expression.type?"lastStatement = lc.voidOperation; "+te(e,n.expression)+"; \n ":"lastStatement = "+te(e,n.expression)+"; "}function fe(e,n){return"BlockStatement"===n.type?le(e,n):"ReturnStatement"===n.type||"BreakStatement"===n.type||"ContinueStatement"===n.type?le(e,n)+"; ":"ExpressionStatement"===n.type?le(e,n):le(e,n)+"; "}function he(e,n){return`if (lang.mustBoolean(${te(e,n.test)}, runtimeCtx) === true) {\n ${fe(e,n.consequent)}\n } `+(null!==n.alternate?"IfStatement"===n.alternate.type?" else "+he(e,n.alternate):` else {\n ${fe(e,n.alternate)}\n }\n`:" else {\n lastStatement = lc.voidOperation;\n }\n")}function ye(e,n){let t="";for(let l=0;l<n.body.length;l++)"EmptyStatement"!==n.body[l].type&&("ReturnStatement"===n.body[l].type||"BreakStatement"===n.body[l].type||"ContinueStatement"===n.body[l].type?t+=le(e,n.body[l])+"; \n":t+=le(e,n.body[l])+" \n");return t}function be(e,n){if(null===n.argument)return"return lc.voidOperation";return"return "+te(e,n.argument)}function we(e,t){const l=n(t.specifiers[0].local);ve(l);const o=e.libraryResolver?.loadLibrary(l),r=De(e);void 0===e.moduleFactory[o.uri]&&(e.moduleFactory[o.uri]=en(o.syntax,{moduleFactory:e.moduleFactory,libraryResolver:e.libraryResolver},e.isAsync)),e.moduleFactoryMap[r]=o.uri;let a,s="";return s=e.isAsync?"(yield lang.loadModule('"+r+"', runtimeCtx) ); ":"lang.loadModule('"+r+"', runtimeCtx); ",void 0!==e.globalScope[l]?"gscope['"+l+"']="+s:void 0!==e.globalScope._SymbolsMap[l]?"gscope['"+e.globalScope._SymbolsMap[l]+"']="+s:(e.undeclaredGlobalsInFunctions.has(l)?(a=e.undeclaredGlobalsInFunctions.get(l).manglename,e.undeclaredGlobalsInFunctions.delete(l)):a=De(e),e.globalScope._SymbolsMap[l]=a,e.mangleMap[l]=a,"gscope[lang.setAssig('"+a+"', runtimeCtx)]="+s)}function Se(e,t){const l=le(e,t.declaration);if("FunctionDeclaration"===t.declaration.type)e.exports[n(t.declaration.id)]="function";else if("VariableDeclaration"===t.declaration.type)for(const o of t.declaration.declarations)e.exports[n(o.id)]="variable";return l}function ve(e){if("iif"===e)throw new p;if("decode"===e)throw new p;if("when"===e)throw new p;if("defaultvalue"===e)throw new p}function xe(e,t){const l=n(t.id);let o;ve(l);let r=!1;void 0!==e.globalScope[l]?o=l:void 0!==e.globalScope._SymbolsMap[l]?o=e.globalScope._SymbolsMap[l]:e.undeclaredGlobalsInFunctions.has(l)?(o=e.undeclaredGlobalsInFunctions.get(l).manglename,e.globalScope._SymbolsMap[l]=o,e.mangleMap[l]=o,e.undeclaredGlobalsInFunctions.delete(l),r=!0):(o=De(e),e.globalScope._SymbolsMap[l]=o,e.mangleMap[l]=o);const a={isAsync:e.isAsync,exports:e.exports,undeclaredGlobalsInFunctions:e.undeclaredGlobalsInFunctions,moduleFactory:e.moduleFactory,moduleFactoryMap:e.moduleFactoryMap,libraryResolver:e.libraryResolver,symbols:e.symbols,mangleMap:e.mangleMap,localScope:{_SymbolsMap:{}},depthCounter:e.depthCounter,globalScope:e.globalScope};let s="new lang.UserDefinedCompiledFunction( lang.functionDepthchecker(function() { var lastStatement = lc.voidOperation; \n var lscope = runtimeCtx.localStack[runtimeCtx.localStack.length-1];\n";for(let i=0;i<t.params.length;i++){const l=n(t.params[i]);ve(l);const o=De(e);a.localScope._SymbolsMap[l]=o,a.mangleMap[l]=o,s+="lscope['"+o+"']=arguments["+i.toString()+"];\n"}return!0===e.isAsync?(s+="return lang.__awaiter(this, void 0, void 0, function* () {\n",s+=ye(a,t.body)+"\n return lastStatement; ",s+="}); }",s+=", runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"):(s+=ye(a,t.body)+"\n return lastStatement; }, runtimeCtx),"+t.params.length+")",s+="\n lastStatement = lc.voidOperation; \n"),r?"gscope[lang.setAssig('"+o+"', runtimeCtx)]="+s:"gscope['"+o+"']="+s}function Me(e,n){const t=[];for(let l=0;l<n.declarations.length;l++)t.push(Fe(e,n.declarations[l]));return t.join("\n")+" \n lastStatement= lc.voidOperation; \n"}function Fe(e,t){const l=null===t.init?null:te(e,t.init),o=n(t.id);if(ve(o),null!==e.localScope){if(void 0!==e.localScope[o])return"lscope['"+o+"']="+l+"; ";if(void 0!==e.localScope._SymbolsMap[o])return"lscope['"+e.localScope._SymbolsMap[o]+"']="+l+"; ";const n=De(e);return e.localScope._SymbolsMap[o]=n,e.mangleMap[o]=n,"lscope['"+n+"']="+l+"; "}if(void 0!==e.globalScope[o])return"gscope['"+o+"']="+l+"; ";if(void 0!==e.globalScope._SymbolsMap[o])return"gscope['"+e.globalScope._SymbolsMap[o]+"']="+l+"; ";if(e.undeclaredGlobalsInFunctions.has(o)){const n=e.undeclaredGlobalsInFunctions.get(o).manglename;return e.globalScope._SymbolsMap[o]=n,e.mangleMap[o]=n,e.undeclaredGlobalsInFunctions.delete(o),"gscope[lang.setAssig('"+n+"', runtimeCtx)]="+l+"; "}const r=De(e);return e.globalScope._SymbolsMap[o]=r,e.mangleMap[o]=r,"gscope['"+r+"']="+l+"; "}function $e(e,n){try{let t;return!0===n.computed?t=te(e,n.property):(ve(n.property.name),t="'"+n.property.name+"'"),"lang.member("+te(e,n.object)+","+t+")"}catch(t){throw t}}function Ce(e,n){try{return"lang.unary("+te(e,n.argument)+",'"+n.operator+"')"}catch(t){throw t}}function Ie(e,n){try{const t=[];for(let l=0;l<n.elements.length;l++)"Literal"===n.elements[l].type?t.push(te(e,n.elements[l])):t.push("lang.aCheck("+te(e,n.elements[l])+",'ArrayExpression')");return"["+t.join(",")+"]"}catch(t){throw t}}function Ae(e,n){try{const t=[];let l=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[l]?"lang.castString(lang.aCheck("+te(e,n.expressions[l])+", 'TemplateLiteral'))":""),l++);return"(["+t.join(",")+"]).join('')"}catch(t){throw t}}function _e(e,n){try{return"lang.binary("+te(e,n.left)+","+te(e,n.right)+",'"+n.operator+"')"}catch(t){throw t}}function Oe(e,n){try{if("AssignmentExpression"===n.left.type||"UpdateExpression"===n.left.type)throw new u(null,c.LogicalExpressionOnlyBoolean,n);if("AssignmentExpression"===n.right.type||"UpdateExpression"===n.right.type)throw new u(null,c.LogicalExpressionOnlyBoolean,n);if("&&"===n.operator||"||"===n.operator)return"(lang.logicalCheck("+te(e,n.left)+") "+n.operator+" lang.logicalCheck("+te(e,n.right)+"))";throw new u(null,c.LogicExpressionOrAnd,null)}catch(t){throw t}}function ke(e,t){try{const l=n(t);if(ve(l),null!==e.localScope){if(void 0!==e.localScope[l])return"lscope['"+l+"']";if(void 0!==e.localScope._SymbolsMap[l])return"lscope['"+e.localScope._SymbolsMap[l]+"']"}if(void 0!==e.globalScope[l])return"gscope['"+l+"']";if(void 0!==e.globalScope._SymbolsMap[l])return"gscope['"+e.globalScope._SymbolsMap[l]+"']";if(null!==e.localScope){if(e.undeclaredGlobalsInFunctions.has(l))return"gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]";const n={manglename:De(e),node:t};return e.undeclaredGlobalsInFunctions.set(l,n),"gscope[lang.chkAssig('"+n.manglename+"',runtimeCtx)]"}throw new u(null,c.InvalidIdentifier,t)}catch(l){throw l}}function Ge(e,t){try{if("MemberExpression"===t.callee.type){let n;!0===t.callee.computed?n=te(e,t.callee.property):(ve(t.callee.property.name),n="'"+t.callee.property.name+"'");let l="[";for(let o=0;o<t.arguments.length;o++)o>0&&(l+=", "),l+=te(e,t.arguments[o]);return l+="]",e.isAsync?"(yield lang.callModuleFunction("+te(e,t.callee.object)+","+l+","+n+",runtimeCtx))":"lang.callModuleFunction("+te(e,t.callee.object)+","+l+","+n+",runtimeCtx)"}if("Identifier"!==t.callee.type)throw new u(null,c.FunctionNotFound,t);const l=n(t.callee);if("iif"===l)return Ee(e,t);if("when"===l)return Be(e,t);if("defaultvalue"===l)return je(e,t);if("decode"===l)return Ne(e,t);let o="";if(null!==e.localScope&&(void 0!==e.localScope[l]?o="lscope['"+l+"']":void 0!==e.localScope._SymbolsMap[l]&&(o="lscope['"+e.localScope._SymbolsMap[l]+"']")),""===o)if(void 0!==e.globalScope[l])o="gscope['"+l+"']";else if(void 0!==e.globalScope._SymbolsMap[l])o="gscope['"+e.globalScope._SymbolsMap[l]+"']";else if(null!==e.localScope)if(e.undeclaredGlobalsInFunctions.has(l))o="gscope[lang.chkAssig('"+e.undeclaredGlobalsInFunctions.get(l).manglename+"',runtimeCtx)]";else{const n={manglename:De(e),node:t.callee};e.undeclaredGlobalsInFunctions.set(l,n),o="gscope[lang.chkAssig('"+n.manglename+"',runtimeCtx)]"}if(""!==o){let n="[";for(let l=0;l<t.arguments.length;l++)l>0&&(n+=", "),n+=te(e,t.arguments[l]);return n+="]",e.isAsync?"(yield lang.callfunc("+o+","+n+",runtimeCtx) )":"lang.callfunc("+o+","+n+",runtimeCtx)"}throw new u(null,c.FunctionNotFound,t)}catch(l){throw l}}function Ee(e,n){try{if(3!==n.arguments.length)throw new u(null,c.WrongNumberOfParameters,n);const t=Le(e);return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${te(e,n.arguments[0])};\n\n if (${t} === true) {\n return ${te(e,n.arguments[1])};\n }\n else if (${t} === false) {\n return ${te(e,n.arguments[2])};\n }\n else {\n lang.error('ExecutionErrorCodes.BooleanConditionRequired');\n }\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function je(e,n){try{if(n.arguments.length<2||n.arguments.length>3)throw new u(null,c.WrongNumberOfParameters,n);const t=Le(e),l=Le(e);return 3===n.arguments.length?`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${te(e,n.arguments[0])};\n var ${l} = ${te(e,n.arguments[1])};\n ${t} = lang.getNestedOptionalValue(${t}, ${l});\n return ${t} != null && ${t} !== "" ? ${t} : ${te(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} = ${te(e,n.arguments[0])};\n if (${t} === null) {\n return ${te(e,n.arguments[1])};\n }\n if (${t} === "") {\n return ${te(e,n.arguments[1])};\n }\n if (${t} === undefined) {\n return ${te(e,n.arguments[1])};\n }\n return ${t};\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Be(e,n){try{if(n.arguments.length<3)throw new u(null,c.WrongNumberOfParameters,n);if(n.arguments.length%2==0)throw new u(null,c.WrongNumberOfParameters,n);const t=Le(e);let l="var ";for(let o=0;o<n.arguments.length-1;o+=2)l+=`${t} = lang.mustBoolean(${te(e,n.arguments[o])}, runtimeCtx);\n if (${t} === true ) {\n return ${te(e,n.arguments[o+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n ${l}\n return ${te(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}function Ne(e,n){try{if(n.arguments.length<2)throw new u(null,c.WrongNumberOfParameters,n);if(2===n.arguments.length)return`(${te(e,n.arguments[1])})`;if((n.arguments.length-1)%2==0)throw new u(null,c.WrongNumberOfParameters,n);const t=Le(e),l=Le(e);let o="var ";for(let r=1;r<n.arguments.length-1;r+=2)o+=`${l} = ${te(e,n.arguments[r])};\n if (lang.binary(${l}, ${t}, "==") === true ) {\n return ${te(e,n.arguments[r+1])}\n }\n`;return`${e.isAsync?"(yield (function() { \n return lang.__awaiter(this, void 0, void 0, function* () {":"function() {"}\n var ${t} = ${te(e,n.arguments[0])};\n ${o}\n return ${te(e,n.arguments[n.arguments.length-1])}\n ${e.isAsync?"})}()))":"}()"}`}catch(t){throw t}}const Re={};function De(e){return e.symbols.symbolCounter++,`_T${e.symbols.symbolCounter}`}function Le(e){return e.symbols.symbolCounter++,`_Tvar${e.symbols.symbolCounter}`}D(Re,ne),V(Re,ne),L(Re,ne,ze),P(Re,ne),U(Re,ne),W(Re,ne),Re.iif=function(e,n){try{return ne(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}},Re.decode=function(e,n){try{return ne(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}},Re.when=function(e,n){try{return ne(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}},Re.defaultvalue=function(e,n){try{return ne(e,n,((t,l,o)=>{throw new i(e,c.Unrecognized,n)}))}catch(t){throw t}};const Ue={};for(const nn in Re)Ue[nn]=new g(Re[nn]);K(Re,ne);for(const nn in Re)Re[nn]=new g(Re[nn]);const Ke=function(){};Ke.prototype=Re;const Pe=function(){};function We(e,n,t){const l={_SymbolsMap:{}};e||(e={}),t||(t={}),l.textformatting=1,l.infinity=1,l.pi=1;for(const o in n)l[o]=1;for(const o in t)l[o]=1;for(const o in e)l[o]=1;return l}function Ve(e,n,t,l){const o=t?new Pe:new Ke;e||(e={}),n||(n={});const r=new s({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});r.immutable=!1,o._SymbolsMap={textformatting:1,infinity:1,pi:1},o.textformatting=r,o.infinity=Number.POSITIVE_INFINITY,o.pi=Math.PI;for(const a in n)o[a]=n[a],o._SymbolsMap[a]=1;for(const a in e){const n=e[a];o._SymbolsMap[a]=1,z(n)?o[a]=m.createFromGraphic(n,l??null):o[a]=n}return o}Pe.prototype=Ue;const qe={fixSpatialReference:b,parseArguments:ee,standardFunction:ne};function Te(e,n){const t={mode:n,compiled:!0,functions:{},signatures:[],standardFunction:ne,standardFunctionAsync:ne,evaluateIdentifier:ze};for(let l=0;l<e.length;l++)e[l].registerFunctions(t);if("sync"===n){for(const e in t.functions)Re[e]=new g(t.functions[e]),Ke.prototype[e]=Re[e];for(let e=0;e<t.signatures.length;e++)B(t.signatures[e],"sync")}else{for(const e in t.functions)Ue[e]=new g(t.functions[e]),Pe.prototype[e]=Ue[e];for(let e=0;e<t.signatures.length;e++)B(t.signatures[e],"async")}}function Ze(e,n){return e(n)}function ze(e,n){const t=n.name;if("_SymbolsMap"===t)throw new i(e,c.InvalidIdentifier,null);if(e.localStack.length>0){const n=e.localStack[e.localStack.length-1];if(!t.toLowerCase().startsWith("_t")&&void 0!==n[t])return n[t];const l=e.mangleMap[t];if(void 0!==l&&void 0!==n[l])return n[l]}if(!t.toLowerCase().startsWith("_t")&&void 0!==e.globalScope[t])return e.globalScope[t];if(1===e.globalScope._SymbolsMap[t])return e.globalScope[t];const l=e.mangleMap[t];return void 0!==l?e.globalScope[l]:void 0}Te([R],"sync"),Te([R],"async"),Te([N],"async");const Je={isNumber:e=>J(e),isArray:e=>Y(e),isImmutableArray:e=>$(e),isDictionaryLike:e=>C(e),isString:e=>H(e),isDictionary:e=>I(e),isGeometry:e=>A(e),getGeometryKeys:e=>o(e),geometryMember:(e,n,t,l,o=1)=>r(e,n,t,l,o),error(e){throw new i(null,e,null)},__awaiter(e,n,t,l){const o=l.apply(e,n||[]);let r=o.next();for(;!r.done&&!q(r.value);)r=o.next(r.value);return r.done?r.value:new Promise(((e,n)=>{function t(l){for(;!l.done;){if(q(l.value))return void Promise.resolve(l.value).then((e=>{try{t(o.next(e))}catch(l){n(l)}}),(e=>{try{t(o.throw(e))}catch(l){n(l)}}));try{l=o.next(l.value)}catch(r){return void n(r)}}e(l.value)}t(r)}))},functionDepthchecker:(e,n)=>function(){if(n.depthCounter.depth++,n.localStack.push({}),n.depthCounter.depth>64)throw new i(null,c.MaximumCallDepth,null);const t=e.apply(this,arguments);return q(t)?t.then((e=>(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,e))):(n.depthCounter.depth--,n.localStack.length=n.localStack.length-1,t)},chkAssig(e,n){if(void 0===n.gdefs[e])throw new i(n,c.InvalidIdentifier,null);return e},mustBoolean(e,n){if(!0===e||!1===e)return e;throw new i(n,c.BooleanConditionRequired,null)},setAssig:(e,n)=>(n.gdefs[e]=1,e),castString:e=>_(e),aCheck(e,n){if(y(e)){if("ArrayExpression"===n)throw new i(null,c.NoFunctionInArray,null);if("ObjectExpression"===n)throw new i(null,c.NoFunctionInDictionary,null);throw new i(null,c.NoFunctionInTemplateLiteral,null)}return e===x?null:e},Dictionary:s,Feature:m,UserDefinedCompiledFunction:X,dictionary(e){const n={},t=new Map;for(let o=0;o<e.length;o+=2){if(y(e[o+1]))throw new i(null,c.NoFunctionInDictionary,null);if(!1===H(e[o]))throw new i(null,c.KeyMustBeString,null);let l=e[o].toString();const r=l.toLowerCase();t.has(r)?l=t.get(r):t.set(r,l),e[o+1]===x?n[l]=null:n[l]=e[o+1]}const l=new s(n);return l.immutable=!1,l},entry:(e,n)=>new s({key:e,value:n}),strCheck(e){if(!1===H(e))throw new i(null,c.KeyMustBeString,null);return e},unary(e,n){if(Q(e)){if("!"===n)return!e;if("-"===n)return-1*O(e);if("+"===n)return 1*O(e);if("~"===n)return~O(e);throw new i(null,c.UnsupportedUnaryOperator,null)}if("-"===n)return-1*O(e);if("+"===n)return 1*O(e);if("~"===n)return~O(e);throw new i(null,c.UnsupportedUnaryOperator,null)},logicalCheck(e){if(!1===Q(e))throw new i(null,c.LogicExpressionOrAnd,null);return e},logical(e,n,t){if(Q(e)&&Q(n))switch(t){case"||":return e||n;case"&&":return e&&n;default:throw new i(null,c.LogicExpressionOrAnd,null)}throw new i(null,c.LogicExpressionOrAnd,null)},binary(e,n,t){switch(t){case"|":case"<<":case">>":case">>>":case"^":case"&":return E(O(e),O(n),t);case"==":case"=":return G(e,n);case"!=":return!G(e,n);case"<":case">":case"<=":case">=":return k(e,n,t);case"+":return H(e)||H(n)?_(e)+_(n):O(e)+O(n);case"-":return O(e)-O(n);case"*":return O(e)*O(n);case"/":return O(e)/O(n);case"%":return O(e)%O(n);default:throw new i(null,c.UnsupportedOperator,null)}},assign(e,n,t){switch(n){case"=":return e===x?null:e;case"/=":return O(t)/O(e);case"*=":return O(t)*O(e);case"-=":return O(t)-O(e);case"+=":return H(t)||H(e)?_(t)+_(e):O(t)+O(e);case"%=":return O(t)%O(e);default:throw new i(null,c.UnsupportedOperator,null)}},update(e,n,t,l){const o=O(e[n]);return e[n]="++"===t?o+1:o-1,!1===l?o:"++"===t?o+1:o-1},graphicToFeature:(e,n,t)=>null===e?null:m.createFromGraphicLikeObject(e.geometry,e.attributes,n,t.timeZone),memberupdate(e,n,t,l){let o;if(Y(e)){if(!J(n))throw new i(null,c.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>=e.length)throw new i(null,c.OutOfBounds,null);o=O(e[n]),e[n]="++"===t?o+1:o-1}else if(e instanceof s){if(!1===H(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new i(null,c.FieldNotFound,null,{key:n});o=O(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else if(j(e)){if(!1===H(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0!==e.hasField(n))throw new i(null,c.FieldNotFound,null);o=O(e.field(n)),e.setField(n,"++"===t?o+1:o-1)}else{if($(e))throw new i(null,c.Immutable,null);if(!(e instanceof Xe))throw new i(null,c.InvalidIdentifier,null);if(!1===H(n))throw new i(null,c.ModuleAccessorMustBeString,null);if(!0!==e.hasGlobal(n))throw new i(null,c.ModuleExportNotFound,null);o=O(e.global(n)),e.setGlobal(n,"++"===t?o+1:o-1)}return!1===l?o:"++"===t?o+1:o-1},assignmember(e,n,t,l){if(Y(e)){if(!J(n))throw new i(null,c.ArrayAccessorMustBeNumber,null);if(n<0&&(n=e.length+n),n<0||n>e.length)throw new i(null,c.OutOfBounds,null);if(n===e.length){if("="!==t)throw new i(null,c.OutOfBounds,null);e[n]=this.assign(l,t,e[n])}else e[n]=this.assign(l,t,e[n])}else if(e instanceof s){if(!1===H(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(l,t,e.field(n)));else{if("="!==t)throw new i(null,c.FieldNotFound,null);e.setField(n,this.assign(l,t,null))}}else if(j(e)){if(!1===H(n))throw new i(null,c.KeyAccessorMustBeString,null);if(!0===e.hasField(n))e.setField(n,this.assign(l,t,e.field(n)));else{if("="!==t)throw new i(null,c.FieldNotFound,null);e.setField(n,this.assign(l,t,null))}}else{if($(e))throw new i(null,c.Immutable,null);if(!(e instanceof Xe))throw new i(null,c.InvalidIdentifier,null);if(!1===H(n))throw new i(null,c.ModuleAccessorMustBeString,null);if(!e.hasGlobal(n))throw new i(null,c.ModuleExportNotFound,null);e.setGlobal(n,this.assign(l,t,e.global(n)))}},member(e,n){if(null===e)throw new i(null,c.MemberOfNull,null);if(e instanceof s||C(e)){if(H(n))return e.field(n);throw new i(null,c.InvalidMemberAccessKey,null)}if(e instanceof T){if(H(n))return r(e,n,null,null);throw new i(null,c.InvalidMemberAccessKey,null)}if(Y(e)){if(J(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new i(null,c.OutOfBounds,null);return e[n]}throw new i(null,c.InvalidMemberAccessKey,null)}if(H(e)){if(J(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length+n),n>=e.length||n<0)throw new i(null,c.OutOfBounds,null);return e[n]}throw new i(null,c.InvalidMemberAccessKey,null)}if($(e)){if(J(n)&&isFinite(n)&&Math.floor(n)===n){if(n<0&&(n=e.length()+n),n>=e.length()||n<0)throw new i(null,c.OutOfBounds,null);return e.get(n)}throw new i(null,c.InvalidMemberAccessKey,null)}if(e instanceof Xe){if(H(n))return e.global(n);throw new i(null,c.InvalidMemberAccessKey,null)}throw new i(null,c.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 l=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]=l,l},callModuleFunction(e,n,t,l){if(!(e instanceof Xe))throw new i(null,c.FunctionNotFound,null);const o=e.global(t);if(!1===y(o))throw new i(null,c.CallNonFunction,null);return o.call(l,{preparsed:!0,arguments:n})},getNestedOptionalValue:(e,n)=>a(e,n)};function Ye(e){console.log(e)}function He(n,t,o=!1){null==t&&(t={vars:{},customfunctions:{}});let r=null;n.usesModules&&(r=new l(null,n.loadedModules));const a={isAsync:o,globalScope:We(t.vars,o?Ue:Re,t.customfunctions),moduleFactory:{},moduleFactoryMap:{},undeclaredGlobalsInFunctions:new Map,libraryResolver:r,localScope:null,mangleMap:{},depthCounter:{depth:1},exports:{},symbols:{symbolCounter:0}};let s=ye(a,n);""===s&&(s="lc.voidOperation; "),a.undeclaredGlobalsInFunctions.size>0&&a.undeclaredGlobalsInFunctions.forEach((e=>{throw new u(null,c.InvalidIdentifier,e.node)}));let p="";p=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+s+"\n return lastStatement; }); } \n return this.postProcess(yield mainBody()); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+s+"\n return lastStatement; } \n return this.postProcess(mainBody()); ";const m=a.moduleFactory,g=a.moduleFactoryMap,d=a.exports,f={};let h;for(h in d)f[h]=a.mangleMap[h]??h;const b={lc:w,lang:Je,mangles:a.mangleMap,postProcess(e){if(e instanceof S&&(e=e.value),e instanceof v&&(e=e.value),e===x&&(e=null),e===M)throw new i(null,c.IllegalResult,null);if(e===F)throw new i(null,c.IllegalResult,null);if(y(e))throw new i(null,c.IllegalResult,null);return e},prepare(n,t){const l=n.spatialReference??Z.WebMercator,o=Ve(n.vars,n.customfunctions,t,n.timeZone);return{localStack:[],moduleFactory:m,moduleFactoryMap:g,mangleMap:this.mangles,moduleSingletons:{},exports:d,gdefs:{},exportmangle:f,spatialReference:l,globalScope:o,abortSignal:n.abortSignal??e,services:n.services,console:n.console??Ye,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,depthCounter:{depth:1}}}};return new Function("context",p).bind(b)}async function Qe(){return Te([await import("./functions/geomasync.js")],"async"),!0}class Xe extends t{constructor(e){super(),this.moduleContext=e}hasGlobal(e){return void 0===this.moduleContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.moduleContext.exports[e]}setGlobal(e,n){const t=this.moduleContext.globalScope,l=e.toLowerCase();if(y(n))throw new i(null,c.AssignModuleFunction,null);t[this.moduleContext.exportmangle[l]]=n}global(e){const n=this.moduleContext.globalScope,t=e.toLowerCase(),l=n[this.moduleContext.exportmangle[t]];if(void 0===l)throw new i(null,c.InvalidIdentifier,null);if(y(l)&&!(l instanceof f)){const e=new f;return e.fn=l,e.parameterEvaluator=ne,e.context=this.moduleContext,n[this.moduleContext.exportmangle[t]]=e,e}return l}}function en(n,t,o){const r={isAsync:o,moduleFactory:t.moduleFactory,moduleFactoryMap:{},libraryResolver:new l(null,n.loadedModules),globalScope:We(null,o?Ue:Re,null),localScope:null,mangleMap:{},undeclaredGlobalsInFunctions:new Map,depthCounter:{depth:1},exports:{},symbols:{symbolCounter:0}};let a=ye(r,n);""===a&&(a="lc.voidOperation; ");let s="";s=o?"var runtimeCtx=this.prepare(context, true);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \nreturn lang.__awaiter(this, void 0, void 0, function* () {\n\n function mainBody() {\n var lastStatement=lc.voidOperation;\n return lang.__awaiter(this, void 0, void 0, function* () {\n"+a+"\n return lastStatement; }); } \n yield mainBody(); \n return this.prepareModule(runtimeCtx); }); ":"var runtimeCtx=this.prepare(context, false);\n var lc = this.lc; var lang = this.lang; var gscope=runtimeCtx.globalScope; \n function mainBody() {\n var lastStatement=lc.voidOperation;\n "+a+"\n return lastStatement; } \n mainBody(); \n return this.prepareModule(runtimeCtx); ";const i=r.moduleFactory,c=r.moduleFactoryMap,u=r.exports,p={};let m;for(m in u)p[m]=r.mangleMap[m]??m;const g={lc:w,lang:Je,mangles:r.mangleMap,prepareModule:e=>new Xe(e),prepare(n,t){const l=n.spatialReference??Z.WebMercator,o=Ve(null,null,t,n.timeZone);return{localStack:[],exports:u,exportmangle:p,gdefs:{},moduleFactory:i,moduleFactoryMap:c,moduleSingletons:n.moduleSingletons,mangleMap:this.mangles,spatialReference:l,globalScope:o,abortSignal:n.abortSignal??e,services:n.services,console:n.console??Ye,lrucache:n.lrucache,timeZone:n.timeZone??null,interceptor:n.interceptor,depthCounter:n.depthCounter}}};return new Function("context",s).bind(g)}export{X as UserDefinedCompiledFunction,He as compileScript,Qe as enableAsyncSupport,Ze as executeScript,Te as extend,qe as functionHelper};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../request.js";import t from"./featureSetCollection.js";import{p as a,_ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import s from"./featureset/actions/GroupBy.js";import l from"./featureset/actions/OrderBy.js";import i from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import p from"./featureset/support/cache.js";import{FeatureSetError as f,FeatureSetErrorCodes as y}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as m,extractServiceUrl as h,isSupportedLayer as I}from"./featureset/support/shared.js";import L from"../core/Loadable.js";import w from"../core/sql/WhereClause.js";import S from"../layers/FeatureLayer.js";import _ from"../layers/Layer.js";import C from"../portal/PortalItem.js";function g(){null===p.applicationCache&&(p.applicationCache=new p)}async function k(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new S({url:e,outFields:t,sourceJSON:r})}const n=new S({url:e,outFields:t}),s=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,s);try{return await s,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await s,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new S({url:e,outFields:t,sourceJSON:a})}const s=new S({url:e,outFields:t}),l=(async()=>(await s.load(),s.sourceJSON))();a.setCachedLayerMetadata(e,l);try{return await l,s}catch(n){throw a.removeCachedLayerMetadata(e,l),n}}return new S({url:e,outFields:t})}async function F(e,t,a,r,n,s=null){return N(await k(e,["*"],n),t,a,r,n,s)}function N(e,t=null,a=null,r=!0,n=null,s=null){switch(e.type){case"catalog-footprint":return N(e.parent,t,a,r,n,s);case"subtype-sublayer":{const l=N(e.parent,t,a,r,n,s);return l.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:l.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"knowledge-graph-sublayer":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:s});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const l={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:s};return!e.url&&e.source?new c(l):new u(l)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function A(t){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw p.applicationCache.clearLayerInfo(t),r}}return a}async function T(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new f(y.DataElementsNotFound)})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(s){throw p.applicationCache.clearLayerInfo(r),s}}return n}async function O(t,a){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw p.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(s){throw a.removeCachedServiceMetadata(t,r),s}}return r}async function E(e,t,a){const r={metadata:null,networkId:-1,unVersion:3,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map,queryelem:null,layerNameLkp:{},lkp:null},n=await O(e,null);if(r.metadata=n,void 0!==n.controllerDatasetLayers?.utilityNetworkLayerId&&null!==n.controllerDatasetLayers.utilityNetworkLayerId){if(n.layers)for(const e of n.layers)r.layerNameLkp[e.id]=e.name;if(n.tables)for(const e of n.tables)r.layerNameLkp[e.id]=e.name;const s=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=s;const l=await T(e,s);if(l){r.queryelem=l,r.queryelem?.dataElement&&void 0!==r.queryelem.dataElement.schemaGeneration&&(r.unVersion=r.queryelem.dataElement.schemaGeneration),r.lkp={},r.queryelem.dataElement.domainNetworks||(r.queryelem.dataElement.domainNetworks=[]);for(const e of r.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}}if(r.queryelem.dataElement.terminalConfigurations)for(const e of r.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)r.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const n=await A(e+"/"+s);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let s=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),s=await F(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await s.load(),r.unVersion>=4&&(s=s.filter(w.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:s.getFieldsIndex(),timeZone:s.dateFieldsTimeZoneDefaultUTC})),await s.load())}return{lkp:r.lkp,associations:s,unVersion:r.unVersion,terminals:r.terminals,layerIdLookup:r.layerIdLookup,sourceIdLookup:r.sourceIdLookup}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}async function j(e,t,a,r=null,n=null,s=!0,l=null,i=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await F(o,r,n,s,l,i);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:s,lrucache:l,interceptor:i})}n.registerAction(),s.registerAction(),l.registerAction(),i.registerAction(),o.registerAction();class b extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=N(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(L.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=this._map.allLayers.find((t=>I(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>I(t)&&t.title===e));if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){if(L.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=this._map.allLayers.find((t=>I(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>I(t)&&t.id===e));if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=N(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await O(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let s=null;for(const l of n.layers??[])l.name===e&&(s=l);if(!s)for(const l of n.tables??[])l.name===e&&(s=l);if(s){const e=await k(this._url+"/"+s.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let s=null;for(const l of n.layers??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(s=l);if(!s)for(const l of n.tables??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(s=l);if(s){const e=await k(this._url+"/"+s.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new b(e,t,a,r)}function v(e,t,a=null,r=null){return new D(e,t,a,r)}function R(e,t,n,s,l){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof _&&m(e)){const a=e;switch(t){case"datasource":return N(a,l,"outFields"in a?a.outFields:null,!0,n,s).getDataSourceFeatureSet();case"parent":case"root":return N(a,l,"outFields"in a?a.outFields:null,!0,n,s)}return null}if(r(e)){switch(t){case"datasource":return N(e.parent,l,e.parent.outFields,!0,n,s).getDataSourceFeatureSet();case"parent":case"root":return N(e,l,e.parent.outFields,!0,n,s)}return null}return null}async function q(e,t,a,r,n,s,l,i=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+s.url);if(o)return G(await o,t,a,r,n,l,i)}if(null!=l){const o=l.getCachedPortalItem(s.url,e);if(null!=o)return await G(await o,t,a,r,n,l,i)}const o=new C({id:e,portal:s}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+s.url,o):null!=l&&l.setCachedPortalItem(s.url,e,o);try{return await G(await o,t,a,r,n,l,i)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+s.url),null!=l&&l.removeCachedPortalItem(s.url,e,o),u}}async function G(e,t,a,r,n,s,l){let i;if("Feature Service"===e.type||"Map Service"===e.type)i=await k(h(e.url??"")+"/"+t,["*"],s);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=s){const t=s.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)i=await t;else{const t=_.fromPortalItem(e);s.setCachedPortalItemLayer(e.portal.url,e.id,t);try{i=await t}catch(o){throw s.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else i=await _.fromPortalItem(e)}return N(i,a,r,n,s,l)}export{E as constructAssociationMetaDataFeatureSetFromUrl,N as constructFeatureSet,q as constructFeatureSetFromPortalItem,j as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,R as convertToFeatureSet,M as createFeatureSetCollectionFromMap,v as createFeatureSetCollectionFromService,g as initialiseMetaDataCache};
5
+ import e from"../request.js";import t from"./featureSetCollection.js";import{p as a,$ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import s from"./featureset/actions/GroupBy.js";import l from"./featureset/actions/OrderBy.js";import i from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import p from"./featureset/support/cache.js";import{FeatureSetError as f,FeatureSetErrorCodes as y}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as m,extractServiceUrl as h,isSupportedLayer as I}from"./featureset/support/shared.js";import L from"../core/Loadable.js";import w from"../core/sql/WhereClause.js";import S from"../layers/FeatureLayer.js";import _ from"../layers/Layer.js";import C from"../portal/PortalItem.js";function g(){null===p.applicationCache&&(p.applicationCache=new p)}async function k(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new S({url:e,outFields:t,sourceJSON:r})}const n=new S({url:e,outFields:t}),s=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,s);try{return await s,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await s,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new S({url:e,outFields:t,sourceJSON:a})}const s=new S({url:e,outFields:t}),l=(async()=>(await s.load(),s.sourceJSON))();a.setCachedLayerMetadata(e,l);try{return await l,s}catch(n){throw a.removeCachedLayerMetadata(e,l),n}}return new S({url:e,outFields:t})}async function F(e,t,a,r,n,s=null){return N(await k(e,["*"],n),t,a,r,n,s)}function N(e,t=null,a=null,r=!0,n=null,s=null){switch(e.type){case"catalog-footprint":return N(e.parent,t,a,r,n,s);case"subtype-sublayer":{const l=N(e.parent,t,a,r,n,s);return l.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:l.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"knowledge-graph-sublayer":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:s});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const l={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:s};return!e.url&&e.source?new c(l):new u(l)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function A(t){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw p.applicationCache.clearLayerInfo(t),r}}return a}async function T(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new f(y.DataElementsNotFound)})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(s){throw p.applicationCache.clearLayerInfo(r),s}}return n}async function O(t,a){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw p.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(s){throw a.removeCachedServiceMetadata(t,r),s}}return r}async function E(e,t,a){const r={metadata:null,networkId:-1,unVersion:3,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map,queryelem:null,layerNameLkp:{},lkp:null},n=await O(e,null);if(r.metadata=n,void 0!==n.controllerDatasetLayers?.utilityNetworkLayerId&&null!==n.controllerDatasetLayers.utilityNetworkLayerId){if(n.layers)for(const e of n.layers)r.layerNameLkp[e.id]=e.name;if(n.tables)for(const e of n.tables)r.layerNameLkp[e.id]=e.name;const s=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=s;const l=await T(e,s);if(l){r.queryelem=l,r.queryelem?.dataElement&&void 0!==r.queryelem.dataElement.schemaGeneration&&(r.unVersion=r.queryelem.dataElement.schemaGeneration),r.lkp={},r.queryelem.dataElement.domainNetworks||(r.queryelem.dataElement.domainNetworks=[]);for(const e of r.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}}if(r.queryelem.dataElement.terminalConfigurations)for(const e of r.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)r.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const n=await A(e+"/"+s);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let s=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),s=await F(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await s.load(),r.unVersion>=4&&(s=s.filter(w.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:s.getFieldsIndex(),timeZone:s.dateFieldsTimeZoneDefaultUTC})),await s.load())}return{lkp:r.lkp,associations:s,unVersion:r.unVersion,terminals:r.terminals,layerIdLookup:r.layerIdLookup,sourceIdLookup:r.sourceIdLookup}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}async function j(e,t,a,r=null,n=null,s=!0,l=null,i=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await F(o,r,n,s,l,i);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:s,lrucache:l,interceptor:i})}n.registerAction(),s.registerAction(),l.registerAction(),i.registerAction(),o.registerAction();class b extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=N(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(L.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=this._map.allLayers.find((t=>I(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>I(t)&&t.title===e));if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){if(L.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=this._map.allLayers.find((t=>I(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>I(t)&&t.id===e));if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=N(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await O(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let s=null;for(const l of n.layers??[])l.name===e&&(s=l);if(!s)for(const l of n.tables??[])l.name===e&&(s=l);if(s){const e=await k(this._url+"/"+s.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let s=null;for(const l of n.layers??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(s=l);if(!s)for(const l of n.tables??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(s=l);if(s){const e=await k(this._url+"/"+s.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new b(e,t,a,r)}function v(e,t,a=null,r=null){return new D(e,t,a,r)}function R(e,t,n,s,l){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof _&&m(e)){const a=e;switch(t){case"datasource":return N(a,l,"outFields"in a?a.outFields:null,!0,n,s).getDataSourceFeatureSet();case"parent":case"root":return N(a,l,"outFields"in a?a.outFields:null,!0,n,s)}return null}if(r(e)){switch(t){case"datasource":return N(e.parent,l,e.parent.outFields,!0,n,s).getDataSourceFeatureSet();case"parent":case"root":return N(e,l,e.parent.outFields,!0,n,s)}return null}return null}async function q(e,t,a,r,n,s,l,i=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+s.url);if(o)return G(await o,t,a,r,n,l,i)}if(null!=l){const o=l.getCachedPortalItem(s.url,e);if(null!=o)return await G(await o,t,a,r,n,l,i)}const o=new C({id:e,portal:s}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+s.url,o):null!=l&&l.setCachedPortalItem(s.url,e,o);try{return await G(await o,t,a,r,n,l,i)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+s.url),null!=l&&l.removeCachedPortalItem(s.url,e,o),u}}async function G(e,t,a,r,n,s,l){let i;if("Feature Service"===e.type||"Map Service"===e.type)i=await k(h(e.url??"")+"/"+t,["*"],s);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=s){const t=s.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)i=await t;else{const t=_.fromPortalItem(e);s.setCachedPortalItemLayer(e.portal.url,e.id,t);try{i=await t}catch(o){throw s.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else i=await _.fromPortalItem(e)}return N(i,a,r,n,s,l)}export{E as constructAssociationMetaDataFeatureSetFromUrl,N as constructFeatureSet,q as constructFeatureSetFromPortalItem,j as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,R as convertToFeatureSet,M as createFeatureSetCollectionFromMap,v as createFeatureSetCollectionFromService,g as initialiseMetaDataCache};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import{$ as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as o,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import w from"../support/StatsField.js";import{createMD5Hash as F,outputTypes as I}from"../../../core/MD5.js";import{aggregateFunction as S}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as j}from"../../../core/sql/TimeOnly.js";import k from"../../../core/sql/WhereClause.js";import C from"../../../geometry/SpatialReference.js";import A from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class O extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new w;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new C({wkid:4326});this.fields=[];const a=new w;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=k.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new A;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new o(l.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new A;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new A;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new o(l.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,o){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(o),l=!0===d.nowhereclause?new u(n._candidates.slice().concat(n._known.slice()),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(),n._known.slice(),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),l}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const o=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(o){a(o)}}_calculateFieldStat(e,t,i){const s=[];for(const n of e.features)if(null!==t.workingexpr){const e=t.workingexpr.calculateValue(n);null!==e&&(e instanceof x||e instanceof j?s.push(e.toNumber()):e instanceof D?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=S(t.typeofstat,[s])}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:k.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return F(t,I.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
5
+ import e from"../../../Graphic.js";import{a0 as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as o,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import w from"../support/StatsField.js";import{createMD5Hash as F,outputTypes as I}from"../../../core/MD5.js";import{aggregateFunction as S}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as j}from"../../../core/sql/TimeOnly.js";import k from"../../../core/sql/WhereClause.js";import C from"../../../geometry/SpatialReference.js";import A from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class O extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new w;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new C({wkid:4326});this.fields=[];const a=new w;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=k.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new A;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new o(l.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new A;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new A;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new o(l.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,o){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(o),l=!0===d.nowhereclause?new u(n._candidates.slice().concat(n._known.slice()),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(),n._known.slice(),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),l}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const o=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(o){a(o)}}_calculateFieldStat(e,t,i){const s=[];for(const n of e.features)if(null!==t.workingexpr){const e=t.workingexpr.calculateValue(n);null!==e&&(e instanceof x||e instanceof j?s.push(e.toNumber()):e instanceof D?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=S(t.typeofstat,[s])}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:k.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return F(t,I.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{$ as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import s from"../support/IdSet.js";import i from"../support/OrderbyClause.js";class a extends n{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const n=new s([],[],!0,null);for(let s=0;s<r.length;s++)n._known.push(r[s].id);return n}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t(r.NeverReach)}async _getFilteredSet(e,t,r,n,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===n?this._orderbyclause:n,i);this._checkCancelled(i);const o=new s(a._candidates.slice(),a._known.slice(),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new s(e._candidates.slice().concat(e._known.slice()),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){n._featuresetFunctions.orderBy=function(e){return""===e?this:new a({parentfeatureset:this,orderbyclause:new i(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{a as default};
5
+ import{a0 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import s from"../support/IdSet.js";import i from"../support/OrderbyClause.js";class a extends n{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const n=new s([],[],!0,null);for(let s=0;s<r.length;s++)n._known.push(r[s].id);return n}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t(r.NeverReach)}async _getFilteredSet(e,t,r,n,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===n?this._orderbyclause:n,i);this._checkCancelled(i);const o=new s(a._candidates.slice(),a._known.slice(),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new s(e._candidates.slice().concat(e._known.slice()),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){n._featuresetFunctions.orderBy=function(e){return""===e?this:new a({parentfeatureset:this,orderbyclause:new i(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{a as default};
@@ -0,0 +1,5 @@
1
+ /*
2
+ All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
+ */
5
+ import"../arcadeEnvironment.js";import"../Dictionary.js";import"../executionError.js";import"../../chunks/languageUtils.js";import"../../core/Logger.js";import"../../portal/Portal.js";import"../../rest/translate.js";import"../../rest/support/TranslateContent.js";import"../../rest/support/TranslateParameters.js";import"../../rest/support/TranslateResult.js";import"../../support/guards.js";export{r as registerFunctions}from"../../chunks/aiServices.js";
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as n,createDateTimeZone as e}from"../ArcadeDate.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as t}from"../executionError.js";import{D as o,L as u,t as a,k as s,g as i,j as l,f as c,h as f,K as m,N as d,O as h}from"../../chunks/languageUtils.js";import{DateOnly as y}from"../../core/sql/DateOnly.js";import{TimeOnly as N}from"../../core/sql/TimeOnly.js";import{getLocale as w}from"../../intl/locale.js";import{DateTime as g}from"luxon";import{isString as A}from"../../support/guards.js";function k(n,e,r){return n+(T(r)?P:D)[e]}function T(n){return n%4==0&&(n%100!=0||n%400==0)}const D=[0,31,59,90,120,151,181,212,243,273,304,334],P=[0,31,60,91,121,152,182,213,244,274,305,335];function S(n){return null===n?n:!1===n.isValid?null:n}function Z(n,e){return""===n||"default"===n.toLowerCase().trim()?u(e):"z"===n||"Z"===n?"UTC":n}function p(n,e){return l(n)?n.toArcadeDate():f(n,u(e))}function C(T,D){T.today=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=new Date;return i.setHours(0,0,0,0),n.dateJSAndZoneToArcadeDate(i,u(e))}))},T.time=function(e,c){return D(e,c,((f,m,d)=>{switch(o(d,0,4,e,c),d.length){case 0:{const r=n.nowToArcadeDate(u(e));return new N(r.hour,r.minute,r.second,r.millisecond)}case 1:{if(s(d[0]))return d[0].clone();if(i(d[0]))return new N(d[0].hour,d[0].minute,d[0].second,d[0].millisecond);if(l(d[0]))return new N(0,0,0,0);if(A(d[0]))return N.fromString(d[0]);const n=a(d[0]);return!1===isNaN(n)?N.fromMilliseconds(n):null}case 2:return A(d[0])&&A(d[1])?N.fromString(d[0],d[1]):N.fromParts(a(d[0]),a(d[1]),0,0);case 3:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),0);case 4:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),a(d[3]))}throw new r(e,t.InvalidParameter,c)}))},T.dateonly=function(e,r){return D(e,r,((t,s,f)=>{if(o(f,0,3,e,r),3===f.length)return y.fromParts(a(f[0]),a(f[1])+1,a(f[2]));if(2===f.length){const n=c(f[1]);return""===n?null:"X"===n?y.fromSeconds(a(f[0])):"x"===n?y.fromMilliseconds(a(f[0])):y.fromString(c(f[0]),n)}if(1===f.length){if(A(f[0])){if(""===f[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(f[0]))return y.fromString(f[0]+"-01-01")}if(l(f[0]))return f[0].clone();if(i(f[0]))return y.fromParts(f[0].year,f[0].monthJS+1,f[0].day);const n=a(f[0]);return!1===isNaN(n)?y.fromMilliseconds(n):A(f[0])?y.fromString(f[0]):null}if(0===f.length){const r=n.nowToArcadeDate(u(e));return!1===r.isValid?null:y.fromParts(r.year,r.monthJS+1,r.day)}return null}))},T.changetimezone=function(a,s){return D(a,s,((i,m,d)=>{if(o(d,2,2,a,s),null===d[0])return null;if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneDateOnly,s);if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneTime,s);const h=f(d[0],u(a));if(null===h)throw new r(a,t.InvalidParameter,s);const y=e(Z(c(d[1]),a),!1);if(null===y)return null;const N=n.arcadeDateAndZoneToArcadeDate(h,y);return!1===N.isValid?null:N}))},T.timezone=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,1,2,e,r),s(i[0]))return"Unknown";if(l(i[0]))return"Unknown";const c=f(i[0],u(e));if(null===c)return null;const m=c.timeZone;return"system"===m?n.systemTimeZoneCanonicalName:"utc"===m.toLowerCase()?"UTC":"unknown"===m.toLowerCase()?"Unknown":m}))},T.timezoneoffset=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:60*s.timeZoneOffset*1e3}))},T.now=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=n.nowToArcadeDate(u(e));return!1===i.isValid?null:i}))},T.timestamp=function(e,r){return D(e,r,((t,u,a)=>{o(a,0,0,e,r);const s=n.nowUTCToArcadeDate();return!1===s.isValid?null:s}))},T.toutc=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toUTC()}))},T.tolocal=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toLocal()}))},T.day=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.day}))},T.month=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthJS}))},T.year=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.year}))},T.hour=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].hour;const i=f(a[0],u(n));return null===i?NaN:i.hour}))},T.second=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].second;const i=f(a[0],u(n));return null===i?NaN:i.second}))},T.millisecond=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].millisecond;const i=f(a[0],u(n));return null===i?NaN:i.millisecond}))},T.minute=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].minute;const i=f(a[0],u(n));return null===i?NaN:i.minute}))},T.week=function(n,e){return D(n,e,((s,i,l)=>{o(l,1,2,n,e);const c=p(l[0],u(n));if(null===c)return NaN;const f=a(m(l[1],0));if(f<0||f>6)throw new r(n,t.InvalidParameter,e);const d=c.day,h=c.monthJS,y=c.year,N=c.dayOfWeekJS,w=k(d,h,y)-1,g=Math.floor(w/7);return N-f+(N-f<0?7:0)<w-7*g?g+1:g}))},T.weekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekJS}))},T.isoweekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekISO}))},T.isomonth=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthISO}))},T.isoweek=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.weekISO}))},T.isoyear=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.yearISO}))},T.date=function(r,t){return D(r,t,((i,m,h)=>{if(o(h,0,8,r,t),3===h.length){if(l(h[0])&&s(h[1])&&A(h[2])){const t=e(Z(c(h[2])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,t))}return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),0,0,0,0,u(r)))}if(4===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),0,0,0,u(r)));if(5===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),0,0,u(r)));if(6===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),0,u(r)));if(7===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),u(r)));if(8===h.length){const t=e(Z(c(h[7])??"unknown",r),!1);return null===t?null:S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),t))}if(2===h.length){if(l(h[0])&&A(h[1])){const t=e(Z(c(h[1])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,t))}if(l(h[0])&&s(h[1]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,"unknown"));let t,o=c(h[1]);return""===o?null:(o=d(o,!0),t="X"===o?g.fromSeconds(a(h[0])):"x"===o?g.fromMillis(a(h[0])):g.fromFormat(c(h[0]),o,{locale:w(),numberingSystem:"latn"}),t.isValid?n.dateTimeToArcadeDate(t):null)}if(1===h.length){if(l(h[0]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,"unknown"));if(A(h[0])){if(""===h[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(h[0]))return f(h[0]+"-01-01",u(r))}const e=a(h[0]);if(!1===isNaN(e)){const t=g.fromMillis(e);return t.isValid?n.dateTimeAndZoneToArcadeDate(t,u(r)):null}return f(h[0],u(r))}return 0===h.length?n.nowToArcadeDate(u(r)):null}))},T.datediff=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,2,4,e,r),s(i[0]))return s(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(s(i[1]))return NaN;if(l(i[0]))return l(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(l(i[1]))return NaN;let d=f(i[0],u(e)),h=f(i[1],u(e));if(null===d||null===h)return NaN;let y=m(i[3],"");switch(""!==y&&null!==y?(y=Z(c(y),e),d=n.arcadeDateAndZoneToArcadeDate(d,y),h=n.arcadeDateAndZoneToArcadeDate(h,y)):d.timeZone!==h.timeZone&&(d.isUnknownTimeZone?d=n.arcadeDateAndZoneToArcadeDate(d,h.timeZone):h=(h.isUnknownTimeZone,n.arcadeDateAndZoneToArcadeDate(h,d.timeZone))),c(i[2]).toLowerCase()){case"days":case"day":case"d":return d.diff(h,"days");case"months":case"month":return d.diff(h,"months");case"minutes":case"minute":case"m":return"M"===i[2]?d.diff(h,"months"):d.diff(h,"minutes");case"seconds":case"second":case"s":return d.diff(h,"seconds");case"milliseconds":case"millisecond":case"ms":default:return d.diff(h);case"hours":case"hour":case"h":return d.diff(h,"hours");case"years":case"year":case"y":return d.diff(h,"years")}}))},T.dateadd=function(n,e){return D(n,e,((r,t,i)=>{o(i,2,3,n,e);let m=a(i[1]);if(isNaN(m)||m===1/0||m===-1/0)return s(i[0])||l(i[0])?i[0].clone():f(i[0],u(n));let d="milliseconds";switch(c(i[2]).toLowerCase()){case"days":case"day":case"d":d="days",m=l(i[0])?m:h(m);break;case"months":case"month":d="months",m=l(i[0])?m:h(m);break;case"minutes":case"minute":case"m":d="M"===i[2]?"months":"minutes";break;case"seconds":case"second":case"s":d="seconds";break;case"milliseconds":case"millisecond":case"ms":d="milliseconds";break;case"hours":case"hour":case"h":d="hours";break;case"years":case"year":case"y":d="years"}if(s(i[0]))return i[0].plus(d,m);if(l(i[0]))return i[0].plus(d,m);const y=f(i[0],u(n));return null===y?null:y.plus({[d]:m})}))}}export{C as registerFunctions};
5
+ import{ArcadeDate as n,createDateTimeZone as e}from"../ArcadeDate.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as t}from"../executionError.js";import{D as o,L as u,t as a,k as s,g as i,j as l,f as c,h as f,K as m,O as d,P as h}from"../../chunks/languageUtils.js";import{DateOnly as y}from"../../core/sql/DateOnly.js";import{TimeOnly as N}from"../../core/sql/TimeOnly.js";import{getLocale as w}from"../../intl/locale.js";import{DateTime as g}from"luxon";import{isString as A}from"../../support/guards.js";function k(n,e,r){return n+(T(r)?P:D)[e]}function T(n){return n%4==0&&(n%100!=0||n%400==0)}const D=[0,31,59,90,120,151,181,212,243,273,304,334],P=[0,31,60,91,121,152,182,213,244,274,305,335];function S(n){return null===n?n:!1===n.isValid?null:n}function Z(n,e){return""===n||"default"===n.toLowerCase().trim()?u(e):"z"===n||"Z"===n?"UTC":n}function p(n,e){return l(n)?n.toArcadeDate():f(n,u(e))}function C(T,D){T.today=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=new Date;return i.setHours(0,0,0,0),n.dateJSAndZoneToArcadeDate(i,u(e))}))},T.time=function(e,c){return D(e,c,((f,m,d)=>{switch(o(d,0,4,e,c),d.length){case 0:{const r=n.nowToArcadeDate(u(e));return new N(r.hour,r.minute,r.second,r.millisecond)}case 1:{if(s(d[0]))return d[0].clone();if(i(d[0]))return new N(d[0].hour,d[0].minute,d[0].second,d[0].millisecond);if(l(d[0]))return new N(0,0,0,0);if(A(d[0]))return N.fromString(d[0]);const n=a(d[0]);return!1===isNaN(n)?N.fromMilliseconds(n):null}case 2:return A(d[0])&&A(d[1])?N.fromString(d[0],d[1]):N.fromParts(a(d[0]),a(d[1]),0,0);case 3:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),0);case 4:return N.fromParts(a(d[0]),a(d[1]),a(d[2]),a(d[3]))}throw new r(e,t.InvalidParameter,c)}))},T.dateonly=function(e,r){return D(e,r,((t,s,f)=>{if(o(f,0,3,e,r),3===f.length)return y.fromParts(a(f[0]),a(f[1])+1,a(f[2]));if(2===f.length){const n=c(f[1]);return""===n?null:"X"===n?y.fromSeconds(a(f[0])):"x"===n?y.fromMilliseconds(a(f[0])):y.fromString(c(f[0]),n)}if(1===f.length){if(A(f[0])){if(""===f[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(f[0]))return y.fromString(f[0]+"-01-01")}if(l(f[0]))return f[0].clone();if(i(f[0]))return y.fromParts(f[0].year,f[0].monthJS+1,f[0].day);const n=a(f[0]);return!1===isNaN(n)?y.fromMilliseconds(n):A(f[0])?y.fromString(f[0]):null}if(0===f.length){const r=n.nowToArcadeDate(u(e));return!1===r.isValid?null:y.fromParts(r.year,r.monthJS+1,r.day)}return null}))},T.changetimezone=function(a,s){return D(a,s,((i,m,d)=>{if(o(d,2,2,a,s),null===d[0])return null;if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneDateOnly,s);if(l(d[0]))throw new r(a,t.CannotChangeTimeZoneTime,s);const h=f(d[0],u(a));if(null===h)throw new r(a,t.InvalidParameter,s);const y=e(Z(c(d[1]),a),!1);if(null===y)return null;const N=n.arcadeDateAndZoneToArcadeDate(h,y);return!1===N.isValid?null:N}))},T.timezone=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,1,2,e,r),s(i[0]))return"Unknown";if(l(i[0]))return"Unknown";const c=f(i[0],u(e));if(null===c)return null;const m=c.timeZone;return"system"===m?n.systemTimeZoneCanonicalName:"utc"===m.toLowerCase()?"UTC":"unknown"===m.toLowerCase()?"Unknown":m}))},T.timezoneoffset=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:60*s.timeZoneOffset*1e3}))},T.now=function(e,r){return D(e,r,((t,a,s)=>{o(s,0,0,e,r);const i=n.nowToArcadeDate(u(e));return!1===i.isValid?null:i}))},T.timestamp=function(e,r){return D(e,r,((t,u,a)=>{o(a,0,0,e,r);const s=n.nowUTCToArcadeDate();return!1===s.isValid?null:s}))},T.toutc=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toUTC()}))},T.tolocal=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=f(a[0],u(n));return null===s?null:s.toLocal()}))},T.day=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.day}))},T.month=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthJS}))},T.year=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.year}))},T.hour=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].hour;const i=f(a[0],u(n));return null===i?NaN:i.hour}))},T.second=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].second;const i=f(a[0],u(n));return null===i?NaN:i.second}))},T.millisecond=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].millisecond;const i=f(a[0],u(n));return null===i?NaN:i.millisecond}))},T.minute=function(n,e){return D(n,e,((r,t,a)=>{if(o(a,1,1,n,e),s(a[0]))return a[0].minute;const i=f(a[0],u(n));return null===i?NaN:i.minute}))},T.week=function(n,e){return D(n,e,((s,i,l)=>{o(l,1,2,n,e);const c=p(l[0],u(n));if(null===c)return NaN;const f=a(m(l[1],0));if(f<0||f>6)throw new r(n,t.InvalidParameter,e);const d=c.day,h=c.monthJS,y=c.year,N=c.dayOfWeekJS,w=k(d,h,y)-1,g=Math.floor(w/7);return N-f+(N-f<0?7:0)<w-7*g?g+1:g}))},T.weekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekJS}))},T.isoweekday=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.dayOfWeekISO}))},T.isomonth=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.monthISO}))},T.isoweek=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.weekISO}))},T.isoyear=function(n,e){return D(n,e,((r,t,a)=>{o(a,1,1,n,e);const s=p(a[0],u(n));return null===s?NaN:s.yearISO}))},T.date=function(r,t){return D(r,t,((i,m,h)=>{if(o(h,0,8,r,t),3===h.length){if(l(h[0])&&s(h[1])&&A(h[2])){const t=e(Z(c(h[2])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,t))}return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),0,0,0,0,u(r)))}if(4===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),0,0,0,u(r)));if(5===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),0,0,u(r)));if(6===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),0,u(r)));if(7===h.length)return S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),u(r)));if(8===h.length){const t=e(Z(c(h[7])??"unknown",r),!1);return null===t?null:S(n.fromParts(a(h[0]),a(h[1])+1,a(h[2]),a(h[3]),a(h[4]),a(h[5]),a(h[6]),t))}if(2===h.length){if(l(h[0])&&A(h[1])){const t=e(Z(c(h[1])??"unknown",r),!1);return null===t?null:S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,t))}if(l(h[0])&&s(h[1]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,h[1].hour,h[1].minute,h[1].second,h[1].millisecond,"unknown"));let t,o=c(h[1]);return""===o?null:(o=d(o,!0),t="X"===o?g.fromSeconds(a(h[0])):"x"===o?g.fromMillis(a(h[0])):g.fromFormat(c(h[0]),o,{locale:w(),numberingSystem:"latn"}),t.isValid?n.dateTimeToArcadeDate(t):null)}if(1===h.length){if(l(h[0]))return S(n.fromParts(h[0].year,h[0].month,h[0].day,0,0,0,0,"unknown"));if(A(h[0])){if(""===h[0].replaceAll(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""))return null;if(!0===/^[0-9][0-9][0-9][0-9]$/.test(h[0]))return f(h[0]+"-01-01",u(r))}const e=a(h[0]);if(!1===isNaN(e)){const t=g.fromMillis(e);return t.isValid?n.dateTimeAndZoneToArcadeDate(t,u(r)):null}return f(h[0],u(r))}return 0===h.length?n.nowToArcadeDate(u(r)):null}))},T.datediff=function(e,r){return D(e,r,((t,a,i)=>{if(o(i,2,4,e,r),s(i[0]))return s(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(s(i[1]))return NaN;if(l(i[0]))return l(i[1])?i[0].difference(i[1],c(i[2])):NaN;if(l(i[1]))return NaN;let d=f(i[0],u(e)),h=f(i[1],u(e));if(null===d||null===h)return NaN;let y=m(i[3],"");switch(""!==y&&null!==y?(y=Z(c(y),e),d=n.arcadeDateAndZoneToArcadeDate(d,y),h=n.arcadeDateAndZoneToArcadeDate(h,y)):d.timeZone!==h.timeZone&&(d.isUnknownTimeZone?d=n.arcadeDateAndZoneToArcadeDate(d,h.timeZone):h=(h.isUnknownTimeZone,n.arcadeDateAndZoneToArcadeDate(h,d.timeZone))),c(i[2]).toLowerCase()){case"days":case"day":case"d":return d.diff(h,"days");case"months":case"month":return d.diff(h,"months");case"minutes":case"minute":case"m":return"M"===i[2]?d.diff(h,"months"):d.diff(h,"minutes");case"seconds":case"second":case"s":return d.diff(h,"seconds");case"milliseconds":case"millisecond":case"ms":default:return d.diff(h);case"hours":case"hour":case"h":return d.diff(h,"hours");case"years":case"year":case"y":return d.diff(h,"years")}}))},T.dateadd=function(n,e){return D(n,e,((r,t,i)=>{o(i,2,3,n,e);let m=a(i[1]);if(isNaN(m)||m===1/0||m===-1/0)return s(i[0])||l(i[0])?i[0].clone():f(i[0],u(n));let d="milliseconds";switch(c(i[2]).toLowerCase()){case"days":case"day":case"d":d="days",m=l(i[0])?m:h(m);break;case"months":case"month":d="months",m=l(i[0])?m:h(m);break;case"minutes":case"minute":case"m":d="M"===i[2]?"months":"minutes";break;case"seconds":case"second":case"s":d="seconds";break;case"milliseconds":case"millisecond":case"ms":d="milliseconds";break;case"hours":case"hour":case"h":d="hours";break;case"years":case"year":case"y":d="years"}if(s(i[0]))return i[0].plus(d,m);if(l(i[0]))return i[0].plus(d,m);const y=f(i[0],u(n));return null===y?null:y.plus({[d]:m})}))}}export{C as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as t}from"../executionError.js";import r from"../Feature.js";import{D as o,n as i,P as a,f as u,L as s,Q as d,S as f,w as c,T as m,U as l,g as p}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as y}from"../featureset/support/shared.js";import{SqlTimeStampOffset as w}from"../../core/sql/SqlTimestampOffset.js";import v from"../../core/sql/WhereClause.js";import{isString as b}from"../../support/guards.js";function h(e){const n=e?.fullSchema();return n?.datesInUnknownTimezone?"unknown":n?.dateFieldsTimeZone||"UTC"}function T(e){const n=e.fullSchema()?.fieldsIndex;return null==n&&e instanceof r?e.fieldsIndex:n}const I={getAttributeSQL(e,n){const t=e.field(n);if(null==t)return t;if(p(t)){const r=t.toDateTime(),o=T(e)?.get(n)?.type;return"esriFieldTypeTimestampOffset"===o||"timestamp-offset"===o?w.fromDateTime(r):r}return t}};function g(r,p,w){r.domain=function(r,d){return p(r,d,((f,c,m)=>{if(o(m,2,3,r,d),i(m[0])){const n=a(m[0],u(m[1]),void 0===m[2]?void 0:m[2]);return n&&n.domain?"coded-value"===n.domain.type||"codedValue"===n.domain.type?e.convertObjectToArcadeDictionary({type:"codedValue",name:n.domain.name,dataType:y[n.field.type],codedValues:n.domain.codedValues.map((e=>({name:e.name,code:e.code})))},s(r)):e.convertObjectToArcadeDictionary({type:"range",name:n.domain.name,dataType:y[n.field.type],min:n.domain.minValue,max:n.domain.maxValue},s(r)):null}throw new n(r,t.InvalidParameter,d)}))},r.domaincode=function(e,r){return p(e,r,((a,s,f)=>{if(o(f,2,4,e,r),i(f[0]))return d(f[0],u(f[1]),f[2],void 0===f[3]?void 0:f[3]);throw new n(e,t.InvalidParameter,r)}))},r.domainname=function(e,r){return p(e,r,((a,s,d)=>{if(o(d,2,4,e,r),i(d[0]))return f(d[0],u(d[1]),d[2],void 0===d[3]?void 0:d[3]);throw new n(e,t.InvalidParameter,r)}))},r.expects=function(e,r){return p(e,r,((o,i,a)=>{if(a.length<1)throw new n(e,t.WrongNumberOfParameters,r);return c}))},r.featureinfilter=function(e,r){return p(e,r,((e,r,a)=>{o(a,2,2,e,r);const[u,s]=a;if(null==u)return!1;if(""===s||null==s)return!0;if(!i(u)||!b(s))throw new n(e,t.InvalidParameter,r);const d=v.create(s,{fieldsIndex:T(u),timeZone:h(u)}),f=d.getVariables();for(const n of f)d.parameters[n]=w(e,{name:n});return d.testFeature(u,I)}))},r.gdbversion=function(e,r){return p(e,r,((a,u,s)=>{if(o(s,1,1,e,r),i(s[0]))return s[0].gdbVersion();throw new n(e,t.InvalidParameter,r)}))},r.schema=function(r,o){return p(r,o,((a,u,d)=>{if(i(d[0])){const n=m(d[0]);return n?e.convertObjectToArcadeDictionary(n,s(r)):null}throw new n(r,t.InvalidParameter,o)}))},r.subtypecode=function(e,r){return p(e,r,((a,u,s)=>{if(o(s,1,1,e,r),i(s[0])){const e=l(s[0]);if(!e)return null;if(e.subtypeField&&s[0].hasField(e.subtypeField)){const n=s[0].field(e.subtypeField);for(const t of e.subtypes)if(t.code===n)return t.code;return null}return null}throw new n(e,t.InvalidParameter,r)}))},r.subtypename=function(e,r){return p(e,r,((a,u,s)=>{if(o(s,1,1,e,r),i(s[0])){const e=l(s[0]);if(!e)return"";if(e.subtypeField&&s[0].hasField(e.subtypeField)){const n=s[0].field(e.subtypeField);for(const t of e.subtypes)if(t.code===n)return t.name;return""}return""}throw new n(e,t.InvalidParameter,r)}))},r.subtypes=function(r,a){return p(r,a,((u,d,f)=>{if(o(f,1,1,r,a),i(f[0])){const n=l(f[0]);return n?e.convertObjectToArcadeDictionary(n,s(r)):null}throw new n(r,t.InvalidParameter,a)}))}}export{g as registerFunctions};
5
+ import e from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as t}from"../executionError.js";import r from"../Feature.js";import{D as o,n as i,Q as a,f as u,L as s,S as d,T as f,w as c,U as m,V as l,g as p}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as y}from"../featureset/support/shared.js";import{SqlTimeStampOffset as w}from"../../core/sql/SqlTimestampOffset.js";import v from"../../core/sql/WhereClause.js";import{isString as b}from"../../support/guards.js";function h(e){const n=e?.fullSchema();return n?.datesInUnknownTimezone?"unknown":n?.dateFieldsTimeZone||"UTC"}function T(e){const n=e.fullSchema()?.fieldsIndex;return null==n&&e instanceof r?e.fieldsIndex:n}const I={getAttributeSQL(e,n){const t=e.field(n);if(null==t)return t;if(p(t)){const r=t.toDateTime(),o=T(e)?.get(n)?.type;return"esriFieldTypeTimestampOffset"===o||"timestamp-offset"===o?w.fromDateTime(r):r}return t}};function g(r,p,w){r.domain=function(r,d){return p(r,d,((f,c,m)=>{if(o(m,2,3,r,d),i(m[0])){const n=a(m[0],u(m[1]),void 0===m[2]?void 0:m[2]);return n&&n.domain?"coded-value"===n.domain.type||"codedValue"===n.domain.type?e.convertObjectToArcadeDictionary({type:"codedValue",name:n.domain.name,dataType:y[n.field.type],codedValues:n.domain.codedValues.map((e=>({name:e.name,code:e.code})))},s(r)):e.convertObjectToArcadeDictionary({type:"range",name:n.domain.name,dataType:y[n.field.type],min:n.domain.minValue,max:n.domain.maxValue},s(r)):null}throw new n(r,t.InvalidParameter,d)}))},r.domaincode=function(e,r){return p(e,r,((a,s,f)=>{if(o(f,2,4,e,r),i(f[0]))return d(f[0],u(f[1]),f[2],void 0===f[3]?void 0:f[3]);throw new n(e,t.InvalidParameter,r)}))},r.domainname=function(e,r){return p(e,r,((a,s,d)=>{if(o(d,2,4,e,r),i(d[0]))return f(d[0],u(d[1]),d[2],void 0===d[3]?void 0:d[3]);throw new n(e,t.InvalidParameter,r)}))},r.expects=function(e,r){return p(e,r,((o,i,a)=>{if(a.length<1)throw new n(e,t.WrongNumberOfParameters,r);return c}))},r.featureinfilter=function(e,r){return p(e,r,((e,r,a)=>{o(a,2,2,e,r);const[u,s]=a;if(null==u)return!1;if(""===s||null==s)return!0;if(!i(u)||!b(s))throw new n(e,t.InvalidParameter,r);const d=v.create(s,{fieldsIndex:T(u),timeZone:h(u)}),f=d.getVariables();for(const n of f)d.parameters[n]=w(e,{name:n});return d.testFeature(u,I)}))},r.gdbversion=function(e,r){return p(e,r,((a,u,s)=>{if(o(s,1,1,e,r),i(s[0]))return s[0].gdbVersion();throw new n(e,t.InvalidParameter,r)}))},r.schema=function(r,o){return p(r,o,((a,u,d)=>{if(i(d[0])){const n=m(d[0]);return n?e.convertObjectToArcadeDictionary(n,s(r)):null}throw new n(r,t.InvalidParameter,o)}))},r.subtypecode=function(e,r){return p(e,r,((a,u,s)=>{if(o(s,1,1,e,r),i(s[0])){const e=l(s[0]);if(!e)return null;if(e.subtypeField&&s[0].hasField(e.subtypeField)){const n=s[0].field(e.subtypeField);for(const t of e.subtypes)if(t.code===n)return t.code;return null}return null}throw new n(e,t.InvalidParameter,r)}))},r.subtypename=function(e,r){return p(e,r,((a,u,s)=>{if(o(s,1,1,e,r),i(s[0])){const e=l(s[0]);if(!e)return"";if(e.subtypeField&&s[0].hasField(e.subtypeField)){const n=s[0].field(e.subtypeField);for(const t of e.subtypes)if(t.code===n)return t.name;return""}return""}throw new n(e,t.InvalidParameter,r)}))},r.subtypes=function(r,a){return p(r,a,((u,d,f)=>{if(o(f,1,1,r,a),i(f[0])){const n=l(f[0]);return n?e.convertObjectToArcadeDictionary(n,s(r)):null}throw new n(r,t.InvalidParameter,a)}))}}export{g as registerFunctions};