@arcgis/core 4.31.0-next.20240918 → 4.31.0-next.20240920

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/Camera.js +1 -1
  2. package/WebDocument2D.js +1 -1
  3. package/WebLinkChart.js +1 -1
  4. package/WebMap.js +1 -1
  5. package/arcade/featureSetUtils.js +1 -1
  6. package/arcade/featureset/actions/Adapted.js +1 -1
  7. package/arcade/featureset/actions/GroupBy.js +1 -1
  8. package/arcade/featureset/support/FeatureSet.js +1 -1
  9. package/arcade/featureset/support/StatsField.js +1 -1
  10. package/arcade/featureset/support/sqlUtils.js +1 -1
  11. package/arcade/functions/featuresetbase.js +1 -1
  12. package/arcade/functions/featuresetstats.js +1 -1
  13. package/assets/esri/core/workers/RemoteClient.js +1 -1
  14. package/assets/esri/core/workers/chunks/008f290833724454160d.js +1 -0
  15. package/assets/esri/core/workers/chunks/{ae23da458884b36a337f.js → 093a1ee161cb6a840283.js} +2 -2
  16. package/assets/esri/core/workers/chunks/0eb789af3c26fecdf3be.js +1 -0
  17. package/assets/esri/core/workers/chunks/11609925a534e728ca1e.js +1 -0
  18. package/assets/esri/core/workers/chunks/{133e2a9b84958c53e2ea.js → 14f77efbfba0ca9efb6c.js} +1 -1
  19. package/assets/esri/core/workers/chunks/2020b99675caabf5ac87.js +1 -0
  20. package/assets/esri/core/workers/chunks/23005ea017369781a300.js +1 -0
  21. package/assets/esri/core/workers/chunks/31b659b560581fc797f8.js +1 -0
  22. package/assets/esri/core/workers/chunks/41205645790e5f2bdaf7.js +1 -0
  23. package/assets/esri/core/workers/chunks/41a3c7d286a050002d20.js +1 -0
  24. package/assets/esri/core/workers/chunks/42b92b4c2c9fd2b15f60.js +2 -0
  25. package/assets/esri/core/workers/chunks/{ba561e03df67894e437f.js.LICENSE.txt → 42b92b4c2c9fd2b15f60.js.LICENSE.txt} +1 -1
  26. package/assets/esri/core/workers/chunks/42f1598ec31301b1e115.js +1 -0
  27. package/assets/esri/core/workers/chunks/{82bd4b8e864846efaaa9.js → 59833b27d8413b6d9312.js} +1 -1
  28. package/assets/esri/core/workers/chunks/59e4731d246203e94a96.js +1 -0
  29. package/assets/esri/core/workers/chunks/5f9beed2a9599b9ce649.js +1 -0
  30. package/assets/esri/core/workers/chunks/6508ff21b0a5725629eb.js +1 -0
  31. package/assets/esri/core/workers/chunks/65b1d7fa57d4c764efe8.js +1 -0
  32. package/assets/esri/core/workers/chunks/668af6e91eda15f4d8d7.js +1 -0
  33. package/assets/esri/core/workers/chunks/69c09478c899cd5e5013.js +1 -0
  34. package/assets/esri/core/workers/chunks/{72500eb0abf74ebb26c1.js → 6c07116c8f7361780803.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{b99d380cce485e65c990.js → 6cda92678ffeeaea0330.js} +1 -1
  36. package/assets/esri/core/workers/chunks/6d668f7696f280ec9588.js +1 -0
  37. package/assets/esri/core/workers/chunks/{a56af6bb7cfff9a91046.js → 6ea5588176a32a6a8004.js} +1 -1
  38. package/assets/esri/core/workers/chunks/7088f771163fda53d196.js +1 -0
  39. package/assets/esri/core/workers/chunks/79ed119c70ce6ea02f71.js +1 -0
  40. package/assets/esri/core/workers/chunks/7b4880b2dc6b01d70ccc.js +1 -0
  41. package/assets/esri/core/workers/chunks/83507fa29814b78964bd.js +1 -0
  42. package/assets/esri/core/workers/chunks/83649583139b818d4dfa.js +1 -0
  43. package/assets/esri/core/workers/chunks/{2bd17a263bb81ce3b19e.js → 8d25ba9e1475a21f4562.js} +1 -1
  44. package/assets/esri/core/workers/chunks/92b440ed7e593f5ec449.js +1 -0
  45. package/assets/esri/core/workers/chunks/95ea77a7d63c9d7ed78b.js +1 -0
  46. package/assets/esri/core/workers/chunks/a6c3c1827d2e8bbfcd9e.js +1 -0
  47. package/assets/esri/core/workers/chunks/ad4fa125e09cc0047f5b.js +1 -0
  48. package/assets/esri/core/workers/chunks/bb5a18dd1e6a71905668.js +2 -0
  49. package/assets/esri/core/workers/chunks/bc95ecfca457a723c4e8.js +1 -0
  50. package/assets/esri/core/workers/chunks/bf406a46515d5dfebe06.js +1 -0
  51. package/assets/esri/core/workers/chunks/cd7fc0ca9057feb5d14e.js +1 -0
  52. package/assets/esri/core/workers/chunks/da3a4eb3fbb9dd509b4b.js +1 -0
  53. package/assets/esri/core/workers/chunks/e1e9a7695e48e34a69bd.js +1 -0
  54. package/assets/esri/core/workers/chunks/e4f1464ed269c301b4ee.js +1 -0
  55. package/assets/esri/core/workers/chunks/e5633fd14abbd4901acc.js +1 -0
  56. package/assets/esri/core/workers/chunks/{34e4c327bcc4ee5729d1.js → e611141692355a1ba2b2.js} +1 -1
  57. package/assets/esri/core/workers/chunks/{390ae63e392b4bee8ee6.js → efa3c919261672871f2f.js} +1 -1
  58. package/assets/esri/core/workers/chunks/{8cb5d31e6a7f61702870.js → f14cefc311a21116d21b.js} +1 -1
  59. package/assets/esri/core/workers/chunks/f41e8d0d6f5e81289179.js +1 -0
  60. package/assets/esri/core/workers/chunks/{6e0e9e264e15351a3aed.js → f7e01814faee49aa6d75.js} +1 -1
  61. package/assets/esri/core/workers/chunks/{5ca8e767cc03e1425338.js → f9e90a2fda559ca68848.js} +1 -1
  62. package/assets/esri/themes/base/widgets/_OrientedImageryViewer.scss +6 -0
  63. package/assets/esri/themes/dark/main.css +1 -1
  64. package/assets/esri/themes/light/main.css +1 -1
  65. package/assets/esri/themes/light/view.css +1 -1
  66. package/assets/esri/widgets/BasemapGallery/t9n/BasemapGallery.json +1 -1
  67. package/assets/esri/widgets/BasemapGallery/t9n/BasemapGallery_en.json +1 -1
  68. package/assets/esri/widgets/OrientedImageryViewer/t9n/OrientedImageryViewer.json +1 -1
  69. package/assets/esri/widgets/OrientedImageryViewer/t9n/OrientedImageryViewer_en.json +1 -1
  70. package/chunks/Centroid-DZi-eb9F.js +1 -1
  71. package/chunks/CloudsComposition.glsl.js +2 -2
  72. package/chunks/ComponentShader.glsl.js +10 -13
  73. package/chunks/Distance2DCalculator-De7WFGFq.js +5 -0
  74. package/chunks/Fog.glsl.js +2 -2
  75. package/chunks/GeodeticDistanceCalculator-CN7xMqrJ.js +5 -0
  76. package/chunks/HighlightApply.glsl.js +25 -43
  77. package/chunks/HighlightDownsample.glsl.js +20 -34
  78. package/chunks/LineSeries.js +1 -1
  79. package/chunks/{OITCompositing.glsl.js → OITBlend.glsl.js} +1 -1
  80. package/chunks/OperatorGeneralize.js +1 -1
  81. package/chunks/OperatorGeodesicBuffer.js +1 -1
  82. package/chunks/OperatorGeodeticArea.js +1 -1
  83. package/chunks/OperatorGeodeticDensifyByLength.js +1 -1
  84. package/chunks/OperatorGeodeticDistance.js +1 -1
  85. package/chunks/OperatorGeodeticLength.js +1 -1
  86. package/chunks/OperatorProximity.js +1 -1
  87. package/chunks/OperatorShapePreservingLength.js +5 -0
  88. package/chunks/Polyline.js +1 -1
  89. package/chunks/Theme.js +1 -1
  90. package/chunks/Tick.js +1 -1
  91. package/chunks/tslib.es6.js +1 -1
  92. package/core/sql/WhereClause.js +1 -1
  93. package/core/sql/WhereClauseCache.js +1 -1
  94. package/core/sql/WhereGrammar.js +1 -1
  95. package/core/sql.js +1 -1
  96. package/geometry/operators/areaOperator.js +5 -0
  97. package/geometry/operators/containsOperator.js +1 -1
  98. package/geometry/operators/crossesOperator.js +1 -1
  99. package/geometry/operators/disjointOperator.js +1 -1
  100. package/geometry/operators/distanceOperator.js +1 -1
  101. package/geometry/operators/equalsOperator.js +1 -1
  102. package/geometry/operators/geodeticDensifyOperator.js +5 -0
  103. package/geometry/operators/gx/operatorAutoComplete.js +1 -1
  104. package/geometry/operators/gx/operatorBuffer.js +1 -1
  105. package/geometry/operators/gx/operatorClip.js +1 -1
  106. package/geometry/operators/gx/operatorConvexHull.js +1 -1
  107. package/geometry/operators/gx/operatorCut.js +1 -1
  108. package/geometry/operators/gx/operatorDifference.js +1 -1
  109. package/geometry/operators/gx/operatorGeodesicBuffer.js +1 -1
  110. package/geometry/operators/gx/operatorGeodeticArea.js +1 -1
  111. package/geometry/operators/gx/{operatorGeodeticDensifyByLength.js → operatorGeodeticDensify.js} +1 -1
  112. package/geometry/operators/gx/operatorGeodeticDistance.js +1 -1
  113. package/geometry/operators/gx/operatorGeodeticLength.js +1 -1
  114. package/geometry/operators/gx/operatorIntegrate.js +1 -1
  115. package/geometry/operators/gx/operatorIntersection.js +1 -1
  116. package/geometry/operators/gx/operatorLabelPoint.js +1 -1
  117. package/geometry/operators/gx/operatorOffset.js +1 -1
  118. package/geometry/operators/gx/operatorSimplify.js +1 -1
  119. package/geometry/operators/gx/operatorSymmetricDifference.js +1 -1
  120. package/geometry/operators/gx/operatorUnion.js +1 -1
  121. package/geometry/operators/intersectsOperator.js +1 -1
  122. package/geometry/operators/isNearOperator.js +1 -1
  123. package/geometry/operators/lengthOperator.js +5 -0
  124. package/geometry/operators/overlapsOperator.js +1 -1
  125. package/geometry/operators/relateOperator.js +1 -1
  126. package/geometry/operators/reshapeOperator.js +1 -1
  127. package/geometry/operators/touchesOperator.js +1 -1
  128. package/geometry/operators/withinOperator.js +1 -1
  129. package/geometry/support/axisAngleDegrees.js +1 -1
  130. package/geometry/support/meshUtils/loadExternal.js +1 -1
  131. package/interfaces.d.ts +17 -6
  132. package/intl/locale.js +1 -1
  133. package/layers/graphics/OptimizedGeometry.js +1 -1
  134. package/layers/graphics/data/FeatureStore.js +1 -1
  135. package/layers/graphics/sources/csv/csv.js +1 -1
  136. package/layers/graphics/sources/support/CSVSourceWorker.js +1 -1
  137. package/layers/support/ControlPointsGeoreference.js +1 -1
  138. package/layers/support/MediaElementBase.js +1 -1
  139. package/layers/support/mediaUtils.js +1 -1
  140. package/linkChart/LinkChartProperties.js +1 -1
  141. package/linkChart/utils.js +1 -1
  142. package/package.json +2 -2
  143. package/portal/schemas/definitions.js +1 -1
  144. package/rest/print.js +1 -1
  145. package/smartMapping/support/adapters/InMemoryLayerAdapter.js +1 -1
  146. package/support/revision.js +1 -1
  147. package/symbols/cim/cimAnalyzer.js +1 -1
  148. package/views/2d/engine/webgl/mesh/templates/templateUtils.js +1 -1
  149. package/views/2d/engine/webgl/shaderGraph/techniques/text/TextMeshWriter.js +1 -1
  150. package/views/2d/layers/LayerView2D.js +1 -1
  151. package/views/2d/layers/VectorTileLayerView2D.js +1 -1
  152. package/views/3d/environment/Clouds.js +5 -0
  153. package/views/3d/environment/CloudsParameters.js +1 -1
  154. package/views/3d/environment/CloudsPresets.js +1 -1
  155. package/views/3d/environment/CloudsRenderer.js +5 -0
  156. package/views/3d/environment/CloudsTechnique.js +1 -1
  157. package/views/3d/environment/CloudsTechniqueConfiguration.js +1 -1
  158. package/views/3d/environment/EnvironmentRenderer.js +1 -1
  159. package/views/3d/environment/Fog.js +1 -1
  160. package/views/3d/environment/Precipitation.js +1 -1
  161. package/views/3d/environment/PrecipitationTechnique.js +1 -1
  162. package/views/3d/environment/weather.js +1 -1
  163. package/views/3d/layers/BuildingComponentSublayerView3D.js +1 -1
  164. package/views/3d/layers/BuildingSceneLayerView3D.js +1 -1
  165. package/views/3d/layers/DynamicLayerView3D.js +1 -1
  166. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  167. package/views/3d/layers/IntegratedMeshLayerView3D.js +1 -1
  168. package/views/3d/layers/MediaLayerView3D.js +1 -1
  169. package/views/3d/layers/PointCloudLayerView3D.js +1 -1
  170. package/views/3d/layers/SceneLayerView3D.js +1 -1
  171. package/views/3d/layers/TiledLayerView3D.js +1 -1
  172. package/views/3d/layers/VoxelLayerView3D.js +1 -1
  173. package/views/3d/layers/i3s/I3SMeshViewFilter.js +1 -1
  174. package/views/3d/layers/support/DefinitionExpressionSceneLayerView.js +1 -1
  175. package/views/3d/state/ViewStateManager.js +1 -1
  176. package/views/3d/support/cameraUtils.js +1 -1
  177. package/views/3d/support/viewpointUtils.js +1 -1
  178. package/views/3d/terrain/TerrainSurface.js +1 -1
  179. package/views/3d/webgl-engine/collections/Component/Material/ComponentTechniqueConfiguration.js +1 -1
  180. package/views/3d/webgl-engine/core/shaderLibrary/shading/Water.glsl.js +2 -2
  181. package/views/3d/webgl-engine/core/shaderLibrary/util/CloudsParallaxShading.glsl.js +2 -2
  182. package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
  183. package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
  184. package/views/3d/webgl-engine/effects/transparency/OITBlend.glsl.js +5 -0
  185. package/views/3d/webgl-engine/effects/transparency/OITBlend.js +5 -0
  186. package/views/3d/webgl-engine/effects/transparency/OITBlendTechnique.js +5 -0
  187. package/views/3d/webgl-engine/lib/BindParameters.js +1 -1
  188. package/views/3d/webgl-engine/lib/CompositingHelper.js +1 -1
  189. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  190. package/views/3d/webgl-engine/shaders/HighlightApply.glsl.js +1 -1
  191. package/views/3d/webgl-engine/shaders/HighlightDownsample.glsl.js +1 -1
  192. package/views/LinkChartView.js +1 -1
  193. package/views/MapView.js +1 -1
  194. package/views/SceneView.js +1 -1
  195. package/views/View2D.js +1 -1
  196. package/views/animation/pointToPoint/Segment.js +1 -1
  197. package/views/interactive/snapping/featureSources/FeatureServiceSnappingSource.js +1 -1
  198. package/views/webgl/Texture.js +1 -1
  199. package/widgets/BasemapGallery/BasemapGalleryViewModel.js +1 -1
  200. package/widgets/BasemapGallery.js +1 -1
  201. package/widgets/BatchAttributeForm/BatchAttributeFormViewModel.js +1 -1
  202. package/widgets/BatchAttributeForm/templates/BatchAttributeFormElementTemplate.js +1 -1
  203. package/widgets/BatchAttributeForm/templates/BatchAttributeFormTemplate.js +1 -1
  204. package/widgets/BatchAttributeForm/templates/BatchFieldElementTemplate.js +1 -1
  205. package/widgets/BatchAttributeForm/templates/batchAttributeFormTemplateUtils.js +1 -1
  206. package/widgets/Feature/FeatureMedia/pieChart.js +1 -1
  207. package/widgets/Feature/FeatureMedia/xyChart.js +1 -1
  208. package/widgets/FeatureForm/FieldInput.js +1 -1
  209. package/widgets/LayerList/LayerListViewModel.js +1 -1
  210. package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
  211. package/widgets/OrientedImageryViewer/adapters/OrientedImageryViewerViewModelAdapter2D.js +1 -1
  212. package/widgets/OrientedImageryViewer/adapters/OrientedImageryViewerViewModelAdapter3D.js +1 -1
  213. package/widgets/OrientedImageryViewer/constants.js +1 -1
  214. package/widgets/OrientedImageryViewer/css.js +1 -1
  215. package/widgets/OrientedImageryViewer/utils.js +1 -1
  216. package/widgets/OrientedImageryViewer.js +1 -1
  217. package/widgets/Print/CustomTemplate.js +1 -1
  218. package/widgets/Print/PrintViewModel.js +1 -1
  219. package/widgets/ScaleBar/ScaleBarViewModel.js +1 -1
  220. package/widgets/VersionManagement/VersionManagementViewModel.js +1 -1
  221. package/widgets/support/SnappingControls.js +1 -1
  222. package/assets/esri/core/workers/chunks/0cfa9665dab31e5235a8.js +0 -1
  223. package/assets/esri/core/workers/chunks/0d57786a20c675f28653.js +0 -1
  224. package/assets/esri/core/workers/chunks/0eeab9d3dce332669f83.js +0 -1
  225. package/assets/esri/core/workers/chunks/16c9d5572ec94a781ffd.js +0 -1
  226. package/assets/esri/core/workers/chunks/171753192d75729a5f46.js +0 -1
  227. package/assets/esri/core/workers/chunks/22fb5687932019304225.js +0 -1
  228. package/assets/esri/core/workers/chunks/252f7416b9678914a0ac.js +0 -1
  229. package/assets/esri/core/workers/chunks/2606f6a33ea45a124e91.js +0 -1
  230. package/assets/esri/core/workers/chunks/29afd450dee4fda5244f.js +0 -1
  231. package/assets/esri/core/workers/chunks/36e1354a18d1d314bcbc.js +0 -1
  232. package/assets/esri/core/workers/chunks/3b3c8362359a82c66793.js +0 -1
  233. package/assets/esri/core/workers/chunks/481a0b8f8e9cc1ea0c9b.js +0 -1
  234. package/assets/esri/core/workers/chunks/4902e786ab8232e6d3ef.js +0 -1
  235. package/assets/esri/core/workers/chunks/52370857db536d1745e1.js +0 -1
  236. package/assets/esri/core/workers/chunks/5307a9877bdbcabe92ed.js +0 -1
  237. package/assets/esri/core/workers/chunks/5e43cb91bbe20f2d32e3.js +0 -1
  238. package/assets/esri/core/workers/chunks/66fba777d82955387570.js +0 -1
  239. package/assets/esri/core/workers/chunks/67df47efb9a9dfeafee2.js +0 -1
  240. package/assets/esri/core/workers/chunks/6be62448e33baabe028c.js +0 -1
  241. package/assets/esri/core/workers/chunks/878ca47631cf9ad809ea.js +0 -1
  242. package/assets/esri/core/workers/chunks/941fe04f47059074c05b.js +0 -2
  243. package/assets/esri/core/workers/chunks/a6560ff77be29344bc50.js +0 -1
  244. package/assets/esri/core/workers/chunks/a88e3121737124d0485d.js +0 -1
  245. package/assets/esri/core/workers/chunks/b866668f5b7a9913529c.js +0 -1
  246. package/assets/esri/core/workers/chunks/ba561e03df67894e437f.js +0 -2
  247. package/assets/esri/core/workers/chunks/bb335b4299fc3521dd9e.js +0 -1
  248. package/assets/esri/core/workers/chunks/bd2868996acf8aaadf1c.js +0 -1
  249. package/assets/esri/core/workers/chunks/be0b19c95d7ebee1ea01.js +0 -1
  250. package/assets/esri/core/workers/chunks/be777c95d0c04fc352b6.js +0 -1
  251. package/assets/esri/core/workers/chunks/c91397803ee7141e33a9.js +0 -1
  252. package/assets/esri/core/workers/chunks/ea51a7c32f716f4f1a34.js +0 -1
  253. package/assets/esri/core/workers/chunks/eb9c069a04b8d95f96d5.js +0 -1
  254. package/assets/esri/core/workers/chunks/f129f69077523c42ea58.js +0 -1
  255. package/assets/esri/core/workers/chunks/f2191adc8711e1400156.js +0 -1
  256. package/assets/esri/core/workers/chunks/fc12935e50024081a27d.js +0 -1
  257. package/chunks/Distance2DCalculator-BzAEa8Xe.js +0 -5
  258. package/chunks/GeodeticDistanceCalculator-BS_KY66f.js +0 -5
  259. package/chunks/OperatorShapePreservingDensify.js +0 -5
  260. package/geometry/operators/geodeticDensifyByLengthOperator.js +0 -5
  261. package/geometry/operators/gx/operatorShapePreservingDensify.js +0 -5
  262. package/geometry/operators/shapePreservingDensifyOperator.js +0 -5
  263. package/views/3d/environment/CloudsData.js +0 -5
  264. package/views/3d/environment/CloudsGenerator.js +0 -5
  265. package/views/3d/webgl-engine/shaders/OITCompositing.glsl.js +0 -5
  266. package/views/3d/webgl-engine/shaders/OITCompositingTechnique.js +0 -5
  267. /package/assets/esri/core/workers/chunks/{941fe04f47059074c05b.js.LICENSE.txt → bb5a18dd1e6a71905668.js.LICENSE.txt} +0 -0
package/Camera.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{_ as o}from"./chunks/tslib.es6.js";import r from"./CameraLayout.js";import{ClonableMixin as t}from"./core/Clonable.js";import{cyclicalDegrees as e}from"./core/Cyclical.js";import{JSONSupport as s}from"./core/JSONSupport.js";import{clamp as i}from"./core/mathUtils.js";import{property as p}from"./core/accessorSupport/decorators/property.js";import{cast as n}from"./core/accessorSupport/decorators/cast.js";import"./core/RandomLCG.js";import"./core/has.js";import{reader as a}from"./core/accessorSupport/decorators/reader.js";import{subclass as l}from"./core/accessorSupport/decorators/subclass.js";import{writer as c}from"./core/accessorSupport/decorators/writer.js";import{ensureNumber as u}from"./core/accessorSupport/ensureType.js";import m from"./geometry/Point.js";let y=class extends(t(s)){constructor(...o){super(...o),this.position=new m([0,0,0]),this.heading=0,this.tilt=0,this.fov=55,this.layout=new r}normalizeCtorArgs(o,r,t,e){if(o&&"object"==typeof o&&("x"in o||Array.isArray(o))){const s={position:o};return null!=r&&(s.heading=r),null!=t&&(s.tilt=t),null!=e&&(s.fov=e),s}return o}writePosition(o,r,t,e){const s=o.clone();s.x=u(o.x||0),s.y=u(o.y||0),s.z=o.hasZ?u(o.z||0):o.z,r[t]=s.write({},e)}readPosition(o,r){const t=new m;return t.read(o,r),t.x=u(t.x||0),t.y=u(t.y||0),t.z=t.hasZ?u(t.z||0):t.z,t}equals(o){return null!=o&&(this.tilt===o.tilt&&this.heading===o.heading&&this.fov===o.fov&&this.position.equals(o.position)&&this.layout.equals(o.layout))}};o([p({type:m,json:{write:{isRequired:!0}}})],y.prototype,"position",void 0),o([c("position")],y.prototype,"writePosition",null),o([a("position")],y.prototype,"readPosition",null),o([p({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}}),n((o=>e.normalize(u(o))))],y.prototype,"heading",void 0),o([p({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}}),n((o=>i(u(o),-180,180)))],y.prototype,"tilt",void 0),o([p({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}}),n((o=>i(u(o,55),1,170)))],y.prototype,"fov",void 0),o([p({type:r,nonNullable:!0,json:{read:!1,write:!1}})],y.prototype,"layout",void 0),y=o([l("esri.Camera")],y);const d=y;export{d as default};
5
+ import{_ as o}from"./chunks/tslib.es6.js";import r from"./CameraLayout.js";import{ClonableMixin as t}from"./core/Clonable.js";import{cyclicalDegrees as e}from"./core/Cyclical.js";import{JSONSupport as s}from"./core/JSONSupport.js";import{clamp as i}from"./core/mathUtils.js";import{property as p}from"./core/accessorSupport/decorators/property.js";import{cast as n}from"./core/accessorSupport/decorators/cast.js";import"./core/RandomLCG.js";import"./core/has.js";import{reader as a}from"./core/accessorSupport/decorators/reader.js";import{subclass as l}from"./core/accessorSupport/decorators/subclass.js";import{writer as c}from"./core/accessorSupport/decorators/writer.js";import{ensureNumber as u}from"./core/accessorSupport/ensureType.js";import m from"./geometry/Point.js";let y=class extends(t(s)){constructor(...o){super(...o),this.position=new m([0,0,0]),this.heading=0,this.tilt=0,this.fov=55,this.layout=new r}normalizeCtorArgs(o,r,t,e){if(o&&"object"==typeof o&&("x"in o||Array.isArray(o))){const s={position:o};return null!=r&&(s.heading=r),null!=t&&(s.tilt=t),null!=e&&(s.fov=e),s}return o}writePosition(o,r,t,e){const s=o.clone();s.x=u(o.x||0),s.y=u(o.y||0),s.z=o.hasZ?u(o.z||0):o.z,r[t]=s.write({},e)}readPosition(o,r){const t=new m;return t.read(o,r),t.x=u(t.x||0),t.y=u(t.y||0),t.z=t.hasZ?u(t.z||0):t.z,t}equals(o){return null!=o&&(this.tilt===o.tilt&&this.heading===o.heading&&this.fov===o.fov&&this.position.equals(o.position)&&this.layout.equals(o.layout))}};o([p({type:m,json:{write:{isRequired:!0}}})],y.prototype,"position",void 0),o([c("position")],y.prototype,"writePosition",null),o([a("position")],y.prototype,"readPosition",null),o([p({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}}),n((o=>e.normalize(u(o))))],y.prototype,"heading",void 0),o([p({type:Number,nonNullable:!0,json:{write:{isRequired:!0}}}),n((o=>i(u(o),-180,180)))],y.prototype,"tilt",void 0),o([p({type:Number,nonNullable:!0,json:{default:55,write:!0}}),n((o=>i(u(o,55),1,170)))],y.prototype,"fov",void 0),o([p({type:r,nonNullable:!0,json:{read:!1,write:!1}})],y.prototype,"layout",void 0),y=o([l("esri.Camera")],y);const d=y;export{d as default};
package/WebDocument2D.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"./chunks/tslib.es6.js";import{version as t}from"./kernel.js";import r from"./Map.js";import i from"./Viewpoint.js";import{isSome as o}from"./core/arrayUtils.js";import s from"./core/Collection.js";import n from"./core/Error.js";import a from"./core/Loadable.js";import{loadAll as p}from"./core/loadAll.js";import l from"./core/Logger.js";import{destroyMaybe as u}from"./core/maybe.js";import{MultiOriginJSONMixin as m}from"./core/MultiOriginJSONSupport.js";import{EsriPromiseMixin as h}from"./core/Promise.js";import{debounce as c}from"./core/promiseUtils.js";import{whenOnce as d}from"./core/reactiveUtils.js";import{addQueryParameter as g,isDataProtocol as f,dataComponents as b}from"./core/urlUtils.js";import{property as w}from"./core/accessorSupport/decorators/property.js";import"./core/has.js";import{reader as y}from"./core/accessorSupport/decorators/reader.js";import{subclass as A}from"./core/accessorSupport/decorators/subclass.js";import{writer as S}from"./core/accessorSupport/decorators/writer.js";import{readLoadable as _}from"./core/accessorSupport/read.js";import v from"./geometry/SpatialReference.js";import V from"./portal/PortalItem.js";import{typeKeyword as j}from"./portal/support/portalItemUtils.js";import I from"./support/MapFloorInfo.js";import{SaveOperationType as U}from"./webdoc/interfaces.js";import P from"./webdoc/RangeInfo.js";import O from"./webdoc/Widgets.js";import{getOptimalThumbnailSize as F}from"./webdoc/support/thumbnailUtils.js";import{loadFromSource as L}from"./webdoc/support/webdocLoadUtils.js";import{getLayerJSON as R}from"./webdoc/support/writeUtils.js";import k from"./webmap/ApplicationProperties.js";import x from"./webmap/Bookmark.js";import T from"./webmap/InitialViewProperties.js";import{Version as B}from"./webmap/Version.js";import E from"./webmap/background/ColorBackground.js";const N=s.ofType(x),J=new Map([["image/jpeg","jpeg"],["image/jpg","jpg"],["image/png","png"],["image/gif","gif"]]),M="ArcGIS Pro",Z=j.JSAPI;let W=class extends(m(a.LoadableMixin(h(r)))){constructor(e){super(e),this._isAuthoringAppSetByUser=!1,this._isAuthoringAppVersionSetByUser=!1,this._thumbnailFilename=null,this._updateFromPromise=null,this.resourceReferences={portalItem:null,paths:[]},this.applicationProperties=null,this.bookmarks=new N,this.floorInfo=null,this.initialViewProperties=new T,this.portalItem=null,this.sourceVersion=null,this.widgets=null,this._debouncedSaveOperations=c((async(e,t,r)=>{const{save:i,saveAs:o}=await import("./webdoc/support/webdocSaveUtils.js");switch(e){case U.SAVE:return i(this.context,this,t);case U.SAVE_AS:return o(this.context,this,r,t)}})),this.authoringApp=this.authoringAppVersion=null,this._isAuthoringAppSetByUser=this._isAuthoringAppVersionSetByUser=!1}destroy(){this.portalItem=u(this.portalItem)}initialize(){if(this.when().catch((e=>{l.getLogger(this).error("#load()","Failed to load web map",e)})),this.resourceInfo){let t;try{t=this._validateJSON(this.resourceInfo)}catch(e){return void this.addResolvingPromise(Promise.reject(e))}this.read(t)}}set authoringApp(e){this._isAuthoringAppSetByUser=!0,this._set("authoringApp",e)}writeAuthoringApp(e,t){e&&this._isAuthoringAppSetByUser?t.authoringApp=e:t.authoringApp=Z}set authoringAppVersion(e){this._isAuthoringAppVersionSetByUser=!0,this._set("authoringAppVersion",e)}writeAuthoringAppVersion(e,r){e&&this._isAuthoringAppVersionSetByUser?r.authoringAppVersion=e:r.authoringAppVersion=t}readInitialViewProperties(e,t){const r=new T;t.background&&(r.background=E.fromJSON(t.background));const o=t.initialState?.viewpoint;if(o){if(o.rotation){B.parse(t.version||"","webmap").lessThan(2,20)&&t.authoringApp===M&&(o.rotation*=-1)}r.viewpoint=i.fromJSON(o)}return t.mapRangeInfo&&(r.rangeInfo=P.fromJSON(t.mapRangeInfo)),t.spatialReference&&(r.spatialReference=v.fromJSON(t.spatialReference)),t.timeZone&&(r.timeZone=t.timeZone),r}writeInitialViewProperties(e,t,r,i){e&&(e.background?.color&&(t.background=e.background.write({},i)),e.viewpoint&&(t.initialState={viewpoint:e.viewpoint.write({},i)}),e.rangeInfo&&(t.mapRangeInfo=e.rangeInfo.toJSON(i)),e.spatialReference&&(t.spatialReference=e.spatialReference.write({},i)),t.timeZone=e.timeZone)}writeLayers(e,t,r,i){t[r]=this._writeLayers(e,i,"operational-layers")}readSourceVersion(e,t){const[r,i]=t.version.split(".");return new B(parseInt(r,10),parseInt(i,10))}writeSourceVersion(e,t,r){t[r]=`${this.context.currentVersion.major}.${this.context.currentVersion.minor}`}writeTables(e,t,r,i){const o=this._writeLayers(e,i,"tables");o.length&&(t[r]=o)}get thumbnailUrl(){return this.portalItem?.thumbnailUrl||null}set thumbnailUrl(e){e?(this._override("thumbnailUrl",e),this._thumbnailFilename=this._generateCustomThumbnailFilename(e)):this._clearThumbnailOverride()}get updatingFromView(){return!!this._updateFromPromise}load(e){return this.addResolvingPromise(L(this.context,this)),Promise.resolve(this)}loadAll(){return p(this,(e=>{e(this.ground,this.basemap,this.layers,this.tables)}))}read(e,t){t={...t,origin:this.context.origin};const r=this._getAuthoringPropsState();_(this,e,(t=>super.read(e,t)),t),this._restoreAuthoringPropsFromState(r)}write(e,t){if("loaded"!==this.loadStatus){const e=new n("webmap:not-loaded","Web map must be loaded before it can be serialized");throw l.getLogger(this).error("#toJSON()","Web map must be loaded before it can be serialized",this.loadError||this.loadStatus),e}return this._removeDanglingLayerRefs(),t={...t,origin:this.context.origin,restrictedWebMapWriting:!0,webmap:this},super.write(e,t)}async save(e){return this._debouncedSaveOperations(U.SAVE,e)}async saveAs(e,t){return this._debouncedSaveOperations(U.SAVE_AS,t,e)}async updateFrom(e,t){const r=this._updateFromInternal(e,t);this._updateFromPromise=r,await r;r===this._updateFromPromise&&(this._updateFromPromise=null)}getLayerJSONFromResourceInfo(e){const t=this.resourceInfo;return this._collectAllLayersJSON([...t?.baseMap?.baseMapLayers||[],...t?.operationalLayers||[],...this.basemap?.resourceInfo?.data?.baseMapLayers||[]]).find((t=>t.id===e.id))}async updateItemThumbnail(){this.thumbnailUrl&&this._isOverridden("thumbnailUrl")&&(await(this.portalItem?.updateThumbnail({thumbnail:this.thumbnailUrl,filename:this._thumbnailFilename})),this._clearThumbnailOverride())}getThumbnailState(){let e=this.thumbnailUrl;return e&&(e=this._isOverridden("thumbnailUrl")?e:g(e,"w","8192")),{thumbnailUrl:e,filename:this._thumbnailFilename}}restoreThumbnailFromState(e){this.thumbnailUrl=e.thumbnailUrl,this._thumbnailFilename=e.filename}_collectAllLayersJSON(e){return e.reduce(((e,t)=>(e.push(t),"GroupLayer"===t.layerType&&(e=e.concat(this._collectAllLayersJSON(t.layers||[]))),e)),[])}_writeLayers(e,t,r){t={...t,layerContainerType:r};return e.map((e=>R(e,"tables"===r?null:this.getLayerJSONFromResourceInfo(e),t))).filter(o).toArray()}_validateJSON(e){const t=B.parse(e.version||"","webmap");return this.context.currentVersion.validate(t),e.version=`${t.major}.${t.minor}`,e}_removeDanglingLayerRefs(){const e=this.applicationProperties,t=e?.viewing?.search,r=e=>this.allLayers.some((t=>t.id===e));if(t?.layers&&(t.layers=t.layers.filter((e=>r(e.id)))),t?.tables&&(t.tables=t.tables.filter((e=>this.tables.some((t=>t.id===e.id))))),e){const t=e.editing?.locationTracking;t?.info&&!r(t.info.layerId)&&(e.editing=null)}const i="presentation"in this?this.presentation:null,o=i?.slides;o&&o.forEach((e=>{e.visibleLayers&&(e.visibleLayers=e.visibleLayers.filter((e=>r(e.id))))}))}async _updateFromInternal(e,t){if(t??={},await d((()=>e.ready)),this._updateInitialViewProperties(e,t),e.map===this)for(const r of e.allLayerViews)"visible"in r&&"visible"in r.layer&&r._isOverridden("visible")&&(r.layer.visible=r.visible),"featureEffect"in r&&"featureEffect"in r.layer&&r._isOverridden("featureEffect")&&(r.layer.featureEffect=r.featureEffect);await this._updateThumbnailUrl(e,t),this.updateFromView(e)}_updateInitialViewProperties(e,t){if(t.backgroundExcluded||(this.initialViewProperties.background=e.background?.clone()),this.initialViewProperties.spatialReference=e.spatialReference?.clone(),this.initialViewProperties.timeZone=e.timeZone,t.viewpointExcluded||(this.initialViewProperties.viewpoint=new i({rotation:e.rotation,scale:t.scalePreserved?e.scale:null,targetGeometry:this._getViewExtent(e)})),!t.widgetsExcluded)for(const r of e.persistableViewModels)r.updateWebDocument(this)}_getViewExtent(e){const t=e.center.clone().normalize(),r=e.extent.clone(),i=r.width/2;return r.xmin=t.x-i,r.xmax=t.x+i,r}async _updateThumbnailUrl(e,t){if(t.thumbnailExcluded)return;const r=F(e,t.thumbnailSize),i=await e.takeScreenshot({format:"png",width:r.width,height:r.height});this._setAutoGeneratedThumbnail(i.dataUrl)}_setAutoGeneratedThumbnail(e){this.thumbnailUrl=e,this._thumbnailFilename=null}_clearThumbnailOverride(){this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"),this._thumbnailFilename=null}_generateCustomThumbnailFilename(e){if(f(e)){const t=b(e),r=t?.mediaType,i=r&&J.get(r.toLowerCase())||null,o=`thumbnail${Date.now()}`;return i?`${o}.${i}`:o}return null}_getAuthoringPropsState(){return{authoringApp:this.authoringApp,authoringAppVersion:this.authoringAppVersion,isAuthoringAppSetByUser:this._isAuthoringAppSetByUser,isAuthoringAppVersionSetByUser:this._isAuthoringAppVersionSetByUser}}_restoreAuthoringPropsFromState(e){e.isAuthoringAppSetByUser?this.authoringApp=e.authoringApp:this._isAuthoringAppSetByUser=!1,e.isAuthoringAppVersionSetByUser?this.authoringAppVersion=e.authoringAppVersion:this._isAuthoringAppVersionSetByUser=!1}};e([w()],W.prototype,"_updateFromPromise",void 0),e([w({type:k,json:{write:!0}})],W.prototype,"applicationProperties",void 0),e([w({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],W.prototype,"authoringApp",null),e([S("authoringApp")],W.prototype,"writeAuthoringApp",null),e([w({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],W.prototype,"authoringAppVersion",null),e([S("authoringAppVersion")],W.prototype,"writeAuthoringAppVersion",null),e([w({type:N,json:{write:{overridePolicy:e=>({enabled:!!(e&&e.length>0),ignoreOrigin:!0})}}})],W.prototype,"bookmarks",void 0),e([w({type:I,json:{name:"mapFloorInfo",write:!0}})],W.prototype,"floorInfo",void 0),e([w({type:T,nonNullable:!0,json:{read:{source:["background","initialState.viewpoint","mapRangeInfo","spatialReference","timeZone"]},write:{ignoreOrigin:!0,target:{background:{type:E},"initialState.viewpoint":{type:i},mapRangeInfo:{type:P},spatialReference:{type:v},"timeZone:":{type:String}}}}})],W.prototype,"initialViewProperties",void 0),e([y("initialViewProperties")],W.prototype,"readInitialViewProperties",null),e([S("initialViewProperties")],W.prototype,"writeInitialViewProperties",null),e([w({json:{read:!1,write:{target:"operationalLayers",ignoreOrigin:!0}}})],W.prototype,"layers",void 0),e([S("layers")],W.prototype,"writeLayers",null),e([w({type:V})],W.prototype,"portalItem",void 0),e([w()],W.prototype,"resourceInfo",void 0),e([w({readOnly:!0,type:B,json:{read:{source:"version"},write:{allowNull:!0,ignoreOrigin:!0,target:"version",isRequired:!0}}})],W.prototype,"sourceVersion",void 0),e([y("sourceVersion")],W.prototype,"readSourceVersion",null),e([S("sourceVersion")],W.prototype,"writeSourceVersion",null),e([w({json:{read:!1,write:{ignoreOrigin:!0}}})],W.prototype,"tables",void 0),e([S("tables")],W.prototype,"writeTables",null),e([w()],W.prototype,"thumbnailUrl",null),e([w()],W.prototype,"updatingFromView",null),e([w({type:O,json:{write:!0}})],W.prototype,"widgets",void 0),W=e([A("esri.WebDocument2D")],W);const $=W;export{$ as default};
5
+ import{_ as e}from"./chunks/tslib.es6.js";import{version as t}from"./kernel.js";import r from"./Map.js";import i from"./Viewpoint.js";import{isSome as o}from"./core/arrayUtils.js";import s from"./core/Collection.js";import n from"./core/Error.js";import a from"./core/Loadable.js";import{loadAll as p}from"./core/loadAll.js";import l from"./core/Logger.js";import{destroyMaybe as u}from"./core/maybe.js";import{MultiOriginJSONMixin as m}from"./core/MultiOriginJSONSupport.js";import{EsriPromiseMixin as h}from"./core/Promise.js";import{debounce as c}from"./core/promiseUtils.js";import{whenOnce as d}from"./core/reactiveUtils.js";import{addQueryParameter as g,isDataProtocol as f,dataComponents as b}from"./core/urlUtils.js";import{property as y}from"./core/accessorSupport/decorators/property.js";import"./core/has.js";import{reader as w}from"./core/accessorSupport/decorators/reader.js";import{subclass as A}from"./core/accessorSupport/decorators/subclass.js";import{writer as S}from"./core/accessorSupport/decorators/writer.js";import{readLoadable as _}from"./core/accessorSupport/read.js";import v from"./geometry/SpatialReference.js";import V from"./portal/PortalItem.js";import{typeKeyword as j}from"./portal/support/portalItemUtils.js";import I from"./support/MapFloorInfo.js";import{SaveOperationType as U}from"./webdoc/interfaces.js";import P from"./webdoc/RangeInfo.js";import O from"./webdoc/Widgets.js";import{getOptimalThumbnailSize as L}from"./webdoc/support/thumbnailUtils.js";import{loadFromSource as F}from"./webdoc/support/webdocLoadUtils.js";import{getLayerJSON as R}from"./webdoc/support/writeUtils.js";import k from"./webmap/ApplicationProperties.js";import x from"./webmap/Bookmark.js";import T from"./webmap/InitialViewProperties.js";import{Version as B}from"./webmap/Version.js";import E from"./webmap/background/ColorBackground.js";const N=s.ofType(x),J=new Map([["image/jpeg","jpeg"],["image/jpg","jpg"],["image/png","png"],["image/gif","gif"]]),M="ArcGIS Pro",Z=j.JSAPI;let W=class extends(m(a.LoadableMixin(h(r)))){constructor(e){super(e),this._isAuthoringAppSetByUser=!1,this._isAuthoringAppVersionSetByUser=!1,this._thumbnailFilename=null,this._updateFromPromise=null,this.resourceReferences={portalItem:null,paths:[]},this.applicationProperties=null,this.bookmarks=new N,this.floorInfo=null,this.initialViewProperties=new T,this.portalItem=null,this.sourceVersion=null,this.widgets=null,this._debouncedSaveOperations=c((async(e,t,r)=>{const{save:i,saveAs:o}=await import("./webdoc/support/webdocSaveUtils.js");switch(e){case U.SAVE:return i(this.context,this,t);case U.SAVE_AS:return o(this.context,this,r,t)}})),this.authoringApp=this.authoringAppVersion=null,this._isAuthoringAppSetByUser=this._isAuthoringAppVersionSetByUser=!1}destroy(){this.portalItem=u(this.portalItem)}initialize(){if(this.when().catch((e=>{l.getLogger(this).error("#load()","Failed to load web map",e)})),this.resourceInfo){let t;try{t=this._validateJSON(this.resourceInfo)}catch(e){return void this.addResolvingPromise(Promise.reject(e))}this.read(t)}}set authoringApp(e){this._isAuthoringAppSetByUser=!0,this._set("authoringApp",e)}writeAuthoringApp(e,t){e&&this._isAuthoringAppSetByUser?t.authoringApp=e:t.authoringApp=Z}set authoringAppVersion(e){this._isAuthoringAppVersionSetByUser=!0,this._set("authoringAppVersion",e)}writeAuthoringAppVersion(e,r){e&&this._isAuthoringAppVersionSetByUser?r.authoringAppVersion=e:r.authoringAppVersion=t}readInitialViewProperties(e,t){const r=new T;t.background&&(r.background=E.fromJSON(t.background));const o=t.initialState?.viewpoint;if(o){if(o.rotation){B.parse(t.version||"","webmap").lessThan(2,20)&&t.authoringApp===M&&(o.rotation*=-1)}r.viewpoint=i.fromJSON(o)}return t.mapRangeInfo&&(r.rangeInfo=P.fromJSON(t.mapRangeInfo)),t.spatialReference&&(r.spatialReference=v.fromJSON(t.spatialReference)),t.timeZone&&(r.timeZone=t.timeZone),r}writeInitialViewProperties(e,t,r,i){e&&(e.background?.color&&(t.background=e.background.write({},i)),e.viewpoint&&(t.initialState={viewpoint:e.viewpoint.write({},i)}),e.rangeInfo&&(t.mapRangeInfo=e.rangeInfo.toJSON(i)),e.spatialReference&&(t.spatialReference=e.spatialReference.write({},i)),t.timeZone=e.timeZone)}writeLayers(e,t,r,i){t[r]=this._writeLayers(e,i,"operational-layers")}readSourceVersion(e,t){const[r,i]=t.version.split(".");return new B(parseInt(r,10),parseInt(i,10))}writeSourceVersion(e,t,r){t[r]=`${this.context.currentVersion.major}.${this.context.currentVersion.minor}`}writeTables(e,t,r,i){const o=this._writeLayers(e,i,"tables");o.length&&(t[r]=o)}get thumbnailUrl(){return this.portalItem?.thumbnailUrl||null}set thumbnailUrl(e){e?(this._override("thumbnailUrl",e),this._thumbnailFilename=this._generateCustomThumbnailFilename(e)):this._clearThumbnailOverride()}get updatingFromView(){return!!this._updateFromPromise}load(e){return this.addResolvingPromise(F(this.context,this)),Promise.resolve(this)}loadAll(){return p(this,(e=>{e(this.ground,this.basemap,this.layers,this.tables)}))}read(e,t){t={...t,origin:this.context.origin};const r=this._getAuthoringPropsState();_(this,e,(t=>super.read(e,t)),t),this._restoreAuthoringPropsFromState(r)}write(e,t){if("loaded"!==this.loadStatus){const e=new n("webmap:not-loaded","Web map must be loaded before it can be serialized");throw l.getLogger(this).error("#toJSON()","Web map must be loaded before it can be serialized",this.loadError||this.loadStatus),e}return this._removeDanglingLayerRefs(),t={...t,origin:this.context.origin,restrictedWebMapWriting:!0,webmap:this},super.write(e,t)}async save(e){return this._debouncedSaveOperations(U.SAVE,e)}async saveAs(e,t){return this._debouncedSaveOperations(U.SAVE_AS,t,e)}async updateFrom(e,t){const r=this._updateFromInternal(e,t);this._updateFromPromise=r,await r;r===this._updateFromPromise&&(this._updateFromPromise=null)}getLayerJSONFromResourceInfo(e){const t=this.resourceInfo;return this._collectAllLayersJSON([...t?.baseMap?.baseMapLayers||[],...t?.operationalLayers||[],...this.basemap?.resourceInfo?.data?.baseMapLayers||[]]).find((t=>t.id===e.id))}async updateItemThumbnail(){this.thumbnailUrl&&this._isOverridden("thumbnailUrl")&&(await(this.portalItem?.updateThumbnail({thumbnail:this.thumbnailUrl,filename:this._thumbnailFilename})),this._clearThumbnailOverride())}getThumbnailState(){let e=this.thumbnailUrl;return e&&(e=this._isOverridden("thumbnailUrl")?e:g(e,"w","8192")),{thumbnailUrl:e,filename:this._thumbnailFilename}}restoreThumbnailFromState(e){this.thumbnailUrl=e.thumbnailUrl,this._thumbnailFilename=e.filename}_collectAllLayersJSON(e){return e.reduce(((e,t)=>(e.push(t),"GroupLayer"===t.layerType&&(e=e.concat(this._collectAllLayersJSON(t.layers||[]))),e)),[])}_writeLayers(e,t,r){t={...t,layerContainerType:r};return e.map((e=>R(e,"tables"===r?null:this.getLayerJSONFromResourceInfo(e),t))).filter(o).toArray()}_validateJSON(e){const t=B.parse(e.version||"","webmap");return this.context.currentVersion.validate(t),e.version=`${t.major}.${t.minor}`,e}_removeDanglingLayerRefs(){const e=this.applicationProperties,t=e?.viewing?.search,r=e=>this.allLayers.some((t=>t.id===e));if(t?.layers&&(t.layers=t.layers.filter((e=>r(e.id)))),t?.tables&&(t.tables=t.tables.filter((e=>this.tables.some((t=>t.id===e.id))))),e){const t=e.editing?.locationTracking;t?.info&&!r(t.info.layerId)&&(e.editing=null)}const i="presentation"in this?this.presentation:null,o=i?.slides;o&&o.forEach((e=>{e.visibleLayers&&(e.visibleLayers=e.visibleLayers.filter((e=>r(e.id))))}))}async _updateFromInternal(e,t){if(t??={},await d((()=>e.ready)),this._updateInitialViewProperties(e,t),e.map===this)for(const r of e.allLayerViews)"visible"in r&&"visible"in r.layer&&r._isOverridden("visible")&&(r.layer.visible=r.visible),"featureEffect"in r&&"featureEffect"in r.layer&&r._isOverridden("featureEffect")&&(r.layer.featureEffect=r.featureEffect);await this._updateThumbnailUrl(e,t)}_updateInitialViewProperties(e,t){if(t.backgroundExcluded||(this.initialViewProperties.background=e.background?.clone()),this.initialViewProperties.spatialReference=e.spatialReference?.clone(),this.initialViewProperties.timeZone=e.timeZone,t.viewpointExcluded||(this.initialViewProperties.viewpoint=new i({rotation:e.rotation,scale:t.scalePreserved?e.scale:null,targetGeometry:this._getViewExtent(e)})),!t.widgetsExcluded)for(const r of e.persistableViewModels)r.updateWebDocument(this)}_getViewExtent(e){const t=e.center.clone().normalize(),r=e.extent.clone(),i=r.width/2;return r.xmin=t.x-i,r.xmax=t.x+i,r}async _updateThumbnailUrl(e,t){if(t.thumbnailExcluded)return;const r=L(e,t.thumbnailSize),i=await e.takeScreenshot({format:"png",width:r.width,height:r.height});this._setAutoGeneratedThumbnail(i.dataUrl)}_setAutoGeneratedThumbnail(e){this.thumbnailUrl=e,this._thumbnailFilename=null}_clearThumbnailOverride(){this._clearOverride("thumbnailUrl"),this.clear("thumbnailUrl","user"),this._thumbnailFilename=null}_generateCustomThumbnailFilename(e){if(f(e)){const t=b(e),r=t?.mediaType,i=r&&J.get(r.toLowerCase())||null,o=`thumbnail${Date.now()}`;return i?`${o}.${i}`:o}return null}_getAuthoringPropsState(){return{authoringApp:this.authoringApp,authoringAppVersion:this.authoringAppVersion,isAuthoringAppSetByUser:this._isAuthoringAppSetByUser,isAuthoringAppVersionSetByUser:this._isAuthoringAppVersionSetByUser}}_restoreAuthoringPropsFromState(e){e.isAuthoringAppSetByUser?this.authoringApp=e.authoringApp:this._isAuthoringAppSetByUser=!1,e.isAuthoringAppVersionSetByUser?this.authoringAppVersion=e.authoringAppVersion:this._isAuthoringAppVersionSetByUser=!1}};e([y()],W.prototype,"_updateFromPromise",void 0),e([y({type:k,json:{write:!0}})],W.prototype,"applicationProperties",void 0),e([y({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],W.prototype,"authoringApp",null),e([S("authoringApp")],W.prototype,"writeAuthoringApp",null),e([y({type:String,json:{write:{allowNull:!0,ignoreOrigin:!0}}})],W.prototype,"authoringAppVersion",null),e([S("authoringAppVersion")],W.prototype,"writeAuthoringAppVersion",null),e([y({type:N,json:{write:{overridePolicy:e=>({enabled:!!(e&&e.length>0),ignoreOrigin:!0})}}})],W.prototype,"bookmarks",void 0),e([y({type:I,json:{name:"mapFloorInfo",write:!0}})],W.prototype,"floorInfo",void 0),e([y({type:T,nonNullable:!0,json:{read:{source:["background","initialState.viewpoint","mapRangeInfo","spatialReference","timeZone"]},write:{ignoreOrigin:!0,target:{background:{type:E},"initialState.viewpoint":{type:i},mapRangeInfo:{type:P},spatialReference:{type:v},"timeZone:":{type:String}}}}})],W.prototype,"initialViewProperties",void 0),e([w("initialViewProperties")],W.prototype,"readInitialViewProperties",null),e([S("initialViewProperties")],W.prototype,"writeInitialViewProperties",null),e([y({json:{read:!1,write:{target:"operationalLayers",ignoreOrigin:!0}}})],W.prototype,"layers",void 0),e([S("layers")],W.prototype,"writeLayers",null),e([y({type:V})],W.prototype,"portalItem",void 0),e([y()],W.prototype,"resourceInfo",void 0),e([y({readOnly:!0,type:B,json:{read:{source:"version"},write:{allowNull:!0,ignoreOrigin:!0,target:"version",isRequired:!0}}})],W.prototype,"sourceVersion",void 0),e([w("sourceVersion")],W.prototype,"readSourceVersion",null),e([S("sourceVersion")],W.prototype,"writeSourceVersion",null),e([y({json:{read:!1,write:{ignoreOrigin:!0}}})],W.prototype,"tables",void 0),e([S("tables")],W.prototype,"writeTables",null),e([y()],W.prototype,"thumbnailUrl",null),e([y()],W.prototype,"updatingFromView",null),e([y({type:O,json:{write:!0}})],W.prototype,"widgets",void 0),W=e([A("esri.WebDocument2D")],W);const $=W;export{$ as default};
package/WebLinkChart.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{_ as r}from"./chunks/tslib.es6.js";import e from"./WebDocument2D.js";import t from"./core/Error.js";import{property as o}from"./core/accessorSupport/decorators/property.js";import"./core/has.js";import"./core/Logger.js";import"./core/RandomLCG.js";import{subclass as i}from"./core/accessorSupport/decorators/subclass.js";import s from"./linkChart/LinkChartProperties.js";import a from"./webmap/InitialViewProperties.js";import{currentVersion as p}from"./webmap/utils.js";import{Version as n}from"./webmap/Version.js";var c;const m={currentVersion:p,createInitialViewProperties:()=>new a,parseVersion:n.parse,itemType:"Web Link Chart",name:"linkchart",origin:"link-chart"};let l=c=class extends e{constructor(r){super(r),this.mapType="webLinkChart",this.linkChartProperties=new s}get activeLinkChartLayer(){return this.layers.find((({type:r})=>"link-chart"===r))}get context(){return m}static fromJSON(r){if(r)return new c({resourceInfo:r});throw new t("linkchart:empty-resource","Expected a JSON resource but got nothing")}updateFromView(r){this.linkChartProperties.layoutType=r.layoutType}};r([o({readOnly:!0})],l.prototype,"activeLinkChartLayer",null),r([o({json:{write:!0}})],l.prototype,"mapType",void 0),r([o({type:s,nonNullable:!0,json:{write:!0}})],l.prototype,"linkChartProperties",void 0),l=c=r([i("esri.WebLinkChart")],l);const h=l;export{h as default};
5
+ import{_ as r}from"./chunks/tslib.es6.js";import t from"./WebDocument2D.js";import e from"./core/Error.js";import{watch as o}from"./core/reactiveUtils.js";import{property as i}from"./core/accessorSupport/decorators/property.js";import"./core/has.js";import"./core/Logger.js";import"./core/RandomLCG.js";import{subclass as s}from"./core/accessorSupport/decorators/subclass.js";import{OriginId as a}from"./core/accessorSupport/PropertyOrigin.js";import{layoutMap as n}from"./linkChart/enums.js";import p from"./linkChart/LinkChartProperties.js";import c from"./webmap/InitialViewProperties.js";import{currentVersion as m}from"./webmap/utils.js";import{Version as l}from"./webmap/Version.js";var h;const u={currentVersion:m,createInitialViewProperties:()=>new c,parseVersion:l.parse,itemType:"Web Link Chart",name:"linkchart",origin:"link-chart"};let y=h=class extends t{constructor(r){super(r),this.mapType="webLinkChart",this.linkChartProperties=new p}initialize(){this.addHandles(o((()=>this.linkChartProperties.layoutType),(async r=>{if(this.linkChartProperties.originIdOf("layoutType")!==a.LINK_CHART&&n.has(r)){const t=n.get(r);await(this.activeLinkChartLayer?.applyNewLinkChartLayout(t))}})))}get activeLinkChartLayer(){return this.layers.find((({type:r})=>"link-chart"===r))}get context(){return u}static fromJSON(r){if(r)return new h({resourceInfo:r});throw new e("linkchart:empty-resource","Expected a JSON resource but got nothing")}};r([i({readOnly:!0})],y.prototype,"activeLinkChartLayer",null),r([i({json:{write:!0}})],y.prototype,"mapType",void 0),r([i({type:p,nonNullable:!0,json:{write:!0}})],y.prototype,"linkChartProperties",void 0),y=h=r([s("esri.WebLinkChart")],y);const f=y;export{f as default};
package/WebMap.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.31/esri/copyright.txt for details.
4
4
  */
5
- import{_ as o}from"./chunks/tslib.es6.js";import t from"./WebDocument2D.js";import r from"./core/Collection.js";import e from"./core/Error.js";import{loadAll as s}from"./core/loadAll.js";import{property as i}from"./core/accessorSupport/decorators/property.js";import"./core/has.js";import"./core/Logger.js";import"./core/RandomLCG.js";import{subclass as p}from"./core/accessorSupport/decorators/subclass.js";import n from"./networks/UtilityNetwork.js";import m from"./webdoc/GeotriggersInfo.js";import a from"./webdoc/IPSInfo.js";import c from"./webmap/InitialViewProperties.js";import{currentVersion as l}from"./webmap/utils.js";import{Version as f}from"./webmap/Version.js";const u={currentVersion:l,createInitialViewProperties:()=>new c,parseVersion:f.parse,itemType:"Web Map",name:"webmap",origin:"web-map"},w=r.ofType(n);let y=class extends t{constructor(o){super(o),this.geotriggersInfo=null,this.ipsInfo=null,this.presentation=null,this.utilityNetworks=null}destroy(){if(this.utilityNetworks){const o=this.utilityNetworks.removeAll();for(const t of o)t.destroy();this.utilityNetworks.destroy()}}get context(){return u}loadAll(){return s(this,(o=>{o(this.ground,this.basemap,this.layers,this.tables,this.ipsInfo?.positioningService?.portalItem)}))}static fromJSON(o){if(o)return new this({resourceInfo:o});throw new e("webmap:empty-resource","Expected a JSON resource but got nothing")}updateFromView(o){}};y.VERSION=l,o([i({type:m,json:{write:!0}})],y.prototype,"geotriggersInfo",void 0),o([i({type:a,json:{write:!0,name:"mapIPSInfo"}})],y.prototype,"ipsInfo",void 0),o([i({json:{write:!0}})],y.prototype,"presentation",void 0),o([i({type:w,json:{read:!0,write:!0}})],y.prototype,"utilityNetworks",void 0),y=o([p("esri.WebMap")],y);const d=y;export{d as default};
5
+ import{_ as o}from"./chunks/tslib.es6.js";import t from"./WebDocument2D.js";import r from"./core/Collection.js";import e from"./core/Error.js";import{loadAll as s}from"./core/loadAll.js";import{property as i}from"./core/accessorSupport/decorators/property.js";import"./core/has.js";import"./core/Logger.js";import"./core/RandomLCG.js";import{subclass as p}from"./core/accessorSupport/decorators/subclass.js";import n from"./networks/UtilityNetwork.js";import m from"./webdoc/GeotriggersInfo.js";import a from"./webdoc/IPSInfo.js";import c from"./webmap/InitialViewProperties.js";import{currentVersion as l}from"./webmap/utils.js";import{Version as f}from"./webmap/Version.js";const u={currentVersion:l,createInitialViewProperties:()=>new c,parseVersion:f.parse,itemType:"Web Map",name:"webmap",origin:"web-map"},w=r.ofType(n);let y=class extends t{constructor(o){super(o),this.geotriggersInfo=null,this.ipsInfo=null,this.presentation=null,this.utilityNetworks=null}destroy(){if(this.utilityNetworks){const o=this.utilityNetworks.removeAll();for(const t of o)t.destroy();this.utilityNetworks.destroy()}}get context(){return u}loadAll(){return s(this,(o=>{o(this.ground,this.basemap,this.layers,this.tables,this.ipsInfo?.positioningService?.portalItem)}))}static fromJSON(o){if(o)return new this({resourceInfo:o});throw new e("webmap:empty-resource","Expected a JSON resource but got nothing")}};y.VERSION=l,o([i({type:m,json:{write:!0}})],y.prototype,"geotriggersInfo",void 0),o([i({type:a,json:{write:!0,name:"mapIPSInfo"}})],y.prototype,"ipsInfo",void 0),o([i({json:{write:!0}})],y.prototype,"presentation",void 0),o([i({type:w,json:{read:!0,write:!0}})],y.prototype,"utilityNetworks",void 0),y=o([p("esri.WebMap")],y);const j=y;export{j 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.31/esri/copyright.txt for details.
4
4
  */
5
- import e from"../request.js";import t from"./featureSetCollection.js";import{u as a,a0 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(),e.parent.fieldsIndex,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)",i.getFieldsIndex(),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)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{u as a,a0 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)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.31/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import{cloneGeometry as t}from"../../kernel.js";import{SqlError as r,SqlErrorCodes as s,FeatureSetError as a,FeatureSetErrorCodes as i}from"../support/errorsupport.js";import l from"../support/FeatureSet.js";import n from"../support/IdSet.js";import{cloneField as o,FeatureServiceDatabaseType as h,isDate as u,isLuxonDate as c,isArcadeTime as d,isArcadeDate as p,isArcadeDateOnly as f,layerGeometryEsriConstants as g}from"../support/shared.js";import{reformulateWithoutField as N,toWhereClause as _,translateFunctionToDatabaseSpecific as S,makeToday as m,makeSqlFromDateTimeParameter as w,makeTimeString as v,arcadeDateToSqlString as C,arcadeDateOnlyToSqlString as T,convertIntervalToSql as F,combine as W,scanForField as y}from"../support/sqlUtils.js";import{assertIsSome as A}from"../../../core/maybe.js";import{WhereClause as E}from"../../../core/sql/WhereClause.js";import x from"../../../geometry/SpatialReference.js";class D{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class I extends D{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class k extends D{constructor(e,t,r){super(o(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:N(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class b extends D{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,h.Standardised,this.field.name,this.codefield instanceof E?_(this.codefield,h.Standardised):this.codefield,e.parameters);return r.includes(b.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:E.create(r,t._parent.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC)}}evaluateNodeToWhereClause(e,t,a=null,i=null,l){let n,o,h,g;switch(e.type){case"interval":return F(this.evaluateNodeToWhereClause(e.value,t,a,i,l),e.qualifier,e.op);case"case-expression":{let r=" CASE ";"simple"===e.format&&(r+=this.evaluateNodeToWhereClause(e.operand,t,a,b.BADNESS,l));for(let s=0;s<e.clauses.length;s++)r+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[s].operand,t,a,b.BADNESS,l)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[s].value,t,a,b.BADNESS,l);return null!==e.else&&(r+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,a,b.BADNESS,l)),r+=" END ",r}case"parameter":{const r=l[e.value.toLowerCase()];if("string"==typeof r)return"'"+r.toString().replaceAll("'","''")+"'";if(u(r))return w(r,t);if(c(r))return w(r,t);if(d(r))return v(r,t);if(p(r))return C(r,t);if(f(r))return T(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("'","''")+"'"):u(r[s])||c(r[s])?e.push(w(r[s],t)):d(r[s])?e.push(v(r[s],t)):p(r[s])?e.push(C(r[s],t)):f(r[s])?e.push(T(r[s],t)):e.push(r[s].toString());return e}return r.toString()}case"expression-list":o=[];for(const r of e.value)o.push(this.evaluateNodeToWhereClause(r,t,a,i,l));return o;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,a,b.BADNESS,l)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" AND "+this.evaluateNodeToWhereClause(e.right,t,a,i,l)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" OR "+this.evaluateNodeToWhereClause(e.right,t,a,i,l)+") ";case"IS":if("null"!==e.right.type)throw new r(s.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new r(s.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IS NOT NULL )";case"IN":if(n=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const r=[];let s=!0;for(const t of e.right.value){if("string"!==t.type){s=!1;break}if(void 0===this.lkp[t.value]){s=!1;break}r.push(this.lkp[t.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+r.join(",")+")) "}return n=this.evaluateNodeToWhereClause(e.right,t,a,i,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+n.join(",")+")) "}return g=this.evaluateNodeToWhereClause(e.right,t,a,i,l),Array.isArray(g)?" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+g.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+g+")) ";case"NOT IN":if(n=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const r=[];let s=!0;for(const t of e.right.value){if("string"!==t.type){s=!1;break}if(void 0===this.lkp[t.value]){s=!1;break}r.push(this.lkp[t.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+r.join(",")+")) "}return n=this.evaluateNodeToWhereClause(e.right,t,a,i,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+n.join(",")+")) "}return g=this.evaluateNodeToWhereClause(e.right,t,a,i,l),Array.isArray(g)?" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+g.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+g+")) ";case"BETWEEN":return h=this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" BETWEEN "+h[0]+" AND "+h[1]+" ) ";case"NOTBETWEEN":return h=this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" NOT BETWEEN "+h[0]+" AND "+h[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") ";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" ("+i+" "+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+" "+i+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") "}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 m("date"===e.mode,t);case"column-reference":return a&&a.toLowerCase()===e.column.toLowerCase()?"("+i+")":e.column;case"data-type":return e.value;case"function":{const r=this.evaluateNodeToWhereClause(e.args,t,a,b.BADNESS,l);return S(e.name,r,t)}}throw new r(s.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof E?this.reverseLkp[E.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}}b.BADNESS="_!!!_BAD_LKP_!!!!";class B extends D{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:N(e,this.field.name,_(this._sql,h.Standardised),t.getFieldsIndex())}}extractValue(e){return E.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}class L extends l{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 x({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=g.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),A(t),this._wset=new n(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,i){const l=[];-1!==s&&void 0===this._featureCache[s]&&l.push(s);const o=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(r,o))return await this._expandPagedSet(r,o,0,0,i),this._getFeatures(r,s,a,i);let h=0;for(let e=r._lastFetchedIndex;e<r._known.length&&(h++,h<=a&&(r._lastFetchedIndex+=1),!(void 0===this._featureCache[r._known[e]]&&(r._known[e]!==s&&l.push(r._known[e]),l.length>=o)));e++);if(0===l.length)return"success";r=new n([],l,r._ordered,null);const u=Math.min(l.length,a);await(this._parent?._getFeatures(r,-1,u,i)),this._checkCancelled(i);const c=[];for(let e=0;e<u;e++){const t=this._parent?._featureFromCache(l[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:l[e]})}for(const n of c){const r=[];for(const e of this.adaptedFields)r[e.field.name]=e.extractValue(n);this._featureCache[n.id]=new e({attributes:r,geometry:t(n.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new a(i.NeverReach)}async _getFilteredSet(e,t,r,s,a){let i=!1;const l=this._reformulateWithoutAdaptions(r);i=l.cannot,r=l.where;let o=!1;if(null!==s){o=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof I)&&!0===s.scanForField(t.field.name)){if(!(t instanceof k)){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=W(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const h=await this._parent._getFilteredSet(e,t,r,s,a);let u;return this._checkCancelled(a),u=!0===i?new n(h._candidates.slice().concat(h._known.slice()),[],!0===o&&h._ordered,this._clonePageDefinition(h.pagesDefinition)):new n(h._candidates.slice(),h._known.slice(),!0===o&&h._ordered,this._clonePageDefinition(h.pagesDefinition)),u}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!==e)for(const r of this.adaptedFields)if(!0===y(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=W(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const h=await this._parent._stat(e,t,r,s,a,i,l);return!1===h.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:h}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 I))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=W(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,r,s,l,n,o){if(null===this._parent)throw new a(i.NeverReach);const h=[];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 a(i.NeverReach);const r=e.clone();r.workingexpr=t.where,h.push(r)}else h.push(e)}const u=this._reformulateWithoutAdaptions(l);if(u.cannot)throw new a(i.NeverReach);return null!==(l=u.where)?null!==this._extraFilter&&(l=W(this._extraFilter,l)):l=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,h,r,s,l,n,o)}}export{L as AdaptedFeatureSet,D as AdaptedField,k as FieldRename,I as OriginalField,B as SqlExpressionAdapted,b as StringToCodeAdapted};
5
+ import e from"../../../Graphic.js";import{cloneGeometry as t}from"../../kernel.js";import{SqlError as r,SqlErrorCodes as s,FeatureSetError as a,FeatureSetErrorCodes as i}from"../support/errorsupport.js";import l from"../support/FeatureSet.js";import n from"../support/IdSet.js";import{cloneField as o,FeatureServiceDatabaseType as u,isDate as h,isLuxonDate as c,isArcadeTime as d,isArcadeDate as p,isArcadeDateOnly as f,layerGeometryEsriConstants as g}from"../support/shared.js";import{reformulateWithoutField as N,toWhereClause as _,translateFunctionToDatabaseSpecific as S,makeToday as m,makeSqlFromDateTimeParameter as w,makeTimeString as v,arcadeDateToSqlString as C,arcadeDateOnlyToSqlString as T,convertIntervalToSql as F,combine as W,scanForField as y}from"../support/sqlUtils.js";import{assertIsSome as A}from"../../../core/maybe.js";import{WhereClause as E}from"../../../core/sql/WhereClause.js";import x from"../../../geometry/SpatialReference.js";class D{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class I extends D{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class k extends D{constructor(e,t,r){super(o(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:N(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class b extends D{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,u.Standardised,this.field.name,this.codefield instanceof E?_(this.codefield,u.Standardised):this.codefield,e.parameters);return r.includes(b.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:E.create(r,{fieldsIndex:t._parent.getFieldsIndex(),timeZone:t.dateFieldsTimeZoneDefaultUTC})}}evaluateNodeToWhereClause(e,t,a=null,i=null,l){let n,o,u,g;switch(e.type){case"interval":return F(this.evaluateNodeToWhereClause(e.value,t,a,i,l),e.qualifier,e.op);case"case-expression":{let r=" CASE ";"simple"===e.format&&(r+=this.evaluateNodeToWhereClause(e.operand,t,a,b.BADNESS,l));for(let s=0;s<e.clauses.length;s++)r+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[s].operand,t,a,b.BADNESS,l)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[s].value,t,a,b.BADNESS,l);return null!==e.else&&(r+=" ELSE "+this.evaluateNodeToWhereClause(e.else,t,a,b.BADNESS,l)),r+=" END ",r}case"parameter":{const r=l[e.value.toLowerCase()];if("string"==typeof r)return"'"+r.toString().replaceAll("'","''")+"'";if(h(r))return w(r,t);if(c(r))return w(r,t);if(d(r))return v(r,t);if(p(r))return C(r,t);if(f(r))return T(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("'","''")+"'"):h(r[s])||c(r[s])?e.push(w(r[s],t)):d(r[s])?e.push(v(r[s],t)):p(r[s])?e.push(C(r[s],t)):f(r[s])?e.push(T(r[s],t)):e.push(r[s].toString());return e}return r.toString()}case"expression-list":o=[];for(const r of e.value)o.push(this.evaluateNodeToWhereClause(r,t,a,i,l));return o;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,t,a,b.BADNESS,l)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" AND "+this.evaluateNodeToWhereClause(e.right,t,a,i,l)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" OR "+this.evaluateNodeToWhereClause(e.right,t,a,i,l)+") ";case"IS":if("null"!==e.right.type)throw new r(s.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new r(s.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IS NOT NULL )";case"IN":if(n=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const r=[];let s=!0;for(const t of e.right.value){if("string"!==t.type){s=!1;break}if(void 0===this.lkp[t.value]){s=!1;break}r.push(this.lkp[t.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+r.join(",")+")) "}return n=this.evaluateNodeToWhereClause(e.right,t,a,i,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+n.join(",")+")) "}return g=this.evaluateNodeToWhereClause(e.right,t,a,i,l),Array.isArray(g)?" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+g.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" IN ("+g+")) ";case"NOT IN":if(n=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const r=[];let s=!0;for(const t of e.right.value){if("string"!==t.type){s=!1;break}if(void 0===this.lkp[t.value]){s=!1;break}r.push(this.lkp[t.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+r.join(",")+")) "}return n=this.evaluateNodeToWhereClause(e.right,t,a,i,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+n.join(",")+")) "}return g=this.evaluateNodeToWhereClause(e.right,t,a,i,l),Array.isArray(g)?" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+g.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,i,l)+" NOT IN ("+g+")) ";case"BETWEEN":return u=this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" BETWEEN "+u[0]+" AND "+u[1]+" ) ";case"NOTBETWEEN":return u=this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)," ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" NOT BETWEEN "+u[0]+" AND "+u[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") ";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" ("+i+" "+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+" "+i+") ";return" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,t,a,b.BADNESS,l)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,t,a,b.BADNESS,l)+") "}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 m("date"===e.mode,t);case"current-user":return"CURRENT_USER";case"column-reference":return a&&a.toLowerCase()===e.column.toLowerCase()?"("+i+")":e.column;case"data-type":return e.value;case"function":{const r=this.evaluateNodeToWhereClause(e.args,t,a,b.BADNESS,l);return S(e.name,r,t)}}throw new r(s.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof E?this.reverseLkp[E.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}}b.BADNESS="_!!!_BAD_LKP_!!!!";class B extends D{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:N(e,this.field.name,_(this._sql,u.Standardised),t.getFieldsIndex())}}extractValue(e){return E.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}class L extends l{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 x({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=g.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),A(t),this._wset=new n(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,i){const l=[];-1!==s&&void 0===this._featureCache[s]&&l.push(s);const o=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(r,o))return await this._expandPagedSet(r,o,0,0,i),this._getFeatures(r,s,a,i);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&&l.push(r._known[e]),l.length>=o)));e++);if(0===l.length)return"success";r=new n([],l,r._ordered,null);const h=Math.min(l.length,a);await(this._parent?._getFeatures(r,-1,h,i)),this._checkCancelled(i);const c=[];for(let e=0;e<h;e++){const t=this._parent?._featureFromCache(l[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:l[e]})}for(const n of c){const r=[];for(const e of this.adaptedFields)r[e.field.name]=e.extractValue(n);this._featureCache[n.id]=new e({attributes:r,geometry:t(n.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new a(i.NeverReach)}async _getFilteredSet(e,t,r,s,a){let i=!1;const l=this._reformulateWithoutAdaptions(r);i=l.cannot,r=l.where;let o=!1;if(null!==s){o=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof I)&&!0===s.scanForField(t.field.name)){if(!(t instanceof k)){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=W(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===i?new n(u._candidates.slice().concat(u._known.slice()),[],!0===o&&u._ordered,this._clonePageDefinition(u.pagesDefinition)):new n(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===y(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=W(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 I))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=W(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,r,s,l,n,o){if(null===this._parent)throw new a(i.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 a(i.NeverReach);const r=e.clone();r.workingexpr=t.where,u.push(r)}else u.push(e)}const h=this._reformulateWithoutAdaptions(l);if(h.cannot)throw new a(i.NeverReach);return null!==(l=h.where)?null!==this._extraFilter&&(l=W(this._extraFilter,l)):l=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,u,r,s,l,n,o)}}export{L as AdaptedFeatureSet,D as AdaptedField,k as FieldRename,I as OriginalField,B 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.31/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import{a1 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 l,FeatureSetErrorCodes as o}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{calculateStat as w}from"../support/stats.js";import F from"../support/StatsField.js";import{createMD5Hash as I,outputTypes as S}from"../../../core/MD5.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as k}from"../../../core/sql/TimeOnly.js";import{WhereClause as j}from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import C 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 F;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof j?i.expression:j.create(i.expression,r,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 j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new F;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=j.create(this._parent.objectIdField,this._parent.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new C;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 l(o.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 C;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 C;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 l(o.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 l(o.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 l(o.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,l){if(""!==e)return new u([],[],!0,null);let o=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(l),o=!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)),o}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)o=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})}o=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 o}_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 l=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:l};else{if(l!==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:l},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(l){a(l)}}_calculateFieldStat(e,t,i){const s=[];for(let n=0;n<e.features.length;n++)if(null!==t.workingexpr){const i=t.workingexpr.calculateValue(e.features[n]);null!==i&&(i instanceof x||i instanceof k?s.push(i.toNumber()):i instanceof D?s.push(i.toMilliseconds()):s.push(i))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=w("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=w("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=w("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=w("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=w("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=w("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:j.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 I(t,S.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{a1 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 l,FeatureSetErrorCodes as o}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{calculateStat as w}from"../support/stats.js";import F from"../support/StatsField.js";import{createMD5Hash as I,outputTypes as S}from"../../../core/MD5.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as k}from"../../../core/sql/TimeOnly.js";import{WhereClause as j}from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import C 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 F;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof j?i.expression:j.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 j?i.expression:j.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 A({wkid:4326});this.fields=[];const a=new F;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=j.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 C;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 l(o.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 C;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 C;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 l(o.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 l(o.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 l(o.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,l){if(""!==e)return new u([],[],!0,null);let o=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(l),o=!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)),o}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)o=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})}o=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 o}_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 l=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:l};else{if(l!==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:l},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(l){a(l)}}_calculateFieldStat(e,t,i){const s=[];for(let n=0;n<e.features.length;n++)if(null!==t.workingexpr){const i=t.workingexpr.calculateValue(e.features[n]);null!==i&&(i instanceof x||i instanceof k?s.push(i.toNumber()):i instanceof D?s.push(i.toMilliseconds()):s.push(i))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=w("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=w("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=w("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=w("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=w("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=w("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:j.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 I(t,S.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.31/esri/copyright.txt for details.
4
4
  */
5
- import e from"./cache.js";import{FeatureSetError as t,FeatureSetErrorCodes as s}from"./errorsupport.js";import n from"./FeatureSetIterator.js";import i from"./IdSet.js";import{FeatureServiceDatabaseType as a,layerGeometryEsriConstants as r,IdState as l,convertSquareUnitsToCode as u,convertLinearUnitsToCode as h,esriFieldToJson as o,layerGeometryEsriRestConstants as c}from"./shared.js";import{max as d,min as _,sum as p,variance as f,stdev as m,mean as g,distinct as y,count as F}from"./stats.js";import{isPromiseLike as T}from"../../../core/promiseUtils.js";import{WhereClause as b}from"../../../core/sql/WhereClause.js";import{union as I,geodesicArea as w,planarArea as S,geodesicLength as D,planarLength as P}from"../../../geometry/geometryEngineAsync.js";import k from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/FieldsIndex.js";class x{constructor(e){this.recentlyUsedQueries=null,this.featureSetQueryInterceptor=null,this._idstates=[],this._parent=null,this._wset=null,this._mainSetInUse=null,this._maxProcessing=200,this._maxQuery=500,this._totalCount=-1,this._databaseType=a.NotEvaluated,this._databaseTypeProbed=null,this.declaredRootClass="esri.arcade.featureset.support.FeatureSet",this._featureCache=[],this.typeIdField=null,this.types=null,this.subtypeField=null,this.subtypes=null,this.fields=null,this.geometryType="",this.objectIdField="",this.globalIdField="",this.spatialReference=null,this.hasM=!1,this.hasZ=!1,this._transparent=!1,this.loaded=!1,this._loadPromise=null,this._fieldsIndex=null,this.fsetInfo=null,e?.lrucache&&(this.recentlyUsedQueries=e.lrucache),e?.interceptor&&(this.featureSetQueryInterceptor=e.interceptor)}optimisePagingFeatureQueries(e){this._parent&&this._parent.optimisePagingFeatureQueries(e)}_hasMemorySource(){return!0}prop(e,t){return void 0===t?this[e]:(void 0!==this[e]&&(this[e]=t),this)}end(){return null!==this._parent&&!0===this._parent._transparent?this._parent.end():this._parent}_ensureLoaded(){return this.load()}load(){return null===this._loadPromise&&(this._loadPromise=this.loadImpl()),this._loadPromise}async loadImpl(){return!0===this._parent?.loaded?(this._initialiseFeatureSet(),this):(await(this._parent?.load()),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types,this.subtypeField=this._parent.subtypeField,this.subtypes=this._parent.subtypes):(this.fields=[],this.typeIdField="",this.subtypeField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new k({wkid:4326}),this.geometryType=r.point)}getField(e,t){let s;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(s=t),!!s)))),s}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=C.fromLayer({timeInfo:this.timeInfo,editFieldsInfo:this.editFieldsInfo,dateFieldsTimeZone:this.dateFieldsTimeZone,datesInUnknownTimezone:this.datesInUnknownTimezone,fields:this.fields})),this._fieldsIndex}_maxProcessingRate(){return null!==this._parent?Math.min(this._maxProcessing,this._parent._maxProcessingRate()):Math.min(this._maxProcessing,this._maxQueryRate())}_maxQueryRate(){return null!==this._parent?Math.max(this._maxQuery,this._parent._maxQueryRate()):this._maxQuery}_checkCancelled(e){if(null!=e&&e.aborted)throw new t(s.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,s,n,i){return null!==this._parent&&this._parent._canDoAggregates(e,t,s,n,i)}async _getAggregatePagesDataSourceDefinition(e,n,i,a,r,l,u){if(null===this._parent)throw new t(s.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,n,i,a,r,l,u)}async _getAgregagtePhysicalPage(e,n,i){if(null===this._parent)throw new t(s.NeverReach);return this._parent._getAgregagtePhysicalPage(e,n,i)}async databaseType(){if(this._databaseType===a.NotEvaluated){if(null!==e.applicationCache){const t=e.applicationCache.getDatabaseType(this._cacheableFeatureSetSourceKey());if(null!==t)return t}if(null!==this._databaseTypeProbed)return this._databaseTypeProbed;try{this._databaseTypeProbed=this._getDatabaseTypeImpl(),null!==e.applicationCache&&e.applicationCache.setDatabaseType(this._cacheableFeatureSetSourceKey(),this._databaseTypeProbed)}catch(t){throw null!==e.applicationCache&&e.applicationCache.clearDatabaseType(this._cacheableFeatureSetSourceKey()),t}return this._databaseTypeProbed}return this._databaseType}async _getDatabaseTypeImpl(){const e=[{thetype:a.SqlServer,testwhere:"(CAST( '2015-01-01' as DATETIME) = CAST( '2015-01-01' as DATETIME)) AND OBJECTID<0"},{thetype:a.Oracle,testwhere:"(TO_DATE('2003-11-18','YYYY-MM-DD') = TO_DATE('2003-11-18','YYYY-MM-DD')) AND OBJECTID<0"},{thetype:a.StandardisedNoInterval,testwhere:"(date '2015-01-01 10:10:10' = date '2015-01-01 10:10:10') AND OBJECTID<0"}];for(const t of e){if(!0===await this._runDatabaseProbe(t.testwhere))return t.thetype}return a.StandardisedNoInterval}_cacheableFeatureSetSourceKey(){return"MUSTBESET"}async _runDatabaseProbe(e){if(null!==this._parent)return this._parent._runDatabaseProbe(e);throw new t(s.NotImplemented)}isTable(){return this._parent?.isTable()??!1}_featureFromCache(e){if(void 0!==this._featureCache[e])return this._featureCache[e]}_isInFeatureSet(e){return l.Unknown}_getSet(e){throw new t(s.NotImplemented)}async _getFeature(e,n,i){if(this._checkCancelled(i),void 0!==this._featureFromCache(n))return this._featureFromCache(n);if(await this._getFeatures(e,n,this._maxProcessingRate(),i),this._checkCancelled(i),void 0!==this._featureFromCache(n))return this._featureFromCache(n);throw new t(s.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const s=new i([],e,!1,null),n=[];await this._getFeatures(s,-1,e.length,t),this._checkCancelled(t);for(const i of e)void 0!==this._featureFromCache(i)&&n.push(this._featureFromCache(i));return n}async _getFeatures(e,t,s,n){return"success"}_getFilteredSet(e,n,i,a,r){throw new t(s.NotImplemented)}async _refineSetBlock(e,t,s){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,s),this._refineSetBlock(e,t,s);this._checkCancelled(s);const n=e._candidates.length;this._refineKnowns(e,t);let i=n-e._candidates.length;if(0===e._candidates.length)return e;if(i>=t)return e;if(await this._refineIfParentKnown(e,t-i,s),this._checkCancelled(s),this._refineKnowns(e,t-i),i=n-e._candidates.length,i<t&&e._candidates.length>0){const n=t-i,a=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(a,a.length>n?n:e._candidates.length,s),this._checkCancelled(s),this._refineKnowns(e,t-i),e}return e}_fetchAndRefineFeatures(e,t,s){return null}_prepareFetchAndRefineSet(e){const t=[];for(let s=0;s<e.length;s++)this._isPhysicalFeature(e[s])&&t.push(e[s]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let s=0,n=null;const i=[];t=this._maxQueryRate();for(let a=0;a<e._candidates.length&&"GETPAGES"!==e._candidates[a];a++){let r=!1;const u=this._candidateIdTransform(e._candidates[a]);u!==e._candidates[a]&&(r=!0);const h=this._isInFeatureSet(u);if(h===l.InFeatureSet)!0===r?e._known.includes(u)||(e._known.push(u),s+=1):(e._known.push(e._candidates[a]),s+=1),null===n?n={start:a,end:a}:n.end===a-1?n.end=a:(i.push(n),n={start:a,end:a});else if(h===l.NotInFeatureSet)null===n?n={start:a,end:a}:n.end===a-1?n.end=a:(i.push(n),n={start:a,end:a}),s+=1;else if(h===l.Unknown&&(s+=1,!0===e._ordered))break;if(s>=t)break}null!==n&&i.push(n);for(let a=i.length-1;a>=0;a--)e._candidates.splice(i[a].start,i[a].end-i[a].start+1)}_refineIfParentKnown(e,t,s){const n=new i([],[],e._ordered,null);return n._candidates=e._candidates.slice(),this._parent._refineSetBlock(n,t,s)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let s=0;for(let n=e._lastFetchedIndex;n<e._known.length;n++){if("GETPAGES"===e._known[n])return!0;if(void 0===this._featureCache[e._known[n]]&&(s+=1,s>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let s=0;for(let n=0;n<e._candidates.length;n++){if("GETPAGES"===e._candidates[n])return!0;if(s+=1,s>=t)break}return!1}async _expandPagedSet(e,n,i,a,r){if(null===this._parent)throw new t(s.NotImplemented);return this._parent._expandPagedSet(e,n,i,a,r)}async _expandPagedSetFeatureSet(e,t,s,n,i){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(n=1),0===n&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(n=2),0===n)return"finished";const a=await this._getPage(e,n,i);return s+a<t?this._expandPagedSet(e,t,s+a,0,i):"success"}async _getPage(e,t,s){const n=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){n.length=n.length-1;let t=0;for(let i=0;i<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+i>=e.pagesDefinition.internal.set.length);i++)n[n.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+i],t++;e.pagesDefinition.resultOffset+=t;let s=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(s=!0),!1===s&&n.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,s),this._getPage(e,t,s)}_getPhysicalPage(e,t,s){return null}_clonePageDefinition(e){return null===this._parent?null:this._parent._clonePageDefinition(e)}_first(e){return this.iterator(e).next()}first(e){return this._first(e)}async calculateStatistic(e,t,s,n){await this._ensureLoaded();let i=await this._stat(e,t,"",null,null,s,n);return!1===i.calculated&&(i=await this._manualStat(e,t,s,n)),i.result}async _manualStat(e,t,s,n){let i=null;switch(e.toLowerCase()){case"count":return i=await F(this,n),{calculated:!0,result:i};case"distinct":return i=await y(this,t,s,n),{calculated:!0,result:i};case"avg":case"mean":return i=await g(this,t,n),{calculated:!0,result:i};case"stdev":return i=await m(this,t,n),{calculated:!0,result:i};case"variance":return i=await f(this,t,n),{calculated:!0,result:i};case"sum":return i=await p(this,t,n),{calculated:!0,result:i};case"min":return i=await _(this,t,n),{calculated:!0,result:i};case"max":return i=await d(this,t,n),{calculated:!0,result:i};default:return{calculated:!0,result:0}}}async _stat(e,t,s,n,i,a,r){const l=await this._parent._stat(e,t,s,n,i,a,r);return!1===l.calculated?null===i&&""===s&&null===n?this._manualStat(e,t,a,r):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),s=[];return new Promise(((e,n)=>{this._unionShapeInBatches(s,t,e,n)}))}_unionAllGeom(e){return new Promise(((t,s)=>{const n=this.iterator(this._defaultTracker(e)),i=[];this._unionShapeInBatches(i,n,t,s)}))}_unionShapeInBatches(e,t,s,n){t.next().then((i=>{try{null!==i&&null!==i.geometry&&e.push(i.geometry),e.length>30||null===i&&e.length>1?I(e).then((a=>{try{null===i?s(a):(e=[a],this._unionShapeInBatches(e,t,s,n))}catch(r){n(r)}}),n):null===i?1===e.length?s(e[0]):s(null):this._unionShapeInBatches(e,t,s,n)}catch(a){n(a)}}),n)}iterator(e){return new n(this,e)}intersection(e,t=!1){return x._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,s=!0){return x._featuresetFunctions.difference.bind(this)(e,t,s)}symmetricDifference(e,t=!1,s=!0){return x._featuresetFunctions.symmetricDifference.bind(this)(e,t,s)}morphShape(e,t,s="unknown",n=null){return x._featuresetFunctions.morphShape.bind(this)(e,t,s,n)}morphShapeAndAttributes(e,t,s="unknown"){return x._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,s)}union(e,t=!1){return x._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return x._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return x._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return x._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return x._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return x._featuresetFunctions.relate.bind(this)(e,t)}within(e){return x._featuresetFunctions.within.bind(this)(e)}touches(e){return x._featuresetFunctions.touches.bind(this)(e)}top(e){return x._featuresetFunctions.top.bind(this)(e)}crosses(e){return x._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,s,n=!0){return x._featuresetFunctions.buffer.bind(this)(e,t,s,n)}filter(e,t=null){return x._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return x._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return x._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return x._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,s){return new Promise(((n,i)=>{this._reduceImpl(this.iterator(this._defaultTracker(s)),e,t,0,n,i,0)}))}_reduceImpl(e,t,s,n,i,a,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._reduceImpl(e,t,s,n,i,a,r)}));e.next().then((l=>{try{if(null===l)i(s);else{const u=t(s,l,n,this);T(u)?u.then((s=>{this._reduceImpl(e,t,s,n+1,i,a,r)}),a):this._reduceImpl(e,t,u,n+1,i,a,r)}}catch(u){a(u)}}),a)}catch(l){a(l)}}removeField(e){return x._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,s=null){return x._featuresetFunctions.addField.bind(this)(e,t,s)}sumArea(e,t=!1,s){const n=u(e);return this.reduce(((e,s)=>null===s.geometry?0:t?w(s.geometry,n).then((t=>e+t)):S(s.geometry,n).then((t=>e+t))),0,s)}sumLength(e,t=!1,s){const n=h(e);return this.reduce(((e,s)=>null===s.geometry?0:t?D(s.geometry,n).then((t=>e+t)):P(s.geometry,n).then((t=>e+t))),0,s)}async distinct(e,t=1e3,s=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(i,s),this.calculateStatistic("distinct",i,t,this._defaultTracker(n))}async min(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("min",n,-1,this._defaultTracker(s))}async max(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("max",n,-1,this._defaultTracker(s))}async avg(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("avg",n,-1,this._defaultTracker(s))}async sum(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("sum",n,-1,this._defaultTracker(s))}async stdev(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("stdev",n,-1,this._defaultTracker(s))}async variance(e,t=null,s){await this.load();const n=b.create(e,this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC);return v(n,t),this.calculateStatistic("variance",n,-1,this._defaultTracker(s))}async count(e){return await this.load(),this.calculateStatistic("count",b.create("1",this.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((s,n)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,s,n,0)}))}_forEachImpl(e,t,s,n,i,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._forEachImpl(e,t,s,n,i,a)}),0);e.next().then((r=>{try{if(null===r)n(s);else{const l=t(r);null==l?this._forEachImpl(e,t,s,n,i,a):T(l)?l.then((()=>{try{this._forEachImpl(e,t,s,n,i,a)}catch(r){i(r)}}),i):this._forEachImpl(e,t,s,n,i,a)}}catch(l){i(l)}}),i)}catch(r){i(r)}}convertToJSON(e){const t={layerDefinition:{geometryType:this.geometryType,fields:[]},featureSet:{features:[],geometryType:this.geometryType}};for(let s=0;s<this.fields.length;s++)t.layerDefinition.fields.push(o(this.fields[s]));return this.reduce(((e,s)=>{const n={geometry:s.geometry?.toJSON(),attributes:{}};for(const t in s.attributes)n.attributes[t]=s.attributes[t];return t.featureSet.features.push(n),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,s,n,i){return this._parent.queryAttachments(e,t,s,n,i)}serviceUrl(){return this._parent.serviceUrl()}subtypeMetaData(){return this.subtypeField&&this.subtypes?{subtypeField:this.subtypeField,subtypes:this.subtypes?this.subtypes.map((e=>({name:e.name,code:e.code}))):[]}:this.typeIdField?{subtypeField:this.typeIdField,subtypes:this.types?this.types.map((e=>({name:e.name,code:e.id}))):[]}:null}relationshipMetaData(){return this._parent.relationshipMetaData()}get gdbVersion(){return this._parent?this._parent.gdbVersion:""}schema(){const e=[];for(const t of this.fields)e.push(o(t));return{objectIdField:this.objectIdField,globalIdField:this.globalIdField,geometryType:void 0===c[this.geometryType]?"esriGeometryNull":c[this.geometryType],fields:e}}async convertToText(e,t){if("schema"===e)return await this._ensureLoaded(),JSON.stringify(this.schema());if("featureset"===e){await this._ensureLoaded();const e=[];await this.reduce(((t,s)=>{const n={geometry:s.geometry?s.geometry.toJSON():null,attributes:s.attributes};return null!==n.geometry&&n.geometry.spatialReference&&delete n.geometry.spatialReference,e.push(n),1}),0,t);const s=this.schema();return s.features=e,s.spatialReference=this.spatialReference.toJSON(),JSON.stringify(s)}return this.castToText()}getFeatureByObjectId(e,t){return this._parent.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._parent.getOwningSystemUrl()}getIdentityUser(){return this._parent.getIdentityUser()}getRootFeatureSet(){return null!==this._parent?this._parent.getRootFeatureSet():this}getDataSourceFeatureSet(){return null!==this._parent?this._parent.getDataSourceFeatureSet():this}castAsJson(e=null){return"keeptype"===e?.featureset?this:"none"===e?.featureset?null:{type:"FeatureSet"}}async castAsJsonAsync(e=null,t=null){if("keeptype"===t?.featureset)return this;if("schema"===t?.featureset)return await this._ensureLoaded(),JSON.parse(JSON.stringify(this.schema()));if("none"===t?.featureset)return null;await this._ensureLoaded();const s=[];await this.reduce(((e,n)=>{const i={geometry:n.geometry?!0===t?.keepGeometryType?n.geometry:n.geometry.toJSON():null,attributes:n.attributes};return null!==i.geometry&&i.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete i.geometry.spatialReference,s.push(i),1}),0,e);const n=this.schema();return n.features=s,n.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),n}fieldTimeZone(e){return this.getFieldsIndex().getTimeZone(e)}get preferredTimeZone(){return this._parent?.preferredTimeZone??null}get dateFieldsTimeZone(){return this._parent?.dateFieldsTimeZone??null}get dateFieldsTimeZoneDefaultUTC(){if(this.datesInUnknownTimezone)return"unknown";const e=this.dateFieldsTimeZone??"UTC";return""===e?"UTC":e}get datesInUnknownTimezone(){return this._parent.datesInUnknownTimezone}get editFieldsInfo(){return this._parent?.editFieldsInfo??null}get timeInfo(){return this._parent?.timeInfo??null}set featureSetInfo(e){this.fsetInfo=e}async getFeatureSetInfo(){return this.fsetInfo??await(this._parent?.getFeatureSetInfo())??null}}function v(e,t){if(null!==t){const s={};for(const e in t)s[e.toLowerCase()]=t[e];e.parameters=s}}x._featuresetFunctions={};export{x as default};
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=[],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.31/esri/copyright.txt for details.
4
4
  */
5
- import{SqlError as e,SqlErrorCodes as t}from"./errorsupport.js";import{FeatureServiceDatabaseType as r}from"./shared.js";import{toWhereClauseFromTree as n}from"./sqlUtils.js";import{WhereClause as 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 e(t.MissingStatisticParameters);const a=i.create(n(s.parseTree.args.value[0],r.Standardised,s.parameters),s.fieldsIndex,s.timeZone);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(r,n,o,l){const p=new a;p.field=r;const f=i.create(n,o,l),u=s(f);if(null===u)throw new e(t.UnsupportedSqlFunction,{function:""});const c=u.name.toUpperCase().trim();if("MIN"===c){if(p.typeofstat="MIN",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:"min"})}else if("MAX"===c){if(p.typeofstat="MAX",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:"max"})}else if("COUNT"===c)p.typeofstat="COUNT",p.workingexpr=u.expr;else if("STDEV"===c){if(p.typeofstat="STDDEV",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:"stdev"})}else if("SUM"===c){if(p.typeofstat="SUM",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:"sum"})}else if("MEAN"===c){if(p.typeofstat="AVG",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:c})}else if("AVG"===c){if(p.typeofstat="AVG",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:"avg"})}else{if("VAR"!==c)throw new e(t.UnsupportedSqlFunction,{function:c});if(p.typeofstat="VAR",p.workingexpr=u.expr,null===f)throw new e(t.InvalidFunctionParameters,{function:"var"})}return p}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};
5
+ import{SqlError as e,SqlErrorCodes as t}from"./errorsupport.js";import{FeatureServiceDatabaseType as r}from"./shared.js";import{toWhereClauseFromTree as n}from"./sqlUtils.js";import{WhereClause as 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 e(t.MissingStatisticParameters);const a=i.create(n(s.parseTree.args.value[0],r.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(r,n,o,l){const f=new a;f.field=r;const u=i.create(n,{fieldsIndex:o,timeZone:l}),p=s(u);if(null===p)throw new e(t.UnsupportedSqlFunction,{function:""});const c=p.name.toUpperCase().trim();if("MIN"===c){if(f.typeofstat="MIN",f.workingexpr=p.expr,null===u)throw new e(t.InvalidFunctionParameters,{function:"min"})}else if("MAX"===c){if(f.typeofstat="MAX",f.workingexpr=p.expr,null===u)throw new e(t.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 e(t.InvalidFunctionParameters,{function:"stdev"})}else if("SUM"===c){if(f.typeofstat="SUM",f.workingexpr=p.expr,null===u)throw new e(t.InvalidFunctionParameters,{function:"sum"})}else if("MEAN"===c){if(f.typeofstat="AVG",f.workingexpr=p.expr,null===u)throw new e(t.InvalidFunctionParameters,{function:c})}else if("AVG"===c){if(f.typeofstat="AVG",f.workingexpr=p.expr,null===u)throw new e(t.InvalidFunctionParameters,{function:"avg"})}else{if("VAR"!==c)throw new e(t.UnsupportedSqlFunction,{function:c});if(f.typeofstat="VAR",f.workingexpr=p.expr,null===u)throw new e(t.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.31/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as e}from"../../ArcadeDate.js";import{SqlError as r,SqlErrorCodes as t}from"./errorsupport.js";import{FeatureServiceDatabaseType as a,isDate as s,isLuxonDate as n,isArcadeTime as c,isArcadeDate as i,isArcadeDateOnly as o}from"./shared.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 p(e,r){return h(e?.parseTree,r,e?.parameters)}function f(e,r,t){return h(e,r,t)}function m(e,r,t,s){return l.create(h(e.parseTree,a.Standardised,e.parameters,r,t),s,e.timeZone)}function g(e,r,t="AND"){return l.create("(("+p(e,a.Standardised)+")"+t+"("+p(r,a.Standardised)+"))",e.fieldsIndex,e.timeZone)}function h(e,u,l,d=null,p=null){let f,m,g,L;switch(e.type){case"interval":return F(h(e.value,u,l,d,p),e.qualifier,e.op);case"case-expression":{let r=" CASE ";"simple"===e.format&&(r+=h(e.operand,u,l,d,p));for(let t=0;t<e.clauses.length;t++)r+=" WHEN "+h(e.clauses[t].operand,u,l,d,p)+" THEN "+h(e.clauses[t].value,u,l,d,p);return null!==e.else&&(r+=" ELSE "+h(e.else,u,l,d,p)),r+=" END ",r}case"parameter":{const r=l[e.value.toLowerCase()];if("string"==typeof r){return"'"+l[e.value.toLowerCase()].toString().replaceAll("'","''")+"'"}if(s(r))return w(r,u);if(n(r))return w(r,u);if(c(r))return E(r,u);if(i(r))return T(r,u);if(o(r))return S(r,u);if(Array.isArray(r)){const e=[];for(let t=0;t<r.length;t++)"string"==typeof r[t]?e.push("'"+r[t].toString().replaceAll("'","''")+"'"):s(r[t])||n(r[t])?e.push(w(r[t],u)):c(r[t])?e.push(E(r[t],u)):i(r[t])?e.push(T(r[t],u)):o(r[t])?e.push(S(r[t],u)):e.push(r[t].toString());return e}return r.toString()}case"expression-list":m=[];for(const r of e.value)m.push(h(r,u,l,d,p));return m;case"unary-expression":return" ( NOT "+h(e.expr,u,l,d,p)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+h(e.left,u,l,d,p)+" AND "+h(e.right,u,l,d,p)+") ";case"OR":return" ("+h(e.left,u,l,d,p)+" OR "+h(e.right,u,l,d,p)+") ";case"IS":if("null"!==e.right.type)throw new r(t.UnsupportedIsRhs);return" ("+h(e.left,u,l,d,p)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new r(t.UnsupportedIsRhs);return" ("+h(e.left,u,l,d,p)+" IS NOT NULL )";case"IN":return f=[],"expression-list"===e.right.type?(f=h(e.right,u,l,d,p)," ("+h(e.left,u,l,d,p)+" IN ("+f.join(",")+")) "):(L=h(e.right,u,l,d,p),Array.isArray(L)?" ("+h(e.left,u,l,d,p)+" IN ("+L.join(",")+")) ":" ("+h(e.left,u,l,d,p)+" IN ("+L+")) ");case"NOT IN":return f=[],"expression-list"===e.right.type?(f=h(e.right,u,l,d,p)," ("+h(e.left,u,l,d,p)+" NOT IN ("+f.join(",")+")) "):(L=h(e.right,u,l,d,p),Array.isArray(L)?" ("+h(e.left,u,l,d,p)+" NOT IN ("+L.join(",")+")) ":" ("+h(e.left,u,l,d,p)+" NOT IN ("+L+")) ");case"BETWEEN":return g=h(e.right,u,l,d,p)," ("+h(e.left,u,l,d,p)+" BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"NOTBETWEEN":return g=h(e.right,u,l,d,p)," ("+h(e.left,u,l,d,p)+" NOT BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"LIKE":return""!==e.escape?" ("+h(e.left,u,l,d,p)+" LIKE "+h(e.right,u,l,d,p)+" ESCAPE '"+e.escape+"') ":" ("+h(e.left,u,l,d,p)+" LIKE "+h(e.right,u,l,d,p)+") ";case"NOT LIKE":return""!==e.escape?" ("+h(e.left,u,l,d,p)+" NOT LIKE "+h(e.right,u,l,d,p)+" ESCAPE '"+e.escape+"') ":" ("+h(e.left,u,l,d,p)+" NOT LIKE "+h(e.right,u,l,d,p)+") ";case"<>":case"<":case">":case">=":case"<=":case"=":case"*":case"-":case"+":case"/":return" ("+h(e.left,u,l,d,p)+" "+e.operator+" "+h(e.right,u,l,d,p)+") ";case"||":return" ("+h(e.left,u,l,d,p)+" "+(u===a.SqlServer?"+":e.operator)+" "+h(e.right,u,l,d,p)+") "}throw new r(t.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 A("date"===e.mode,u);case"column-reference":return d?d.toLowerCase()===e.column.toLowerCase()?"("+p+")":!0===e.delimited?`"${e.column.split('"').join('""')}"`:e.column:e.column;case"data-type":return e.value;case"function":{const r=h(e.args,u,l,d,p);return y(e.name,r,u)}}throw new r(t.UnsupportedSyntax,{node:e.type})}function y(e,s,n){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!==s.length)throw new r(t.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${s[0]})`;case"ceiling":case"ceil":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"ceiling"});switch(n){case a.Standardised:case a.StandardisedNoInterval:}return"CEILING("+s[0]+")";case"mod":case"power":case"nullif":if(2!==s.length)throw new r(t.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${s[0]},${s[1]})`;case"round":if(2===s.length)return"ROUND("+s[0]+","+s[1]+")";if(1===s.length)return"ROUND("+s[0]+")";throw new r(t.InvalidFunctionParameters,{function:"round"});case"truncate":if(s.length<1||s.length>2)throw new r(t.InvalidFunctionParameters,{function:"truncate"});return n===a.SqlServer?"ROUND("+s[0]+(1===s.length?"0":","+s[1])+",1)":"TRUNCATE("+s[0]+(1===s.length?")":","+s[1]+")");case"char_length":case"len":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"char_length"});switch(n){case a.SqlServer:return"LEN("+s[0]+")";case a.Oracle:return"LENGTH("+s[0]+")";default:return"CHAR_LENGTH("+s[0]+")"}case"coalesce":case"concat":{if(s.length<1)throw new r(t.InvalidFunctionParameters,{function:e.toLowerCase()});let a=e.toUpperCase().trim()+"(";for(let e=0;e<s.length;e++)0!==e&&(a+=","),a+=s[e];return a+=")",a}case"lower":case"lcase":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"lower"});return"LOWER("+s[0]+")";case"upper":case"ucase":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"upper"});return"UPPER("+s[0]+")";case"substring":{let e="";switch(n){case a.Oracle:return e="SUBSTR("+s[0]+","+s[1],3===s.length&&(e+=","+s[2]),e+=")",e;case a.SqlServer:return e=3===s.length?"SUBSTRING("+s[0]+","+s[1]+","+s[2]+")":"SUBSTRING("+s[0]+", "+s[1]+", LEN("+s[0]+") - "+s[1]+")",e;default:return e="SUBSTRING("+s[0]+" FROM "+s[1],3===s.length&&(e+=" FOR "+s[2]),e+=")",e}}case"extract":return"EXTRACT("+s[0].replaceAll("'","")+" FROM "+s[1]+")";case"cast":{let e="";switch(n){case a.Oracle:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`;case a.Postgres:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`;case a.SqlServer:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`;default:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`}}}throw new r(t.InvalidFunctionParameters,{function:e})}function T(e,r){const t=e.toDateTime(),s=0===t.hour&&0===t.minute&&0===t.second&&0===t.millisecond;switch(r){case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:return s?`date '${t.toFormat("yyyy-LL-dd")}'`:`timestamp '${t.toFormat("yyyy-LL-dd HH:mm:ss")}'`;case a.Oracle:return s?`TO_DATE('${t.toFormat("yyyy-LL-dd")}','YYYY-MM-DD')`:`TO_DATE('${t.toFormat("yyyy-LL-dd HH:mm:ss")}','YYYY-MM-DD HH24:MI:SS')`;case a.SqlServer:return`'${t.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;case a.PGDB:return`#${t.toFormat(s?"LL-dd-yyyy":"LL-dd-yyyy HH:mm:ss")}#`;case a.Postgres:return`TIMESTAMP '${t.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;default:return`timestamp '${t.toFormat("yyyy-LL-dd HH:mm:ss")}'`}}function S(e,r){switch(r){case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:return e.toSQLWithKeyword();case a.Oracle:return`TO_DATE('${e.toFormat("Y-MM-DD")}'`;case a.SqlServer:return`'${e.toFormat("Y-MM-DD")}'`;case a.PGDB:return`#${e.toFormat("Y-MM-DD")}#`;case a.Postgres:return`TIMESTAMP '${e.toFormat("Y-MM-DD")}'`;default:return e.toSQLWithKeyword()}}function E(e,r){switch(e instanceof u&&(e=e.toStorageString()),r){case a.Oracle:return`TO_DATE('${e}', 'HH24:MI:SS')`;case a.SqlServer:return`'${e}'`;case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:case a.Postgres:default:return`time '${e}'`}}function w(r,t){return T(e.dateTimeToArcadeDate(n(r)?r:d.fromJSDate(r)),t)}function A(e,r){switch(r){case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:case a.Oracle:return e?"CURRENT_DATE":"CURRENT_TIMESTAMP";case a.SqlServer:return e?"CAST(GETDATE() AS DATE)":"GETDATE()";case a.PGDB:case a.Postgres:default:return e?"CURRENT_DATE":"CURRENT_TIMESTAMP"}}function L(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(I(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 I(e,a,n,u){let l;switch(a.type){case"interval":return"integer";case"case-expression":{const r=[];if("simple"===a.format){for(let t=0;t<a.clauses.length;t++)r.push(I(e,a.clauses[t].value,n,u));null!==a.else&&r.push(I(e,a.else,n,u))}else{for(let t=0;t<a.clauses.length;t++)r.push(I(e,a.clauses[t].value,n,u));null!==a.else&&r.push(I(e,a.else,n,u))}return b(r)}case"parameter":{const e=u[a.value.toLowerCase()];if(void 0===e&&n){const e=n[a.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(s(e))return"date";if(i(e))return"date";if(o(e))return"date-only";if(c(e))return"time-only";if("number"==typeof e)return e%1==0?"integer":"double"}return void 0===e?"":e}case"expression-list":{const r=[];for(const t of a.value)r.push(I(e,t,n,u));return r}case"unary-expression":return"boolean";case"binary-expression":switch(a.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"!==a.right.type)throw new r(t.UnsupportedIsRhs);return"boolean";case"*":case"-":case"+":case"/":return b([I(e,a.left,n,u),I(e,a.right,n,u)]);case"||":return"string";default:throw new r(t.UnsupportedOperator,{operator:a.operator})}case"null":return"";case"boolean":return"boolean";case"string":return"string";case"number":return null===a.value?"":a.value%1==0?"integer":"double";case"date":return"date";case"timestamp":return a.withtimezone?"timestamp-offset":"date";case"time":return"time-only";case"current-time":return"date";case"column-reference":{const r=e[a.column.toLowerCase()];return void 0===r?"":r}case"function":switch(a.name.toLowerCase()){case"cast":switch(a.args?.value[1]?.value.type??""){case"integer":case"smallint":return"integer";case"real":case"float":return"double";case"date":case"timestamp":return!0===a.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=I(e,a.args,n,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=I(e,a.args,n,u),Array.isArray(l)&&(l=b(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=I(e,a.args,n,u),Array.isArray(l)?l.length>0?l[0]:"":l}return""}throw new r(t.UnsupportedSyntax,{node:a.type})}const N={boolean:1,string:2,integer:3,double:4,date:5};function b(e){if(e){let r="";for(const t of e)""!==t&&(r=""===r||N[r]<N[t]?t:r);return r}return""}function v(e,r){return O(e.parseTree,r)}function D(e){return"column-reference"===e?.parseTree.type}function O(e,r){if(null==e)return!1;switch(e.type){case"when-clause":return O(e.operand,r)||O(e.value,r);case"case-expression":for(const t of e.clauses)if(O(t,r))return!0;return!("simple"!==e.format||!O(e.operand,r))||!(null===e.else||!O(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(O(t,r))return!0;return!1;case"unary-expression":return O(e.expr,r);case"binary-expression":return O(e.left,r)||O(e.right,r);case"column-reference":return r.toLowerCase()===e.column.toLowerCase();case"function":return O(e.args,r)}return!1}function R(e){let r="";return r+=e.period.toUpperCase(),r}function F(e,r,t){let a="";return a="interval-period"===r.type?R(r):R(r.start)+" TO "+R(r.end),"INTERVAL "+t+" "+e+" "+a}export{S as arcadeDateOnlyToSqlString,T as arcadeDateToSqlString,g as combine,F as convertIntervalToSql,D as isSingleField,w as makeSqlFromDateTimeParameter,E as makeTimeString,A as makeToday,L as predictType,m as reformulateWithoutField,v as scanForField,p as toWhereClause,f as toWhereClauseFromTree,y as translateFunctionToDatabaseSpecific};
5
+ import{ArcadeDate as e}from"../../ArcadeDate.js";import{SqlError as r,SqlErrorCodes as t}from"./errorsupport.js";import{FeatureServiceDatabaseType as a,isDate as s,isLuxonDate as n,isArcadeTime as c,isArcadeDate as i,isArcadeDateOnly as o}from"./shared.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 h(e?.parseTree,r,e?.parameters)}function p(e,r,t){return h(e,r,t)}function m(e,r,t,s){const n=h(e.parseTree,a.Standardised,e.parameters,r,t);return l.create(n,{fieldsIndex:s,timeZone:e.timeZone,currentUser:e.currentUser})}function g(e,r,t="AND"){return l.create("(("+f(e,a.Standardised)+")"+t+"("+f(r,a.Standardised)+"))",{fieldsIndex:e.fieldsIndex,timeZone:e.timeZone,currentUser:e.currentUser})}function h(e,u,l,d=null,f=null){let p,m,g,A;switch(e.type){case"interval":return F(h(e.value,u,l,d,f),e.qualifier,e.op);case"case-expression":{let r=" CASE ";"simple"===e.format&&(r+=h(e.operand,u,l,d,f));for(let t=0;t<e.clauses.length;t++)r+=" WHEN "+h(e.clauses[t].operand,u,l,d,f)+" THEN "+h(e.clauses[t].value,u,l,d,f);return null!==e.else&&(r+=" ELSE "+h(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(s(r))return w(r,u);if(n(r))return w(r,u);if(c(r))return E(r,u);if(i(r))return T(r,u);if(o(r))return S(r,u);if(Array.isArray(r)){const e=[];for(let t=0;t<r.length;t++)"string"==typeof r[t]?e.push("'"+r[t].toString().replaceAll("'","''")+"'"):s(r[t])||n(r[t])?e.push(w(r[t],u)):c(r[t])?e.push(E(r[t],u)):i(r[t])?e.push(T(r[t],u)):o(r[t])?e.push(S(r[t],u)):e.push(r[t].toString());return e}return r.toString()}case"expression-list":m=[];for(const r of e.value)m.push(h(r,u,l,d,f));return m;case"unary-expression":return" ( NOT "+h(e.expr,u,l,d,f)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+h(e.left,u,l,d,f)+" AND "+h(e.right,u,l,d,f)+") ";case"OR":return" ("+h(e.left,u,l,d,f)+" OR "+h(e.right,u,l,d,f)+") ";case"IS":if("null"!==e.right.type)throw new r(t.UnsupportedIsRhs);return" ("+h(e.left,u,l,d,f)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new r(t.UnsupportedIsRhs);return" ("+h(e.left,u,l,d,f)+" IS NOT NULL )";case"IN":return p=[],"expression-list"===e.right.type?(p=h(e.right,u,l,d,f)," ("+h(e.left,u,l,d,f)+" IN ("+p.join(",")+")) "):(A=h(e.right,u,l,d,f),Array.isArray(A)?" ("+h(e.left,u,l,d,f)+" IN ("+A.join(",")+")) ":" ("+h(e.left,u,l,d,f)+" IN ("+A+")) ");case"NOT IN":return p=[],"expression-list"===e.right.type?(p=h(e.right,u,l,d,f)," ("+h(e.left,u,l,d,f)+" NOT IN ("+p.join(",")+")) "):(A=h(e.right,u,l,d,f),Array.isArray(A)?" ("+h(e.left,u,l,d,f)+" NOT IN ("+A.join(",")+")) ":" ("+h(e.left,u,l,d,f)+" NOT IN ("+A+")) ");case"BETWEEN":return g=h(e.right,u,l,d,f)," ("+h(e.left,u,l,d,f)+" BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"NOTBETWEEN":return g=h(e.right,u,l,d,f)," ("+h(e.left,u,l,d,f)+" NOT BETWEEN "+g[0]+" AND "+g[1]+" ) ";case"LIKE":return""!==e.escape?" ("+h(e.left,u,l,d,f)+" LIKE "+h(e.right,u,l,d,f)+" ESCAPE '"+e.escape+"') ":" ("+h(e.left,u,l,d,f)+" LIKE "+h(e.right,u,l,d,f)+") ";case"NOT LIKE":return""!==e.escape?" ("+h(e.left,u,l,d,f)+" NOT LIKE "+h(e.right,u,l,d,f)+" ESCAPE '"+e.escape+"') ":" ("+h(e.left,u,l,d,f)+" NOT LIKE "+h(e.right,u,l,d,f)+") ";case"<>":case"<":case">":case">=":case"<=":case"=":case"*":case"-":case"+":case"/":return" ("+h(e.left,u,l,d,f)+" "+e.operator+" "+h(e.right,u,l,d,f)+") ";case"||":return" ("+h(e.left,u,l,d,f)+" "+(u===a.SqlServer?"+":e.operator)+" "+h(e.right,u,l,d,f)+") "}throw new r(t.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 I("date"===e.mode,u);case"current-user":return"CURRENT_USER";case"column-reference":return d?d.toLowerCase()===e.column.toLowerCase()?"("+f+")":!0===e.delimited?`"${e.column.split('"').join('""')}"`:e.column:e.column;case"data-type":return e.value;case"function":{const r=h(e.args,u,l,d,f);return y(e.name,r,u)}}throw new r(t.UnsupportedSyntax,{node:e.type})}function y(e,s,n){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!==s.length)throw new r(t.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${s[0]})`;case"ceiling":case"ceil":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"ceiling"});switch(n){case a.Standardised:case a.StandardisedNoInterval:}return"CEILING("+s[0]+")";case"mod":case"power":case"nullif":if(2!==s.length)throw new r(t.InvalidFunctionParameters,{function:e.toLowerCase().trim()});return`${e.toUpperCase().trim()}(${s[0]},${s[1]})`;case"round":if(2===s.length)return"ROUND("+s[0]+","+s[1]+")";if(1===s.length)return"ROUND("+s[0]+")";throw new r(t.InvalidFunctionParameters,{function:"round"});case"truncate":if(s.length<1||s.length>2)throw new r(t.InvalidFunctionParameters,{function:"truncate"});return n===a.SqlServer?"ROUND("+s[0]+(1===s.length?"0":","+s[1])+",1)":"TRUNCATE("+s[0]+(1===s.length?")":","+s[1]+")");case"char_length":case"len":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"char_length"});switch(n){case a.SqlServer:return"LEN("+s[0]+")";case a.Oracle:return"LENGTH("+s[0]+")";default:return"CHAR_LENGTH("+s[0]+")"}case"coalesce":case"concat":{if(s.length<1)throw new r(t.InvalidFunctionParameters,{function:e.toLowerCase()});let a=e.toUpperCase().trim()+"(";for(let e=0;e<s.length;e++)0!==e&&(a+=","),a+=s[e];return a+=")",a}case"lower":case"lcase":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"lower"});return"LOWER("+s[0]+")";case"upper":case"ucase":if(1!==s.length)throw new r(t.InvalidFunctionParameters,{function:"upper"});return"UPPER("+s[0]+")";case"substring":{let e="";switch(n){case a.Oracle:return e="SUBSTR("+s[0]+","+s[1],3===s.length&&(e+=","+s[2]),e+=")",e;case a.SqlServer:return e=3===s.length?"SUBSTRING("+s[0]+","+s[1]+","+s[2]+")":"SUBSTRING("+s[0]+", "+s[1]+", LEN("+s[0]+") - "+s[1]+")",e;default:return e="SUBSTRING("+s[0]+" FROM "+s[1],3===s.length&&(e+=" FOR "+s[2]),e+=")",e}}case"extract":return"EXTRACT("+s[0].replaceAll("'","")+" FROM "+s[1]+")";case"cast":{let e="";switch(n){case a.Oracle:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`;case a.Postgres:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`;case a.SqlServer:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`;default:switch(s[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("+s[1].size.toString()+")"}return`CAST(${s[0]} AS ${e})`}}}throw new r(t.InvalidFunctionParameters,{function:e})}function T(e,r){const t=e.toDateTime(),s=0===t.hour&&0===t.minute&&0===t.second&&0===t.millisecond;switch(r){case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:return s?`date '${t.toFormat("yyyy-LL-dd")}'`:`timestamp '${t.toFormat("yyyy-LL-dd HH:mm:ss")}'`;case a.Oracle:return s?`TO_DATE('${t.toFormat("yyyy-LL-dd")}','YYYY-MM-DD')`:`TO_DATE('${t.toFormat("yyyy-LL-dd HH:mm:ss")}','YYYY-MM-DD HH24:MI:SS')`;case a.SqlServer:return`'${t.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;case a.PGDB:return`#${t.toFormat(s?"LL-dd-yyyy":"LL-dd-yyyy HH:mm:ss")}#`;case a.Postgres:return`TIMESTAMP '${t.toFormat(s?"yyyy-LL-dd":"yyyy-LL-dd HH:mm:ss")}'`;default:return`timestamp '${t.toFormat("yyyy-LL-dd HH:mm:ss")}'`}}function S(e,r){switch(r){case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:return e.toSQLWithKeyword();case a.Oracle:return`TO_DATE('${e.toFormat("Y-MM-DD")}'`;case a.SqlServer:return`'${e.toFormat("Y-MM-DD")}'`;case a.PGDB:return`#${e.toFormat("Y-MM-DD")}#`;case a.Postgres:return`TIMESTAMP '${e.toFormat("Y-MM-DD")}'`;default:return e.toSQLWithKeyword()}}function E(e,r){switch(e instanceof u&&(e=e.toStorageString()),r){case a.Oracle:return`TO_DATE('${e}', 'HH24:MI:SS')`;case a.SqlServer:return`'${e}'`;case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:case a.Postgres:default:return`time '${e}'`}}function w(r,t){return T(e.dateTimeToArcadeDate(n(r)?r:d.fromJSDate(r)),t)}function I(e,r){switch(r){case a.FILEGDB:case a.Standardised:case a.StandardisedNoInterval:case a.Oracle:return e?"CURRENT_DATE":"CURRENT_TIMESTAMP";case a.SqlServer:return e?"CAST(GETDATE() AS DATE)":"GETDATE()";case a.PGDB:case a.Postgres:default:return e?"CURRENT_DATE":"CURRENT_TIMESTAMP"}}function A(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(L(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 L(e,a,n,u){let l;switch(a.type){case"interval":return"integer";case"case-expression":{const r=[];if("simple"===a.format){for(let t=0;t<a.clauses.length;t++)r.push(L(e,a.clauses[t].value,n,u));null!==a.else&&r.push(L(e,a.else,n,u))}else{for(let t=0;t<a.clauses.length;t++)r.push(L(e,a.clauses[t].value,n,u));null!==a.else&&r.push(L(e,a.else,n,u))}return b(r)}case"parameter":{const e=u[a.value.toLowerCase()];if(void 0===e&&n){const e=n[a.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(s(e))return"date";if(i(e))return"date";if(o(e))return"date-only";if(c(e))return"time-only";if("number"==typeof e)return e%1==0?"integer":"double"}return void 0===e?"":e}case"expression-list":{const r=[];for(const t of a.value)r.push(L(e,t,n,u));return r}case"unary-expression":return"boolean";case"binary-expression":switch(a.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"!==a.right.type)throw new r(t.UnsupportedIsRhs);return"boolean";case"*":case"-":case"+":case"/":return b([L(e,a.left,n,u),L(e,a.right,n,u)]);case"||":return"string";default:throw new r(t.UnsupportedOperator,{operator:a.operator})}case"null":return"";case"boolean":return"boolean";case"string":return"string";case"number":return null===a.value?"":a.value%1==0?"integer":"double";case"date":return"date";case"timestamp":return a.withtimezone?"timestamp-offset":"date";case"time":return"time-only";case"current-time":return"date";case"current-user":return"string";case"column-reference":{const r=e[a.column.toLowerCase()];return void 0===r?"":r}case"function":switch(a.name.toLowerCase()){case"cast":switch(a.args?.value[1]?.value.type??""){case"integer":case"smallint":return"integer";case"real":case"float":return"double";case"date":case"timestamp":return!0===a.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=L(e,a.args,n,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=L(e,a.args,n,u),Array.isArray(l)&&(l=b(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=L(e,a.args,n,u),Array.isArray(l)?l.length>0?l[0]:"":l}return""}throw new r(t.UnsupportedSyntax,{node:a.type})}const N={boolean:1,string:2,integer:3,double:4,date:5};function b(e){if(e){let r="";for(const t of e)""!==t&&(r=""===r||N[r]<N[t]?t:r);return r}return""}function v(e,r){return O(e.parseTree,r)}function D(e){return"column-reference"===e?.parseTree.type}function O(e,r){if(null==e)return!1;switch(e.type){case"when-clause":return O(e.operand,r)||O(e.value,r);case"case-expression":for(const t of e.clauses)if(O(t,r))return!0;return!("simple"!==e.format||!O(e.operand,r))||!(null===e.else||!O(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(O(t,r))return!0;return!1;case"unary-expression":return O(e.expr,r);case"binary-expression":return O(e.left,r)||O(e.right,r);case"column-reference":return r.toLowerCase()===e.column.toLowerCase();case"function":return O(e.args,r)}return!1}function R(e){let r="";return r+=e.period.toUpperCase(),r}function F(e,r,t){let a="";return a="interval-period"===r.type?R(r):R(r.start)+" TO "+R(r.end),"INTERVAL "+t+" "+e+" "+a}export{S as arcadeDateOnlyToSqlString,T as arcadeDateToSqlString,g as combine,F as convertIntervalToSql,D as isSingleField,w as makeSqlFromDateTimeParameter,E as makeTimeString,I as makeToday,A as predictType,m as reformulateWithoutField,v as scanForField,f as toWhereClause,p as toWhereClauseFromTree,y as translateFunctionToDatabaseSpecific};