@arcgis/core 4.34.0-next.74 → 4.34.0-next.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/PopupTemplate.js +1 -1
- package/applications/Components/QuantityFormatter.js +1 -1
- package/applications/Components/arcadeEditorUtils.d.ts +4 -0
- package/applications/Components/arcadeEditorUtils.js +5 -0
- package/applications/Components/featureUtils.d.ts +1 -0
- package/applications/Components/featureUtils.js +1 -1
- package/arcade/Feature.js +1 -1
- package/arcade/Pixel.js +5 -0
- package/arcade/Voxel.js +1 -1
- package/arcade/arcadeAsyncRuntime.js +1 -1
- package/arcade/arcadeCompiler.js +1 -1
- package/arcade/arcadeRuntime.js +1 -1
- package/arcade/featureSetUtils.js +1 -1
- package/arcade/featureset/actions/GroupBy.js +1 -1
- package/arcade/featureset/actions/OrderBy.js +1 -1
- package/arcade/featureset/support/FeatureSetIterator.js +1 -1
- package/arcade/functions/feature.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/arcade/functions/featuresetstring.js +1 -1
- package/arcade/functions/fieldStats.js +1 -1
- package/arcade/functions/geometry.js +1 -1
- package/arcade/functions/maths.js +1 -1
- package/arcade/functions/string.js +1 -1
- package/arcade/languageUtils.js +1 -1
- package/arcade.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/009556f323e58271bc7a.js +1 -0
- package/assets/esri/core/workers/chunks/{11acefc48c0354e675df.js → 0309d008e50e55c7ff1d.js} +1 -1
- package/assets/esri/core/workers/chunks/13de06e614adf92239fe.js +1 -0
- package/assets/esri/core/workers/chunks/14a22d1a0eefa970efa1.js +1 -0
- package/assets/esri/core/workers/chunks/16d66770ef841564ee3f.js +1 -0
- package/assets/esri/core/workers/chunks/17103e6542aae53c7301.js +1 -0
- package/assets/esri/core/workers/chunks/{dd447dfc50ee7f511b84.js → 19c1f1431c0b2f4525a2.js} +1 -1
- package/assets/esri/core/workers/chunks/{5c30252c1bb8350cae5f.js → 1c52999a6392370844a6.js} +1 -1
- package/assets/esri/core/workers/chunks/21bfad7283620766d9cd.js +1 -0
- package/assets/esri/core/workers/chunks/{7219ceab0b6fae2e69b6.js → 280af3640f8e93c1024e.js} +2 -2
- package/assets/esri/core/workers/chunks/{49f7a5523462aebf90fc.js.LICENSE.txt → 280af3640f8e93c1024e.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/3064320d54a9b48bd697.js +1 -0
- package/assets/esri/core/workers/chunks/3a5f0c759dd2f4638343.js +1 -0
- package/assets/esri/core/workers/chunks/{d12f373fcf5848ddcd8a.js → 3f523bc8551e712c9bd4.js} +1 -1
- package/assets/esri/core/workers/chunks/{5b7e5ec6aea1f7f9b005.js → 3fecfe4f8ca2a5fd7360.js} +1 -1
- package/assets/esri/core/workers/chunks/4832faefd3b7edc17c84.js +1 -0
- package/assets/esri/core/workers/chunks/{78b33c6d73824085c6d1.js → 48449abe795cb7a831eb.js} +1 -1
- package/assets/esri/core/workers/chunks/4d47187bc0821413492d.js +1 -0
- package/assets/esri/core/workers/chunks/5102c20645d9708c34b4.js +1 -0
- package/assets/esri/core/workers/chunks/541bffd61006d0e36166.js +1 -0
- package/assets/esri/core/workers/chunks/58cc06ed86301f4cee75.js +1 -0
- package/assets/esri/core/workers/chunks/{e12e8d69c05c182b6a69.js → 61bb39597ccf89f99a72.js} +1 -1
- package/assets/esri/core/workers/chunks/{f4e9640306f64b1af7a3.js → 65ec21d29e8563fdbc55.js} +1 -1
- package/assets/esri/core/workers/chunks/67d9cfe02613cb73ee37.js.LICENSE.txt +1 -1
- package/assets/esri/core/workers/chunks/{6dc62c170e9583222df2.js → 70367da4ba916376f40c.js} +1 -1
- package/assets/esri/core/workers/chunks/{fb669a2e50ca7aacac25.js → 71fef0a33b7ed9456e47.js} +1 -1
- package/assets/esri/core/workers/chunks/7430c462c350fdd26349.js +1 -0
- package/assets/esri/core/workers/chunks/{ff3fe5c97a98c8cab4ac.js → 7a23b127f551bf13ef54.js} +2 -2
- package/assets/esri/core/workers/chunks/{ff3fe5c97a98c8cab4ac.js.LICENSE.txt → 7a23b127f551bf13ef54.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/7b73a808922b52755abd.js +1 -0
- package/assets/esri/core/workers/chunks/{d682dd49bb9ee7f48f93.js → 9304c3cdf732745577fd.js} +1 -1
- package/assets/esri/core/workers/chunks/{8d642b34d40edfe02d8e.js → 9c64b78c5c9b35b31d98.js} +2 -2
- package/assets/esri/core/workers/chunks/{8d642b34d40edfe02d8e.js.LICENSE.txt → 9c64b78c5c9b35b31d98.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/a0edff37fd4a3f2cb2eb.js +1 -0
- package/assets/esri/core/workers/chunks/a6533bab3b2fbc1e2a47.js +1 -0
- package/assets/esri/core/workers/chunks/a9f6054d86982b9e5a7c.js +1 -0
- package/assets/esri/core/workers/chunks/{10ec10ca361842efce92.js → ab005fe84952f0676020.js} +1 -1
- package/assets/esri/core/workers/chunks/{5c53deb45bc142219c76.js → b15ff6c9ef2de8a49853.js} +2 -2
- package/assets/esri/core/workers/chunks/{5a476e6743902e35f81a.js.LICENSE.txt → b15ff6c9ef2de8a49853.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/b70d71144a060f7eeeeb.js +1 -0
- package/assets/esri/core/workers/chunks/b8d02f1b73c374767a5f.js +1 -0
- package/assets/esri/core/workers/chunks/ba6452acee3d6defb37e.js +1 -0
- package/assets/esri/core/workers/chunks/bccecd678faff927ac76.js +1 -0
- package/assets/esri/core/workers/chunks/{ce1f4508487298ab57b6.js → bd2dc1282c49125ede89.js} +1 -1
- package/assets/esri/core/workers/chunks/bfbbf180c2c8fdbb6731.js +1 -0
- package/assets/esri/core/workers/chunks/{f542bdc994a5ea3aa9d1.js → c38360d912f256519e06.js} +1 -1
- package/assets/esri/core/workers/chunks/{e3ad0a390387c5847aca.js → c6fecf2bbd2a711f15d3.js} +1 -1
- package/assets/esri/core/workers/chunks/c86f5bb199cf046b8952.js +1 -0
- package/assets/esri/core/workers/chunks/cd1869e183001266c4c1.js +2 -0
- package/assets/esri/core/workers/chunks/{626c18c1bbc50b3b16b2.js.LICENSE.txt → cd1869e183001266c4c1.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/{90321feb56f3a84f6e58.js → d153b29c542c37ae1636.js} +2 -2
- package/assets/esri/core/workers/chunks/{90321feb56f3a84f6e58.js.LICENSE.txt → d153b29c542c37ae1636.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/{b5f197e24982f6e14468.js → d1f181f91b36351f1d3b.js} +2 -2
- package/assets/esri/core/workers/chunks/d55c55d39a253630d228.js +1 -0
- package/assets/esri/core/workers/chunks/{49f7a5523462aebf90fc.js → d66cdb9bb494da19696b.js} +2 -2
- package/assets/esri/core/workers/chunks/{5c53deb45bc142219c76.js.LICENSE.txt → d66cdb9bb494da19696b.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/{9c00c2263e52ad51c2a2.js → d95554f43694b4769675.js} +1 -1
- package/assets/esri/core/workers/chunks/dd587d51dad2d82708d1.js +1 -0
- package/assets/esri/core/workers/chunks/ecac5ca00c742bfb5898.js +1 -0
- package/assets/esri/core/workers/chunks/ed773dab5965e42a2879.js +2 -0
- package/assets/esri/core/workers/chunks/{7219ceab0b6fae2e69b6.js.LICENSE.txt → ed773dab5965e42a2879.js.LICENSE.txt} +1 -1
- package/assets/esri/core/workers/chunks/{0d946a226b846b3c0849.js → fc06014fb484fc8c697e.js} +1 -1
- package/assets/esri/images/portal/xrexperience16.png +0 -0
- package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
- package/assets/esri/libs/lyr3d/lyr3DWorker.wasm +0 -0
- package/chunks/Compositing.glsl.js +4 -3
- package/chunks/Fog.glsl.js +6 -6
- package/chunks/GlowComposition.glsl.js +31 -12
- package/chunks/LineMarker.glsl.js +37 -36
- package/chunks/RibbonLine.glsl.js +83 -83
- package/chunks/array.js +1 -1
- package/chunks/cameraUtilsSpherical.js +1 -1
- package/chunks/languageUtils.js +1 -1
- package/chunks/lyr3DMain.js +1 -1
- package/chunks/lyr3DWorker.js +1 -1
- package/config.js +1 -1
- package/core/quantityFormatUtils.js +1 -1
- package/core/sql.d.ts +1 -0
- package/core/unitFormatUtils.js +1 -1
- package/core/unitUtils.js +1 -1
- package/form/FormTemplate.js +1 -1
- package/geometry/support/curves/circleUtils.js +1 -1
- package/geometry/support/curves/circularArcUtils.js +1 -1
- package/geometry/support/curves/closestPointOnCurve.js +1 -1
- package/geometry/support/curves/curveExtent.js +1 -1
- package/geometry/support/curves/lineUtils.js +5 -0
- package/geometry/support/heightModelInfoUtils.js +1 -1
- package/geometry/support/normalizeUtils.js +1 -1
- package/geometry/support/spatialReferenceUtils.js +1 -1
- package/interfaces.d.ts +315 -18
- package/kernel.js +1 -1
- package/layers/GaussianSplatLayer.js +1 -1
- package/layers/ImageryLayer.js +1 -1
- package/layers/ImageryTileLayer.js +1 -1
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/Lyr3DWorkerHandle.js +1 -1
- package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
- package/layers/support/fieldUtils.js +1 -1
- package/layers/support/tiles3DUtils.js +1 -1
- package/networks/CircuitManager.js +1 -1
- package/networks/support/Circuit.js +1 -1
- package/networks/support/CircuitSection.js +1 -1
- package/networks/support/Subcircuit.js +1 -1
- package/package.json +2 -2
- package/portal/PortalItem.js +1 -1
- package/renderers/ClassBreaksRenderer.js +1 -1
- package/renderers/DictionaryRenderer.js +1 -1
- package/renderers/DotDensityRenderer.js +1 -1
- package/renderers/HeatmapRenderer.js +1 -1
- package/renderers/PieChartRenderer.js +1 -1
- package/renderers/UniqueValueRenderer.js +1 -1
- package/renderers/mixins/VisualVariablesMixin.js +1 -1
- package/support/arcadeUtils.js +1 -1
- package/support/loadArcade.js +1 -1
- package/support/modeUtils.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/CIMSymbol.js +1 -1
- package/symbols/support/FeatureExpressionInfo.js +1 -1
- package/views/2d/layers/LayerView2D.js +1 -1
- package/views/2d/layers/MediaLayerView2D.js +1 -1
- package/views/2d/layers/TileLayerView2D.js +1 -1
- package/views/3d/analysis/Dimension/DimensionVisualization.js +1 -1
- package/views/3d/analysis/Dimension/LengthDimensionSubTool.js +1 -1
- package/views/3d/analysis/Dimension/lengthDimensionManipulatorUtils.js +1 -1
- package/views/3d/analysis/Slice/ResizeManipulator.js +1 -1
- package/views/3d/analysis/Slice/RotateManipulator.js +1 -1
- package/views/3d/analysis/Slice/ShiftManipulator.js +1 -1
- package/views/3d/analysis/Viewshed/ViewshedFieldOfViewManipulation.js +1 -1
- package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementTool.js +1 -1
- package/views/3d/environment/Fog.js +1 -1
- package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/LineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/MarkerVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/OutlineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
- package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
- package/views/3d/layers/FlowSubView3D.js +1 -1
- package/views/3d/layers/GaussianSplatLayerView3D.js +1 -1
- package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
- package/views/3d/layers/Lyr3DWorker.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
- package/views/3d/layers/i3s/PointCloudRenderer.js +1 -1
- package/views/3d/layers/support/Tiles3DIntersectionHandler.js +1 -1
- package/views/3d/state/SurfaceCollisionConstraint.js +1 -1
- package/views/3d/state/ViewStateManager.js +1 -1
- package/views/3d/state/controllers/SurfaceCollisionCorrectionController.js +1 -1
- package/views/3d/support/cameraUtils.js +1 -1
- package/views/3d/support/cameraUtilsSpherical.js +1 -1
- package/views/3d/support/flow/FlowSubViewExtent3D.js +1 -1
- package/views/3d/support/flow/FlowSubViewTiles3D.js +1 -1
- package/views/3d/support/flow/FlowWorker.js +1 -1
- package/views/3d/support/flow/geometryUtils.js +1 -1
- package/views/3d/support/flow/loadUtils.js +1 -1
- package/{layers/support/GaussianSplatAtlasPageAllocator.js → views/3d/support/gaussianSplatting/GaussianSplatAtlasPages.js} +1 -1
- package/views/3d/support/gaussianSplatting/GaussianSplatDataStore.js +5 -0
- package/views/3d/support/gaussianSplatting/GaussianSplatOrderTexture.js +5 -0
- package/views/3d/support/gaussianSplatting/GaussianSplatTextureAtlas.js +5 -0
- package/views/3d/support/gaussianSplatting/GaussianTile.js +5 -0
- package/views/3d/terrain/OverlayManager.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/attributes/RibbonVertexPosition.glsl.js +23 -13
- package/views/3d/webgl-engine/core/shaderLibrary/shading/LineStipple.glsl.js +37 -25
- package/views/3d/webgl-engine/core/shaderLibrary/shading/MarkerSizing.glsl.js +11 -11
- package/views/3d/webgl-engine/core/shaderLibrary/util/NoPerspective.glsl.js +5 -0
- package/views/3d/webgl-engine/effects/glow/GlowComposition.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/glow/GlowPresets.glsl.js +1 -1
- package/views/3d/webgl-engine/effects/glow/GlowRenderNode.js +1 -1
- package/views/3d/webgl-engine/lib/CompositingHelper.js +1 -1
- package/views/3d/webgl-engine/lib/GaussianSplatRenderNode.js +1 -1
- package/views/3d/webgl-engine/lib/GridLocalOriginFactory.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/strokes.js +1 -1
- package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/stippleTextureRepository.js +1 -1
- package/views/3d/webgl-engine/parts/RenderView.js +1 -1
- package/views/3d/webgl-engine/shaders/CompositingTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/CompositingTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/shaders/LineMarker.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/LineMarkerTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLine.glsl.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLineTechniqueConfiguration.js +1 -1
- package/views/3d/webgl-engine/shaders/sources/edgeRenderer/LineOffset.glsl.js +10 -11
- package/views/GroundView.js +1 -1
- package/views/VideoView.js +1 -1
- package/views/interactive/snapping/allLayerSnapping.js +1 -1
- package/views/layers/ImageryLayerView.js +1 -1
- package/views/support/LayerViewManager.js +1 -1
- package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
- package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
- package/widgets/support/widget.js +1 -1
- package/assets/esri/core/workers/chunks/06bd58c219678315cf5c.js +0 -1
- package/assets/esri/core/workers/chunks/0751f539db31bdb5caec.js +0 -1
- package/assets/esri/core/workers/chunks/19228ab0fe7944c554e5.js +0 -1
- package/assets/esri/core/workers/chunks/2a19a4d7d1c580121065.js +0 -1
- package/assets/esri/core/workers/chunks/3d2629357242492afcfa.js +0 -1
- package/assets/esri/core/workers/chunks/5a476e6743902e35f81a.js +0 -2
- package/assets/esri/core/workers/chunks/5a95688651d7e8b7101d.js +0 -1
- package/assets/esri/core/workers/chunks/5c4ba165816809e06340.js +0 -1
- package/assets/esri/core/workers/chunks/5f239972cb95afdfa77a.js +0 -1
- package/assets/esri/core/workers/chunks/626c18c1bbc50b3b16b2.js +0 -2
- package/assets/esri/core/workers/chunks/6963ded8428cc8d51d85.js +0 -1
- package/assets/esri/core/workers/chunks/6c3ae96c6ef764fb9552.js +0 -1
- package/assets/esri/core/workers/chunks/6da298da2ec09cced0b5.js +0 -1
- package/assets/esri/core/workers/chunks/76ec3d2646ba64e3442f.js +0 -1
- package/assets/esri/core/workers/chunks/8b1d2bbb2b2eb1830921.js +0 -1
- package/assets/esri/core/workers/chunks/925ad2665c2fe0f47cc3.js +0 -1
- package/assets/esri/core/workers/chunks/a2f4b6d8da93f106852c.js +0 -1
- package/assets/esri/core/workers/chunks/ada8e07ff12bc5d4a1d9.js +0 -1
- package/assets/esri/core/workers/chunks/b03dcbc31bccb9fdf9fe.js +0 -1
- package/assets/esri/core/workers/chunks/b0de01f8c9b1c3182e0c.js +0 -1
- package/assets/esri/core/workers/chunks/c7ba8f2aca0fbd6ceded.js +0 -1
- package/assets/esri/core/workers/chunks/c908184d747d33366881.js +0 -1
- package/assets/esri/core/workers/chunks/d1711256493d55eca523.js +0 -1
- package/assets/esri/core/workers/chunks/d305ca524837c5dc81c8.js +0 -1
- package/assets/esri/core/workers/chunks/e6e4e2fb9568319c6207.js +0 -1
- package/assets/esri/core/workers/chunks/e6f2ac738df16fb5e13a.js +0 -1
- package/assets/esri/core/workers/chunks/e8d25d4ca9b335883f34.js +0 -1
- package/assets/esri/core/workers/chunks/ee391a41144855fc625d.js +0 -1
- package/assets/esri/core/workers/chunks/f060a52a9b69eb250d63.js +0 -1
- package/layers/support/gaussianSplatUtils.js +0 -5
package/arcade/arcadeRuntime.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as i}from"./compilerUtils.js";import{getNestedOptionalValue as s,getGeometryKeys as l,geometryMember as a}from"./containerUtils.js";import c from"./Dictionary.js";import{ArcadeExecutionError as u,ensureArcadeExecutionError as f}from"./executionError.js";import p from"./Feature.js";import{NativeFunction as h,ArcadeFunction as d,ScopeMarshalledFunction as w,wrapModuleScopedResponse as m}from"./FunctionWrapper.js";import{R as g,I as b,q as y,i as v,z as x,A as S,v as F,B as R,x as I,j,r as O,h as A,s as M,u as N,w as k,y as C,k as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as G}from"../chunks/array.js";import{registerFunctions as U}from"./functions/date.js";import{registerFunctions as D}from"./functions/feature.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as L}from"./functions/geomsync.js";import{registerFunctions as _}from"./functions/maths.js";import{registerFunctions as z}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import{registerFunctions as q}from"./functions/track.js";import"../core/has.js";import W from"../core/Logger.js";import P from"../geometry/Geometry.js";import V from"../geometry/SpatialReference.js";import{isGraphic as T,isBoolean as Y,isArray as $,isString as H,isNumber as J}from"../support/guards.js";const Q=()=>W.getLogger("esri.arcade.arcadeRuntime"),X=Symbol("uninitialized");function ee(e){if(e===X)throw new u(null,"InvalidIdentifier",null)}function te(e){return ee(e),e}function ne(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new u(t,"InvalidIdentifier",n)}function re(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return ee(e),e.value}const i=t.globalScope[o];if(void 0!==i)return ee(i),i.value;throw new u(t,r,n)}const oe=function(){};oe.prototype=Object.freeze(Object.create(null));class ie extends d{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,services:this.context.services,timeZone:this.context.timeZone??null,lrucache:this.context.lrucache,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,abortSignal:this.context.abortSignal,localScope:new oe,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",null);return se(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return ce(e,t,(n,r,o)=>{const i={spatialReference:e.spatialReference,services:e.services,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,timeZone:e.timeZone??null,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,abortSignal:e.abortSignal,localScope:new oe,track:e.track};if(i.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",t);return se(i,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,(o,i,s)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,services:e.services,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,abortSignal:e.abortSignal,localScope:new oe,track:e.track};return s=s.map(t=>!v(t)||t instanceof w?t:m(t,e,r)),m(se(l,this.definition.body,this._params,this._locals,s,t),n,r)})}}function se(e,t,n,r,o,i){try{if(n.length!==o.length)throw new u(e,"WrongNumberOfParameters",i);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=X}const s=fe(e,t);if(s instanceof g)return s.value;if(s===x)throw new u(e,"UnexpectedToken",i);if(s===S)throw new u(e,"UnexpectedToken",i);return s instanceof b?s.value:s}catch(s){throw s}}class le extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t),r=this.moduleGlobalContext.globalScope[n];if(ee(r),v(r.value)&&!(r.value instanceof w)){const e=new w;return e.fn=r.value,e.parameterEvaluator=ce,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(v(n))throw new u(null,"AssignModuleFunction",null);const r=e(t);if(void 0===this.moduleGlobalContext.globalScope[r])throw new u(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static load(e,n){const{globals:i,exports:s}=o(n),l=new Ve;for(const t of i)t in l||(l[t]=X);const a=e.spatialReference??V.WebMercator,c={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:a,track:e.track,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:s,localScope:null,globalScope:l};return Fe(c,n),new le(c)}}function ae(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(ue(e,t.arguments[r]));return n}function ce(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,ae(e,t))}catch(r){throw r}}function ue(e,t){try{switch(t.type){case"AssignmentExpression":return ve(e,t);case"UpdateExpression":return be(e,t);case"TemplateLiteral":return Ue(e,t);case"Identifier":return De(e,t);case"MemberExpression":return Ne(e,t);case"Literal":return t.value;case"CallExpression":return Ke(e,t);case"UnaryExpression":return ke(e,t);case"BinaryExpression":return Ee(e,t);case"LogicalExpression":return Be(e,t);case"ArrayExpression":return Ce(e,t);case"ObjectExpression":return pe(e,t);default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}function fe(e,t){switch(t.type){case"EmptyStatement":return F;case"VariableDeclaration":return Ae(e,t);case"ImportDeclaration":return je(e,t);case"ExportNamedDeclaration":return Oe(e,t);case"BlockStatement":return Fe(e,t);case"FunctionDeclaration":return Ie(e,t);case"ReturnStatement":return Re(e,t);case"IfStatement":return Se(e,t);case"ExpressionStatement":return xe(e,t);case"BreakStatement":return x;case"ContinueStatement":return S;case"ForStatement":return we(e,t);case"ForInStatement":return he(e,t);case"ForOfStatement":return de(e,t);case"WhileStatement":return me(e,t);default:throw new u(e,"Unrecognized",t)}}function pe(e,t){const n=Object.create(null),r=new Map;for(let i=0;i<t.properties.length;i++){const o=t.properties[i],s="Identifier"===o.key.type?o.key.name:ue(e,o.key),l=ue(e,o.value);if(v(l))throw new u(e,"NoFunctionInDictionary",t);if(!1===H(s))throw new u(e,"KeyMustBeString",t);let a=s.toString();const c=a.toLowerCase();r.has(c)?a=r.get(c):r.set(c,a),n[a]=l===F?null:l}const o=new c(n);return o.immutable=!1,o}function he(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&Ae(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let n=0;n<o;n++){r.scope[r.id]={value:n};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}if(n instanceof c||O(n)){const o=n.keys();for(let n=0;n<o.length;n++){r.scope[r.id]={value:o[n]};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(A(n)){for(const o of l(n)){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}return F}function de(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&fe(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let i=0;i<o;i++){if(i>=n.length)throw new u(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:n.get(o)};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(n instanceof c||O(n)){for(const o of n.keys()){const i=n.field(o);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}if(A(n)){for(const o of l(n)){const i=a(n,o,e,t,1);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}return F}function we(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?fe(e,t.init):ue(e,t.init));const n={testResult:!0,lastAction:F};do{ge(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof g?n.lastAction:F}function me(e,t){const n={testResult:!0,lastAction:F};if(n.testResult=ue(e,t.test),!1===n.testResult)return F;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t);for(;!0===n.testResult&&(n.lastAction=fe(e,t.body),n.lastAction!==x)&&!(n.lastAction instanceof g);)if(n.testResult=ue(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new u(e,"BooleanConditionRequired",t);return n.lastAction instanceof g?n.lastAction:F}function ge(e,t,n){if(null!==t.test){if(n.testResult=ue(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t)}n.lastAction=fe(e,t.body),n.lastAction!==x?n.lastAction instanceof g?n.testResult=!1:null!==t.update&&ue(e,t.update):n.testResult=!1}function be(e,t){if("CallExpression"===t.argument.type)throw new u(e,"NeverReach",t);let n;if("MemberExpression"===t.argument.type){const r=ue(e,t.argument.object);let o;if(!0===t.argument.computed)o=ue(e,t.argument.property);else{if("Identifier"!==t.argument.property.type)throw new u(e,"Unrecognized",t);o=t.argument.property.name}if($(r)){if(!J(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new u(e,"OutOfBounds",t);n=M(r[o]),r[o]="++"===t.operator?n+1:n-1}else if(r instanceof c){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else if(E(r)){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else{if(j(r))throw new u(e,"Immutable",t);if(!(r instanceof le))throw new u(e,"InvalidParameter",t);if(!1===H(o))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);n=M(r.global(o)),r.setGlobal(o,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}const r=ne(e,t.argument);n=M(te(r.var).value);const o="++"===t.operator?n+1:n-1;return r.scope[r.id]={value:o},!1===t.prefix?n:"++"===t.operator?n+1:n-1}function ye(e,t,n,r,o){switch(t){case"=":return e===F?null:e;case"/=":return M(n)/M(e);case"*=":return M(n)*M(e);case"-=":return M(n)-M(e);case"+=":return H(n)||H(e)?N(n)+N(e):M(n)+M(e);case"%=":return M(n)%M(e);default:throw new u(o,"UnsupportedOperator",r)}}function ve(e,t){if("MemberExpression"===t.left.type){const n=ue(e,t.left.object);let r;if(!0===t.left.computed)r=ue(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new u(e,"InvalidIdentifier",t);r=t.left.property.name}const o=ue(e,t.right);if($(n)){if(!J(r))throw new u(e,"ArrayAccessMustBeNumber",t);if(r<0&&(r=n.length+r),r<0||r>n.length)throw new u(e,"OutOfBounds",t);if(r===n.length){if("="!==t.operator)throw new u(e,"OutOfBounds",t);n[r]=ye(o,t.operator,n[r],t,e)}else n[r]=ye(o,t.operator,n[r],t,e)}else if(n instanceof c){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else if(E(n)){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else{if(j(n))throw new u(e,"Immutable",t);if(!(n instanceof le))throw new u(e,"InvalidIdentifier",t);if(!1===H(r))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==n.hasGlobal(r))throw new u(e,"ModuleExportNotFound",t);n.setGlobal(r,ye(o,t.operator,n.global(r),t,e))}return F}const n=ne(e,t.left),r=ue(e,t.right);return n.scope[n.id]={value:ye(r,t.operator,"="!==t.operator?te(n.var).value:null,t,e)},F}function xe(e,t){const n=ue(e,t.expression);return n===F?F:new b(n)}function Se(e,t){const n=ue(e,t.test);if(!0===n)return fe(e,t.consequent);if(!1===n)return null!==t.alternate?fe(e,t.alternate):F;throw new u(e,"BooleanConditionRequired",t)}function Fe(e,t){let n=F;for(let r=0;r<t.body.length;r++)if(n=fe(e,t.body[r]),n instanceof g||n===x||n===S)return n;return n}function Re(e,t){if(null===t.argument)return new g(F);const n=ue(e,t.argument);return new g(n)}function Ie(t,n){if(null!=t.localScope)throw Q().error("Function declarations are only valid in global scope."),new u(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw Q().error(`Function "${r}" not declared.`),new u(t,"NeverReach",n);const o=i(n),s=n.params.map(t=>e(t)),l=Array.from(o).filter(e=>!s.includes(e));return t.globalScope[r]={value:new ie(n,t,s,l)},F}function je(e,t){const n=ne(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw Q().error("Internal error: module loader not initialized"),new u(e,"NeverReach",t);const o=r.loadLibrary(n.id);let i;return r._moduleSingletons?.has(o.uri)?i=r._moduleSingletons.get(o.uri):(i=le.load(e,o.syntax),r._moduleSingletons?.set(o.uri,i)),n.scope[n.id]={value:i},F}function Oe(e,t){return fe(e,t.declaration),F}function Ae(e,t){for(let n=0;n<t.declarations.length;n++)Me(e,t.declarations[n]);return F}function Me(e,t){let n=null===t.init?null:ue(e,t.init);if(n===F&&(n=null),"Identifier"!==t.id.type)throw new u(e,"InvalidIdentifier",t);const r=ne(e,t.id);r.scope[r.id]={value:n}}function Ne(e,t){try{const n=ue(e,t.object);if(null===n)throw new u(e,"MemberOfNull",t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof c||O(n))return n.field(t.property.name);if(n instanceof P)return a(n,t.property.name,e,t);if(n instanceof le){if(!n.hasGlobal(t.property.name))throw new u(e,"InvalidIdentifier",t);return n.global(t.property.name)}}throw new u(e,"InvalidMemberAccessKey",t)}let r=ue(e,t.property);if(n instanceof c||O(n)){if(H(r))return n.field(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof le){if(H(r))return n.global(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof P){if(H(r))return a(n,r,e,t);throw new u(e,"InvalidMemberAccessKey",t)}if($(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(H(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(j(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new u(e,"OutOfBounds",t);return n.get(r)}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}catch(n){throw n}}function ke(e,t){try{const n=ue(e,t.argument);if(Y(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);if("~"===t.operator)return~M(n);throw new u(e,"UnsupportUnaryOperator",t)}if("~"===t.operator)return~M(n);if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);throw new u(e,"UnsupportUnaryOperator",t)}catch(n){throw n}}function Ce(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=ue(e,t.elements[r]);if(v(o))throw new u(e,"NoFunctionInArray",t);o===F?n.push(null):n.push(o)}return n}catch(n){throw n}}function Ee(e,t){try{const n=ue(e,t.left),r=ue(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return C(M(n),M(r),t.operator);case"==":return I(n,r);case"!=":return!I(n,r);case"<":case">":case"<=":case">=":return k(n,r,t.operator);case"+":return H(n)||H(r)?N(n)+N(r):M(n)+M(r);case"-":return M(n)-M(r);case"*":return M(n)*M(r);case"/":return M(n)/M(r);case"%":return M(n)%M(r);default:throw new u(e,"UnsupportedOperator",t)}}catch(n){throw n}}function Be(e,t){try{const n=ue(e,t.left);if(Y(n))switch(t.operator){case"||":{if(!0===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}default:throw new u(e,"LogicExpressionOrAnd",t)}throw new u(e,"LogicalExpressionOnlyBoolean",t)}catch(n){throw n}}function Ge(e,t,n){if(v(e))throw new u(t,"NoFunctionInTemplateLiteral",n);return e}function Ue(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){n+=t.expressions[r]?N(Ge(ue(e,t.expressions[r]),e,t)):"",r++}return n}function De(e,t){return re(e,t)}function Ke(e,t){try{if("MemberExpression"===t.callee.type){const n=ue(e,t.callee.object);if(!(n instanceof le))throw new u(e,"FunctionNotFound",t);const r=!1===t.callee.computed?t.callee.property.name:ue(e,t.callee.property);if(!n.hasGlobal(r))throw new u(e,"FunctionNotFound",t);const o=n.global(r);if(!v(o))throw new u(e,"CallNonFunction",t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new u(e,"FunctionNotFound",t);const n=re(e,t.callee,"FunctionNotFound");if(v(n))return n.call(e,t);throw new u(e,"CallNonFunction",t)}catch(n){throw n}}function Le(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,3,3,e,t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",t);return ue(e,!0===r?n[1]:n[2])}catch(n){throw n}}function _e(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,2,3,e,t);const r=ue(e,n[0]);if(3===n.length){const t=ue(e,n[1]),o=s(r,t);return null!=o&&""!==o?o:ue(e,n[2])}return null===r||""===r||void 0===r?ue(e,n[1]):r}catch(n){throw n}}function ze(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<2)throw new u(e,"WrongNumberOfParameters",t);if(2===n.length)return ue(e,n[1]);{if((n.length-1)%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);return Ze(e,t,1,r)}}catch(n){throw n}}function Ze(e,t,n,r){try{const o=t.arguments,i=ue(e,o[n]);if(I(i,r))return ue(e,o[n+1]);{const i=o.length-n;return 1===i?ue(e,o[n]):2===i?null:3===i?ue(e,o[n+2]):Ze(e,t,n+2,r)}}catch(o){throw o}}function qe(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<3)throw new u(e,"WrongNumberOfParameters",t);if(n.length%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",n[0]);return We(e,t,0,r)}catch(n){throw n}}function We(e,t,n,r){try{const o=t.arguments;if(!0===r)return ue(e,o[n+1]);if(3===o.length-n)return ue(e,o[n+2]);{const r=ue(e,o[n+2]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",o[n+2]);return We(e,t,n+2,r)}}catch(o){throw o}}function Pe(){const e=Object.create(null);U(e,ce),Z(e,ce),D(e,ce,De),_(e,ce),K(e,ce),z(e,ce),L(e,ce),q(e,ce),e.iif=Le,e.defaultvalue=_e,e.decode=ze,e.when=qe;const t=function(){this.textformatting={value:c.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new h(r)});return t}const Ve=Pe();function Te(e){const t={mode:"sync",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ce,evaluateIdentifier:De};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Ve.prototype[n]=Object.freeze({value:new h(r)});for(let n=0;n<t.signatures.length;n++)B(t.signatures[n],"sync")}function Ye(e){console.log(e)}function $e(n,i){const s=new Set(Object.keys(i?.vars||{}).map(t=>e(t))),l=new Set(Object.keys(i?.customfunctions||{}).map(t=>e(t))),{globals:a,exports:c}=o(n);return e=>{const o=e.spatialReference??V.WebMercator;let i=null;n.usesModules&&(i=new r(new Map,n.loadedModules));const f=new Ve;for(const t of l)null!=e.customfunctions&&t in e.customfunctions?f[t]={value:new h(e.customfunctions[t])}:f[t]=X;for(const t of s){if(null==e.vars||!(t in e.vars)){t in f||(f[t]=X);continue}const n=e.vars[t]??null;T(n)?f[t]={value:p.createFromGraphic(n,e.timeZone??null)}:f[t]={value:n}}for(const t of a)t in f||(f[t]=X);const d={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:i,exports:c,localScope:null,globalScope:f},w=Fe(d,n);if(w instanceof g||w instanceof b){const e=w.value;if(y(e))return null;if(v(e))throw new u(d,"IllegalResult",null);return e}if(y(w))return null;if(w===x)throw new u(d,"IllegalResult",null);if(w===S)throw new u(d,"IllegalResult",null);throw new u(d,"NeverReach",null)}}function He(e,t){return $e(e,t)(t)}Te([G]);export{He as executeScript,Te as extend,$e as prepareScript};
|
|
5
|
+
import{toSymbolId as e,neverAbortedSignal as t}from"./arcadeEnvironment.js";import{ArcadeModule as n}from"./ArcadeModule.js";import{ArcadeModuleLoader as r}from"./ArcadeModuleLoader.js";import{collectDeclaredGlobalNames as o,collectDeclaredLocalNames as i}from"./compilerUtils.js";import{getNestedOptionalValue as s,getGeometryKeys as l,geometryMember as a}from"./containerUtils.js";import c from"./Dictionary.js";import{ArcadeExecutionError as u,ensureArcadeExecutionError as f}from"./executionError.js";import{Feature as p}from"./Feature.js";import{NativeFunction as h,ArcadeFunction as d,ScopeMarshalledFunction as w,wrapModuleScopedResponse as m}from"./FunctionWrapper.js";import{R as g,I as b,q as y,i as v,z as x,A as S,v as F,B as R,x as I,j,r as O,h as A,s as M,u as N,w as k,y as C,k as E}from"../chunks/languageUtils.js";import{addFunctionDeclaration as B}from"./treeAnalysis.js";import{A as G}from"../chunks/array.js";import{registerFunctions as U}from"./functions/date.js";import{registerFunctions as D}from"./functions/feature.js";import{registerFunctions as K}from"./functions/geometry.js";import{registerFunctions as L}from"./functions/geomsync.js";import{registerFunctions as _}from"./functions/maths.js";import{registerFunctions as z}from"./functions/stats.js";import{registerFunctions as Z}from"./functions/string.js";import{registerFunctions as q}from"./functions/track.js";import"../core/has.js";import W from"../core/Logger.js";import P from"../geometry/Geometry.js";import V from"../geometry/SpatialReference.js";import{isGraphic as T,isBoolean as Y,isArray as $,isString as H,isNumber as J}from"../support/guards.js";const Q=()=>W.getLogger("esri.arcade.arcadeRuntime"),X=Symbol("uninitialized");function ee(e){if(e===X)throw new u(null,"InvalidIdentifier",null)}function te(e){return ee(e),e}function ne(t,n){const r=e(n);if(null!==t.localScope){const e=t.localScope[r];if(void 0!==e)return{scope:t.localScope,id:r,var:e}}const o=t.globalScope[r];if(void 0!==o)return{scope:t.globalScope,id:r,var:o};throw new u(t,"InvalidIdentifier",n)}function re(t,n,r="InvalidIdentifier"){const o=e(n);if(null!==t.localScope){const e=t.localScope[o];if(void 0!==e)return ee(e),e.value}const i=t.globalScope[o];if(void 0!==i)return ee(i),i.value;throw new u(t,r,n)}const oe=function(){};oe.prototype=Object.freeze(Object.create(null));class ie extends d{constructor(e,t,n,r){super(),this.definition=e,this.context=t,this._params=n,this._locals=r}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,services:this.context.services,timeZone:this.context.timeZone??null,lrucache:this.context.lrucache,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,abortSignal:this.context.abortSignal,localScope:new oe,depthCounter:{depth:e.depthCounter.depth+1},globalScope:this.context.globalScope,track:this.context.track};if(n.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",null);return se(n,this.definition.body,this._params,this._locals,t,null)}}call(e,t){return ce(e,t,(n,r,o)=>{const i={spatialReference:e.spatialReference,services:e.services,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,timeZone:e.timeZone??null,console:e.console,lrucache:e.lrucache,interceptor:e.interceptor,abortSignal:e.abortSignal,localScope:new oe,track:e.track};if(i.depthCounter.depth>64)throw new u(e,"MaximumCallDepth",t);return se(i,this.definition.body,this._params,this._locals,o,t)})}marshalledCall(e,t,n,r){return r(e,t,(o,i,s)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,services:e.services,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,timeZone:e.timeZone??null,lrucache:e.lrucache,interceptor:e.interceptor,abortSignal:e.abortSignal,localScope:new oe,track:e.track};return s=s.map(t=>!v(t)||t instanceof w?t:m(t,e,r)),m(se(l,this.definition.body,this._params,this._locals,s,t),n,r)})}}function se(e,t,n,r,o,i){try{if(n.length!==o.length)throw new u(e,"WrongNumberOfParameters",i);if(null!=e.localScope){for(let t=0;t<n.length;t++)e.localScope[n[t]]={value:o[t]};for(const t of r)e.localScope[t]=X}const s=fe(e,t);if(s instanceof g)return s.value;if(s===x)throw new u(e,"UnexpectedToken",i);if(s===S)throw new u(e,"UnexpectedToken",i);return s instanceof b?s.value:s}catch(s){throw s}}class le extends n{constructor(e){super(),this.moduleGlobalContext=e}global(t){const n=e(t),r=this.moduleGlobalContext.globalScope[n];if(ee(r),v(r.value)&&!(r.value instanceof w)){const e=new w;return e.fn=r.value,e.parameterEvaluator=ce,e.context=this.moduleGlobalContext,this.moduleGlobalContext.globalScope[n]={value:e},e}return r.value}setGlobal(t,n){if(v(n))throw new u(null,"AssignModuleFunction",null);const r=e(t);if(void 0===this.moduleGlobalContext.globalScope[r])throw new u(null,"ModuleExportNotFound",null);this.moduleGlobalContext.globalScope[r]={value:n}}hasGlobal(t){return this.moduleGlobalContext.exports.has(e(t))}static load(e,n){const{globals:i,exports:s}=o(n),l=new Ve;for(const t of i)t in l||(l[t]=X);const a=e.spatialReference??V.WebMercator,c={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:a,track:e.track,depthCounter:{depth:1},libraryResolver:new r(e.libraryResolver._moduleSingletons,n.loadedModules),exports:s,localScope:null,globalScope:l};return Fe(c,n),new le(c)}}function ae(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(ue(e,t.arguments[r]));return n}function ce(e,t,n){try{return!0===t.preparsed?n(e,null,t.arguments):n(e,t,ae(e,t))}catch(r){throw r}}function ue(e,t){try{switch(t.type){case"AssignmentExpression":return ve(e,t);case"UpdateExpression":return be(e,t);case"TemplateLiteral":return Ue(e,t);case"Identifier":return De(e,t);case"MemberExpression":return Ne(e,t);case"Literal":return t.value;case"CallExpression":return Ke(e,t);case"UnaryExpression":return ke(e,t);case"BinaryExpression":return Ee(e,t);case"LogicalExpression":return Be(e,t);case"ArrayExpression":return Ce(e,t);case"ObjectExpression":return pe(e,t);default:throw new u(e,"Unrecognized",t)}}catch(n){throw f(e,t,n)}}function fe(e,t){switch(t.type){case"EmptyStatement":return F;case"VariableDeclaration":return Ae(e,t);case"ImportDeclaration":return je(e,t);case"ExportNamedDeclaration":return Oe(e,t);case"BlockStatement":return Fe(e,t);case"FunctionDeclaration":return Ie(e,t);case"ReturnStatement":return Re(e,t);case"IfStatement":return Se(e,t);case"ExpressionStatement":return xe(e,t);case"BreakStatement":return x;case"ContinueStatement":return S;case"ForStatement":return we(e,t);case"ForInStatement":return he(e,t);case"ForOfStatement":return de(e,t);case"WhileStatement":return me(e,t);default:throw new u(e,"Unrecognized",t)}}function pe(e,t){const n=Object.create(null),r=new Map;for(let i=0;i<t.properties.length;i++){const o=t.properties[i],s="Identifier"===o.key.type?o.key.name:ue(e,o.key),l=ue(e,o.value);if(v(l))throw new u(e,"NoFunctionInDictionary",t);if(!1===H(s))throw new u(e,"KeyMustBeString",t);let a=s.toString();const c=a.toLowerCase();r.has(c)?a=r.get(c):r.set(c,a),n[a]=l===F?null:l}const o=new c(n);return o.immutable=!1,o}function he(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&Ae(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let n=0;n<o;n++){r.scope[r.id]={value:n};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}if(n instanceof c||O(n)){const o=n.keys();for(let n=0;n<o.length;n++){r.scope[r.id]={value:o[n]};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(A(n)){for(const o of l(n)){r.scope[r.id]={value:o};const n=fe(e,t.body);if(n===x)break;if(n instanceof g)return n}return F}return F}function de(e,t){const n=ue(e,t.right);"VariableDeclaration"===t.left.type&&fe(e,t.left);const r=ne(e,"VariableDeclaration"===t.left.type?t.left.declarations[0].id:t.left);if($(n)||H(n)){const o=n.length;for(let i=0;i<o;i++){if(i>=n.length)throw new u(e,"OutOfBounds",t);r.scope[r.id]={value:n[i]};const o=fe(e,t.body);if(o===x)break;if(o instanceof g)return o}return F}if(j(n)){for(let o=0;o<n.length();o++){r.scope[r.id]={value:n.get(o)};const i=fe(e,t.body);if(i===x)break;if(i instanceof g)return i}return F}if(n instanceof c||O(n)){for(const o of n.keys()){const i=n.field(o);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}if(A(n)){for(const o of l(n)){const i=a(n,o,e,t,1);r.scope[r.id]={value:c.containerEntry(o,i)};const s=fe(e,t.body);if(s===x)break;if(s instanceof g)return s}return F}return F}function we(e,t){null!==t.init&&("VariableDeclaration"===t.init.type?fe(e,t.init):ue(e,t.init));const n={testResult:!0,lastAction:F};do{ge(e,t,n)}while(!0===n.testResult);return n.lastAction instanceof g?n.lastAction:F}function me(e,t){const n={testResult:!0,lastAction:F};if(n.testResult=ue(e,t.test),!1===n.testResult)return F;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t);for(;!0===n.testResult&&(n.lastAction=fe(e,t.body),n.lastAction!==x)&&!(n.lastAction instanceof g);)if(n.testResult=ue(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new u(e,"BooleanConditionRequired",t);return n.lastAction instanceof g?n.lastAction:F}function ge(e,t,n){if(null!==t.test){if(n.testResult=ue(e,t.test),!1===n.testResult)return;if(!0!==n.testResult)throw new u(e,"BooleanConditionRequired",t)}n.lastAction=fe(e,t.body),n.lastAction!==x?n.lastAction instanceof g?n.testResult=!1:null!==t.update&&ue(e,t.update):n.testResult=!1}function be(e,t){if("CallExpression"===t.argument.type)throw new u(e,"NeverReach",t);let n;if("MemberExpression"===t.argument.type){const r=ue(e,t.argument.object);let o;if(!0===t.argument.computed)o=ue(e,t.argument.property);else{if("Identifier"!==t.argument.property.type)throw new u(e,"Unrecognized",t);o=t.argument.property.name}if($(r)){if(!J(o))throw new u(e,"ArrayAccessMustBeNumber",t);if(o<0&&(o=r.length+o),o<0||o>=r.length)throw new u(e,"OutOfBounds",t);n=M(r[o]),r[o]="++"===t.operator?n+1:n-1}else if(r instanceof c){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else if(E(r)){if(!1===H(o))throw new u(e,"KeyAccessorMustBeString",t);if(!0!==r.hasField(o))throw new u(e,"FieldNotFound",t);n=M(r.field(o)),r.setField(o,"++"===t.operator?n+1:n-1)}else{if(j(r))throw new u(e,"Immutable",t);if(!(r instanceof le))throw new u(e,"InvalidParameter",t);if(!1===H(o))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==r.hasGlobal(o))throw new u(e,"ModuleExportNotFound",t);n=M(r.global(o)),r.setGlobal(o,"++"===t.operator?n+1:n-1)}return!1===t.prefix?n:"++"===t.operator?n+1:n-1}const r=ne(e,t.argument);n=M(te(r.var).value);const o="++"===t.operator?n+1:n-1;return r.scope[r.id]={value:o},!1===t.prefix?n:"++"===t.operator?n+1:n-1}function ye(e,t,n,r,o){switch(t){case"=":return e===F?null:e;case"/=":return M(n)/M(e);case"*=":return M(n)*M(e);case"-=":return M(n)-M(e);case"+=":return H(n)||H(e)?N(n)+N(e):M(n)+M(e);case"%=":return M(n)%M(e);default:throw new u(o,"UnsupportedOperator",r)}}function ve(e,t){if("MemberExpression"===t.left.type){const n=ue(e,t.left.object);let r;if(!0===t.left.computed)r=ue(e,t.left.property);else{if("Identifier"!==t.left.property.type)throw new u(e,"InvalidIdentifier",t);r=t.left.property.name}const o=ue(e,t.right);if($(n)){if(!J(r))throw new u(e,"ArrayAccessMustBeNumber",t);if(r<0&&(r=n.length+r),r<0||r>n.length)throw new u(e,"OutOfBounds",t);if(r===n.length){if("="!==t.operator)throw new u(e,"OutOfBounds",t);n[r]=ye(o,t.operator,n[r],t,e)}else n[r]=ye(o,t.operator,n[r],t,e)}else if(n instanceof c){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else if(E(n)){if(!1===H(r))throw new u(e,"KeyAccessorMustBeString",t);if(!0===n.hasField(r))n.setField(r,ye(o,t.operator,n.field(r),t,e));else{if("="!==t.operator)throw new u(e,"FieldNotFound",t,{key:r});n.setField(r,ye(o,t.operator,null,t,e))}}else{if(j(n))throw new u(e,"Immutable",t);if(!(n instanceof le))throw new u(e,"InvalidIdentifier",t);if(!1===H(r))throw new u(e,"ModuleAccessorMustBeString",t);if(!0!==n.hasGlobal(r))throw new u(e,"ModuleExportNotFound",t);n.setGlobal(r,ye(o,t.operator,n.global(r),t,e))}return F}const n=ne(e,t.left),r=ue(e,t.right);return n.scope[n.id]={value:ye(r,t.operator,"="!==t.operator?te(n.var).value:null,t,e)},F}function xe(e,t){const n=ue(e,t.expression);return n===F?F:new b(n)}function Se(e,t){const n=ue(e,t.test);if(!0===n)return fe(e,t.consequent);if(!1===n)return null!==t.alternate?fe(e,t.alternate):F;throw new u(e,"BooleanConditionRequired",t)}function Fe(e,t){let n=F;for(let r=0;r<t.body.length;r++)if(n=fe(e,t.body[r]),n instanceof g||n===x||n===S)return n;return n}function Re(e,t){if(null===t.argument)return new g(F);const n=ue(e,t.argument);return new g(n)}function Ie(t,n){if(null!=t.localScope)throw Q().error("Function declarations are only valid in global scope."),new u(t,"NeverReach",n);const r=e(n.id);if(!(r in t.globalScope))throw Q().error(`Function "${r}" not declared.`),new u(t,"NeverReach",n);const o=i(n),s=n.params.map(t=>e(t)),l=Array.from(o).filter(e=>!s.includes(e));return t.globalScope[r]={value:new ie(n,t,s,l)},F}function je(e,t){const n=ne(e,t.specifiers[0].local),r=e.libraryResolver;if(null==r)throw Q().error("Internal error: module loader not initialized"),new u(e,"NeverReach",t);const o=r.loadLibrary(n.id);let i;return r._moduleSingletons?.has(o.uri)?i=r._moduleSingletons.get(o.uri):(i=le.load(e,o.syntax),r._moduleSingletons?.set(o.uri,i)),n.scope[n.id]={value:i},F}function Oe(e,t){return fe(e,t.declaration),F}function Ae(e,t){for(let n=0;n<t.declarations.length;n++)Me(e,t.declarations[n]);return F}function Me(e,t){let n=null===t.init?null:ue(e,t.init);if(n===F&&(n=null),"Identifier"!==t.id.type)throw new u(e,"InvalidIdentifier",t);const r=ne(e,t.id);r.scope[r.id]={value:n}}function Ne(e,t){try{const n=ue(e,t.object);if(null===n)throw new u(e,"MemberOfNull",t);if(!1===t.computed){if("Identifier"===t.property.type){if(n instanceof c||O(n))return n.field(t.property.name);if(n instanceof P)return a(n,t.property.name,e,t);if(n instanceof le){if(!n.hasGlobal(t.property.name))throw new u(e,"InvalidIdentifier",t);return n.global(t.property.name)}}throw new u(e,"InvalidMemberAccessKey",t)}let r=ue(e,t.property);if(n instanceof c||O(n)){if(H(r))return n.field(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof le){if(H(r))return n.global(r);throw new u(e,"InvalidMemberAccessKey",t)}if(n instanceof P){if(H(r))return a(n,r,e,t);throw new u(e,"InvalidMemberAccessKey",t)}if($(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(H(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length+r),r>=n.length||r<0)throw new u(e,"OutOfBounds",t);return n[r]}throw new u(e,"InvalidMemberAccessKey",t)}if(j(n)){if(J(r)&&isFinite(r)&&Math.floor(r)===r){if(r<0&&(r=n.length()+r),r>=n.length()||r<0)throw new u(e,"OutOfBounds",t);return n.get(r)}throw new u(e,"InvalidMemberAccessKey",t)}throw new u(e,"InvalidMemberAccessKey",t)}catch(n){throw n}}function ke(e,t){try{const n=ue(e,t.argument);if(Y(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);if("~"===t.operator)return~M(n);throw new u(e,"UnsupportUnaryOperator",t)}if("~"===t.operator)return~M(n);if("-"===t.operator)return-1*M(n);if("+"===t.operator)return 1*M(n);throw new u(e,"UnsupportUnaryOperator",t)}catch(n){throw n}}function Ce(e,t){try{const n=[];for(let r=0;r<t.elements.length;r++){const o=ue(e,t.elements[r]);if(v(o))throw new u(e,"NoFunctionInArray",t);o===F?n.push(null):n.push(o)}return n}catch(n){throw n}}function Ee(e,t){try{const n=ue(e,t.left),r=ue(e,t.right);switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return C(M(n),M(r),t.operator);case"==":return I(n,r);case"!=":return!I(n,r);case"<":case">":case"<=":case">=":return k(n,r,t.operator);case"+":return H(n)||H(r)?N(n)+N(r):M(n)+M(r);case"-":return M(n)-M(r);case"*":return M(n)*M(r);case"/":return M(n)/M(r);case"%":return M(n)%M(r);default:throw new u(e,"UnsupportedOperator",t)}}catch(n){throw n}}function Be(e,t){try{const n=ue(e,t.left);if(Y(n))switch(t.operator){case"||":{if(!0===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}case"&&":{if(!1===n)return n;const r=ue(e,t.right);if(Y(r))return r;throw new u(e,"LogicExpressionOrAnd",t)}default:throw new u(e,"LogicExpressionOrAnd",t)}throw new u(e,"LogicalExpressionOnlyBoolean",t)}catch(n){throw n}}function Ge(e,t,n){if(v(e))throw new u(t,"NoFunctionInTemplateLiteral",n);return e}function Ue(e,t){let n="",r=0;for(const o of t.quasis)if(n+=o.value?o.value.cooked:"",!1===o.tail){n+=t.expressions[r]?N(Ge(ue(e,t.expressions[r]),e,t)):"",r++}return n}function De(e,t){return re(e,t)}function Ke(e,t){try{if("MemberExpression"===t.callee.type){const n=ue(e,t.callee.object);if(!(n instanceof le))throw new u(e,"FunctionNotFound",t);const r=!1===t.callee.computed?t.callee.property.name:ue(e,t.callee.property);if(!n.hasGlobal(r))throw new u(e,"FunctionNotFound",t);const o=n.global(r);if(!v(o))throw new u(e,"CallNonFunction",t);return o.call(e,t)}if("Identifier"!==t.callee.type)throw new u(e,"FunctionNotFound",t);const n=re(e,t.callee,"FunctionNotFound");if(v(n))return n.call(e,t);throw new u(e,"CallNonFunction",t)}catch(n){throw n}}function Le(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,3,3,e,t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",t);return ue(e,!0===r?n[1]:n[2])}catch(n){throw n}}function _e(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;R(null===n?[]:n,2,3,e,t);const r=ue(e,n[0]);if(3===n.length){const t=ue(e,n[1]),o=s(r,t);return null!=o&&""!==o?o:ue(e,n[2])}return null===r||""===r||void 0===r?ue(e,n[1]):r}catch(n){throw n}}function ze(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<2)throw new u(e,"WrongNumberOfParameters",t);if(2===n.length)return ue(e,n[1]);{if((n.length-1)%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);return Ze(e,t,1,r)}}catch(n){throw n}}function Ze(e,t,n,r){try{const o=t.arguments,i=ue(e,o[n]);if(I(i,r))return ue(e,o[n+1]);{const i=o.length-n;return 1===i?ue(e,o[n]):2===i?null:3===i?ue(e,o[n+2]):Ze(e,t,n+2,r)}}catch(o){throw o}}function qe(e,t){try{if(!0===t.preparsed)throw new u(e,"NeverReach",t);const n=t.arguments;if(n.length<3)throw new u(e,"WrongNumberOfParameters",t);if(n.length%2==0)throw new u(e,"WrongNumberOfParameters",t);const r=ue(e,n[0]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",n[0]);return We(e,t,0,r)}catch(n){throw n}}function We(e,t,n,r){try{const o=t.arguments;if(!0===r)return ue(e,o[n+1]);if(3===o.length-n)return ue(e,o[n+2]);{const r=ue(e,o[n+2]);if(!1===Y(r))throw new u(e,"BooleanConditionRequired",o[n+2]);return We(e,t,n+2,r)}}catch(o){throw o}}function Pe(){const e=Object.create(null);U(e,ce),Z(e,ce),D(e,ce,De),_(e,ce),K(e,ce),z(e,ce),L(e,ce),q(e,ce),e.iif=Le,e.defaultvalue=_e,e.decode=ze,e.when=qe;const t=function(){this.textformatting={value:c.textFormatting()}};t.prototype=Object.create(null),t.prototype.infinity=Object.freeze({value:Number.POSITIVE_INFINITY}),t.prototype.pi=Object.freeze({value:Math.PI});for(const[n,r]of Object.entries(e))t.prototype[n]=Object.freeze({value:new h(r)});return t}const Ve=Pe();function Te(e){const t={mode:"sync",compiled:!1,functions:Object.create(null),signatures:[],standardFunction:ce,evaluateIdentifier:De};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const[n,r]of Object.entries(t.functions))Ve.prototype[n]=Object.freeze({value:new h(r)});for(let n=0;n<t.signatures.length;n++)B(t.signatures[n],"sync")}function Ye(e){console.log(e)}function $e(n,i){const s=new Set(Object.keys(i?.vars||{}).map(t=>e(t))),l=new Set(Object.keys(i?.customfunctions||{}).map(t=>e(t))),{globals:a,exports:c}=o(n);return e=>{const o=e.spatialReference??V.WebMercator;let i=null;n.usesModules&&(i=new r(new Map,n.loadedModules));const f=new Ve;for(const t of l)null!=e.customfunctions&&t in e.customfunctions?f[t]={value:new h(e.customfunctions[t])}:f[t]=X;for(const t of s){if(null==e.vars||!(t in e.vars)){t in f||(f[t]=X);continue}const n=e.vars[t]??null;T(n)?f[t]={value:p.createFromGraphic(n,e.timeZone??null)}:f[t]={value:n}}for(const t of a)t in f||(f[t]=X);const d={lrucache:e.lrucache,interceptor:e.interceptor,services:e.services,console:e.console??Ye,abortSignal:t,timeZone:e.timeZone??null,spatialReference:o,track:e.track,depthCounter:{depth:1},libraryResolver:i,exports:c,localScope:null,globalScope:f},w=Fe(d,n);if(w instanceof g||w instanceof b){const e=w.value;if(y(e))return null;if(v(e))throw new u(d,"IllegalResult",null);return e}if(y(w))return null;if(w===x)throw new u(d,"IllegalResult",null);if(w===S)throw new u(d,"IllegalResult",null);throw new u(d,"NeverReach",null)}}function He(e,t){return $e(e,t)(t)}Te([G]);export{He as executeScript,Te as extend,$e as prepareScript};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../request.js";import t from"./featureSetCollection.js";import{m as a,$ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import l from"./featureset/actions/GroupBy.js";import s 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}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,isSupportedLayer as m,extractServiceUrl as h}from"./featureset/support/shared.js";import{isLoadable as I}from"../core/Loadable.js";import w from"../core/sql/WhereClause.js";import L from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import _ from"../portal/PortalItem.js";function C(){null===p.applicationCache&&(p.applicationCache=new p)}async function g(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new L({url:e,outFields:t,sourceJSON:r})}const n=new L({url:e,outFields:t}),l=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,l);try{return await l,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await l,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new L({url:e,outFields:t,sourceJSON:a})}const l=new L({url:e,outFields:t}),s=(async()=>(await l.load(),l.sourceJSON))();a.setCachedLayerMetadata(e,s);try{return await s,l}catch(n){throw a.removeCachedLayerMetadata(e,s),n}}return new L({url:e,outFields:t})}async function k(e,t,a,r,n,l=null){return F(await g(e,["*"],n),t,a,r,n,l)}function F(e,t=null,a=null,r=!0,n=null,l=null){switch(e.type){case"catalog-footprint":return F(e.parent,t,a,r,n,l);case"subtype-sublayer":{const s=F(e.parent,t,a,r,n,l);return s.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:s.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:l});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:l};return!e.url&&e.source?new c(s):new u(s)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function N(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("DataElementsNotFound")})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(l){throw p.applicationCache.clearLayerInfo(r),l}}return n}async function A(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(l){throw a.removeCachedServiceMetadata(t,r),l}}return r}async function O(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 A(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 l=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=l;const s=await T(e,l);if(s){r.queryelem=s,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 N(e+"/"+l);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let l=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),l=await k(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await l.load(),r.unVersion>=4&&(l=l.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:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})),await l.load())}return{lkp:r.lkp,associations:l,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 E(e,t,a,r=null,n=null,l=!0,s=null,i=null){let o=e.serviceUrl();if(!o)return null;o=o.endsWith("/")?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await k(o,r,n,l,s,i);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:l,lrucache:s,interceptor:i})}n.registerAction(),l.registerAction(),s.registerAction(),i.registerAction(),o.registerAction();class j 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=F(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(I(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 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=this._map.allLayers.find(t=>m(t)&&t.title===e);if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(t)&&t.title===e);if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){if(I(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 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=this._map.allLayers.find(t=>m(t)&&t.id===e);if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(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=F(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 A(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 s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])s.name===e&&(l=s);if(!l)for(const s of n.tables??[])s.name===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(!l)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new j(e,t,a,r)}function b(e,t,a=null,r=null){return new D(e,t,a,r)}function v(e,t,n,l,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l)}return null}if(r(e)){switch(t){case"datasource":return F(e.parent,s,e.parent.outFields,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(e,s,e.parent.outFields,!0,n,l)}return null}return null}async function R(e,t,a,r,n,l,s,i=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+l.url);if(o)return q(await o,t,a,r,n,s,i)}if(null!=s){const o=s.getCachedPortalItem(l.url,e);if(null!=o)return await q(await o,t,a,r,n,s,i)}const o=new _({id:e,portal:l}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+l.url,o):null!=s&&s.setCachedPortalItem(l.url,e,o);try{return await q(await o,t,a,r,n,s,i)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+l.url),null!=s&&s.removeCachedPortalItem(l.url,e,o),u}}async function q(e,t,a,r,n,l,s){let i;if("Feature Service"===e.type||"Map Service"===e.type)i=await g(h(e.url??"")+"/"+t,["*"],l);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=l){const t=l.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)i=await t;else{const t=S.fromPortalItem(e);l.setCachedPortalItemLayer(e.portal.url,e.id,t);try{i=await t}catch(o){throw l.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else i=await S.fromPortalItem(e)}return F(i,a,r,n,l,s)}export{O as constructAssociationMetaDataFeatureSetFromUrl,F as constructFeatureSet,R as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,k as constructFeatureSetFromUrl,v as convertToFeatureSet,M as createFeatureSetCollectionFromMap,b as createFeatureSetCollectionFromService,C as initialiseMetaDataCache};
|
|
5
|
+
import e from"../request.js";import t from"./featureSetCollection.js";import{m as a,a0 as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import l from"./featureset/actions/GroupBy.js";import s 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}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,isSupportedLayer as m,extractServiceUrl as h}from"./featureset/support/shared.js";import{isLoadable as I}from"../core/Loadable.js";import w from"../core/sql/WhereClause.js";import L from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import _ from"../portal/PortalItem.js";function C(){null===p.applicationCache&&(p.applicationCache=new p)}async function g(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new L({url:e,outFields:t,sourceJSON:r})}const n=new L({url:e,outFields:t}),l=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,l);try{return await l,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await l,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new L({url:e,outFields:t,sourceJSON:a})}const l=new L({url:e,outFields:t}),s=(async()=>(await l.load(),l.sourceJSON))();a.setCachedLayerMetadata(e,s);try{return await s,l}catch(n){throw a.removeCachedLayerMetadata(e,s),n}}return new L({url:e,outFields:t})}async function k(e,t,a,r,n,l=null){return F(await g(e,["*"],n),t,a,r,n,l)}function F(e,t=null,a=null,r=!0,n=null,l=null){switch(e.type){case"catalog-footprint":return F(e.parent,t,a,r,n,l);case"subtype-sublayer":{const s=F(e.parent,t,a,r,n,l);return s.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:s.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:l});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:l};return!e.url&&e.source?new c(s):new u(s)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function N(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("DataElementsNotFound")})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(l){throw p.applicationCache.clearLayerInfo(r),l}}return n}async function A(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(l){throw a.removeCachedServiceMetadata(t,r),l}}return r}async function O(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 A(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 l=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=l;const s=await T(e,l);if(s){r.queryelem=s,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 N(e+"/"+l);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let l=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),l=await k(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await l.load(),r.unVersion>=4&&(l=l.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:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})),await l.load())}return{lkp:r.lkp,associations:l,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 E(e,t,a,r=null,n=null,l=!0,s=null,i=null){let o=e.serviceUrl();if(!o)return null;o=o.endsWith("/")?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await k(o,r,n,l,s,i);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:l,lrucache:s,interceptor:i})}n.registerAction(),l.registerAction(),s.registerAction(),i.registerAction(),o.registerAction();class j 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=F(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(I(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 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=this._map.allLayers.find(t=>m(t)&&t.title===e);if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(t)&&t.title===e);if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){if(I(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 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=this._map.allLayers.find(t=>m(t)&&t.id===e);if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(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=F(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 A(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 s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])s.name===e&&(l=s);if(!l)for(const s of n.tables??[])s.name===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(!l)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new j(e,t,a,r)}function b(e,t,a=null,r=null){return new D(e,t,a,r)}function v(e,t,n,l,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l)}return null}if(r(e)){switch(t){case"datasource":return F(e.parent,s,e.parent.outFields,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(e,s,e.parent.outFields,!0,n,l)}return null}return null}async function R(e,t,a,r,n,l,s,i=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+l.url);if(o)return q(await o,t,a,r,n,s,i)}if(null!=s){const o=s.getCachedPortalItem(l.url,e);if(null!=o)return await q(await o,t,a,r,n,s,i)}const o=new _({id:e,portal:l}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+l.url,o):null!=s&&s.setCachedPortalItem(l.url,e,o);try{return await q(await o,t,a,r,n,s,i)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+l.url),null!=s&&s.removeCachedPortalItem(l.url,e,o),u}}async function q(e,t,a,r,n,l,s){let i;if("Feature Service"===e.type||"Map Service"===e.type)i=await g(h(e.url??"")+"/"+t,["*"],l);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=l){const t=l.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)i=await t;else{const t=S.fromPortalItem(e);l.setCachedPortalItemLayer(e.portal.url,e.id,t);try{i=await t}catch(o){throw l.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else i=await S.fromPortalItem(e)}return F(i,a,r,n,l,s)}export{O as constructAssociationMetaDataFeatureSetFromUrl,F as constructFeatureSet,R as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,k as constructFeatureSetFromUrl,v as convertToFeatureSet,M as createFeatureSetCollectionFromMap,b as createFeatureSetCollectionFromService,C 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.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{StringEnum as t}from"../../enum.js";import{a0 as i}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as s,OriginalField as n,AdaptedFeatureSet as r}from"./Adapted.js";import a from"./AttributeFilter.js";import o from"./OrderBy.js";import{FeatureSetError 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{layerGeometryEsriConstants as p}from"../support/shared.js";import{isSingleField as h,toWhereClause as c,predictType as g,scanForField as _,reformulateWithoutField as m}from"../support/sqlUtils.js";import y from"../support/StatsField.js";import{createMD5Hash as b,outputTypes as w}from"../../../core/MD5.js";import{aggregateFunction as F}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as I}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as S}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as x}from"../../../core/sql/TimeOnly.js";import D from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import j from"../../../layers/support/Field.js";import k from"../../../layers/support/FieldsIndex.js";const C=new t(["MIN","MAX","VAR","STDDEV","COUNT","SUM","AVG"],[["VARIANCE","VAR"],["AVERAGE","AVG"],["MEAN","AVG"],["STDEV","STDDEV"]]);class T 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 0}_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,i=1;const r=this._parent?this._parent.getFieldsIndex():new k([]);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"+i.toString(),i++)}for(const s of this._config.statsfields){const e=new y;e.field=s.name,e.tofieldname=s.name,e.workingexpr=s.expression instanceof D?s.expression:D.create(s.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=C.lookup(s.statistic)??"COUNT",this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const s of this._config.groupbyfields){const e={name:s.name,singlefield:null,tofieldname:s.name,expression:s.expression instanceof D?s.expression:D.create(s.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 A({wkid:4326});this.fields=[];const a=new y;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=D.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const n of this._decodedGroupbyfield){const t=new j;if(n.name=this._nextUniqueName(e),t.name=n.tofieldname,t.alias=t.name,h(n.expression)){const e=this._parent.getField(c(n.expression,0));if(!e)throw new l("AggregationFieldNotFound");n.name=e.name,n.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,n.sqlType=e.type}else{t.type=this._convertToEsriFieldType(g(n.expression,this._parent.fields));const e=new j;e.name=n.name,e.alias=e.name,this.phsyicalgroupbyfields.push(n.name),this._adaptedFields.push(new s(e,n.expression)),this._candosimplegroupby=!1,n.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const s of this._parent.fields)this._adaptedFields.push(new n(s));for(let s=0;s<this._decodedStatsfield.length;s++){const t=new j;let i=null;const n=this._decodedStatsfield[s];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&&h(n.workingexpr)?c(n.workingexpr,0):"";switch(this._decodedStatsfield[s].typeofstat){case"SUM":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(i=this._parent.getField(r),!i))throw new 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,n){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let r=0;r<this._decodedStatsfield.length;r++)if(!0===_(i,this._decodedStatsfield[r].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 r=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(n),l=!0===d.nowhereclause?new u(r._candidates.slice().concat(r._known.slice()),[],!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)):new u(r._candidates.slice(),r._known.slice(),!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)),l}let p=this._parent;if(this._adaptedFields.length>0&&(p=new r({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 o({parentfeatureset:p,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=p;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new a({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 o({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=m(e,t.tofieldname,c(t.workingexpr,0),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=m(e,t.tofieldname,c(t.expression,0),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,t,s,n,r,a){try{i(e.pagesDefinition.internal.iterator.next()).then(i=>{if(null===i)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(i);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[i],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]),t-=1,e.pagesDefinition.internal.workingItem={features:[i],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(i)}this._nextAggregateItem(e,t,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 I||e instanceof x?s.push(e.toNumber()):e instanceof S?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=F(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]:D.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 b(t,w.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new T({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{T as default};
|
|
5
|
+
import e from"../../../Graphic.js";import{StringEnum as t}from"../../enum.js";import{a1 as i}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as s,OriginalField as n,AdaptedFeatureSet as r}from"./Adapted.js";import a from"./AttributeFilter.js";import o from"./OrderBy.js";import{FeatureSetError 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{layerGeometryEsriConstants as p}from"../support/shared.js";import{isSingleField as h,toWhereClause as c,predictType as g,scanForField as _,reformulateWithoutField as m}from"../support/sqlUtils.js";import y from"../support/StatsField.js";import{createMD5Hash as b,outputTypes as w}from"../../../core/MD5.js";import{aggregateFunction as F}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as I}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as S}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as x}from"../../../core/sql/TimeOnly.js";import D from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import j from"../../../layers/support/Field.js";import k from"../../../layers/support/FieldsIndex.js";const C=new t(["MIN","MAX","VAR","STDDEV","COUNT","SUM","AVG"],[["VARIANCE","VAR"],["AVERAGE","AVG"],["MEAN","AVG"],["STDEV","STDDEV"]]);class T 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 0}_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,i=1;const r=this._parent?this._parent.getFieldsIndex():new k([]);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"+i.toString(),i++)}for(const s of this._config.statsfields){const e=new y;e.field=s.name,e.tofieldname=s.name,e.workingexpr=s.expression instanceof D?s.expression:D.create(s.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=C.lookup(s.statistic)??"COUNT",this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const s of this._config.groupbyfields){const e={name:s.name,singlefield:null,tofieldname:s.name,expression:s.expression instanceof D?s.expression:D.create(s.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 A({wkid:4326});this.fields=[];const a=new y;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=D.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const n of this._decodedGroupbyfield){const t=new j;if(n.name=this._nextUniqueName(e),t.name=n.tofieldname,t.alias=t.name,h(n.expression)){const e=this._parent.getField(c(n.expression,0));if(!e)throw new l("AggregationFieldNotFound");n.name=e.name,n.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,n.sqlType=e.type}else{t.type=this._convertToEsriFieldType(g(n.expression,this._parent.fields));const e=new j;e.name=n.name,e.alias=e.name,this.phsyicalgroupbyfields.push(n.name),this._adaptedFields.push(new s(e,n.expression)),this._candosimplegroupby=!1,n.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const s of this._parent.fields)this._adaptedFields.push(new n(s));for(let s=0;s<this._decodedStatsfield.length;s++){const t=new j;let i=null;const n=this._decodedStatsfield[s];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&&h(n.workingexpr)?c(n.workingexpr,0):"";switch(this._decodedStatsfield[s].typeofstat){case"SUM":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(i=this._parent.getField(r),!i))throw new 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,n){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let r=0;r<this._decodedStatsfield.length;r++)if(!0===_(i,this._decodedStatsfield[r].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 r=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(n),l=!0===d.nowhereclause?new u(r._candidates.slice().concat(r._known.slice()),[],!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)):new u(r._candidates.slice(),r._known.slice(),!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)),l}let p=this._parent;if(this._adaptedFields.length>0&&(p=new r({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 o({parentfeatureset:p,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=p;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new a({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 o({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=m(e,t.tofieldname,c(t.workingexpr,0),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=m(e,t.tofieldname,c(t.expression,0),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,t,s,n,r,a){try{i(e.pagesDefinition.internal.iterator.next()).then(i=>{if(null===i)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(i);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[i],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]),t-=1,e.pagesDefinition.internal.workingItem={features:[i],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(i)}this._nextAggregateItem(e,t,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 I||e instanceof x?s.push(e.toNumber()):e instanceof S?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=F(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]:D.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 b(t,w.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new T({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{T 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.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{
|
|
5
|
+
import{a1 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import n from"../support/IdSet.js";import s from"../support/OrderbyClause.js";class i extends r{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 s=new n([],[],!0,null);for(let n=0;n<r.length;n++)s._known.push(r[n].id);return s}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("NeverReach")}async _getFilteredSet(e,t,r,s,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===s?this._orderbyclause:s,i);this._checkCancelled(i);const o=new n(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 n(e._candidates.slice().concat(e._known.slice()),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){r._featuresetFunctions.orderBy=function(e){return""===e?this:new i({parentfeatureset:this,orderbyclause:new s(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{i 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.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import t
|
|
5
|
+
import{Feature as t}from"../../Feature.js";class e{constructor(t,e){this._lastId=-1,this._progress=e,this._parent=t}reset(){this._lastId=-1}async nextBatchAsArcadeFeatures(e,s){const n=await this.nextBatch(e);return null===n?n:n.map(e=>t.createFromGraphicLikeObject(e.geometry,e.attributes,this._parent,s))}nextBatch(t){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then(e=>this.nextBatch(t),e=>this.nextBatch(t));const e={returnpromise:null,hasset:!1},s=[];return e.returnpromise=new Promise((n,a)=>{this._parent._getSet(this._progress).then(r=>{const i=r._known;let h=i.length-1;if("GETPAGES"===i[i.length-1]&&(h-=1),this._lastId+t>h&&i.length>0&&"GETPAGES"===i[i.length-1])return void this._parent._expandPagedSet(r,this._parent._maxQueryRate(),0,0,this._progress).then(s=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(n,a)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)});const _=r._candidates;if(h>=this._lastId+t||0===_.length){for(let e=0;e<t;e++){const t=e+this._lastId+1;if(t>=i.length)break;s[e]=i[t]}return this._lastId+=s.length,0===s.length&&(e.hasset=!0,this._parent._mainSetInUse=null,n([])),void this._parent._getFeatureBatch(s,this._progress).then(t=>{e.hasset=!0,this._parent._mainSetInUse=null,n(t)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})}this._parent._refineSetBlock(r,this._parent._maxProcessingRate(),this._progress).then(()=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(n,a)},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})},t=>{e.hasset=!0,this._parent._mainSetInUse=null,a(t)})}),!1===e.hasset&&(this._parent._mainSetInUse=e.returnpromise,e.hasset=!0),e.returnpromise}next(){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then(t=>this.next(),t=>this.next());const t={returnpromise:null,hasset:!1};return t.returnpromise=new Promise((e,s)=>{this._parent._getSet(this._progress).then(n=>{const a=n._known;if(this._lastId<a.length-1)"GETPAGES"===a[this._lastId+1]?this._parent._expandPagedSet(n,this._parent._maxQueryRate(),0,0,this._progress).then(e=>(t.hasset=!0,this._parent._mainSetInUse=null,this.next())).then(e,s):(this._lastId+=1,this._parent._getFeature(n,a[this._lastId],this._progress).then(s=>{t.hasset=!0,this._parent._mainSetInUse=null,e(s)},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)}));else{n._candidates.length>0?this._parent._refineSetBlock(n,this._parent._maxProcessingRate(),this._progress).then(()=>{t.hasset=!0,this._parent._mainSetInUse=null,this.next().then(e,s)},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)}):(t.hasset=!0,this._parent._mainSetInUse=null,e(null))}},e=>{t.hasset=!0,this._parent._mainSetInUse=null,s(e)})}),!1===t.hasset&&(this._parent._mainSetInUse=t.returnpromise,t.hasset=!0),t.returnpromise}async count(){if(-1!==this._parent._totalCount)return this._parent._totalCount;const t=await this._parent._getSet(this._progress),e=await this._refineAllSets(t);return this._parent._totalCount=e._known.length,this._parent._totalCount}async _refineAllSets(t){if(t._known.length>0&&"GETPAGES"===t._known[t._known.length-1])return await this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,1,this._progress),this._refineAllSets(t);if(t._candidates.length>0){if("GETPAGES"===t._known[t._candidates.length-1])return await this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,2,this._progress),this._refineAllSets(t);const e=await this._parent._refineSetBlock(t,this._parent._maxProcessingRate(),this._progress);return e._candidates.length>0?this._refineAllSets(e):e}return t}}export{e as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../ArcadeDate.js";import{toSymbolId as r}from"../arcadeEnvironment.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n}from"../executionError.js";import o
|
|
5
|
+
import{ArcadeDate as e}from"../ArcadeDate.js";import{toSymbolId as r}from"../arcadeEnvironment.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n}from"../executionError.js";import{Feature as o}from"../Feature.js";import{B as i,k as a,Q as u,u as s,K as d,S as m,T as c,v as f,U as l,V as p,e as y}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as v}from"../featureset/support/shared.js";import{SqlTimeStampOffset as w}from"../../core/sql/SqlTimestampOffset.js";import h from"../../core/sql/WhereClause.js";import{internalTimeReceivedField as b}from"../../layers/support/streamLayerUtils.js";import{isString as T,isNumber as j}from"../../support/guards.js";function I(e){const r=e?.fullSchema();return r?.datesInUnknownTimezone?"unknown":r?.dateFieldsTimeZone||"UTC"}function F(e){const r=e.fullSchema()?.fieldsIndex;return null==r&&e instanceof o?e.fieldsIndex:r}const g={getAttributeSQL(e,r){const t=e.field(r);if(null==t)return t;if(y(t)){const n=t.toDateTime(),o=F(e)?.get(r)?.type;return"esriFieldTypeTimestampOffset"===o||"timestamp-offset"===o?w.fromDateTime(n):n}return t}};function P(o,w,P){o.domain=function(e,r){return w(e,r,(o,m,c)=>{if(i(c,2,3,e,r),a(c[0])){const r=u(c[0],s(c[1]),void 0===c[2]?void 0:c[2]);return r&&r.domain?"coded-value"===r.domain.type||"codedValue"===r.domain.type?t.convertObjectToArcadeDictionary({type:"codedValue",name:r.domain.name,dataType:v[r.field.type],codedValues:r.domain.codedValues.map(e=>({name:e.name,code:e.code}))},d(e)):t.convertObjectToArcadeDictionary({type:"range",name:r.domain.name,dataType:v[r.field.type],min:r.domain.minValue,max:r.domain.maxValue},d(e)):null}throw new n(e,"InvalidParameter",r)})},o.domaincode=function(e,r){return w(e,r,(t,o,u)=>{if(i(u,2,4,e,r),a(u[0]))return m(u[0],s(u[1]),u[2],void 0===u[3]?void 0:u[3]);throw new n(e,"InvalidParameter",r)})},o.domainname=function(e,r){return w(e,r,(t,o,u)=>{if(i(u,2,4,e,r),a(u[0]))return c(u[0],s(u[1]),u[2],void 0===u[3]?void 0:u[3]);throw new n(e,"InvalidParameter",r)})},o.expects=function(e,r){return w(e,r,(t,o,i)=>{if(i.length<1)throw new n(e,"WrongNumberOfParameters",r);return f})},o.featureinfilter=function(e,r){return w(e,r,(e,r,t)=>{i(t,2,2,e,r);const[o,u]=t;if(null==o)return!1;if(""===u||null==u)return!0;if(!a(o)||!T(u))throw new n(e,"InvalidParameter",r);const s=h.create(u,{fieldsIndex:F(o),timeZone:I(o)}),d=s.getVariables();for(const n of d)s.parameters[n]=P(e,{name:n});return s.testFeature(o,g)})},o.gdbversion=function(e,r){return w(e,r,(t,o,u)=>{if(i(u,1,1,e,r),a(u[0]))return u[0].gdbVersion();throw new n(e,"InvalidParameter",r)})},o.schema=function(e,r){return w(e,r,(o,i,u)=>{if(a(u[0])){const r=l(u[0]);return r?t.convertObjectToArcadeDictionary(r,d(e)):null}throw new n(e,"InvalidParameter",r)})},o.subtypecode=function(e,r){return w(e,r,(t,o,u)=>{if(i(u,1,1,e,r),a(u[0])){const e=p(u[0]);if(!e)return null;if(e.subtypeField&&u[0].hasField(e.subtypeField)){const r=u[0].field(e.subtypeField);for(const t of e.subtypes)if(t.code===r)return t.code;return null}return null}throw new n(e,"InvalidParameter",r)})},o.subtypename=function(e,r){return w(e,r,(t,o,u)=>{if(i(u,1,1,e,r),a(u[0])){const e=p(u[0]);if(!e)return"";if(e.subtypeField&&u[0].hasField(e.subtypeField)){const r=u[0].field(e.subtypeField);for(const t of e.subtypes)if(t.code===r)return t.name;return""}return""}throw new n(e,"InvalidParameter",r)})},o.subtypes=function(e,r){return w(e,r,(o,u,s)=>{if(i(s,1,1,e,r),a(s[0])){const r=p(s[0]);return r?t.convertObjectToArcadeDictionary(r,d(e)):null}throw new n(e,"InvalidParameter",r)})},o[r("TimeReceived")]=function(r,t){return w(r,t,(r,t,o)=>{if(i(o,1,1,r,t),a(o[0])){if(o[0].hasField(b)){const t=o[0].field(b);return j(t)?e.epochToArcadeDate(t,r.timeZone??"system"):y(t)?t:null}return null}throw new n(r,"InvalidParameter",t)})}}export{P 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.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../Graphic.js";import{ArcadeDate as t}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import i from"../Dictionary.js";import{StringEnum as a,toStringEnumKey as r}from"../enum.js";import{ArcadeExecutionError as o}from"../executionError.js";import s from"../Feature.js";import{convertToFeatureSet as l,constructFeatureSetFromPortalItem as f,constructFeatureSet as d,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as m}from"../featureSetUtils.js";import p from"../ImmutableArray.js";import{B as y,g as w,f as I,m as h,u as g,N as F,K as b,e as T,l as D,J as x,H as E,k as N,j as A,i as v,s as S,L,Y as j}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as k,StringToCodeAdapted as Z,FieldRename as $,AdaptedFeatureSet as P,OriginalField as U}from"../featureset/actions/Adapted.js";import M from"../featureset/actions/AttributeFilter.js";import R from"../featureset/actions/OrderBy.js";import O from"../featureset/actions/Top.js";import z from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import H from"../featureset/support/OrderbyClause.js";import{isSupportedLayer as G,cloneField as V}from"../featureset/support/shared.js";import{isSingleField as _}from"../featureset/support/sqlUtils.js";import{calculateStat as B}from"./fieldStats.js";import{isPromiseLike as K}from"../../core/promiseUtils.js";import q from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";import{queryAssociations as X}from"../../rest/networks/queryAssociations.js";import ee from"../../rest/networks/support/NetworkElement.js";import te from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ne,isArray as ie,isInteger as ae}from"../../support/guards.js";function re(e){if(1===e.length){if(ie(e[0]))return B("distinct",e[0],-1);if(A(e[0]))return B("distinct",e[0].toArray(),-1)}return B("distinct",e,-1)}function oe(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function se(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function le(e){if(null===e)return null;const t={type:se(e,"type",""),name:se(e,"name","")};if("range"===t.type)t.range=se(e,"range",[]);else{t.codedValues=[];for(const n of se(e,"codedValues",[]))t.codedValues.push({name:se(n,"name",""),code:se(n,"code",null)})}return t}function fe(e){if(null===e)return null;const t={},n=se(e,"wkt");null!==n&&(t.wkt=n);const i=se(e,"wkid");return null!==i&&(t.wkid=i),t}function de(e){if(null===e)return null;const t={hasZ:se(e,"hasz",!1),hasM:se(e,"hasm",!1)},n=se(e,"spatialreference");null!=n&&(t.spatialReference=fe(n));const i=se(e,"x",null);if(null!==i)return t.x=i,t.y=se(e,"y",null),t.hasZ&&(t.z=se(e,"z",null)),t.hasM&&(t.m=se(e,"m",null)),t;const a=se(e,"rings",null);if(null!==a)return t.rings=a,t;const r=se(e,"paths",null);if(null!==r)return t.paths=r,t;const o=se(e,"points",null);if(null!==o)return t.points=o,t;for(const s of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=se(e,s,null);null!==n&&(t[s]=n)}return t}function ue(e,t){for(const n of t)if(n===e)return!0;return!1}function ce(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ue(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==ie(e.layerDefinition.fields)&&!1!==ie(e.featureSet.features))))}function me(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function pe(t,n,i,a,r,s,l){const f=await t.getFeatureSetInfo();if(null===(f?.layerId??null))return null;if(!r.layerIdLookup.get(f.layerId))return null;const u=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),c=[];switch(i){case"connected":c.push("connectivity"),c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity"),c.push("junction-edge-midspan-connectivity"),c.push("junction-junction-connectivity");break;case"container":case"content":c.push("containment");break;case"structure":case"attached":c.push("attachment");break;case"junctionedge":c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity");break;case"midspan":c.push("junction-edge-midspan-connectivity");break;default:throw new o(s,"InvalidParameter",l)}let m=null,p=!1;if(null!==a&&""!==a&&void 0!==a){for(const e of r.terminals)e.terminalName===a&&(m=e.terminalId);null===m&&(p=!0)}const y=[];if(!p){const a=new ee({globalId:n.field(t.globalIdField),networkSourceId:r.layerIdLookup.get(f.layerId).sourceId,...m?{terminalId:m}:""}),o=await X(u,new te({types:c,elements:[a]}));let s=0;for(const t of o.associations){let n=null,o="",l="";if(t.fromNetworkElement?.globalId===a.globalId?(n=t.toNetworkElement,l="to"):t.toNetworkElement?.globalId===a.globalId&&(n=t.fromNetworkElement,l="from"),!n)continue;switch(i){case"attached":if("attachment"!==t.associationType)continue;if("to"!==l)continue;break;case"structure":if("attachment"!==t.associationType)continue;if("from"!==l)continue;break;case"container":if("containment"!==t.associationType)continue;if("from"!==l)continue;break;case"content":if("containment"!==t.associationType)continue;if("to"!==l)continue;break;case"connected":break;case"junctionedge":"junction-edge-to-connectivity"===t.associationType?o="to":"junction-edge-from-connectivity"===t.associationType&&(o="from");break;case"midspan":if("junction-edge-midspan-connectivity"!==t.associationType)continue}const f=r.sourceIdLookup.get(n.networkSourceId)?.className??"";y.push(new e({geometry:null,attributes:{objectId:s++,globalId:n.globalId,percentAlong:t.percentAlong??0,isContentVisible:t.isContentVisible?0:1,className:f,side:o}}))}}const w=new Q({source:y,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new J({name:"objectId",alias:"objectId",type:"oid"}),new J({name:"globalId",alias:"globalId",type:"global-id"}),new J({name:"percentAlong",alias:"percentAlong",type:"double"}),new J({name:"side",alias:"side",type:"string"}),new J({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new J({name:"className",alias:"className",type:"string"})]});return d(w)}function ye(e){if("async"===e.mode){e.functions.timezone=function(n,a){return e.standardFunctionAsync(n,a,async(e,r,s)=>{if(y(s,1,2,n,a),w(s[0]))return"Unknown";if(I(s[0]))return"Unknown";if(h(s[0])){if(await s[0].load(),1===s.length||null===s[1])return s[0].datesInUnknownTimezone?me("unknown"):me(s[0].dateFieldsTimeZone);if(!(s[1]instanceof i)||!1===s[1].hasField("type"))throw new o(n,"InvalidParameter",a);const e=s[1].field("type");if(!1===ne(e))throw new o(n,"InvalidParameter",a);switch(g(e).toLowerCase()){case"preferredtimezone":return me(s[0].preferredTimeZone);case"editfieldsinfo":return me(s[0].editFieldsInfo?.timeZone??null);case"timeinfo":return me(s[0].timeInfo?.timeZone??null);case"field":if(s[1].hasField("fieldname")&&ne(s[1].field("fieldname")))return me(s[0].fieldTimeZone(g(s[1].field("fieldname"))))}throw new o(n,"InvalidParameter",a)}const l=F(s[0],b(n));if(null===l)return null;const f=l.timeZone;return"system"===f?t.systemTimeZoneCanonicalName:"utc"===f.toLowerCase()?"UTC":"unknown"===f.toLowerCase()?"Unknown":f})},e.functions.sqltimestamp=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,1,3,t,n);const r=a[0];if(T(r)){if(1===a.length)return r.toSQLWithKeyword();if(2===a.length)return r.changeTimeZone(g(a[1])).toSQLWithKeyword();throw new o(t,"InvalidParameter",n)}if(I(r))return r.toSQLWithKeyword();if(h(r)){if(3!==a.length)throw new o(t,"InvalidParameter",n);await r.load();const e=g(a[1]);if(I(a[2]))return a[2].toSQLWithKeyword();if(!1===T(a[2]))throw new o(t,"InvalidParameter",n);const i=r.fieldTimeZone(e);return null==i?a[2].toSQLWithKeyword():a[2].changeTimeZone(i).toSQLWithKeyword()}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,(e,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetById(e,r,i)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"featuresetbyid",min:2,max:4});const B=new a(["datasource","parent","root"]);e.functions.getfeatureset=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,2,t,n),N(a[0])){const e=null==a[1]?"datasource":B.lookup(g(a[1]));return l(a[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"getfeatureset",min:1,max:2}),e.functions.featuresetbyportalitem=function(t,i){return e.standardFunctionAsync(t,i,(e,a,r)=>{if(y(r,2,5,t,i),null===r[0])throw new o(t,"PortalRequired",i);if(r[0]instanceof n){const e=g(r[1]),n=g(r[2]);let a=x(r[3],null);const s=E(x(r[4],!0));if(null===a&&(a=["*"]),!1===ie(a))throw new o(t,"InvalidParameter",i);let l;return l=t.services?.portal?t.services.portal:Y.getDefault(),l=C(r[0],l),f(e,n,t.spatialReference,a,s,l,t.lrucache,t.interceptor)}if(!1===ne(r[0]))throw new o(t,"PortalRequired",i);const s=g(r[0]),l=g(r[1]);let d=x(r[2],null);const u=E(x(r[3],!0));if(null===d&&(d=["*"]),!1===ie(d))throw new o(t,"InvalidParameter",i);return f(s,l,t.spatialReference,d,u,t.services?.portal??Y.getDefault(),t.lrucache,t.interceptor)})},e.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),e.functions.featuresetbyname=function(t,n){return e.standardFunctionAsync(t,n,(e,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetByName(e,r,i)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"featuresetbyname",min:2,max:4}),e.functions.featureset=function(t,n){return e.standardFunction(t,n,(e,a,r)=>{y(r,1,1,t,n);const s={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ne(r[0])){const e=JSON.parse(r[0]);void 0!==e.layerDefinition?(s.layerDefinition=e.layerDefinition,s.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(s.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(s.featureSet.features=e.features,s.featureSet.geometryType=e.geometryType,s.layerDefinition.geometryType=s.featureSet.geometryType,s.layerDefinition.objectIdField=e.objectIdFieldName??"",s.layerDefinition.typeIdField=e.typeIdFieldName,s.layerDefinition.globalIdField=e.globalIdFieldName,s.layerDefinition.fields=e.fields,e.spatialReference&&(s.layerDefinition.spatialReference=e.spatialReference))}else{if(!(r[0]instanceof i))throw new o(t,"InvalidParameter",n);{const e=JSON.parse(r[0].castToText(!0)),i=se(e,"layerdefinition");if(null!==i){s.layerDefinition.geometryType=se(i,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.globalIdField=se(i,"globalidfield",""),s.layerDefinition.objectIdField=se(i,"objectidfield",""),s.layerDefinition.typeIdField=se(i,"typeidfield",""),s.layerDefinition.hasZ=!0===se(i,"hasz",!1),s.layerDefinition.hasM=!0===se(i,"hasm",!1);const t=se(i,"spatialreference");t&&(s.layerDefinition.spatialReference=fe(t));const n=[];for(const e of se(i,"fields",[])){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};n.push(t)}s.layerDefinition.fields=n;const a=se(e,"featureset");if(a){const e={};for(const t of n)e[t.name.toLowerCase()]=t.name;for(const t of se(a,"features",[])){const n={},i=se(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];s.featureSet.features.push({attributes:n,geometry:de(se(t,"geometry"))})}}}else{s.layerDefinition.hasZ=!0===se(e,"hasz",!1),s.layerDefinition.hasM=!0===se(e,"hasm",!1),s.layerDefinition.geometryType=se(e,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.objectIdField=se(e,"objectidfieldname",""),s.layerDefinition.typeIdField=se(e,"typeidfieldname","");const i=se(e,"spatialreference");i&&(s.layerDefinition.spatialReference=fe(i));const a=[],r=se(e,"fields",null);if(!ie(r))throw new o(t,"InvalidParameter",n);for(const e of r){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};a.push(t)}s.layerDefinition.fields=a;const l={};for(const e of a)l[e.name.toLowerCase()]=e.name;let f=se(e,"features",null);if(ie(f))for(const e of f){const t={},n=se(e,"attributes",{});for(const e in n)t[l[e.toLowerCase()]]=n[e];s.featureSet.features.push({attributes:t,geometry:de(se(e,"geometry",null))})}else f=null,s.featureSet.features=f}}}if(!1===ce(s))throw new o(t,"InvalidParameter",n);return s.layerDefinition.geometryType||(s.layerDefinition.geometryType="esriGeometryNull"),W.create(s,t.spatialReference)})},e.signatures.push({name:"featureset",min:1,max:1}),e.functions.filter=function(t,n){return e.standardFunctionAsync(t,n,async(i,a,r)=>{if(y(r,2,2,t,n),ie(r[0])||A(r[0])){const e=[];let i,a=r[0];if(a instanceof p&&(a=a.toArray()),!v(r[1]))throw new o(t,"InvalidParameter",n);i=r[1].createFunction(t);for(const t of a){const n=i(t);K(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(h(r[0])){const n=await r[0].load(),i=q.create(r[1],{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC}),a=i.getVariables();if(a.length>0){const n={};for(const i of a)n[i]=e.evaluateIdentifier(t,{name:i});i.parameters=n}return new M({parentfeatureset:r[0],whereclause:i})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=new H(a[1]);return new R({parentfeatureset:a[0],orderbyclause:e})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0]))return new O({parentfeatureset:a[0],topnum:a[1]});if(ie(a[0]))return S(a[1])>=a[0].length?a[0].slice():a[0].slice(0,S(a[1]));if(A(a[0]))return S(a[1])>=a[0].length()?a[0].slice():a[0].slice(0,S(a[1]));throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"top",min:2,max:2}),e.functions.first=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,1,t,n),h(a[0])){const n=await a[0].first(e.abortSignal);if(null!==n){const e=s.createFromGraphicLikeObject(n.geometry,n.attributes,a[0],t.timeZone);return e._underlyingGraphic=n,e}return n}return ie(a[0])?0===a[0].length?null:a[0][0]:A(a[0])?0===a[0].length()?null:a[0].get(0):null})},e.signatures.push({name:"first",min:1,max:1}),e.functions.attachments=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{y(r,1,2,t,n);const s={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(r.length>1)if(r[1]instanceof i){if(r[1].hasField("minsize")&&(s.minsize=S(r[1].field("minsize"))),r[1].hasField("metadata")&&(s.returnMetadata=E(r[1].field("metadata"))),r[1].hasField("maxsize")&&(s.maxsize=S(r[1].field("maxsize"))),r[1].hasField("types")){const e=L(r[1].field("types"),!1);e.length>0&&(s.types=e)}}else if(null!==r[1])throw new o(t,"InvalidParameter",n);if(N(r[0])){const e=r[0]._layer;let n;if(h(e))n=e;else{if(null==e||!G(e))return[];n=d(e,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}return await n.load(),n.queryAttachments(r[0].field(n.objectIdField),s.minsize,s.maxsize,s.types,s.returnMetadata)}if(null===r[0])return[];throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"attachments",min:1,max:2}),e.functions.featuresetbyrelationshipname=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,4,t,n);const r=a[0],s=g(a[1]);let l=x(a[2],null);const f=E(x(a[3],!0));if(null===l&&(l=["*"]),!1===ie(l))throw new o(t,"InvalidParameter",n);if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);const m=r._layer;let p;if(h(m))p=m;else{if(null==m||!G(m))return null;p=d(m,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}p=await p.load();const w=p.relationshipMetaData().filter(e=>e.name===s);if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(p,w[0],r.field(p.objectIdField),p.spatialReference,l,f,t.lrucache,t.interceptor);let I=p.serviceUrl();if(!I)return null;I=I.endsWith("/")?I+w[0].relatedTableId.toString():I+"/"+w[0].relatedTableId.toString();const F=await c(I,p.spatialReference,l,f,t.lrucache,t.interceptor);await F.load();let b=F.relationshipMetaData();if(b=b.filter(e=>e.id===w[0].id),!1===r.hasField(w[0].keyField)||null===r.field(w[0].keyField)){const e=await p.getFeatureByObjectId(r.field(p.objectIdField),[w[0].keyField]);if(e){const t=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new z({parentfeatureset:F})}const T=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:r.field(w[0].keyField)},F.filter(T)})},e.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),e.functions.featuresetbyassociation=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,3,t,n);const s=a[0],l=r(g(x(a[1],""))),f=ne(a[2])?g(a[2]):null;if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);let u=s._layer;if(u instanceof Q&&(u=d(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)),null===u)return null;if(!1===h(u))return null;await u.load();const c=u.serviceUrl(),p=await m(c,t.spatialReference,!0);if(p.unVersion>=8)return await pe(u,s,l,f,p,t,n);const w=p.associations;let I=null,F=null,b=!1;if(null!==f&&""!==f&&void 0!==f){for(const e of p.terminals)e.terminalName===f&&(F=e.terminalId);null===F&&(b=!0)}const T=w.getFieldsIndex(),D=T.get("TOGLOBALID").name,E=T.get("FROMGLOBALID").name,A=T.get("TOTERMINALID").name,v=T.get("FROMTERMINALID").name,S=T.get("FROMNETWORKSOURCEID").name,L=T.get("TONETWORKSOURCEID").name,C=T.get("ASSOCIATIONTYPE").name,M=T.get("ISCONTENTVISIBLE").name,R=T.get("OBJECTID").name;for(const t of u.fields)if("global-id"===t.type){I=s.field(t.name);break}let O=null,z=new k(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new k(new J({name:"side",alias:"side",type:"string"}),q.create("''",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));const H="globalid",G="globalId",_={};for(const t in p.lkp)_[t]=p.lkp[t].sourceId;const B=new Z(new J({name:"classname",alias:"classname",type:"string"}),null,_);let K="";switch(l){case"midspan":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (5))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new k(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),z=p.unVersion>=4?new U(P.findField(w.fields,T.get("PERCENTALONG").name)):new k(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (4,6))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new k(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new k(new J({name:"side",alias:"side",type:"string"}),q.create(`CASE WHEN (${C}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${D}='@T'`,t=`${E}='@T'`;null!==F&&(e+=` AND ${A}=@A`,t+=` AND ${v}=@A`),K="(("+e+") OR ("+t+"))",K=j(K,"@T",I??""),e=j(e,"@T",I??""),null!==F&&(e=j(e,"@A",F.toString()),K=j(K,"@A",F.toString())),B.codefield=q.create("CASE WHEN "+e+` THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const n=V(P.findField(w.fields,E));n.name=H,n.alias=H,O=new k(n,q.create("CASE WHEN "+e+` THEN ${E} ELSE ${D} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"container":K=`${D}='${I}' AND ${C} = 2`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,H);break;case"content":K=`(${E}='${I}' AND ${C} = 2)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,H);break;case"structure":K=`(${D}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,G);break;case"attached":K=`(${E}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,G);break;default:throw new o(t,"InvalidParameter",n)}b&&(K="1 <> 1");return new P({parentfeatureset:w,adaptedFields:[new U(P.findField(w.fields,R)),new U(P.findField(w.fields,M)),O,W,B,z],extraFilter:K?q.create(K,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}):null})})},e.signatures.push({name:"featuresetbyassociation",min:2,max:6}),e.functions.groupby=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(y(s,3,3,t,n),!h(s[0]))throw new o(t,"InvalidParameter",n);const l=await s[0].load(),f=[],d=[];let u=!1,c=[];if(ne(s[1]))c.push(s[1]);else if(s[1]instanceof i)c.push(s[1]);else if(ie(s[1]))c=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);c=s[1].toArray()}for(const e of c)if(ne(e)){const t=q.create(g(e),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";f.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(u=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",a=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(u=!0),!i)throw new o(t,"InvalidParameter",n);f.push({name:i,expression:q.create(a||i,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],ne(s[2]))c.push(s[2]);else if(ie(s[2]))c=s[2];else if(A(s[2]))c=s[2].toArray();else{if(!(s[2]instanceof i))throw new o(t,"InvalidParameter",n);c.push(s[2])}for(const e of c){if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"",a=e.hasField("statistic")?e.field("statistic"):"",r=e.hasField("expression")?e.field("expression"):"";if(!(i&&a&&ne(a)&&r))throw new o(t,"InvalidParameter",n);d.push({name:i,statistic:a,expression:q.create(r,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of f)oe(n.expression,e,t);for(const n of d)oe(n.expression,e,t);return s[0].groupby(f,d)})},e.signatures.push({name:"groupby",min:3,max:3}),e.functions.distinct=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(h(s[0])){y(s,2,2,t,n);const a=await s[0].load(),r=[];let l=[];if(ne(s[1]))l.push(s[1]);else if(s[1]instanceof i)l.push(s[1]);else if(ie(s[1]))l=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);l=s[1].toArray()}let f=!1;for(const e of l)if(ne(e)){const t=q.create(g(e),{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";r.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(f=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",s=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(f=!0),!i)throw new o(t,"InvalidParameter",n);r.push({name:i,expression:q.create(s||i,{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC})})}}if(f){const e={};for(const n of a.fields)e[n.name.toLowerCase()]=1;for(const n of r)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of r)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of r)oe(n.expression,e,t);return s[0].groupby(r,[])}return re(s)})},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{if(y(r,1,1,t,n),!h(r[0]))return null;const o=await r[0].getFeatureSetInfo();return o?i.convertObjectToArcadeDictionary({layerId:o.layerId,layerName:o.layerName,itemId:o.itemId,serviceLayerUrl:o.serviceLayerUrl,webMapLayerId:o.webMapLayerId??null,webMapLayerTitle:o.webMapLayerTitle??null,className:null,objectClassId:null},b(t),!1,!1):null})},e.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),e.functions.filterbysubtypecode=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=await a[0].load(),i=a[1];if(!ae(i))throw new o(t,"InvalidParameter",n);if(e.subtypeField){const t=q.create(`${e.subtypeField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new o(t,"FeatureSetDoesNotHaveSubtypes",n);const r=q.create(`${e.typeIdField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:r})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filterbysubtypecode",min:2,max:2})}}export{ye as registerFunctions};
|
|
5
|
+
import e from"../../Graphic.js";import{ArcadeDate as t}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import i from"../Dictionary.js";import{StringEnum as a,toStringEnumKey as r}from"../enum.js";import{ArcadeExecutionError as o}from"../executionError.js";import{Feature as s}from"../Feature.js";import{convertToFeatureSet as l,constructFeatureSetFromPortalItem as f,constructFeatureSet as d,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as m}from"../featureSetUtils.js";import p from"../ImmutableArray.js";import{B as y,g as w,f as I,m as h,u as g,N as F,K as b,e as T,l as D,J as x,H as E,k as N,j as A,i as v,s as S,L,Z as j}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as k,FieldRename as $,AdaptedFeatureSet as P,OriginalField as U}from"../featureset/actions/Adapted.js";import M from"../featureset/actions/AttributeFilter.js";import R from"../featureset/actions/OrderBy.js";import O from"../featureset/actions/Top.js";import z from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import H from"../featureset/support/OrderbyClause.js";import{isSupportedLayer as G,cloneField as V}from"../featureset/support/shared.js";import{isSingleField as _}from"../featureset/support/sqlUtils.js";import{calculateStat as B}from"./fieldStats.js";import{isPromiseLike as K}from"../../core/promiseUtils.js";import q from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";import{queryAssociations as X}from"../../rest/networks/queryAssociations.js";import ee from"../../rest/networks/support/NetworkElement.js";import te from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ne,isArray as ie,isInteger as ae}from"../../support/guards.js";function re(e){if(1===e.length){if(ie(e[0]))return B("distinct",e[0],-1);if(A(e[0]))return B("distinct",e[0].toArray(),-1)}return B("distinct",e,-1)}function oe(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function se(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function le(e){if(null===e)return null;const t={type:se(e,"type",""),name:se(e,"name","")};if("range"===t.type)t.range=se(e,"range",[]);else{t.codedValues=[];for(const n of se(e,"codedValues",[]))t.codedValues.push({name:se(n,"name",""),code:se(n,"code",null)})}return t}function fe(e){if(null===e)return null;const t={},n=se(e,"wkt");null!==n&&(t.wkt=n);const i=se(e,"wkid");return null!==i&&(t.wkid=i),t}function de(e){if(null===e)return null;const t={hasZ:se(e,"hasz",!1),hasM:se(e,"hasm",!1)},n=se(e,"spatialreference");null!=n&&(t.spatialReference=fe(n));const i=se(e,"x",null);if(null!==i)return t.x=i,t.y=se(e,"y",null),t.hasZ&&(t.z=se(e,"z",null)),t.hasM&&(t.m=se(e,"m",null)),t;const a=se(e,"rings",null);if(null!==a)return t.rings=a,t;const r=se(e,"paths",null);if(null!==r)return t.paths=r,t;const o=se(e,"points",null);if(null!==o)return t.points=o,t;for(const s of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=se(e,s,null);null!==n&&(t[s]=n)}return t}function ue(e,t){for(const n of t)if(n===e)return!0;return!1}function ce(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ue(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==ie(e.layerDefinition.fields)&&!1!==ie(e.featureSet.features))))}function me(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function pe(t,n,i,a,r,s,l){const f=await t.getFeatureSetInfo();if(null===(f?.layerId??null))return null;if(!r.layerIdLookup.get(f.layerId))return null;const u=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),c=[];switch(i){case"connected":c.push("connectivity"),c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity"),c.push("junction-edge-midspan-connectivity"),c.push("junction-junction-connectivity");break;case"container":case"content":c.push("containment");break;case"structure":case"attached":c.push("attachment");break;case"junctionedge":c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity");break;case"midspan":c.push("junction-edge-midspan-connectivity");break;default:throw new o(s,"InvalidParameter",l)}let m=null,p=!1;if(null!==a&&""!==a&&void 0!==a){for(const e of r.terminals)e.terminalName===a&&(m=e.terminalId);null===m&&(p=!0)}const y=[];if(!p){const a=new ee({globalId:n.field(t.globalIdField),networkSourceId:r.layerIdLookup.get(f.layerId).sourceId,...m?{terminalId:m}:""}),o=await X(u,new te({types:c,elements:[a]}));let s=0;for(const t of o.associations){let n=null,o="",l="";if(t.fromNetworkElement?.globalId===a.globalId?(n=t.toNetworkElement,l="to"):t.toNetworkElement?.globalId===a.globalId&&(n=t.fromNetworkElement,l="from"),!n)continue;switch(i){case"attached":if("attachment"!==t.associationType)continue;if("to"!==l)continue;break;case"structure":if("attachment"!==t.associationType)continue;if("from"!==l)continue;break;case"container":if("containment"!==t.associationType)continue;if("from"!==l)continue;break;case"content":if("containment"!==t.associationType)continue;if("to"!==l)continue;break;case"connected":break;case"junctionedge":"junction-edge-to-connectivity"===t.associationType?o="to":"junction-edge-from-connectivity"===t.associationType&&(o="from");break;case"midspan":if("junction-edge-midspan-connectivity"!==t.associationType)continue}const f=r.sourceIdLookup.get(n.networkSourceId)?.className??"";y.push(new e({geometry:null,attributes:{objectId:s++,globalId:n.globalId,percentAlong:t.percentAlong??0,isContentVisible:t.isContentVisible?0:1,className:f,side:o}}))}}const w=new Q({source:y,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new J({name:"objectId",alias:"objectId",type:"oid"}),new J({name:"globalId",alias:"globalId",type:"global-id"}),new J({name:"percentAlong",alias:"percentAlong",type:"double"}),new J({name:"side",alias:"side",type:"string"}),new J({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new J({name:"className",alias:"className",type:"string"})]});return d(w)}function ye(e){if("async"===e.mode){e.functions.timezone=function(n,a){return e.standardFunctionAsync(n,a,async(e,r,s)=>{if(y(s,1,2,n,a),w(s[0]))return"Unknown";if(I(s[0]))return"Unknown";if(h(s[0])){if(await s[0].load(),1===s.length||null===s[1])return s[0].datesInUnknownTimezone?me("unknown"):me(s[0].dateFieldsTimeZone);if(!(s[1]instanceof i)||!1===s[1].hasField("type"))throw new o(n,"InvalidParameter",a);const e=s[1].field("type");if(!1===ne(e))throw new o(n,"InvalidParameter",a);switch(g(e).toLowerCase()){case"preferredtimezone":return me(s[0].preferredTimeZone);case"editfieldsinfo":return me(s[0].editFieldsInfo?.timeZone??null);case"timeinfo":return me(s[0].timeInfo?.timeZone??null);case"field":if(s[1].hasField("fieldname")&&ne(s[1].field("fieldname")))return me(s[0].fieldTimeZone(g(s[1].field("fieldname"))))}throw new o(n,"InvalidParameter",a)}const l=F(s[0],b(n));if(null===l)return null;const f=l.timeZone;return"system"===f?t.systemTimeZoneCanonicalName:"utc"===f.toLowerCase()?"UTC":"unknown"===f.toLowerCase()?"Unknown":f})},e.functions.sqltimestamp=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,1,3,t,n);const r=a[0];if(T(r)){if(1===a.length)return r.toSQLWithKeyword();if(2===a.length)return r.changeTimeZone(g(a[1])).toSQLWithKeyword();throw new o(t,"InvalidParameter",n)}if(I(r))return r.toSQLWithKeyword();if(h(r)){if(3!==a.length)throw new o(t,"InvalidParameter",n);await r.load();const e=g(a[1]);if(I(a[2]))return a[2].toSQLWithKeyword();if(!1===T(a[2]))throw new o(t,"InvalidParameter",n);const i=r.fieldTimeZone(e);return null==i?a[2].toSQLWithKeyword():a[2].changeTimeZone(i).toSQLWithKeyword()}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,(e,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetById(e,r,i)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"featuresetbyid",min:2,max:4});const B=new a(["datasource","parent","root"]);e.functions.getfeatureset=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,2,t,n),N(a[0])){const e=null==a[1]?"datasource":B.lookup(g(a[1]));return l(a[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"getfeatureset",min:1,max:2}),e.functions.featuresetbyportalitem=function(t,i){return e.standardFunctionAsync(t,i,(e,a,r)=>{if(y(r,2,5,t,i),null===r[0])throw new o(t,"PortalRequired",i);if(r[0]instanceof n){const e=g(r[1]),n=g(r[2]);let a=x(r[3],null);const s=E(x(r[4],!0));if(null===a&&(a=["*"]),!1===ie(a))throw new o(t,"InvalidParameter",i);let l;return l=t.services?.portal?t.services.portal:Y.getDefault(),l=C(r[0],l),f(e,n,t.spatialReference,a,s,l,t.lrucache,t.interceptor)}if(!1===ne(r[0]))throw new o(t,"PortalRequired",i);const s=g(r[0]),l=g(r[1]);let d=x(r[2],null);const u=E(x(r[3],!0));if(null===d&&(d=["*"]),!1===ie(d))throw new o(t,"InvalidParameter",i);return f(s,l,t.spatialReference,d,u,t.services?.portal??Y.getDefault(),t.lrucache,t.interceptor)})},e.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),e.functions.featuresetbyname=function(t,n){return e.standardFunctionAsync(t,n,(e,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetByName(e,r,i)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"featuresetbyname",min:2,max:4}),e.functions.featureset=function(t,n){return e.standardFunction(t,n,(e,a,r)=>{y(r,1,1,t,n);const s={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ne(r[0])){const e=JSON.parse(r[0]);void 0!==e.layerDefinition?(s.layerDefinition=e.layerDefinition,s.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(s.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(s.featureSet.features=e.features,s.featureSet.geometryType=e.geometryType,s.layerDefinition.geometryType=s.featureSet.geometryType,s.layerDefinition.objectIdField=e.objectIdFieldName??"",s.layerDefinition.typeIdField=e.typeIdFieldName,s.layerDefinition.globalIdField=e.globalIdFieldName,s.layerDefinition.fields=e.fields,e.spatialReference&&(s.layerDefinition.spatialReference=e.spatialReference))}else{if(!(r[0]instanceof i))throw new o(t,"InvalidParameter",n);{const e=JSON.parse(r[0].castToText(!0)),i=se(e,"layerdefinition");if(null!==i){s.layerDefinition.geometryType=se(i,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.globalIdField=se(i,"globalidfield",""),s.layerDefinition.objectIdField=se(i,"objectidfield",""),s.layerDefinition.typeIdField=se(i,"typeidfield",""),s.layerDefinition.hasZ=!0===se(i,"hasz",!1),s.layerDefinition.hasM=!0===se(i,"hasm",!1);const t=se(i,"spatialreference");t&&(s.layerDefinition.spatialReference=fe(t));const n=[];for(const e of se(i,"fields",[])){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};n.push(t)}s.layerDefinition.fields=n;const a=se(e,"featureset");if(a){const e={};for(const t of n)e[t.name.toLowerCase()]=t.name;for(const t of se(a,"features",[])){const n={},i=se(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];s.featureSet.features.push({attributes:n,geometry:de(se(t,"geometry"))})}}}else{s.layerDefinition.hasZ=!0===se(e,"hasz",!1),s.layerDefinition.hasM=!0===se(e,"hasm",!1),s.layerDefinition.geometryType=se(e,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.objectIdField=se(e,"objectidfieldname",""),s.layerDefinition.typeIdField=se(e,"typeidfieldname","");const i=se(e,"spatialreference");i&&(s.layerDefinition.spatialReference=fe(i));const a=[],r=se(e,"fields",null);if(!ie(r))throw new o(t,"InvalidParameter",n);for(const e of r){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};a.push(t)}s.layerDefinition.fields=a;const l={};for(const e of a)l[e.name.toLowerCase()]=e.name;let f=se(e,"features",null);if(ie(f))for(const e of f){const t={},n=se(e,"attributes",{});for(const e in n)t[l[e.toLowerCase()]]=n[e];s.featureSet.features.push({attributes:t,geometry:de(se(e,"geometry",null))})}else f=null,s.featureSet.features=f}}}if(!1===ce(s))throw new o(t,"InvalidParameter",n);return s.layerDefinition.geometryType||(s.layerDefinition.geometryType="esriGeometryNull"),W.create(s,t.spatialReference)})},e.signatures.push({name:"featureset",min:1,max:1}),e.functions.filter=function(t,n){return e.standardFunctionAsync(t,n,async(i,a,r)=>{if(y(r,2,2,t,n),ie(r[0])||A(r[0])){const e=[];let i,a=r[0];if(a instanceof p&&(a=a.toArray()),!v(r[1]))throw new o(t,"InvalidParameter",n);i=r[1].createFunction(t);for(const t of a){const n=i(t);K(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(h(r[0])){const n=await r[0].load(),i=q.create(r[1],{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC}),a=i.getVariables();if(a.length>0){const n={};for(const i of a)n[i]=e.evaluateIdentifier(t,{name:i});i.parameters=n}return new M({parentfeatureset:r[0],whereclause:i})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=new H(a[1]);return new R({parentfeatureset:a[0],orderbyclause:e})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0]))return new O({parentfeatureset:a[0],topnum:a[1]});if(ie(a[0]))return S(a[1])>=a[0].length?a[0].slice():a[0].slice(0,S(a[1]));if(A(a[0]))return S(a[1])>=a[0].length()?a[0].slice():a[0].slice(0,S(a[1]));throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"top",min:2,max:2}),e.functions.first=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,1,t,n),h(a[0])){const n=await a[0].first(e.abortSignal);if(null!==n){const e=s.createFromGraphicLikeObject(n.geometry,n.attributes,a[0],t.timeZone);return e._underlyingGraphic=n,e}return n}return ie(a[0])?0===a[0].length?null:a[0][0]:A(a[0])?0===a[0].length()?null:a[0].get(0):null})},e.signatures.push({name:"first",min:1,max:1}),e.functions.attachments=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{y(r,1,2,t,n);const s={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(r.length>1)if(r[1]instanceof i){if(r[1].hasField("minsize")&&(s.minsize=S(r[1].field("minsize"))),r[1].hasField("metadata")&&(s.returnMetadata=E(r[1].field("metadata"))),r[1].hasField("maxsize")&&(s.maxsize=S(r[1].field("maxsize"))),r[1].hasField("types")){const e=L(r[1].field("types"),!1);e.length>0&&(s.types=e)}}else if(null!==r[1])throw new o(t,"InvalidParameter",n);if(N(r[0])){const e=r[0]._layer;let n;if(h(e))n=e;else{if(null==e||!G(e))return[];n=d(e,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}return await n.load(),n.queryAttachments(r[0].field(n.objectIdField),s.minsize,s.maxsize,s.types,s.returnMetadata)}if(null===r[0])return[];throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"attachments",min:1,max:2}),e.functions.featuresetbyrelationshipname=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,4,t,n);const r=a[0],s=g(a[1]);let l=x(a[2],null);const f=E(x(a[3],!0));if(null===l&&(l=["*"]),!1===ie(l))throw new o(t,"InvalidParameter",n);if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);const m=r._layer;let p;if(h(m))p=m;else{if(null==m||!G(m))return null;p=d(m,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}p=await p.load();const w=p.relationshipMetaData().filter(e=>e.name===s);if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(p,w[0],r.field(p.objectIdField),p.spatialReference,l,f,t.lrucache,t.interceptor);let I=p.serviceUrl();if(!I)return null;I=I.endsWith("/")?I+w[0].relatedTableId.toString():I+"/"+w[0].relatedTableId.toString();const F=await c(I,p.spatialReference,l,f,t.lrucache,t.interceptor);await F.load();let b=F.relationshipMetaData();if(b=b.filter(e=>e.id===w[0].id),!1===r.hasField(w[0].keyField)||null===r.field(w[0].keyField)){const e=await p.getFeatureByObjectId(r.field(p.objectIdField),[w[0].keyField]);if(e){const t=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new z({parentfeatureset:F})}const T=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:r.field(w[0].keyField)},F.filter(T)})},e.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),e.functions.featuresetbyassociation=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,3,t,n);const s=a[0],l=r(g(x(a[1],""))),f=ne(a[2])?g(a[2]):null;if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);let u=s._layer;if(u instanceof Q&&(u=d(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)),null===u)return null;if(!1===h(u))return null;await u.load();const c=u.serviceUrl(),p=await m(c,t.spatialReference,!0);if(p.unVersion>=8)return await pe(u,s,l,f,p,t,n);const w=p.associations;let I=null,F=null,b=!1;if(null!==f&&""!==f&&void 0!==f){for(const e of p.terminals)e.terminalName===f&&(F=e.terminalId);null===F&&(b=!0)}const T=w.getFieldsIndex(),D=T.get("TOGLOBALID").name,E=T.get("FROMGLOBALID").name,A=T.get("TOTERMINALID").name,v=T.get("FROMTERMINALID").name,S=T.get("FROMNETWORKSOURCEID").name,L=T.get("TONETWORKSOURCEID").name,C=T.get("ASSOCIATIONTYPE").name,M=T.get("ISCONTENTVISIBLE").name,R=T.get("OBJECTID").name;for(const t of u.fields)if("global-id"===t.type){I=s.field(t.name);break}let O=null,z=new Z(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new Z(new J({name:"side",alias:"side",type:"string"}),q.create("''",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));const H="globalid",G="globalId",_={};for(const t in p.lkp)_[t]=p.lkp[t].sourceId;const B=new k(new J({name:"classname",alias:"classname",type:"string"}),null,_);let K="";switch(l){case"midspan":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (5))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new Z(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),z=p.unVersion>=4?new U(P.findField(w.fields,T.get("PERCENTALONG").name)):new Z(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (4,6))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new Z(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new Z(new J({name:"side",alias:"side",type:"string"}),q.create(`CASE WHEN (${C}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${D}='@T'`,t=`${E}='@T'`;null!==F&&(e+=` AND ${A}=@A`,t+=` AND ${v}=@A`),K="(("+e+") OR ("+t+"))",K=j(K,"@T",I??""),e=j(e,"@T",I??""),null!==F&&(e=j(e,"@A",F.toString()),K=j(K,"@A",F.toString())),B.codefield=q.create("CASE WHEN "+e+` THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const n=V(P.findField(w.fields,E));n.name=H,n.alias=H,O=new Z(n,q.create("CASE WHEN "+e+` THEN ${E} ELSE ${D} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"container":K=`${D}='${I}' AND ${C} = 2`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,H);break;case"content":K=`(${E}='${I}' AND ${C} = 2)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,H);break;case"structure":K=`(${D}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,G);break;case"attached":K=`(${E}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,G);break;default:throw new o(t,"InvalidParameter",n)}b&&(K="1 <> 1");return new P({parentfeatureset:w,adaptedFields:[new U(P.findField(w.fields,R)),new U(P.findField(w.fields,M)),O,W,B,z],extraFilter:K?q.create(K,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}):null})})},e.signatures.push({name:"featuresetbyassociation",min:2,max:6}),e.functions.groupby=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(y(s,3,3,t,n),!h(s[0]))throw new o(t,"InvalidParameter",n);const l=await s[0].load(),f=[],d=[];let u=!1,c=[];if(ne(s[1]))c.push(s[1]);else if(s[1]instanceof i)c.push(s[1]);else if(ie(s[1]))c=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);c=s[1].toArray()}for(const e of c)if(ne(e)){const t=q.create(g(e),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";f.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(u=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",a=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(u=!0),!i)throw new o(t,"InvalidParameter",n);f.push({name:i,expression:q.create(a||i,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],ne(s[2]))c.push(s[2]);else if(ie(s[2]))c=s[2];else if(A(s[2]))c=s[2].toArray();else{if(!(s[2]instanceof i))throw new o(t,"InvalidParameter",n);c.push(s[2])}for(const e of c){if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"",a=e.hasField("statistic")?e.field("statistic"):"",r=e.hasField("expression")?e.field("expression"):"";if(!(i&&a&&ne(a)&&r))throw new o(t,"InvalidParameter",n);d.push({name:i,statistic:a,expression:q.create(r,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of f)oe(n.expression,e,t);for(const n of d)oe(n.expression,e,t);return s[0].groupby(f,d)})},e.signatures.push({name:"groupby",min:3,max:3}),e.functions.distinct=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(h(s[0])){y(s,2,2,t,n);const a=await s[0].load(),r=[];let l=[];if(ne(s[1]))l.push(s[1]);else if(s[1]instanceof i)l.push(s[1]);else if(ie(s[1]))l=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);l=s[1].toArray()}let f=!1;for(const e of l)if(ne(e)){const t=q.create(g(e),{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";r.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(f=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",s=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(f=!0),!i)throw new o(t,"InvalidParameter",n);r.push({name:i,expression:q.create(s||i,{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC})})}}if(f){const e={};for(const n of a.fields)e[n.name.toLowerCase()]=1;for(const n of r)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of r)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of r)oe(n.expression,e,t);return s[0].groupby(r,[])}return re(s)})},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{if(y(r,1,1,t,n),!h(r[0]))return null;const o=await r[0].getFeatureSetInfo();return o?i.convertObjectToArcadeDictionary({layerId:o.layerId,layerName:o.layerName,itemId:o.itemId,serviceLayerUrl:o.serviceLayerUrl,webMapLayerId:o.webMapLayerId??null,webMapLayerTitle:o.webMapLayerTitle??null,className:null,objectClassId:null},b(t),!1,!1):null})},e.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),e.functions.filterbysubtypecode=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=await a[0].load(),i=a[1];if(!ae(i))throw new o(t,"InvalidParameter",n);if(e.subtypeField){const t=q.create(`${e.subtypeField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new o(t,"FeatureSetDoesNotHaveSubtypes",n);const r=q.create(`${e.typeIdField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:r})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filterbysubtypecode",min:2,max:2})}}export{ye 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.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,Q as r,u as o,m as i,
|
|
5
|
+
import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,Q as r,u as o,m as i,a2 as c,V as s,K as d,T as u,a3 as m,S as f,a4 as l,J as y,t as v,U as w}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as p}from"../featureset/support/shared.js";function h(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:p[a.field.type],codedValues:a.domain.codedValues.map(n=>({name:n.name,code:n.code}))},d(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:p[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},d(e)):null}function T(p){"async"===p.mode&&(p.functions.domain=function(n,s){return p.standardFunctionAsync(n,s,async(d,u,m)=>{if(e(m,2,3,n,s),t(m[0])){return h(r(m[0],o(m[1]),void 0===m[2]?void 0:m[2]),n)}if(i(m[0])){await m[0]._ensureLoaded();return h(c(o(m[1]),m[0],null,void 0===m[2]?void 0:m[2]),n)}throw new a(n,"InvalidParameter",s)})},p.functions.subtypes=function(r,o){return p.standardFunctionAsync(r,o,async(c,u,m)=>{if(e(m,1,1,r,o),t(m[0])){const a=s(m[0]);return a?n.convertObjectToArcadeDictionary(a,d(r)):null}if(i(m[0])){await m[0]._ensureLoaded();const a=m[0].subtypeMetaData();return a?n.convertObjectToArcadeDictionary(a,d(r)):null}throw new a(r,"InvalidParameter",o)})},p.functions.domainname=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,f)=>{if(e(f,2,4,n,r),t(f[0]))return u(f[0],o(f[1]),f[2],void 0===f[3]?void 0:f[3]);if(i(f[0])){await f[0]._ensureLoaded();const n=c(o(f[1]),f[0],null,void 0===f[3]?void 0:f[3]);return m(n,f[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domainname",min:2,max:4}),p.functions.domaincode=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,u)=>{if(e(u,2,4,n,r),t(u[0]))return f(u[0],o(u[1]),u[2],void 0===u[3]?void 0:u[3]);if(i(u[0])){await u[0]._ensureLoaded();const n=c(o(u[1]),u[0],null,void 0===u[3]?void 0:u[3]);return l(n,u[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domaincode",min:2,max:4}),p.functions.text=function(n,t){return p.standardFunctionAsync(n,t,async(r,o,c)=>{if(e(c,1,2,n,t),i(c[0])){const e=y(c[1],"");if(""===e)return c[0].castToText();if("schema"===e.toLowerCase())return c[0].convertToText("schema",r.abortSignal);if("featureset"===e.toLowerCase())return c[0].convertToText("featureset",r.abortSignal);throw new a(n,"InvalidParameter",t)}return v(c[0],c[1])})},p.functions.gdbversion=function(n,r){return p.standardFunctionAsync(n,r,async(o,c,s)=>{if(e(s,1,1,n,r),t(s[0]))return s[0].gdbVersion();if(i(s[0])){return(await s[0].load()).gdbVersion}throw new a(n,"InvalidParameter",r)})},p.functions.schema=function(r,o){return p.standardFunctionAsync(r,o,async(c,s,u)=>{if(e(u,1,1,r,o),i(u[0]))return await u[0].load(),n.convertObjectToArcadeDictionary(u[0].schema(),d(r));if(t(u[0])){const a=w(u[0]);return a?n.convertObjectToArcadeDictionary(a,d(r)):null}throw new a(r,"InvalidParameter",o)})})}export{T 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.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{
|
|
5
|
+
import{$ as e,v as t,x as r}from"../../chunks/languageUtils.js";import{isNumber as n,isString as s}from"../../support/guards.js";function a(e){let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t/e.length}function u(e){const t=a(e);let r=0;for(let n=0;n<e.length;n++)r+=(t-e[n])**2;return r/e.length}function c(e){let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t}function o(e,a){const u=[],c={},o=[];for(let i=0;i<e.length;i++){if(void 0!==e[i]&&null!==e[i]&&e[i]!==t){const t=e[i];if(n(t)||s(t))void 0===c[t]&&(u.push(t),c[t]=1);else{let e=!1;for(let n=0;n<o.length;n++)!0===r(o[n],t)&&(e=!0);!1===e&&(o.push(t),u.push(t))}}if(u.length>=a&&-1!==a)return u}return u}function i(e){switch(e.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function l(t,r,n=1e3){switch(t.toLowerCase()){case"distinct":return o(r,n);case"avg":case"mean":return a(e(r));case"min":return Math.min.apply(Math,e(r));case"sum":return c(e(r));case"max":return Math.max.apply(Math,e(r));case"stdev":case"stddev":return Math.sqrt(u(e(r)));case"var":case"variance":return u(e(r));case"count":return r.length}return 0}export{l as calculateStat,i as decodeStatType};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r}from"../executionError.js";import a
|
|
5
|
+
import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r}from"../executionError.js";import{Feature as a}from"../Feature.js";import i from"../ImmutablePointArray.js";import{B as l,j as o,D as s,W as f,C as c,k as u,v as m,n as p,h as w,u as h,e as R,g,f as y,i as d,d as P,K as v,X as I,Y as b,r as O,x as j}from"../../chunks/languageUtils.js";import{angle2D as N,angleBetween2D as S,bearing2D as x,bearingBetween2D as J}from"./centroid.js";import{constructGeometryFromDictionary as F}from"../geometry/constructors.js";import k from"../../geometry/Extent.js";import Z from"../../geometry/Geometry.js";import W from"../../geometry/Multipoint.js";import z from"../../geometry/Point.js";import A from"../../geometry/Polygon.js";import q from"../../geometry/Polyline.js";import{isClockwise as D}from"../../geometry/support/coordsUtils.js";import{fromJSON as M}from"../../geometry/support/jsonUtils.js";import{isArray as G,isString as L,isNumber as U,isBoolean as _}from"../../support/guards.js";function C(C,E){C.ringisclockwise=function(e,t){return E(e,t,(n,a,s)=>{l(s,1,1,e,t);let f=[];if(null===s[0])return!1;if(G(s[0]))for(const i of s[0]){if(!(i instanceof z))throw new r(e,"InvalidParameter",t);f.push(i.hasZ?i.hasM?[i.x,i.y,i.z,i.m]:[i.x,i.y,i.z]:[i.x,i.y])}else if(s[0]instanceof i)f=s[0]._elements;else{if(!o(s[0]))throw new r(e,"InvalidParameter",t);for(const n of s[0].toArray()){if(!(n instanceof z))throw new r(e,"InvalidParameter",t);f.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(f.length<3)&&D(f)})},C.polygon=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"polygon"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof A)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new A(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(c)})},C.polyline=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"polyline"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof q)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new q(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(c)})},C.point=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"point"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof z)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new z(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(c)})},C.multipoint=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"multipoint"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof W)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new W(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(c)})},C.extent=function(e,t){return E(e,t,(a,i,o)=>{o=c(o),l(o,1,1,e,t);let u=null;if(o[0]instanceof n)u=s(F(o[0],e.spatialReference),e.spatialReference);else if(o[0]instanceof z){const e={xmin:o[0].x,ymin:o[0].y,xmax:o[0].x,ymax:o[0].y,spatialReference:o[0].spatialReference.toJSON()},t=o[0];t.hasZ&&(e.zmin=t.z,e.zmax=t.z),t.hasM&&(e.mmin=t.m,e.mmax=t.m),u=M(e)}else if(o[0]instanceof A)u=M(o[0].extent?.toJSON());else if(o[0]instanceof q)u=M(o[0].extent?.toJSON());else if(o[0]instanceof W)u=M(o[0].extent?.toJSON());else if(o[0]instanceof k)u=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=s(new k(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(u)})},C.geometry=function(e,t){return E(e,t,(a,i,o)=>{l(o,1,1,e,t);let c=null;if(null===o[0])return null;if(u(o[0]))c=s(o[0].geometry(),e.spatialReference);else if(o[0]instanceof n)c=s(F(o[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(M(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(c)})},C.setgeometry=function(e,t){return E(e,t,(n,a,i)=>{if(l(i,2,2,e,t),!u(i[0]))throw new r(e,"InvalidParameter",t);if(!0===i[0].immutable)throw new r(e,"Immutable",t);if(!(i[1]instanceof Z||null===i[1]))throw new r(e,"InvalidParameter",t);return i[0]._geometry=i[1],m})},C.feature=function(e,t){return E(e,t,(i,l,o)=>{if(0===o.length)throw new r(e,"WrongNumberOfParameters",t);let f;if(1===o.length)if(L(o[0]))f=a.fromJson(JSON.parse(o[0]),e.timeZone);else if(u(o[0]))f=a.createFromArcadeFeature(o[0]);else if(o[0]instanceof Z)f=a.createFromGraphicLikeObject(o[0],null,null,e.timeZone);else{if(!(o[0]instanceof n))throw new r(e,"InvalidParameter",t);{const n=o[0].hasField("geometry")?o[0].field("geometry"):null,i=o[0].hasField("attributes")?o[0].field("attributes"):null;let l,s;if(p(n))l=F(n,e.spatialReference);else{if(null!=n&&!w(n))throw new r(e,"InvalidParameter",t);l=n}if(p(i))s=a.parseAttributesFromDictionary(i);else{if(null!=i)throw new r(e,"InvalidParameter",t);s=null}f=a.createFromGraphicLikeObject(l,s,null,e.timeZone)}}else if(2===o.length){let i=null,l=null;if(null!==o[0])if(o[0]instanceof Z)i=o[0];else{if(!(o[0]instanceof n))throw new r(e,"InvalidParameter",t);i=F(o[0],e.spatialReference)}if(null!==o[1]){if(!(o[1]instanceof n))throw new r(e,"InvalidParameter",t);l=a.parseAttributesFromDictionary(o[1])}f=a.createFromGraphicLikeObject(i,l,null,e.timeZone)}else{let i=null;const l={};if(null!==o[0])if(o[0]instanceof Z)i=o[0];else{if(!(o[0]instanceof n))throw new r(e,"InvalidParameter",t);i=F(o[0],e.spatialReference)}for(let n=1;n<o.length;n+=2){const a=h(o[n]),i=o[n+1];if(!(null==i||L(i)||isNaN(i)||R(i)||U(i)||g(i)||y(i)||_(i)))throw new r(e,"InvalidParameter",t);if(d(i)||!1===P(i))throw new r(e,"InvalidParameter",t);l[a]=i===m?null:i}f=a.createFromGraphicLikeObject(i,l,null,e.timeZone)}return f._geometry=s(f.geometry(),e.spatialReference),f.immutable=!1,f})},C.dictionary=function(e,t){return E(e,t,(a,i,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&L(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,v(e),!1);return r.immutable=!1,r}catch(c){throw new r(e,"InvalidParameter",t)}if(1===l.length&&l[0]instanceof Z)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,v(e),!1);return r.immutable=!1,r}catch(c){throw new r(e,"InvalidParameter",t)}if(1===l.length&&u(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(c){throw new r(e,"InvalidParameter",t)}if(1===l.length&&(p(l[0])||I(l[0])||b(l[0])))try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(c){throw new r(e,"InvalidParameter",t)}if(2===l.length&&l[0]instanceof n&&_(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(c){throw new r(e,"InvalidParameter",t)}if(l.length%2!=0)throw new r(e,"WrongNumberOfParameters",t);const s=Object.create(null);for(let n=0;n<l.length;n+=2){const a=h(l[n]),i=l[n+1];if(!(null==i||L(i)||isNaN(i)||R(i)||U(i)||_(i)||y(i)||g(i)||G(i)||o(i)))throw new r(e,"InvalidParameter",t);if(d(i))throw new r(e,"InvalidParameter",t);s[a]=i===m?null:i}const f=new n(s);return f.immutable=!1,f})},C.haskey=function(t,a){return E(t,a,(i,o,s)=>{l(s,2,2,t,a);const f=h(s[1]);if(O(s[0])||s[0]instanceof n)return s[0].hasField(f);if(s[0]instanceof Z){const t=e(s[0],f,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,"InvalidParameter",a)})},C.hasvalue=function(e,n){return E(e,n,(r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1])))},C.indexof=function(e,t){return E(e,t,(n,a,i)=>{l(i,2,2,e,t);const s=i[1];if(G(i[0])){for(let e=0;e<i[0].length;e++)if(j(s,i[0][e]))return e;return-1}if(o(i[0])){const e=i[0].length();for(let t=0;t<e;t++)if(j(s,i[0].get(t)))return t;return-1}throw new r(e,"InvalidParameter",t)})},C.angle=function(e,t){return E(e,t,(n,a,i)=>{if(i=c(i),l(i,2,3,e,t),!(i[0]instanceof z))throw new r(e,"InvalidParameter",t);if(!(i[1]instanceof z))throw new r(e,"InvalidParameter",t);if(i.length>2&&!(i[2]instanceof z))throw new r(e,"InvalidParameter",t);return 2===i.length?N(i[0],i[1]):S(i[0],i[1],i[2])})},C.bearing=function(e,t){return E(e,t,(n,a,i)=>{if(i=c(i),l(i,2,3,e,t),!(i[0]instanceof z))throw new r(e,"InvalidParameter",t);if(!(i[1]instanceof z))throw new r(e,"InvalidParameter",t);if(i.length>2&&!(i[2]instanceof z))throw new r(e,"InvalidParameter",t);return 2===i.length?x(i[0],i[1]):J(i[0],i[1],i[2])})}}export{C as registerFunctions};
|