@arcgis/core 4.30.0-next.20240314 → 4.30.0-next.20240316
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/arcade/ImmutableArray.js +1 -1
- package/arcade/arcadeAsyncRuntime.js +1 -1
- package/arcade/featureset/support/FeatureSet.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/arcade/functions/stats.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{08c9226e24b2261388e3.js → 01aa4d8263b9e2be7400.js} +1 -1
- package/assets/esri/core/workers/chunks/{90c569353df5af9ed368.js → 0877c99e0338f8e7c0c8.js} +1 -1
- package/assets/esri/core/workers/chunks/{e678b2a0dc6c2824910a.js → 08e3cb4dbf4238ea13c6.js} +1 -1
- package/assets/esri/core/workers/chunks/{7a588b836715a9c9c25f.js → 0c90fc21b5ce4b917633.js} +1 -1
- package/assets/esri/core/workers/chunks/{c76e155332aa0491de3d.js → 0ef3fee7614596d591ba.js} +1 -1
- package/assets/esri/core/workers/chunks/{2d60f3af5886b7dea9ee.js → 12b95408753cea053a40.js} +1 -1
- package/assets/esri/core/workers/chunks/{b93e601da1592f153a3d.js → 13b6de78894ba1a70ace.js} +1 -1
- package/assets/esri/core/workers/chunks/16397420fb6067b47b25.js +1 -0
- package/assets/esri/core/workers/chunks/{67abe8171d41cf21624f.js → 1696784da83588878989.js} +1 -1
- package/assets/esri/core/workers/chunks/{500f39a5f74fa289df25.js → 178d23040a27419e9c56.js} +1 -1
- package/assets/esri/core/workers/chunks/{604dae6ff05ff4ac516b.js → 25673a9f01e8595aa936.js} +1 -1
- package/assets/esri/core/workers/chunks/{39ff4d571abbd2df5d5b.js → 2707b8ef8ca636e184ba.js} +1 -1
- package/assets/esri/core/workers/chunks/4b25dc661bb958e651fd.js +1 -0
- package/assets/esri/core/workers/chunks/{f5a0f106d9edaddb83fa.js → 4e4c146796a47da2c5a1.js} +1 -1
- package/assets/esri/core/workers/chunks/{f46bc8e507d75d218ac7.js → 5929931ff9ecde6cc084.js} +1 -1
- package/assets/esri/core/workers/chunks/5a747af5273646ab848c.js +1 -0
- package/assets/esri/core/workers/chunks/{da7189c3077f49858dc8.js → 5b6fe9c935e065d59ab7.js} +1 -1
- package/assets/esri/core/workers/chunks/{01fc139749c57bd59e21.js → 67b2e96aceecc01e762c.js} +1 -1
- package/assets/esri/core/workers/chunks/6867fe9937c49e99eb6f.js +2 -0
- package/assets/esri/core/workers/chunks/{b6185ae51c0597914857.js → 6ae0b1007d5319f8407b.js} +1 -1
- package/assets/esri/core/workers/chunks/{fd4ec788953d9776126f.js → 7bc977db7b2dc3d238b5.js} +1 -1
- package/assets/esri/core/workers/chunks/7d7c0aee461571a7c1f8.js +1 -0
- package/assets/esri/core/workers/chunks/{03ae0196aafcb6146f61.js → 7f87af6ec7160e9fd713.js} +1 -1
- package/assets/esri/core/workers/chunks/{4e20931f6a5327a06b1d.js → 7fbdf597f8325e4b3c8e.js} +1 -1
- package/assets/esri/core/workers/chunks/8ca8ae3207b1025d0116.js +1 -0
- package/assets/esri/core/workers/chunks/8cdfd39b5f4d12c77f0b.js +1 -0
- package/assets/esri/core/workers/chunks/{893d96c21d929d38ab58.js → 8efb216c3250bd3a5bd8.js} +1 -1
- package/assets/esri/core/workers/chunks/{c0217dde5ff4d6a4c14c.js → 8fc69ac4cce6d4dd5513.js} +1 -1
- package/assets/esri/core/workers/chunks/{a658dd87b1b59e9cf2a3.js → 97379fed66be783a2e42.js} +1 -1
- package/assets/esri/core/workers/chunks/{a38ab7cb733426de9588.js → 9c78ccff1c7f8ae90b06.js} +1 -1
- package/assets/esri/core/workers/chunks/a64e5463214131bf930a.js +1 -0
- package/assets/esri/core/workers/chunks/{7a3a6bb83b03bbb3e1dc.js → a90504a63550290e6be2.js} +1 -1
- package/assets/esri/core/workers/chunks/ad95daa3f4ad7030bf24.js +1 -0
- package/assets/esri/core/workers/chunks/{4b70d2db1cd9ddf4b453.js → b1d2310b2dbbb9697b88.js} +1 -1
- package/assets/esri/core/workers/chunks/{c67b99d2a8376a15a71b.js → bd6a9816d88d757f143e.js} +1 -1
- package/assets/esri/core/workers/chunks/{1f5b7880ccf47ef9229d.js → c66a8fc83e4b7da81746.js} +1 -1
- package/assets/esri/core/workers/chunks/cccf37e2af3f8c5b2869.js +1 -0
- package/assets/esri/core/workers/chunks/{933f56e7299a5844e367.js → de33bb5df97c66623b68.js} +1 -1
- package/assets/esri/core/workers/chunks/{9656002ff528a7eda746.js → e5cb8297d5824f139b3e.js} +1 -1
- package/assets/esri/core/workers/chunks/eb3e82ed1653ecf348da.js +1 -0
- package/assets/esri/core/workers/chunks/f969c134b1694c4c7cb4.js +1 -0
- package/assets/esri/core/workers/chunks/{85d573c58a6b80c38c1d.js → fe7dfb8546d0fc40843c.js} +1 -1
- package/assets/esri/themes/base/widgets/_Popup.scss +4 -0
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/chunks/Laserlines.glsl.js +1 -1
- package/chunks/sphere.js +1 -1
- package/chunks/vec32.js +1 -1
- package/chunks/vec42.js +1 -1
- package/core/libs/gl-matrix-2/math/quat.js +1 -1
- package/core/libs/gl-matrix-2/math/vec3.js +1 -1
- package/core/libs/gl-matrix-2/math/vec4.js +1 -1
- package/geometry/support/sphere.js +1 -1
- package/interfaces.d.ts +89 -50
- package/layers/Lyr3DWasmPerSceneView.js +1 -1
- package/layers/orientedImagery/transformations/imageToGroundUtils.js +1 -1
- package/layers/support/ControlPointsGeoreference.js +1 -1
- package/layers/support/CornersGeoreference.js +1 -1
- package/layers/support/ExtentAndRotationGeoreference.js +1 -1
- package/layers/support/LocalMediaElementSource.js +1 -1
- package/layers/voxel/VoxelVolume.js +1 -1
- package/networks/Network.js +1 -1
- package/networks/UtilityNetwork.js +1 -1
- package/package.json +1 -1
- package/portal/PortalItemResource.js +1 -1
- package/renderers/support/DictionaryLoader.js +1 -1
- package/renderers/support/RasterSymbolizer.js +1 -1
- package/rest/featureService/FeatureService.js +1 -1
- package/smartMapping/raster/support/adapters/ImageryTileLayerAdapter.js +1 -1
- package/smartMapping/support/adapters/FeatureLayerAdapter.js +1 -1
- package/smartMapping/support/adapters/SceneLayerAdapter.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/CIMSymbolDrawHelper.js +1 -1
- package/symbols/cim/Rasterizer.js +1 -1
- package/symbols/cim/TextRasterizer.js +1 -1
- package/symbols/cim/cimAnalyzer.js +1 -1
- package/versionManagement/VersionManagementService.js +1 -1
- package/views/2d/engine/DisplayObject.js +1 -1
- package/views/2d/engine/webgl/AttributeStoreView.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/TechniqueDebugContainer.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/TechniqueDebugLayer.js +1 -1
- package/views/2d/engine/webgl/shaderGraph/techniques/TestDisplayObject.js +1 -1
- package/views/2d/interactive/editingTools/TransformTool.js +1 -1
- package/views/2d/layers/FeatureLayerView2D.js +1 -1
- package/views/2d/layers/MediaLayerView2D.js +1 -1
- package/views/2d/layers/TileLayerView2D.js +1 -1
- package/views/2d/layers/features/FeatureContainer.js +1 -1
- package/views/2d/layers/features/FeaturePipelineWorker.js +1 -1
- package/views/2d/layers/features/Processor.js +1 -1
- package/views/2d/magnifier/MagnifierView2D.js +1 -1
- package/views/2d/support/hitTestUtils.js +1 -1
- package/views/3d/analysis/AreaMeasurement/support/AreaMeasurementVisualization.js +1 -1
- package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
- package/views/3d/analysis/Dimension/LengthDimensionVisualization.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightController.js +1 -1
- package/views/3d/analysis/LineOfSight/LineOfSightTool.js +1 -1
- package/views/3d/camera/constraintUtils/distance.js +1 -1
- package/views/3d/camera/constraintUtils/tilt.js +1 -1
- package/views/3d/environment/ChapmanAtmosphere.js +1 -1
- package/views/3d/environment/EnvironmentRenderer.js +1 -1
- package/views/3d/environment/LocalAtmosphere.js +1 -1
- package/views/3d/environment/Precipitation.js +1 -1
- package/views/3d/environment/Stars.js +1 -1
- package/views/3d/glTF/internal/Resource.js +1 -1
- package/views/3d/interactive/SnappingVisualizer3D.js +1 -1
- package/views/3d/interactive/editingTools/ManipulatedObject3DGraphic.js +5 -0
- package/views/3d/interactive/editingTools/ManipulatedObject3DMediaElement.js +5 -0
- package/views/3d/interactive/editingTools/lineObjectVisualElementUtils.js +1 -1
- package/views/3d/interactive/editingTools/manipulations/MoveXYObjectManipulation.js +1 -1
- package/views/3d/interactive/editingTools/manipulations/MoveZManipulation.js +1 -1
- package/views/3d/interactive/editingTools/media/MediaElementControllerControlPoints.js +5 -0
- package/views/3d/interactive/editingTools/media/MediaElementControllerShape.js +5 -0
- package/views/3d/interactive/editingTools/media/MediaElementManipulator3D.js +5 -0
- package/views/3d/interactive/editingTools/media/mediaElementUtils.js +5 -0
- package/views/3d/interactive/editingTools/move/MoveTool3D.js +1 -1
- package/views/3d/interactive/editingTools/reshape/ReshapeOperation.js +1 -1
- package/views/3d/interactive/editingTools/reshape/ReshapeTool3D.js +1 -1
- package/views/3d/interactive/editingTools/transform/ExtentTransformTool.js +1 -1
- package/views/3d/interactive/editingTools/transform/TransformTool3D.js +1 -1
- package/views/3d/interactive/editingTools/transform/extentTransform/ExtentRotate.js +1 -1
- package/views/3d/interactive/editingTools/transform/extentTransform/PreserveAspectRatio.js +1 -1
- package/views/3d/interactive/editingTools/transform/extentTransform/SnapRotation.js +5 -0
- package/views/3d/interactive/editingTools/transform/extentTransform/extentUtils.js +1 -1
- package/views/3d/interactive/visualElements/ExtendedLineVisualElement.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/I3SMeshView3D.js +1 -1
- package/views/3d/layers/MediaLayerView3D.js +1 -1
- package/views/3d/layers/PointCloudWorker.js +1 -1
- package/views/3d/layers/PointCloudWorkerHandle.js +1 -1
- package/views/3d/layers/graphics/Deconflictor.js +1 -1
- package/views/3d/layers/graphics/Graphics3DIconSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineCalloutSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DMeshObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObjectStates.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DWaterSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/ObjectResourceCache.js +1 -1
- package/views/3d/layers/graphics/objectResourceUtils.js +1 -1
- package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SViewportQueries.js +1 -1
- package/views/3d/layers/support/FeatureTileVisibility3D.js +1 -1
- package/views/3d/layers/support/MediaLayerInteraction.js +5 -0
- package/views/3d/layers/support/MediaLayerInteractionOptions.js +5 -0
- package/views/3d/layers/support/TemporalSceneLayerView.js +1 -1
- package/views/3d/layers/support/makeScheduleFunction.js +5 -0
- package/views/3d/state/controllers/GamepadKeyboardController.js +1 -1
- package/views/3d/state/controllers/PinchAndPanControllerGlobal.js +1 -1
- package/views/3d/state/controllers/ZoomControllerGlobal.js +1 -1
- package/views/3d/state/controllers/ZoomStepControllerGlobal.js +1 -1
- package/views/3d/state/controllers/momentum/ZoomSphericalMomentumController.js +1 -1
- package/views/3d/state/utils/navigationUtils.js +1 -1
- package/views/3d/support/geometryUtils/sphere.js +1 -1
- package/views/3d/support/hitTest.js +1 -1
- package/views/3d/terrain/OverlayManager.js +1 -1
- package/views/3d/terrain/PatchRenderData.js +1 -1
- package/views/3d/terrain/SphericalPatch.js +1 -1
- package/views/3d/terrain/TerrainSurface.js +1 -1
- package/views/3d/terrain/Tile.js +1 -1
- package/views/3d/webgl/RenderCamera.js +1 -1
- package/views/3d/webgl-engine/lib/Object3D.js +1 -1
- package/views/3d/webgl-engine/lib/Octree.js +1 -1
- package/views/3d/webgl-engine/lib/RenderGeometry.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/depthRangeUtils.js +1 -1
- package/views/3d/webgl-engine/lib/edgeRendering/EdgeView.js +1 -1
- package/views/3d/webgl-engine/lib/intersectorUtilsConversions.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/InstanceOctree.js +1 -1
- package/views/3d/webgl-engine/lib/verticalOffsetUtils.js +1 -1
- package/views/MapView.js +1 -1
- package/views/PopupView.js +1 -1
- package/views/interactive/keybindings.js +1 -1
- package/views/interactive/sketch/constraints.js +1 -1
- package/views/interactive/snapping/featureSources/sceneLayerSource/sceneLayerSnappingUtils.js +1 -1
- package/views/interactive/tooltip/components/DrawHeaderActions.js +1 -1
- package/views/layers/MediaLayerView.d.ts +4 -0
- package/views/layers/MediaLayerView.js +5 -0
- package/views/support/geometry3dUtils.js +1 -1
- package/views/support/waitForResources.js +1 -1
- package/widgets/BasemapLayerList.js +1 -1
- package/widgets/Bookmarks.js +1 -1
- package/widgets/Feature/FeatureContent/FeatureContentViewModel.js +1 -1
- package/widgets/Feature/FeatureExpression.js +1 -1
- package/widgets/Feature/FeatureRelationship.js +1 -1
- package/widgets/Feature/FeatureViewModel.js +1 -1
- package/widgets/Feature/resources.js +1 -1
- package/widgets/Feature/support/featureUtils.js +1 -1
- package/widgets/Feature.js +1 -1
- package/widgets/Features/FeaturesViewModel.js +1 -1
- package/widgets/Home.js +1 -1
- package/widgets/LayerList/support/layerListUtils.js +1 -1
- package/widgets/LayerList.js +1 -1
- package/widgets/Popup/css.js +1 -1
- package/widgets/Popup.js +1 -1
- package/widgets/Sketch/SketchViewModel.js +1 -1
- package/widgets/TableList.js +1 -1
- package/widgets/UtilityNetworkAssociations.js +1 -1
- package/widgets/Zoom.js +1 -1
- package/assets/esri/core/workers/chunks/0feee6447793bc42df9d.js +0 -1
- package/assets/esri/core/workers/chunks/14b9001a3233075dd1b7.js +0 -1
- package/assets/esri/core/workers/chunks/1805a6e63a1bfe6950be.js +0 -1
- package/assets/esri/core/workers/chunks/2ceebeac397374a126ba.js +0 -2
- package/assets/esri/core/workers/chunks/5dc63f28bc608c56d3e6.js +0 -1
- package/assets/esri/core/workers/chunks/678ffc061fe5dec51930.js +0 -1
- package/assets/esri/core/workers/chunks/6c5ea910265d4f6a368d.js +0 -1
- package/assets/esri/core/workers/chunks/6fa0abf415859f40ea6c.js +0 -1
- package/assets/esri/core/workers/chunks/8d9e2d1b62cf4fd5697d.js +0 -1
- package/assets/esri/core/workers/chunks/c018ce3935d5f1e60e3c.js +0 -1
- package/assets/esri/core/workers/chunks/d2e4c01e33691801f9ef.js +0 -1
- package/assets/esri/core/workers/chunks/dd04b5b9ee73b28c5254.js +0 -1
- package/views/3d/interactive/editingTools/ManipulatedObjectGraphic3D.js +0 -5
- /package/assets/esri/core/workers/chunks/{2ceebeac397374a126ba.js.LICENSE.txt → 6867fe9937c49e99eb6f.js.LICENSE.txt} +0 -0
package/arcade/ImmutableArray.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.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
class t{constructor(t=[]){this._elements=t}length(){return this._elements.length}get(t){return this._elements[t]}toArray(){
|
|
5
|
+
class t{constructor(t=[]){this._elements=t}length(){return this._elements.length}get(t){return this._elements[t]}toArray(){return this.slice()}slice(t=0,e=this.length()){const s=[];for(let r=t;r<e;r++)s.push(this.get(r));return s}}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.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import n from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as o,ensureArcadeExecutionError as a}from"./executionError.js";import i from"./Feature.js";import{NativeFunction as l,ArcadeFunction as s,ScopeMarshalledFunction as c,wrapModuleScopedResponse as u}from"./FunctionWrapper.js";import{H as f,a as p,q as w,o as d,r as h,c as m,b as g,F as y,D as v,B as b,C as S,i as x,z as F,u as I,g as C,A,j as R,E as M,G as j,x as k}from"../chunks/languageUtils.js";import{addFunctionDeclaration as L}from"./treeAnalysis.js";import{A as E}from"../chunks/array.js";import{registerFunctions as N}from"./functions/date.js";import{registerFunctions as O}from"./functions/geomasync.js";import{registerFunctions as B,geometryMember as P}from"./functions/geometry.js";import{registerFunctions as K}from"./functions/maths.js";import{registerFunctions as D}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import Z from"../geometry/Geometry.js";import U from"../geometry/SpatialReference.js";function q(e){return e&&"function"==typeof e.then}const T=100;async function W(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await Y(e,t.arguments[r]));return n}async function V(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await W(e,t))}class _ extends s{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,null);return Pe(this.definition,n,t,null)}}call(e,t){return H(e,t,((n,a,i)=>{const l={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(l.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,t);return Pe(this.definition,l,i,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!x(t)||t instanceof c?t:u(t,e,r))),u(await Pe(this.definition,l,i,t),n,r)}))}}class z extends e{constructor(e){super(e)}async global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=await Y(this.executingContext,t.node),t.valueset=!0),x(t.value)&&!(t.value instanceof c)){const e=new c;e.fn=t.value,e.parameterEvaluator=H,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(x(t))throw new r(null,o.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}async loadModule(e){let n=e.spatialReference;null==n&&(n=new U({wkid:102100})),this.moduleScope=Ge({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ze,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await Y(this.executingContext,this.source.syntax)}}async function H(e,t,n){if(!0===t.preparsed){const r=n(e,null,t.arguments);return q(r),r}const r=n(e,t,await W(e,t));return q(r),r}async function Y(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,Y(e,t,!0)}try{switch(t?.type){case"VariableDeclarator":return await xe(e,t);case"ImportDeclaration":return await ve(e,t);case"ExportNamedDeclaration":return await be(e,t);case"VariableDeclaration":return await Se(e,t,0);case"BlockStatement":case"Program":return await he(e,t);case"FunctionDeclaration":return await ye(e,t);case"ReturnStatement":return await ge(e,t);case"IfStatement":return await de(e,t);case"ExpressionStatement":return await we(e,t);case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await pe(e,t);case"ForStatement":return await ne(e,t);case"WhileStatement":return await X(e,t);case"ForInStatement":return await ce(e,t);case"BreakStatement":return S;case"EmptyStatement":return b;case"ContinueStatement":return v;case"TemplateElement":return await ke(e,t);case"TemplateLiteral":return await Ee(e,t);case"Identifier":return await Me(e,t);case"MemberExpression":return await Fe(e,t);case"Literal":return t.value;case"CallExpression":return await je(e,t);case"UnaryExpression":return await Ie(e,t);case"BinaryExpression":return await Ae(e,t);case"LogicalExpression":return await Re(e,t);case"ArrayExpression":return await Ce(e,t);case"ObjectExpression":return await J(e,t);case"Property":return await Q(e,t);default:throw new r(e,o.Unrecognized,t)}}catch(i){throw a(e,t,i)}}async function J(e,t){const a=[];for(let n=0;n<t.properties.length;n++)a[n]=await Y(e,t.properties[n]);const i={},l=new Map;for(let n=0;n<a.length;n++){const s=a[n];if(x(s.value))throw new r(e,o.NoFunctionInDictionary,t);if(!1===m(s.key))throw new r(e,o.KeyMustBeString,t);let c=s.key.toString();const u=c.toLowerCase();l.has(u)?c=l.get(u):l.set(u,c),s.value===b?i[c]=null:i[c]=s.value}const s=new n(i);return s.immutable=!1,s}async function Q(e,t){const n=await Y(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await Y(e,t.key),value:n}}async function X(e,t){const n={testResult:!0,lastAction:b};if(n.testResult=await Y(e,t.test),!1===n.testResult)return b;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await Y(e,t.body),n.lastAction!==S)&&!(n.lastAction instanceof F);)if(n.testResult=await Y(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return n.lastAction instanceof F?n.lastAction:b}async function $(e,t,n){const r=await Y(e,t.body);return n.lastAction=r,n.lastAction===S||n.lastAction instanceof F?(n.testResult=!1,n):null!==t.update?(await Y(e,t.update),n):n}async function ee(e,t,n){if(null!==t.test){const a=await Y(e,t.test);if(!0===e.abortSignal?.aborted)throw new r(e,o.Cancelled,t);if(n.testResult=a,!1===n.testResult)return n;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return $(e,t,n)}return $(e,t,n)}function te(e,t,n,r,o,a){try{ee(e,t,n).then((()=>{try{!0===n.testResult?++a>T?(a=0,setTimeout((()=>{te(e,t,n,r,o,a)}),0)):te(e,t,n,r,o,a):n.lastAction instanceof F?r(n.lastAction):r(b)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function ne(e,t){try{return null!==t.init?Y(e,t.init).then((()=>new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:b},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{te(e,t,{testResult:!0,lastAction:b},(e=>{n(e)}),(e=>{r(e)}),0)}))}catch(n){return Promise.reject(n)}}function re(e,t,n,r,o,a,i,l,s,c){try{if(r<=a)return void l(b);o.value="k"===i?n[a]:a,Y(e,t.body).then((u=>{try{u instanceof F?l(u):u===S?l(b):++c>T?(c=0,setTimeout((()=>{re(e,t,n,r,o,a+1,i,l,s,c)}),0)):re(e,t,n,r,o,a+1,i,l,s,c)}catch(f){s(f)}}),(e=>{s(e)}))}catch(u){s(u)}}function oe(e,t,n,r,o,a,i,l,s){try{if(n.length()<=o)return void i(b);r.value="k"===a?n.get(o):o,Y(e,t.body).then((c=>{c instanceof F?i(c):c===S?i(b):++s>T?(s=0,setTimeout((()=>{oe(e,t,n,r,o+1,a,i,l,s)}),0)):oe(e,t,n,r,o+1,a,i,l,s)}),(e=>{l(e)}))}catch(c){l(c)}}function ae(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(b);re(e,t,n,n.length,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ie(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(b);oe(e,t,n,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function le(e,t,n,r,o){try{ae(e,t,n.keys(),r,o,"k")}catch(a){r.reject(a)}}function se(e,t,n,r,o,a,l,s){try{e.next().then((c=>{try{if(null===c)a(b);else{const u=i.createFromGraphicLikeObject(c.geometry,c.attributes,r,t.timeZone);u._underlyingGraphic=c,o.value=u;Y(t,n.body).then((i=>{try{i===S?a(b):i instanceof F?a(i):++s>T?(s=0,setTimeout((()=>{se(e,t,n,r,o,a,l,s)}),0)):se(e,t,n,r,o,a,l,s)}catch(c){l(c)}}),(e=>{l(e)}))}}catch(u){l(u)}}),(e=>{l(e)}))}catch(c){l(c)}}async function ce(e,t){return new Promise(((a,i)=>{Y(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?Y(e,t.left):Promise.resolve(),s.then((()=>{try{let s="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(s=e.name)}else"Identifier"===t.left.type&&(s=t.left.name);if(!s)throw new r(e,o.InvalidIdentifier,t);s=s.toLowerCase();let c=null;if(null!=e.localScope&&void 0!==e.localScope[s]&&(c=e.localScope[s]),null===c&&void 0!==e.globalScope[s]&&(c=e.globalScope[s]),null===c)return void i(new r(e,o.InvalidIdentifier,t));d(l)||m(l)?ae(e,t,l,{reject:i,resolve:a},c):w(l)?ie(e,t,l,{reject:i,resolve:a},c):l instanceof n||h(l)?le(e,t,l,{reject:i,resolve:a},c):I(l)?se(l.iterator(e.abortSignal),e,t,l,c,(e=>{a(e)}),(e=>{i(e)}),0):ae(e,t,[],{reject:i,resolve:a},c)}catch(s){i(s)}}),i)}catch(s){i(s)}}),i)}))}async function ue(e,t){const a=t.argument;if("MemberExpression"===a.type){const i={t:null},l=await Y(e,a.object);let s=null;i.t=l,!0===a.computed?s=await Y(e,a.property):"Identifier"===a.property.type&&(s=a.property.name);const c=i.t;let u;if(d(c)){if(!g(s))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(s<0&&(s=c.length+s),s<0||s>=c.length)throw new r(e,o.OutOfBounds,t);u=C(c[s]),c[s]="++"===t.operator?u+1:u-1}else if(c instanceof n){if(!1===m(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});u=C(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}else if(c instanceof z){if(!1===m(s))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==c.hasGlobal(s))throw new r(e,o.ModuleExportNotFound,t);u=C(await c.global(s)),c.setGlobal(s,"++"===t.operator?u+1:u-1)}else{if(!h(c))throw w(c)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===m(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==c.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});u=C(c.field(s)),c.setField(s,"++"===t.operator?u+1:u-1)}return!1===t.prefix?u:"++"===t.operator?u+1:u-1}const i="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!i)throw new r(e,o.InvalidIdentifier,t);let l;if(null!=e.localScope&&void 0!==e.localScope[i])return l=C(e.localScope[i].value),e.localScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[i])return l=C(e.globalScope[i].value),e.globalScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new r(e,o.InvalidIdentifier,t)}function fe(e,t,n,a,i){switch(t){case"=":return e===b?null:e;case"/=":return C(n)/C(e);case"*=":return C(n)*C(e);case"-=":return C(n)-C(e);case"+=":return m(n)||m(e)?R(n)+R(e):C(n)+C(e);case"%=":return C(n)%C(e);default:throw new r(i,o.UnsupportedOperator,a)}}async function pe(e,t){const a=t.left;if("MemberExpression"===a.type){const i=await Y(e,a.object);let l=null;if(!0===a.computed)l=await Y(e,a.property);else{if("Identifier"!==a.property.type)throw new r(e,o.InvalidIdentifier,t);l=a.property.name}const s=await Y(e,t.right);if(d(i)){if(!g(l))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(l<0&&(l=i.length+l),l<0||l>i.length)throw new r(e,o.OutOfBounds,t);if(l===i.length){if("="!==t.operator)throw new r(e,o.OutOfBounds,t);i[l]=fe(s,t.operator,i[l],t,e)}else i[l]=fe(s,t.operator,i[l],t,e)}else if(i instanceof n){if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,fe(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,fe(s,t.operator,null,t,e))}}else if(i instanceof z){if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasGlobal(l))throw new r(e,o.ModuleExportNotFound,t);i.setGlobal(l,fe(s,t.operator,await i.global(l),t,e))}else{if(!h(i))throw w(i)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,fe(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,fe(s,t.operator,null,t,e))}}return b}const i=a.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[i]){const n=await Y(e,t.right);return e.localScope[i]={value:fe(n,t.operator,e.localScope[i].value,t,e),valueset:!0,node:t.right},b}if(void 0!==e.globalScope[i]){const n=await Y(e,t.right);return e.globalScope[i]={value:fe(n,t.operator,e.globalScope[i].value,t,e),valueset:!0,node:t.right},b}throw new r(e,o.InvalidIdentifier,t)}async function we(e,t){if("AssignmentExpression"===t.expression.type)return Y(e,t.expression);if("CallExpression"===t.expression.type){const n=await Y(e,t.expression);return n===b?b:new A(n)}const n=await Y(e,t.expression);return n===b?b:new A(n)}async function de(e,t){const n=await Y(e,t.test);if(!0===n)return Y(e,t.consequent);if(!1===n)return null!==t.alternate?Y(e,t.alternate):b;throw new r(e,o.BooleanConditionRequired,t)}async function he(e,t){return me(e,t,0)}async function me(e,t,n){if(n>=t.body.length)return b;const r=await Y(e,t.body[n]);return r instanceof F||r===S||r===v||n===t.body.length-1?r:me(e,t,n+1)}async function ge(e,t){if(null===t.argument)return new F(b);const n=await Y(e,t.argument);return new F(n)}async function ye(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new _(t,e)},b}async function ve(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new z(r),await o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},b}async function be(e,t){if(await Y(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return b}async function Se(e,t,n){return n>=t.declarations.length?b:(await Y(e,t.declarations[n]),n===t.declarations.length-1||await Se(e,t,n+1),b)}async function xe(e,t){let n=null;if(n=null===t.init?null:await Y(e,t.init),null!==e.localScope){if(n===b&&(n=null),"Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return null!=e.localScope&&(e.localScope[a]={value:n,valueset:!0,node:t.init}),b}if("Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return n===b&&(n=null),e.globalScope[a]={value:n,valueset:!0,node:t.init},b}async function Fe(e,t){const a=await Y(e,t.object);if(null===a)throw new r(e,o.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(a instanceof n||h(a))return a.field(t.property.name);if(a instanceof Z)return P(a,t.property.name,e,t);if(a instanceof z){if(!a.hasGlobal(t.property.name))throw new r(e,o.InvalidIdentifier,t);return a.global(t.property.name)}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}let i=await Y(e,t.property);if(a instanceof n||h(a)){if(m(i))return a.field(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof z){if(m(i))return a.global(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof Z){if(m(i))return P(a,i,e,t);throw new r(e,o.InvalidMemberAccessKey,t)}if(d(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length+i),i>=a.length||i<0)throw new r(e,o.OutOfBounds,t);return a[i]}throw new r(e,o.InvalidMemberAccessKey,t)}if(w(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length()+i),i>=a.length()||i<0)throw new r(e,o.OutOfBounds,t);return a.get(i)}throw new r(e,o.InvalidMemberAccessKey,t)}if(m(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length+i),i>=a.length||i<0)throw new r(e,o.OutOfBounds,t);return a[i]}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}async function Ie(e,t){const n=await Y(e,t.argument);if(p(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*C(n);if("+"===t.operator)return 1*C(n);if("~"===t.operator)return~C(n);throw new r(e,o.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*C(n);if("+"===t.operator)return 1*C(n);if("~"===t.operator)return~C(n);throw new r(e,o.UnsupportedUnaryOperator,t)}async function Ce(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await Y(e,t.elements[r]));for(let a=0;a<n.length;a++){if(x(n[a]))throw new r(e,o.NoFunctionInArray,t);n[a]===b&&(n[a]=null)}return n}async function Ae(e,t){const n=[];n[0]=await Y(e,t.left),n[1]=await Y(e,t.right);const a=n[0],i=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(C(a),C(i),t.operator);case"==":return y(a,i);case"!=":return!y(a,i);case"<":case">":case"<=":case">=":return M(a,i,t.operator);case"+":return m(a)||m(i)?R(a)+R(i):C(a)+C(i);case"-":return C(a)-C(i);case"*":return C(a)*C(i);case"/":return C(a)/C(i);case"%":return C(a)%C(i);default:throw new r(e,o.UnsupportedOperator,t)}}async function Re(e,t){const n=await Y(e,t.left);let a=null;if(!p(n))throw new r(e,o.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":if(!0===n)return n;if(a=await Y(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(a=await Y(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);default:throw new r(e,o.LogicExpressionOrAnd,t)}}async function Me(e,t){const n=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n]){const t=e.localScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}if(void 0!==e.globalScope[n]){const t=e.globalScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=Y(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}throw new r(e,o.InvalidIdentifier,t)}async function je(e,t){if("MemberExpression"===t.callee.type){const n=await Y(e,t.callee.object);if(!(n instanceof z))throw new r(e,o.FunctionNotFound,t);const a=!1===t.callee.computed?t.callee.property.name:await Y(e,t.callee.property);if(!n.hasGlobal(a))throw new r(e,o.FunctionNotFound,t);const i=await n.global(a);if(!x(i))throw new r(e,o.CallNonFunction,t);return i.call(e,t)}if("Identifier"!==t.callee.type)throw new r(e,o.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(x(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(x(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}throw new r(e,o.FunctionNotFound,t)}async function ke(e,t){return t.value?t.value.cooked:""}function Le(e,t,n){if(x(e))throw new r(t,o.NoFunctionInTemplateLiteral,n);return e}async function Ee(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await Y(e,t.expressions[a]);n[a]=R(r)}let r="",o=0;for(const a of t.quasis)if(r+=a.value?a.value.cooked:"",!1===a.tail){r+=n[o]?Le(n[o],e,t):"",o++}return r}const Ne={};async function Oe(e,t,n,r){const o=await Y(e,t.arguments[n]);if(y(o,r))return Y(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?Y(e,t.arguments[n]):2===a?null:3===a?Y(e,t.arguments[n+2]):Oe(e,t,n+2,r)}async function Be(e,t,n,a){if(!0===a)return Y(e,t.arguments[n+1]);if(3===t.arguments.length-n)return Y(e,t.arguments[n+2]);const i=await Y(e,t.arguments[n+2]);if(!1===p(i))throw new r(e,o.ModuleExportNotFound,t.arguments[n+2]);return Be(e,t,n+2,i)}async function Pe(e,t,n,a){const i=e.body;if(n.length!==e.params.length)throw new r(t,o.WrongNumberOfParameters,null);for(let r=0;r<n.length;r++){const o=e.params[r];"Identifier"===o.type&&null!=t.localScope&&(t.localScope[o.name.toLowerCase()]={d:null,value:n[r],valueset:!0,node:null})}const l=await Y(t,i);if(l instanceof F)return l.value;if(l===S)throw new r(t,o.UnexpectedToken,a);if(l===v)throw new r(t,o.UnexpectedToken,a);return l instanceof A?l.value:l}N(Ne,V),G(Ne,V),K(Ne,V),B(Ne,V),D(Ne,V),O({functions:Ne,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:V,standardFunctionAsync:H}),Ne.iif=async function(e,t){f(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await Y(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t);return Y(e,n?t.arguments[1]:t.arguments[2])},Ne.defaultvalue=async function(e,t){f(null===t.arguments?[]:t.arguments,2,3,e,t);const a=await Y(e,t.arguments[0]);if(3===t.arguments.length){const i=await Y(e,t.arguments[1]);let l=[];if(w(i))l=i.toArray();else{if(!d(i))throw new r(e,o.InvalidParameter,t);l=i}let s=a;if(null===s)return Y(e,t.arguments[2]);for(const r of l)if(h(s)){if(!1===m(r))return Y(e,t.arguments[2]);if(!s.hasField(r))return Y(e,t.arguments[2]);s=s.field(r)}else if(s instanceof n){if(!1===m(r))return Y(e,t.arguments[2]);if(!s.hasField(r))return Y(e,t.arguments[2]);s=s.field(r)}else if(s instanceof Z){if(!1===m(r))return Y(e,t.arguments[2]);if(s=P(s,r,null,null,2),null===s)return Y(e,t.arguments[2]);if("notfound"===s?.keystate)return Y(e,t.arguments[2])}else if(d(s)){if(!1===g(r))return Y(e,t.arguments[2]);if(s=s[r],null==s)return Y(e,t.arguments[2])}else{if(!w(s))return Y(e,t.arguments[2]);if(!1===g(r))return Y(e,t.arguments[2]);if(s=s.get(r),null==s)return Y(e,t.arguments[2])}return s}return null==a||""===a?Y(e,t.arguments[1]):a},Ne.decode=async function(e,t){if(t.arguments.length<2)throw new r(e,o.WrongNumberOfParameters,t);if(2===t.arguments.length)return Y(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new r(e,o.WrongNumberOfParameters,t);return Oe(e,t,1,await Y(e,t.arguments[0]))},Ne.when=async function(e,t){if(t.arguments.length<3)throw new r(e,o.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new r(e,o.WrongNumberOfParameters,t);const n=await Y(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t.arguments[0]);return Be(e,t,0,n)};const Ke={fixSpatialReference:k,parseArguments:W,standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(const We in Ne)Ne[We]={value:new l(Ne[We]),valueset:!0,node:null};const De=function(){};function Ge(e,t,r){const o=new De;null==e&&(e={}),null==t&&(t={});const a=new n({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const n in t)o[n]={value:new l(t[n]),native:!0,valueset:!0,node:null};for(const n in e)e[n]&&"esri.Graphic"===e[n].declaredClass?o[n]={value:i.createFromGraphic(e[n],r),valueset:!0,node:null}:o[n]={value:e[n],valueset:!0,node:null};return o}function Ze(e){console.log(e)}De.prototype=Ne,De.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},De.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ue=Ke;function qe(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:V,standardFunctionAsync:H,evaluateIdentifier:Me};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ne[n]={value:new l(t.functions[n]),valueset:!0,node:null},De.prototype[n]=Ne[n];for(let n=0;n<t.signatures.length;n++)L(t.signatures[n],"async")}async function Te(e,n){let a=n.spatialReference;null==a&&(a=new U({wkid:102100}));let i=null;e.usesModules&&(i=new t(new Map,e.loadedModules));const l=Ge(n.vars,n.customfunctions,n.timeZone),s={spatialReference:a,services:n.services,exports:{},libraryResolver:i,abortSignal:void 0===n.abortSignal||null===n.abortSignal?{aborted:!1}:n.abortSignal,globalScope:l,console:n.console??Ze,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let c=await Y(s,e);if(c instanceof F&&(c=c.value),c instanceof A&&(c=c.value),c===b&&(c=null),c===S)throw new r(s,o.IllegalResult,null);if(c===v)throw new r(s,o.IllegalResult,null);if(x(c))throw new r(s,o.IllegalResult,null);return c}qe([E]);export{Te as executeScript,qe as extend,Ue as functionHelper};
|
|
5
|
+
import{ArcadeModule as e}from"./ArcadeModule.js";import{ArcadeModuleLoader as t}from"./ArcadeModuleLoader.js";import n from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as o,ensureArcadeExecutionError as a}from"./executionError.js";import i from"./Feature.js";import{NativeFunction as l,ArcadeFunction as s,ScopeMarshalledFunction as u,wrapModuleScopedResponse as c}from"./FunctionWrapper.js";import{H as f,a as p,q as w,o as d,r as h,c as m,b as g,F as y,D as v,B as b,C as S,i as x,z as F,u as I,g as C,A,j as R,E as M,G as j,x as k}from"../chunks/languageUtils.js";import{addFunctionDeclaration as L}from"./treeAnalysis.js";import{A as E}from"../chunks/array.js";import{registerFunctions as N}from"./functions/date.js";import{registerFunctions as O}from"./functions/geomasync.js";import{registerFunctions as B,geometryMember as P}from"./functions/geometry.js";import{registerFunctions as K}from"./functions/maths.js";import{registerFunctions as D}from"./functions/stats.js";import{registerFunctions as G}from"./functions/string.js";import Z from"../geometry/Geometry.js";import U from"../geometry/SpatialReference.js";const q=100;async function T(e,t){const n=[];for(let r=0;r<t.arguments.length;r++)n.push(await H(e,t.arguments[r]));return n}async function W(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await T(e,t))}class V extends s{constructor(e,t){super(),this.definition=null,this.context=null,this.definition=e,this.context=t}createFunction(e){return(...t)=>{const n={spatialReference:this.context.spatialReference,console:this.context.console,lrucache:this.context.lrucache,timeZone:this.context.timeZone??null,exports:this.context.exports,libraryResolver:this.context.libraryResolver,interceptor:this.context.interceptor,localScope:{},depthCounter:{depth:e.depthCounter+1},globalScope:this.context.globalScope};if(n.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,null);return Be(this.definition,n,t,null)}}call(e,t){return z(e,t,((n,a,i)=>{const l={spatialReference:e.spatialReference,services:e.services,console:e.console,libraryResolver:e.libraryResolver,exports:e.exports,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{},abortSignal:e.abortSignal,globalScope:e.globalScope,depthCounter:{depth:e.depthCounter.depth+1}};if(l.depthCounter.depth>64)throw new r(e,o.MaximumCallDepth,t);return Be(this.definition,l,i,t)}))}marshalledCall(e,t,n,r){return r(e,t,(async(o,a,i)=>{const l={spatialReference:e.spatialReference,globalScope:n.globalScope,depthCounter:{depth:e.depthCounter.depth+1},libraryResolver:e.libraryResolver,exports:e.exports,console:e.console,abortSignal:e.abortSignal,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:{}};return i=i.map((t=>!x(t)||t instanceof u?t:c(t,e,r))),c(await Be(this.definition,l,i,t),n,r)}))}}class _ extends e{constructor(e){super(e)}async global(e){const t=this.executingContext.globalScope[e.toLowerCase()];if(t.valueset||(t.value=await H(this.executingContext,t.node),t.valueset=!0),x(t.value)&&!(t.value instanceof u)){const e=new u;e.fn=t.value,e.parameterEvaluator=z,e.context=this.executingContext,t.value=e}return t.value}setGlobal(e,t){if(x(t))throw new r(null,o.AssignModuleFunction,null);this.executingContext.globalScope[e.toLowerCase()]={value:t,valueset:!0,node:null}}hasGlobal(e){return void 0===this.executingContext.exports[e]&&(e=e.toLowerCase()),void 0!==this.executingContext.exports[e]}async loadModule(e){let n=e.spatialReference;null==n&&(n=new U({wkid:102100})),this.moduleScope=De({},e.customfunctions,e.timeZone),this.executingContext={spatialReference:n,services:e.services,libraryResolver:new t(e.libraryResolver._moduleSingletons,this.source.syntax.loadedModules),exports:{},abortSignal:void 0===e.abortSignal||null===e.abortSignal?{aborted:!1}:e.abortSignal,globalScope:this.moduleScope,console:e.console??Ge,lrucache:e.lrucache,timeZone:e.timeZone??null,interceptor:e.interceptor,localScope:null,depthCounter:{depth:1}},await H(this.executingContext,this.source.syntax)}}async function z(e,t,n){if(!0===t.preparsed)return n(e,null,t.arguments);return n(e,t,await T(e,t))}async function H(e,t,n){if(t.breakpoint&&!0!==n){const n=t.breakpoint();return await n,H(e,t,!0)}try{switch(t?.type){case"VariableDeclarator":return await Se(e,t);case"ImportDeclaration":return await ye(e,t);case"ExportNamedDeclaration":return await ve(e,t);case"VariableDeclaration":return await be(e,t,0);case"BlockStatement":case"Program":return await de(e,t);case"FunctionDeclaration":return await ge(e,t);case"ReturnStatement":return await me(e,t);case"IfStatement":return await we(e,t);case"ExpressionStatement":return await pe(e,t);case"UpdateExpression":return await ue(e,t);case"AssignmentExpression":return await fe(e,t);case"ForStatement":return await te(e,t);case"WhileStatement":return await Q(e,t);case"ForInStatement":return await se(e,t);case"BreakStatement":return S;case"EmptyStatement":return b;case"ContinueStatement":return v;case"TemplateElement":return await je(e,t);case"TemplateLiteral":return await Le(e,t);case"Identifier":return await Re(e,t);case"MemberExpression":return await xe(e,t);case"Literal":return t.value;case"CallExpression":return await Me(e,t);case"UnaryExpression":return await Fe(e,t);case"BinaryExpression":return await Ce(e,t);case"LogicalExpression":return await Ae(e,t);case"ArrayExpression":return await Ie(e,t);case"ObjectExpression":return await Y(e,t);case"Property":return await J(e,t);default:throw new r(e,o.Unrecognized,t)}}catch(i){throw a(e,t,i)}}async function Y(e,t){const a=[];for(let n=0;n<t.properties.length;n++)a[n]=await H(e,t.properties[n]);const i={},l=new Map;for(let n=0;n<a.length;n++){const s=a[n];if(x(s.value))throw new r(e,o.NoFunctionInDictionary,t);if(!1===m(s.key))throw new r(e,o.KeyMustBeString,t);let u=s.key.toString();const c=u.toLowerCase();l.has(c)?u=l.get(c):l.set(c,u),s.value===b?i[u]=null:i[u]=s.value}const s=new n(i);return s.immutable=!1,s}async function J(e,t){const n=await H(e,t.value);if("Identifier"===t.key.type)return{key:t.key.name,value:n};return{key:await H(e,t.key),value:n}}async function Q(e,t){const n={testResult:!0,lastAction:b};if(n.testResult=await H(e,t.test),!1===n.testResult)return b;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);for(;!0===n.testResult&&(n.lastAction=await H(e,t.body),n.lastAction!==S)&&!(n.lastAction instanceof F);)if(n.testResult=await H(e,t.test),!0!==n.testResult&&!1!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return n.lastAction instanceof F?n.lastAction:b}async function X(e,t,n){const r=await H(e,t.body);return n.lastAction=r,n.lastAction===S||n.lastAction instanceof F?(n.testResult=!1,n):null!==t.update?(await H(e,t.update),n):n}async function $(e,t,n){if(null!==t.test){const a=await H(e,t.test);if(!0===e.abortSignal?.aborted)throw new r(e,o.Cancelled,t);if(n.testResult=a,!1===n.testResult)return n;if(!0!==n.testResult)throw new r(e,o.BooleanConditionRequired,t);return X(e,t,n)}return X(e,t,n)}function ee(e,t,n,r,o,a){try{$(e,t,n).then((()=>{try{!0===n.testResult?++a>q?(a=0,setTimeout((()=>{ee(e,t,n,r,o,a)}),0)):ee(e,t,n,r,o,a):n.lastAction instanceof F?r(n.lastAction):r(b)}catch(i){o(i)}}),(e=>{o(e)}))}catch(i){o(i)}}function te(e,t){try{return null!==t.init?H(e,t.init).then((()=>new Promise(((n,r)=>{ee(e,t,{testResult:!0,lastAction:b},(e=>{n(e)}),(e=>{r(e)}),0)})))):new Promise(((n,r)=>{ee(e,t,{testResult:!0,lastAction:b},(e=>{n(e)}),(e=>{r(e)}),0)}))}catch(n){return Promise.reject(n)}}function ne(e,t,n,r,o,a,i,l,s,u){try{if(r<=a)return void l(b);o.value="k"===i?n[a]:a,H(e,t.body).then((c=>{try{c instanceof F?l(c):c===S?l(b):++u>q?(u=0,setTimeout((()=>{ne(e,t,n,r,o,a+1,i,l,s,u)}),0)):ne(e,t,n,r,o,a+1,i,l,s,u)}catch(f){s(f)}}),(e=>{s(e)}))}catch(c){s(c)}}function re(e,t,n,r,o,a,i,l,s){try{if(n.length()<=o)return void i(b);r.value="k"===a?n.get(o):o,H(e,t.body).then((u=>{u instanceof F?i(u):u===S?i(b):++s>q?(s=0,setTimeout((()=>{re(e,t,n,r,o+1,a,i,l,s)}),0)):re(e,t,n,r,o+1,a,i,l,s)}),(e=>{l(e)}))}catch(u){l(u)}}function oe(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(b);ne(e,t,n,n.length,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ae(e,t,n,r,o,a){try{if(void 0===a&&(a="i"),0===n.length)return void r.resolve(b);re(e,t,n,o,0,a,(e=>{r.resolve(e)}),(e=>{r.reject(e)}),0)}catch(i){r.reject(i)}}function ie(e,t,n,r,o){try{oe(e,t,n.keys(),r,o,"k")}catch(a){r.reject(a)}}function le(e,t,n,r,o,a,l,s){try{e.next().then((u=>{try{if(null===u)a(b);else{const c=i.createFromGraphicLikeObject(u.geometry,u.attributes,r,t.timeZone);c._underlyingGraphic=u,o.value=c;H(t,n.body).then((i=>{try{i===S?a(b):i instanceof F?a(i):++s>q?(s=0,setTimeout((()=>{le(e,t,n,r,o,a,l,s)}),0)):le(e,t,n,r,o,a,l,s)}catch(u){l(u)}}),(e=>{l(e)}))}}catch(c){l(c)}}),(e=>{l(e)}))}catch(u){l(u)}}async function se(e,t){return new Promise(((a,i)=>{H(e,t.right).then((l=>{try{let s=null;s="VariableDeclaration"===t.left.type?H(e,t.left):Promise.resolve(),s.then((()=>{try{let s="";if("VariableDeclaration"===t.left.type){const e=t.left.declarations[0].id;"Identifier"===e.type&&(s=e.name)}else"Identifier"===t.left.type&&(s=t.left.name);if(!s)throw new r(e,o.InvalidIdentifier,t);s=s.toLowerCase();let u=null;if(null!=e.localScope&&void 0!==e.localScope[s]&&(u=e.localScope[s]),null===u&&void 0!==e.globalScope[s]&&(u=e.globalScope[s]),null===u)return void i(new r(e,o.InvalidIdentifier,t));d(l)||m(l)?oe(e,t,l,{reject:i,resolve:a},u):w(l)?ae(e,t,l,{reject:i,resolve:a},u):l instanceof n||h(l)?ie(e,t,l,{reject:i,resolve:a},u):I(l)?le(l.iterator(e.abortSignal),e,t,l,u,(e=>{a(e)}),(e=>{i(e)}),0):oe(e,t,[],{reject:i,resolve:a},u)}catch(s){i(s)}}),i)}catch(s){i(s)}}),i)}))}async function ue(e,t){const a=t.argument;if("MemberExpression"===a.type){const i={t:null},l=await H(e,a.object);let s=null;i.t=l,!0===a.computed?s=await H(e,a.property):"Identifier"===a.property.type&&(s=a.property.name);const u=i.t;let c;if(d(u)){if(!g(s))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(s<0&&(s=u.length+s),s<0||s>=u.length)throw new r(e,o.OutOfBounds,t);c=C(u[s]),u[s]="++"===t.operator?c+1:c-1}else if(u instanceof n){if(!1===m(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==u.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});c=C(u.field(s)),u.setField(s,"++"===t.operator?c+1:c-1)}else if(u instanceof _){if(!1===m(s))throw new r(e,o.ModuleAccessorMustBeString,t);if(!0!==u.hasGlobal(s))throw new r(e,o.ModuleExportNotFound,t);c=C(await u.global(s)),u.setGlobal(s,"++"===t.operator?c+1:c-1)}else{if(!h(u))throw w(u)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===m(s))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==u.hasField(s))throw new r(e,o.FieldNotFound,t,{key:s});c=C(u.field(s)),u.setField(s,"++"===t.operator?c+1:c-1)}return!1===t.prefix?c:"++"===t.operator?c+1:c-1}const i="Identifier"===t.argument.type?t.argument.name.toLowerCase():"";if(!i)throw new r(e,o.InvalidIdentifier,t);let l;if(null!=e.localScope&&void 0!==e.localScope[i])return l=C(e.localScope[i].value),e.localScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;if(void 0!==e.globalScope[i])return l=C(e.globalScope[i].value),e.globalScope[i]={value:"++"===t.operator?l+1:l-1,valueset:!0,node:t},!1===t.prefix?l:"++"===t.operator?l+1:l-1;throw new r(e,o.InvalidIdentifier,t)}function ce(e,t,n,a,i){switch(t){case"=":return e===b?null:e;case"/=":return C(n)/C(e);case"*=":return C(n)*C(e);case"-=":return C(n)-C(e);case"+=":return m(n)||m(e)?R(n)+R(e):C(n)+C(e);case"%=":return C(n)%C(e);default:throw new r(i,o.UnsupportedOperator,a)}}async function fe(e,t){const a=t.left;if("MemberExpression"===a.type){const i=await H(e,a.object);let l=null;if(!0===a.computed)l=await H(e,a.property);else{if("Identifier"!==a.property.type)throw new r(e,o.InvalidIdentifier,t);l=a.property.name}const s=await H(e,t.right);if(d(i)){if(!g(l))throw new r(e,o.ArrayAccessorMustBeNumber,t);if(l<0&&(l=i.length+l),l<0||l>i.length)throw new r(e,o.OutOfBounds,t);if(l===i.length){if("="!==t.operator)throw new r(e,o.OutOfBounds,t);i[l]=ce(s,t.operator,i[l],t,e)}else i[l]=ce(s,t.operator,i[l],t,e)}else if(i instanceof n){if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,ce(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,ce(s,t.operator,null,t,e))}}else if(i instanceof _){if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0!==i.hasGlobal(l))throw new r(e,o.ModuleExportNotFound,t);i.setGlobal(l,ce(s,t.operator,await i.global(l),t,e))}else{if(!h(i))throw w(i)?new r(e,o.Immutable,t):new r(e,o.InvalidParameter,t);if(!1===m(l))throw new r(e,o.KeyAccessorMustBeString,t);if(!0===i.hasField(l))i.setField(l,ce(s,t.operator,i.field(l),t,e));else{if("="!==t.operator)throw new r(e,o.FieldNotFound,t,{key:l});i.setField(l,ce(s,t.operator,null,t,e))}}return b}const i=a.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[i]){const n=await H(e,t.right);return e.localScope[i]={value:ce(n,t.operator,e.localScope[i].value,t,e),valueset:!0,node:t.right},b}if(void 0!==e.globalScope[i]){const n=await H(e,t.right);return e.globalScope[i]={value:ce(n,t.operator,e.globalScope[i].value,t,e),valueset:!0,node:t.right},b}throw new r(e,o.InvalidIdentifier,t)}async function pe(e,t){if("AssignmentExpression"===t.expression.type)return H(e,t.expression);if("CallExpression"===t.expression.type){const n=await H(e,t.expression);return n===b?b:new A(n)}const n=await H(e,t.expression);return n===b?b:new A(n)}async function we(e,t){const n=await H(e,t.test);if(!0===n)return H(e,t.consequent);if(!1===n)return null!==t.alternate?H(e,t.alternate):b;throw new r(e,o.BooleanConditionRequired,t)}async function de(e,t){return he(e,t,0)}async function he(e,t,n){if(n>=t.body.length)return b;const r=await H(e,t.body[n]);return r instanceof F||r===S||r===v||n===t.body.length-1?r:he(e,t,n+1)}async function me(e,t){if(null===t.argument)return new F(b);const n=await H(e,t.argument);return new F(n)}async function ge(e,t){const n=t.id.name.toLowerCase();return e.globalScope[n]={valueset:!0,node:null,value:new V(t,e)},b}async function ye(e,t){const n=t.specifiers[0].local.name.toLowerCase(),r=e.libraryResolver.loadLibrary(n);let o=null;return e.libraryResolver._moduleSingletons?.has(r.uri)?o=e.libraryResolver._moduleSingletons.get(r.uri):(o=new _(r),await o.loadModule(e),e.libraryResolver._moduleSingletons?.set(r.uri,o)),e.globalScope[n]={value:o,valueset:!0,node:t},b}async function ve(e,t){if(await H(e,t.declaration),"FunctionDeclaration"===t.declaration.type)e.exports[t.declaration.id.name.toLowerCase()]="function";else if("VariableDeclaration"===t.declaration.type)for(const n of t.declaration.declarations)e.exports[n.id.name.toLowerCase()]="variable";return b}async function be(e,t,n){return n>=t.declarations.length?b:(await H(e,t.declarations[n]),n===t.declarations.length-1||await be(e,t,n+1),b)}async function Se(e,t){let n=null;if(n=null===t.init?null:await H(e,t.init),null!==e.localScope){if(n===b&&(n=null),"Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return null!=e.localScope&&(e.localScope[a]={value:n,valueset:!0,node:t.init}),b}if("Identifier"!==t.id.type)throw new r(e,o.InvalidIdentifier,t);const a=t.id.name.toLowerCase();return n===b&&(n=null),e.globalScope[a]={value:n,valueset:!0,node:t.init},b}async function xe(e,t){const a=await H(e,t.object);if(null===a)throw new r(e,o.MemberOfNull,t);if(!1===t.computed){if("Identifier"===t.property.type){if(a instanceof n||h(a))return a.field(t.property.name);if(a instanceof Z)return P(a,t.property.name,e,t);if(a instanceof _){if(!a.hasGlobal(t.property.name))throw new r(e,o.InvalidIdentifier,t);return a.global(t.property.name)}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}let i=await H(e,t.property);if(a instanceof n||h(a)){if(m(i))return a.field(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof _){if(m(i))return a.global(i);throw new r(e,o.InvalidMemberAccessKey,t)}if(a instanceof Z){if(m(i))return P(a,i,e,t);throw new r(e,o.InvalidMemberAccessKey,t)}if(d(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length+i),i>=a.length||i<0)throw new r(e,o.OutOfBounds,t);return a[i]}throw new r(e,o.InvalidMemberAccessKey,t)}if(w(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length()+i),i>=a.length()||i<0)throw new r(e,o.OutOfBounds,t);return a.get(i)}throw new r(e,o.InvalidMemberAccessKey,t)}if(m(a)){if(g(i)&&isFinite(i)&&Math.floor(i)===i){if(i<0&&(i=a.length+i),i>=a.length||i<0)throw new r(e,o.OutOfBounds,t);return a[i]}throw new r(e,o.InvalidMemberAccessKey,t)}throw new r(e,o.InvalidMemberAccessKey,t)}async function Fe(e,t){const n=await H(e,t.argument);if(p(n)){if("!"===t.operator)return!n;if("-"===t.operator)return-1*C(n);if("+"===t.operator)return 1*C(n);if("~"===t.operator)return~C(n);throw new r(e,o.UnsupportedUnaryOperator,t)}if("-"===t.operator)return-1*C(n);if("+"===t.operator)return 1*C(n);if("~"===t.operator)return~C(n);throw new r(e,o.UnsupportedUnaryOperator,t)}async function Ie(e,t){const n=[];for(let r=0;r<t.elements.length;r++)n.push(await H(e,t.elements[r]));for(let a=0;a<n.length;a++){if(x(n[a]))throw new r(e,o.NoFunctionInArray,t);n[a]===b&&(n[a]=null)}return n}async function Ce(e,t){const n=[];n[0]=await H(e,t.left),n[1]=await H(e,t.right);const a=n[0],i=n[1];switch(t.operator){case"|":case"<<":case">>":case">>>":case"^":case"&":return j(C(a),C(i),t.operator);case"==":return y(a,i);case"!=":return!y(a,i);case"<":case">":case"<=":case">=":return M(a,i,t.operator);case"+":return m(a)||m(i)?R(a)+R(i):C(a)+C(i);case"-":return C(a)-C(i);case"*":return C(a)*C(i);case"/":return C(a)/C(i);case"%":return C(a)%C(i);default:throw new r(e,o.UnsupportedOperator,t)}}async function Ae(e,t){const n=await H(e,t.left);let a=null;if(!p(n))throw new r(e,o.LogicalExpressionOnlyBoolean,t);switch(t.operator){case"||":if(!0===n)return n;if(a=await H(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);case"&&":if(!1===n)return n;if(a=await H(e,t.right),p(a))return a;throw new r(e,o.LogicExpressionOrAnd,t);default:throw new r(e,o.LogicExpressionOrAnd,t)}}async function Re(e,t){const n=t.name.toLowerCase();if(null!=e.localScope&&void 0!==e.localScope[n]){const t=e.localScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=H(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}if(void 0!==e.globalScope[n]){const t=e.globalScope[n];if(!0===t.valueset)return t.value;if(null!==t.d)return t.d;t.d=H(e,t.node);const r=await t.d;return t.value=r,t.valueset=!0,r}throw new r(e,o.InvalidIdentifier,t)}async function Me(e,t){if("MemberExpression"===t.callee.type){const n=await H(e,t.callee.object);if(!(n instanceof _))throw new r(e,o.FunctionNotFound,t);const a=!1===t.callee.computed?t.callee.property.name:await H(e,t.callee.property);if(!n.hasGlobal(a))throw new r(e,o.FunctionNotFound,t);const i=await n.global(a);if(!x(i))throw new r(e,o.CallNonFunction,t);return i.call(e,t)}if("Identifier"!==t.callee.type)throw new r(e,o.FunctionNotFound,t);if(null!=e.localScope&&void 0!==e.localScope[t.callee.name.toLowerCase()]){const n=e.localScope[t.callee.name.toLowerCase()];if(x(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}if(void 0!==e.globalScope[t.callee.name.toLowerCase()]){const n=e.globalScope[t.callee.name.toLowerCase()];if(x(n.value))return n.value.call(e,t);throw new r(e,o.CallNonFunction,t)}throw new r(e,o.FunctionNotFound,t)}async function je(e,t){return t.value?t.value.cooked:""}function ke(e,t,n){if(x(e))throw new r(t,o.NoFunctionInTemplateLiteral,n);return e}async function Le(e,t){const n=[];for(let a=0;a<t.expressions.length;a++){const r=await H(e,t.expressions[a]);n[a]=R(r)}let r="",o=0;for(const a of t.quasis)if(r+=a.value?a.value.cooked:"",!1===a.tail){r+=n[o]?ke(n[o],e,t):"",o++}return r}const Ee={};async function Ne(e,t,n,r){const o=await H(e,t.arguments[n]);if(y(o,r))return H(e,t.arguments[n+1]);const a=t.arguments.length-n;return 1===a?H(e,t.arguments[n]):2===a?null:3===a?H(e,t.arguments[n+2]):Ne(e,t,n+2,r)}async function Oe(e,t,n,a){if(!0===a)return H(e,t.arguments[n+1]);if(3===t.arguments.length-n)return H(e,t.arguments[n+2]);const i=await H(e,t.arguments[n+2]);if(!1===p(i))throw new r(e,o.ModuleExportNotFound,t.arguments[n+2]);return Oe(e,t,n+2,i)}async function Be(e,t,n,a){const i=e.body;if(n.length!==e.params.length)throw new r(t,o.WrongNumberOfParameters,null);for(let r=0;r<n.length;r++){const o=e.params[r];"Identifier"===o.type&&null!=t.localScope&&(t.localScope[o.name.toLowerCase()]={d:null,value:n[r],valueset:!0,node:null})}const l=await H(t,i);if(l instanceof F)return l.value;if(l===S)throw new r(t,o.UnexpectedToken,a);if(l===v)throw new r(t,o.UnexpectedToken,a);return l instanceof A?l.value:l}N(Ee,W),G(Ee,W),K(Ee,W),B(Ee,W),D(Ee,W),O({functions:Ee,compiled:!1,signatures:null,evaluateIdentifier:null,mode:"async",standardFunction:W,standardFunctionAsync:z}),Ee.iif=async function(e,t){f(null===t.arguments?[]:t.arguments,3,3,e,t);const n=await H(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t);return H(e,n?t.arguments[1]:t.arguments[2])},Ee.defaultvalue=async function(e,t){f(null===t.arguments?[]:t.arguments,2,3,e,t);const a=await H(e,t.arguments[0]);if(3===t.arguments.length){const i=await H(e,t.arguments[1]);let l=[];if(w(i))l=i.toArray();else{if(!d(i))throw new r(e,o.InvalidParameter,t);l=i}let s=a;if(null===s)return H(e,t.arguments[2]);for(const r of l)if(h(s)){if(!1===m(r))return H(e,t.arguments[2]);if(!s.hasField(r))return H(e,t.arguments[2]);s=s.field(r)}else if(s instanceof n){if(!1===m(r))return H(e,t.arguments[2]);if(!s.hasField(r))return H(e,t.arguments[2]);s=s.field(r)}else if(s instanceof Z){if(!1===m(r))return H(e,t.arguments[2]);if(s=P(s,r,null,null,2),null===s)return H(e,t.arguments[2]);if("notfound"===s?.keystate)return H(e,t.arguments[2])}else if(d(s)){if(!1===g(r))return H(e,t.arguments[2]);if(s=s[r],null==s)return H(e,t.arguments[2])}else{if(!w(s))return H(e,t.arguments[2]);if(!1===g(r))return H(e,t.arguments[2]);if(s=s.get(r),null==s)return H(e,t.arguments[2])}return s}return null==a||""===a?H(e,t.arguments[1]):a},Ee.decode=async function(e,t){if(t.arguments.length<2)throw new r(e,o.WrongNumberOfParameters,t);if(2===t.arguments.length)return H(e,t.arguments[1]);if((t.arguments.length-1)%2==0)throw new r(e,o.WrongNumberOfParameters,t);return Ne(e,t,1,await H(e,t.arguments[0]))},Ee.when=async function(e,t){if(t.arguments.length<3)throw new r(e,o.WrongNumberOfParameters,t);if(t.arguments.length%2==0)throw new r(e,o.WrongNumberOfParameters,t);const n=await H(e,t.arguments[0]);if(!1===p(n))throw new r(e,o.BooleanConditionRequired,t.arguments[0]);return Oe(e,t,0,n)};const Pe={fixSpatialReference:k,parseArguments:T,standardFunction:W,standardFunctionAsync:z,evaluateIdentifier:Re};for(const Te in Ee)Ee[Te]={value:new l(Ee[Te]),valueset:!0,node:null};const Ke=function(){};function De(e,t,r){const o=new Ke;null==e&&(e={}),null==t&&(t={});const a=new n({newline:"\n",tab:"\t",singlequote:"'",doublequote:'"',forwardslash:"/",backwardslash:"\\"});a.immutable=!1,o.textformatting={value:a,valueset:!0,node:null};for(const n in t)o[n]={value:new l(t[n]),native:!0,valueset:!0,node:null};for(const n in e)e[n]&&"esri.Graphic"===e[n].declaredClass?o[n]={value:i.createFromGraphic(e[n],r),valueset:!0,node:null}:o[n]={value:e[n],valueset:!0,node:null};return o}function Ge(e){console.log(e)}Ke.prototype=Ee,Ke.prototype.infinity={value:Number.POSITIVE_INFINITY,valueset:!0,node:null},Ke.prototype.pi={value:Math.PI,valueset:!0,node:null};const Ze=Pe;function Ue(e){const t={mode:"async",compiled:!1,functions:{},signatures:[],standardFunction:W,standardFunctionAsync:z,evaluateIdentifier:Re};for(let n=0;n<e.length;n++)e[n].registerFunctions(t);for(const n in t.functions)Ee[n]={value:new l(t.functions[n]),valueset:!0,node:null},Ke.prototype[n]=Ee[n];for(let n=0;n<t.signatures.length;n++)L(t.signatures[n],"async")}async function qe(e,n){let a=n.spatialReference;null==a&&(a=new U({wkid:102100}));let i=null;e.usesModules&&(i=new t(new Map,e.loadedModules));const l=De(n.vars,n.customfunctions,n.timeZone),s={spatialReference:a,services:n.services,exports:{},libraryResolver:i,abortSignal:void 0===n.abortSignal||null===n.abortSignal?{aborted:!1}:n.abortSignal,globalScope:l,console:n.console??Ge,timeZone:n.timeZone??null,lrucache:n.lrucache,interceptor:n.interceptor,localScope:null,depthCounter:{depth:1}};let u=await H(s,e);if(u instanceof F&&(u=u.value),u instanceof A&&(u=u.value),u===b&&(u=null),u===S)throw new r(s,o.IllegalResult,null);if(u===v)throw new r(s,o.IllegalResult,null);if(x(u))throw new r(s,o.IllegalResult,null);return u}Ue([E]);export{qe as executeScript,Ue as extend,Ze as functionHelper};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"./cache.js";import{FeatureSetError as t,FeatureSetErrorCodes as s}from"./errorsupport.js";import i from"./FeatureSetIterator.js";import n from"./IdSet.js";import{FeatureServiceDatabaseType as a,layerGeometryEsriConstants as r,IdState as l,convertSquareUnitsToCode as u,convertLinearUnitsToCode as h,esriFieldToJson as o,layerGeometryEsriRestConstants as c}from"./shared.js";import{max as d,min as _,sum as p,variance as f,stdev as m,mean as g,distinct as y,count as F}from"./stats.js";import{isPromiseLike as b}from"../../../core/promiseUtils.js";import{WhereClause as T}from"../../../core/sql/WhereClause.js";import{union as I,geodesicArea as w,planarArea as S,geodesicLength as D,planarLength as P}from"../../../geometry/geometryEngineAsync.js";import k from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/FieldsIndex.js";class x{constructor(e){this.recentlyUsedQueries=null,this.featureSetQueryInterceptor=null,this._idstates=[],this._parent=null,this._wset=null,this._mainSetInUse=null,this._maxProcessing=200,this._maxQuery=500,this._totalCount=-1,this._databaseType=a.NotEvaluated,this._databaseTypeProbed=null,this.declaredRootClass="esri.arcade.featureset.support.FeatureSet",this._featureCache=[],this.typeIdField=null,this.types=null,this.subtypeField=null,this.subtypes=null,this.fields=null,this.geometryType="",this.objectIdField="",this.globalIdField="",this.spatialReference=null,this.hasM=!1,this.hasZ=!1,this._transparent=!1,this.loaded=!1,this._loadPromise=null,this._fieldsIndex=null,this.fsetInfo=null,e?.lrucache&&(this.recentlyUsedQueries=e.lrucache),e?.interceptor&&(this.featureSetQueryInterceptor=e.interceptor)}optimisePagingFeatureQueries(e){this._parent&&this._parent.optimisePagingFeatureQueries(e)}_hasMemorySource(){return!0}prop(e,t){return void 0===t?this[e]:(void 0!==this[e]&&(this[e]=t),this)}end(){return null!==this._parent&&!0===this._parent._transparent?this._parent.end():this._parent}_ensureLoaded(){return this.load()}load(){return null===this._loadPromise&&(this._loadPromise=this.loadImpl()),this._loadPromise}async loadImpl(){return!0===this._parent?.loaded?(this._initialiseFeatureSet(),this):(await(this._parent?.load()),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types,this.subtypeField=this._parent.subtypeField,this.subtypes=this._parent.subtypes):(this.fields=[],this.typeIdField="",this.subtypeField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new k({wkid:4326}),this.geometryType=r.point)}getField(e,t){let s;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(s=t),!!s)))),s}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=C.fromLayer({timeInfo:this.timeInfo,editFieldsInfo:this.editFieldsInfo,dateFieldsTimeZone:this.dateFieldsTimeZone,datesInUnknownTimezone:this.datesInUnknownTimezone,fields:this.fields})),this._fieldsIndex}_maxProcessingRate(){return null!==this._parent?Math.min(this._maxProcessing,this._parent._maxProcessingRate()):Math.min(this._maxProcessing,this._maxQueryRate())}_maxQueryRate(){return null!==this._parent?Math.max(this._maxQuery,this._parent._maxQueryRate()):this._maxQuery}_checkCancelled(e){if(null!=e&&e.aborted)throw new t(s.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,s,i,n){return null!==this._parent&&this._parent._canDoAggregates(e,t,s,i,n)}async _getAggregatePagesDataSourceDefinition(e,i,n,a,r,l,u){if(null===this._parent)throw new t(s.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,i,n,a,r,l,u)}async _getAgregagtePhysicalPage(e,i,n){if(null===this._parent)throw new t(s.NeverReach);return this._parent._getAgregagtePhysicalPage(e,i,n)}async databaseType(){if(this._databaseType===a.NotEvaluated){if(null!==e.applicationCache){const t=e.applicationCache.getDatabaseType(this._cacheableFeatureSetSourceKey());if(null!==t)return t}if(null!==this._databaseTypeProbed)return this._databaseTypeProbed;try{this._databaseTypeProbed=this._getDatabaseTypeImpl(),null!==e.applicationCache&&e.applicationCache.setDatabaseType(this._cacheableFeatureSetSourceKey(),this._databaseTypeProbed)}catch(t){throw null!==e.applicationCache&&e.applicationCache.clearDatabaseType(this._cacheableFeatureSetSourceKey()),t}return this._databaseTypeProbed}return this._databaseType}async _getDatabaseTypeImpl(){const e=[{thetype:a.SqlServer,testwhere:"(CAST( '2015-01-01' as DATETIME) = CAST( '2015-01-01' as DATETIME)) AND OBJECTID<0"},{thetype:a.Oracle,testwhere:"(TO_DATE('2003-11-18','YYYY-MM-DD') = TO_DATE('2003-11-18','YYYY-MM-DD')) AND OBJECTID<0"},{thetype:a.StandardisedNoInterval,testwhere:"(date '2015-01-01 10:10:10' = date '2015-01-01 10:10:10') AND OBJECTID<0"}];for(const t of e){if(!0===await this._runDatabaseProbe(t.testwhere))return t.thetype}return a.StandardisedNoInterval}_cacheableFeatureSetSourceKey(){return"MUSTBESET"}async _runDatabaseProbe(e){if(null!==this._parent)return this._parent._runDatabaseProbe(e);throw new t(s.NotImplemented)}isTable(){return this._parent?.isTable()??!1}_featureFromCache(e){if(void 0!==this._featureCache[e])return this._featureCache[e]}_isInFeatureSet(e){return l.Unknown}_getSet(e){throw new t(s.NotImplemented)}async _getFeature(e,i,n){if(this._checkCancelled(n),void 0!==this._featureFromCache(i))return this._featureFromCache(i);if(await this._getFeatures(e,i,this._maxProcessingRate(),n),this._checkCancelled(n),void 0!==this._featureFromCache(i))return this._featureFromCache(i);throw new t(s.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const s=new n([],e,!1,null),i=[];await this._getFeatures(s,-1,e.length,t),this._checkCancelled(t);for(const n of e)void 0!==this._featureFromCache(n)&&i.push(this._featureFromCache(n));return i}async _getFeatures(e,t,s,i){return"success"}_getFilteredSet(e,i,n,a,r){throw new t(s.NotImplemented)}async _refineSetBlock(e,t,s){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,s),this._refineSetBlock(e,t,s);this._checkCancelled(s);const i=e._candidates.length;this._refineKnowns(e,t);let n=i-e._candidates.length;if(0===e._candidates.length)return e;if(n>=t)return e;if(await this._refineIfParentKnown(e,t-n,s),this._checkCancelled(s),this._refineKnowns(e,t-n),n=i-e._candidates.length,n<t&&e._candidates.length>0){const i=t-n,a=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(a,a.length>i?i:e._candidates.length,s),this._checkCancelled(s),this._refineKnowns(e,t-n),e}return e}_fetchAndRefineFeatures(e,t,s){return null}_prepareFetchAndRefineSet(e){const t=[];for(let s=0;s<e.length;s++)this._isPhysicalFeature(e[s])&&t.push(e[s]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let s=0,i=null;const n=[];t=this._maxQueryRate();for(let a=0;a<e._candidates.length&&"GETPAGES"!==e._candidates[a];a++){let r=!1;const u=this._candidateIdTransform(e._candidates[a]);u!==e._candidates[a]&&(r=!0);const h=this._isInFeatureSet(u);if(h===l.InFeatureSet)!0===r?e._known.includes(u)||(e._known.push(u),s+=1):(e._known.push(e._candidates[a]),s+=1),null===i?i={start:a,end:a}:i.end===a-1?i.end=a:(n.push(i),i={start:a,end:a});else if(h===l.NotInFeatureSet)null===i?i={start:a,end:a}:i.end===a-1?i.end=a:(n.push(i),i={start:a,end:a}),s+=1;else if(h===l.Unknown&&(s+=1,!0===e._ordered))break;if(s>=t)break}null!==i&&n.push(i);for(let a=n.length-1;a>=0;a--)e._candidates.splice(n[a].start,n[a].end-n[a].start+1)}_refineIfParentKnown(e,t,s){const i=new n([],[],e._ordered,null);return i._candidates=e._candidates.slice(0),this._parent._refineSetBlock(i,t,s)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let s=0;for(let i=e._lastFetchedIndex;i<e._known.length;i++){if("GETPAGES"===e._known[i])return!0;if(void 0===this._featureCache[e._known[i]]&&(s+=1,s>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let s=0;for(let i=0;i<e._candidates.length;i++){if("GETPAGES"===e._candidates[i])return!0;if(s+=1,s>=t)break}return!1}async _expandPagedSet(e,i,n,a,r){if(null===this._parent)throw new t(s.NotImplemented);return this._parent._expandPagedSet(e,i,n,a,r)}async _expandPagedSetFeatureSet(e,t,s,i,n){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(i=1),0===i&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(i=2),0===i)return"finished";const a=await this._getPage(e,i,n);return s+a<t?this._expandPagedSet(e,t,s+a,0,n):"success"}async _getPage(e,t,s){const i=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){i.length=i.length-1;let t=0;for(let n=0;n<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+n>=e.pagesDefinition.internal.set.length);n++)i[i.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+n],t++;e.pagesDefinition.resultOffset+=t;let s=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(s=!0),!1===s&&i.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,s),this._getPage(e,t,s)}_getPhysicalPage(e,t,s){return null}_clonePageDefinition(e){return null===this._parent?null:this._parent._clonePageDefinition(e)}_first(e){return this.iterator(e).next()}first(e){return this._first(e)}async calculateStatistic(e,t,s,i){await this._ensureLoaded();let n=await this._stat(e,t,"",null,null,s,i);return!1===n.calculated&&(n=await this._manualStat(e,t,s,i)),n.result}async _manualStat(e,t,s,i){let n=null;switch(e.toLowerCase()){case"count":return n=await F(this,i),{calculated:!0,result:n};case"distinct":return n=await y(this,t,s,i),{calculated:!0,result:n};case"avg":case"mean":return n=await g(this,t,i),{calculated:!0,result:n};case"stdev":return n=await m(this,t,i),{calculated:!0,result:n};case"variance":return n=await f(this,t,i),{calculated:!0,result:n};case"sum":return n=await p(this,t,i),{calculated:!0,result:n};case"min":return n=await _(this,t,i),{calculated:!0,result:n};case"max":return n=await d(this,t,i),{calculated:!0,result:n};default:return{calculated:!0,result:0}}}async _stat(e,t,s,i,n,a,r){const l=await this._parent._stat(e,t,s,i,n,a,r);return!1===l.calculated?null===n&&""===s&&null===i?this._manualStat(e,t,a,r):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),s=[];return new Promise(((e,i)=>{this._unionShapeInBatches(s,t,e,i)}))}_unionAllGeom(e){return new Promise(((t,s)=>{const i=this.iterator(this._defaultTracker(e)),n=[];this._unionShapeInBatches(n,i,t,s)}))}_unionShapeInBatches(e,t,s,i){t.next().then((n=>{try{null!==n&&null!==n.geometry&&e.push(n.geometry),e.length>30||null===n&&e.length>1?I(e).then((a=>{try{null===n?s(a):(e=[a],this._unionShapeInBatches(e,t,s,i))}catch(r){i(r)}}),i):null===n?1===e.length?s(e[0]):s(null):this._unionShapeInBatches(e,t,s,i)}catch(a){i(a)}}),i)}iterator(e){return new i(this,e)}intersection(e,t=!1){return x._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,s=!0){return x._featuresetFunctions.difference.bind(this)(e,t,s)}symmetricDifference(e,t=!1,s=!0){return x._featuresetFunctions.symmetricDifference.bind(this)(e,t,s)}morphShape(e,t,s="unknown",i=null){return x._featuresetFunctions.morphShape.bind(this)(e,t,s,i)}morphShapeAndAttributes(e,t,s="unknown"){return x._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,s)}union(e,t=!1){return x._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return x._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return x._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return x._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return x._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return x._featuresetFunctions.relate.bind(this)(e,t)}within(e){return x._featuresetFunctions.within.bind(this)(e)}touches(e){return x._featuresetFunctions.touches.bind(this)(e)}top(e){return x._featuresetFunctions.top.bind(this)(e)}crosses(e){return x._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,s,i=!0){return x._featuresetFunctions.buffer.bind(this)(e,t,s,i)}filter(e,t=null){return x._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return x._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return x._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return x._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,s){return new Promise(((i,n)=>{this._reduceImpl(this.iterator(this._defaultTracker(s)),e,t,0,i,n,0)}))}_reduceImpl(e,t,s,i,n,a,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._reduceImpl(e,t,s,i,n,a,r)}));e.next().then((l=>{try{if(null===l)n(s);else{const u=t(s,l,i,this);b(u)?u.then((s=>{this._reduceImpl(e,t,s,i+1,n,a,r)}),a):this._reduceImpl(e,t,u,i+1,n,a,r)}}catch(u){a(u)}}),a)}catch(l){a(l)}}removeField(e){return x._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,s=null){return x._featuresetFunctions.addField.bind(this)(e,t,s)}sumArea(e,t=!1,s){const i=u(e);return this.reduce(((e,s)=>null===s.geometry?0:t?w(s.geometry,i).then((t=>e+t)):S(s.geometry,i).then((t=>e+t))),0,s)}sumLength(e,t=!1,s){const i=h(e);return this.reduce(((e,s)=>null===s.geometry?0:t?D(s.geometry,i).then((t=>e+t)):P(s.geometry,i).then((t=>e+t))),0,s)}_substituteVars(e,t){if(null!==t){const s={};for(const e in t)s[e.toLowerCase()]=t[e];e.parameters=s}}async distinct(e,t=1e3,s=null,i){await this.load();const n=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(n,s),this.calculateStatistic("distinct",n,t,this._defaultTracker(i))}async min(e,t=null,s){await this.load();const i=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(i,t),this.calculateStatistic("min",i,-1,this._defaultTracker(s))}async max(e,t=null,s){await this.load();const i=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(i,t),this.calculateStatistic("max",i,-1,this._defaultTracker(s))}async avg(e,t=null,s){await this.load();const i=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(i,t),this.calculateStatistic("avg",i,-1,this._defaultTracker(s))}async sum(e,t=null,s){await this.load();const i=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(i,t),this.calculateStatistic("sum",i,-1,this._defaultTracker(s))}async stdev(e,t=null,s){await this.load();const i=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(i,t),this.calculateStatistic("stdev",i,-1,this._defaultTracker(s))}async variance(e,t=null,s){await this.load();const i=T.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return this._substituteVars(i,t),this.calculateStatistic("variance",i,-1,this._defaultTracker(s))}async count(e){return await this.load(),this.calculateStatistic("count",T.create("1",this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((s,i)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,s,i,0)}))}_forEachImpl(e,t,s,i,n,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._forEachImpl(e,t,s,i,n,a)}),0);e.next().then((r=>{try{if(null===r)i(s);else{const l=t(r);null==l?this._forEachImpl(e,t,s,i,n,a):b(l)?l.then((()=>{try{this._forEachImpl(e,t,s,i,n,a)}catch(r){n(r)}}),n):this._forEachImpl(e,t,s,i,n,a)}}catch(l){n(l)}}),n)}catch(r){n(r)}}convertToJSON(e){const t={layerDefinition:{geometryType:this.geometryType,fields:[]},featureSet:{features:[],geometryType:this.geometryType}};for(let s=0;s<this.fields.length;s++)t.layerDefinition.fields.push(o(this.fields[s]));return this.reduce(((e,s)=>{const i={geometry:s.geometry?.toJSON(),attributes:{}};for(const t in s.attributes)i.attributes[t]=s.attributes[t];return t.featureSet.features.push(i),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,s,i,n){return this._parent.queryAttachments(e,t,s,i,n)}serviceUrl(){return this._parent.serviceUrl()}subtypeMetaData(){return this.subtypeField&&this.subtypes?{subtypeField:this.subtypeField,subtypes:this.subtypes?this.subtypes.map((e=>({name:e.name,code:e.code}))):[]}:this.typeIdField?{subtypeField:this.typeIdField,subtypes:this.types?this.types.map((e=>({name:e.name,code:e.id}))):[]}:null}relationshipMetaData(){return this._parent.relationshipMetaData()}get gdbVersion(){return this._parent?this._parent.gdbVersion:""}schema(){const e=[];for(const t of this.fields)e.push(o(t));return{objectIdField:this.objectIdField,globalIdField:this.globalIdField,geometryType:void 0===c[this.geometryType]?"esriGeometryNull":c[this.geometryType],fields:e}}async convertToText(e,t){if("schema"===e)return await this._ensureLoaded(),JSON.stringify(this.schema());if("featureset"===e){await this._ensureLoaded();const e=[];await this.reduce(((t,s)=>{const i={geometry:s.geometry?s.geometry.toJSON():null,attributes:s.attributes};return null!==i.geometry&&i.geometry.spatialReference&&delete i.geometry.spatialReference,e.push(i),1}),0,t);const s=this.schema();return s.features=e,s.spatialReference=this.spatialReference.toJSON(),JSON.stringify(s)}return this.castToText()}getFeatureByObjectId(e,t){return this._parent.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._parent.getOwningSystemUrl()}getIdentityUser(){return this._parent.getIdentityUser()}getRootFeatureSet(){return null!==this._parent?this._parent.getRootFeatureSet():this}getDataSourceFeatureSet(){return null!==this._parent?this._parent.getDataSourceFeatureSet():this}castAsJson(e=null){return"keeptype"===e?.featureset?this:"none"===e?.featureset?null:{type:"FeatureSet"}}async castAsJsonAsync(e=null,t=null){if("keeptype"===t?.featureset)return this;if("schema"===t?.featureset)return await this._ensureLoaded(),JSON.parse(JSON.stringify(this.schema()));if("none"===t?.featureset)return null;await this._ensureLoaded();const s=[];await this.reduce(((e,i)=>{const n={geometry:i.geometry?!0===t?.keepGeometryType?i.geometry:i.geometry.toJSON():null,attributes:i.attributes};return null!==n.geometry&&n.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete n.geometry.spatialReference,s.push(n),1}),0,e);const i=this.schema();return i.features=s,i.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),i}fieldTimeZone(e){return this.getFieldsIndex().getTimeZone(e)}get preferredTimeZone(){return this._parent?.preferredTimeZone??null}get dateFieldsTimeZone(){return this._parent?.dateFieldsTimeZone??null}get dateFieldsTimeZoneDefaultUTC(){if(this.datesInUnknownTimezone)return"unknown";const e=this.dateFieldsTimeZone??"UTC";return""===e?"UTC":e}get datesInUnknownTimezone(){return this._parent.datesInUnknownTimezone}get editFieldsInfo(){return this._parent?.editFieldsInfo??null}get timeInfo(){return this._parent?.timeInfo??null}set featureSetInfo(e){this.fsetInfo=e}async getFeatureSetInfo(){return this.fsetInfo??await(this._parent?.getFeatureSetInfo())??null}}x._featuresetFunctions={};export{x as default};
|
|
5
|
+
import e from"./cache.js";import{FeatureSetError as t,FeatureSetErrorCodes as s}from"./errorsupport.js";import n from"./FeatureSetIterator.js";import i from"./IdSet.js";import{FeatureServiceDatabaseType as a,layerGeometryEsriConstants as r,IdState as l,convertSquareUnitsToCode as u,convertLinearUnitsToCode as h,esriFieldToJson as o,layerGeometryEsriRestConstants as c}from"./shared.js";import{max as d,min as _,sum as p,variance as f,stdev as m,mean as g,distinct as y,count as F}from"./stats.js";import{isPromiseLike as T}from"../../../core/promiseUtils.js";import{WhereClause as b}from"../../../core/sql/WhereClause.js";import{union as I,geodesicArea as w,planarArea as S,geodesicLength as D,planarLength as P}from"../../../geometry/geometryEngineAsync.js";import k from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/FieldsIndex.js";class x{constructor(e){this.recentlyUsedQueries=null,this.featureSetQueryInterceptor=null,this._idstates=[],this._parent=null,this._wset=null,this._mainSetInUse=null,this._maxProcessing=200,this._maxQuery=500,this._totalCount=-1,this._databaseType=a.NotEvaluated,this._databaseTypeProbed=null,this.declaredRootClass="esri.arcade.featureset.support.FeatureSet",this._featureCache=[],this.typeIdField=null,this.types=null,this.subtypeField=null,this.subtypes=null,this.fields=null,this.geometryType="",this.objectIdField="",this.globalIdField="",this.spatialReference=null,this.hasM=!1,this.hasZ=!1,this._transparent=!1,this.loaded=!1,this._loadPromise=null,this._fieldsIndex=null,this.fsetInfo=null,e?.lrucache&&(this.recentlyUsedQueries=e.lrucache),e?.interceptor&&(this.featureSetQueryInterceptor=e.interceptor)}optimisePagingFeatureQueries(e){this._parent&&this._parent.optimisePagingFeatureQueries(e)}_hasMemorySource(){return!0}prop(e,t){return void 0===t?this[e]:(void 0!==this[e]&&(this[e]=t),this)}end(){return null!==this._parent&&!0===this._parent._transparent?this._parent.end():this._parent}_ensureLoaded(){return this.load()}load(){return null===this._loadPromise&&(this._loadPromise=this.loadImpl()),this._loadPromise}async loadImpl(){return!0===this._parent?.loaded?(this._initialiseFeatureSet(),this):(await(this._parent?.load()),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types,this.subtypeField=this._parent.subtypeField,this.subtypes=this._parent.subtypes):(this.fields=[],this.typeIdField="",this.subtypeField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new k({wkid:4326}),this.geometryType=r.point)}getField(e,t){let s;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(s=t),!!s)))),s}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=C.fromLayer({timeInfo:this.timeInfo,editFieldsInfo:this.editFieldsInfo,dateFieldsTimeZone:this.dateFieldsTimeZone,datesInUnknownTimezone:this.datesInUnknownTimezone,fields:this.fields})),this._fieldsIndex}_maxProcessingRate(){return null!==this._parent?Math.min(this._maxProcessing,this._parent._maxProcessingRate()):Math.min(this._maxProcessing,this._maxQueryRate())}_maxQueryRate(){return null!==this._parent?Math.max(this._maxQuery,this._parent._maxQueryRate()):this._maxQuery}_checkCancelled(e){if(null!=e&&e.aborted)throw new t(s.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,s,n,i){return null!==this._parent&&this._parent._canDoAggregates(e,t,s,n,i)}async _getAggregatePagesDataSourceDefinition(e,n,i,a,r,l,u){if(null===this._parent)throw new t(s.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,n,i,a,r,l,u)}async _getAgregagtePhysicalPage(e,n,i){if(null===this._parent)throw new t(s.NeverReach);return this._parent._getAgregagtePhysicalPage(e,n,i)}async databaseType(){if(this._databaseType===a.NotEvaluated){if(null!==e.applicationCache){const t=e.applicationCache.getDatabaseType(this._cacheableFeatureSetSourceKey());if(null!==t)return t}if(null!==this._databaseTypeProbed)return this._databaseTypeProbed;try{this._databaseTypeProbed=this._getDatabaseTypeImpl(),null!==e.applicationCache&&e.applicationCache.setDatabaseType(this._cacheableFeatureSetSourceKey(),this._databaseTypeProbed)}catch(t){throw null!==e.applicationCache&&e.applicationCache.clearDatabaseType(this._cacheableFeatureSetSourceKey()),t}return this._databaseTypeProbed}return this._databaseType}async _getDatabaseTypeImpl(){const e=[{thetype:a.SqlServer,testwhere:"(CAST( '2015-01-01' as DATETIME) = CAST( '2015-01-01' as DATETIME)) AND OBJECTID<0"},{thetype:a.Oracle,testwhere:"(TO_DATE('2003-11-18','YYYY-MM-DD') = TO_DATE('2003-11-18','YYYY-MM-DD')) AND OBJECTID<0"},{thetype:a.StandardisedNoInterval,testwhere:"(date '2015-01-01 10:10:10' = date '2015-01-01 10:10:10') AND OBJECTID<0"}];for(const t of e){if(!0===await this._runDatabaseProbe(t.testwhere))return t.thetype}return a.StandardisedNoInterval}_cacheableFeatureSetSourceKey(){return"MUSTBESET"}async _runDatabaseProbe(e){if(null!==this._parent)return this._parent._runDatabaseProbe(e);throw new t(s.NotImplemented)}isTable(){return this._parent?.isTable()??!1}_featureFromCache(e){if(void 0!==this._featureCache[e])return this._featureCache[e]}_isInFeatureSet(e){return l.Unknown}_getSet(e){throw new t(s.NotImplemented)}async _getFeature(e,n,i){if(this._checkCancelled(i),void 0!==this._featureFromCache(n))return this._featureFromCache(n);if(await this._getFeatures(e,n,this._maxProcessingRate(),i),this._checkCancelled(i),void 0!==this._featureFromCache(n))return this._featureFromCache(n);throw new t(s.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const s=new i([],e,!1,null),n=[];await this._getFeatures(s,-1,e.length,t),this._checkCancelled(t);for(const i of e)void 0!==this._featureFromCache(i)&&n.push(this._featureFromCache(i));return n}async _getFeatures(e,t,s,n){return"success"}_getFilteredSet(e,n,i,a,r){throw new t(s.NotImplemented)}async _refineSetBlock(e,t,s){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,s),this._refineSetBlock(e,t,s);this._checkCancelled(s);const n=e._candidates.length;this._refineKnowns(e,t);let i=n-e._candidates.length;if(0===e._candidates.length)return e;if(i>=t)return e;if(await this._refineIfParentKnown(e,t-i,s),this._checkCancelled(s),this._refineKnowns(e,t-i),i=n-e._candidates.length,i<t&&e._candidates.length>0){const n=t-i,a=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(a,a.length>n?n:e._candidates.length,s),this._checkCancelled(s),this._refineKnowns(e,t-i),e}return e}_fetchAndRefineFeatures(e,t,s){return null}_prepareFetchAndRefineSet(e){const t=[];for(let s=0;s<e.length;s++)this._isPhysicalFeature(e[s])&&t.push(e[s]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let s=0,n=null;const i=[];t=this._maxQueryRate();for(let a=0;a<e._candidates.length&&"GETPAGES"!==e._candidates[a];a++){let r=!1;const u=this._candidateIdTransform(e._candidates[a]);u!==e._candidates[a]&&(r=!0);const h=this._isInFeatureSet(u);if(h===l.InFeatureSet)!0===r?e._known.includes(u)||(e._known.push(u),s+=1):(e._known.push(e._candidates[a]),s+=1),null===n?n={start:a,end:a}:n.end===a-1?n.end=a:(i.push(n),n={start:a,end:a});else if(h===l.NotInFeatureSet)null===n?n={start:a,end:a}:n.end===a-1?n.end=a:(i.push(n),n={start:a,end:a}),s+=1;else if(h===l.Unknown&&(s+=1,!0===e._ordered))break;if(s>=t)break}null!==n&&i.push(n);for(let a=i.length-1;a>=0;a--)e._candidates.splice(i[a].start,i[a].end-i[a].start+1)}_refineIfParentKnown(e,t,s){const n=new i([],[],e._ordered,null);return n._candidates=e._candidates.slice(0),this._parent._refineSetBlock(n,t,s)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let s=0;for(let n=e._lastFetchedIndex;n<e._known.length;n++){if("GETPAGES"===e._known[n])return!0;if(void 0===this._featureCache[e._known[n]]&&(s+=1,s>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let s=0;for(let n=0;n<e._candidates.length;n++){if("GETPAGES"===e._candidates[n])return!0;if(s+=1,s>=t)break}return!1}async _expandPagedSet(e,n,i,a,r){if(null===this._parent)throw new t(s.NotImplemented);return this._parent._expandPagedSet(e,n,i,a,r)}async _expandPagedSetFeatureSet(e,t,s,n,i){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(n=1),0===n&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(n=2),0===n)return"finished";const a=await this._getPage(e,n,i);return s+a<t?this._expandPagedSet(e,t,s+a,0,i):"success"}async _getPage(e,t,s){const n=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){n.length=n.length-1;let t=0;for(let i=0;i<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+i>=e.pagesDefinition.internal.set.length);i++)n[n.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+i],t++;e.pagesDefinition.resultOffset+=t;let s=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(s=!0),!1===s&&n.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,s),this._getPage(e,t,s)}_getPhysicalPage(e,t,s){return null}_clonePageDefinition(e){return null===this._parent?null:this._parent._clonePageDefinition(e)}_first(e){return this.iterator(e).next()}first(e){return this._first(e)}async calculateStatistic(e,t,s,n){await this._ensureLoaded();let i=await this._stat(e,t,"",null,null,s,n);return!1===i.calculated&&(i=await this._manualStat(e,t,s,n)),i.result}async _manualStat(e,t,s,n){let i=null;switch(e.toLowerCase()){case"count":return i=await F(this,n),{calculated:!0,result:i};case"distinct":return i=await y(this,t,s,n),{calculated:!0,result:i};case"avg":case"mean":return i=await g(this,t,n),{calculated:!0,result:i};case"stdev":return i=await m(this,t,n),{calculated:!0,result:i};case"variance":return i=await f(this,t,n),{calculated:!0,result:i};case"sum":return i=await p(this,t,n),{calculated:!0,result:i};case"min":return i=await _(this,t,n),{calculated:!0,result:i};case"max":return i=await d(this,t,n),{calculated:!0,result:i};default:return{calculated:!0,result:0}}}async _stat(e,t,s,n,i,a,r){const l=await this._parent._stat(e,t,s,n,i,a,r);return!1===l.calculated?null===i&&""===s&&null===n?this._manualStat(e,t,a,r):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),s=[];return new Promise(((e,n)=>{this._unionShapeInBatches(s,t,e,n)}))}_unionAllGeom(e){return new Promise(((t,s)=>{const n=this.iterator(this._defaultTracker(e)),i=[];this._unionShapeInBatches(i,n,t,s)}))}_unionShapeInBatches(e,t,s,n){t.next().then((i=>{try{null!==i&&null!==i.geometry&&e.push(i.geometry),e.length>30||null===i&&e.length>1?I(e).then((a=>{try{null===i?s(a):(e=[a],this._unionShapeInBatches(e,t,s,n))}catch(r){n(r)}}),n):null===i?1===e.length?s(e[0]):s(null):this._unionShapeInBatches(e,t,s,n)}catch(a){n(a)}}),n)}iterator(e){return new n(this,e)}intersection(e,t=!1){return x._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,s=!0){return x._featuresetFunctions.difference.bind(this)(e,t,s)}symmetricDifference(e,t=!1,s=!0){return x._featuresetFunctions.symmetricDifference.bind(this)(e,t,s)}morphShape(e,t,s="unknown",n=null){return x._featuresetFunctions.morphShape.bind(this)(e,t,s,n)}morphShapeAndAttributes(e,t,s="unknown"){return x._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,s)}union(e,t=!1){return x._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return x._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return x._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return x._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return x._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return x._featuresetFunctions.relate.bind(this)(e,t)}within(e){return x._featuresetFunctions.within.bind(this)(e)}touches(e){return x._featuresetFunctions.touches.bind(this)(e)}top(e){return x._featuresetFunctions.top.bind(this)(e)}crosses(e){return x._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,s,n=!0){return x._featuresetFunctions.buffer.bind(this)(e,t,s,n)}filter(e,t=null){return x._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return x._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return x._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return x._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,s){return new Promise(((n,i)=>{this._reduceImpl(this.iterator(this._defaultTracker(s)),e,t,0,n,i,0)}))}_reduceImpl(e,t,s,n,i,a,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._reduceImpl(e,t,s,n,i,a,r)}));e.next().then((l=>{try{if(null===l)i(s);else{const u=t(s,l,n,this);T(u)?u.then((s=>{this._reduceImpl(e,t,s,n+1,i,a,r)}),a):this._reduceImpl(e,t,u,n+1,i,a,r)}}catch(u){a(u)}}),a)}catch(l){a(l)}}removeField(e){return x._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,s=null){return x._featuresetFunctions.addField.bind(this)(e,t,s)}sumArea(e,t=!1,s){const n=u(e);return this.reduce(((e,s)=>null===s.geometry?0:t?w(s.geometry,n).then((t=>e+t)):S(s.geometry,n).then((t=>e+t))),0,s)}sumLength(e,t=!1,s){const n=h(e);return this.reduce(((e,s)=>null===s.geometry?0:t?D(s.geometry,n).then((t=>e+t)):P(s.geometry,n).then((t=>e+t))),0,s)}async distinct(e,t=1e3,s=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(i,s),this.calculateStatistic("distinct",i,t,this._defaultTracker(n))}async min(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("min",n,-1,this._defaultTracker(s))}async max(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("max",n,-1,this._defaultTracker(s))}async avg(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("avg",n,-1,this._defaultTracker(s))}async sum(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("sum",n,-1,this._defaultTracker(s))}async stdev(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("stdev",n,-1,this._defaultTracker(s))}async variance(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("variance",n,-1,this._defaultTracker(s))}async count(e){return await this.load(),this.calculateStatistic("count",b.create("1",this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((s,n)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,s,n,0)}))}_forEachImpl(e,t,s,n,i,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._forEachImpl(e,t,s,n,i,a)}),0);e.next().then((r=>{try{if(null===r)n(s);else{const l=t(r);null==l?this._forEachImpl(e,t,s,n,i,a):T(l)?l.then((()=>{try{this._forEachImpl(e,t,s,n,i,a)}catch(r){i(r)}}),i):this._forEachImpl(e,t,s,n,i,a)}}catch(l){i(l)}}),i)}catch(r){i(r)}}convertToJSON(e){const t={layerDefinition:{geometryType:this.geometryType,fields:[]},featureSet:{features:[],geometryType:this.geometryType}};for(let s=0;s<this.fields.length;s++)t.layerDefinition.fields.push(o(this.fields[s]));return this.reduce(((e,s)=>{const n={geometry:s.geometry?.toJSON(),attributes:{}};for(const t in s.attributes)n.attributes[t]=s.attributes[t];return t.featureSet.features.push(n),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,s,n,i){return this._parent.queryAttachments(e,t,s,n,i)}serviceUrl(){return this._parent.serviceUrl()}subtypeMetaData(){return this.subtypeField&&this.subtypes?{subtypeField:this.subtypeField,subtypes:this.subtypes?this.subtypes.map((e=>({name:e.name,code:e.code}))):[]}:this.typeIdField?{subtypeField:this.typeIdField,subtypes:this.types?this.types.map((e=>({name:e.name,code:e.id}))):[]}:null}relationshipMetaData(){return this._parent.relationshipMetaData()}get gdbVersion(){return this._parent?this._parent.gdbVersion:""}schema(){const e=[];for(const t of this.fields)e.push(o(t));return{objectIdField:this.objectIdField,globalIdField:this.globalIdField,geometryType:void 0===c[this.geometryType]?"esriGeometryNull":c[this.geometryType],fields:e}}async convertToText(e,t){if("schema"===e)return await this._ensureLoaded(),JSON.stringify(this.schema());if("featureset"===e){await this._ensureLoaded();const e=[];await this.reduce(((t,s)=>{const n={geometry:s.geometry?s.geometry.toJSON():null,attributes:s.attributes};return null!==n.geometry&&n.geometry.spatialReference&&delete n.geometry.spatialReference,e.push(n),1}),0,t);const s=this.schema();return s.features=e,s.spatialReference=this.spatialReference.toJSON(),JSON.stringify(s)}return this.castToText()}getFeatureByObjectId(e,t){return this._parent.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._parent.getOwningSystemUrl()}getIdentityUser(){return this._parent.getIdentityUser()}getRootFeatureSet(){return null!==this._parent?this._parent.getRootFeatureSet():this}getDataSourceFeatureSet(){return null!==this._parent?this._parent.getDataSourceFeatureSet():this}castAsJson(e=null){return"keeptype"===e?.featureset?this:"none"===e?.featureset?null:{type:"FeatureSet"}}async castAsJsonAsync(e=null,t=null){if("keeptype"===t?.featureset)return this;if("schema"===t?.featureset)return await this._ensureLoaded(),JSON.parse(JSON.stringify(this.schema()));if("none"===t?.featureset)return null;await this._ensureLoaded();const s=[];await this.reduce(((e,n)=>{const i={geometry:n.geometry?!0===t?.keepGeometryType?n.geometry:n.geometry.toJSON():null,attributes:n.attributes};return null!==i.geometry&&i.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete i.geometry.spatialReference,s.push(i),1}),0,e);const n=this.schema();return n.features=s,n.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),n}fieldTimeZone(e){return this.getFieldsIndex().getTimeZone(e)}get preferredTimeZone(){return this._parent?.preferredTimeZone??null}get dateFieldsTimeZone(){return this._parent?.dateFieldsTimeZone??null}get dateFieldsTimeZoneDefaultUTC(){if(this.datesInUnknownTimezone)return"unknown";const e=this.dateFieldsTimeZone??"UTC";return""===e?"UTC":e}get datesInUnknownTimezone(){return this._parent.datesInUnknownTimezone}get editFieldsInfo(){return this._parent?.editFieldsInfo??null}get timeInfo(){return this._parent?.timeInfo??null}set featureSetInfo(e){this.fsetInfo=e}async getFeatureSetInfo(){return this.fsetInfo??await(this._parent?.getFeatureSetInfo())??null}}function v(e,t){if(null!==t){const s={};for(const e in t)s[e.toLowerCase()]=t[e];e.parameters=s}}x._featuresetFunctions={};export{x 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.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as o,constructFeatureSetFromPortalItem as l,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as d}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{H as p,n as y,m as w,u as h,c as g,j as F,l as I,N as D,k as T,K as b,h as E,o as A,r as N,q as x,i as S,g as L,a2 as C,T as $,O as v}from"../../chunks/languageUtils.js";import{getPortal as P}from"../portalUtils.js";import{SqlExpressionAdapted as j,StringToCodeAdapted as U,FieldRename as Z,AdaptedFeatureSet as M,OriginalField as R}from"../featureset/actions/Adapted.js";import k from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import z from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as _}from"../featureset/support/shared.js";import{isSingleField as K}from"../featureset/support/sqlUtils.js";import{calculateStat as q}from"./fieldStats.js";import{isPromiseLike as B}from"../../core/promiseUtils.js";import{WhereClause as V}from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";function X(e,t){if(1===t.length){if(A(t[0]))return q(e,t[0],-1);if(x(t[0]))return q(e,t[0].toArray(),-1)}return q(e,t,-1)}async function ee(e,t,n){const a=e.getVariables();if(a.length>0){const i=[];for(let e=0;e<a.length;e++){const r={name:a[e]};i.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<a.length;e++)r[a[e]]=i[e];return e.parameters=r,e}return e}function te(e,t,n=null){for(const a in e)if(a.toLowerCase()===t.toLowerCase())return e[a];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ae(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const a=te(e,"wkid");return null!==a&&(t.wkid=a),t}function ie(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference");null!=n&&(t.spatialReference=ae(n));const a=te(e,"x",null);if(null!==a)return t.x=a,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const i=te(e,"rings",null);if(null!==i)return t.rings=i,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==A(e.layerDefinition.fields)&&!1!==A(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(q){"async"===q.mode&&(q.functions.timezone=function(t,r){return q.standardFunctionAsync(t,r,(async(s,o,l)=>{if(p(l,1,2,t,r),y(l[0]))return"Unknown";if(w(l[0]))return"Unknown";if(h(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new a(t,i.InvalidParameter,r);const e=l[1].field("type");if(!1===g(e))throw new a(t,i.InvalidParameter,r);switch(F(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&g(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(F(l[1].field("fieldname"))))}throw new a(t,i.InvalidParameter,r)}const f=I(l[0],D(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:"utc"===u.toLowerCase()?"UTC":"unknown"===u.toLowerCase()?"Unknown":u}))},q.functions.sqltimestamp=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const o=s[0];if(T(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(F(s[1])).toSQLWithKeyword();throw new a(e,i.InvalidParameter,t)}if(w(o))return o.toSQLWithKeyword();if(h(o)){if(3!==s.length)throw new a(e,i.InvalidParameter,t);await o.load();const n=F(s[1]);if(w(s[2]))return s[2].toSQLWithKeyword();if(!1===T(s[2]))throw new a(e,i.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"sqltimestamp",min:2,max:4}),q.functions.featuresetbyid=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetById(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyid",min:2,max:4}),q.functions.getfeatureset=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,1,2,e,t),N(s[0])){let t=b(s[1],"datasource");return null===t&&(t="datasource"),t=F(t).toLowerCase(),o(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference??null)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"getfeatureset",min:1,max:2}),q.functions.featuresetbyportalitem=function(e,n){return q.standardFunctionAsync(e,n,((r,s,o)=>{if(p(o,2,5,e,n),null===o[0])throw new a(e,i.PortalRequired,n);if(o[0]instanceof t){const t=F(o[1]),r=F(o[2]);let s=b(o[3],null);const f=E(b(o[4],!0));if(null===s&&(s=["*"]),!1===A(s))throw new a(e,i.InvalidParameter,n);let u;return u=e.services?.portal?e.services.portal:Y.getDefault(),u=P(o[0],u),l(t,r,e.spatialReference??null,s,f,u,e.lrucache,e.interceptor)}if(!1===g(o[0]))throw new a(e,i.PortalRequired,n);const f=F(o[0]),u=F(o[1]);let c=b(o[2],null);const d=E(b(o[3],!0));if(null===c&&(c=["*"]),!1===A(c))throw new a(e,i.InvalidParameter,n);return l(f,u,e.spatialReference??null,c,d,e.services?.portal??Y.getDefault(),e.lrucache,e.interceptor)}))},q.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),q.functions.featuresetbyname=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetByName(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyname",min:2,max:4}),q.functions.featureset=function(e,t){return q.standardFunction(e,t,((r,s,o)=>{p(o,1,1,e,t);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(g(o[0])){const e=JSON.parse(o[0]);void 0!==e.layerDefinition?(l.layerDefinition=e.layerDefinition,l.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(l.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(l.featureSet.features=e.features,l.featureSet.geometryType=e.geometryType,l.layerDefinition.geometryType=l.featureSet.geometryType,l.layerDefinition.objectIdField=e.objectIdFieldName??"",l.layerDefinition.typeIdField=e.typeIdFieldName,l.layerDefinition.globalIdField=e.globalIdFieldName,l.layerDefinition.fields=e.fields,e.spatialReference&&(l.layerDefinition.spatialReference=e.spatialReference))}else{if(!(o[0]instanceof n))throw new a(e,i.InvalidParameter,t);{const e=JSON.parse(o[0].castToText(!0)),t=te(e,"layerdefinition");if(null!==t){l.layerDefinition.geometryType=te(t,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=te(t,"globalidfield",""),l.layerDefinition.objectIdField=te(t,"objectidfield",""),l.layerDefinition.typeIdField=te(t,"typeidfield",""),l.layerDefinition.hasZ=!0===te(t,"hasz",!1),l.layerDefinition.hasM=!0===te(t,"hasm",!1);const n=te(t,"spatialreference");n&&(l.layerDefinition.spatialReference=ae(n));const a=[];for(const e of te(t,"fields",[])){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};a.push(t)}l.layerDefinition.fields=a;const i=te(e,"featureset");if(i){const e={};for(const t of a)e[t.name.toLowerCase()]=t.name;for(const t of te(i,"features",[])){const n={},a=te(t,"attributes",{});for(const t in a)n[e[t.toLowerCase()]]=a[t];l.featureSet.features.push({attributes:n,geometry:ie(te(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===te(e,"hasz",!1),l.layerDefinition.hasM=!0===te(e,"hasm",!1),l.layerDefinition.geometryType=te(e,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=te(e,"objectidfieldname",""),l.layerDefinition.typeIdField=te(e,"typeidfieldname","");const t=te(e,"spatialreference");t&&(l.layerDefinition.spatialReference=ae(t));const n=[];let a=te(e,"fields",null);if(A(a)){for(const e of a){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};n.push(t)}l.layerDefinition.fields=n}else a=null,l.layerDefinition.fields=a;const i={};for(const e of n)i[e.name.toLowerCase()]=e.name;let r=te(e,"features",null);if(A(r))for(const e of r){const t={},n=te(e,"attributes",{});for(const e in n)t[i[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ie(te(e,"geometry",null))})}else r=null,l.featureSet.features=r}}}if(!1===se(l))throw new a(e,i.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),W.create(l,e.spatialReference)}))},q.signatures.push({name:"featureset",min:1,max:1}),q.functions.filter=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),A(s[0])||x(s[0])){const n=[];let r,o=s[0];if(o instanceof m&&(o=o.toArray()),!S(s[1]))throw new a(e,i.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);B(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(h(s[0])){const t=await s[0].load(),n=V.create(s[1],t.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC),a=n.getVariables();if(a.length>0){const t=[];for(let n=0;n<a.length;n++){const i={name:a[n]};t.push(await q.evaluateIdentifier(e,i))}const i={};for(let e=0;e<a.length;e++)i[a[e]]=t[e];return n.parameters=i,new k({parentfeatureset:s[0],whereclause:n})}return new k({parentfeatureset:s[0],whereclause:n})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filter",min:2,max:2}),q.functions.orderby=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"orderby",min:2,max:2}),q.functions.top=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0]))return new z({parentfeatureset:s[0],topnum:s[1]});if(A(s[0]))return L(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,L(s[1]));if(x(s[0]))return L(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,L(s[1]));throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"top",min:2,max:2}),q.functions.first=function(e,t){return q.standardFunctionAsync(e,t,(async(n,a,i)=>{if(p(i,1,1,e,t),h(i[0])){const t=await i[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,i[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return A(i[0])?0===i[0].length?null:i[0][0]:x(i[0])?0===i[0].length()?null:i[0].get(0):null}))},q.signatures.push({name:"first",min:1,max:1}),q.functions.attachments=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{p(o,1,2,e,t);const l={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(l.minsize=L(o[1].field("minsize"))),o[1].hasField("metadata")&&(l.returnMetadata=E(o[1].field("metadata"))),o[1].hasField("maxsize")&&(l.maxsize=L(o[1].field("maxsize"))),o[1].hasField("types")){const e=C(o[1].field("types"),!1);e.length>0&&(l.types=e)}}else if(null!==o[1])throw new a(e,i.InvalidParameter,t);if(N(o[0])){let t=o[0]._layer;return t instanceof Q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===h(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),l.minsize,l.maxsize,l.types,l.returnMetadata))}if(null===o[0])return[];throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"attachments",min:1,max:2}),q.functions.featuresetbyrelationshipname=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const o=s[0],l=F(s[1]);let d=b(s[2],null);const m=E(b(s[3],!0));if(null===d&&(d=["*"]),!1===A(d))throw new a(e,i.InvalidParameter,t);if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let y=o._layer;if(y instanceof Q&&(y=f(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===h(y))return null;y=await y.load();const w=y.relationshipMetaData().filter((e=>e.name===l));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(y,w[0],o.field(y.objectIdField),y.spatialReference,d,m,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+w[0].relatedTableId.toString():g+"/"+w[0].relatedTableId.toString();const I=await c(g,y.spatialReference,d,m,e.lrucache,e.interceptor);await I.load();let D=I.relationshipMetaData();if(D=D.filter((e=>e.id===w[0].id)),!1===o.hasField(w[0].keyField)||null===o.field(w[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[w[0].keyField]);if(e){const t=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return t.parameters={id:e.attributes[w[0].keyField]},I.filter(t)}return new H({parentfeatureset:I})}const T=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return T.parameters={id:o.field(w[0].keyField)},I.filter(T)}))},q.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),q.functions.featuresetbyassociation=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const o=s[0],l=F(b(s[1],"")).toLowerCase(),u=g(s[2])?F(s[2]):null;if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let c=o._layer;if(c instanceof Q&&(c=f(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===h(c))return null;await c.load();const m=c.serviceUrl(),y=await d(m,e.spatialReference);let w=null,I=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of y.terminals)e.terminalName===u&&(I=e.terminalId);null===I&&(D=!0)}const T=y.associations.getFieldsIndex(),E=T.get("TOGLOBALID").name,A=T.get("FROMGLOBALID").name,x=T.get("TOTERMINALID").name,S=T.get("FROMTERMINALID").name,L=T.get("FROMNETWORKSOURCEID").name,C=T.get("TONETWORKSOURCEID").name,v=T.get("ASSOCIATIONTYPE").name,P=T.get("ISCONTENTVISIBLE").name,k=T.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){w=o.field(e.name);break}let O=null,z=new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create("''",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));const W="globalid",G="globalId",K={};for(const e in y.lkp)K[e]=y.lkp[e].sourceId;const q=new U(new J({name:"classname",alias:"classname",type:"string"}),null,K);let B="";switch(l){case"midspan":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (5))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),z=y.unVersion>=4?new R(M.findField(y.associations.fields,T.get("PERCENTALONG").name)):new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"junctionedge":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (4,6))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create(`CASE WHEN (${v}=4) THEN 'from' ELSE 'to' END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==I&&(e+=` AND ${x}=@A`,t+=` AND ${S}=@A`),B="(("+e+") OR ("+t+"))",B=$(B,"@T",w??""),e=$(e,"@T",w??""),null!==I&&(e=$(e,"@A",I.toString()),B=$(B,"@A",I.toString())),q.codefield=V.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const n=_(M.findField(y.associations.fields,A));n.name=W,n.alias=W,O=new j(n,V.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"container":B=`${E}='${w}' AND ${v} = 2`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,W);break;case"content":B=`(${A}='${w}' AND ${v} = 2)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,W);break;case"structure":B=`(${E}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,G);break;case"attached":B=`(${A}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,G);break;default:throw new a(e,i.InvalidParameter,t)}D&&(B="1 <> 1");return new M({parentfeatureset:y.associations,adaptedFields:[new R(M.findField(y.associations.fields,k)),new R(M.findField(y.associations.fields,P)),O,H,q,z],extraFilter:B?V.create(B,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC):null})}))},q.signatures.push({name:"featuresetbyassociation",min:2,max:6}),q.functions.groupby=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(p(o,3,3,e,t),!h(o[0]))throw new a(e,i.InvalidParameter,t);const l=await o[0].load(),f=[],u=[];let c=!1,d=[];if(g(o[1]))d.push(o[1]);else if(o[1]instanceof n)d.push(o[1]);else if(A(o[1]))d=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);d=o[1].toArray()}for(const m of d)if(g(m)){const e=V.create(F(m),l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(c=!0)}else{if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(c=!0),!n)throw new a(e,i.InvalidParameter,t);f.push({name:n,expression:V.create(r||n,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(d=[],g(o[2]))d.push(o[2]);else if(A(o[2]))d=o[2];else if(x(o[2]))d=o[2].toArray();else{if(!(o[2]instanceof n))throw new a(e,i.InvalidParameter,t);d.push(o[2])}for(const m of d){if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new a(e,i.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:V.create(s,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(c){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 u)"%%%%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 t of f)await ee(t.expression,q,e);for(const t of u)await ee(t.expression,q,e);return o[0].groupby(f,u)}))},q.signatures.push({name:"groupby",min:3,max:3}),q.functions.distinct=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(h(o[0])){p(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(g(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(A(o[1]))l=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(g(o)){const e=V.create(F(o),r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new a(e,i.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new a(e,i.InvalidParameter,t);s.push({name:n,expression:V.create(l||n,r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC)})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await ee(t.expression,q,e);return o[0].groupby(s,[])}return X("distinct",o)}))},q.functions.getfeaturesetinfo=function(e,t){return q.standardFunctionAsync(e,t,(async(a,i,r)=>{if(p(r,1,1,e,t),!h(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},D(e),!1,!1):null}))},q.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),q.functions.filterbysubtypecode=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const n=await s[0].load(),r=s[1];if(!v(r))throw new a(e,i.InvalidParameter,t);if(n.subtypeField){const e=V.create(`${n.subtypeField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new a(e,i.FeatureSetDoesNotHaveSubtypes,t);const o=V.create(`${n.typeIdField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:o})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le as registerFunctions};
|
|
5
|
+
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as o,constructFeatureSetFromPortalItem as l,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as d}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{H as p,n as y,m as w,u as h,c as g,j as F,l as I,N as D,k as T,K as b,h as E,o as A,r as N,q as x,i as S,g as L,a2 as C,T as $,O as v}from"../../chunks/languageUtils.js";import{getPortal as P}from"../portalUtils.js";import{SqlExpressionAdapted as j,StringToCodeAdapted as U,FieldRename as Z,AdaptedFeatureSet as M,OriginalField as R}from"../featureset/actions/Adapted.js";import k from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import z from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as _}from"../featureset/support/shared.js";import{isSingleField as K}from"../featureset/support/sqlUtils.js";import{calculateStat as q}from"./fieldStats.js";import{isPromiseLike as B}from"../../core/promiseUtils.js";import{WhereClause as V}from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";function X(e){if(1===e.length){if(A(e[0]))return q("distinct",e[0],-1);if(x(e[0]))return q("distinct",e[0].toArray(),-1)}return q("distinct",e,-1)}async function ee(e,t,n){const a=e.getVariables();if(a.length>0){const i=[];for(let e=0;e<a.length;e++){const r={name:a[e]};i.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<a.length;e++)r[a[e]]=i[e];return e.parameters=r,e}return e}function te(e,t,n=null){for(const a in e)if(a.toLowerCase()===t.toLowerCase())return e[a];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ae(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const a=te(e,"wkid");return null!==a&&(t.wkid=a),t}function ie(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference");null!=n&&(t.spatialReference=ae(n));const a=te(e,"x",null);if(null!==a)return t.x=a,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const i=te(e,"rings",null);if(null!==i)return t.rings=i,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==A(e.layerDefinition.fields)&&!1!==A(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(q){"async"===q.mode&&(q.functions.timezone=function(t,r){return q.standardFunctionAsync(t,r,(async(s,o,l)=>{if(p(l,1,2,t,r),y(l[0]))return"Unknown";if(w(l[0]))return"Unknown";if(h(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new a(t,i.InvalidParameter,r);const e=l[1].field("type");if(!1===g(e))throw new a(t,i.InvalidParameter,r);switch(F(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&g(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(F(l[1].field("fieldname"))))}throw new a(t,i.InvalidParameter,r)}const f=I(l[0],D(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:"utc"===u.toLowerCase()?"UTC":"unknown"===u.toLowerCase()?"Unknown":u}))},q.functions.sqltimestamp=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const o=s[0];if(T(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(F(s[1])).toSQLWithKeyword();throw new a(e,i.InvalidParameter,t)}if(w(o))return o.toSQLWithKeyword();if(h(o)){if(3!==s.length)throw new a(e,i.InvalidParameter,t);await o.load();const n=F(s[1]);if(w(s[2]))return s[2].toSQLWithKeyword();if(!1===T(s[2]))throw new a(e,i.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"sqltimestamp",min:2,max:4}),q.functions.featuresetbyid=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetById(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyid",min:2,max:4}),q.functions.getfeatureset=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,1,2,e,t),N(s[0])){let t=b(s[1],"datasource");return null===t&&(t="datasource"),t=F(t).toLowerCase(),o(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference??null)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"getfeatureset",min:1,max:2}),q.functions.featuresetbyportalitem=function(e,n){return q.standardFunctionAsync(e,n,((r,s,o)=>{if(p(o,2,5,e,n),null===o[0])throw new a(e,i.PortalRequired,n);if(o[0]instanceof t){const t=F(o[1]),r=F(o[2]);let s=b(o[3],null);const f=E(b(o[4],!0));if(null===s&&(s=["*"]),!1===A(s))throw new a(e,i.InvalidParameter,n);let u;return u=e.services?.portal?e.services.portal:Y.getDefault(),u=P(o[0],u),l(t,r,e.spatialReference??null,s,f,u,e.lrucache,e.interceptor)}if(!1===g(o[0]))throw new a(e,i.PortalRequired,n);const f=F(o[0]),u=F(o[1]);let c=b(o[2],null);const d=E(b(o[3],!0));if(null===c&&(c=["*"]),!1===A(c))throw new a(e,i.InvalidParameter,n);return l(f,u,e.spatialReference??null,c,d,e.services?.portal??Y.getDefault(),e.lrucache,e.interceptor)}))},q.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),q.functions.featuresetbyname=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetByName(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyname",min:2,max:4}),q.functions.featureset=function(e,t){return q.standardFunction(e,t,((r,s,o)=>{p(o,1,1,e,t);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(g(o[0])){const e=JSON.parse(o[0]);void 0!==e.layerDefinition?(l.layerDefinition=e.layerDefinition,l.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(l.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(l.featureSet.features=e.features,l.featureSet.geometryType=e.geometryType,l.layerDefinition.geometryType=l.featureSet.geometryType,l.layerDefinition.objectIdField=e.objectIdFieldName??"",l.layerDefinition.typeIdField=e.typeIdFieldName,l.layerDefinition.globalIdField=e.globalIdFieldName,l.layerDefinition.fields=e.fields,e.spatialReference&&(l.layerDefinition.spatialReference=e.spatialReference))}else{if(!(o[0]instanceof n))throw new a(e,i.InvalidParameter,t);{const n=JSON.parse(o[0].castToText(!0)),r=te(n,"layerdefinition");if(null!==r){l.layerDefinition.geometryType=te(r,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=te(r,"globalidfield",""),l.layerDefinition.objectIdField=te(r,"objectidfield",""),l.layerDefinition.typeIdField=te(r,"typeidfield",""),l.layerDefinition.hasZ=!0===te(r,"hasz",!1),l.layerDefinition.hasM=!0===te(r,"hasm",!1);const e=te(r,"spatialreference");e&&(l.layerDefinition.spatialReference=ae(e));const t=[];for(const n of te(r,"fields",[])){const e={name:te(n,"name",""),alias:te(n,"alias",""),type:te(n,"type",""),nullable:te(n,"nullable",!0),editable:te(n,"editable",!0),length:te(n,"length",null),domain:ne(te(n,"domain"))};t.push(e)}l.layerDefinition.fields=t;const a=te(n,"featureset");if(a){const e={};for(const n of t)e[n.name.toLowerCase()]=n.name;for(const t of te(a,"features",[])){const n={},a=te(t,"attributes",{});for(const t in a)n[e[t.toLowerCase()]]=a[t];l.featureSet.features.push({attributes:n,geometry:ie(te(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===te(n,"hasz",!1),l.layerDefinition.hasM=!0===te(n,"hasm",!1),l.layerDefinition.geometryType=te(n,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=te(n,"objectidfieldname",""),l.layerDefinition.typeIdField=te(n,"typeidfieldname","");const r=te(n,"spatialreference");r&&(l.layerDefinition.spatialReference=ae(r));const s=[],o=te(n,"fields",null);if(!A(o))throw new a(e,i.InvalidParameter,t);for(const e of o){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};s.push(t)}l.layerDefinition.fields=s;const f={};for(const e of s)f[e.name.toLowerCase()]=e.name;let u=te(n,"features",null);if(A(u))for(const e of u){const t={},n=te(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ie(te(e,"geometry",null))})}else u=null,l.featureSet.features=u}}}if(!1===se(l))throw new a(e,i.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),W.create(l,e.spatialReference)}))},q.signatures.push({name:"featureset",min:1,max:1}),q.functions.filter=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),A(s[0])||x(s[0])){const n=[];let r,o=s[0];if(o instanceof m&&(o=o.toArray()),!S(s[1]))throw new a(e,i.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);B(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(h(s[0])){const t=await s[0].load(),n=V.create(s[1],t.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC),a=n.getVariables();if(a.length>0){const t=[];for(let n=0;n<a.length;n++){const i={name:a[n]};t.push(await q.evaluateIdentifier(e,i))}const i={};for(let e=0;e<a.length;e++)i[a[e]]=t[e];return n.parameters=i,new k({parentfeatureset:s[0],whereclause:n})}return new k({parentfeatureset:s[0],whereclause:n})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filter",min:2,max:2}),q.functions.orderby=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"orderby",min:2,max:2}),q.functions.top=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0]))return new z({parentfeatureset:s[0],topnum:s[1]});if(A(s[0]))return L(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,L(s[1]));if(x(s[0]))return L(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,L(s[1]));throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"top",min:2,max:2}),q.functions.first=function(e,t){return q.standardFunctionAsync(e,t,(async(n,a,i)=>{if(p(i,1,1,e,t),h(i[0])){const t=await i[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,i[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return A(i[0])?0===i[0].length?null:i[0][0]:x(i[0])?0===i[0].length()?null:i[0].get(0):null}))},q.signatures.push({name:"first",min:1,max:1}),q.functions.attachments=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{p(o,1,2,e,t);const l={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(l.minsize=L(o[1].field("minsize"))),o[1].hasField("metadata")&&(l.returnMetadata=E(o[1].field("metadata"))),o[1].hasField("maxsize")&&(l.maxsize=L(o[1].field("maxsize"))),o[1].hasField("types")){const e=C(o[1].field("types"),!1);e.length>0&&(l.types=e)}}else if(null!==o[1])throw new a(e,i.InvalidParameter,t);if(N(o[0])){let t=o[0]._layer;return t instanceof Q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===h(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),l.minsize,l.maxsize,l.types,l.returnMetadata))}if(null===o[0])return[];throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"attachments",min:1,max:2}),q.functions.featuresetbyrelationshipname=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const o=s[0],l=F(s[1]);let d=b(s[2],null);const m=E(b(s[3],!0));if(null===d&&(d=["*"]),!1===A(d))throw new a(e,i.InvalidParameter,t);if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let y=o._layer;if(y instanceof Q&&(y=f(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===h(y))return null;y=await y.load();const w=y.relationshipMetaData().filter((e=>e.name===l));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(y,w[0],o.field(y.objectIdField),y.spatialReference,d,m,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+w[0].relatedTableId.toString():g+"/"+w[0].relatedTableId.toString();const I=await c(g,y.spatialReference,d,m,e.lrucache,e.interceptor);await I.load();let D=I.relationshipMetaData();if(D=D.filter((e=>e.id===w[0].id)),!1===o.hasField(w[0].keyField)||null===o.field(w[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[w[0].keyField]);if(e){const t=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return t.parameters={id:e.attributes[w[0].keyField]},I.filter(t)}return new H({parentfeatureset:I})}const T=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return T.parameters={id:o.field(w[0].keyField)},I.filter(T)}))},q.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),q.functions.featuresetbyassociation=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const o=s[0],l=F(b(s[1],"")).toLowerCase(),u=g(s[2])?F(s[2]):null;if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let c=o._layer;if(c instanceof Q&&(c=f(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===h(c))return null;await c.load();const m=c.serviceUrl(),y=await d(m,e.spatialReference);let w=null,I=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of y.terminals)e.terminalName===u&&(I=e.terminalId);null===I&&(D=!0)}const T=y.associations.getFieldsIndex(),E=T.get("TOGLOBALID").name,A=T.get("FROMGLOBALID").name,x=T.get("TOTERMINALID").name,S=T.get("FROMTERMINALID").name,L=T.get("FROMNETWORKSOURCEID").name,C=T.get("TONETWORKSOURCEID").name,v=T.get("ASSOCIATIONTYPE").name,P=T.get("ISCONTENTVISIBLE").name,k=T.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){w=o.field(e.name);break}let O=null,z=new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create("''",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));const W="globalid",G="globalId",K={};for(const e in y.lkp)K[e]=y.lkp[e].sourceId;const q=new U(new J({name:"classname",alias:"classname",type:"string"}),null,K);let B="";switch(l){case"midspan":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (5))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),z=y.unVersion>=4?new R(M.findField(y.associations.fields,T.get("PERCENTALONG").name)):new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"junctionedge":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (4,6))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create(`CASE WHEN (${v}=4) THEN 'from' ELSE 'to' END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==I&&(e+=` AND ${x}=@A`,t+=` AND ${S}=@A`),B="(("+e+") OR ("+t+"))",B=$(B,"@T",w??""),e=$(e,"@T",w??""),null!==I&&(e=$(e,"@A",I.toString()),B=$(B,"@A",I.toString())),q.codefield=V.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const n=_(M.findField(y.associations.fields,A));n.name=W,n.alias=W,O=new j(n,V.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"container":B=`${E}='${w}' AND ${v} = 2`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,W);break;case"content":B=`(${A}='${w}' AND ${v} = 2)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,W);break;case"structure":B=`(${E}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,G);break;case"attached":B=`(${A}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,G);break;default:throw new a(e,i.InvalidParameter,t)}D&&(B="1 <> 1");return new M({parentfeatureset:y.associations,adaptedFields:[new R(M.findField(y.associations.fields,k)),new R(M.findField(y.associations.fields,P)),O,H,q,z],extraFilter:B?V.create(B,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC):null})}))},q.signatures.push({name:"featuresetbyassociation",min:2,max:6}),q.functions.groupby=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(p(o,3,3,e,t),!h(o[0]))throw new a(e,i.InvalidParameter,t);const l=await o[0].load(),f=[],u=[];let c=!1,d=[];if(g(o[1]))d.push(o[1]);else if(o[1]instanceof n)d.push(o[1]);else if(A(o[1]))d=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);d=o[1].toArray()}for(const m of d)if(g(m)){const e=V.create(F(m),l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(c=!0)}else{if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(c=!0),!n)throw new a(e,i.InvalidParameter,t);f.push({name:n,expression:V.create(r||n,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(d=[],g(o[2]))d.push(o[2]);else if(A(o[2]))d=o[2];else if(x(o[2]))d=o[2].toArray();else{if(!(o[2]instanceof n))throw new a(e,i.InvalidParameter,t);d.push(o[2])}for(const m of d){if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new a(e,i.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:V.create(s,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(c){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 u)"%%%%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 t of f)await ee(t.expression,q,e);for(const t of u)await ee(t.expression,q,e);return o[0].groupby(f,u)}))},q.signatures.push({name:"groupby",min:3,max:3}),q.functions.distinct=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(h(o[0])){p(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(g(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(A(o[1]))l=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(g(o)){const e=V.create(F(o),r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new a(e,i.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new a(e,i.InvalidParameter,t);s.push({name:n,expression:V.create(l||n,r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC)})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await ee(t.expression,q,e);return o[0].groupby(s,[])}return X(o)}))},q.functions.getfeaturesetinfo=function(e,t){return q.standardFunctionAsync(e,t,(async(a,i,r)=>{if(p(r,1,1,e,t),!h(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},D(e),!1,!1):null}))},q.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),q.functions.filterbysubtypecode=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const n=await s[0].load(),r=s[1];if(!v(r))throw new a(e,i.InvalidParameter,t);if(n.subtypeField){const e=V.create(`${n.subtypeField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new a(e,i.FeatureSetDoesNotHaveSubtypes,t);const o=V.create(`${n.typeIdField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:o})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le 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.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeExecutionError as n,ExecutionErrorCodes as r}from"../executionError.js";import{H as t,o as e,c as i,q as u}from"../../chunks/languageUtils.js";import{calculateStat as o}from"./fieldStats.js";function a(n,r
|
|
5
|
+
import{ArcadeExecutionError as n,ExecutionErrorCodes as r}from"../executionError.js";import{H as t,o as e,c as i,q as u}from"../../chunks/languageUtils.js";import{calculateStat as o}from"./fieldStats.js";function a(n,r){if(1===r.length){if(e(r[0]))return o(n,r[0],-1);if(u(r[0]))return o(n,r[0].toArray(),-1)}return o(n,r,-1)}function f(o,f){o.stdev=function(n,r){return f(n,r,((n,r,t)=>a("stdev",t)))},o.variance=function(n,r){return f(n,r,((n,r,t)=>a("variance",t)))},o.average=function(n,r){return f(n,r,((n,r,t)=>a("mean",t)))},o.mean=function(n,r){return f(n,r,((n,r,t)=>a("mean",t)))},o.sum=function(n,r){return f(n,r,((n,r,t)=>a("sum",t)))},o.min=function(n,r){return f(n,r,((n,r,t)=>a("min",t)))},o.max=function(n,r){return f(n,r,((n,r,t)=>a("max",t)))},o.distinct=function(n,r){return f(n,r,((n,r,t)=>a("distinct",t)))},o.count=function(o,a){return f(o,a,((f,c,m)=>{if(t(m,1,1,o,a),e(m[0])||i(m[0]))return m[0].length;if(u(m[0]))return m[0].length();throw new n(o,r.InvalidParameter,a)}))}}export{f as registerFunctions};
|