@arcgis/core 4.32.0-next.20241209 → 4.32.0-next.20241211
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/applications/Components/arcadeUtils.d.ts +4 -0
- package/{core/units.js → applications/Components/arcadeUtils.js} +1 -1
- package/arcade/featureSetUtils.js +1 -1
- package/arcade/featureset/actions/Adapted.js +1 -1
- package/arcade/featureset/actions/AttributeFilter.js +1 -1
- package/arcade/featureset/actions/GroupBy.js +1 -1
- package/arcade/featureset/support/FeatureSet.js +1 -1
- package/arcade/featureset/support/StatsField.js +1 -1
- package/arcade/featureset/support/sqlUtils.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/arcade/functions/featuresetstats.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/068772a1066498af363d.js +1 -0
- package/assets/esri/core/workers/chunks/0a578f14ea8ce1c1a507.js +1 -0
- package/assets/esri/core/workers/chunks/0b2da288fc8cdb025e85.js +1 -0
- package/assets/esri/core/workers/chunks/{eb243e9d233b3e8b594f.js → 0e0ee4cb722f6e183bf6.js} +1 -1
- package/assets/esri/core/workers/chunks/0e9bd990a8d0691fb9c8.js +1 -0
- package/assets/esri/core/workers/chunks/1100d9d114287b6443e2.js +1 -0
- package/assets/esri/core/workers/chunks/19a41d91e6b5f5219f8d.js +1 -0
- package/assets/esri/core/workers/chunks/23966144429ec415143b.js +1 -0
- package/assets/esri/core/workers/chunks/3029354194f1a3030c5c.js +1 -0
- package/assets/esri/core/workers/chunks/{5ce409978f9f3d370da6.js → 32149a9d6fe4505b7a46.js} +1 -1
- package/assets/esri/core/workers/chunks/{197ac668dcdfc4e06515.js → 3dc76fd95ab4b537adec.js} +1 -1
- package/assets/esri/core/workers/chunks/437612b390ba3850db74.js +1 -0
- package/assets/esri/core/workers/chunks/46fbecda3095947deef7.js +1 -0
- package/assets/esri/core/workers/chunks/{42b24e49d0b5a0c33006.js → 4753a1ee76d0d335236d.js} +1 -1
- package/assets/esri/core/workers/chunks/4ea0037bbe375fb4d6c1.js +1 -0
- package/assets/esri/core/workers/chunks/{2d93885095034ce3e22f.js → 5032161adbe8154e226d.js} +1 -1
- package/assets/esri/core/workers/chunks/{b8e3b3663cc5b8a75e64.js → 5119811063bfc97fb725.js} +1 -1
- package/assets/esri/core/workers/chunks/57a028a42ddcb5bdc9f7.js +1 -0
- package/assets/esri/core/workers/chunks/594e8e3bf7b083a8e1fb.js +1 -0
- package/assets/esri/core/workers/chunks/59bf879b4802a5ba431e.js +1 -0
- package/assets/esri/core/workers/chunks/5ea6f9fa41485e5bdbba.js +1 -0
- package/assets/esri/core/workers/chunks/77f5db553abe827ecbd7.js +1 -0
- package/assets/esri/core/workers/chunks/7a0ddaf2c279a2d24c86.js +1 -0
- package/assets/esri/core/workers/chunks/{1350e228d0c06f639c9c.js → 7a790873467ea34332c4.js} +1 -1
- package/assets/esri/core/workers/chunks/7de09792f387466dd79c.js +1 -0
- package/assets/esri/core/workers/chunks/{7fbd2b4844b6d2acab4e.js → 7de9c01849c4aa1940e7.js} +1 -1
- package/assets/esri/core/workers/chunks/8531abfadac90713fa2f.js +1 -0
- package/assets/esri/core/workers/chunks/8aefbb870460a5b338a6.js +1 -0
- package/assets/esri/core/workers/chunks/911cf45ee0dc8d5302f9.js +1 -0
- package/assets/esri/core/workers/chunks/9b020c47ca9ff5de9bb8.js +1 -0
- package/assets/esri/core/workers/chunks/9db2489eb8358e0bee14.js +1 -0
- package/assets/esri/core/workers/chunks/a1bf2255239f055dbbc0.js +1 -0
- package/assets/esri/core/workers/chunks/a3cef3837f4df9ab022e.js +1 -0
- package/assets/esri/core/workers/chunks/a5ad50ae4667257d7db8.js +1 -0
- package/assets/esri/core/workers/chunks/{9d712a5be4cb32357a68.js → aaebac78f6a15c498b04.js} +1 -1
- package/assets/esri/core/workers/chunks/b15894bff153e0793ef4.js +1 -0
- package/assets/esri/core/workers/chunks/{2c7029147472e87605d7.js → b4d76d46661aba356ea3.js} +1 -1
- package/assets/esri/core/workers/chunks/{59a32bd035c33f05f431.js → c849e378476673bff9a1.js} +3 -3
- package/assets/esri/core/workers/chunks/c98d90ad85b2582360c9.js +1 -0
- package/assets/esri/core/workers/chunks/{c372a1f6bf77251a72a3.js → cb15fc452da18dadd87a.js} +1 -1
- package/assets/esri/core/workers/chunks/d14e4fc82ad772899336.js +1 -0
- package/assets/esri/core/workers/chunks/d7de424035f62b824695.js +1 -0
- package/assets/esri/core/workers/chunks/d87b4b4ba7ca85fd4bcd.js +1 -0
- package/assets/esri/core/workers/chunks/{9e88507679559221da9a.js → e008f3f33f1a8bd91e5d.js} +1 -1
- package/assets/esri/core/workers/chunks/e213f4a1c95a33f80cdc.js +1 -0
- package/assets/esri/core/workers/chunks/e33db87f2a2615a2f2fa.js +1 -0
- package/assets/esri/core/workers/chunks/e7c3199813070ff30a3d.js +1 -0
- package/assets/esri/core/workers/chunks/eddab4dc706e75c6637f.js +1 -0
- package/assets/esri/core/workers/chunks/f0adabf6d71a27f3183b.js +1 -0
- package/assets/esri/core/workers/chunks/f2d5991b48fba97a3dab.js +1 -0
- package/assets/esri/core/workers/chunks/{56b9461e4e7da3593b64.js → f5bf92c315c2944863d1.js} +1 -1
- package/assets/esri/core/workers/chunks/{cd9c686be6137b3233d2.js → f6668fd8fdcf59788010.js} +27 -26
- package/assets/esri/core/workers/chunks/{4e056b5f9086e96ba52a.js → fce1158755f959730602.js} +1 -1
- package/assets/esri/core/workers/chunks/{6216b5a1384a1f110cda.js → ff095805f151ef3ac402.js} +1 -1
- package/assets/esri/themes/base/widgets/_UtilityNetworkAssociations.scss +15 -8
- 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/HUDMaterial.glsl.js +26 -25
- package/chunks/NativeLine.glsl.js +7 -7
- package/chunks/PointRenderer.glsl.js +1 -1
- package/chunks/RealisticTree.glsl.js +2 -2
- package/chunks/WaterSurface.glsl.js +16 -16
- package/core/Accessor.js +1 -1
- package/core/quantity.d.ts +1 -1
- package/core/sql/WhereClause.d.ts +1 -1
- package/core/sql/WhereClause.js +1 -1
- package/core/sql/WhereClauseCache.js +1 -1
- package/core/sql.js +1 -1
- package/core/units.d.ts +1 -1
- package/editing/sharedTemplates/SharedTemplate.js +5 -0
- package/editing/sharedTemplates/SharedTemplateMetadata.js +5 -0
- package/editing/sharedTemplates/SharedTemplateProvider.js +5 -0
- package/editing/sharedTemplates/support/toolNames.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/FeatureTemplateDefinition.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/GroupTemplateDefinition.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/PresetTemplateDefinition.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/TemplateDefinitionBase.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/parts/FeatureTemplateRelationshipPart.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/parts/GroupTemplatePart.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/parts/PresetTemplatePart.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/parts/TemplatePartBase.js +5 -0
- package/editing/sharedTemplates/templateDefinitions/parts/builders/builderUtils.js +5 -0
- package/form/FormTemplate.js +1 -1
- package/form/elements/FieldElement.js +1 -1
- package/form/elements/GroupElement.js +1 -1
- package/form/elements/inputs.d.ts +4 -0
- package/form/elements/inputs.js +5 -0
- package/form/elements.d.ts +4 -0
- package/form/elements.js +5 -0
- package/form/support/formUtils.js +1 -1
- package/geometry/geometryEngine.js +1 -1
- package/interfaces.d.ts +680 -593
- package/layers/FeatureLayer.js +1 -1
- package/layers/WCSLayer.js +1 -1
- package/layers/graphics/data/QueryEngine.js +1 -1
- package/layers/graphics/data/QueryEngineResult.js +1 -1
- package/layers/graphics/data/queryUtils.js +1 -1
- package/layers/graphics/data/queryValidationUtils.js +1 -1
- package/layers/graphics/sources/CSVSource.js +1 -1
- package/layers/graphics/sources/FeatureLayerSource.js +1 -1
- package/layers/graphics/sources/GeoJSONSource.js +1 -1
- package/layers/graphics/sources/MemorySource.js +1 -1
- package/layers/graphics/sources/OGCFeatureSource.js +1 -1
- package/layers/graphics/sources/WFSSource.js +1 -1
- package/layers/graphics/sources/WFSSourceWorker.js +1 -1
- package/layers/graphics/sources/geojson/GeoJSONSourceWorker.js +1 -1
- package/layers/graphics/sources/support/CSVSourceWorker.js +1 -1
- package/layers/graphics/sources/support/MemorySourceWorker.js +1 -1
- package/layers/graphics/sources/support/QueryTask.js +1 -1
- package/layers/graphics/sources/support/clientSideDefaults.js +1 -1
- package/layers/orientedImagery/core/ExposurePoint.js +1 -1
- package/layers/support/capabilities.js +1 -1
- package/layers/support/featureLayerUtils.js +1 -1
- package/layers/support/serviceCapabilitiesUtils.js +1 -1
- package/package.json +1 -1
- package/rest/query/executeAttributeBinsQuery.js +5 -0
- package/rest/query/operations/{queryBins.js → queryAttributeBins.js} +1 -1
- package/rest/query.js +1 -1
- package/rest/support/AttributeBinsQuery.js +5 -0
- package/rest/support/AutoIntervalBinParameters.js +1 -1
- package/rest/support/BaseImageMeasureParameters.d.ts +1 -1
- package/rest/support/BaseImageMeasureParameters.js +1 -1
- package/rest/support/BaseImageMeasureResult.d.ts +1 -1
- package/rest/support/BaseImageMeasureResult.js +1 -1
- package/rest/support/DateBinTimeInterval.js +1 -1
- package/rest/support/ImageAreaParameters.js +1 -1
- package/rest/support/ImageAreaResult.js +1 -1
- package/rest/support/ImageDistanceParameters.js +1 -1
- package/rest/support/ImageDistanceResult.js +1 -1
- package/rest/support/ImageHeightParameters.js +1 -1
- package/rest/support/ImageHeightResult.js +1 -1
- package/rest/support/ImagePointParameters.js +1 -1
- package/rest/support/ImagePointResult.js +1 -1
- package/rest/support/JobInfo.js +1 -1
- package/rest/support/generateRendererUtils.js +1 -1
- package/rest/support/imageMeasureUtils.js +5 -0
- package/smartMapping/statistics/histogram.js +1 -1
- package/smartMapping/support/adapters/FeatureLayerAdapter.js +1 -1
- package/statistics/utils.js +1 -1
- package/support/revision.js +1 -1
- package/tables/AttributeTableTemplate.js +1 -1
- package/tables/elements/AttributeTableGroupElement.js +1 -1
- package/tables/elements.d.ts +4 -0
- package/tables/elements.js +5 -0
- package/views/2d/layers/FeatureLayerView2D.js +1 -1
- package/views/2d/layers/GraphicsLayerView2D.js +1 -1
- package/views/3d/analysis/AnalysisViewManager3D.js +1 -1
- package/views/3d/environment/EnvironmentManager.js +1 -1
- package/views/3d/environment/EnvironmentRenderer.js +1 -1
- package/views/3d/environment/SceneViewEnvironment.js +1 -1
- package/views/3d/layers/BuildingComponentSublayerView3D.js +1 -1
- package/views/3d/layers/PointCloudLayerView3D.js +1 -1
- package/views/3d/layers/SceneLayerView3D.js +1 -1
- package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
- package/views/3d/layers/graphics/Graphics3DDrapedGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DGraphic.js +1 -1
- package/views/3d/layers/graphics/Graphics3DLodInstanceGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DObjectSymbolLayer.js +1 -1
- package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
- package/views/3d/layers/i3s/{PointGraphic.js → PointCloudGraphic.js} +1 -1
- package/views/3d/layers/i3s/{PointHighlights.js → PointCloudHighlights.js} +1 -1
- package/views/3d/layers/i3s/PointCloudRenderer.js +5 -0
- package/views/3d/layers/i3s/PointCloudRendererNode.js +5 -0
- package/views/3d/layers/support/DefinitionExpressionSceneLayerView.js +1 -1
- package/views/3d/state/ViewState.js +1 -1
- package/views/3d/terrain/OverlayRenderer.js +1 -1
- package/views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js +1 -1
- package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
- package/views/3d/webgl-engine/lib/Geometry.js +1 -1
- package/views/3d/webgl-engine/lib/Object3DStateID.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/SortedRenderGeometryRenderer.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/InstanceData.js +1 -1
- package/views/3d/webgl-engine/lib/lodRendering/LodRenderer.js +1 -1
- package/views/3d/webgl-engine/materials/ColorMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/LineCalloutMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/MeasurementArrowMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/PatternMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/ShadedColorMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/SlicePlaneMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/WaterMaterial.js +1 -1
- package/views/3d/webgl-engine/materials/renderers/Instance.js +1 -1
- package/views/3d/webgl-engine/materials/renderers/MergedRenderer.js +1 -1
- package/views/3d/webgl-engine/materials/renderers/PerBufferData.js +1 -1
- package/views/3d/webgl-engine/shaders/ColorMaterialTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/HUDMaterialTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/ImageMaterialTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/LineCalloutTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/LineMarkerTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/NativeLineTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/PatternTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/RibbonLineTechnique.js +1 -1
- package/views/3d/webgl-engine/shaders/ShadedColorMaterialTechnique.js +1 -1
- package/views/SceneView.js +1 -1
- package/views/interactive/snapping/featureSources/FeatureServiceSnappingSource.js +1 -1
- package/widgets/Bookmarks/BookmarksViewModel.js +1 -1
- package/widgets/BuildingExplorer/BuildingDisciplinesTree/BuildingDisciplinesNode.js +1 -1
- package/widgets/BuildingExplorer/BuildingDisciplinesTree/BuildingDisciplinesTree.js +1 -1
- package/widgets/Compass/CompassViewModel.js +1 -1
- package/widgets/CoordinateConversion/CoordinateConversionViewModel.js +1 -1
- package/widgets/DirectionalPad/DirectionalPadViewModel.js +1 -1
- package/widgets/Directions/DirectionsViewModel.js +1 -1
- package/widgets/FeatureTable/support/EditableColumnTemplateMixin.js +1 -1
- package/widgets/Features/FeaturesViewModel.js +1 -1
- package/widgets/FloorFilter/FloorFilterViewModel.js +1 -1
- package/widgets/Home/HomeViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/components/ImageViewerViewModel.js +1 -1
- package/widgets/PanoramicViewer/PanoramicViewerViewModel.js +1 -1
- package/widgets/Popup.js +1 -1
- package/widgets/Search/SearchViewModel.js +1 -1
- package/widgets/UtilityNetworkAssociations.js +1 -1
- package/widgets/UtilityNetworkTrace.js +1 -1
- package/widgets/Weather/WeatherViewModel.js +1 -1
- package/widgets/support/GeolocationPositioning.js +1 -1
- package/widgets/support/GoTo.d.ts +1 -1
- package/widgets/support/GoTo.js +1 -1
- package/widgets/support/Selector2D/SelectionOperation.js +1 -1
- package/applications/Components/sceneViewUtils.d.ts +0 -4
- package/applications/Components/sceneViewUtils.js +0 -5
- package/assets/esri/core/workers/chunks/06f7ad8407cfd53e7038.js +0 -1
- package/assets/esri/core/workers/chunks/0d2a8b4304bd2c46c748.js +0 -1
- package/assets/esri/core/workers/chunks/13c86e096f277c3a3d8a.js +0 -1
- package/assets/esri/core/workers/chunks/1c9a810ea7d21c369586.js +0 -1
- package/assets/esri/core/workers/chunks/32239aade1555e0a5275.js +0 -1
- package/assets/esri/core/workers/chunks/466117330e74ffe16b99.js +0 -1
- package/assets/esri/core/workers/chunks/48235ecd4923bba7a5ff.js +0 -1
- package/assets/esri/core/workers/chunks/49c51b546d43ef73a655.js +0 -1
- package/assets/esri/core/workers/chunks/595c63a3397ae49044f4.js +0 -1
- package/assets/esri/core/workers/chunks/596ad0f71f6863b15c7b.js +0 -1
- package/assets/esri/core/workers/chunks/5adea6b7f5d42b9fb10a.js +0 -1
- package/assets/esri/core/workers/chunks/647fa83bfd0b4501c026.js +0 -1
- package/assets/esri/core/workers/chunks/65eb22760e37d427e8c8.js +0 -1
- package/assets/esri/core/workers/chunks/6842b8d8d3fe7a33a630.js +0 -1
- package/assets/esri/core/workers/chunks/6880a5de8dd94c28e957.js +0 -1
- package/assets/esri/core/workers/chunks/6b6fb8f614e1e2fdb7b4.js +0 -1
- package/assets/esri/core/workers/chunks/6cab7d1594ef4460a507.js +0 -1
- package/assets/esri/core/workers/chunks/7122d36e70c26f489fbe.js +0 -1
- package/assets/esri/core/workers/chunks/79908b0722c2748b115d.js +0 -1
- package/assets/esri/core/workers/chunks/8366b2b34d365bd7a422.js +0 -1
- package/assets/esri/core/workers/chunks/8613032eb13c63fbfb02.js +0 -1
- package/assets/esri/core/workers/chunks/8c8086e8d56e8c4a5889.js +0 -1
- package/assets/esri/core/workers/chunks/8e5bfcebb10194d0cbc1.js +0 -1
- package/assets/esri/core/workers/chunks/942b4dc7b3583bfa3164.js +0 -1
- package/assets/esri/core/workers/chunks/97a7eff0344392d3fd69.js +0 -1
- package/assets/esri/core/workers/chunks/99f50916ac6ea64f0386.js +0 -1
- package/assets/esri/core/workers/chunks/a99457c8bd43c1988ada.js +0 -1
- package/assets/esri/core/workers/chunks/c7c23343b79ab607aa15.js +0 -1
- package/assets/esri/core/workers/chunks/d45dd811c31965359954.js +0 -1
- package/assets/esri/core/workers/chunks/dcf88605951b3f8e7883.js +0 -1
- package/assets/esri/core/workers/chunks/de56f5be82f8b4cc9012.js +0 -1
- package/assets/esri/core/workers/chunks/e725d60b1a5f808601b7.js +0 -1
- package/assets/esri/core/workers/chunks/e73c89c4981b34ed0751.js +0 -1
- package/assets/esri/core/workers/chunks/f0e58773ff9a8a17637f.js +0 -1
- package/assets/esri/core/workers/chunks/f41cbb770b2e3cf274b9.js +0 -1
- package/assets/esri/core/workers/chunks/ff11ad1a2021aa7ab8d9.js +0 -1
- package/assets/esri/core/workers/chunks/ff5e3bf0e9b4cc48688f.js +0 -1
- package/form/elements/inputs/attachments/support/inputs.d.ts +0 -4
- package/form/elements/support/inputs.d.ts +0 -4
- package/form/elements/support/inputs.js +0 -5
- package/form/support/elements.d.ts +0 -4
- package/form/support/elements.js +0 -5
- package/rest/featureService/sharedTemplates/SharedTemplate.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/FeatureTemplateDefinition.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/GroupTemplateDefinition.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/PresetTemplateDefinition.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/parts/FeatureTemplateRelationshipPart.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/parts/GroupTemplatePart.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/parts/PresetTemplatePart.js +0 -5
- package/rest/featureService/sharedTemplates/templateDefinitions/parts/builders/builderUtils.js +0 -5
- package/rest/query/executeBinsQuery.js +0 -5
- package/rest/support/BinsQuery.js +0 -5
- package/tables/support/elements.d.ts +0 -4
- package/views/3d/layers/i3s/PointRenderer.js +0 -5
- /package/tables/support/{elements.js → tablesUtils.js} +0 -0
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
import{extractFieldNames as r}from"../../support/arcadeUtils.js";function t(t,e){return r(t,e)}export{t as extractFieldNames};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../request.js";import t from"./featureSetCollection.js";import{p as a,W as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import l from"./featureset/actions/OrderBy.js";import s from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import f from"./featureset/support/cache.js";import{FeatureSetError as p,FeatureSetErrorCodes as m}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,extractServiceUrl as h,isSupportedLayer as w}from"./featureset/support/shared.js";import _ from"../core/Loadable.js";import{WhereClause as L}from"../core/sql/WhereClause.js";import I from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import C from"../portal/PortalItem.js";function g(){null===f.applicationCache&&(f.applicationCache=new f)}async function F(e,t,a){if(f.applicationCache){const a=f.applicationCache.getLayerInfo(e);if(a){const r=await a;return new I({url:e,outFields:t,sourceJSON:r})}const n=new I({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(f.applicationCache){f.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(r){throw f.applicationCache.clearLayerInfo(e),r}}return await i,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new I({url:e,outFields:t,sourceJSON:a})}const i=new I({url:e,outFields:t}),l=(async()=>(await i.load(),i.sourceJSON))();a.setCachedLayerMetadata(e,l);try{return await l,i}catch(n){throw a.removeCachedLayerMetadata(e,l),n}}return new I({url:e,outFields:t})}async function N(e,t,a,r,n,i=null){return T(await F(e,["*"],n),t,a,r,n,i)}function T(e,t=null,a=null,r=!0,n=null,i=null){switch(e.type){case"catalog-footprint":return T(e.parent,t,a,r,n,i);case"subtype-sublayer":{const l=T(e.parent,t,a,r,n,i);return l.filter(L.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:l.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const l={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!e.url&&e.source?new c(l):new u(l)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function A(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function b(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new p(m.DataElementsNotFound)})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw f.applicationCache.clearLayerInfo(r),i}}return n}async function k(t,a){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw f.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(i){throw a.removeCachedServiceMetadata(t,r),i}}return r}async function O(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await k(e,null);if(a.metadata=r,void 0!==r.controllerDatasetLayers?.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await b(e,n);if(i){a.queryelem=i,a.queryelem?.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await A(e+"/"+n);if(void 0!==r.systemLayers?.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await N(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(L.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:i.getFieldsIndex(),timeZone:i.dateFieldsTimeZoneDefaultUTC})),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function E(e,t,a,r=null,n=null,i=!0,l=null,s=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await N(o,r,n,i,l,s);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:l,interceptor:s})}n.registerAction(),i.registerAction(),l.registerAction(),s.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.title===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.id===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e={...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await k(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])l.name===e&&(i=l);if(!i)for(const l of n.tables??[])l.name===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(!i)for(const l of n.tables??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function v(e,t,a=null,r=null){return new j(e,t,a,r)}function R(e,t,a=null,r=null){return new D(e,t,a,r)}function M(e,t,n,i,l){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return T(a,l,a.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(a,l,a.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return T(e.parent,l,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(e,l,e.parent.outFields,!0,n,i)}return null}return null}async function q(e,t,a,r,n,i,l,s=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o)return G(await o,t,a,r,n,l,s)}if(null!=l){const o=l.getCachedPortalItem(i.url,e);if(null!=o)return await G(await o,t,a,r,n,l,s)}const o=new C({id:e,portal:i}).load();f.applicationCache?f.applicationCache.setLayerInfo(e+":"+i.url,o):null!=l&&l.setCachedPortalItem(i.url,e,o);try{return await G(await o,t,a,r,n,l,s)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),null!=l&&l.removeCachedPortalItem(i.url,e,o),u}}async function G(e,t,a,r,n,i,l){let s;if("Feature Service"===e.type||"Map Service"===e.type)s=await F(h(e.url??"")+"/"+t,["*"],i);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=i){const t=i.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)s=await t;else{const t=S.fromPortalItem(e);i.setCachedPortalItemLayer(e.portal.url,e.id,t);try{s=await t}catch(o){throw i.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else s=await S.fromPortalItem(e)}return T(s,a,r,n,i,l)}export{O as constructAssociationMetaDataFeatureSetFromUrl,T as constructFeatureSet,q as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,N as constructFeatureSetFromUrl,M as convertToFeatureSet,v as createFeatureSetCollectionFromMap,R as createFeatureSetCollectionFromService,g as initialiseMetaDataCache};
|
|
5
|
+
import e from"../request.js";import t from"./featureSetCollection.js";import{p as a,W as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import l from"./featureset/actions/OrderBy.js";import s from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import f from"./featureset/support/cache.js";import{FeatureSetError as p,FeatureSetErrorCodes as m}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,extractServiceUrl as h,isSupportedLayer as w}from"./featureset/support/shared.js";import _ from"../core/Loadable.js";import L from"../core/sql/WhereClause.js";import I from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import C from"../portal/PortalItem.js";function g(){null===f.applicationCache&&(f.applicationCache=new f)}async function F(e,t,a){if(f.applicationCache){const a=f.applicationCache.getLayerInfo(e);if(a){const r=await a;return new I({url:e,outFields:t,sourceJSON:r})}const n=new I({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(f.applicationCache){f.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(r){throw f.applicationCache.clearLayerInfo(e),r}}return await i,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new I({url:e,outFields:t,sourceJSON:a})}const i=new I({url:e,outFields:t}),l=(async()=>(await i.load(),i.sourceJSON))();a.setCachedLayerMetadata(e,l);try{return await l,i}catch(n){throw a.removeCachedLayerMetadata(e,l),n}}return new I({url:e,outFields:t})}async function N(e,t,a,r,n,i=null){return T(await F(e,["*"],n),t,a,r,n,i)}function T(e,t=null,a=null,r=!0,n=null,i=null){switch(e.type){case"catalog-footprint":return T(e.parent,t,a,r,n,i);case"subtype-sublayer":{const l=T(e.parent,t,a,r,n,i);return l.filter(L.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:l.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const l={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!e.url&&e.source?new c(l):new u(l)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function A(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function b(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new p(m.DataElementsNotFound)})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw f.applicationCache.clearLayerInfo(r),i}}return n}async function k(t,a){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw f.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(i){throw a.removeCachedServiceMetadata(t,r),i}}return r}async function O(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await k(e,null);if(a.metadata=r,void 0!==r.controllerDatasetLayers?.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await b(e,n);if(i){a.queryelem=i,a.queryelem?.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await A(e+"/"+n);if(void 0!==r.systemLayers?.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await N(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(L.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:i.getFieldsIndex(),timeZone:i.dateFieldsTimeZoneDefaultUTC})),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function E(e,t,a,r=null,n=null,i=!0,l=null,s=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await N(o,r,n,i,l,s);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:l,interceptor:s})}n.registerAction(),i.registerAction(),l.registerAction(),s.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.title===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>w(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.id===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e={...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await k(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])l.name===e&&(i=l);if(!i)for(const l of n.tables??[])l.name===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(!i)for(const l of n.tables??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function v(e,t,a=null,r=null){return new j(e,t,a,r)}function R(e,t,a=null,r=null){return new D(e,t,a,r)}function M(e,t,n,i,l){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return T(a,l,a.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(a,l,a.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return T(e.parent,l,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(e,l,e.parent.outFields,!0,n,i)}return null}return null}async function q(e,t,a,r,n,i,l,s=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o)return G(await o,t,a,r,n,l,s)}if(null!=l){const o=l.getCachedPortalItem(i.url,e);if(null!=o)return await G(await o,t,a,r,n,l,s)}const o=new C({id:e,portal:i}).load();f.applicationCache?f.applicationCache.setLayerInfo(e+":"+i.url,o):null!=l&&l.setCachedPortalItem(i.url,e,o);try{return await G(await o,t,a,r,n,l,s)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),null!=l&&l.removeCachedPortalItem(i.url,e,o),u}}async function G(e,t,a,r,n,i,l){let s;if("Feature Service"===e.type||"Map Service"===e.type)s=await F(h(e.url??"")+"/"+t,["*"],i);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=i){const t=i.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)s=await t;else{const t=S.fromPortalItem(e);i.setCachedPortalItemLayer(e.portal.url,e.id,t);try{s=await t}catch(o){throw i.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else s=await S.fromPortalItem(e)}return T(s,a,r,n,i,l)}export{O as constructAssociationMetaDataFeatureSetFromUrl,T as constructFeatureSet,q as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,N as constructFeatureSetFromUrl,M as convertToFeatureSet,v as createFeatureSetCollectionFromMap,R as createFeatureSetCollectionFromService,g as initialiseMetaDataCache};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{cloneGeometry as t}from"../../kernel.js";import{FeatureSetError as r,FeatureSetErrorCodes as s}from"../support/errorsupport.js";import a from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{cloneField as l,FeatureServiceDatabaseType as n,isDate as o,isLuxonDate as u,isArcadeTime as h,isArcadeDate as c,isArcadeDateOnly as d,layerGeometryEsriConstants as p}from"../support/shared.js";import{reformulateWithoutField as f,toWhereClause as g,translateFunctionToDatabaseSpecific as N,convertColumnReferenceToSql as _,makeToday as S,makeSqlFromDateTimeParameter as m,makeTimeString as w,arcadeDateToSqlString as v,arcadeDateOnlyToSqlString as C,convertIntervalToSql as T,combine as F,scanForField as W}from"../support/sqlUtils.js";import{assertIsSome as y}from"../../../core/maybe.js";import{SqlError as A,SqlErrorCodes as E}from"../../../core/sql/errorSupport.js";import{WhereClause as x}from"../../../core/sql/WhereClause.js";import D from"../../../geometry/SpatialReference.js";class I{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class k extends I{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class b extends I{constructor(e,t,r){super(l(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:f(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class B extends I{constructor(e,t,r){super(e),this.codefield=t,this.lkp=r,this.reverseLkp={};for(const s in r)this.reverseLkp[r[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const r=this.evaluateNodeToWhereClause(e.parseTree,n.Standardised,this.field.name,this.codefield instanceof x?g(this.codefield,n.Standardised):this.codefield,e.parameters);return r.includes(B.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:x.create(r,{fieldsIndex:t._parent.getFieldsIndex(),timeZone:t.dateFieldsTimeZoneDefaultUTC})}}evaluateNodeToWhereClause(e,t,r=null,s=null,a){let i,l,n,p;switch(e.type){case"interval":return T(this.evaluateNodeToWhereClause(e.value,t,r,s,a),e.qualifier,e.op);case"case-expression":{let s=" CASE ";"simple"===e.format&&(s+=this.evaluateNodeToWhereClause(e.operand,t,r,B.BADNESS,a));for(let i=0;i<e.clauses.length;i++)s+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[i].operand,t,r,B.BADNESS,a)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[i].value,t,r,B.BADNESS,a);return null!==e.else&&(s+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,r,B.BADNESS,a)),s+=" END ",s}case"parameter":{const r=a[e.value.toLowerCase()];if("string"==typeof r)return"'"+r.toString().replaceAll("'","''")+"'";if(o(r))return m(r,t);if(u(r))return m(r,t);if(h(r))return w(r,t);if(c(r))return v(r,t);if(d(r))return C(r,t);if(Array.isArray(r)){const e=[];for(let s=0;s<r.length;s++)"string"==typeof r[s]?e.push("'"+r[s].toString().replaceAll("'","''")+"'"):o(r[s])||u(r[s])?e.push(m(r[s],t)):h(r[s])?e.push(w(r[s],t)):c(r[s])?e.push(v(r[s],t)):d(r[s])?e.push(C(r[s],t)):e.push(r[s].toString());return e}return r.toString()}case"expression-list":l=[];for(const i of e.value)l.push(this.evaluateNodeToWhereClause(i,t,r,s,a));return l;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,r,B.BADNESS,a)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" AND "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" OR "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"IS":if("null"!==e.right.type)throw new A(E.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new A(E.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NOT NULL )";case"IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return p=this.evaluateNodeToWhereClause(e.right,t,r,s,a),Array.isArray(p)?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+p.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+p+")) ";case"NOT IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return p=this.evaluateNodeToWhereClause(e.right,t,r,s,a),Array.isArray(p)?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+p.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+p+")) ";case"BETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"NOTBETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" NOT BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") ";case"<>":case"=":if("column-reference"===e.left.type&&"string"===e.right.type){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&void 0!==this.lkp[e.right.value.toString()])return" ("+s+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if("column-reference"===e.right.type&&"string"===e.left.type&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+s+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") "}case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":return`timestamp '${e.value}'`;case"date":return`date '${e.value}'`;case"time":return`time '${e.value}'`;case"number":return e.value.toString();case"current-time":return S(e.mode,t);case"current-user":return"CURRENT_USER";case"column-reference":return r&&r.toLowerCase()===e.column.toLowerCase()?"("+s+")":_(e.column);case"data-type":return e.value;case"function":{const s=this.evaluateNodeToWhereClause(e.args,t,r,B.BADNESS,a);return N(e.name,s,t)}}throw new A(E.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof x?this.reverseLkp[x.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}}B.BADNESS="_!!!_BAD_LKP_!!!!";class L extends I{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:f(e,this.field.name,g(this._sql,n.Standardised),t.getFieldsIndex())}}extractValue(e){return x.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}class R extends a{static findField(e,t){for(const r of e)if(r.name.toLowerCase()===t.toString().toLowerCase())return r;return null}constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=[],this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}_initialiseFeatureSet(){null!==this._parent?(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.spatialReference=new D({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypeField=null,this.subtypes=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();let t=null;return t=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await(this._parent?._getSet(e)),this._checkCancelled(e),y(t),this._wset=new i(t._candidates.slice(),t._known.slice(),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(r,s,a,l){const n=[];-1!==s&&void 0===this._featureCache[s]&&n.push(s);const o=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(r,o))return await this._expandPagedSet(r,o,0,0,l),this._getFeatures(r,s,a,l);let u=0;for(let e=r._lastFetchedIndex;e<r._known.length&&(u++,u<=a&&(r._lastFetchedIndex+=1),!(void 0===this._featureCache[r._known[e]]&&(r._known[e]!==s&&n.push(r._known[e]),n.length>=o)));e++);if(0===n.length)return"success";r=new i([],n,r._ordered,null);const h=Math.min(n.length,a);await(this._parent?._getFeatures(r,-1,h,l)),this._checkCancelled(l);const c=[];for(let e=0;e<h;e++){const t=this._parent?._featureFromCache(n[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:n[e]})}for(const i of c){const r=[];for(const e of this.adaptedFields)r[e.field.name]=e.extractValue(i);this._featureCache[i.id]=new e({attributes:r,geometry:t(i.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new r(s.NeverReach)}async _getFilteredSet(e,t,r,s,a){let l=!1;const n=this._reformulateWithoutAdaptions(r);l=n.cannot,r=n.where;let o=!1;if(null!==s){o=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof k)&&!0===s.scanForField(t.field.name)){if(!(t instanceof b)){s=null,o=!1;break}e.push({field:t.field.name,newfield:t.originalField.name})}s&&e.length>0&&(s=s.replaceFields(e))}null!==r?null!==this._extraFilter&&(r=F(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const u=await this._parent._getFilteredSet(e,t,r,s,a);let h;return this._checkCancelled(a),h=!0===l?new i(u._candidates.slice().concat(u._known.slice()),[],!0===o&&u._ordered,this._clonePageDefinition(u.pagesDefinition)):new i(u._candidates.slice(),u._known.slice(),!0===o&&u._ordered,this._clonePageDefinition(u.pagesDefinition)),h}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!==e)for(const r of this.adaptedFields)if(!0===W(e,r.field.name)){const s=r.rewriteSql(e,this);if(!0!==s.rewritten){t.cannot=!0,t.where=null;break}t.where=s.where}return t}async _stat(e,t,r,s,a,i,l){let n=!1,o=this._reformulateWithoutAdaptions(t);if(n=o.cannot,t=o.where,o=this._reformulateWithoutAdaptions(a),n=n||o.cannot,null!==(a=o.where)?null!==this._extraFilter&&(a=F(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const u=await this._parent._stat(e,t,r,s,a,i,l);return!1===u.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:u}async _canDoAggregates(e,t,r,s,a){if(null===this._parent)return!1;for(let n=0;n<e.length;n++)for(const t of this.adaptedFields)if(e[n].toLowerCase()===t.field.name.toLowerCase()&&!(t instanceof k))return!1;const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)return!1;const r=e.clone();r.workingexpr=t.where,i.push(r)}else i.push(e)}const l=this._reformulateWithoutAdaptions(a);return!l.cannot&&(null!==(a=l.where)?null!==this._extraFilter&&(a=F(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,a,i,l,n,o){if(null===this._parent)throw new r(s.NeverReach);const u=[];for(let c=0;c<t.length;c++){const e=t[c];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)throw new r(s.NeverReach);const a=e.clone();a.workingexpr=t.where,u.push(a)}else u.push(e)}const h=this._reformulateWithoutAdaptions(l);if(h.cannot)throw new r(s.NeverReach);return null!==(l=h.where)?null!==this._extraFilter&&(l=F(this._extraFilter,l)):l=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,u,a,i,l,n,o)}}export{R as AdaptedFeatureSet,I as AdaptedField,b as FieldRename,k as OriginalField,L as SqlExpressionAdapted,B as StringToCodeAdapted};
|
|
5
|
+
import e from"../../../Graphic.js";import{cloneGeometry as t}from"../../kernel.js";import{FeatureSetError as r,FeatureSetErrorCodes as s}from"../support/errorsupport.js";import a from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{cloneField as l,FeatureServiceDatabaseType as n,isDate as o,isLuxonDate as u,isArcadeTime as h,isArcadeDate as c,isArcadeDateOnly as d,layerGeometryEsriConstants as p}from"../support/shared.js";import{reformulateWithoutField as f,toWhereClause as g,translateFunctionToDatabaseSpecific as N,convertColumnReferenceToSql as _,makeToday as S,makeSqlFromDateTimeParameter as m,makeTimeString as w,arcadeDateToSqlString as v,arcadeDateOnlyToSqlString as C,convertIntervalToSql as T,combine as F,scanForField as W}from"../support/sqlUtils.js";import{assertIsSome as y}from"../../../core/maybe.js";import{SqlError as A,SqlErrorCodes as E}from"../../../core/sql/errorSupport.js";import x from"../../../core/sql/WhereClause.js";import D from"../../../geometry/SpatialReference.js";class I{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class k extends I{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class b extends I{constructor(e,t,r){super(l(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:f(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class B extends I{constructor(e,t,r){super(e),this.codefield=t,this.lkp=r,this.reverseLkp={};for(const s in r)this.reverseLkp[r[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const r=this.evaluateNodeToWhereClause(e.parseTree,n.Standardised,this.field.name,this.codefield instanceof x?g(this.codefield,n.Standardised):this.codefield,e.parameters);return r.includes(B.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:x.create(r,{fieldsIndex:t._parent.getFieldsIndex(),timeZone:t.dateFieldsTimeZoneDefaultUTC})}}evaluateNodeToWhereClause(e,t,r=null,s=null,a){let i,l,n,p;switch(e.type){case"interval":return T(this.evaluateNodeToWhereClause(e.value,t,r,s,a),e.qualifier,e.op);case"case-expression":{let s=" CASE ";"simple"===e.format&&(s+=this.evaluateNodeToWhereClause(e.operand,t,r,B.BADNESS,a));for(let i=0;i<e.clauses.length;i++)s+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[i].operand,t,r,B.BADNESS,a)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[i].value,t,r,B.BADNESS,a);return null!==e.else&&(s+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,r,B.BADNESS,a)),s+=" END ",s}case"parameter":{const r=a[e.value.toLowerCase()];if("string"==typeof r)return"'"+r.toString().replaceAll("'","''")+"'";if(o(r))return m(r,t);if(u(r))return m(r,t);if(h(r))return w(r,t);if(c(r))return v(r,t);if(d(r))return C(r,t);if(Array.isArray(r)){const e=[];for(let s=0;s<r.length;s++)"string"==typeof r[s]?e.push("'"+r[s].toString().replaceAll("'","''")+"'"):o(r[s])||u(r[s])?e.push(m(r[s],t)):h(r[s])?e.push(w(r[s],t)):c(r[s])?e.push(v(r[s],t)):d(r[s])?e.push(C(r[s],t)):e.push(r[s].toString());return e}return r.toString()}case"expression-list":l=[];for(const i of e.value)l.push(this.evaluateNodeToWhereClause(i,t,r,s,a));return l;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,r,B.BADNESS,a)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" AND "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" OR "+this.evaluateNodeToWhereClause(e.right,t,r,s,a)+") ";case"IS":if("null"!==e.right.type)throw new A(E.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new A(E.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IS NOT NULL )";case"IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+i.join(",")+")) "}return p=this.evaluateNodeToWhereClause(e.right,t,r,s,a),Array.isArray(p)?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+p.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" IN ("+p+")) ";case"NOT IN":if(i=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const i=[];let l=!0;for(const t of e.right.value){if("string"!==t.type){l=!1;break}if(void 0===this.lkp[t.value]){l=!1;break}i.push(this.lkp[t.value].toString())}if(l)return" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return i=this.evaluateNodeToWhereClause(e.right,t,r,s,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+i.join(",")+")) "}return p=this.evaluateNodeToWhereClause(e.right,t,r,s,a),Array.isArray(p)?" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+p.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,s,a)+" NOT IN ("+p+")) ";case"BETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"NOTBETWEEN":return n=this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)," ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" NOT BETWEEN "+n[0]+" AND "+n[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") ";case"<>":case"=":if("column-reference"===e.left.type&&"string"===e.right.type){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&void 0!==this.lkp[e.right.value.toString()])return" ("+s+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if("column-reference"===e.right.type&&"string"===e.left.type&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+s+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,t,r,B.BADNESS,a)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,r,B.BADNESS,a)+") "}case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":return`timestamp '${e.value}'`;case"date":return`date '${e.value}'`;case"time":return`time '${e.value}'`;case"number":return e.value.toString();case"current-time":return S(e.mode,t);case"current-user":return"CURRENT_USER";case"column-reference":return r&&r.toLowerCase()===e.column.toLowerCase()?"("+s+")":_(e.column);case"data-type":return e.value;case"function":{const s=this.evaluateNodeToWhereClause(e.args,t,r,B.BADNESS,a);return N(e.name,s,t)}}throw new A(E.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof x?this.reverseLkp[x.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}}B.BADNESS="_!!!_BAD_LKP_!!!!";class L extends I{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:f(e,this.field.name,g(this._sql,n.Standardised),t.getFieldsIndex())}}extractValue(e){return x.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}class R extends a{static findField(e,t){for(const r of e)if(r.name.toLowerCase()===t.toString().toLowerCase())return r;return null}constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=[],this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}_initialiseFeatureSet(){null!==this._parent?(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.spatialReference=new D({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypeField=null,this.subtypes=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();let t=null;return t=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await(this._parent?._getSet(e)),this._checkCancelled(e),y(t),this._wset=new i(t._candidates.slice(),t._known.slice(),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(r,s,a,l){const n=[];-1!==s&&void 0===this._featureCache[s]&&n.push(s);const o=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(r,o))return await this._expandPagedSet(r,o,0,0,l),this._getFeatures(r,s,a,l);let u=0;for(let e=r._lastFetchedIndex;e<r._known.length&&(u++,u<=a&&(r._lastFetchedIndex+=1),!(void 0===this._featureCache[r._known[e]]&&(r._known[e]!==s&&n.push(r._known[e]),n.length>=o)));e++);if(0===n.length)return"success";r=new i([],n,r._ordered,null);const h=Math.min(n.length,a);await(this._parent?._getFeatures(r,-1,h,l)),this._checkCancelled(l);const c=[];for(let e=0;e<h;e++){const t=this._parent?._featureFromCache(n[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:n[e]})}for(const i of c){const r=[];for(const e of this.adaptedFields)r[e.field.name]=e.extractValue(i);this._featureCache[i.id]=new e({attributes:r,geometry:t(i.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new r(s.NeverReach)}async _getFilteredSet(e,t,r,s,a){let l=!1;const n=this._reformulateWithoutAdaptions(r);l=n.cannot,r=n.where;let o=!1;if(null!==s){o=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof k)&&!0===s.scanForField(t.field.name)){if(!(t instanceof b)){s=null,o=!1;break}e.push({field:t.field.name,newfield:t.originalField.name})}s&&e.length>0&&(s=s.replaceFields(e))}null!==r?null!==this._extraFilter&&(r=F(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const u=await this._parent._getFilteredSet(e,t,r,s,a);let h;return this._checkCancelled(a),h=!0===l?new i(u._candidates.slice().concat(u._known.slice()),[],!0===o&&u._ordered,this._clonePageDefinition(u.pagesDefinition)):new i(u._candidates.slice(),u._known.slice(),!0===o&&u._ordered,this._clonePageDefinition(u.pagesDefinition)),h}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!==e)for(const r of this.adaptedFields)if(!0===W(e,r.field.name)){const s=r.rewriteSql(e,this);if(!0!==s.rewritten){t.cannot=!0,t.where=null;break}t.where=s.where}return t}async _stat(e,t,r,s,a,i,l){let n=!1,o=this._reformulateWithoutAdaptions(t);if(n=o.cannot,t=o.where,o=this._reformulateWithoutAdaptions(a),n=n||o.cannot,null!==(a=o.where)?null!==this._extraFilter&&(a=F(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const u=await this._parent._stat(e,t,r,s,a,i,l);return!1===u.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:u}async _canDoAggregates(e,t,r,s,a){if(null===this._parent)return!1;for(let n=0;n<e.length;n++)for(const t of this.adaptedFields)if(e[n].toLowerCase()===t.field.name.toLowerCase()&&!(t instanceof k))return!1;const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)return!1;const r=e.clone();r.workingexpr=t.where,i.push(r)}else i.push(e)}const l=this._reformulateWithoutAdaptions(a);return!l.cannot&&(null!==(a=l.where)?null!==this._extraFilter&&(a=F(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,a,i,l,n,o){if(null===this._parent)throw new r(s.NeverReach);const u=[];for(let c=0;c<t.length;c++){const e=t[c];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)throw new r(s.NeverReach);const a=e.clone();a.workingexpr=t.where,u.push(a)}else u.push(e)}const h=this._reformulateWithoutAdaptions(l);if(h.cannot)throw new r(s.NeverReach);return null!==(l=h.where)?null!==this._extraFilter&&(l=F(this._extraFilter,l)):l=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,u,a,i,l,n,o)}}export{R as AdaptedFeatureSet,I as AdaptedField,b as FieldRename,k as OriginalField,L as SqlExpressionAdapted,B as StringToCodeAdapted};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{FeatureSetError as e,FeatureSetErrorCodes as t}from"../support/errorsupport.js";import s from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{layerGeometryEsriConstants as r,IdState as n}from"../support/shared.js";import{combine as a}from"../support/sqlUtils.js";import{isPromiseLike as l}from"../../../core/promiseUtils.js";import
|
|
5
|
+
import{FeatureSetError as e,FeatureSetErrorCodes as t}from"../support/errorsupport.js";import s from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{layerGeometryEsriConstants as r,IdState as n}from"../support/shared.js";import{combine as a}from"../support/sqlUtils.js";import{isPromiseLike as l}from"../../../core/promiseUtils.js";import h from"../../../core/sql/WhereClause.js";import u from"../../../geometry/SpatialReference.js";class c extends s{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.actions.AttributeFilter",this._maxProcessing=1e3,this._parent=e.parentfeatureset,e.whereclause instanceof h?(this._whereclause=e.whereclause,this._whereClauseFunction=null):(this._whereClauseFunction=e.whereclause,this._whereclause=null)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(),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 u({wkid:4326}),this.geometryType=r.point)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._parent._getFilteredSet("",null,this._whereclause,null,e);return this._checkCancelled(e),null!==this._whereClauseFunction?this._wset=new i(t._candidates.slice().concat(t._known.slice()),[],t._ordered,this._clonePageDefinition(t.pagesDefinition)):this._wset=new i(t._candidates.slice(),t._known.slice(),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){let t=this._parent?._isInFeatureSet(e);return t===n.NotInFeatureSet?t:(t=this._idstates[e],void 0===t?n.Unknown:t)}_getFeature(e,t,s){return this._parent._getFeature(e,t,s)}_getFeatures(e,t,s,i){return this._parent._getFeatures(e,t,s,i)}_featureFromCache(e){return this._parent._featureFromCache(e)}executeWhereClause(e){return this._whereclause?.testFeature(e)??!1}async executeWhereClauseDeferred(e){if(null!==this._whereClauseFunction){const t=this._whereClauseFunction(e);return l(t),t}return this.executeWhereClause(e)}async _fetchAndRefineFeatures(e,t,s){const r=new i([],e,!1,null),a=Math.min(t,e.length);if(await(this._parent?._getFeatures(r,-1,a,s)),this._checkCancelled(s),null==this._whereClauseFunction){for(let t=0;t<a;t++){const s=this._parent?._featureFromCache(e[t]);!0===this.executeWhereClause(s)?this._idstates[e[t]]=n.InFeatureSet:this._idstates[e[t]]=n.NotInFeatureSet}return"success"}const l=[];for(let i=0;i<a;i++){const t=this._parent?._featureFromCache(e[i]);l.push(await this.executeWhereClauseDeferred(t))}for(let i=0;i<t;i++)!0===l[i]?this._idstates[e[i]]=n.InFeatureSet:this._idstates[e[i]]=n.NotInFeatureSet;return"success"}async _getFilteredSet(e,t,s,r,n){null!==this._whereClauseFunction||(null!==s?null!==this._whereclause&&(s=a(this._whereclause,s)):s=this._whereclause),await this._ensureLoaded();const l=await this._parent._getFilteredSet(e,t,s,r,n);let h;return this._checkCancelled(n),h=null!==this._whereClauseFunction?new i(l._candidates.slice().concat(l._known.slice()),[],l._ordered,this._clonePageDefinition(l.pagesDefinition)):new i(l._candidates.slice(),l._known.slice(),l._ordered,this._clonePageDefinition(l.pagesDefinition)),h}async _stat(e,t,s,i,r,n,l){if(null!==this._whereClauseFunction)return null===r&&""===s&&null===i?this._manualStat(e,t,n,l):{calculated:!1};let h=this._whereclause;null!==r&&null!==this._whereclause&&(h=a(this._whereclause,r));const u=await this._parent._stat(e,t,s,i,h,n,l);return!1===u.calculated?null===r&&""===s&&null===i?this._manualStat(e,t,n,l):{calculated:!1}:u}async _canDoAggregates(e,t,s,i,r){return null===this._whereClauseFunction&&(null!==r?null!==this._whereclause&&(r=a(this._whereclause,r)):r=this._whereclause,null!==this._parent&&this._parent._canDoAggregates(e,t,s,i,r))}async _getAggregatePagesDataSourceDefinition(s,i,r,n,l,h,u){if(null===this._parent)throw new e(t.NeverReach);return null!==l?null!==this._whereclause&&(l=a(this._whereclause,l)):l=this._whereclause,this._parent._getAggregatePagesDataSourceDefinition(s,i,r,n,l,h,u)}static registerAction(){s._featuresetFunctions.filter=function(e){if("function"==typeof e)return new c({parentfeatureset:this,whereclause:e});let t=null;return e instanceof h&&(t=e),new c({parentfeatureset:this,whereclause:t})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{c 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.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{X as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as o,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import w from"../support/StatsField.js";import{createMD5Hash as F,outputTypes as I}from"../../../core/MD5.js";import{aggregateFunction as S}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as j}from"../../../core/sql/TimeOnly.js";import{WhereClause as k}from"../../../core/sql/WhereClause.js";import C from"../../../geometry/SpatialReference.js";import A from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class O extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new w;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new C({wkid:4326});this.fields=[];const a=new w;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=k.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new A;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new o(l.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new A;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new A;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new o(l.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,o){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(o),l=!0===d.nowhereclause?new u(n._candidates.slice().concat(n._known.slice()),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(),n._known.slice(),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),l}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const o=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(o){a(o)}}_calculateFieldStat(e,t,i){const s=[];for(const n of e.features)if(null!==t.workingexpr){const e=t.workingexpr.calculateValue(n);null!==e&&(e instanceof x||e instanceof j?s.push(e.toNumber()):e instanceof D?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=S(t.typeofstat,[s])}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:k.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return F(t,I.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
|
|
5
|
+
import e from"../../../Graphic.js";import{X as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as o,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import w from"../support/StatsField.js";import{createMD5Hash as F,outputTypes as I}from"../../../core/MD5.js";import{aggregateFunction as S}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as j}from"../../../core/sql/TimeOnly.js";import k from"../../../core/sql/WhereClause.js";import C from"../../../geometry/SpatialReference.js";import A from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class O extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new w;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof k?i.expression:k.create(i.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new C({wkid:4326});this.fields=[];const a=new w;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=k.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new A;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new o(l.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new A;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new A;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new o(l.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,o){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(o),l=!0===d.nowhereclause?new u(n._candidates.slice().concat(n._known.slice()),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(),n._known.slice(),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),l}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const o=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(o){a(o)}}_calculateFieldStat(e,t,i){const s=[];for(const n of e.features)if(null!==t.workingexpr){const e=t.workingexpr.calculateValue(n);null!==e&&(e instanceof x||e instanceof j?s.push(e.toNumber()):e instanceof D?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=S(t.typeofstat,[s])}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:k.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return F(t,I.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"./cache.js";import{FeatureSetError as t,FeatureSetErrorCodes as n}from"./errorsupport.js";import s 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 f,sum as _,variance as p,stdev as m,mean as g,distinct as y,count as F}from"./stats.js";import{isPromiseLike as I}from"../../../core/promiseUtils.js";import{WhereClause as T}from"../../../core/sql/WhereClause.js";import{union as b,geodesicArea as w,planarArea as S,geodesicLength as D,planarLength as x}from"../../../geometry/geometryEngineAsync.js";import P from"../../../geometry/SpatialReference.js";import k from"../../../layers/support/FieldsIndex.js";class C{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=Object.create(null),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(),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 P({wkid:4326}),this.geometryType=r.point)}getField(e,t){let n;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(n=t),!!n)))),n}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=k.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(n.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,n,s,i){return null!==this._parent&&this._parent._canDoAggregates(e,t,n,s,i)}async _getAggregatePagesDataSourceDefinition(e,s,i,a,r,l,u){if(null===this._parent)throw new t(n.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,s,i,a,r,l,u)}async _getAgregagtePhysicalPage(e,s,i){if(null===this._parent)throw new t(n.NeverReach);return this._parent._getAgregagtePhysicalPage(e,s,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(n.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(n.NotImplemented)}async _getFeature(e,s,i){if(this._checkCancelled(i),void 0!==this._featureFromCache(s))return this._featureFromCache(s);if(await this._getFeatures(e,s,this._maxProcessingRate(),i),this._checkCancelled(i),void 0!==this._featureFromCache(s))return this._featureFromCache(s);throw new t(n.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const n=new i([],e,!1,null),s=[];await this._getFeatures(n,-1,e.length,t),this._checkCancelled(t);for(const i of e)void 0!==this._featureFromCache(i)&&s.push(this._featureFromCache(i));return s}async _getFeatures(e,t,n,s){return"success"}_getFilteredSet(e,s,i,a,r){throw new t(n.NotImplemented)}async _refineSetBlock(e,t,n){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,n),this._refineSetBlock(e,t,n);this._checkCancelled(n);const s=e._candidates.length;this._refineKnowns(e,t);let i=s-e._candidates.length;if(0===e._candidates.length)return e;if(i>=t)return e;if(await this._refineIfParentKnown(e,t-i,n),this._checkCancelled(n),this._refineKnowns(e,t-i),i=s-e._candidates.length,i<t&&e._candidates.length>0){const s=t-i,a=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(a,a.length>s?s:e._candidates.length,n),this._checkCancelled(n),this._refineKnowns(e,t-i),e}return e}_fetchAndRefineFeatures(e,t,n){return null}_prepareFetchAndRefineSet(e){const t=[];for(let n=0;n<e.length;n++)this._isPhysicalFeature(e[n])&&t.push(e[n]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let n=0,s=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),n+=1):(e._known.push(e._candidates[a]),n+=1),null===s?s={start:a,end:a}:s.end===a-1?s.end=a:(i.push(s),s={start:a,end:a});else if(h===l.NotInFeatureSet)null===s?s={start:a,end:a}:s.end===a-1?s.end=a:(i.push(s),s={start:a,end:a}),n+=1;else if(h===l.Unknown&&(n+=1,!0===e._ordered))break;if(n>=t)break}null!==s&&i.push(s);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,n){const s=new i([],[],e._ordered,null);return s._candidates=e._candidates.slice(),this._parent._refineSetBlock(s,t,n)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let n=0;for(let s=e._lastFetchedIndex;s<e._known.length;s++){if("GETPAGES"===e._known[s])return!0;if(void 0===this._featureCache[e._known[s]]&&(n+=1,n>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let n=0;for(let s=0;s<e._candidates.length;s++){if("GETPAGES"===e._candidates[s])return!0;if(n+=1,n>=t)break}return!1}async _expandPagedSet(e,s,i,a,r){if(null===this._parent)throw new t(n.NotImplemented);return this._parent._expandPagedSet(e,s,i,a,r)}async _expandPagedSetFeatureSet(e,t,n,s,i){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(s=1),0===s&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(s=2),0===s)return"finished";const a=await this._getPage(e,s,i);return n+a<t?this._expandPagedSet(e,t,n+a,0,i):"success"}async _getPage(e,t,n){const s=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){s.length=s.length-1;let t=0;for(let i=0;i<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+i>=e.pagesDefinition.internal.set.length);i++)s[s.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+i],t++;e.pagesDefinition.resultOffset+=t;let n=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(n=!0),!1===n&&s.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,n),this._getPage(e,t,n)}_getPhysicalPage(e,t,n){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,n,s){await this._ensureLoaded();let i=await this._stat(e,t,"",null,null,n,s);return!1===i.calculated&&(i=await this._manualStat(e,t,n,s)),i.result}async _manualStat(e,t,n,s){let i=null;switch(e.toLowerCase()){case"count":return i=await F(this,s),{calculated:!0,result:i};case"distinct":return i=await y(this,t,n,s),{calculated:!0,result:i};case"avg":case"mean":return i=await g(this,t,s),{calculated:!0,result:i};case"stdev":return i=await m(this,t,s),{calculated:!0,result:i};case"variance":return i=await p(this,t,s),{calculated:!0,result:i};case"sum":return i=await _(this,t,s),{calculated:!0,result:i};case"min":return i=await f(this,t,s),{calculated:!0,result:i};case"max":return i=await d(this,t,s),{calculated:!0,result:i};default:return{calculated:!0,result:0}}}async _stat(e,t,n,s,i,a,r){const l=await this._parent._stat(e,t,n,s,i,a,r);return!1===l.calculated?null===i&&""===n&&null===s?this._manualStat(e,t,a,r):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),n=[];return new Promise(((e,s)=>{this._unionShapeInBatches(n,t,e,s)}))}_unionAllGeom(e){return new Promise(((t,n)=>{const s=this.iterator(this._defaultTracker(e)),i=[];this._unionShapeInBatches(i,s,t,n)}))}_unionShapeInBatches(e,t,n,s){t.next().then((i=>{try{null!==i&&null!==i.geometry&&e.push(i.geometry),e.length>30||null===i&&e.length>1?b(e).then((a=>{try{null===i?n(a):(e=[a],this._unionShapeInBatches(e,t,n,s))}catch(r){s(r)}}),s):null===i?1===e.length?n(e[0]):n(null):this._unionShapeInBatches(e,t,n,s)}catch(a){s(a)}}),s)}iterator(e){return new s(this,e)}intersection(e,t=!1){return C._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,n=!0){return C._featuresetFunctions.difference.bind(this)(e,t,n)}symmetricDifference(e,t=!1,n=!0){return C._featuresetFunctions.symmetricDifference.bind(this)(e,t,n)}morphShape(e,t,n="unknown",s=null){return C._featuresetFunctions.morphShape.bind(this)(e,t,n,s)}morphShapeAndAttributes(e,t,n="unknown"){return C._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,n)}union(e,t=!1){return C._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return C._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return C._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return C._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return C._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return C._featuresetFunctions.relate.bind(this)(e,t)}within(e){return C._featuresetFunctions.within.bind(this)(e)}touches(e){return C._featuresetFunctions.touches.bind(this)(e)}top(e){return C._featuresetFunctions.top.bind(this)(e)}crosses(e){return C._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,n,s=!0){return C._featuresetFunctions.buffer.bind(this)(e,t,n,s)}filter(e,t=null){return C._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return C._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return C._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return C._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,n){return new Promise(((s,i)=>{this._reduceImpl(this.iterator(this._defaultTracker(n)),e,t,0,s,i,0)}))}_reduceImpl(e,t,n,s,i,a,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._reduceImpl(e,t,n,s,i,a,r)}));e.next().then((l=>{try{if(null===l)i(n);else{const u=t(n,l,s,this);I(u)?u.then((n=>{this._reduceImpl(e,t,n,s+1,i,a,r)}),a):this._reduceImpl(e,t,u,s+1,i,a,r)}}catch(u){a(u)}}),a)}catch(l){a(l)}}removeField(e){return C._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,n=null){return C._featuresetFunctions.addField.bind(this)(e,t,n)}sumArea(e,t=!1,n){const s=u(e);return this.reduce(((e,n)=>null===n.geometry?0:t?w(n.geometry,s).then((t=>e+t)):S(n.geometry,s).then((t=>e+t))),0,n)}sumLength(e,t=!1,n){const s=h(e);return this.reduce(((e,n)=>null===n.geometry?0:t?D(n.geometry,s).then((t=>e+t)):x(n.geometry,s).then((t=>e+t))),0,n)}async distinct(e,t=1e3,n=null,s){await this.load();const i=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(i,n),this.calculateStatistic("distinct",i,t,this._defaultTracker(s))}async min(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("min",s,-1,this._defaultTracker(n))}async max(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("max",s,-1,this._defaultTracker(n))}async avg(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("avg",s,-1,this._defaultTracker(n))}async sum(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("sum",s,-1,this._defaultTracker(n))}async stdev(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("stdev",s,-1,this._defaultTracker(n))}async variance(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("variance",s,-1,this._defaultTracker(n))}async count(e){return await this.load(),this.calculateStatistic("count",T.create("1",{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((n,s)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,n,s,0)}))}_forEachImpl(e,t,n,s,i,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._forEachImpl(e,t,n,s,i,a)}),0);e.next().then((r=>{try{if(null===r)s(n);else{const l=t(r);null==l?this._forEachImpl(e,t,n,s,i,a):I(l)?l.then((()=>{try{this._forEachImpl(e,t,n,s,i,a)}catch(r){i(r)}}),i):this._forEachImpl(e,t,n,s,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 n=0;n<this.fields.length;n++)t.layerDefinition.fields.push(o(this.fields[n]));return this.reduce(((e,n)=>{const s={geometry:n.geometry?.toJSON(),attributes:{}};for(const t in n.attributes)s.attributes[t]=n.attributes[t];return t.featureSet.features.push(s),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,n,s,i){return this._parent.queryAttachments(e,t,n,s,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,n)=>{const s={geometry:n.geometry?n.geometry.toJSON():null,attributes:n.attributes};return null!==s.geometry&&s.geometry.spatialReference&&delete s.geometry.spatialReference,e.push(s),1}),0,t);const n=this.schema();return n.features=e,n.spatialReference=this.spatialReference.toJSON(),JSON.stringify(n)}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 n=[];await this.reduce(((e,s)=>{const i={geometry:s.geometry?!0===t?.keepGeometryType?s.geometry:s.geometry.toJSON():null,attributes:s.attributes};return null!==i.geometry&&i.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete i.geometry.spatialReference,n.push(i),1}),0,e);const s=this.schema();return s.features=n,s.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),s}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 n={};for(const e in t)n[e.toLowerCase()]=t[e];e.parameters=n}}C._featuresetFunctions={};export{C as default};
|
|
5
|
+
import e from"./cache.js";import{FeatureSetError as t,FeatureSetErrorCodes as n}from"./errorsupport.js";import s 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 f,sum as _,variance as p,stdev as m,mean as g,distinct as y,count as F}from"./stats.js";import{isPromiseLike as I}from"../../../core/promiseUtils.js";import T from"../../../core/sql/WhereClause.js";import{union as b,geodesicArea as w,planarArea as S,geodesicLength as D,planarLength as x}from"../../../geometry/geometryEngineAsync.js";import P from"../../../geometry/SpatialReference.js";import k from"../../../layers/support/FieldsIndex.js";class C{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=Object.create(null),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(),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 P({wkid:4326}),this.geometryType=r.point)}getField(e,t){let n;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(n=t),!!n)))),n}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=k.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(n.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,n,s,i){return null!==this._parent&&this._parent._canDoAggregates(e,t,n,s,i)}async _getAggregatePagesDataSourceDefinition(e,s,i,a,r,l,u){if(null===this._parent)throw new t(n.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,s,i,a,r,l,u)}async _getAgregagtePhysicalPage(e,s,i){if(null===this._parent)throw new t(n.NeverReach);return this._parent._getAgregagtePhysicalPage(e,s,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(n.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(n.NotImplemented)}async _getFeature(e,s,i){if(this._checkCancelled(i),void 0!==this._featureFromCache(s))return this._featureFromCache(s);if(await this._getFeatures(e,s,this._maxProcessingRate(),i),this._checkCancelled(i),void 0!==this._featureFromCache(s))return this._featureFromCache(s);throw new t(n.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const n=new i([],e,!1,null),s=[];await this._getFeatures(n,-1,e.length,t),this._checkCancelled(t);for(const i of e)void 0!==this._featureFromCache(i)&&s.push(this._featureFromCache(i));return s}async _getFeatures(e,t,n,s){return"success"}_getFilteredSet(e,s,i,a,r){throw new t(n.NotImplemented)}async _refineSetBlock(e,t,n){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,n),this._refineSetBlock(e,t,n);this._checkCancelled(n);const s=e._candidates.length;this._refineKnowns(e,t);let i=s-e._candidates.length;if(0===e._candidates.length)return e;if(i>=t)return e;if(await this._refineIfParentKnown(e,t-i,n),this._checkCancelled(n),this._refineKnowns(e,t-i),i=s-e._candidates.length,i<t&&e._candidates.length>0){const s=t-i,a=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(a,a.length>s?s:e._candidates.length,n),this._checkCancelled(n),this._refineKnowns(e,t-i),e}return e}_fetchAndRefineFeatures(e,t,n){return null}_prepareFetchAndRefineSet(e){const t=[];for(let n=0;n<e.length;n++)this._isPhysicalFeature(e[n])&&t.push(e[n]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let n=0,s=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),n+=1):(e._known.push(e._candidates[a]),n+=1),null===s?s={start:a,end:a}:s.end===a-1?s.end=a:(i.push(s),s={start:a,end:a});else if(h===l.NotInFeatureSet)null===s?s={start:a,end:a}:s.end===a-1?s.end=a:(i.push(s),s={start:a,end:a}),n+=1;else if(h===l.Unknown&&(n+=1,!0===e._ordered))break;if(n>=t)break}null!==s&&i.push(s);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,n){const s=new i([],[],e._ordered,null);return s._candidates=e._candidates.slice(),this._parent._refineSetBlock(s,t,n)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let n=0;for(let s=e._lastFetchedIndex;s<e._known.length;s++){if("GETPAGES"===e._known[s])return!0;if(void 0===this._featureCache[e._known[s]]&&(n+=1,n>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let n=0;for(let s=0;s<e._candidates.length;s++){if("GETPAGES"===e._candidates[s])return!0;if(n+=1,n>=t)break}return!1}async _expandPagedSet(e,s,i,a,r){if(null===this._parent)throw new t(n.NotImplemented);return this._parent._expandPagedSet(e,s,i,a,r)}async _expandPagedSetFeatureSet(e,t,n,s,i){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(s=1),0===s&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(s=2),0===s)return"finished";const a=await this._getPage(e,s,i);return n+a<t?this._expandPagedSet(e,t,n+a,0,i):"success"}async _getPage(e,t,n){const s=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){s.length=s.length-1;let t=0;for(let i=0;i<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+i>=e.pagesDefinition.internal.set.length);i++)s[s.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+i],t++;e.pagesDefinition.resultOffset+=t;let n=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(n=!0),!1===n&&s.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,n),this._getPage(e,t,n)}_getPhysicalPage(e,t,n){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,n,s){await this._ensureLoaded();let i=await this._stat(e,t,"",null,null,n,s);return!1===i.calculated&&(i=await this._manualStat(e,t,n,s)),i.result}async _manualStat(e,t,n,s){let i=null;switch(e.toLowerCase()){case"count":return i=await F(this,s),{calculated:!0,result:i};case"distinct":return i=await y(this,t,n,s),{calculated:!0,result:i};case"avg":case"mean":return i=await g(this,t,s),{calculated:!0,result:i};case"stdev":return i=await m(this,t,s),{calculated:!0,result:i};case"variance":return i=await p(this,t,s),{calculated:!0,result:i};case"sum":return i=await _(this,t,s),{calculated:!0,result:i};case"min":return i=await f(this,t,s),{calculated:!0,result:i};case"max":return i=await d(this,t,s),{calculated:!0,result:i};default:return{calculated:!0,result:0}}}async _stat(e,t,n,s,i,a,r){const l=await this._parent._stat(e,t,n,s,i,a,r);return!1===l.calculated?null===i&&""===n&&null===s?this._manualStat(e,t,a,r):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),n=[];return new Promise(((e,s)=>{this._unionShapeInBatches(n,t,e,s)}))}_unionAllGeom(e){return new Promise(((t,n)=>{const s=this.iterator(this._defaultTracker(e)),i=[];this._unionShapeInBatches(i,s,t,n)}))}_unionShapeInBatches(e,t,n,s){t.next().then((i=>{try{null!==i&&null!==i.geometry&&e.push(i.geometry),e.length>30||null===i&&e.length>1?b(e).then((a=>{try{null===i?n(a):(e=[a],this._unionShapeInBatches(e,t,n,s))}catch(r){s(r)}}),s):null===i?1===e.length?n(e[0]):n(null):this._unionShapeInBatches(e,t,n,s)}catch(a){s(a)}}),s)}iterator(e){return new s(this,e)}intersection(e,t=!1){return C._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,n=!0){return C._featuresetFunctions.difference.bind(this)(e,t,n)}symmetricDifference(e,t=!1,n=!0){return C._featuresetFunctions.symmetricDifference.bind(this)(e,t,n)}morphShape(e,t,n="unknown",s=null){return C._featuresetFunctions.morphShape.bind(this)(e,t,n,s)}morphShapeAndAttributes(e,t,n="unknown"){return C._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,n)}union(e,t=!1){return C._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return C._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return C._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return C._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return C._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return C._featuresetFunctions.relate.bind(this)(e,t)}within(e){return C._featuresetFunctions.within.bind(this)(e)}touches(e){return C._featuresetFunctions.touches.bind(this)(e)}top(e){return C._featuresetFunctions.top.bind(this)(e)}crosses(e){return C._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,n,s=!0){return C._featuresetFunctions.buffer.bind(this)(e,t,n,s)}filter(e,t=null){return C._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return C._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return C._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return C._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,n){return new Promise(((s,i)=>{this._reduceImpl(this.iterator(this._defaultTracker(n)),e,t,0,s,i,0)}))}_reduceImpl(e,t,n,s,i,a,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._reduceImpl(e,t,n,s,i,a,r)}));e.next().then((l=>{try{if(null===l)i(n);else{const u=t(n,l,s,this);I(u)?u.then((n=>{this._reduceImpl(e,t,n,s+1,i,a,r)}),a):this._reduceImpl(e,t,u,s+1,i,a,r)}}catch(u){a(u)}}),a)}catch(l){a(l)}}removeField(e){return C._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,n=null){return C._featuresetFunctions.addField.bind(this)(e,t,n)}sumArea(e,t=!1,n){const s=u(e);return this.reduce(((e,n)=>null===n.geometry?0:t?w(n.geometry,s).then((t=>e+t)):S(n.geometry,s).then((t=>e+t))),0,n)}sumLength(e,t=!1,n){const s=h(e);return this.reduce(((e,n)=>null===n.geometry?0:t?D(n.geometry,s).then((t=>e+t)):x(n.geometry,s).then((t=>e+t))),0,n)}async distinct(e,t=1e3,n=null,s){await this.load();const i=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(i,n),this.calculateStatistic("distinct",i,t,this._defaultTracker(s))}async min(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("min",s,-1,this._defaultTracker(n))}async max(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("max",s,-1,this._defaultTracker(n))}async avg(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("avg",s,-1,this._defaultTracker(n))}async sum(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("sum",s,-1,this._defaultTracker(n))}async stdev(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("stdev",s,-1,this._defaultTracker(n))}async variance(e,t=null,n){await this.load();const s=T.create(e,{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC});return v(s,t),this.calculateStatistic("variance",s,-1,this._defaultTracker(n))}async count(e){return await this.load(),this.calculateStatistic("count",T.create("1",{fieldsIndex:this.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((n,s)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,n,s,0)}))}_forEachImpl(e,t,n,s,i,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._forEachImpl(e,t,n,s,i,a)}),0);e.next().then((r=>{try{if(null===r)s(n);else{const l=t(r);null==l?this._forEachImpl(e,t,n,s,i,a):I(l)?l.then((()=>{try{this._forEachImpl(e,t,n,s,i,a)}catch(r){i(r)}}),i):this._forEachImpl(e,t,n,s,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 n=0;n<this.fields.length;n++)t.layerDefinition.fields.push(o(this.fields[n]));return this.reduce(((e,n)=>{const s={geometry:n.geometry?.toJSON(),attributes:{}};for(const t in n.attributes)s.attributes[t]=n.attributes[t];return t.featureSet.features.push(s),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,n,s,i){return this._parent.queryAttachments(e,t,n,s,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,n)=>{const s={geometry:n.geometry?n.geometry.toJSON():null,attributes:n.attributes};return null!==s.geometry&&s.geometry.spatialReference&&delete s.geometry.spatialReference,e.push(s),1}),0,t);const n=this.schema();return n.features=e,n.spatialReference=this.spatialReference.toJSON(),JSON.stringify(n)}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 n=[];await this.reduce(((e,s)=>{const i={geometry:s.geometry?!0===t?.keepGeometryType?s.geometry:s.geometry.toJSON():null,attributes:s.attributes};return null!==i.geometry&&i.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete i.geometry.spatialReference,n.push(i),1}),0,e);const s=this.schema();return s.features=n,s.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),s}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 n={};for(const e in t)n[e.toLowerCase()]=t[e];e.parameters=n}}C._featuresetFunctions={};export{C 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.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{FeatureServiceDatabaseType as e}from"./shared.js";import{toWhereClauseFromTree as t}from"./sqlUtils.js";import{SqlError as r,SqlErrorCodes as n}from"../../../core/sql/errorSupport.js";import
|
|
5
|
+
import{FeatureServiceDatabaseType as e}from"./shared.js";import{toWhereClauseFromTree as t}from"./sqlUtils.js";import{SqlError as r,SqlErrorCodes as n}from"../../../core/sql/errorSupport.js";import i from"../../../core/sql/WhereClause.js";function s(s){if("function"===s.parseTree.type){if(0===s.parseTree.args.value.length)return{name:s.parseTree.name,expr:null};if(s.parseTree.args.value.length>1)throw new r(n.MissingStatisticParameters);const a=i.create(t(s.parseTree.args.value[0],e.Standardised,s.parameters),{fieldsIndex:s.fieldsIndex,timeZone:s.timeZone,currentUser:s.currentUser});return{name:s.parseTree.name,expr:a}}return null}class a{constructor(){this.field="",this.tofieldname="",this.typeofstat="MIN",this.workingexpr=null}clone(){const e=new a;return e.field=this.field,e.tofieldname=this.tofieldname,e.typeofstat=this.typeofstat,e.workingexpr=this.workingexpr,e}static parseStatField(e,t,o,l){const f=new a;f.field=e;const u=i.create(t,{fieldsIndex:o,timeZone:l}),p=s(u);if(null===p)throw new r(n.UnsupportedSqlFunction,{function:""});const c=p.name.toUpperCase().trim();if("MIN"===c){if(f.typeofstat="MIN",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:"min"})}else if("MAX"===c){if(f.typeofstat="MAX",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:"max"})}else if("COUNT"===c)f.typeofstat="COUNT",f.workingexpr=p.expr;else if("STDEV"===c){if(f.typeofstat="STDDEV",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:"stdev"})}else if("SUM"===c){if(f.typeofstat="SUM",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:"sum"})}else if("MEAN"===c){if(f.typeofstat="AVG",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:c})}else if("AVG"===c){if(f.typeofstat="AVG",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:"avg"})}else{if("VAR"!==c)throw new r(n.UnsupportedSqlFunction,{function:c});if(f.typeofstat="VAR",f.workingexpr=p.expr,null===u)throw new r(n.InvalidFunctionParameters,{function:"var"})}return f}toStatisticsName(){switch(this.typeofstat.toUpperCase()){case"MIN":return"min";case"MAX":return"max";case"SUM":return"sum";case"COUNT":default:return"count";case"VAR":return"var";case"STDDEV":return"stddev";case"AVG":return"avg"}}}export{a 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.32/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../../ArcadeDate.js";import{FeatureServiceDatabaseType as r,isDate as t,isLuxonDate as a,isArcadeTime as s,isArcadeDate as n,isArcadeDateOnly as c}from"./shared.js";import{SqlError as i,SqlErrorCodes as o}from"../../../core/sql/errorSupport.js";import{TimeOnly as u}from"../../../core/sql/TimeOnly.js";import{WhereClause as l}from"../../../core/sql/WhereClause.js";import{DateTime as d}from"luxon";function f(e,r){return y(e?.parseTree,r,e?.parameters)}function m(e,r,t){return y(e,r,t)}function p(e,t,a,s){const n=y(e.parseTree,r.Standardised,e.parameters,t,a);return l.create(n,{fieldsIndex:s,timeZone:e.timeZone,currentUser:e.currentUser})}function g(e,t,a="AND"){return l.create("(("+f(e,r.Standardised)+")"+a+"("+f(t,r.Standardised)+"))",{fieldsIndex:e.fieldsIndex,timeZone:e.timeZone,currentUser:e.currentUser})}function h(e){return!0===e.delimited?`"${e.column.split('"').join('""')}"`:e.column}function y(e,u,l,d=null,f=null){let m,p,g,w;switch(e.type){case"interval":return F(y(e.value,u,l,d,f),e.qualifier,e.op);case"case-expression":{let r=" CASE ";"simple"===e.format&&(r+=y(e.operand,u,l,d,f));for(let t=0;t<e.clauses.length;t++)r+=" WHEN "+y(e.clauses[t].operand,u,l,d,f)+" THEN "+y(e.clauses[t].value,u,l,d,f);return null!==e.else&&(r+=" ELSE "+y(e.else,u,l,d,f)),r+=" END ",r}case"parameter":{const r=l[e.value.toLowerCase()];if("string"==typeof r){return"'"+l[e.value.toLowerCase()].toString().replaceAll("'","''")+"'"}if(t(r))return I(r,u);if(a(r))return I(r,u);if(s(r))return A(r,u);if(n(r))return S(r,u);if(c(r))return E(r,u);if(Array.isArray(r)){const e=[];for(let i=0;i<r.length;i++)"string"==typeof r[i]?e.push("'"+r[i].toString().replaceAll("'","''")+"'"):t(r[i])||a(r[i])?e.push(I(r[i],u)):s(r[i])?e.push(A(r[i],u)):n(r[i])?e.push(S(r[i],u)):c(r[i])?e.push(E(r[i],u)):e.push(r[i].toString());return e}return r.toString()}case"expression-list":p=[];for(const r of e.value)p.push(y(r,u,l,d,f));return p;case"unary-expression":return" ( NOT "+y(e.expr,u,l,d,f)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+y(e.left,u,l,d,f)+" AND "+y(e.right,u,l,d,f)+") ";case"OR":return" ("+y(e.left,u,l,d,f)+" OR "+y(e.right,u,l,d,f)+") ";case"IS":if("null"!==e.right.type)throw new i(o.UnsupportedIsRhs);return" ("+y(e.left,u,l,d,f)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new i(o.UnsupportedIsRhs);return" ("+y(e.left,u,l,d,f)+" IS NOT NULL )";case"IN":return m=[],"expression-list"===e.right.type?(m=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" IN ("+m.join(",")+")) "):(w=y(e.right,u,l,d,f),Array.isArray(w)?" ("+y(e.left,u,l,d,f)+" IN ("+w.join(",")+")) ":" ("+y(e.left,u,l,d,f)+" IN ("+w+")) ");case"NOT IN":return m=[],"expression-list"===e.right.type?(m=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" NOT IN ("+m.join(",")+")) "):(w=y(e.right,u,l,d,f),Array.isArray(w)?" ("+y(e.left,u,l,d,f)+" NOT IN ("+w.join(",")+")) ":" ("+y(e.left,u,l,d,f)+" NOT IN ("+w+")) ");case"BETWEEN":return g=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"NOTBETWEEN":return g=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" NOT BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"LIKE":return""!==e.escape?" ("+y(e.left,u,l,d,f)+" LIKE "+y(e.right,u,l,d,f)+" ESCAPE '"+e.escape+"') ":" ("+y(e.left,u,l,d,f)+" LIKE "+y(e.right,u,l,d,f)+") ";case"NOT LIKE":return""!==e.escape?" ("+y(e.left,u,l,d,f)+" NOT LIKE "+y(e.right,u,l,d,f)+" ESCAPE '"+e.escape+"') ":" ("+y(e.left,u,l,d,f)+" NOT LIKE "+y(e.right,u,l,d,f)+") ";case"<>":case"<":case">":case">=":case"<=":case"=":case"*":case"-":case"+":case"/":return" ("+y(e.left,u,l,d,f)+" "+e.operator+" "+y(e.right,u,l,d,f)+") ";case"||":return" ("+y(e.left,u,l,d,f)+" "+(u===r.SqlServer?"+":e.operator)+" "+y(e.right,u,l,d,f)+") "}throw new i(o.UnsupportedOperator,{operator:e.operator});case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":return`timestamp '${e.value}'`;case"date":return`date '${e.value}'`;case"time":return`time '${e.value}'`;case"number":return e.value.toString();case"current-time":return L(e.mode,u);case"current-user":return"CURRENT_USER";case"column-reference":return d&&d.toLowerCase()===e.column.toLowerCase()?"("+f+")":h(e);case"data-type":return e.value;case"function":{const r=y(e.args,u,l,d,f);return T(e.name,r,u)}}throw new i(o.UnsupportedSyntax,{node:e.type})}function T(e,t,a){switch(e.toLowerCase().trim()){case"cos":case"sin":case"tan":case"cosh":case"tanh":case"sinh":case"acos":case"asin":case"atan":case"floor":case"log10":case"log":case"abs":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${t[0]})`;case"ceiling":case"ceil":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"ceiling"});switch(a){case r.Standardised:case r.StandardisedNoInterval:}return"CEILING("+t[0]+")";case"mod":case"power":case"nullif":if(2!==t.length)throw new i(o.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${t[0]},${t[1]})`;case"round":if(2===t.length)return"ROUND("+t[0]+","+t[1]+")";if(1===t.length)return"ROUND("+t[0]+")";throw new i(o.InvalidFunctionParameters,{function:"round"});case"truncate":if(t.length<1||t.length>2)throw new i(o.InvalidFunctionParameters,{function:"truncate"});return a===r.SqlServer?"ROUND("+t[0]+(1===t.length?"0":","+t[1])+",1)":"TRUNCATE("+t[0]+(1===t.length?")":","+t[1]+")");case"char_length":case"len":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"char_length"});switch(a){case r.SqlServer:return"LEN("+t[0]+")";case r.Oracle:return"LENGTH("+t[0]+")";default:return"CHAR_LENGTH("+t[0]+")"}case"coalesce":case"concat":{if(t.length<1)throw new i(o.InvalidFunctionParameters,{function:e.toLowerCase()});let r=e.toUpperCase().trim()+"(";for(let e=0;e<t.length;e++)0!==e&&(r+=","),r+=t[e];return r+=")",r}case"lower":case"lcase":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"lower"});return"LOWER("+t[0]+")";case"upper":case"ucase":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"upper"});return"UPPER("+t[0]+")";case"substring":{let e="";switch(a){case r.Oracle:return e="SUBSTR("+t[0]+","+t[1],3===t.length&&(e+=","+t[2]),e+=")",e;case r.SqlServer:return e=3===t.length?"SUBSTRING("+t[0]+","+t[1]+","+t[2]+")":"SUBSTRING("+t[0]+", "+t[1]+", LEN("+t[0]+") - "+t[1]+")",e;default:return e="SUBSTRING("+t[0]+" FROM "+t[1],3===t.length&&(e+=" FOR "+t[2]),e+=")",e}}case"extract":return"EXTRACT("+t[0].replaceAll("'","")+" FROM "+t[1]+")";case"cast":{let e="";switch(a){case r.Oracle:switch(t[1].type){case"date":e="DATE";break;case"float":e="DOUBLE";break;case"integer":e="INTEGER";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="TIMESTAMP";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`;case r.Postgres:switch(t[1].type){case"date":e="DATE";break;case"float":e="DOUBLE PRECISION";break;case"integer":e="INT";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="TIMESTAMP";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`;case r.SqlServer:switch(t[1].type){case"date":e="DATE";break;case"float":e="FLOAT";break;case"integer":e="INT";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="DATETIME";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`;default:switch(t[1].type){case"date":e="DATE";break;case"float":e="FLOAT";break;case"integer":e="INTEGER";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="TIMESTAMP";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`}}}throw new i(o.InvalidFunctionParameters,{function:e})}function S(e,t){const a=e.toDateTime(),s=0===a.hour&&0===a.minute&&0===a.second&&0===a.millisecond;switch(t){case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:return s?`date '${a.toFormat("yyyy-LL-dd")}'`:`timestamp '${a.toFormat("yyyy-LL-dd HH:mm:ss")}'`;case r.Oracle:return s?`TO_DATE('${a.toFormat("yyyy-LL-dd")}','YYYY-MM-DD')`:`TO_DATE('${a.toFormat("yyyy-LL-dd HH:mm:ss")}','YYYY-MM-DD HH24:MI:SS')`;case r.SqlServer:return`'${a.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;case r.PGDB:return`#${a.toFormat(s?"LL-dd-yyyy":"LL-dd-yyyy HH:mm:ss")}#`;case r.Postgres:return`TIMESTAMP '${a.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;default:return`timestamp '${a.toFormat("yyyy-LL-dd HH:mm:ss")}'`}}function E(e,t){switch(t){case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:return e.toSQLWithKeyword();case r.Oracle:return`TO_DATE('${e.toFormat("Y-MM-DD")}'`;case r.SqlServer:return`'${e.toFormat("Y-MM-DD")}'`;case r.PGDB:return`#${e.toFormat("Y-MM-DD")}#`;case r.Postgres:return`TIMESTAMP '${e.toFormat("Y-MM-DD")}'`;default:return e.toSQLWithKeyword()}}function A(e,t){switch(e instanceof u&&(e=e.toStorageString()),t){case r.Oracle:return`TO_DATE('${e}', 'HH24:MI:SS')`;case r.SqlServer:return`'${e}'`;case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:case r.Postgres:default:return`time '${e}'`}}function I(r,t){return S(e.dateTimeToArcadeDate(a(r)?r:d.fromJSDate(r)),t)}function L(e,t){switch(t){case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:case r.Oracle:case r.PGDB:default:return"date"===e?"CURRENT_DATE":"time"===e?"CURRENT_TIME":"CURRENT_TIMESTAMP";case r.SqlServer:return"date"===e?"CAST(GETDATE() AS DATE)":"time"===e?"CAST(GETDATE() AS TIME)":"GETDATE()";case r.Postgres:return"date"===e?"CURRENT_DATE":"time"===e?"LOCALTIME":"CURRENT_TIMESTAMP"}}function w(e,r,t={}){const a={},s={},n={esriFieldTypeSmallInteger:"integer",esriFieldTypeInteger:"integer",esriFieldTypeBigInteger:"integer",esriFieldTypeSingle:"double",esriFieldTypeDouble:"double",esriFieldTypeString:"string",esriFieldTypeTimeOnly:"time-only",esriFieldTypeDateOnly:"date-only",esriFieldTypeTimestampOffset:"timestamp-offset",esriFieldTypeDate:"date",esriFieldTypeOID:"integer",esriFieldTypeGUID:"guid",esriFieldTypeGlobalID:"guid",oid:"integer",long:"integer","small-integer":"integer",integer:"integer","big-integer":"integer",single:"double","time-only":"time-only","date-only":"date-only","timestamp-offset":"timestemp-offset",double:"double",date:"date",guid:"guid","global-id":"guid",string:"string"};for(const c of r){const e=c.type?n[c.type]:void 0;a[c.name.toLowerCase()]=void 0===e?"":e}for(const c in t){const e=n[t[c]];s[c.toLowerCase()]=void 0===e?"":e}switch(N(a,e.parseTree,e.parameters,s)){case"double":return"double";case"integer":return"integer";case"date":return"date";case"date-only":return"date-only";case"time-only":return"time-only";case"timestamp-offset":return"timestamp-offset";case"string":return"string";case"global-id":case"guid":return"guid"}return""}function N(e,r,a,u){let l;switch(r.type){case"interval":return"integer";case"case-expression":{const t=[];if("simple"===r.format){for(let s=0;s<r.clauses.length;s++)t.push(N(e,r.clauses[s].value,a,u));null!==r.else&&t.push(N(e,r.else,a,u))}else{for(let s=0;s<r.clauses.length;s++)t.push(N(e,r.clauses[s].value,a,u));null!==r.else&&t.push(N(e,r.else,a,u))}return v(t)}case"parameter":{const e=u[r.value.toLowerCase()];if(void 0===e&&a){const e=a[r.value.toLowerCase()];if(void 0===e)return"";if(null===e)return"";if("string"==typeof e||e instanceof String)return"string";if("boolean"==typeof e)return"boolean";if(t(e))return"date";if(n(e))return"date";if(c(e))return"date-only";if(s(e))return"time-only";if("number"==typeof e)return e%1==0?"integer":"double"}return void 0===e?"":e}case"expression-list":{const t=[];for(const s of r.value)t.push(N(e,s,a,u));return t}case"unary-expression":return"boolean";case"binary-expression":switch(r.operator){case"AND":case"OR":case"IN":case"NOT IN":case"BETWEEN":case"NOTBETWEEN":case"LIKE":case"NOT LIKE":case"<>":case"<":case">":case">=":case"<=":case"=":return"boolean";case"IS":case"ISNOT":if("null"!==r.right.type)throw new i(o.UnsupportedIsRhs);return"boolean";case"*":case"-":case"+":case"/":return v([N(e,r.left,a,u),N(e,r.right,a,u)]);case"||":return"string";default:throw new i(o.UnsupportedOperator,{operator:r.operator})}case"null":return"";case"boolean":return"boolean";case"string":return"string";case"number":return null===r.value?"":r.value%1==0?"integer":"double";case"date":return"date";case"timestamp":return r.withtimezone?"timestamp-offset":"date";case"time":return"time-only";case"current-time":return"time"===r.mode?"time-only":"date";case"current-user":return"string";case"column-reference":{const t=e[r.column.toLowerCase()];return void 0===t?"":t}case"function":switch(r.name.toLowerCase()){case"cast":switch(r.args?.value[1]?.value.type??""){case"integer":case"smallint":return"integer";case"real":case"float":return"double";case"date":case"timestamp":return!0===r.args?.value[1]?.value?.withtimezone?"timestamp-offset":"date";case"time":return"time-only";case"varchar":return"string";default:return""}case"position":case"extract":case"char_length":case"mod":return"integer";case"round":if(l=N(e,r.args,a,u),Array.isArray(l)){if(l.length<=0)return"double";l=l[0]}return l;case"sign":return"integer";case"ceiling":case"floor":case"abs":return l=N(e,r.args,a,u),Array.isArray(l)&&(l=v(l)),"integer"===l||"double"===l?l:"double";case"area":case"length":case"log":case"log10":case"sin":case"cos":case"tan":case"asin":case"acos":case"atan":case"cosh":case"sinh":case"tanh":case"power":return"double";case"substring":case"trim":case"concat":case"lower":case"upper":return"string";case"truncate":return"double";case"nullif":case"coalesce":return l=N(e,r.args,a,u),Array.isArray(l)?l.length>0?l[0]:"":l}return""}throw new i(o.UnsupportedSyntax,{node:r.type})}const b={boolean:1,string:2,integer:3,double:4,date:5};function v(e){if(e){let r="";for(const t of e)""!==t&&(r=""===r||b[r]<b[t]?t:r);return r}return""}function D(e,r){return R(e.parseTree,r)}function O(e){return"column-reference"===e?.parseTree.type}function R(e,r){if(null==e)return!1;switch(e.type){case"when-clause":return R(e.operand,r)||R(e.value,r);case"case-expression":for(const t of e.clauses)if(R(t,r))return!0;return!("simple"!==e.format||!R(e.operand,r))||!(null===e.else||!R(e.else,r));case"parameter":case"null":case"boolean":case"date":case"timestamp":case"time":case"string":case"number":return!1;case"expression-list":for(const t of e.value)if(R(t,r))return!0;return!1;case"unary-expression":return R(e.expr,r);case"binary-expression":return R(e.left,r)||R(e.right,r);case"column-reference":return r.toLowerCase()===e.column.toLowerCase();case"function":return R(e.args,r)}return!1}function C(e){let r="";return r+=e.period.toUpperCase(),r}function F(e,r,t){let a="";return a="interval-period"===r.type?C(r):C(r.start)+" TO "+C(r.end),"INTERVAL "+t+" "+e+" "+a}export{E as arcadeDateOnlyToSqlString,S as arcadeDateToSqlString,g as combine,h as convertColumnReferenceToSql,F as convertIntervalToSql,O as isSingleField,I as makeSqlFromDateTimeParameter,A as makeTimeString,L as makeToday,w as predictType,p as reformulateWithoutField,D as scanForField,f as toWhereClause,m as toWhereClauseFromTree,T as translateFunctionToDatabaseSpecific};
|
|
5
|
+
import{ArcadeDate as e}from"../../ArcadeDate.js";import{FeatureServiceDatabaseType as r,isDate as t,isLuxonDate as a,isArcadeTime as s,isArcadeDate as n,isArcadeDateOnly as c}from"./shared.js";import{SqlError as i,SqlErrorCodes as o}from"../../../core/sql/errorSupport.js";import{TimeOnly as u}from"../../../core/sql/TimeOnly.js";import l from"../../../core/sql/WhereClause.js";import{DateTime as d}from"luxon";function f(e,r){return y(e?.parseTree,r,e?.parameters)}function m(e,r,t){return y(e,r,t)}function p(e,t,a,s){const n=y(e.parseTree,r.Standardised,e.parameters,t,a);return l.create(n,{fieldsIndex:s,timeZone:e.timeZone,currentUser:e.currentUser})}function g(e,t,a="AND"){return l.create("(("+f(e,r.Standardised)+")"+a+"("+f(t,r.Standardised)+"))",{fieldsIndex:e.fieldsIndex,timeZone:e.timeZone,currentUser:e.currentUser})}function h(e){return!0===e.delimited?`"${e.column.split('"').join('""')}"`:e.column}function y(e,u,l,d=null,f=null){let m,p,g,w;switch(e.type){case"interval":return F(y(e.value,u,l,d,f),e.qualifier,e.op);case"case-expression":{let r=" CASE ";"simple"===e.format&&(r+=y(e.operand,u,l,d,f));for(let t=0;t<e.clauses.length;t++)r+=" WHEN "+y(e.clauses[t].operand,u,l,d,f)+" THEN "+y(e.clauses[t].value,u,l,d,f);return null!==e.else&&(r+=" ELSE "+y(e.else,u,l,d,f)),r+=" END ",r}case"parameter":{const r=l[e.value.toLowerCase()];if("string"==typeof r){return"'"+l[e.value.toLowerCase()].toString().replaceAll("'","''")+"'"}if(t(r))return I(r,u);if(a(r))return I(r,u);if(s(r))return A(r,u);if(n(r))return S(r,u);if(c(r))return E(r,u);if(Array.isArray(r)){const e=[];for(let i=0;i<r.length;i++)"string"==typeof r[i]?e.push("'"+r[i].toString().replaceAll("'","''")+"'"):t(r[i])||a(r[i])?e.push(I(r[i],u)):s(r[i])?e.push(A(r[i],u)):n(r[i])?e.push(S(r[i],u)):c(r[i])?e.push(E(r[i],u)):e.push(r[i].toString());return e}return r.toString()}case"expression-list":p=[];for(const r of e.value)p.push(y(r,u,l,d,f));return p;case"unary-expression":return" ( NOT "+y(e.expr,u,l,d,f)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+y(e.left,u,l,d,f)+" AND "+y(e.right,u,l,d,f)+") ";case"OR":return" ("+y(e.left,u,l,d,f)+" OR "+y(e.right,u,l,d,f)+") ";case"IS":if("null"!==e.right.type)throw new i(o.UnsupportedIsRhs);return" ("+y(e.left,u,l,d,f)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new i(o.UnsupportedIsRhs);return" ("+y(e.left,u,l,d,f)+" IS NOT NULL )";case"IN":return m=[],"expression-list"===e.right.type?(m=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" IN ("+m.join(",")+")) "):(w=y(e.right,u,l,d,f),Array.isArray(w)?" ("+y(e.left,u,l,d,f)+" IN ("+w.join(",")+")) ":" ("+y(e.left,u,l,d,f)+" IN ("+w+")) ");case"NOT IN":return m=[],"expression-list"===e.right.type?(m=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" NOT IN ("+m.join(",")+")) "):(w=y(e.right,u,l,d,f),Array.isArray(w)?" ("+y(e.left,u,l,d,f)+" NOT IN ("+w.join(",")+")) ":" ("+y(e.left,u,l,d,f)+" NOT IN ("+w+")) ");case"BETWEEN":return g=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"NOTBETWEEN":return g=y(e.right,u,l,d,f)," ("+y(e.left,u,l,d,f)+" NOT BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"LIKE":return""!==e.escape?" ("+y(e.left,u,l,d,f)+" LIKE "+y(e.right,u,l,d,f)+" ESCAPE '"+e.escape+"') ":" ("+y(e.left,u,l,d,f)+" LIKE "+y(e.right,u,l,d,f)+") ";case"NOT LIKE":return""!==e.escape?" ("+y(e.left,u,l,d,f)+" NOT LIKE "+y(e.right,u,l,d,f)+" ESCAPE '"+e.escape+"') ":" ("+y(e.left,u,l,d,f)+" NOT LIKE "+y(e.right,u,l,d,f)+") ";case"<>":case"<":case">":case">=":case"<=":case"=":case"*":case"-":case"+":case"/":return" ("+y(e.left,u,l,d,f)+" "+e.operator+" "+y(e.right,u,l,d,f)+") ";case"||":return" ("+y(e.left,u,l,d,f)+" "+(u===r.SqlServer?"+":e.operator)+" "+y(e.right,u,l,d,f)+") "}throw new i(o.UnsupportedOperator,{operator:e.operator});case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":return`timestamp '${e.value}'`;case"date":return`date '${e.value}'`;case"time":return`time '${e.value}'`;case"number":return e.value.toString();case"current-time":return L(e.mode,u);case"current-user":return"CURRENT_USER";case"column-reference":return d&&d.toLowerCase()===e.column.toLowerCase()?"("+f+")":h(e);case"data-type":return e.value;case"function":{const r=y(e.args,u,l,d,f);return T(e.name,r,u)}}throw new i(o.UnsupportedSyntax,{node:e.type})}function T(e,t,a){switch(e.toLowerCase().trim()){case"cos":case"sin":case"tan":case"cosh":case"tanh":case"sinh":case"acos":case"asin":case"atan":case"floor":case"log10":case"log":case"abs":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${t[0]})`;case"ceiling":case"ceil":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"ceiling"});switch(a){case r.Standardised:case r.StandardisedNoInterval:}return"CEILING("+t[0]+")";case"mod":case"power":case"nullif":if(2!==t.length)throw new i(o.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${t[0]},${t[1]})`;case"round":if(2===t.length)return"ROUND("+t[0]+","+t[1]+")";if(1===t.length)return"ROUND("+t[0]+")";throw new i(o.InvalidFunctionParameters,{function:"round"});case"truncate":if(t.length<1||t.length>2)throw new i(o.InvalidFunctionParameters,{function:"truncate"});return a===r.SqlServer?"ROUND("+t[0]+(1===t.length?"0":","+t[1])+",1)":"TRUNCATE("+t[0]+(1===t.length?")":","+t[1]+")");case"char_length":case"len":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"char_length"});switch(a){case r.SqlServer:return"LEN("+t[0]+")";case r.Oracle:return"LENGTH("+t[0]+")";default:return"CHAR_LENGTH("+t[0]+")"}case"coalesce":case"concat":{if(t.length<1)throw new i(o.InvalidFunctionParameters,{function:e.toLowerCase()});let r=e.toUpperCase().trim()+"(";for(let e=0;e<t.length;e++)0!==e&&(r+=","),r+=t[e];return r+=")",r}case"lower":case"lcase":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"lower"});return"LOWER("+t[0]+")";case"upper":case"ucase":if(1!==t.length)throw new i(o.InvalidFunctionParameters,{function:"upper"});return"UPPER("+t[0]+")";case"substring":{let e="";switch(a){case r.Oracle:return e="SUBSTR("+t[0]+","+t[1],3===t.length&&(e+=","+t[2]),e+=")",e;case r.SqlServer:return e=3===t.length?"SUBSTRING("+t[0]+","+t[1]+","+t[2]+")":"SUBSTRING("+t[0]+", "+t[1]+", LEN("+t[0]+") - "+t[1]+")",e;default:return e="SUBSTRING("+t[0]+" FROM "+t[1],3===t.length&&(e+=" FOR "+t[2]),e+=")",e}}case"extract":return"EXTRACT("+t[0].replaceAll("'","")+" FROM "+t[1]+")";case"cast":{let e="";switch(a){case r.Oracle:switch(t[1].type){case"date":e="DATE";break;case"float":e="DOUBLE";break;case"integer":e="INTEGER";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="TIMESTAMP";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`;case r.Postgres:switch(t[1].type){case"date":e="DATE";break;case"float":e="DOUBLE PRECISION";break;case"integer":e="INT";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="TIMESTAMP";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`;case r.SqlServer:switch(t[1].type){case"date":e="DATE";break;case"float":e="FLOAT";break;case"integer":e="INT";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="DATETIME";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`;default:switch(t[1].type){case"date":e="DATE";break;case"float":e="FLOAT";break;case"integer":e="INTEGER";break;case"real":e="REAL";break;case"smallint":e="SMALLINT";break;case"timestamp":e="TIMESTAMP";break;case"varchar":e="VARCHAR("+t[1].size.toString()+")"}return`CAST(${t[0]} AS ${e})`}}}throw new i(o.InvalidFunctionParameters,{function:e})}function S(e,t){const a=e.toDateTime(),s=0===a.hour&&0===a.minute&&0===a.second&&0===a.millisecond;switch(t){case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:return s?`date '${a.toFormat("yyyy-LL-dd")}'`:`timestamp '${a.toFormat("yyyy-LL-dd HH:mm:ss")}'`;case r.Oracle:return s?`TO_DATE('${a.toFormat("yyyy-LL-dd")}','YYYY-MM-DD')`:`TO_DATE('${a.toFormat("yyyy-LL-dd HH:mm:ss")}','YYYY-MM-DD HH24:MI:SS')`;case r.SqlServer:return`'${a.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;case r.PGDB:return`#${a.toFormat(s?"LL-dd-yyyy":"LL-dd-yyyy HH:mm:ss")}#`;case r.Postgres:return`TIMESTAMP '${a.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;default:return`timestamp '${a.toFormat("yyyy-LL-dd HH:mm:ss")}'`}}function E(e,t){switch(t){case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:return e.toSQLWithKeyword();case r.Oracle:return`TO_DATE('${e.toFormat("Y-MM-DD")}'`;case r.SqlServer:return`'${e.toFormat("Y-MM-DD")}'`;case r.PGDB:return`#${e.toFormat("Y-MM-DD")}#`;case r.Postgres:return`TIMESTAMP '${e.toFormat("Y-MM-DD")}'`;default:return e.toSQLWithKeyword()}}function A(e,t){switch(e instanceof u&&(e=e.toStorageString()),t){case r.Oracle:return`TO_DATE('${e}', 'HH24:MI:SS')`;case r.SqlServer:return`'${e}'`;case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:case r.Postgres:default:return`time '${e}'`}}function I(r,t){return S(e.dateTimeToArcadeDate(a(r)?r:d.fromJSDate(r)),t)}function L(e,t){switch(t){case r.FILEGDB:case r.Standardised:case r.StandardisedNoInterval:case r.Oracle:case r.PGDB:default:return"date"===e?"CURRENT_DATE":"time"===e?"CURRENT_TIME":"CURRENT_TIMESTAMP";case r.SqlServer:return"date"===e?"CAST(GETDATE() AS DATE)":"time"===e?"CAST(GETDATE() AS TIME)":"GETDATE()";case r.Postgres:return"date"===e?"CURRENT_DATE":"time"===e?"LOCALTIME":"CURRENT_TIMESTAMP"}}function w(e,r,t={}){const a={},s={},n={esriFieldTypeSmallInteger:"integer",esriFieldTypeInteger:"integer",esriFieldTypeBigInteger:"integer",esriFieldTypeSingle:"double",esriFieldTypeDouble:"double",esriFieldTypeString:"string",esriFieldTypeTimeOnly:"time-only",esriFieldTypeDateOnly:"date-only",esriFieldTypeTimestampOffset:"timestamp-offset",esriFieldTypeDate:"date",esriFieldTypeOID:"integer",esriFieldTypeGUID:"guid",esriFieldTypeGlobalID:"guid",oid:"integer",long:"integer","small-integer":"integer",integer:"integer","big-integer":"integer",single:"double","time-only":"time-only","date-only":"date-only","timestamp-offset":"timestemp-offset",double:"double",date:"date",guid:"guid","global-id":"guid",string:"string"};for(const c of r){const e=c.type?n[c.type]:void 0;a[c.name.toLowerCase()]=void 0===e?"":e}for(const c in t){const e=n[t[c]];s[c.toLowerCase()]=void 0===e?"":e}switch(N(a,e.parseTree,e.parameters,s)){case"double":return"double";case"integer":return"integer";case"date":return"date";case"date-only":return"date-only";case"time-only":return"time-only";case"timestamp-offset":return"timestamp-offset";case"string":return"string";case"global-id":case"guid":return"guid"}return""}function N(e,r,a,u){let l;switch(r.type){case"interval":return"integer";case"case-expression":{const t=[];if("simple"===r.format){for(let s=0;s<r.clauses.length;s++)t.push(N(e,r.clauses[s].value,a,u));null!==r.else&&t.push(N(e,r.else,a,u))}else{for(let s=0;s<r.clauses.length;s++)t.push(N(e,r.clauses[s].value,a,u));null!==r.else&&t.push(N(e,r.else,a,u))}return v(t)}case"parameter":{const e=u[r.value.toLowerCase()];if(void 0===e&&a){const e=a[r.value.toLowerCase()];if(void 0===e)return"";if(null===e)return"";if("string"==typeof e||e instanceof String)return"string";if("boolean"==typeof e)return"boolean";if(t(e))return"date";if(n(e))return"date";if(c(e))return"date-only";if(s(e))return"time-only";if("number"==typeof e)return e%1==0?"integer":"double"}return void 0===e?"":e}case"expression-list":{const t=[];for(const s of r.value)t.push(N(e,s,a,u));return t}case"unary-expression":return"boolean";case"binary-expression":switch(r.operator){case"AND":case"OR":case"IN":case"NOT IN":case"BETWEEN":case"NOTBETWEEN":case"LIKE":case"NOT LIKE":case"<>":case"<":case">":case">=":case"<=":case"=":return"boolean";case"IS":case"ISNOT":if("null"!==r.right.type)throw new i(o.UnsupportedIsRhs);return"boolean";case"*":case"-":case"+":case"/":return v([N(e,r.left,a,u),N(e,r.right,a,u)]);case"||":return"string";default:throw new i(o.UnsupportedOperator,{operator:r.operator})}case"null":return"";case"boolean":return"boolean";case"string":return"string";case"number":return null===r.value?"":r.value%1==0?"integer":"double";case"date":return"date";case"timestamp":return r.withtimezone?"timestamp-offset":"date";case"time":return"time-only";case"current-time":return"time"===r.mode?"time-only":"date";case"current-user":return"string";case"column-reference":{const t=e[r.column.toLowerCase()];return void 0===t?"":t}case"function":switch(r.name.toLowerCase()){case"cast":switch(r.args?.value[1]?.value.type??""){case"integer":case"smallint":return"integer";case"real":case"float":return"double";case"date":case"timestamp":return!0===r.args?.value[1]?.value?.withtimezone?"timestamp-offset":"date";case"time":return"time-only";case"varchar":return"string";default:return""}case"position":case"extract":case"char_length":case"mod":return"integer";case"round":if(l=N(e,r.args,a,u),Array.isArray(l)){if(l.length<=0)return"double";l=l[0]}return l;case"sign":return"integer";case"ceiling":case"floor":case"abs":return l=N(e,r.args,a,u),Array.isArray(l)&&(l=v(l)),"integer"===l||"double"===l?l:"double";case"area":case"length":case"log":case"log10":case"sin":case"cos":case"tan":case"asin":case"acos":case"atan":case"cosh":case"sinh":case"tanh":case"power":return"double";case"substring":case"trim":case"concat":case"lower":case"upper":return"string";case"truncate":return"double";case"nullif":case"coalesce":return l=N(e,r.args,a,u),Array.isArray(l)?l.length>0?l[0]:"":l}return""}throw new i(o.UnsupportedSyntax,{node:r.type})}const b={boolean:1,string:2,integer:3,double:4,date:5};function v(e){if(e){let r="";for(const t of e)""!==t&&(r=""===r||b[r]<b[t]?t:r);return r}return""}function D(e,r){return R(e.parseTree,r)}function O(e){return"column-reference"===e?.parseTree.type}function R(e,r){if(null==e)return!1;switch(e.type){case"when-clause":return R(e.operand,r)||R(e.value,r);case"case-expression":for(const t of e.clauses)if(R(t,r))return!0;return!("simple"!==e.format||!R(e.operand,r))||!(null===e.else||!R(e.else,r));case"parameter":case"null":case"boolean":case"date":case"timestamp":case"time":case"string":case"number":return!1;case"expression-list":for(const t of e.value)if(R(t,r))return!0;return!1;case"unary-expression":return R(e.expr,r);case"binary-expression":return R(e.left,r)||R(e.right,r);case"column-reference":return r.toLowerCase()===e.column.toLowerCase();case"function":return R(e.args,r)}return!1}function C(e){let r="";return r+=e.period.toUpperCase(),r}function F(e,r,t){let a="";return a="interval-period"===r.type?C(r):C(r.start)+" TO "+C(r.end),"INTERVAL "+t+" "+e+" "+a}export{E as arcadeDateOnlyToSqlString,S as arcadeDateToSqlString,g as combine,h as convertColumnReferenceToSql,F as convertIntervalToSql,O as isSingleField,I as makeSqlFromDateTimeParameter,A as makeTimeString,L as makeToday,w as predictType,p as reformulateWithoutField,D as scanForField,f as toWhereClause,m as toWhereClauseFromTree,T as translateFunctionToDatabaseSpecific};
|