@arcgis/core 4.30.0-next.20240221 → 4.30.0-next.20240222

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 (119) hide show
  1. package/arcade/featureSetUtils.js +1 -1
  2. package/arcade/featureset/actions/GroupBy.js +1 -1
  3. package/arcade/featureset/actions/OrderBy.js +1 -1
  4. package/arcade/functions/featuresetbase.js +1 -1
  5. package/arcade/functions/featuresetstring.js +1 -1
  6. package/arcade/functions/fieldStats.js +1 -1
  7. package/arcade/functions/knowledgegraph.js +1 -1
  8. package/arcade/functions/string.js +1 -1
  9. package/arcade/languageUtils.js +1 -1
  10. package/assets/esri/core/workers/RemoteClient.js +1 -1
  11. package/assets/esri/core/workers/chunks/{a4bdcad81c872f3732c4.js → 0096bd8eee07eed0cc35.js} +1 -1
  12. package/assets/esri/core/workers/chunks/{8f3e29b90b4be7f59d63.js → 0cb55bc9d464cfacb2ec.js} +1 -1
  13. package/assets/esri/core/workers/chunks/1aa8942502ad10bcf42a.js +1 -0
  14. package/assets/esri/core/workers/chunks/1be615202cd259f3a712.js +1 -0
  15. package/assets/esri/core/workers/chunks/{65f156afc2522e95b476.js → 21e7a88478f5d15e0e71.js} +1 -1
  16. package/assets/esri/core/workers/chunks/{b8e5f94e8fab2e9c9eb8.js → 25b68fef8b442e036fc8.js} +1 -1
  17. package/assets/esri/core/workers/chunks/2b89bb874e06efee1e49.js +1 -0
  18. package/assets/esri/core/workers/chunks/{3749c0b608e034d86c3d.js → 37bee3710072130da762.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{ccad09938327f5b065fc.js → 3fded260649aa8ce438a.js} +1 -1
  20. package/assets/esri/core/workers/chunks/{65f7adaaf1f535310c11.js → 49973a5d968609fce4e0.js} +1 -1
  21. package/assets/esri/core/workers/chunks/{2785351e9b718f6170a4.js → 576df46df89e3dcd8b93.js} +1 -1
  22. package/assets/esri/core/workers/chunks/59cc6d5442ef712b323d.js +1 -0
  23. package/assets/esri/core/workers/chunks/5bbff9fab5bd15e20805.js +1 -0
  24. package/assets/esri/core/workers/chunks/68b0d39ad88e43c037a2.js +1 -0
  25. package/assets/esri/core/workers/chunks/6a96b5056b51f7fac5a9.js +1 -0
  26. package/assets/esri/core/workers/chunks/709da1141285320ac38a.js +1 -0
  27. package/assets/esri/core/workers/chunks/78e7ae4c907c63a9e05c.js +1 -0
  28. package/assets/esri/core/workers/chunks/815e7a62286ea1ffe3ea.js +1 -0
  29. package/assets/esri/core/workers/chunks/81653f6364a5d11776f5.js +1 -0
  30. package/assets/esri/core/workers/chunks/{63c2ca47e8df5e9b5574.js → 87fb028c66de06bf6d75.js} +1 -1
  31. package/assets/esri/core/workers/chunks/8d7feafb0c77a1832342.js +1 -0
  32. package/assets/esri/core/workers/chunks/{b9d8dada7003a0b564c1.js → a0d54e02cd6702a14c52.js} +1 -1
  33. package/assets/esri/core/workers/chunks/a4c761ece22515d8a833.js +1 -0
  34. package/assets/esri/core/workers/chunks/a68b976b1146b044b674.js +1 -0
  35. package/assets/esri/core/workers/chunks/abf2ced956e862a926f2.js +1 -0
  36. package/assets/esri/core/workers/chunks/ac80613be789fd9ab32c.js +1 -0
  37. package/assets/esri/core/workers/chunks/{0d8e3e8c09851eba40fd.js → b3180c3a67108c5a8d19.js} +1 -1
  38. package/assets/esri/core/workers/chunks/bbad1823a11e47843272.js +1 -0
  39. package/assets/esri/core/workers/chunks/{a9c923e931cc8fa51bf5.js → c26631d9ac3e2540a12d.js} +1 -1
  40. package/assets/esri/core/workers/chunks/{73c9073c738d39967c36.js → c655504b4a9a0d3d9c7c.js} +1 -1
  41. package/assets/esri/core/workers/chunks/c7dea15d9bb826a9f9c3.js +1 -0
  42. package/assets/esri/core/workers/chunks/{2286db4c83ff1b6fb088.js → ca39d70cd54526b0d9b5.js} +1 -1
  43. package/assets/esri/core/workers/chunks/cdc553da11ac94ea6887.js +1 -0
  44. package/assets/esri/core/workers/chunks/{2fd14cbfb77566cbc69e.js → cf326c0f1f86673ede11.js} +1 -1
  45. package/assets/esri/core/workers/chunks/{c9a61e16039685a74f48.js → d0728af890f58903f9d9.js} +1 -1
  46. package/assets/esri/core/workers/chunks/d118ef2a4766d4253b93.js +1 -0
  47. package/assets/esri/core/workers/chunks/d454c4b6e536074402ce.js +1 -0
  48. package/assets/esri/core/workers/chunks/d64cb0cfd36a26eb0b6e.js +1 -0
  49. package/assets/esri/core/workers/chunks/{6b9f826ecf779adf90a6.js → d91470a93d42c4a55013.js} +1 -1
  50. package/assets/esri/core/workers/chunks/e7a05d3ed84716be50a0.js +1 -0
  51. package/assets/esri/core/workers/chunks/ef1037679d32db3a275b.js +1 -0
  52. package/assets/esri/core/workers/chunks/f07426e5feacbcc5c3b1.js +1 -0
  53. package/assets/esri/core/workers/chunks/f5fff999e371e4ac5575.js +1 -0
  54. package/chunks/languageUtils.js +1 -1
  55. package/interfaces.d.ts +1 -1
  56. package/layers/save/mediaLayerUtils.js +1 -1
  57. package/layers/save/utils.js +1 -1
  58. package/layers/support/LayerContingentValuesCache.js +1 -1
  59. package/package.json +1 -1
  60. package/rest/print.js +1 -1
  61. package/support/elevationInfoUtils.js +1 -1
  62. package/support/revision.js +1 -1
  63. package/symbols/cim/SDFHelper.js +1 -1
  64. package/views/2d/engine/webgl/SDFConverter.js +1 -1
  65. package/views/2d/engine/webgl/TextureManager.js +1 -1
  66. package/views/2d/engine/webgl/definitions.js +1 -1
  67. package/views/2d/engine/webgl/shaderGraph/techniques/markers/ComputedMarkerParams.js +1 -1
  68. package/views/2d/layers/FeatureLayerView2D.js +1 -1
  69. package/views/3d/interactive/Manipulator3D.js +1 -1
  70. package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
  71. package/views/3d/interactive/editingTools/manipulations/MoveXYAxisManipulation.js +1 -1
  72. package/views/3d/interactive/editingTools/manipulations/MoveXYDiscManipulation.js +1 -1
  73. package/views/3d/interactive/editingTools/manipulations/MoveXYGraphicManipulation.js +1 -1
  74. package/views/3d/interactive/editingTools/manipulations/MoveZManipulation.js +1 -1
  75. package/views/3d/interactive/editingTools/manipulations/moveUtils.js +1 -1
  76. package/views/3d/interactive/editingTools/meshFastUpdateUtils.js +1 -1
  77. package/views/3d/interactive/editingTools/moveGraphic/GraphicMoveTool.js +1 -1
  78. package/views/3d/interactive/editingTools/transformGraphic/ScaleRotateMeshAdapter.js +1 -1
  79. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  80. package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
  81. package/views/3d/terrain/OverlayRenderer.js +1 -1
  82. package/views/3d/webgl-engine/lib/TextRenderer.js +1 -1
  83. package/views/3d/webgl-engine/lib/TextTextureAtlas.js +1 -1
  84. package/views/interactive/dragEventPipeline.js +1 -1
  85. package/views/webgl/WebGLDriverTest.js +1 -1
  86. package/views/webgl/testDoublePrecisionArithmetic.js +1 -1
  87. package/widgets/AreaMeasurement2D/AreaMeasurement2DTool.js +1 -1
  88. package/widgets/DistanceMeasurement2D/DistanceMeasurement2DTool.js +1 -1
  89. package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
  90. package/widgets/Editor/UpdateWorkflow.js +1 -1
  91. package/widgets/Editor.js +1 -1
  92. package/widgets/ElevationProfile/ElevationProfileInteraction.js +1 -1
  93. package/widgets/ElevationProfile/support/geometryUtils.js +1 -1
  94. package/assets/esri/core/workers/chunks/0accca800293f3037a30.js +0 -1
  95. package/assets/esri/core/workers/chunks/1f61b7adc11bb20af4ed.js +0 -1
  96. package/assets/esri/core/workers/chunks/2c96771a365f8f70e996.js +0 -1
  97. package/assets/esri/core/workers/chunks/352e7f8d694f3f217a2d.js +0 -1
  98. package/assets/esri/core/workers/chunks/36d091be859bbb1a149b.js +0 -1
  99. package/assets/esri/core/workers/chunks/3bc079ea278d77b3cfce.js +0 -1
  100. package/assets/esri/core/workers/chunks/42ae6025dfd893517f5d.js +0 -1
  101. package/assets/esri/core/workers/chunks/4dc18a8180f3e8b6131a.js +0 -1
  102. package/assets/esri/core/workers/chunks/50b41f91be903a0977f9.js +0 -1
  103. package/assets/esri/core/workers/chunks/617e23b6a0099201c716.js +0 -1
  104. package/assets/esri/core/workers/chunks/64df2521b2814d2fb918.js +0 -1
  105. package/assets/esri/core/workers/chunks/79c041b292648c5eaecc.js +0 -1
  106. package/assets/esri/core/workers/chunks/7a0d53109c18602785c8.js +0 -1
  107. package/assets/esri/core/workers/chunks/7f45a9e9bdbcffc2d6e0.js +0 -1
  108. package/assets/esri/core/workers/chunks/9a8007a4145b00a8cf27.js +0 -1
  109. package/assets/esri/core/workers/chunks/a48201b109e9e9aab2d6.js +0 -1
  110. package/assets/esri/core/workers/chunks/a854611d1a86b838c6ad.js +0 -1
  111. package/assets/esri/core/workers/chunks/a9f20b21211debaa2879.js +0 -1
  112. package/assets/esri/core/workers/chunks/ad26c63b71348ec753e8.js +0 -1
  113. package/assets/esri/core/workers/chunks/ad77d9dea22804ba5f0d.js +0 -1
  114. package/assets/esri/core/workers/chunks/bd1708539daafa28951d.js +0 -1
  115. package/assets/esri/core/workers/chunks/c2da576f052cbda2566d.js +0 -1
  116. package/assets/esri/core/workers/chunks/ccd53b81c2688dd11584.js +0 -1
  117. package/assets/esri/core/workers/chunks/f5e3b8ecd0581253e18b.js +0 -1
  118. package/assets/esri/core/workers/chunks/ff14214611e1e070235e.js +0 -1
  119. package/views/webgl/testSamplerPrecision.js +0 -5
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import e from"../request.js";import t from"./featureSetCollection.js";import{a0 as a,a1 as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import l 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 y from"./featureset/support/FeatureSet.js";import{extractServiceUrl as h}from"./featureset/support/shared.js";import{WhereClause as _}from"../core/sql/WhereClause.js";import w from"../layers/FeatureLayer.js";import L from"../portal/PortalItem.js";function I(){null===f.applicationCache&&(f.applicationCache=new f)}async function S(e,t){if(f.applicationCache){const r=f.applicationCache.getLayerInfo(e);if(r){const a=await r;return new w({url:e,outFields:t,sourceJSON:a})}const n=new w({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(a){throw f.applicationCache.clearLayerInfo(e),a}}return await i,n}return new w({url:e,outFields:t})}async function F(e,t,a,r,n,i=null){return g(await S(e,["*"]),t,a,r,n,i)}function g(e,t=null,r=null,n=!0,i=null,s=null){if(e instanceof w||a(e)){const a={layer:e,spatialReference:t,outFields:r,includeGeometry:n,lrucache:i,interceptor:s};return!0==!(e.url||!e.source)?new c(a):new u(a)}const l=g(e.parent,t,r,n,i,s);return l.filter(_.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),e.parent.fieldsIndex,l.dateFieldsTimeZoneDefaultUTC))}async function N(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 C(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 T(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"}});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,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function A(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await T(e);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 C(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 N(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 F(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(_.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 k(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await F(o,r,n,i,s,l);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}n.registerAction(),i.registerAction(),s.registerAction(),l.registerAction(),o.registerAction();class O extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=g(e,this._overridespref,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,r=null){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,r);null===r&&(r=["*"]),r=(r=r.slice(0)).sort();const n=JSON.stringify(r);for(let a=0;a<this._instantLayers.length;a++){const r=this._instantLayers[a];if(r.opitem.title===e&&r.includeGeometry===t&&r.outFields===n)return this._instantLayers[a].featureset}const i=this._map.allLayers.find((t=>{if(t instanceof w){if(t.title===e)return!0}else if(a(t)&&t.title===e)return!0;return!1}));if(i)return this._makeAndAddFeatureSet(i,t,r);if(this._map.tables){const a=this._map.tables.find((t=>!!(t.title&&t.title===e||t.title&&t.title===e)));if(a){if(a instanceof w)return this._makeAndAddFeatureSet(a,t,r);if(a._materializedTable);else{const e=a.outFields?a:{...a,outFields:["*"]};a._materializedTable=new w(e)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,r)}}return null}async featureSetById(e,t=!0,r=["*"]){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetById(e,t,r);null===r&&(r=["*"]),r=(r=r.slice(0)).sort();const n=JSON.stringify(r);for(let a=0;a<this._instantLayers.length;a++){const r=this._instantLayers[a];if(r.opitem.id===e&&r.includeGeometry===t&&r.outFields===n)return this._instantLayers[a].featureset}const i=this._map.allLayers.find((t=>{if(t instanceof w){if(t.id===e)return!0}else if(a(t)&&t.id===e)return!0;return!1}));if(i)return this._makeAndAddFeatureSet(i,t,r);if(this._map.tables){const a=this._map.tables.find((t=>t.id===e));if(a){if(a instanceof w)return this._makeAndAddFeatureSet(a,t,r);if(a._materializedTable);else{const e={...a,outFields:["*"]};a._materializedTable=new w(e)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,r)}}return null}}class b extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=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=g(e,this._overridespref,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 T(this._url);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new b(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])s.name===e&&(i=s);if(!i)for(const s of n.tables??[])s.name===e&&(i=s);if(i){const e=await S(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await S(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function D(e,t,a=null,r=null){return new O(e,t,a,r)}function E(e,t,a=null,r=null){return new b(e,t,a,r)}function j(e,t,n,i,s){if(null===e)return null;if(e instanceof w){switch(t){case"datasource":return g(e,s,e.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.outFields,!0,n,i)}return null}if(a(e)){switch(t){case"datasource":return g(e,s,e.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return g(e.parent,s,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.parent.outFields,!0,n,i)}return null}if(e instanceof y)switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}async function q(e,t,a,r,n,i,s,l=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return g(new w({url:h(e.url)+"/"+t,outFields:["*"]}),a,r,n,s,l)}}const o=new L({id:e,portal:i}).load();f.applicationCache&&f.applicationCache.setLayerInfo(e+":"+i.url,o);try{const e=await o;return g(new w({url:h(e.url??"")+"/"+t,outFields:["*"]}),a,r,n,s,l)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),u}}export{A as constructAssociationMetaDataFeatureSetFromUrl,g as constructFeatureSet,q as constructFeatureSetFromPortalItem,k as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,j as convertToFeatureSet,D as createFeatureSetCollectionFromMap,E as createFeatureSetCollectionFromService,I as initialiseMetaDataCache};
5
+ import e from"../request.js";import t from"./featureSetCollection.js";import{$ as a,a0 as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import l 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 y from"./featureset/support/FeatureSet.js";import{extractServiceUrl as h}from"./featureset/support/shared.js";import{WhereClause as _}from"../core/sql/WhereClause.js";import w from"../layers/FeatureLayer.js";import L from"../portal/PortalItem.js";function I(){null===f.applicationCache&&(f.applicationCache=new f)}async function S(e,t){if(f.applicationCache){const r=f.applicationCache.getLayerInfo(e);if(r){const a=await r;return new w({url:e,outFields:t,sourceJSON:a})}const n=new w({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(a){throw f.applicationCache.clearLayerInfo(e),a}}return await i,n}return new w({url:e,outFields:t})}async function F(e,t,a,r,n,i=null){return g(await S(e,["*"]),t,a,r,n,i)}function g(e,t=null,r=null,n=!0,i=null,s=null){if(e instanceof w||a(e)){const a={layer:e,spatialReference:t,outFields:r,includeGeometry:n,lrucache:i,interceptor:s};return!0==!(e.url||!e.source)?new c(a):new u(a)}const l=g(e.parent,t,r,n,i,s);return l.filter(_.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),e.parent.fieldsIndex,l.dateFieldsTimeZoneDefaultUTC))}async function N(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 C(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 T(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"}});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,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function A(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await T(e);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 C(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 N(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 F(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(_.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 k(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await F(o,r,n,i,s,l);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}n.registerAction(),i.registerAction(),s.registerAction(),l.registerAction(),o.registerAction();class O extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=g(e,this._overridespref,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,r=null){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,r);null===r&&(r=["*"]),r=(r=r.slice(0)).sort();const n=JSON.stringify(r);for(let a=0;a<this._instantLayers.length;a++){const r=this._instantLayers[a];if(r.opitem.title===e&&r.includeGeometry===t&&r.outFields===n)return this._instantLayers[a].featureset}const i=this._map.allLayers.find((t=>{if(t instanceof w){if(t.title===e)return!0}else if(a(t)&&t.title===e)return!0;return!1}));if(i)return this._makeAndAddFeatureSet(i,t,r);if(this._map.tables){const a=this._map.tables.find((t=>!!(t.title&&t.title===e||t.title&&t.title===e)));if(a){if(a instanceof w)return this._makeAndAddFeatureSet(a,t,r);if(a._materializedTable);else{const e=a.outFields?a:{...a,outFields:["*"]};a._materializedTable=new w(e)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,r)}}return null}async featureSetById(e,t=!0,r=["*"]){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetById(e,t,r);null===r&&(r=["*"]),r=(r=r.slice(0)).sort();const n=JSON.stringify(r);for(let a=0;a<this._instantLayers.length;a++){const r=this._instantLayers[a];if(r.opitem.id===e&&r.includeGeometry===t&&r.outFields===n)return this._instantLayers[a].featureset}const i=this._map.allLayers.find((t=>{if(t instanceof w){if(t.id===e)return!0}else if(a(t)&&t.id===e)return!0;return!1}));if(i)return this._makeAndAddFeatureSet(i,t,r);if(this._map.tables){const a=this._map.tables.find((t=>t.id===e));if(a){if(a instanceof w)return this._makeAndAddFeatureSet(a,t,r);if(a._materializedTable);else{const e={...a,outFields:["*"]};a._materializedTable=new w(e)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,r)}}return null}}class b extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=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=g(e,this._overridespref,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 T(this._url);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new b(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])s.name===e&&(i=s);if(!i)for(const s of n.tables??[])s.name===e&&(i=s);if(i){const e=await S(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await S(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function D(e,t,a=null,r=null){return new O(e,t,a,r)}function E(e,t,a=null,r=null){return new b(e,t,a,r)}function j(e,t,n,i,s){if(null===e)return null;if(e instanceof w){switch(t){case"datasource":return g(e,s,e.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.outFields,!0,n,i)}return null}if(a(e)){switch(t){case"datasource":return g(e,s,e.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return g(e.parent,s,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.parent.outFields,!0,n,i)}return null}if(e instanceof y)switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}async function q(e,t,a,r,n,i,s,l=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return g(new w({url:h(e.url)+"/"+t,outFields:["*"]}),a,r,n,s,l)}}const o=new L({id:e,portal:i}).load();f.applicationCache&&f.applicationCache.setLayerInfo(e+":"+i.url,o);try{const e=await o;return g(new w({url:h(e.url??"")+"/"+t,outFields:["*"]}),a,r,n,s,l)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),u}}export{A as constructAssociationMetaDataFeatureSetFromUrl,g as constructFeatureSet,q as constructFeatureSetFromPortalItem,k as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,j as convertToFeatureSet,D as createFeatureSetCollectionFromMap,E as createFeatureSetCollectionFromService,I 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.30/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import{a2 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(0).concat(n._known.slice(0)),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(0),n._known.slice(0),!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,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(0).concat(n._known.slice(0)),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(0),n._known.slice(0),!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.30/esri/copyright.txt for details.
4
4
  */
5
- import{a2 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import s from"../support/IdSet.js";import i from"../support/OrderbyClause.js";class a extends n{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const n=new s([],[],!0,null);for(let s=0;s<r.length;s++)n._known.push(r[s].id);return n}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t(r.NeverReach)}async _getFilteredSet(e,t,r,n,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===n?this._orderbyclause:n,i);this._checkCancelled(i);const o=new s(a._candidates.slice(0),a._known.slice(0),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new s(e._candidates.slice(0).concat(e._known.slice(0)),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){n._featuresetFunctions.orderBy=function(e){return""===e?this:new a({parentfeatureset:this,orderbyclause:new i(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{a as default};
5
+ import{a1 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import s from"../support/IdSet.js";import i from"../support/OrderbyClause.js";class a extends n{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const n=new s([],[],!0,null);for(let s=0;s<r.length;s++)n._known.push(r[s].id);return n}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t(r.NeverReach)}async _getFilteredSet(e,t,r,n,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===n?this._orderbyclause:n,i);this._checkCancelled(i);const o=new s(a._candidates.slice(0),a._known.slice(0),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new s(e._candidates.slice(0).concat(e._known.slice(0)),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){n._featuresetFunctions.orderBy=function(e){return""===e?this:new a({parentfeatureset:this,orderbyclause:new i(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{a as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as o,constructFeatureSetFromPortalItem as l,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as d,constructAssociationMetaDataFeatureSetFromUrl as c}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{H as p,n as y,m as w,u as h,c as g,j as F,l as I,N as D,k as T,K as b,h as E,o as A,r as N,q as x,i as S,g as L,a3 as C,T as $,O as v}from"../../chunks/languageUtils.js";import{getPortal as P}from"../portalUtils.js";import{SqlExpressionAdapted as j,StringToCodeAdapted as U,FieldRename as Z,AdaptedFeatureSet as M,OriginalField as R}from"../featureset/actions/Adapted.js";import k from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import z from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as _}from"../featureset/support/shared.js";import{isSingleField as K}from"../featureset/support/sqlUtils.js";import{calculateStat as q}from"./fieldStats.js";import{isPromiseLike as B}from"../../core/promiseUtils.js";import{WhereClause as V}from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";function X(e,t,n,a){if(1===a.length){if(A(a[0]))return q(e,a[0],-1);if(x(a[0]))return q(e,a[0].toArray(),-1)}return q(e,a,-1)}async function ee(e,t,n){const a=e.getVariables();if(a.length>0){const i=[];for(let e=0;e<a.length;e++){const r={name:a[e]};i.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<a.length;e++)r[a[e]]=i[e];return e.parameters=r,e}return e}function te(e,t,n=null){for(const a in e)if(a.toLowerCase()===t.toLowerCase())return e[a];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ae(e){if(null===e)return null;const t={},n=te(e,"wkt",null);null!==n&&(t.wkt=n);const a=te(e,"wkid",null);return null!==a&&(t.wkid=a),t}function ie(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference",null);n&&(t.spatialReference=ae(n));const a=te(e,"x",null);if(null!==a)return t.x=a,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const i=te(e,"rings",null);if(null!==i)return t.rings=i,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==A(e.layerDefinition.fields)&&!1!==A(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(q){"async"===q.mode&&(q.functions.timezone=function(t,r){return q.standardFunctionAsync(t,r,(async(s,o,l)=>{if(p(l,1,2,t,r),y(l[0]))return"Unknown";if(w(l[0]))return"Unknown";if(h(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new a(t,i.InvalidParameter,r);const e=l[1].field("type");if(!1===g(e))throw new a(t,i.InvalidParameter,r);switch(F(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&g(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(F(l[1].field("fieldname"))))}throw new a(t,i.InvalidParameter,r)}const f=I(l[0],D(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:"utc"===u.toLowerCase()?"UTC":"unknown"===u.toLowerCase()?"Unknown":u}))},q.functions.sqltimestamp=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const o=s[0];if(T(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(F(s[1])).toSQLWithKeyword();throw new a(e,i.InvalidParameter,t)}if(w(o))return o.toSQLWithKeyword();if(h(o)){if(3!==s.length)throw new a(e,i.InvalidParameter,t);await o.load();const n=F(s[1]);if(w(s[2]))return s[2].toSQLWithKeyword();if(!1===T(s[2]))throw new a(e,i.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"sqltimestamp",min:2,max:4}),q.functions.featuresetbyid=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetById(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyid",min:2,max:4}),q.functions.getfeatureset=function(e,t){return q.standardFunctionAsync(e,t,((n,r,s)=>{if(p(s,1,2,e,t),N(s[0])){let t=b(s[1],"datasource");return null===t&&(t="datasource"),t=F(t).toLowerCase(),o(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"getfeatureset",min:1,max:2}),q.functions.featuresetbyportalitem=function(e,n){return q.standardFunctionAsync(e,n,((r,s,o)=>{if(p(o,2,5,e,n),null===o[0])throw new a(e,i.PortalRequired,n);if(o[0]instanceof t){const t=F(o[1]),r=F(o[2]);let s=b(o[3],null);const f=E(b(o[4],!0));if(null===s&&(s=["*"]),!1===A(s))throw new a(e,i.InvalidParameter,n);let u=null;return u=e.services?.portal?e.services.portal:Y.getDefault(),u=P(o[0],u),l(t,r,e.spatialReference,s,f,u,e.lrucache,e.interceptor)}if(!1===g(o[0]))throw new a(e,i.PortalRequired,n);const f=F(o[0]),u=F(o[1]);let d=b(o[2],null);const c=E(b(o[3],!0));if(null===d&&(d=["*"]),!1===A(d))throw new a(e,i.InvalidParameter,n);return l(f,u,e.spatialReference,d,c,e.services?.portal??Y.getDefault(),e.lrucache,e.interceptor)}))},q.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),q.functions.featuresetbyname=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetByName(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyname",min:2,max:4}),q.functions.featureset=function(e,t){return q.standardFunction(e,t,((r,s,o)=>{p(o,1,1,e,t);let l=o[0];const f={layerDefinition:{geometryType:"",objectIdField:"",hasM:!1,hasZ:!1,globalIdField:"",typeIdField:"",fields:[]},featureSet:{geometryType:"",features:[]}};if(g(l))l=JSON.parse(l),void 0!==l.layerDefinition?(f.layerDefinition=l.layerDefinition,f.featureSet=l.featureSet,l.layerDefinition.spatialReference&&(f.layerDefinition.spatialReference=l.layerDefinition.spatialReference)):(f.featureSet.features=l.features,f.featureSet.geometryType=l.geometryType,f.layerDefinition.geometryType=f.featureSet.geometryType,f.layerDefinition.objectIdField=l.objectIdFieldName??"",f.layerDefinition.typeIdField=l.typeIdFieldName,f.layerDefinition.globalIdField=l.globalIdFieldName,f.layerDefinition.fields=l.fields,l.spatialReference&&(f.layerDefinition.spatialReference=l.spatialReference));else{if(!(o[0]instanceof n))throw new a(e,i.InvalidParameter,t);{l=JSON.parse(o[0].castToText(!0));const e=te(l,"layerdefinition");if(null!==e){f.layerDefinition.geometryType=te(e,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.globalIdField=te(e,"globalidfield",""),f.layerDefinition.objectIdField=te(e,"objectidfield",""),f.layerDefinition.typeIdField=te(e,"typeidfield",""),f.layerDefinition.hasZ=!0===te(e,"hasz",!1),f.layerDefinition.hasM=!0===te(e,"hasm",!1);const t=te(e,"spatialreference",null);t&&(f.layerDefinition.spatialReference=ae(t));for(const a of te(e,"fields",[])){const e={name:te(a,"name",""),alias:te(a,"alias",""),type:te(a,"type",""),nullable:te(a,"nullable",!0),editable:te(a,"editable",!0),length:te(a,"length",null),domain:ne(te(a,"domain"))};f.layerDefinition.fields.push(e)}const n=te(l,"featureset",null);if(n){const e={};for(const t of f.layerDefinition.fields)e[t.name.toLowerCase()]=t.name;for(const t of te(n,"features",[])){const n={},a=te(t,"attributes",{});for(const t in a)n[e[t.toLowerCase()]]=a[t];f.featureSet.features.push({attributes:n,geometry:ie(te(t,"geometry",null))})}}}else{f.layerDefinition.hasZ=!0===te(l,"hasz",!1),f.layerDefinition.hasM=!0===te(l,"hasm",!1),f.layerDefinition.geometryType=te(l,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.objectIdField=te(l,"objectidfieldname",""),f.layerDefinition.typeIdField=te(l,"typeidfieldname","");const e=te(l,"spatialreference",null);e&&(f.layerDefinition.spatialReference=ae(e));let t=te(l,"fields",null);if(A(t))for(const i of t){const e={name:te(i,"name",""),alias:te(i,"alias",""),type:te(i,"type",""),nullable:te(i,"nullable",!0),editable:te(i,"editable",!0),length:te(i,"length",null),domain:ne(te(i,"domain"))};f.layerDefinition.fields.push(e)}else t=null,f.layerDefinition.fields=t;const n={};for(const i of f.layerDefinition.fields)n[i.name.toLowerCase()]=i.name;let a=te(l,"features",null);if(A(a))for(const i of a){const e={},t=te(i,"attributes",{});for(const a in t)e[n[a.toLowerCase()]]=t[a];f.featureSet.features.push({attributes:e,geometry:ie(te(i,"geometry",null))})}else a=null,f.featureSet.features=a}}}if(!1===se(f))throw new a(e,i.InvalidParameter,t);return f.layerDefinition.geometryType||(f.layerDefinition.geometryType="esriGeometryNull"),W.create(f,e.spatialReference)}))},q.signatures.push({name:"featureset",min:1,max:1}),q.functions.filter=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),A(s[0])||x(s[0])){const n=[];let r=s[0];r instanceof m&&(r=r.toArray());let o=null;if(!S(s[1]))throw new a(e,i.InvalidParameter,t);o=s[1].createFunction(e);for(const e of r){const t=o(e);B(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(h(s[0])){const t=await s[0].load(),n=V.create(s[1],t.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC),a=n.getVariables();if(a.length>0){const t=[];for(let n=0;n<a.length;n++){const i={name:a[n]};t.push(await q.evaluateIdentifier(e,i))}const i={};for(let e=0;e<a.length;e++)i[a[e]]=t[e];return n.parameters=i,new k({parentfeatureset:s[0],whereclause:n})}return new k({parentfeatureset:s[0],whereclause:n})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filter",min:2,max:2}),q.functions.orderby=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"orderby",min:2,max:2}),q.functions.top=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0]))return new z({parentfeatureset:s[0],topnum:s[1]});if(A(s[0]))return L(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,L(s[1]));if(x(s[0]))return L(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,L(s[1]));throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"top",min:2,max:2}),q.functions.first=function(e,t){return q.standardFunctionAsync(e,t,(async(n,a,i)=>{if(p(i,1,1,e,t),h(i[0])){const t=await i[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,i[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return A(i[0])?0===i[0].length?null:i[0][0]:x(i[0])?0===i[0].length()?null:i[0].get(0):null}))},q.signatures.push({name:"first",min:1,max:1}),q.functions.attachments=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{p(o,1,2,e,t);const l={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(l.minsize=L(o[1].field("minsize"))),o[1].hasField("metadata")&&(l.returnMetadata=E(o[1].field("metadata"))),o[1].hasField("maxsize")&&(l.maxsize=L(o[1].field("maxsize"))),o[1].hasField("types")){const e=C(o[1].field("types"),!1);e.length>0&&(l.types=e)}}else if(null!==o[1])throw new a(e,i.InvalidParameter,t);if(N(o[0])){let t=o[0]._layer;return t instanceof Q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===h(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),l.minsize,l.maxsize,l.types,l.returnMetadata))}if(null===o[0])return[];throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"attachments",min:1,max:2}),q.functions.featuresetbyrelationshipname=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const o=s[0],l=F(s[1]);let c=b(s[2],null);const m=E(b(s[3],!0));if(null===c&&(c=["*"]),!1===A(c))throw new a(e,i.InvalidParameter,t);if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let y=o._layer;if(y instanceof Q&&(y=f(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===h(y))return null;y=await y.load();const w=y.relationshipMetaData().filter((e=>e.name===l));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(y,w[0],o.field(y.objectIdField),y.spatialReference,c,m,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+w[0].relatedTableId.toString():g+"/"+w[0].relatedTableId.toString();const I=await d(g,y.spatialReference,c,m,e.lrucache,e.interceptor);await I.load();let D=I.relationshipMetaData();if(D=D.filter((e=>e.id===w[0].id)),!1===o.hasField(w[0].keyField)||null===o.field(w[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[w[0].keyField]);if(e){const t=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return t.parameters={id:e.attributes[w[0].keyField]},I.filter(t)}return new H({parentfeatureset:I})}const T=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return T.parameters={id:o.field(w[0].keyField)},I.filter(T)}))},q.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),q.functions.featuresetbyassociation=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const o=s[0],l=F(b(s[1],"")).toLowerCase(),u=g(s[2])?F(s[2]):null;if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let d=o._layer;if(d instanceof Q&&(d=f(d,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===d)return null;if(!1===h(d))return null;await d.load();const m=d.serviceUrl(),y=await c(m,e.spatialReference);let w=null,I=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of y.terminals)e.terminalName===u&&(I=e.terminalId);null===I&&(D=!0)}const T=y.associations.getFieldsIndex(),E=T.get("TOGLOBALID").name,A=T.get("FROMGLOBALID").name,x=T.get("TOTERMINALID").name,S=T.get("FROMTERMINALID").name,L=T.get("FROMNETWORKSOURCEID").name,C=T.get("TONETWORKSOURCEID").name,v=T.get("ASSOCIATIONTYPE").name,P=T.get("ISCONTENTVISIBLE").name,k=T.get("OBJECTID").name;for(const e of d.fields)if("global-id"===e.type){w=o.field(e.name);break}let O=null,z=new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create("''",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));const W="globalid",G="globalId",K={};for(const e in y.lkp)K[e]=y.lkp[e].sourceId;const q=new U(new J({name:"classname",alias:"classname",type:"string"}),null,K);let B="";switch(l){case"midspan":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (5))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),z=y.unVersion>=4?new R(M.findField(y.associations.fields,T.get("PERCENTALONG").name)):new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"junctionedge":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (4,6))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create(`CASE WHEN (${v}=4) THEN 'from' ELSE 'to' END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==I&&(e+=` AND ${x}=@A`,t+=` AND ${S}=@A`),B="(("+e+") OR ("+t+"))",B=$(B,"@T",w??""),e=$(e,"@T",w??""),null!==I&&(e=$(e,"@A",I.toString()),B=$(B,"@A",I.toString())),q.codefield=V.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const n=_(M.findField(y.associations.fields,A));n.name=W,n.alias=W,O=new j(n,V.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"container":B=`${E}='${w}' AND ${v} = 2`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,W);break;case"content":B=`(${A}='${w}' AND ${v} = 2)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,W);break;case"structure":B=`(${E}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,G);break;case"attached":B=`(${A}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,G);break;default:throw new a(e,i.InvalidParameter,t)}D&&(B="1 <> 1");return new M({parentfeatureset:y.associations,adaptedFields:[new R(M.findField(y.associations.fields,k)),new R(M.findField(y.associations.fields,P)),O,H,q,z],extraFilter:B?V.create(B,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC):null})}))},q.signatures.push({name:"featuresetbyassociation",min:2,max:6}),q.functions.groupby=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(p(o,3,3,e,t),!h(o[0]))throw new a(e,i.InvalidParameter,t);const l=await o[0].load(),f=[],u=[];let d=!1,c=[];if(g(o[1]))c.push(o[1]);else if(o[1]instanceof n)c.push(o[1]);else if(A(o[1]))c=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);c=o[1].toArray()}for(const m of c)if(g(m)){const e=V.create(F(m),l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(d=!0)}else{if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(d=!0),!n)throw new a(e,i.InvalidParameter,t);f.push({name:n,expression:V.create(r||n,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(c=[],g(o[2]))c.push(o[2]);else if(A(o[2]))c=o[2];else if(x(o[2]))c=o[2].toArray();else{if(!(o[2]instanceof n))throw new a(e,i.InvalidParameter,t);c.push(o[2])}for(const m of c){if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new a(e,i.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:V.create(s,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(d){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of u)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)await ee(t.expression,q,e);for(const t of u)await ee(t.expression,q,e);return o[0].groupby(f,u)}))},q.signatures.push({name:"groupby",min:3,max:3}),q.functions.distinct=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(h(o[0])){p(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(g(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(A(o[1]))l=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(g(o)){const e=V.create(F(o),r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new a(e,i.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new a(e,i.InvalidParameter,t);s.push({name:n,expression:V.create(l||n,r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC)})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await ee(t.expression,q,e);return o[0].groupby(s,[])}return X("distinct",r,s,o)}))}),q.functions.getfeaturesetinfo=function(e,t){return q.standardFunctionAsync(e,t,(async(a,i,r)=>{if(p(r,1,1,e,t),!h(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},D(e),!1,!1):null}))},q.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),q.functions.filterbysubtypecode=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const n=await s[0].load(),r=s[1];if(!v(r))throw new a(e,i.InvalidParameter,t);if(n.subtypeField){const e=V.create(`${n.subtypeField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new a(e,i.FeatureSetDoesNotHaveSubtypes,t);const o=V.create(`${n.typeIdField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:o})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filterbysubtypecode",min:2,max:2})}export{le as registerFunctions};
5
+ import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as o,constructFeatureSetFromPortalItem as l,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as d,constructAssociationMetaDataFeatureSetFromUrl as c}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{H as p,n as y,m as w,u as h,c as g,j as F,l as I,N as D,k as T,K as b,h as E,o as A,r as N,q as x,i as S,g as L,a2 as C,T as $,O as v}from"../../chunks/languageUtils.js";import{getPortal as P}from"../portalUtils.js";import{SqlExpressionAdapted as j,StringToCodeAdapted as U,FieldRename as Z,AdaptedFeatureSet as M,OriginalField as R}from"../featureset/actions/Adapted.js";import k from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import z from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as _}from"../featureset/support/shared.js";import{isSingleField as K}from"../featureset/support/sqlUtils.js";import{calculateStat as q}from"./fieldStats.js";import{isPromiseLike as B}from"../../core/promiseUtils.js";import{WhereClause as V}from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";function X(e,t,n,a){if(1===a.length){if(A(a[0]))return q(e,a[0],-1);if(x(a[0]))return q(e,a[0].toArray(),-1)}return q(e,a,-1)}async function ee(e,t,n){const a=e.getVariables();if(a.length>0){const i=[];for(let e=0;e<a.length;e++){const r={name:a[e]};i.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<a.length;e++)r[a[e]]=i[e];return e.parameters=r,e}return e}function te(e,t,n=null){for(const a in e)if(a.toLowerCase()===t.toLowerCase())return e[a];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ae(e){if(null===e)return null;const t={},n=te(e,"wkt",null);null!==n&&(t.wkt=n);const a=te(e,"wkid",null);return null!==a&&(t.wkid=a),t}function ie(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference",null);n&&(t.spatialReference=ae(n));const a=te(e,"x",null);if(null!==a)return t.x=a,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const i=te(e,"rings",null);if(null!==i)return t.rings=i,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==A(e.layerDefinition.fields)&&!1!==A(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(q){"async"===q.mode&&(q.functions.timezone=function(t,r){return q.standardFunctionAsync(t,r,(async(s,o,l)=>{if(p(l,1,2,t,r),y(l[0]))return"Unknown";if(w(l[0]))return"Unknown";if(h(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new a(t,i.InvalidParameter,r);const e=l[1].field("type");if(!1===g(e))throw new a(t,i.InvalidParameter,r);switch(F(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&g(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(F(l[1].field("fieldname"))))}throw new a(t,i.InvalidParameter,r)}const f=I(l[0],D(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:"utc"===u.toLowerCase()?"UTC":"unknown"===u.toLowerCase()?"Unknown":u}))},q.functions.sqltimestamp=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const o=s[0];if(T(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(F(s[1])).toSQLWithKeyword();throw new a(e,i.InvalidParameter,t)}if(w(o))return o.toSQLWithKeyword();if(h(o)){if(3!==s.length)throw new a(e,i.InvalidParameter,t);await o.load();const n=F(s[1]);if(w(s[2]))return s[2].toSQLWithKeyword();if(!1===T(s[2]))throw new a(e,i.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"sqltimestamp",min:2,max:4}),q.functions.featuresetbyid=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetById(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyid",min:2,max:4}),q.functions.getfeatureset=function(e,t){return q.standardFunctionAsync(e,t,((n,r,s)=>{if(p(s,1,2,e,t),N(s[0])){let t=b(s[1],"datasource");return null===t&&(t="datasource"),t=F(t).toLowerCase(),o(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"getfeatureset",min:1,max:2}),q.functions.featuresetbyportalitem=function(e,n){return q.standardFunctionAsync(e,n,((r,s,o)=>{if(p(o,2,5,e,n),null===o[0])throw new a(e,i.PortalRequired,n);if(o[0]instanceof t){const t=F(o[1]),r=F(o[2]);let s=b(o[3],null);const f=E(b(o[4],!0));if(null===s&&(s=["*"]),!1===A(s))throw new a(e,i.InvalidParameter,n);let u=null;return u=e.services?.portal?e.services.portal:Y.getDefault(),u=P(o[0],u),l(t,r,e.spatialReference,s,f,u,e.lrucache,e.interceptor)}if(!1===g(o[0]))throw new a(e,i.PortalRequired,n);const f=F(o[0]),u=F(o[1]);let d=b(o[2],null);const c=E(b(o[3],!0));if(null===d&&(d=["*"]),!1===A(d))throw new a(e,i.InvalidParameter,n);return l(f,u,e.spatialReference,d,c,e.services?.portal??Y.getDefault(),e.lrucache,e.interceptor)}))},q.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),q.functions.featuresetbyname=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetByName(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyname",min:2,max:4}),q.functions.featureset=function(e,t){return q.standardFunction(e,t,((r,s,o)=>{p(o,1,1,e,t);let l=o[0];const f={layerDefinition:{geometryType:"",objectIdField:"",hasM:!1,hasZ:!1,globalIdField:"",typeIdField:"",fields:[]},featureSet:{geometryType:"",features:[]}};if(g(l))l=JSON.parse(l),void 0!==l.layerDefinition?(f.layerDefinition=l.layerDefinition,f.featureSet=l.featureSet,l.layerDefinition.spatialReference&&(f.layerDefinition.spatialReference=l.layerDefinition.spatialReference)):(f.featureSet.features=l.features,f.featureSet.geometryType=l.geometryType,f.layerDefinition.geometryType=f.featureSet.geometryType,f.layerDefinition.objectIdField=l.objectIdFieldName??"",f.layerDefinition.typeIdField=l.typeIdFieldName,f.layerDefinition.globalIdField=l.globalIdFieldName,f.layerDefinition.fields=l.fields,l.spatialReference&&(f.layerDefinition.spatialReference=l.spatialReference));else{if(!(o[0]instanceof n))throw new a(e,i.InvalidParameter,t);{l=JSON.parse(o[0].castToText(!0));const e=te(l,"layerdefinition");if(null!==e){f.layerDefinition.geometryType=te(e,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.globalIdField=te(e,"globalidfield",""),f.layerDefinition.objectIdField=te(e,"objectidfield",""),f.layerDefinition.typeIdField=te(e,"typeidfield",""),f.layerDefinition.hasZ=!0===te(e,"hasz",!1),f.layerDefinition.hasM=!0===te(e,"hasm",!1);const t=te(e,"spatialreference",null);t&&(f.layerDefinition.spatialReference=ae(t));for(const a of te(e,"fields",[])){const e={name:te(a,"name",""),alias:te(a,"alias",""),type:te(a,"type",""),nullable:te(a,"nullable",!0),editable:te(a,"editable",!0),length:te(a,"length",null),domain:ne(te(a,"domain"))};f.layerDefinition.fields.push(e)}const n=te(l,"featureset",null);if(n){const e={};for(const t of f.layerDefinition.fields)e[t.name.toLowerCase()]=t.name;for(const t of te(n,"features",[])){const n={},a=te(t,"attributes",{});for(const t in a)n[e[t.toLowerCase()]]=a[t];f.featureSet.features.push({attributes:n,geometry:ie(te(t,"geometry",null))})}}}else{f.layerDefinition.hasZ=!0===te(l,"hasz",!1),f.layerDefinition.hasM=!0===te(l,"hasm",!1),f.layerDefinition.geometryType=te(l,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.objectIdField=te(l,"objectidfieldname",""),f.layerDefinition.typeIdField=te(l,"typeidfieldname","");const e=te(l,"spatialreference",null);e&&(f.layerDefinition.spatialReference=ae(e));let t=te(l,"fields",null);if(A(t))for(const i of t){const e={name:te(i,"name",""),alias:te(i,"alias",""),type:te(i,"type",""),nullable:te(i,"nullable",!0),editable:te(i,"editable",!0),length:te(i,"length",null),domain:ne(te(i,"domain"))};f.layerDefinition.fields.push(e)}else t=null,f.layerDefinition.fields=t;const n={};for(const i of f.layerDefinition.fields)n[i.name.toLowerCase()]=i.name;let a=te(l,"features",null);if(A(a))for(const i of a){const e={},t=te(i,"attributes",{});for(const a in t)e[n[a.toLowerCase()]]=t[a];f.featureSet.features.push({attributes:e,geometry:ie(te(i,"geometry",null))})}else a=null,f.featureSet.features=a}}}if(!1===se(f))throw new a(e,i.InvalidParameter,t);return f.layerDefinition.geometryType||(f.layerDefinition.geometryType="esriGeometryNull"),W.create(f,e.spatialReference)}))},q.signatures.push({name:"featureset",min:1,max:1}),q.functions.filter=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),A(s[0])||x(s[0])){const n=[];let r=s[0];r instanceof m&&(r=r.toArray());let o=null;if(!S(s[1]))throw new a(e,i.InvalidParameter,t);o=s[1].createFunction(e);for(const e of r){const t=o(e);B(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(h(s[0])){const t=await s[0].load(),n=V.create(s[1],t.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC),a=n.getVariables();if(a.length>0){const t=[];for(let n=0;n<a.length;n++){const i={name:a[n]};t.push(await q.evaluateIdentifier(e,i))}const i={};for(let e=0;e<a.length;e++)i[a[e]]=t[e];return n.parameters=i,new k({parentfeatureset:s[0],whereclause:n})}return new k({parentfeatureset:s[0],whereclause:n})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filter",min:2,max:2}),q.functions.orderby=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"orderby",min:2,max:2}),q.functions.top=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0]))return new z({parentfeatureset:s[0],topnum:s[1]});if(A(s[0]))return L(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,L(s[1]));if(x(s[0]))return L(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,L(s[1]));throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"top",min:2,max:2}),q.functions.first=function(e,t){return q.standardFunctionAsync(e,t,(async(n,a,i)=>{if(p(i,1,1,e,t),h(i[0])){const t=await i[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,i[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return A(i[0])?0===i[0].length?null:i[0][0]:x(i[0])?0===i[0].length()?null:i[0].get(0):null}))},q.signatures.push({name:"first",min:1,max:1}),q.functions.attachments=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{p(o,1,2,e,t);const l={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(l.minsize=L(o[1].field("minsize"))),o[1].hasField("metadata")&&(l.returnMetadata=E(o[1].field("metadata"))),o[1].hasField("maxsize")&&(l.maxsize=L(o[1].field("maxsize"))),o[1].hasField("types")){const e=C(o[1].field("types"),!1);e.length>0&&(l.types=e)}}else if(null!==o[1])throw new a(e,i.InvalidParameter,t);if(N(o[0])){let t=o[0]._layer;return t instanceof Q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===h(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),l.minsize,l.maxsize,l.types,l.returnMetadata))}if(null===o[0])return[];throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"attachments",min:1,max:2}),q.functions.featuresetbyrelationshipname=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const o=s[0],l=F(s[1]);let c=b(s[2],null);const m=E(b(s[3],!0));if(null===c&&(c=["*"]),!1===A(c))throw new a(e,i.InvalidParameter,t);if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let y=o._layer;if(y instanceof Q&&(y=f(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===h(y))return null;y=await y.load();const w=y.relationshipMetaData().filter((e=>e.name===l));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(y,w[0],o.field(y.objectIdField),y.spatialReference,c,m,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+w[0].relatedTableId.toString():g+"/"+w[0].relatedTableId.toString();const I=await d(g,y.spatialReference,c,m,e.lrucache,e.interceptor);await I.load();let D=I.relationshipMetaData();if(D=D.filter((e=>e.id===w[0].id)),!1===o.hasField(w[0].keyField)||null===o.field(w[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[w[0].keyField]);if(e){const t=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return t.parameters={id:e.attributes[w[0].keyField]},I.filter(t)}return new H({parentfeatureset:I})}const T=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return T.parameters={id:o.field(w[0].keyField)},I.filter(T)}))},q.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),q.functions.featuresetbyassociation=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const o=s[0],l=F(b(s[1],"")).toLowerCase(),u=g(s[2])?F(s[2]):null;if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let d=o._layer;if(d instanceof Q&&(d=f(d,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===d)return null;if(!1===h(d))return null;await d.load();const m=d.serviceUrl(),y=await c(m,e.spatialReference);let w=null,I=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of y.terminals)e.terminalName===u&&(I=e.terminalId);null===I&&(D=!0)}const T=y.associations.getFieldsIndex(),E=T.get("TOGLOBALID").name,A=T.get("FROMGLOBALID").name,x=T.get("TOTERMINALID").name,S=T.get("FROMTERMINALID").name,L=T.get("FROMNETWORKSOURCEID").name,C=T.get("TONETWORKSOURCEID").name,v=T.get("ASSOCIATIONTYPE").name,P=T.get("ISCONTENTVISIBLE").name,k=T.get("OBJECTID").name;for(const e of d.fields)if("global-id"===e.type){w=o.field(e.name);break}let O=null,z=new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create("''",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));const W="globalid",G="globalId",K={};for(const e in y.lkp)K[e]=y.lkp[e].sourceId;const q=new U(new J({name:"classname",alias:"classname",type:"string"}),null,K);let B="";switch(l){case"midspan":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (5))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),z=y.unVersion>=4?new R(M.findField(y.associations.fields,T.get("PERCENTALONG").name)):new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"junctionedge":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (4,6))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create(`CASE WHEN (${v}=4) THEN 'from' ELSE 'to' END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==I&&(e+=` AND ${x}=@A`,t+=` AND ${S}=@A`),B="(("+e+") OR ("+t+"))",B=$(B,"@T",w??""),e=$(e,"@T",w??""),null!==I&&(e=$(e,"@A",I.toString()),B=$(B,"@A",I.toString())),q.codefield=V.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const n=_(M.findField(y.associations.fields,A));n.name=W,n.alias=W,O=new j(n,V.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"container":B=`${E}='${w}' AND ${v} = 2`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,W);break;case"content":B=`(${A}='${w}' AND ${v} = 2)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,W);break;case"structure":B=`(${E}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,G);break;case"attached":B=`(${A}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,G);break;default:throw new a(e,i.InvalidParameter,t)}D&&(B="1 <> 1");return new M({parentfeatureset:y.associations,adaptedFields:[new R(M.findField(y.associations.fields,k)),new R(M.findField(y.associations.fields,P)),O,H,q,z],extraFilter:B?V.create(B,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC):null})}))},q.signatures.push({name:"featuresetbyassociation",min:2,max:6}),q.functions.groupby=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(p(o,3,3,e,t),!h(o[0]))throw new a(e,i.InvalidParameter,t);const l=await o[0].load(),f=[],u=[];let d=!1,c=[];if(g(o[1]))c.push(o[1]);else if(o[1]instanceof n)c.push(o[1]);else if(A(o[1]))c=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);c=o[1].toArray()}for(const m of c)if(g(m)){const e=V.create(F(m),l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(d=!0)}else{if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(d=!0),!n)throw new a(e,i.InvalidParameter,t);f.push({name:n,expression:V.create(r||n,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(c=[],g(o[2]))c.push(o[2]);else if(A(o[2]))c=o[2];else if(x(o[2]))c=o[2].toArray();else{if(!(o[2]instanceof n))throw new a(e,i.InvalidParameter,t);c.push(o[2])}for(const m of c){if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new a(e,i.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:V.create(s,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(d){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of u)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)await ee(t.expression,q,e);for(const t of u)await ee(t.expression,q,e);return o[0].groupby(f,u)}))},q.signatures.push({name:"groupby",min:3,max:3}),q.functions.distinct=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(h(o[0])){p(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(g(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(A(o[1]))l=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(g(o)){const e=V.create(F(o),r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new a(e,i.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new a(e,i.InvalidParameter,t);s.push({name:n,expression:V.create(l||n,r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC)})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await ee(t.expression,q,e);return o[0].groupby(s,[])}return X("distinct",r,s,o)}))}),q.functions.getfeaturesetinfo=function(e,t){return q.standardFunctionAsync(e,t,(async(a,i,r)=>{if(p(r,1,1,e,t),!h(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},D(e),!1,!1):null}))},q.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),q.functions.filterbysubtypecode=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const n=await s[0].load(),r=s[1];if(!v(r))throw new a(e,i.InvalidParameter,t);if(n.subtypeField){const e=V.create(`${n.subtypeField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new a(e,i.FeatureSetDoesNotHaveSubtypes,t);const o=V.create(`${n.typeIdField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:o})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filterbysubtypecode",min:2,max:2})}export{le as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as e}from"../executionError.js";import{H as t,r,X as o,j as i,u as c,a4 as s,W as d,N as u,Y as m,a5 as f,Z as l,a6 as y,K as v,t as p,V as w}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as h}from"../featureset/support/shared.js";function T(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:h[a.field.type],codedValues:a.domain.codedValues.map((n=>({name:n.name,code:n.code})))},u(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:h[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},u(e)):null}function b(h){"async"===h.mode&&(h.functions.domain=function(n,d){return h.standardFunctionAsync(n,d,(async(u,m,f)=>{if(t(f,2,3,n,d),r(f[0])){return T(o(f[0],i(f[1]),void 0===f[2]?void 0:f[2]),n)}if(c(f[0])){await f[0]._ensureLoaded();return T(s(i(f[1]),f[0],null,void 0===f[2]?void 0:f[2]),n)}throw new a(n,e.InvalidParameter,d)}))},h.functions.subtypes=function(o,i){return h.standardFunctionAsync(o,i,(async(s,m,f)=>{if(t(f,1,1,o,i),r(f[0])){const a=d(f[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}if(c(f[0])){await f[0]._ensureLoaded();const a=f[0].subtypeMetaData();return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))},h.functions.domainname=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,l)=>{if(t(l,2,4,n,o),r(l[0]))return m(l[0],i(l[1]),l[2],void 0===l[3]?void 0:l[3]);if(c(l[0])){await l[0]._ensureLoaded();const n=s(i(l[1]),l[0],null,void 0===l[3]?void 0:l[3]);return f(n,l[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domainname",min:2,max:4}),h.functions.domaincode=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,m)=>{if(t(m,2,4,n,o),r(m[0]))return l(m[0],i(m[1]),m[2],void 0===m[3]?void 0:m[3]);if(c(m[0])){await m[0]._ensureLoaded();const n=s(i(m[1]),m[0],null,void 0===m[3]?void 0:m[3]);return y(n,m[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domaincode",min:2,max:4})),h.functions.text=function(n,a){return h.standardFunctionAsync(n,a,((e,r,o)=>{if(t(o,1,2,n,a),!c(o[0]))return p(o[0],o[1]);{const n=v(o[1],"");if(""===n)return o[0].castToText();if("schema"===n.toLowerCase())return o[0].convertToText("schema",e.abortSignal);if("featureset"===n.toLowerCase())return o[0].convertToText("featureset",e.abortSignal)}}))},h.functions.gdbversion=function(n,o){return h.standardFunctionAsync(n,o,(async(i,s,d)=>{if(t(d,1,1,n,o),r(d[0]))return d[0].gdbVersion();if(c(d[0])){return(await d[0].load()).gdbVersion}throw new a(n,e.InvalidParameter,o)}))},h.functions.schema=function(o,i){return h.standardFunctionAsync(o,i,(async(s,d,m)=>{if(t(m,1,1,o,i),c(m[0]))return await m[0].load(),n.convertObjectToArcadeDictionary(m[0].schema(),u(o));if(r(m[0])){const a=w(m[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))}}export{b as registerFunctions};
5
+ import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as e}from"../executionError.js";import{H as t,r,W as o,j as i,u as c,a3 as s,V as d,N as u,X as m,a4 as f,Y as l,a5 as y,K as v,t as p,U as w}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as h}from"../featureset/support/shared.js";function T(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:h[a.field.type],codedValues:a.domain.codedValues.map((n=>({name:n.name,code:n.code})))},u(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:h[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},u(e)):null}function b(h){"async"===h.mode&&(h.functions.domain=function(n,d){return h.standardFunctionAsync(n,d,(async(u,m,f)=>{if(t(f,2,3,n,d),r(f[0])){return T(o(f[0],i(f[1]),void 0===f[2]?void 0:f[2]),n)}if(c(f[0])){await f[0]._ensureLoaded();return T(s(i(f[1]),f[0],null,void 0===f[2]?void 0:f[2]),n)}throw new a(n,e.InvalidParameter,d)}))},h.functions.subtypes=function(o,i){return h.standardFunctionAsync(o,i,(async(s,m,f)=>{if(t(f,1,1,o,i),r(f[0])){const a=d(f[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}if(c(f[0])){await f[0]._ensureLoaded();const a=f[0].subtypeMetaData();return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))},h.functions.domainname=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,l)=>{if(t(l,2,4,n,o),r(l[0]))return m(l[0],i(l[1]),l[2],void 0===l[3]?void 0:l[3]);if(c(l[0])){await l[0]._ensureLoaded();const n=s(i(l[1]),l[0],null,void 0===l[3]?void 0:l[3]);return f(n,l[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domainname",min:2,max:4}),h.functions.domaincode=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,m)=>{if(t(m,2,4,n,o),r(m[0]))return l(m[0],i(m[1]),m[2],void 0===m[3]?void 0:m[3]);if(c(m[0])){await m[0]._ensureLoaded();const n=s(i(m[1]),m[0],null,void 0===m[3]?void 0:m[3]);return y(n,m[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domaincode",min:2,max:4})),h.functions.text=function(n,a){return h.standardFunctionAsync(n,a,((e,r,o)=>{if(t(o,1,2,n,a),!c(o[0]))return p(o[0],o[1]);{const n=v(o[1],"");if(""===n)return o[0].castToText();if("schema"===n.toLowerCase())return o[0].convertToText("schema",e.abortSignal);if("featureset"===n.toLowerCase())return o[0].convertToText("featureset",e.abortSignal)}}))},h.functions.gdbversion=function(n,o){return h.standardFunctionAsync(n,o,(async(i,s,d)=>{if(t(d,1,1,n,o),r(d[0]))return d[0].gdbVersion();if(c(d[0])){return(await d[0].load()).gdbVersion}throw new a(n,e.InvalidParameter,o)}))},h.functions.schema=function(o,i){return h.standardFunctionAsync(o,i,(async(s,d,m)=>{if(t(m,1,1,o,i),c(m[0]))return await m[0].load(),n.convertObjectToArcadeDictionary(m[0].schema(),u(o));if(r(m[0])){const a=w(m[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))}}export{b as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import{$ as e,B as t,b as n,c as r,F as a}from"../../chunks/languageUtils.js";function s(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t/e.length}function c(e){const t=s(e);let n=0;for(let r=0;r<e.length;r++)n+=(t-e[r])**2;return n/e.length}function u(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t}function i(e,s){const c=[],u={},i=[];for(let o=0;o<e.length;o++){if(void 0!==e[o]&&null!==e[o]&&e[o]!==t){const t=e[o];if(n(t)||r(t))void 0===u[t]&&(c.push(t),u[t]=1);else{let e=!1;for(let n=0;n<i.length;n++)!0===a(i[n],t)&&(e=!0);!1===e&&(i.push(t),c.push(t))}}if(c.length>=s&&-1!==s)return c}return c}function o(e){switch(e.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function l(t,n,r=1e3){switch(t.toLowerCase()){case"distinct":return i(n,r);case"avg":case"mean":return s(e(n));case"min":return Math.min.apply(Math,e(n));case"sum":return u(e(n));case"max":return Math.max.apply(Math,e(n));case"stdev":case"stddev":return Math.sqrt(c(e(n)));case"var":case"variance":return c(e(n));case"count":return n.length}return 0}export{l as calculateStat,o as decodeStatType};
5
+ import{_ as e,B as t,b as n,c as r,F as a}from"../../chunks/languageUtils.js";function s(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t/e.length}function c(e){const t=s(e);let n=0;for(let r=0;r<e.length;r++)n+=(t-e[r])**2;return n/e.length}function u(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n];return t}function i(e,s){const c=[],u={},i=[];for(let o=0;o<e.length;o++){if(void 0!==e[o]&&null!==e[o]&&e[o]!==t){const t=e[o];if(n(t)||r(t))void 0===u[t]&&(c.push(t),u[t]=1);else{let e=!1;for(let n=0;n<i.length;n++)!0===a(i[n],t)&&(e=!0);!1===e&&(i.push(t),c.push(t))}}if(c.length>=s&&-1!==s)return c}return c}function o(e){switch(e.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function l(t,n,r=1e3){switch(t.toLowerCase()){case"distinct":return i(n,r);case"avg":case"mean":return s(e(n));case"min":return Math.min.apply(Math,e(n));case"sum":return u(e(n));case"max":return Math.max.apply(Math,e(n));case"stdev":case"stddev":return Math.sqrt(c(e(n)));case"var":case"variance":return c(e(n));case"count":return n.length}return 0}export{l as calculateStat,o as decodeStatType};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../config.js";import"../../geometry.js";import r from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as o}from"../executionError.js";import{H as a,j as i,c as s,w as p,K as l,o as c,N as f,b as u,k as m,m as g,n as h,v as d,p as w,a7 as y}from"../../chunks/languageUtils.js";import{getPortal as j}from"../portalUtils.js";import S from"../../geometry/Geometry.js";import{isLoaded as R,load as v,project as G}from"../../geometry/projection.js";import{webMercatorToGeographic as k,geographicToWebMercator as x}from"../../geometry/support/webMercatorUtils.js";import P from"../../portal/Portal.js";import b from"../../portal/PortalItem.js";import{project as I}from"../../rest/geometryService/project.js";import W from"../../rest/knowledgeGraph/Entity.js";import T from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import D from"../../rest/knowledgeGraph/ObjectValue.js";import N from"../../rest/knowledgeGraph/Path.js";import q from"../../rest/knowledgeGraph/Relationship.js";import A from"../../rest/support/ProjectParameters.js";import U from"../../geometry/SpatialReference.js";let F=null;async function J(r){const t=e.geometryServiceUrl??"";if(!t){R()||await v();for(const e of r)e.container[e.indexer]=G(e.container[e.indexer],U.WGS84);return}const n=r.map((e=>e.container[e.indexer])),o=new A({geometries:n,outSpatialReference:U.WGS84}),a=await I(t,o);for(let e=0;e<a.length;e++){const t=r[e];t.container[t.indexer]=a[e]}}async function M(e,r){const t=new b({portal:e,id:r});return await t.load(),null===F&&(F=await import("../../rest/knowledgeGraphService.js")),await F.fetchKnowledgeGraph(t.url)}function Q(e,r,t,a,i){if(null===e)return null;if(s(e)||u(e))return e;if(m(e))return e.toJSDate();if(m(e))return e.toJSDate();if(g(e))return e.toStorageFormat();if(h(e))return e.toStorageString();if(d(e)){const n={};for(const o of e.keys())n[o]=Q(e.field(o),r,t,a,i),n[o]instanceof S&&i.push({container:n,indexer:o});return n}if(c(e)){const n=e.map((e=>Q(e,r,t,a,i)));for(let e=0;e<n.length;e++)n[e]instanceof S&&i.push({container:n,indexer:e});return n}if(w(e)){if(e.spatialReference.isWGS84)return e;if(e.spatialReference.isWebMercator&&r)return k(e);if(!r||!t)return e;throw new n(a,o.WrongSpatialReference,null)}}function E(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return x(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new n(r,o.WrongSpatialReference,null)}function K(e,r){if(!e)return null;const t={};for(const n in e)t[n]=V(e[n],r);return t}function V(e,r){return null===e?null:c(e)?e.map((e=>V(e,r))):e instanceof W?{graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:K(e.properties,r)}:e instanceof D?{graphType:"object",properties:K(e.properties,r)}:e instanceof q?{graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:K(e.properties,r)}:e instanceof N?{graphType:"path",path:e.path?e.path.map((e=>V(e,r))):null}:w(e)?E(e,r):s(e)||u(e)||y(e)?e:null}function C(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(t,p){return e.standardFunctionAsync(t,p,((e,l,c)=>{if(a(c,2,2,t,p),null===c[0])throw new n(t,o.PortalRequired,p);if(c[0]instanceof r){const e=i(c[1]);let r=null;r=t.services?.portal?t.services.portal:P.getDefault();return M(j(c[0],r),e)}if(!1===s(c[0]))throw new n(t,o.InvalidParameter,p);const f=i(c[0]);return M(t.services?.portal??P.getDefault(),f)}))},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,i){return e.standardFunctionAsync(r,i,(async(e,u,m)=>{a(m,2,4,r,i);const g=m[0];if(!p(g))throw new n(r,o.InvalidParameter,i);const h=m[1];if(!s(h))throw new n(r,o.InvalidParameter,i);null===F&&(F=await import("../../rest/knowledgeGraphService.js"));let d=null;const w=l(m[2],null);if(!(w instanceof t||null===w))throw new n(r,o.InvalidParameter,i);if(w){let e=[];d=Q(w,!0,!1,r,e),e=e.filter((e=>!e.container[e.indexer].spatialReference.isWGS84)),e.length>0&&await J(e)}const y=new T({openCypherQuery:h,bindParameters:d});(g?.serviceDefinition?.currentVersion??11.3)>11.2&&(y.outputSpatialReference=r.spatialReference);const j=(await F.executeQueryStreaming(g,y)).resultRowsStream.getReader(),S=[];try{for(;;){const{done:e,value:t}=await j.read();if(e)break;if(c(t))for(const n of t)S.push(V(n,r));else{const e=[];for(const n of t)e.push(V(t[n],r));S.push(e)}}}catch(R){throw R}return t.convertJsonToArcade(S,f(r),!1,!0)}))},e.signatures.push({name:"querygraph",min:2,max:4}))}export{C as registerFunctions};
5
+ import e from"../../config.js";import"../../geometry.js";import r from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as o}from"../executionError.js";import{H as a,j as i,c as s,w as p,K as l,o as c,N as f,b as u,k as m,m as g,n as h,v as d,p as w,a6 as y}from"../../chunks/languageUtils.js";import{getPortal as j}from"../portalUtils.js";import S from"../../geometry/Geometry.js";import{isLoaded as R,load as v,project as G}from"../../geometry/projection.js";import{webMercatorToGeographic as k,geographicToWebMercator as x}from"../../geometry/support/webMercatorUtils.js";import P from"../../portal/Portal.js";import b from"../../portal/PortalItem.js";import{project as I}from"../../rest/geometryService/project.js";import W from"../../rest/knowledgeGraph/Entity.js";import T from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import D from"../../rest/knowledgeGraph/ObjectValue.js";import N from"../../rest/knowledgeGraph/Path.js";import q from"../../rest/knowledgeGraph/Relationship.js";import A from"../../rest/support/ProjectParameters.js";import U from"../../geometry/SpatialReference.js";let F=null;async function J(r){const t=e.geometryServiceUrl??"";if(!t){R()||await v();for(const e of r)e.container[e.indexer]=G(e.container[e.indexer],U.WGS84);return}const n=r.map((e=>e.container[e.indexer])),o=new A({geometries:n,outSpatialReference:U.WGS84}),a=await I(t,o);for(let e=0;e<a.length;e++){const t=r[e];t.container[t.indexer]=a[e]}}async function M(e,r){const t=new b({portal:e,id:r});return await t.load(),null===F&&(F=await import("../../rest/knowledgeGraphService.js")),await F.fetchKnowledgeGraph(t.url)}function Q(e,r,t,a,i){if(null===e)return null;if(s(e)||u(e))return e;if(m(e))return e.toJSDate();if(m(e))return e.toJSDate();if(g(e))return e.toStorageFormat();if(h(e))return e.toStorageString();if(d(e)){const n={};for(const o of e.keys())n[o]=Q(e.field(o),r,t,a,i),n[o]instanceof S&&i.push({container:n,indexer:o});return n}if(c(e)){const n=e.map((e=>Q(e,r,t,a,i)));for(let e=0;e<n.length;e++)n[e]instanceof S&&i.push({container:n,indexer:e});return n}if(w(e)){if(e.spatialReference.isWGS84)return e;if(e.spatialReference.isWebMercator&&r)return k(e);if(!r||!t)return e;throw new n(a,o.WrongSpatialReference,null)}}function E(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return x(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new n(r,o.WrongSpatialReference,null)}function K(e,r){if(!e)return null;const t={};for(const n in e)t[n]=V(e[n],r);return t}function V(e,r){return null===e?null:c(e)?e.map((e=>V(e,r))):e instanceof W?{graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:K(e.properties,r)}:e instanceof D?{graphType:"object",properties:K(e.properties,r)}:e instanceof q?{graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:K(e.properties,r)}:e instanceof N?{graphType:"path",path:e.path?e.path.map((e=>V(e,r))):null}:w(e)?E(e,r):s(e)||u(e)||y(e)?e:null}function C(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(t,p){return e.standardFunctionAsync(t,p,((e,l,c)=>{if(a(c,2,2,t,p),null===c[0])throw new n(t,o.PortalRequired,p);if(c[0]instanceof r){const e=i(c[1]);let r=null;r=t.services?.portal?t.services.portal:P.getDefault();return M(j(c[0],r),e)}if(!1===s(c[0]))throw new n(t,o.InvalidParameter,p);const f=i(c[0]);return M(t.services?.portal??P.getDefault(),f)}))},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,i){return e.standardFunctionAsync(r,i,(async(e,u,m)=>{a(m,2,4,r,i);const g=m[0];if(!p(g))throw new n(r,o.InvalidParameter,i);const h=m[1];if(!s(h))throw new n(r,o.InvalidParameter,i);null===F&&(F=await import("../../rest/knowledgeGraphService.js"));let d=null;const w=l(m[2],null);if(!(w instanceof t||null===w))throw new n(r,o.InvalidParameter,i);if(w){let e=[];d=Q(w,!0,!1,r,e),e=e.filter((e=>!e.container[e.indexer].spatialReference.isWGS84)),e.length>0&&await J(e)}const y=new T({openCypherQuery:h,bindParameters:d});(g?.serviceDefinition?.currentVersion??11.3)>11.2&&(y.outputSpatialReference=r.spatialReference);const j=(await F.executeQueryStreaming(g,y)).resultRowsStream.getReader(),S=[];try{for(;;){const{done:e,value:t}=await j.read();if(e)break;if(c(t))for(const n of t)S.push(V(n,r));else{const e=[];for(const n of t)e.push(V(t[n],r));S.push(e)}}}catch(R){throw R}return t.convertJsonToArcade(S,f(r),!1,!0)}))},e.signatures.push({name:"querygraph",min:2,max:4}))}export{C as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as a}from"../executionError.js";import{H as o,j as i,P as u,g as s,U as l,B as d,K as p,h as c,t as f,o as h,q as y,T as m,r as g,V as A,N as w,W as I,X as v,Y as U,Z as b,c as j,_ as x,k as N,m as P,n as F,a as T,b as C,i as O,u as k,s as L}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as S}from"../featureset/support/shared.js";import{convertDirection as z}from"./convertdirection.js";import{XXH as D}from"./hash.js";import{hasSamePortal as R}from"../../core/urlUtils.js";import H from"../../geometry/Extent.js";import M from"../../geometry/Multipoint.js";import V from"../../geometry/Point.js";import W from"../../geometry/Polygon.js";import J from"../../geometry/Polyline.js";import B from"../../geometry/SpatialReference.js";import Z from"../../portal/Portal.js";function E(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function q(t,e){return!!t&&R(t,e?.restUrl||"")}function K(t,e){if(!t||!e)return t===e;if(t.x===e.x&&t.y===e.y){if(t.hasZ){if(t.z!==e.z)return!1}else if(e.hasZ)return!1;if(t.hasM){if(t.m!==e.m)return!1}else if(e.hasM)return!1;return!0}return!1}function X(o,i,u){if(null!==o)if(h(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o)X(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else if(y(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.toArray())X(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else{if(N(o))return i.updateIntArray([o.toNumber()]),void i.updateUint8Array([241]);if(P(o))return i.updateIntArray([o.toNumber()]),void i.updateIntArray([257]);if(F(o))return i.updateIntArray([o.toNumber()]),void i.updateIntArray([263]);if(j(o))return i.updateIntArray([o.length]),i.updateWithString(o),void i.updateUint8Array([41]);if(T(o))i.updateUint8Array([!0===o?1:0,113]);else{if(C(o))return i.updateFloatArray([o]),void i.updateUint8Array([173]);if(o instanceof e)throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof t)throw new n(u.context,a.UnsupportedHashType,u.node);if(!(o instanceof r)){if(g(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof V)return i.updateIntArray([3833836621]),i.updateIntArray([0]),i.updateFloatArray([o.x]),i.updateIntArray([1]),i.updateFloatArray([o.y]),o.hasZ&&(i.updateIntArray([2]),i.updateFloatArray([o.z])),o.hasM&&(i.updateIntArray([3]),i.updateFloatArray([o.m])),i.updateIntArray([3765347959]),void X(o.spatialReference.wkid,i,u);if(o instanceof W){i.updateIntArray([1266616829]);for(let t=0;t<o.rings.length;t++){const e=o.rings[t],r=[];let n=null,a=null;for(let i=0;i<e.length;i++){const u=o.getPoint(t,i);if(0===i)n=u;else if(K(a,u))continue;a=u,i===e.length-1&&K(n,u)||r.push(u)}i.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];i.updateIntArray([3962308117,t]),X(e,i,u),i.updateIntArray([2716288009])}i.updateIntArray([2278822459])}return i.updateIntArray([3878477243]),void X(o.spatialReference.wkid,i,u)}if(o instanceof J){i.updateIntArray([4106883559]);for(let t=0;t<o.paths.length;t++){const e=o.paths[t];i.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)i.updateIntArray([3962308117,r]),X(o.getPoint(t,r),i,u),i.updateIntArray([2716288009]);i.updateIntArray([2278822459])}return i.updateIntArray([2568784753]),void X(o.spatialReference.wkid,i,u)}if(o instanceof M){i.updateIntArray([588535921,o.points.length]);for(let t=0;t<o.points.length;t++){const e=o.getPoint(t);i.updateIntArray([t]),X(e,i,u)}return i.updateIntArray([1700171621]),void X(o.spatialReference.wkid,i,u)}if(o instanceof H)return i.updateIntArray([3483648373]),i.updateIntArray([0]),i.updateFloatArray([o.xmax]),i.updateIntArray([1]),i.updateFloatArray([o.xmin]),i.updateIntArray([2]),i.updateFloatArray([o.ymax]),i.updateIntArray([3]),i.updateFloatArray([o.ymin]),o.hasZ&&(i.updateIntArray([4]),i.updateFloatArray([o.zmax]),i.updateIntArray([5]),i.updateFloatArray([o.zmin])),o.hasM&&(i.updateIntArray([6]),i.updateFloatArray([o.mmax]),i.updateIntArray([7]),i.updateFloatArray([o.mmin])),i.updateIntArray([3622027469]),void X(o.spatialReference.wkid,i,u);if(o instanceof B)return i.updateIntArray([14]),void 0!==o.wkid&&null!==o.wkid&&i.updateIntArray([o.wkid]),o.wkt&&i.updateWithString(o.wkt),void(o.wkt2&&i.updateWithString(o.wkt2));if(O(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(k(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(L(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o===d)throw new n(u.context,a.UnsupportedHashType,u.node);throw new n(u.context,a.UnsupportedHashType,u.node)}if(i.updateUint8Array([223]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.keys()){i.updateIntArray([t.length]),i.updateWithString(t),i.updateUint8Array([251]);X(o.field(t),i,u),i.updateUint8Array([239])}u.map.delete(o),u.currentLength--}i.updateUint8Array([73])}}else i.updateUint8Array([0,139])}function Y(e,N){e.portal=function(e,r){return N(e,r,((n,a,u)=>(o(u,1,1,e,r),new t(i(u[0])))))},e.typeof=function(t,e){return N(t,e,((r,i,s)=>{o(s,1,1,t,e);const l=u(s[0]);if("Unrecognized Type"===l)throw new n(t,a.UnrecognizedType,e);return l}))},e.trim=function(t,e){return N(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim())))},e.tohex=function(t,e){return N(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)}))},e.upper=function(t,e){return N(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase())))},e.proper=function(t,e){return N(t,e,((r,n,a)=>{o(a,1,2,t,e);let u=1;2===a.length&&"firstword"===i(a[1]).toLowerCase()&&(u=2);const s=/\s/,l=i(a[0]);let d="",p=!0;for(let t=0;t<l.length;t++){let e=l[t];if(s.test(e))1===u&&(p=!0);else{e.toUpperCase()!==e.toLowerCase()&&(p?(e=e.toUpperCase(),p=!1):e=e.toLowerCase())}d+=e}return d}))},e.lower=function(t,e){return N(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase())))},e.guid=function(t,e){return N(t,e,((r,n,a)=>{if(o(a,0,1,t,e),a.length>0)switch(i(a[0]).toLowerCase()){case"digits":return l().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return l();case"digits-hyphen-braces":return"{"+l()+"}";case"digits-hyphen-parentheses":return"("+l()+")"}return"{"+l()+"}"}))},e.standardizeguid=function(t,e){return N(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(\-?)(?<partB>[0-9a-z]{4})(\-?)(?<partC>[0-9a-z]{4})(\-?)(?<partD>[0-9a-z]{4})(\-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const l=s.groups;switch(u=l.partA+"-"+l.partB+"-"+l.partC+"-"+l.partD+"-"+l.partE,i(a[1]).toLowerCase()){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-braces":return"{"+u+"}";case"digits-hyphen-parentheses":return"("+u+")"}return"{"+u+"}"}))},e.console=function(t,e){return N(t,e,((e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),d)))},e.mid=function(t,e){return N(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u<0&&(u=0),2===a.length)return i(a[0]).substr(u);let l=s(a[2]);return isNaN(l)?"":(l<0&&(l=0),i(a[0]).substr(u,l))}))},e.find=function(t,e){return N(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(p(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)}))},e.left=function(t,e){return N(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(0,u))}))},e.right=function(t,e){return N(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(-1*u,u))}))},e.split=function(t,e){return N(t,e,((r,n,a)=>{let u;o(a,2,4,t,e);let l=s(p(a[2],-1));const d=c(p(a[3],!1));if(-1===l||null===l||!0===d?u=i(a[0]).split(i(a[1])):(isNaN(l)&&(l=-1),l<-1&&(l=-1),u=i(a[0]).split(i(a[1]),l)),!1===d)return u;const f=[];for(let t=0;t<u.length&&!(-1!==l&&f.length>=l);t++)""!==u[t]&&void 0!==u[t]&&f.push(u[t]);return f}))},e.text=function(t,e){return N(t,e,((r,n,a)=>(o(a,1,2,t,e),f(a[0],a[1]))))},e.concatenate=function(t,e){return N(t,e,((t,e,r)=>{const n=[];if(r.length<1)return"";if(h(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=f(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(y(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=f(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=f(r[a]);return n.join("")}))},e.reverse=function(t,e){return N(t,e,((r,i,u)=>{if(o(u,1,1,t,e),h(u[0])){const t=u[0].slice(0);return t.reverse(),t}if(y(u[0])){const t=u[0].toArray().slice(0);return t.reverse(),t}throw new n(t,a.InvalidParameter,e)}))},e.replace=function(t,e){return N(t,e,((r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),l=i(a[2]);return 4!==a.length||c(a[3])?m(u,s,l):u.replace(s,l)}))},e.schema=function(t,e){return N(t,e,((o,i,u)=>{if(g(u[0])){const e=A(u[0]);return e?r.convertObjectToArcadeDictionary(e,w(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypes=function(t,e){return N(t,e,((i,u,s)=>{if(o(s,1,1,t,e),g(s[0])){const e=I(s[0]);return e?r.convertObjectToArcadeDictionary(e,w(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypecode=function(t,e){return N(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0])){const t=I(u[0]);if(!t)return null;if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.code;return null}return null}throw new n(t,a.InvalidParameter,e)}))},e.subtypename=function(t,e){return N(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0])){const t=I(u[0]);if(!t)return"";if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.name;return""}return""}throw new n(t,a.InvalidParameter,e)}))},e.gdbversion=function(t,e){return N(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0]))return u[0].gdbVersion();throw new n(t,a.InvalidParameter,e)}))},e.domain=function(t,e){return N(t,e,((u,s,l)=>{if(o(l,2,3,t,e),g(l[0])){const e=v(l[0],i(l[1]),void 0===l[2]?void 0:l[2]);return e&&e.domain?"coded-value"===e.domain.type||"codedValue"===e.domain.type?r.convertObjectToArcadeDictionary({type:"codedValue",name:e.domain.name,dataType:S[e.field.type],codedValues:e.domain.codedValues.map((t=>({name:t.name,code:t.code})))},w(t)):r.convertObjectToArcadeDictionary({type:"range",name:e.domain.name,dataType:S[e.field.type],min:e.domain.minValue,max:e.domain.maxValue},w(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.domainname=function(t,e){return N(t,e,((r,u,s)=>{if(o(s,2,4,t,e),g(s[0]))return U(s[0],i(s[1]),s[2],void 0===s[3]?void 0:s[3]);throw new n(t,a.InvalidParameter,e)}))},e.domaincode=function(t,e){return N(t,e,((r,u,s)=>{if(o(s,2,4,t,e),g(s[0]))return b(s[0],i(s[1]),s[2],void 0===s[3]?void 0:s[3]);throw new n(t,a.InvalidParameter,e)}))},e.urlencode=function(t,e){return N(t,e,((n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))}))},e.hash=function(t,e){return N(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=new D(0);return X(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()}))},e.convertdirection=function(t,e){return N(t,e,((r,n,a)=>(o(a,3,3,t,e),z(a[0],a[1],a[2]))))},e.fromjson=function(t,e){return N(t,e,((u,s,l)=>{if(o(l,1,1,t,e),!1===j(l[0]))throw new n(t,a.InvalidParameter,e);return r.convertJsonToArcade(JSON.parse(i(l[0])),w(t))}))},e.expects=function(t,e){return N(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);return d}))},e.tocharcode=function(t,e){return N(t,e,((r,u,l)=>{o(l,1,2,t,e);const d=s(p(l[1],0)),c=i(l[0]);if(0===c.length&&1===l.length)return null;if(c.length<=d||d<0)throw new n(t,a.OutOfBounds,e);return c.charCodeAt(d)}))},e.tocodepoint=function(t,e){return N(t,e,((r,u,l)=>{o(l,1,2,t,e);const d=s(p(l[1],0)),c=i(l[0]);if(0===c.length&&1===l.length)return null;if(c.length<=d||d<0)throw new n(t,a.OutOfBounds,e);return c.codePointAt(d)}))},e.fromcharcode=function(t,e){return N(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);const u=i.map((t=>Math.trunc(s(t)))).filter((t=>t>=0&&t<=65535));return 0===u.length?null:String.fromCharCode.apply(null,u)}))},e.fromcodepoint=function(t,e){return N(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);let u;try{u=i.map((t=>Math.trunc(s(t)))).filter((t=>t<=1114111&&t>>>0===t))}catch(l){return null}return 0===u.length?null:String.fromCodePoint.apply(null,u)}))},e.getuser=function(e,u){return N(e,u,((s,l,d)=>{o(d,0,2,e,u);let c=p(d[1],"");if(c=!0===c||!1===c?"":i(c),null!==c&&""!==c)return null;if(0===d.length||d[0]instanceof t){let t=null;if(t=e.services?.portal?e.services.portal:Z.getDefault(),d.length>0){if(!q(d[0].field("url"),t))return null}if(!t)return null;if(""===c){const n=E(t);if(n){const t=JSON.parse(JSON.stringify(n));for(const e of["lastLogin","created","modified"])void 0!==t[e]&&null!==t[e]&&(t[e]=new Date(t[e]));return r.convertObjectToArcadeDictionary(t,w(e))}}return null}throw new n(e,a.InvalidParameter,u)}))},e.getenvironment=function(t,e){return N(t,e,((n,a,i)=>(o(i,0,0,t,e),r.convertObjectToArcadeDictionary(x(w(t),t.spatialReference),w(t),!0))))}}export{Y as registerFunctions};
5
+ import t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as a}from"../executionError.js";import{H as o,j as i,P as u,g as s,B as l,K as d,h as p,t as c,o as f,q as h,T as y,r as m,U as g,N as A,V as w,W as I,X as v,Y as U,c as b,Z as j,k as x,m as N,n as P,a as F,b as T,i as C,u as O,s as k}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as L}from"../featureset/support/shared.js";import{convertDirection as S}from"./convertdirection.js";import{XXH as z}from"./hash.js";import{hasSamePortal as D}from"../../core/urlUtils.js";import{generateUUID as R}from"../../core/uuid.js";import H from"../../geometry/Extent.js";import M from"../../geometry/Multipoint.js";import V from"../../geometry/Point.js";import W from"../../geometry/Polygon.js";import J from"../../geometry/Polyline.js";import B from"../../geometry/SpatialReference.js";import Z from"../../portal/Portal.js";function E(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function q(t,e){return!!t&&D(t,e?.restUrl||"")}function K(t,e){if(!t||!e)return t===e;if(t.x===e.x&&t.y===e.y){if(t.hasZ){if(t.z!==e.z)return!1}else if(e.hasZ)return!1;if(t.hasM){if(t.m!==e.m)return!1}else if(e.hasM)return!1;return!0}return!1}function X(o,i,u){if(null!==o)if(f(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o)X(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else if(h(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.toArray())X(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else{if(x(o))return i.updateIntArray([o.toNumber()]),void i.updateUint8Array([241]);if(N(o))return i.updateIntArray([o.toNumber()]),void i.updateIntArray([257]);if(P(o))return i.updateIntArray([o.toNumber()]),void i.updateIntArray([263]);if(b(o))return i.updateIntArray([o.length]),i.updateWithString(o),void i.updateUint8Array([41]);if(F(o))i.updateUint8Array([!0===o?1:0,113]);else{if(T(o))return i.updateFloatArray([o]),void i.updateUint8Array([173]);if(o instanceof e)throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof t)throw new n(u.context,a.UnsupportedHashType,u.node);if(!(o instanceof r)){if(m(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof V)return i.updateIntArray([3833836621]),i.updateIntArray([0]),i.updateFloatArray([o.x]),i.updateIntArray([1]),i.updateFloatArray([o.y]),o.hasZ&&(i.updateIntArray([2]),i.updateFloatArray([o.z])),o.hasM&&(i.updateIntArray([3]),i.updateFloatArray([o.m])),i.updateIntArray([3765347959]),void X(o.spatialReference.wkid,i,u);if(o instanceof W){i.updateIntArray([1266616829]);for(let t=0;t<o.rings.length;t++){const e=o.rings[t],r=[];let n=null,a=null;for(let i=0;i<e.length;i++){const u=o.getPoint(t,i);if(0===i)n=u;else if(K(a,u))continue;a=u,i===e.length-1&&K(n,u)||r.push(u)}i.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];i.updateIntArray([3962308117,t]),X(e,i,u),i.updateIntArray([2716288009])}i.updateIntArray([2278822459])}return i.updateIntArray([3878477243]),void X(o.spatialReference.wkid,i,u)}if(o instanceof J){i.updateIntArray([4106883559]);for(let t=0;t<o.paths.length;t++){const e=o.paths[t];i.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)i.updateIntArray([3962308117,r]),X(o.getPoint(t,r),i,u),i.updateIntArray([2716288009]);i.updateIntArray([2278822459])}return i.updateIntArray([2568784753]),void X(o.spatialReference.wkid,i,u)}if(o instanceof M){i.updateIntArray([588535921,o.points.length]);for(let t=0;t<o.points.length;t++){const e=o.getPoint(t);i.updateIntArray([t]),X(e,i,u)}return i.updateIntArray([1700171621]),void X(o.spatialReference.wkid,i,u)}if(o instanceof H)return i.updateIntArray([3483648373]),i.updateIntArray([0]),i.updateFloatArray([o.xmax]),i.updateIntArray([1]),i.updateFloatArray([o.xmin]),i.updateIntArray([2]),i.updateFloatArray([o.ymax]),i.updateIntArray([3]),i.updateFloatArray([o.ymin]),o.hasZ&&(i.updateIntArray([4]),i.updateFloatArray([o.zmax]),i.updateIntArray([5]),i.updateFloatArray([o.zmin])),o.hasM&&(i.updateIntArray([6]),i.updateFloatArray([o.mmax]),i.updateIntArray([7]),i.updateFloatArray([o.mmin])),i.updateIntArray([3622027469]),void X(o.spatialReference.wkid,i,u);if(o instanceof B)return i.updateIntArray([14]),void 0!==o.wkid&&null!==o.wkid&&i.updateIntArray([o.wkid]),o.wkt&&i.updateWithString(o.wkt),void(o.wkt2&&i.updateWithString(o.wkt2));if(C(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(O(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(k(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o===l)throw new n(u.context,a.UnsupportedHashType,u.node);throw new n(u.context,a.UnsupportedHashType,u.node)}if(i.updateUint8Array([223]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.keys()){i.updateIntArray([t.length]),i.updateWithString(t),i.updateUint8Array([251]);X(o.field(t),i,u),i.updateUint8Array([239])}u.map.delete(o),u.currentLength--}i.updateUint8Array([73])}}else i.updateUint8Array([0,139])}function Y(e,x){e.portal=function(e,r){return x(e,r,((n,a,u)=>(o(u,1,1,e,r),new t(i(u[0])))))},e.typeof=function(t,e){return x(t,e,((r,i,s)=>{o(s,1,1,t,e);const l=u(s[0]);if("Unrecognized Type"===l)throw new n(t,a.UnrecognizedType,e);return l}))},e.trim=function(t,e){return x(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim())))},e.tohex=function(t,e){return x(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)}))},e.upper=function(t,e){return x(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase())))},e.proper=function(t,e){return x(t,e,((r,n,a)=>{o(a,1,2,t,e);let u=1;2===a.length&&"firstword"===i(a[1]).toLowerCase()&&(u=2);const s=/\s/,l=i(a[0]);let d="",p=!0;for(let t=0;t<l.length;t++){let e=l[t];if(s.test(e))1===u&&(p=!0);else{e.toUpperCase()!==e.toLowerCase()&&(p?(e=e.toUpperCase(),p=!1):e=e.toLowerCase())}d+=e}return d}))},e.lower=function(t,e){return x(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase())))},e.guid=function(t,e){return x(t,e,((r,n,a)=>{if(o(a,0,1,t,e),a.length>0)switch(i(a[0]).toLowerCase()){case"digits":return R().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return R();case"digits-hyphen-braces":return"{"+R()+"}";case"digits-hyphen-parentheses":return"("+R()+")"}return"{"+R()+"}"}))},e.standardizeguid=function(t,e){return x(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(\-?)(?<partB>[0-9a-z]{4})(\-?)(?<partC>[0-9a-z]{4})(\-?)(?<partD>[0-9a-z]{4})(\-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const l=s.groups;switch(u=l.partA+"-"+l.partB+"-"+l.partC+"-"+l.partD+"-"+l.partE,i(a[1]).toLowerCase()){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-braces":return"{"+u+"}";case"digits-hyphen-parentheses":return"("+u+")"}return"{"+u+"}"}))},e.console=function(t,e){return x(t,e,((e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),l)))},e.mid=function(t,e){return x(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u<0&&(u=0),2===a.length)return i(a[0]).substr(u);let l=s(a[2]);return isNaN(l)?"":(l<0&&(l=0),i(a[0]).substr(u,l))}))},e.find=function(t,e){return x(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(d(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)}))},e.left=function(t,e){return x(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(0,u))}))},e.right=function(t,e){return x(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(-1*u,u))}))},e.split=function(t,e){return x(t,e,((r,n,a)=>{let u;o(a,2,4,t,e);let l=s(d(a[2],-1));const c=p(d(a[3],!1));if(-1===l||null===l||!0===c?u=i(a[0]).split(i(a[1])):(isNaN(l)&&(l=-1),l<-1&&(l=-1),u=i(a[0]).split(i(a[1]),l)),!1===c)return u;const f=[];for(let t=0;t<u.length&&!(-1!==l&&f.length>=l);t++)""!==u[t]&&void 0!==u[t]&&f.push(u[t]);return f}))},e.text=function(t,e){return x(t,e,((r,n,a)=>(o(a,1,2,t,e),c(a[0],a[1]))))},e.concatenate=function(t,e){return x(t,e,((t,e,r)=>{const n=[];if(r.length<1)return"";if(f(r[0])){const t=d(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=c(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(h(r[0])){const t=d(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=c(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=c(r[a]);return n.join("")}))},e.reverse=function(t,e){return x(t,e,((r,i,u)=>{if(o(u,1,1,t,e),f(u[0])){const t=u[0].slice(0);return t.reverse(),t}if(h(u[0])){const t=u[0].toArray().slice(0);return t.reverse(),t}throw new n(t,a.InvalidParameter,e)}))},e.replace=function(t,e){return x(t,e,((r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),l=i(a[2]);return 4!==a.length||p(a[3])?y(u,s,l):u.replace(s,l)}))},e.schema=function(t,e){return x(t,e,((o,i,u)=>{if(m(u[0])){const e=g(u[0]);return e?r.convertObjectToArcadeDictionary(e,A(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypes=function(t,e){return x(t,e,((i,u,s)=>{if(o(s,1,1,t,e),m(s[0])){const e=w(s[0]);return e?r.convertObjectToArcadeDictionary(e,A(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypecode=function(t,e){return x(t,e,((r,i,u)=>{if(o(u,1,1,t,e),m(u[0])){const t=w(u[0]);if(!t)return null;if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.code;return null}return null}throw new n(t,a.InvalidParameter,e)}))},e.subtypename=function(t,e){return x(t,e,((r,i,u)=>{if(o(u,1,1,t,e),m(u[0])){const t=w(u[0]);if(!t)return"";if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.name;return""}return""}throw new n(t,a.InvalidParameter,e)}))},e.gdbversion=function(t,e){return x(t,e,((r,i,u)=>{if(o(u,1,1,t,e),m(u[0]))return u[0].gdbVersion();throw new n(t,a.InvalidParameter,e)}))},e.domain=function(t,e){return x(t,e,((u,s,l)=>{if(o(l,2,3,t,e),m(l[0])){const e=I(l[0],i(l[1]),void 0===l[2]?void 0:l[2]);return e&&e.domain?"coded-value"===e.domain.type||"codedValue"===e.domain.type?r.convertObjectToArcadeDictionary({type:"codedValue",name:e.domain.name,dataType:L[e.field.type],codedValues:e.domain.codedValues.map((t=>({name:t.name,code:t.code})))},A(t)):r.convertObjectToArcadeDictionary({type:"range",name:e.domain.name,dataType:L[e.field.type],min:e.domain.minValue,max:e.domain.maxValue},A(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.domainname=function(t,e){return x(t,e,((r,u,s)=>{if(o(s,2,4,t,e),m(s[0]))return v(s[0],i(s[1]),s[2],void 0===s[3]?void 0:s[3]);throw new n(t,a.InvalidParameter,e)}))},e.domaincode=function(t,e){return x(t,e,((r,u,s)=>{if(o(s,2,4,t,e),m(s[0]))return U(s[0],i(s[1]),s[2],void 0===s[3]?void 0:s[3]);throw new n(t,a.InvalidParameter,e)}))},e.urlencode=function(t,e){return x(t,e,((n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))}))},e.hash=function(t,e){return x(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=new z(0);return X(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()}))},e.convertdirection=function(t,e){return x(t,e,((r,n,a)=>(o(a,3,3,t,e),S(a[0],a[1],a[2]))))},e.fromjson=function(t,e){return x(t,e,((u,s,l)=>{if(o(l,1,1,t,e),!1===b(l[0]))throw new n(t,a.InvalidParameter,e);return r.convertJsonToArcade(JSON.parse(i(l[0])),A(t))}))},e.expects=function(t,e){return x(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);return l}))},e.tocharcode=function(t,e){return x(t,e,((r,u,l)=>{o(l,1,2,t,e);const p=s(d(l[1],0)),c=i(l[0]);if(0===c.length&&1===l.length)return null;if(c.length<=p||p<0)throw new n(t,a.OutOfBounds,e);return c.charCodeAt(p)}))},e.tocodepoint=function(t,e){return x(t,e,((r,u,l)=>{o(l,1,2,t,e);const p=s(d(l[1],0)),c=i(l[0]);if(0===c.length&&1===l.length)return null;if(c.length<=p||p<0)throw new n(t,a.OutOfBounds,e);return c.codePointAt(p)}))},e.fromcharcode=function(t,e){return x(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);const u=i.map((t=>Math.trunc(s(t)))).filter((t=>t>=0&&t<=65535));return 0===u.length?null:String.fromCharCode.apply(null,u)}))},e.fromcodepoint=function(t,e){return x(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);let u;try{u=i.map((t=>Math.trunc(s(t)))).filter((t=>t<=1114111&&t>>>0===t))}catch(l){return null}return 0===u.length?null:String.fromCodePoint.apply(null,u)}))},e.getuser=function(e,u){return x(e,u,((s,l,p)=>{o(p,0,2,e,u);let c=d(p[1],"");if(c=!0===c||!1===c?"":i(c),null!==c&&""!==c)return null;if(0===p.length||p[0]instanceof t){let t=null;if(t=e.services?.portal?e.services.portal:Z.getDefault(),p.length>0){if(!q(p[0].field("url"),t))return null}if(!t)return null;if(""===c){const n=E(t);if(n){const t=JSON.parse(JSON.stringify(n));for(const e of["lastLogin","created","modified"])void 0!==t[e]&&null!==t[e]&&(t[e]=new Date(t[e]));return r.convertObjectToArcadeDictionary(t,A(e))}}return null}throw new n(e,a.InvalidParameter,u)}))},e.getenvironment=function(t,e){return x(t,e,((n,a,i)=>(o(i,0,0,t,e),r.convertObjectToArcadeDictionary(j(A(t),t.spatialReference),A(t),!0))))}}export{Y as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.30/esri/copyright.txt for details.
4
4
  */
5
- import"../config.js";import"../kernel.js";import"./ArcadeDate.js";import"./ArcadeModule.js";import"./executionError.js";import"./FunctionWrapper.js";import"./ImmutableArray.js";import"./ImmutablePathArray.js";import"./ImmutablePointArray.js";import"./featureset/support/shared.js";import"../core/number.js";import"../core/sql/DateOnly.js";import"../core/sql/TimeOnly.js";import"../geometry/Extent.js";import"../geometry/Geometry.js";import"../geometry/Multipoint.js";import"../geometry/Point.js";import"../geometry/Polygon.js";import"../geometry/Polyline.js";import"../geometry/SpatialReference.js";import"../geometry/support/coordsUtils.js";import"../geometry/support/jsonUtils.js";import"../intl/locale.js";import"luxon";export{a9 as ImplicitResultE,a8 as ReturnResultE,R as absRound,ag as arcadeVersion,M as autoCastArrayOfPointsToMultiPoint,J as autoCastArrayOfPointsToPolygon,L as autoCastArrayOfPointsToPolyline,I as autoCastFeatureToGeometry,G as binaryOperator,C as breakResult,d as castAsJson,e as castAsJsonAsync,D as continueResult,_ as defaultExecutingContext,N as defaultTimeZone,K as defaultUndefined,F as equalityTest,Z as featureDomainCodeLookup,Y as featureDomainValueLookup,X as featureFullDomain,V as featureSchema,W as featureSubtypes,S as fixNullGeometry,x as fixSpatialReference,ad as formatDate,ac as formatNumber,U as generateUUID,a4 as getDomain,a6 as getDomainCode,a5 as getDomainValue,P as getType,E as greaterThanLessThan,A as implicitResult,o as isArray,a as isBoolean,k as isDate,m as isDateOnly,v as isDictionary,r as isFeature,u as isFeatureSet,s as isFeatureSetCollection,i as isFunctionParameter,p as isGeometry,q as isImmutableArray,O as isInteger,a7 as isJsDate,w as isKnowledgeGraph,aa as isModule,b as isNumber,ab as isObject,f as isSimpleType,c as isString,a0 as isSubtypeGrouplayer,a1 as isSubtypeSublayer,n as isTime,T as multiReplace,ae as parseGeometryFromJson,H as pcCheck,z as returnResult,af as stableStringify,Q as standardiseDateFormat,a2 as tick,h as toBoolean,l as toDate,g as toNumber,$ as toNumberArray,j as toString,a3 as toStringArray,t as toStringExplicit,B as voidOperation}from"../chunks/languageUtils.js";
5
+ import"../config.js";import"../kernel.js";import"./ArcadeDate.js";import"./ArcadeModule.js";import"./executionError.js";import"./FunctionWrapper.js";import"./ImmutableArray.js";import"./ImmutablePathArray.js";import"./ImmutablePointArray.js";import"./featureset/support/shared.js";import"../core/number.js";import"../core/sql/DateOnly.js";import"../core/sql/TimeOnly.js";import"../geometry/Extent.js";import"../geometry/Geometry.js";import"../geometry/Multipoint.js";import"../geometry/Point.js";import"../geometry/Polygon.js";import"../geometry/Polyline.js";import"../geometry/SpatialReference.js";import"../geometry/support/coordsUtils.js";import"../geometry/support/jsonUtils.js";import"../intl/locale.js";import"luxon";export{a8 as ImplicitResultE,a7 as ReturnResultE,R as absRound,af as arcadeVersion,M as autoCastArrayOfPointsToMultiPoint,J as autoCastArrayOfPointsToPolygon,L as autoCastArrayOfPointsToPolyline,I as autoCastFeatureToGeometry,G as binaryOperator,C as breakResult,d as castAsJson,e as castAsJsonAsync,D as continueResult,Z as defaultExecutingContext,N as defaultTimeZone,K as defaultUndefined,F as equalityTest,Y as featureDomainCodeLookup,X as featureDomainValueLookup,W as featureFullDomain,U as featureSchema,V as featureSubtypes,S as fixNullGeometry,x as fixSpatialReference,ac as formatDate,ab as formatNumber,a3 as getDomain,a5 as getDomainCode,a4 as getDomainValue,P as getType,E as greaterThanLessThan,A as implicitResult,o as isArray,a as isBoolean,k as isDate,m as isDateOnly,v as isDictionary,r as isFeature,u as isFeatureSet,s as isFeatureSetCollection,i as isFunctionParameter,p as isGeometry,q as isImmutableArray,O as isInteger,a6 as isJsDate,w as isKnowledgeGraph,a9 as isModule,b as isNumber,aa as isObject,f as isSimpleType,c as isString,$ as isSubtypeGrouplayer,a0 as isSubtypeSublayer,n as isTime,T as multiReplace,ad as parseGeometryFromJson,H as pcCheck,z as returnResult,ae as stableStringify,Q as standardiseDateFormat,a1 as tick,h as toBoolean,l as toDate,g as toNumber,_ as toNumberArray,j as toString,a2 as toStringArray,t as toStringExplicit,B as voidOperation}from"../chunks/languageUtils.js";