@arcgis/core 5.2.0-next.30 → 5.2.0-next.32

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 (156) hide show
  1. package/WebDocument2D.js +1 -1
  2. package/WebScene.js +1 -1
  3. package/arcade/ArcadePortal.js +1 -1
  4. package/arcade/Attachment.js +1 -1
  5. package/arcade/Dictionary.js +1 -1
  6. package/arcade/Feature.js +1 -1
  7. package/arcade/arcadeAsyncRuntime.js +1 -1
  8. package/arcade/arcadeCompiler.js +1 -1
  9. package/arcade/arcadeRuntime.js +1 -1
  10. package/arcade/containerUtils.js +1 -1
  11. package/arcade/debug.js +1 -1
  12. package/arcade/deepClone.js +1 -1
  13. package/arcade/featureSetUtils.js +1 -1
  14. package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
  15. package/arcade/featureset/support/shared.js +1 -1
  16. package/arcade/functions/convertdirection.js +1 -1
  17. package/arcade/functions/date.js +1 -1
  18. package/arcade/functions/feature.js +1 -1
  19. package/arcade/functions/featuresetbase.js +1 -1
  20. package/arcade/functions/featuresetgeom.js +1 -1
  21. package/arcade/functions/featuresetstats.js +1 -1
  22. package/arcade/functions/featuresetstring.js +1 -1
  23. package/arcade/functions/geomasync.js +1 -1
  24. package/arcade/functions/geometry.js +1 -1
  25. package/arcade/functions/geomsync.js +1 -1
  26. package/arcade/functions/knowledgegraph.js +1 -1
  27. package/arcade/functions/maths.js +1 -1
  28. package/arcade/functions/stats.js +1 -1
  29. package/arcade/functions/string.js +1 -1
  30. package/arcade/geometry/constructors.js +1 -1
  31. package/arcade/geometry/functions.js +1 -1
  32. package/arcade/languageUtils.js +1 -1
  33. package/assets/esri/core/workers/RemoteClient.js +1 -1
  34. package/assets/esri/core/workers/chunks/{e5d2fab228d54b18a8a8.js → 08405116b5feb2d00101.js} +1 -1
  35. package/assets/esri/core/workers/chunks/{774615303c1cc9a77e20.js → 11af659688cf963ea6cd.js} +1 -1
  36. package/assets/esri/core/workers/chunks/{2665337e1b665e7e2b70.js → 15081b361fc42f40b865.js} +1 -1
  37. package/assets/esri/core/workers/chunks/{bcb2092c87d8d21c6458.js → 197b9f8483fad2258650.js} +1 -1
  38. package/assets/esri/core/workers/chunks/1cd8dff4373494b01ad4.js +1 -0
  39. package/assets/esri/core/workers/chunks/1d92da90fbbc3f98b201.js +1 -0
  40. package/assets/esri/core/workers/chunks/210ffc448c73a7bf63aa.js +1 -0
  41. package/assets/esri/core/workers/chunks/{a14e5607c5c091c77e3d.js → 2540beb53f1443a070d7.js} +1 -1
  42. package/assets/esri/core/workers/chunks/{689673173ca1c0e098fe.js → 25932fa010f9a32475c1.js} +1 -1
  43. package/assets/esri/core/workers/chunks/{e2d500ac1a264d09c857.js → 32b5d2537feefe6e94a3.js} +1 -1
  44. package/assets/esri/core/workers/chunks/34a024eda22d228e1fbe.js +1 -0
  45. package/assets/esri/core/workers/chunks/3f63b14b53b5ca716e3a.js +1 -0
  46. package/assets/esri/core/workers/chunks/{6df54132299b9e8f6dad.js → 456b77b8f13933a75b68.js} +1 -1
  47. package/assets/esri/core/workers/chunks/{3c342e662c13a05f4caf.js → 49713dfa4c8b788079d1.js} +1 -1
  48. package/assets/esri/core/workers/chunks/{45e4b9069263adeae394.js → 49a45083a9a155614c1c.js} +1 -1
  49. package/assets/esri/core/workers/chunks/4be31fcc5482a2526d2b.js +1 -0
  50. package/assets/esri/core/workers/chunks/{31d92ba9089617aa59ab.js → 57c003c6745d450558a7.js} +1 -1
  51. package/assets/esri/core/workers/chunks/{8104ac2eee69d79ada86.js → 6048c89fc4dcd2e9988d.js} +1 -1
  52. package/assets/esri/core/workers/chunks/{1b9c68e8431bb4608209.js → 6162f6735ea4622e54d8.js} +1 -1
  53. package/assets/esri/core/workers/chunks/684c9b4bd9590d2db12f.js +1 -0
  54. package/assets/esri/core/workers/chunks/684d3cb4fb233180b2d0.js +1 -0
  55. package/assets/esri/core/workers/chunks/{fe6385115d76e16e8da0.js → 75baf6dff6e7658b17b3.js} +1 -1
  56. package/assets/esri/core/workers/chunks/{166a0df6e37627e18976.js → 7a2dfa42610fe8414ed7.js} +1 -1
  57. package/assets/esri/core/workers/chunks/{43847d66726fd0bcbbb7.js → 83ae56c7fa8d84865605.js} +1 -1
  58. package/assets/esri/core/workers/chunks/8722e2790272e90a1897.js +1 -0
  59. package/assets/esri/core/workers/chunks/{1282598516cd0e3056b7.js → 977e6f589bd266d6067d.js} +2 -2
  60. package/assets/esri/core/workers/chunks/9f3d37e5f42bf1529673.js +1 -0
  61. package/assets/esri/core/workers/chunks/a833fc9250635eb4152f.js +1 -0
  62. package/assets/esri/core/workers/chunks/{47290f27375c76bcc9c7.js → b0253fe7b3529bc22270.js} +1 -1
  63. package/assets/esri/core/workers/chunks/b324bdb9c74fc3f956db.js +1 -0
  64. package/assets/esri/core/workers/chunks/{1bd7b7f4ee7ea6cb7ef9.js → b60f24a6c777301803f4.js} +1 -1
  65. package/assets/esri/core/workers/chunks/bd155794e9bc16dd0474.js +1 -0
  66. package/assets/esri/core/workers/chunks/{906f4c0fa8135e6c2f03.js → c660a5a1086870a3a6b9.js} +1 -1
  67. package/assets/esri/core/workers/chunks/cb58aff1ff186fa18345.js +1 -0
  68. package/assets/esri/core/workers/chunks/{17b98787a0698f584882.js → e7cb1b72f0b54e845741.js} +1 -1
  69. package/assets/esri/core/workers/chunks/{21122f3f3e19a7fd7d33.js → f69d3ff8a69c1985bca3.js} +1 -1
  70. package/assets/esri/libs/lyr3d/lyr3DMain.wasm +0 -0
  71. package/assets/esri/libs/parquet/pkg/bundle_bg.wasm +0 -0
  72. package/chunks/ShadowCastVisualize.glsl.js +4 -10
  73. package/chunks/aiServices.js +1 -1
  74. package/chunks/array.js +1 -1
  75. package/chunks/languageUtils.js +1 -1
  76. package/chunks/lyr3DMain.js +1 -1
  77. package/config.js +1 -1
  78. package/core/has.js +1 -1
  79. package/graphic/AnnotationFeatureGraphicOrigin.d.ts +3 -3
  80. package/graphic/AnnotationFeatureGraphicOrigin.js +1 -1
  81. package/intl/messages.d.ts +12 -2
  82. package/intl/t9n.d.ts +8 -1
  83. package/intl.d.ts +4 -0
  84. package/kernel.js +1 -1
  85. package/layers/AnnotationFeatureLayer.d.ts +1 -4
  86. package/layers/AnnotationFeatureLayer.js +1 -1
  87. package/layers/DimensionFeatureLayer.js +1 -1
  88. package/layers/VoxelWasmPerSceneView.js +1 -1
  89. package/layers/mixins/DataElementMixin.js +2 -0
  90. package/layers/support/AnnotationFeatureSublayer.js +1 -1
  91. package/layers/support/parquetUtils.js +1 -1
  92. package/package.json +1 -1
  93. package/support/ArcadeExpression.js +1 -1
  94. package/support/arcadeUtils.js +1 -1
  95. package/support/revision.js +1 -1
  96. package/symbols/cim/supportUtils.js +2 -0
  97. package/views/2d/engine/webgl/util/DimensionMatcher.js +1 -1
  98. package/views/2d/layers/features/layerAdapters/AnnotationLayerAdapter.js +1 -1
  99. package/views/2d/layers/features/layerAdapters/DimensionLayerAdapter.js +1 -1
  100. package/views/2d/layers/features/support/FeatureSetReaderParquet.js +1 -1
  101. package/views/2d/layers/support/annodime/annotationSchema.js +1 -1
  102. package/views/2d/layers/support/annodime/dimensionSchema.js +1 -1
  103. package/views/2d/layers/support/annodime/utils.js +1 -1
  104. package/views/2d/layers/support/annodime/virtualFields.js +1 -1
  105. package/views/3d/camera/constraintUtils.js +1 -1
  106. package/views/3d/state/ConstraintsManager.js +1 -1
  107. package/views/3d/terrain/PatchGeometryFactory.js +1 -1
  108. package/views/3d/terrain/PatchRenderData.js +1 -1
  109. package/views/3d/terrain/PatchRenderDataWaterproofness.js +2 -0
  110. package/views/3d/terrain/PlanarPatch.js +1 -1
  111. package/views/3d/terrain/SphericalPatch.js +1 -1
  112. package/views/3d/terrain/TileRenderer.js +1 -1
  113. package/views/3d/webgl-engine/effects/OpaqueEnvironment.js +1 -1
  114. package/views/3d/webgl-engine/effects/RenderNodes.js +1 -1
  115. package/views/3d/webgl-engine/effects/debug/RenderNodeVisualizerNode.js +1 -1
  116. package/views/3d/webgl-engine/effects/focusArea/FocusAreaMask.js +1 -1
  117. package/views/3d/webgl-engine/effects/geometry/ObjectAndLayerID.js +1 -1
  118. package/views/3d/webgl-engine/effects/highlight/Highlight.js +1 -1
  119. package/views/3d/webgl-engine/effects/highlight/ShadowHighlight.js +1 -1
  120. package/views/3d/webgl-engine/effects/highlight/ShadowHighlightBuffer.js +1 -1
  121. package/views/3d/webgl-engine/effects/laserlines/LaserLineRenderer.js +1 -1
  122. package/views/3d/webgl-engine/effects/magnifier/Magnifier.js +1 -1
  123. package/views/3d/webgl-engine/effects/smaa/SMAA.js +1 -1
  124. package/views/3d/webgl-engine/effects/stars/Stars.js +1 -1
  125. package/views/3d/webgl-engine/effects/stars/StarsTechnique.js +1 -1
  126. package/views/3d/webgl-engine/lib/CutFillComputation.js +1 -1
  127. package/views/3d/webgl-engine/lib/GaussianSplatRenderer.js +1 -1
  128. package/views/3d/webgl-engine/lib/GaussianSplatShadows.js +1 -1
  129. package/views/3d/webgl-engine/lib/Renderer.js +1 -1
  130. package/views/3d/webgl-engine/lib/ShadowAccumulator.js +1 -1
  131. package/views/3d/webgl-engine/lib/ShadowCastRenderer.js +1 -1
  132. package/views/3d/webgl-engine/lib/ShadowMap.js +1 -1
  133. package/views/3d/webgl-engine/statistics/RendererPerformanceInfo.js +1 -1
  134. package/views/3d/webgl.js +1 -1
  135. package/views/PopupView.js +1 -1
  136. package/views/layers/FeatureLikeLayerView.js +1 -1
  137. package/views/popupAdapter.js +1 -1
  138. package/webdoc/support/thumbnailUtils.js +1 -1
  139. package/webdoc/support/webdocSaveUtils.js +1 -1
  140. package/widgets/support/widget.d.ts +1 -0
  141. package/assets/esri/core/workers/chunks/125edba5c618c6257cb8.js +0 -1
  142. package/assets/esri/core/workers/chunks/168be2eac0fa3c67ae27.js +0 -1
  143. package/assets/esri/core/workers/chunks/32740b075d7a890d7888.js +0 -1
  144. package/assets/esri/core/workers/chunks/5189413a83faf3480e29.js +0 -1
  145. package/assets/esri/core/workers/chunks/a2be8784f2cfdbb42681.js +0 -1
  146. package/assets/esri/core/workers/chunks/a9db775210ebeee41738.js +0 -1
  147. package/assets/esri/core/workers/chunks/bca6abc185dedec0f41b.js +0 -1
  148. package/assets/esri/core/workers/chunks/bee56a6ac99312f03109.js +0 -1
  149. package/assets/esri/core/workers/chunks/d1d135a54233092ad637.js +0 -1
  150. package/assets/esri/core/workers/chunks/d750e4abeb777caa8c36.js +0 -1
  151. package/assets/esri/core/workers/chunks/daf539e9f88fc9e101e4.js +0 -1
  152. package/assets/esri/core/workers/chunks/e774303efefee31952d0.js +0 -1
  153. package/assets/esri/core/workers/chunks/e8546ab510fc9515bd23.js +0 -1
  154. package/assets/esri/core/workers/chunks/fc9664d3282b052ef40f.js +0 -1
  155. package/views/2d/layers/support/annodime/DimensionMatcherSchema.js +0 -2
  156. package/views/2d/layers/support/annodime/unsupported.js +0 -2
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../Graphic.js";import{ArcadeDate as t}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import i from"../Dictionary.js";import{StringEnum as a,toStringEnumKey as r}from"../enum.js";import{ArcadeExecutionError as o}from"../executionError.js";import{Feature as s}from"../Feature.js";import{convertToFeatureSet as l,constructFeatureSetFromPortalItem as f,constructFeatureSet as d,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as m}from"../featureSetUtils.js";import p from"../ImmutableArray.js";import{B as y,g as w,f as h,m as I,s as g,U as F,P as b,e as T,l as D,O as x,N as E,k as N,j as A,i as S,r as v,S as j,a1 as L}from"../../chunks/languageUtils.js";import{getPortal as C,getDefaultPortal as k}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as $,FieldRename as P,AdaptedFeatureSet as U,OriginalField as M}from"../featureset/actions/Adapted.js";import R from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/GroupBy.js";import z from"../featureset/actions/OrderBy.js";import W from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import G from"../featureset/sources/FeatureLayerMemory.js";import V from"../featureset/support/OrderbyClause.js";import{isSupportedLayer as B,cloneField as _}from"../featureset/support/shared.js";import{isSingleField as q}from"../featureset/support/sqlUtils.js";import{calculateStat as K}from"./fieldStats.js";import{isPromiseLike as Q}from"../../core/promiseUtils.js";import J from"../../core/sql/WhereClause.js";import Y from"../../layers/FeatureLayer.js";import X from"../../layers/support/Field.js";import{queryAssociations as ee}from"../../rest/networks/queryAssociations.js";import te from"../../rest/networks/support/NetworkElement.js";import ne from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ie,isArray as ae,isInteger as re}from"../../support/guards.js";function oe(e){if(1===e.length){if(ae(e[0]))return K("distinct",e[0],-1);if(A(e[0]))return K("distinct",e[0].toArray(),-1)}return K("distinct",e,-1)}function se(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function le(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function fe(e){if(null===e)return null;const t={type:le(e,"type",""),name:le(e,"name","")};if("range"===t.type)t.range=le(e,"range",[]);else{t.codedValues=[];for(const n of le(e,"codedValues",[]))t.codedValues.push({name:le(n,"name",""),code:le(n,"code",null)})}return t}function de(e){if(null===e)return null;const t={},n=le(e,"wkt");null!==n&&(t.wkt=n);const i=le(e,"wkid");return null!==i&&(t.wkid=i),t}function ue(e){if(null===e)return null;const t={hasZ:le(e,"hasz",!1),hasM:le(e,"hasm",!1)},n=le(e,"spatialreference");null!=n&&(t.spatialReference=de(n));const i=le(e,"x",null);if(null!==i)return t.x=i,t.y=le(e,"y",null),t.hasZ&&(t.z=le(e,"z",null)),t.hasM&&(t.m=le(e,"m",null)),t;const a=le(e,"rings",null);if(null!==a)return t.rings=a,t;const r=le(e,"paths",null);if(null!==r)return t.paths=r,t;const o=le(e,"points",null);if(null!==o)return t.points=o,t;for(const s of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=le(e,s,null);null!==n&&(t[s]=n)}return t}function ce(e,t){for(const n of t)if(n===e)return!0;return!1}function me(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ce(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==ae(e.layerDefinition.fields)&&!1!==ae(e.featureSet.features))))}function pe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function ye(t,n,i,a,r,s){const l=await t.getFeatureSetInfo();if(null===(l?.layerId??null))return null;if(!r.layerIdLookup.get(l.layerId))return null;const f=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),u=[];switch(i){case"connected":u.push("connectivity"),u.push("junction-edge-from-connectivity"),u.push("junction-edge-to-connectivity"),u.push("junction-edge-midspan-connectivity"),u.push("junction-junction-connectivity");break;case"container":case"content":u.push("containment");break;case"structure":case"attached":u.push("attachment");break;case"junctionedge":u.push("junction-edge-from-connectivity"),u.push("junction-edge-to-connectivity");break;case"midspan":u.push("junction-edge-midspan-connectivity");break;default:throw new o("InvalidParameter",s)}let c=null,m=!1;if(null!==a&&""!==a&&void 0!==a){for(const e of r.terminals)e.terminalName===a&&(c=e.terminalId);null===c&&(m=!0)}const p=[];if(!m){const a=new te({globalId:n.field(t.globalIdField),networkSourceId:r.layerIdLookup.get(l.layerId).sourceId,...c?{terminalId:c}:""}),o=await ee(f,new ne({types:u,elements:[a]}));let s=0;for(const t of o.associations){let n=null,o="",l="";if(t.fromNetworkElement?.globalId===a.globalId?(n=t.toNetworkElement,l="to"):t.toNetworkElement?.globalId===a.globalId&&(n=t.fromNetworkElement,l="from"),!n)continue;switch(i){case"attached":if("attachment"!==t.associationType)continue;if("to"!==l)continue;break;case"structure":if("attachment"!==t.associationType)continue;if("from"!==l)continue;break;case"container":if("containment"!==t.associationType)continue;if("from"!==l)continue;break;case"content":if("containment"!==t.associationType)continue;if("to"!==l)continue;break;case"connected":break;case"junctionedge":"junction-edge-to-connectivity"===t.associationType?o="to":"junction-edge-from-connectivity"===t.associationType&&(o="from");break;case"midspan":if("junction-edge-midspan-connectivity"!==t.associationType)continue}const f=r.sourceIdLookup.get(n.networkSourceId)?.className??"";p.push(new e({geometry:null,attributes:{objectId:s++,globalId:n.globalId,percentAlong:t.percentAlong??0,isContentVisible:t.isContentVisible?0:1,className:f,side:o}}))}}const y=new Y({source:p,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new X({name:"objectId",alias:"objectId",type:"oid"}),new X({name:"globalId",alias:"globalId",type:"global-id"}),new X({name:"percentAlong",alias:"percentAlong",type:"double"}),new X({name:"side",alias:"side",type:"string"}),new X({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new X({name:"className",alias:"className",type:"string"})]});return d(y)}function we(e){if("async"===e.mode){e.functions.timezone=function(n,a){return e.standardFunctionAsync(n,a,async(e,r,s)=>{if(y(s,1,2,a),w(s[0]))return"Unknown";if(h(s[0]))return"Unknown";if(I(s[0])){if(await s[0].load(),1===s.length||null===s[1])return s[0].datesInUnknownTimezone?pe("unknown"):pe(s[0].dateFieldsTimeZone);if(!(s[1]instanceof i)||!1===s[1].hasField("type"))throw new o("InvalidParameter",a);const e=s[1].field("type");if(!1===ie(e))throw new o("InvalidParameter",a);switch(g(e).toLowerCase()){case"preferredtimezone":return pe(s[0].preferredTimeZone);case"editfieldsinfo":return pe(s[0].editFieldsInfo?.timeZone??null);case"timeinfo":return pe(s[0].timeInfo?.timeZone??null);case"field":if(s[1].hasField("fieldname")&&ie(s[1].field("fieldname")))return pe(s[0].fieldTimeZone(g(s[1].field("fieldname"))))}throw new o("InvalidParameter",a)}const l=F(s[0],b(n));if(null===l)return null;const f=l.timeZone;return"system"===f?t.systemTimeZoneCanonicalName:"utc"===f.toLowerCase()?"UTC":"unknown"===f.toLowerCase()?"Unknown":f})},e.functions.sqltimestamp=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{y(i,1,3,n);const a=i[0];if(T(a)){if(1===i.length)return a.toSQLWithKeyword();if(2===i.length)return a.changeTimeZone(g(i[1])).toSQLWithKeyword();throw new o("InvalidParameter",n)}if(h(a))return a.toSQLWithKeyword();if(I(a)){if(3!==i.length)throw new o("InvalidParameter",n);await a.load();const e=g(i[1]);if(h(i[2]))return i[2].toSQLWithKeyword();if(!1===T(i[2]))throw new o("InvalidParameter",n);const t=a.fieldTimeZone(e);return null==t?i[2].toSQLWithKeyword():i[2].changeTimeZone(t).toSQLWithKeyword()}throw new o("InvalidParameter",n)})},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,(e,t,i)=>{if(y(i,2,4,n),D(i[0])){const e=g(i[1]);let t=x(i[2],null);const a=E(x(i[3],!0));if(null===t&&(t=["*"]),!1===ae(t))throw new o("InvalidParameter",n);return i[0].featureSetById(e,a,t)}throw new o("InvalidParameter",n)})},e.signatures.push({name:"featuresetbyid",min:2,max:4});const K=new a(["datasource","parent","root"]);e.functions.getfeatureset=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,2,n),N(a[0])){const e=null==a[1]?"datasource":K.lookup(g(a[1]));return l(a[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new o("InvalidParameter",n)})},e.signatures.push({name:"getfeatureset",min:1,max:2}),e.functions.featuresetbyportalitem=function(t,i){return e.standardFunctionAsync(t,i,(e,a,r)=>{if(y(r,2,5,i),null===r[0])throw new o("PortalRequired",i);if(r[0]instanceof n){const e=g(r[1]),n=g(r[2]);let a=x(r[3],null);const s=E(x(r[4],!0));if(null===a&&(a=["*"]),!1===ae(a))throw new o("InvalidParameter",i);const l=C(t,r[0]);return f(e,n,t.spatialReference,a,s,l,t.lrucache,t.interceptor)}if(!1===ie(r[0]))throw new o("PortalRequired",i);const s=g(r[0]),l=g(r[1]);let d=x(r[2],null);const u=E(x(r[3],!0));if(null===d&&(d=["*"]),!1===ae(d))throw new o("InvalidParameter",i);return f(s,l,t.spatialReference,d,u,k(t),t.lrucache,t.interceptor)})},e.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),e.functions.featuresetbyname=function(t,n){return e.standardFunctionAsync(t,n,(e,t,i)=>{if(y(i,2,4,n),D(i[0])){const e=g(i[1]);let t=x(i[2],null);const a=E(x(i[3],!0));if(null===t&&(t=["*"]),!1===ae(t))throw new o("InvalidParameter",n);return i[0].featureSetByName(e,a,t)}throw new o("InvalidParameter",n)})},e.signatures.push({name:"featuresetbyname",min:2,max:4}),e.functions.featureset=function(t,n){return e.standardFunction(t,n,(e,a,r)=>{y(r,1,1,n);const s={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ie(r[0])){const e=JSON.parse(r[0]);void 0!==e.layerDefinition?(s.layerDefinition=e.layerDefinition,s.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(s.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(s.featureSet.features=e.features,s.featureSet.geometryType=e.geometryType,s.layerDefinition.geometryType=s.featureSet.geometryType,s.layerDefinition.objectIdField=e.objectIdFieldName??"",s.layerDefinition.typeIdField=e.typeIdFieldName,s.layerDefinition.globalIdField=e.globalIdFieldName,s.layerDefinition.fields=e.fields,e.spatialReference&&(s.layerDefinition.spatialReference=e.spatialReference))}else{if(!(r[0]instanceof i))throw new o("InvalidParameter",n);{const e=JSON.parse(r[0].castToText(!0)),t=le(e,"layerdefinition");if(null!==t){s.layerDefinition.geometryType=le(t,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.globalIdField=le(t,"globalidfield",""),s.layerDefinition.objectIdField=le(t,"objectidfield",""),s.layerDefinition.typeIdField=le(t,"typeidfield",""),s.layerDefinition.hasZ=!0===le(t,"hasz",!1),s.layerDefinition.hasM=!0===le(t,"hasm",!1);const n=le(t,"spatialreference");n&&(s.layerDefinition.spatialReference=de(n));const i=[];for(const e of le(t,"fields",[])){const t={name:le(e,"name",""),alias:le(e,"alias",""),type:le(e,"type",""),nullable:le(e,"nullable",!0),editable:le(e,"editable",!0),length:le(e,"length",null),domain:fe(le(e,"domain"))};i.push(t)}s.layerDefinition.fields=i;const a=le(e,"featureset");if(a){const e={};for(const t of i)e[t.name.toLowerCase()]=t.name;for(const t of le(a,"features",[])){const n={},i=le(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];s.featureSet.features.push({attributes:n,geometry:ue(le(t,"geometry"))})}}}else{s.layerDefinition.hasZ=!0===le(e,"hasz",!1),s.layerDefinition.hasM=!0===le(e,"hasm",!1),s.layerDefinition.geometryType=le(e,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.objectIdField=le(e,"objectidfieldname",""),s.layerDefinition.typeIdField=le(e,"typeidfieldname","");const t=le(e,"spatialreference");t&&(s.layerDefinition.spatialReference=de(t));const i=[],a=le(e,"fields",null);if(!ae(a))throw new o("InvalidParameter",n);for(const e of a){const t={name:le(e,"name",""),alias:le(e,"alias",""),type:le(e,"type",""),nullable:le(e,"nullable",!0),editable:le(e,"editable",!0),length:le(e,"length",null),domain:fe(le(e,"domain"))};i.push(t)}s.layerDefinition.fields=i;const r={};for(const e of i)r[e.name.toLowerCase()]=e.name;let l=le(e,"features",null);if(ae(l))for(const e of l){const t={},n=le(e,"attributes",{});for(const e in n)t[r[e.toLowerCase()]]=n[e];s.featureSet.features.push({attributes:t,geometry:ue(le(e,"geometry",null))})}else l=null,s.featureSet.features=l}}}if(!1===me(s))throw new o("InvalidParameter",n);return s.layerDefinition.geometryType||(s.layerDefinition.geometryType="esriGeometryNull"),G.create(s,t.spatialReference)})},e.signatures.push({name:"featureset",min:1,max:1}),e.functions.filter=function(t,n){return e.standardFunctionAsync(t,n,async(i,a,r)=>{if(y(r,2,2,n),ae(r[0])||A(r[0])){const e=[];let i,a=r[0];if(a instanceof p&&(a=a.toArray()),!S(r[1]))throw new o("InvalidParameter",n);i=r[1].createFunction(t);for(const t of a){const n=i(t);Q(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(I(r[0])){const n=await r[0].load(),i=J.create(r[1],{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC}),a=i.getVariables();if(a.length>0){const n={};for(const i of a)n[i]=e.evaluateIdentifier(t,{name:i});i.parameters=n}return new R({parentfeatureset:r[0],whereclause:i})}throw new o("InvalidParameter",n)})},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{if(y(i,2,2,n),I(i[0])){const e=new V(i[1]);return new z({parentfeatureset:i[0],orderbyclause:e})}throw new o("InvalidParameter",n)})},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{if(y(i,2,2,n),I(i[0]))return new W({parentfeatureset:i[0],topnum:i[1]});if(ae(i[0]))return v(i[1])>=i[0].length?i[0].slice():i[0].slice(0,v(i[1]));if(A(i[0]))return v(i[1])>=i[0].length()?i[0].slice():i[0].slice(0,v(i[1]));throw new o("InvalidParameter",n)})},e.signatures.push({name:"top",min:2,max:2}),e.functions.first=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,1,n),I(a[0])){const n=await a[0].first(e.abortSignal);if(null!==n){const e=s.createFromGraphicLikeObject(n.geometry,n.attributes,a[0],t.timeZone);return e._underlyingGraphic=n,e}return n}return ae(a[0])?0===a[0].length?null:a[0][0]:A(a[0])?0===a[0].length()?null:a[0].get(0):null})},e.signatures.push({name:"first",min:1,max:1}),e.functions.attachments=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{y(r,1,2,n);const s={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(r.length>1)if(r[1]instanceof i){if(r[1].hasField("minsize")&&(s.minsize=v(r[1].field("minsize"))),r[1].hasField("metadata")&&(s.returnMetadata=E(r[1].field("metadata"))),r[1].hasField("maxsize")&&(s.maxsize=v(r[1].field("maxsize"))),r[1].hasField("types")){const e=j(r[1].field("types"),!1);e.length>0&&(s.types=e)}}else if(null!==r[1])throw new o("InvalidParameter",n);if(N(r[0])){const e=r[0]._layer;let n;if(I(e))n=e;else{if(null==e||!B(e))return[];n=d(e,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}return await n.load(),n.queryAttachments(r[0].field(n.objectIdField),s.minsize,s.maxsize,s.types,s.returnMetadata)}if(null===r[0])return[];throw new o("InvalidParameter",n)})},e.signatures.push({name:"attachments",min:1,max:2}),e.functions.featuresetbyrelationshipname=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,4,n);const r=a[0],s=g(a[1]);let l=x(a[2],null);const f=E(x(a[3],!0));if(null===l&&(l=["*"]),!1===ae(l))throw new o("InvalidParameter",n);if(null===a[0])return null;if(!N(a[0]))throw new o("InvalidParameter",n);const m=r._layer;let p;if(I(m))p=m;else{if(null==m||!B(m))return null;p=d(m,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}p=await p.load();const w=p.relationshipMetadata().filter(e=>e.name===s);if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(p,w[0],r.field(p.objectIdField),p.spatialReference,l,f,t.lrucache,t.interceptor);let h=p.serviceUrl();if(!h)return null;h=h.endsWith("/")?h+w[0].relatedTableId.toString():h+"/"+w[0].relatedTableId.toString();const F=await c(h,p.spatialReference,l,f,t.lrucache,t.interceptor);await F.load();let b=F.relationshipMetadata();if(b=b.filter(e=>e.id===w[0].id),!1===r.hasField(w[0].keyField)||null===r.field(w[0].keyField)){const e=await p.getFeatureByObjectId(r.field(p.objectIdField),[w[0].keyField]);if(e){const t=J.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},new R({parentfeatureset:F,whereclause:t})}return new H({parentfeatureset:F})}const T=J.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:r.field(w[0].keyField)},new R({parentfeatureset:F,whereclause:T})})},e.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),e.functions.featuresetbyassociation=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,3,n);const s=a[0],l=r(g(x(a[1],""))),f=ie(a[2])?g(a[2]):null;if(null===a[0])return null;if(!N(a[0]))throw new o("InvalidParameter",n);const u=s._layer;let c;if(I(u))c=u;else{if(null==u||!B(u))return null;c=d(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}await c.load();const p=c.serviceUrl(),w=await m(p,t.spatialReference,!0);if(w.unVersion>=8)return await ye(c,s,l,f,w,n);const h=w.associations;if(null==h)return null;let F=null,b=null,T=!1;if(null!==f&&""!==f&&void 0!==f){for(const e of w.terminals)e.terminalName===f&&(b=e.terminalId);null===b&&(T=!0)}const D=h.getFieldsIndex(),E=D.get("TOGLOBALID").name,A=D.get("FROMGLOBALID").name,S=D.get("TOTERMINALID").name,v=D.get("FROMTERMINALID").name,j=D.get("FROMNETWORKSOURCEID").name,C=D.get("TONETWORKSOURCEID").name,k=D.get("ASSOCIATIONTYPE").name,R=D.get("ISCONTENTVISIBLE").name,O=D.get("OBJECTID").name;for(const t of c.fields)if("global-id"===t.type){F=s.field(t.name);break}let z=null,W=new Z(new X({name:"percentalong",alias:"percentalong",type:"double"}),J.create("0",{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC})),H=new Z(new X({name:"side",alias:"side",type:"string"}),J.create("''",{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));const G="globalid",V="globalId",q={};for(const t in w.lkp)q[t]=w.lkp[t].sourceId;const K=new $(new X({name:"classname",alias:"classname",type:"string"}),null,q);let Q="";switch(l){case"midspan":{Q=`((${E}='${F}') OR ( ${A}='${F}')) AND (${k} IN (5))`,K.codefield=J.create(`CASE WHEN (${E}='${F}') THEN ${j} ELSE ${C} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC});const e=_(U.findField(h.fields,A));e.name=G,e.alias=G,z=new Z(e,J.create(`CASE WHEN (${A}='${F}') THEN ${E} ELSE ${A} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC})),W=w.unVersion>=4?new M(U.findField(h.fields,D.get("PERCENTALONG").name)):new Z(new X({name:"percentalong",alias:"percentalong",type:"double"}),J.create("0",{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{Q=`((${E}='${F}') OR ( ${A}='${F}')) AND (${k} IN (4,6))`,K.codefield=J.create(`CASE WHEN (${E}='${F}') THEN ${j} ELSE ${C} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC});const e=_(U.findField(h.fields,A));e.name=G,e.alias=G,z=new Z(e,J.create(`CASE WHEN (${A}='${F}') THEN ${E} ELSE ${A} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC})),H=new Z(new X({name:"side",alias:"side",type:"string"}),J.create(`CASE WHEN (${k}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==b&&(e+=` AND ${S}=@A`,t+=` AND ${v}=@A`),Q="(("+e+") OR ("+t+"))",Q=L(Q,"@T",F??""),e=L(e,"@T",F??""),null!==b&&(e=L(e,"@A",b.toString()),Q=L(Q,"@A",b.toString())),K.codefield=J.create("CASE WHEN "+e+` THEN ${j} ELSE ${C} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC});const n=_(U.findField(h.fields,A));n.name=G,n.alias=G,z=new Z(n,J.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));break}case"container":Q=`${E}='${F}' AND ${k} = 2`,null!==b&&(Q+=` AND ${S} = `+b.toString()),K.codefield=j,Q="( "+Q+" )",z=new P(U.findField(h.fields,A),G,G);break;case"content":Q=`(${A}='${F}' AND ${k} = 2)`,null!==b&&(Q+=` AND ${v} = `+b.toString()),K.codefield=C,Q="( "+Q+" )",z=new P(U.findField(h.fields,E),G,G);break;case"structure":Q=`(${E}='${F}' AND ${k} = 3)`,null!==b&&(Q+=` AND ${S} = `+b.toString()),K.codefield=j,Q="( "+Q+" )",z=new P(U.findField(h.fields,A),G,V);break;case"attached":Q=`(${A}='${F}' AND ${k} = 3)`,null!==b&&(Q+=` AND ${v} = `+b.toString()),K.codefield=C,Q="( "+Q+" )",z=new P(U.findField(h.fields,E),G,V);break;default:throw new o("InvalidParameter",n)}T&&(Q="1 <> 1");return new U({parentfeatureset:h,adaptedFields:[new M(U.findField(h.fields,O)),new M(U.findField(h.fields,R)),z,H,K,W],extraFilter:Q?J.create(Q,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}):null})})},e.signatures.push({name:"featuresetbyassociation",min:2,max:6}),e.functions.groupby=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(y(s,3,3,n),!I(s[0]))throw new o("InvalidParameter",n);const l=await s[0].load(),f=[],d=[];let u=!1,c=[];if(ie(s[1]))c.push(s[1]);else if(s[1]instanceof i)c.push(s[1]);else if(ae(s[1]))c=s[1];else{if(!A(s[1]))throw new o("InvalidParameter",n);c=s[1].toArray()}for(const e of c)if(ie(e)){const t=J.create(g(e),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),n=!0===q(t)?g(e):"%%%%FIELDNAME";f.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(u=!0)}else{if(!(e instanceof i))throw new o("InvalidParameter",n);{const t=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",i=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===t&&(u=!0),!t)throw new o("InvalidParameter",n);f.push({name:t,expression:J.create(i||t,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],ie(s[2]))c.push(s[2]);else if(ae(s[2]))c=s[2];else if(A(s[2]))c=s[2].toArray();else{if(!(s[2]instanceof i))throw new o("InvalidParameter",n);c.push(s[2])}for(const e of c){if(!(e instanceof i))throw new o("InvalidParameter",n);{const t=e.hasField("name")?e.field("name"):"",i=e.hasField("statistic")?e.field("statistic"):"",a=e.hasField("expression")?e.field("expression"):"";if(!(t&&i&&ie(i)&&a))throw new o("InvalidParameter",n);d.push({name:t,statistic:i,expression:J.create(a,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of f)se(n.expression,e,t);for(const n of d)se(n.expression,e,t);return new O({parentfeatureset:s[0],groupbyfields:f,statsfields:d})})},e.signatures.push({name:"groupby",min:3,max:3}),e.functions.distinct=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(I(s[0])){y(s,2,2,n);const a=await s[0].load(),r=[];let l=[];if(ie(s[1]))l.push(s[1]);else if(s[1]instanceof i)l.push(s[1]);else if(ae(s[1]))l=s[1];else{if(!A(s[1]))throw new o("InvalidParameter",n);l=s[1].toArray()}let f=!1;for(const e of l)if(ie(e)){const t=J.create(g(e),{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),n=!0===q(t)?g(e):"%%%%FIELDNAME";r.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(f=!0)}else{if(!(e instanceof i))throw new o("InvalidParameter",n);{const t=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",i=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===t&&(f=!0),!t)throw new o("InvalidParameter",n);r.push({name:t,expression:J.create(i||t,{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC})})}}if(f){const e={};for(const n of a.fields)e[n.name.toLowerCase()]=1;for(const n of r)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of r)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of r)se(n.expression,e,t);return new O({parentfeatureset:s[0],groupbyfields:r,statsfields:[]})}return oe(s)})},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{if(y(r,1,1,n),!I(r[0]))return null;const o=await r[0].getFeatureSetInfo();return o?i.convertObjectToArcadeDictionary({layerId:o.layerId,layerName:o.layerName,itemId:o.itemId,serviceLayerUrl:o.serviceLayerUrl,webMapLayerId:o.webMapLayerId??null,webMapLayerTitle:o.webMapLayerTitle??null,className:null,objectClassId:null},b(t),!1,!1):null})},e.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),e.functions.filterbysubtypecode=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{if(y(i,2,2,n),I(i[0])){const e=await i[0].load(),t=i[1];if(!re(t))throw new o("InvalidParameter",n);if(e.subtypeField){const t=J.create(`${e.subtypeField}= ${i[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new R({parentfeatureset:i[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new o("FeatureSetDoesNotHaveSubtypes",n);const a=J.create(`${e.typeIdField}= ${i[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new R({parentfeatureset:i[0],whereclause:a})}throw new o("InvalidParameter",n)})},e.signatures.push({name:"filterbysubtypecode",min:2,max:2})}}export{we as registerFunctions};
2
+ import e from"../../Graphic.js";import{ArcadeDate as t}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import i from"../Dictionary.js";import{StringEnum as a,toStringEnumKey as r}from"../enum.js";import{ArcadeExecutionError as o}from"../executionError.js";import{Feature as s}from"../Feature.js";import{convertToFeatureSet as l,constructFeatureSetFromPortalItem as f,constructFeatureSet as d,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as m}from"../featureSetUtils.js";import p from"../ImmutableArray.js";import{B as y,n as w,o as h,k as I,s as g,U as F,T as b,e as T,j as D,O as x,N as E,h as N,g as A,i as S,r as v,Q as L,a1 as j}from"../../chunks/languageUtils.js";import{getPortal as C,getDefaultPortal as k}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as $,FieldRename as P,AdaptedFeatureSet as U,OriginalField as M}from"../featureset/actions/Adapted.js";import R from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/GroupBy.js";import z from"../featureset/actions/OrderBy.js";import W from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import G from"../featureset/sources/FeatureLayerMemory.js";import _ from"../featureset/support/OrderbyClause.js";import{isSupportedLayer as V,cloneField as B}from"../featureset/support/shared.js";import{isSingleField as q}from"../featureset/support/sqlUtils.js";import{calculateStat as K}from"./fieldStats.js";import{isPromiseLike as Q}from"../../core/promiseUtils.js";import J from"../../core/sql/WhereClause.js";import Y from"../../layers/FeatureLayer.js";import X from"../../layers/support/Field.js";import{queryAssociations as ee}from"../../rest/networks/queryAssociations.js";import te from"../../rest/networks/support/NetworkElement.js";import ne from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ie,isArray as ae,isInteger as re}from"../../support/guards.js";function oe(e){if(1===e.length){if(ae(e[0]))return K("distinct",e[0],-1);if(A(e[0]))return K("distinct",e[0].toArray(),-1)}return K("distinct",e,-1)}function se(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function le(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function fe(e){if(null===e)return null;const t={type:le(e,"type",""),name:le(e,"name","")};if("range"===t.type)t.range=le(e,"range",[]);else{t.codedValues=[];for(const n of le(e,"codedValues",[]))t.codedValues.push({name:le(n,"name",""),code:le(n,"code",null)})}return t}function de(e){if(null===e)return null;const t={},n=le(e,"wkt");null!==n&&(t.wkt=n);const i=le(e,"wkid");return null!==i&&(t.wkid=i),t}function ue(e){if(null===e)return null;const t={hasZ:le(e,"hasz",!1),hasM:le(e,"hasm",!1)},n=le(e,"spatialreference");null!=n&&(t.spatialReference=de(n));const i=le(e,"x",null);if(null!==i)return t.x=i,t.y=le(e,"y",null),t.hasZ&&(t.z=le(e,"z",null)),t.hasM&&(t.m=le(e,"m",null)),t;const a=le(e,"rings",null);if(null!==a)return t.rings=a,t;const r=le(e,"paths",null);if(null!==r)return t.paths=r,t;const o=le(e,"points",null);if(null!==o)return t.points=o,t;for(const s of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=le(e,s,null);null!==n&&(t[s]=n)}return t}function ce(e,t){for(const n of t)if(n===e)return!0;return!1}function me(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ce(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==ae(e.layerDefinition.fields)&&!1!==ae(e.featureSet.features))))}function pe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function ye(t,n,i,a,r,s){const l=await t.getFeatureSetInfo();if(null===(l?.layerId??null))return null;if(!r.layerIdLookup.get(l.layerId))return null;const f=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),u=[];switch(i){case"connected":u.push("connectivity"),u.push("junction-edge-from-connectivity"),u.push("junction-edge-to-connectivity"),u.push("junction-edge-midspan-connectivity"),u.push("junction-junction-connectivity");break;case"container":case"content":u.push("containment");break;case"structure":case"attached":u.push("attachment");break;case"junctionedge":u.push("junction-edge-from-connectivity"),u.push("junction-edge-to-connectivity");break;case"midspan":u.push("junction-edge-midspan-connectivity");break;default:throw new o("InvalidParameter",s)}let c=null,m=!1;if(null!==a&&""!==a&&void 0!==a){for(const e of r.terminals)e.terminalName===a&&(c=e.terminalId);null===c&&(m=!0)}const p=[];if(!m){const a=new te({globalId:n.field(t.globalIdField),networkSourceId:r.layerIdLookup.get(l.layerId).sourceId,...c?{terminalId:c}:""}),o=await ee(f,new ne({types:u,elements:[a]}));let s=0;for(const t of o.associations){let n=null,o="",l="";if(t.fromNetworkElement?.globalId===a.globalId?(n=t.toNetworkElement,l="to"):t.toNetworkElement?.globalId===a.globalId&&(n=t.fromNetworkElement,l="from"),!n)continue;switch(i){case"attached":if("attachment"!==t.associationType)continue;if("to"!==l)continue;break;case"structure":if("attachment"!==t.associationType)continue;if("from"!==l)continue;break;case"container":if("containment"!==t.associationType)continue;if("from"!==l)continue;break;case"content":if("containment"!==t.associationType)continue;if("to"!==l)continue;break;case"connected":break;case"junctionedge":"junction-edge-to-connectivity"===t.associationType?o="to":"junction-edge-from-connectivity"===t.associationType&&(o="from");break;case"midspan":if("junction-edge-midspan-connectivity"!==t.associationType)continue}const f=r.sourceIdLookup.get(n.networkSourceId)?.className??"";p.push(new e({geometry:null,attributes:{objectId:s++,globalId:n.globalId,percentAlong:t.percentAlong??0,isContentVisible:t.isContentVisible?0:1,className:f,side:o}}))}}const y=new Y({source:p,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new X({name:"objectId",alias:"objectId",type:"oid"}),new X({name:"globalId",alias:"globalId",type:"global-id"}),new X({name:"percentAlong",alias:"percentAlong",type:"double"}),new X({name:"side",alias:"side",type:"string"}),new X({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new X({name:"className",alias:"className",type:"string"})]});return d(y)}function we(e){if("async"===e.mode){e.functions.timezone=function(n,a){return e.standardFunctionAsync(n,a,async(e,r,s)=>{if(y(s,1,2,a),w(s[0]))return"Unknown";if(h(s[0]))return"Unknown";if(I(s[0])){if(await s[0].load(),1===s.length||null===s[1])return s[0].datesInUnknownTimezone?pe("unknown"):pe(s[0].dateFieldsTimeZone);if(!(s[1]instanceof i)||!1===s[1].hasField("type"))throw new o("InvalidParameter",a);const e=s[1].field("type");if(!1===ie(e))throw new o("InvalidParameter",a);switch(g(e).toLowerCase()){case"preferredtimezone":return pe(s[0].preferredTimeZone);case"editfieldsinfo":return pe(s[0].editFieldsInfo?.timeZone??null);case"timeinfo":return pe(s[0].timeInfo?.timeZone??null);case"field":if(s[1].hasField("fieldname")&&ie(s[1].field("fieldname")))return pe(s[0].fieldTimeZone(g(s[1].field("fieldname"))))}throw new o("InvalidParameter",a)}const l=F(s[0],b(n));if(null===l)return null;const f=l.timeZone;return"system"===f?t.systemTimeZoneCanonicalName:"utc"===f.toLowerCase()?"UTC":"unknown"===f.toLowerCase()?"Unknown":f})},e.functions.sqltimestamp=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{y(i,1,3,n);const a=i[0];if(T(a)){if(1===i.length)return a.toSQLWithKeyword();if(2===i.length)return a.changeTimeZone(g(i[1])).toSQLWithKeyword();throw new o("InvalidParameter",n)}if(h(a))return a.toSQLWithKeyword();if(I(a)){if(3!==i.length)throw new o("InvalidParameter",n);await a.load();const e=g(i[1]);if(h(i[2]))return i[2].toSQLWithKeyword();if(!1===T(i[2]))throw new o("InvalidParameter",n);const t=a.fieldTimeZone(e);return null==t?i[2].toSQLWithKeyword():i[2].changeTimeZone(t).toSQLWithKeyword()}throw new o("InvalidParameter",n)})},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,(e,t,i)=>{if(y(i,2,4,n),D(i[0])){const e=g(i[1]);let t=x(i[2],null);const a=E(x(i[3],!0));if(null===t&&(t=["*"]),!1===ae(t))throw new o("InvalidParameter",n);return i[0].featureSetById(e,a,t)}throw new o("InvalidParameter",n)})},e.signatures.push({name:"featuresetbyid",min:2,max:4});const K=new a(["datasource","parent","root"]);e.functions.getfeatureset=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,2,n),N(a[0])){const e=null==a[1]?"datasource":K.lookup(g(a[1]));return l(a[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new o("InvalidParameter",n)})},e.signatures.push({name:"getfeatureset",min:1,max:2}),e.functions.featuresetbyportalitem=function(t,i){return e.standardFunctionAsync(t,i,(e,a,r)=>{if(y(r,2,5,i),null===r[0])throw new o("PortalRequired",i);if(r[0]instanceof n){const e=g(r[1]),n=g(r[2]);let a=x(r[3],null);const s=E(x(r[4],!0));if(null===a&&(a=["*"]),!1===ae(a))throw new o("InvalidParameter",i);const l=C(t,r[0]);return f(e,n,t.spatialReference,a,s,l,t.lrucache,t.interceptor)}if(!1===ie(r[0]))throw new o("PortalRequired",i);const s=g(r[0]),l=g(r[1]);let d=x(r[2],null);const u=E(x(r[3],!0));if(null===d&&(d=["*"]),!1===ae(d))throw new o("InvalidParameter",i);return f(s,l,t.spatialReference,d,u,k(t),t.lrucache,t.interceptor)})},e.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),e.functions.featuresetbyname=function(t,n){return e.standardFunctionAsync(t,n,(e,t,i)=>{if(y(i,2,4,n),D(i[0])){const e=g(i[1]);let t=x(i[2],null);const a=E(x(i[3],!0));if(null===t&&(t=["*"]),!1===ae(t))throw new o("InvalidParameter",n);return i[0].featureSetByName(e,a,t)}throw new o("InvalidParameter",n)})},e.signatures.push({name:"featuresetbyname",min:2,max:4}),e.functions.featureset=function(t,n){return e.standardFunction(t,n,(e,a,r)=>{y(r,1,1,n);const s={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ie(r[0])){const e=JSON.parse(r[0]);void 0!==e.layerDefinition?(s.layerDefinition=e.layerDefinition,s.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(s.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(s.featureSet.features=e.features,s.featureSet.geometryType=e.geometryType,s.layerDefinition.geometryType=s.featureSet.geometryType,s.layerDefinition.objectIdField=e.objectIdFieldName??"",s.layerDefinition.typeIdField=e.typeIdFieldName,s.layerDefinition.globalIdField=e.globalIdFieldName,s.layerDefinition.fields=e.fields,e.spatialReference&&(s.layerDefinition.spatialReference=e.spatialReference))}else{if(!(r[0]instanceof i))throw new o("InvalidParameter",n);{const e=JSON.parse(r[0].castToText(!0)),t=le(e,"layerdefinition");if(null!==t){s.layerDefinition.geometryType=le(t,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.globalIdField=le(t,"globalidfield",""),s.layerDefinition.objectIdField=le(t,"objectidfield",""),s.layerDefinition.typeIdField=le(t,"typeidfield",""),s.layerDefinition.hasZ=!0===le(t,"hasz",!1),s.layerDefinition.hasM=!0===le(t,"hasm",!1);const n=le(t,"spatialreference");n&&(s.layerDefinition.spatialReference=de(n));const i=[];for(const e of le(t,"fields",[])){const t={name:le(e,"name",""),alias:le(e,"alias",""),type:le(e,"type",""),nullable:le(e,"nullable",!0),editable:le(e,"editable",!0),length:le(e,"length",null),domain:fe(le(e,"domain"))};i.push(t)}s.layerDefinition.fields=i;const a=le(e,"featureset");if(a){const e={};for(const t of i)e[t.name.toLowerCase()]=t.name;for(const t of le(a,"features",[])){const n={},i=le(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];s.featureSet.features.push({attributes:n,geometry:ue(le(t,"geometry"))})}}}else{s.layerDefinition.hasZ=!0===le(e,"hasz",!1),s.layerDefinition.hasM=!0===le(e,"hasm",!1),s.layerDefinition.geometryType=le(e,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.objectIdField=le(e,"objectidfieldname",""),s.layerDefinition.typeIdField=le(e,"typeidfieldname","");const t=le(e,"spatialreference");t&&(s.layerDefinition.spatialReference=de(t));const i=[],a=le(e,"fields",null);if(!ae(a))throw new o("InvalidParameter",n);for(const e of a){const t={name:le(e,"name",""),alias:le(e,"alias",""),type:le(e,"type",""),nullable:le(e,"nullable",!0),editable:le(e,"editable",!0),length:le(e,"length",null),domain:fe(le(e,"domain"))};i.push(t)}s.layerDefinition.fields=i;const r={};for(const e of i)r[e.name.toLowerCase()]=e.name;let l=le(e,"features",null);if(ae(l))for(const e of l){const t={},n=le(e,"attributes",{});for(const e in n)t[r[e.toLowerCase()]]=n[e];s.featureSet.features.push({attributes:t,geometry:ue(le(e,"geometry",null))})}else l=null,s.featureSet.features=l}}}if(!1===me(s))throw new o("InvalidParameter",n);return s.layerDefinition.geometryType||(s.layerDefinition.geometryType="esriGeometryNull"),G.create(s,t.spatialReference)})},e.signatures.push({name:"featureset",min:1,max:1}),e.functions.filter=function(t,n){return e.standardFunctionAsync(t,n,async(i,a,r)=>{if(y(r,2,2,n),ae(r[0])||A(r[0])){const e=[];let i,a=r[0];if(a instanceof p&&(a=a.toArray()),!S(r[1]))throw new o("InvalidParameter",n);i=r[1].createFunction(t);for(const t of a){const n=i(t);Q(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(I(r[0])){const n=await r[0].load(),i=J.create(r[1],{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC}),a=i.getVariables();if(a.length>0){const n={};for(const i of a)n[i]=e.evaluateIdentifier(t,{name:i});i.parameters=n}return new R({parentfeatureset:r[0],whereclause:i})}throw new o("InvalidParameter",n)})},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{if(y(i,2,2,n),I(i[0])){const e=new _(i[1]);return new z({parentfeatureset:i[0],orderbyclause:e})}throw new o("InvalidParameter",n)})},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{if(y(i,2,2,n),I(i[0]))return new W({parentfeatureset:i[0],topnum:i[1]});if(ae(i[0]))return v(i[1])>=i[0].length?i[0].slice():i[0].slice(0,v(i[1]));if(A(i[0]))return v(i[1])>=i[0].length()?i[0].slice():i[0].slice(0,v(i[1]));throw new o("InvalidParameter",n)})},e.signatures.push({name:"top",min:2,max:2}),e.functions.first=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,1,1,n),I(a[0])){const n=await a[0].first(e.abortSignal);if(null!==n){const e=s.createFromGraphicLikeObject(n.geometry,n.attributes,a[0],t.timeZone);return e._underlyingGraphic=n,e}return n}return ae(a[0])?0===a[0].length?null:a[0][0]:A(a[0])?0===a[0].length()?null:a[0].get(0):null})},e.signatures.push({name:"first",min:1,max:1}),e.functions.attachments=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{y(r,1,2,n);const s={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(r.length>1)if(r[1]instanceof i){if(r[1].hasField("minsize")&&(s.minsize=v(r[1].field("minsize"))),r[1].hasField("metadata")&&(s.returnMetadata=E(r[1].field("metadata"))),r[1].hasField("maxsize")&&(s.maxsize=v(r[1].field("maxsize"))),r[1].hasField("types")){const e=L(r[1].field("types"),!1);e.length>0&&(s.types=e)}}else if(null!==r[1])throw new o("InvalidParameter",n);if(N(r[0])){const e=r[0]._layer;let n;if(I(e))n=e;else{if(null==e||!V(e))return[];n=d(e,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}return await n.load(),n.queryAttachments(r[0].field(n.objectIdField),s.minsize,s.maxsize,s.types,s.returnMetadata)}if(null===r[0])return[];throw new o("InvalidParameter",n)})},e.signatures.push({name:"attachments",min:1,max:2}),e.functions.featuresetbyrelationshipname=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,4,n);const r=a[0],s=g(a[1]);let l=x(a[2],null);const f=E(x(a[3],!0));if(null===l&&(l=["*"]),!1===ae(l))throw new o("InvalidParameter",n);if(null===a[0])return null;if(!N(a[0]))throw new o("InvalidParameter",n);const m=r._layer;let p;if(I(m))p=m;else{if(null==m||!V(m))return null;p=d(m,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}p=await p.load();const w=p.relationshipMetadata().filter(e=>e.name===s);if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(p,w[0],r.field(p.objectIdField),p.spatialReference,l,f,t.lrucache,t.interceptor);let h=p.serviceUrl();if(!h)return null;h=h.endsWith("/")?h+w[0].relatedTableId.toString():h+"/"+w[0].relatedTableId.toString();const F=await c(h,p.spatialReference,l,f,t.lrucache,t.interceptor);await F.load();let b=F.relationshipMetadata();if(b=b.filter(e=>e.id===w[0].id),!1===r.hasField(w[0].keyField)||null===r.field(w[0].keyField)){const e=await p.getFeatureByObjectId(r.field(p.objectIdField),[w[0].keyField]);if(e){const t=J.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},new R({parentfeatureset:F,whereclause:t})}return new H({parentfeatureset:F})}const T=J.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:r.field(w[0].keyField)},new R({parentfeatureset:F,whereclause:T})})},e.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),e.functions.featuresetbyassociation=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{y(a,2,3,n);const s=a[0],l=r(g(x(a[1],""))),f=ie(a[2])?g(a[2]):null;if(null===a[0])return null;if(!N(a[0]))throw new o("InvalidParameter",n);const u=s._layer;let c;if(I(u))c=u;else{if(null==u||!V(u))return null;c=d(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)}await c.load();const p=c.serviceUrl(),w=await m(p,t.spatialReference,!0);if(w.unVersion>=8)return await ye(c,s,l,f,w,n);const h=w.associations;if(null==h)return null;let F=null,b=null,T=!1;if(null!==f&&""!==f&&void 0!==f){for(const e of w.terminals)e.terminalName===f&&(b=e.terminalId);null===b&&(T=!0)}const D=h.getFieldsIndex(),E=D.get("TOGLOBALID").name,A=D.get("FROMGLOBALID").name,S=D.get("TOTERMINALID").name,v=D.get("FROMTERMINALID").name,L=D.get("FROMNETWORKSOURCEID").name,C=D.get("TONETWORKSOURCEID").name,k=D.get("ASSOCIATIONTYPE").name,R=D.get("ISCONTENTVISIBLE").name,O=D.get("OBJECTID").name;for(const t of c.fields)if("global-id"===t.type){F=s.field(t.name);break}let z=null,W=new Z(new X({name:"percentalong",alias:"percentalong",type:"double"}),J.create("0",{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC})),H=new Z(new X({name:"side",alias:"side",type:"string"}),J.create("''",{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));const G="globalid",_="globalId",q={};for(const t in w.lkp)q[t]=w.lkp[t].sourceId;const K=new $(new X({name:"classname",alias:"classname",type:"string"}),null,q);let Q="";switch(l){case"midspan":{Q=`((${E}='${F}') OR ( ${A}='${F}')) AND (${k} IN (5))`,K.codefield=J.create(`CASE WHEN (${E}='${F}') THEN ${L} ELSE ${C} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC});const e=B(U.findField(h.fields,A));e.name=G,e.alias=G,z=new Z(e,J.create(`CASE WHEN (${A}='${F}') THEN ${E} ELSE ${A} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC})),W=w.unVersion>=4?new M(U.findField(h.fields,D.get("PERCENTALONG").name)):new Z(new X({name:"percentalong",alias:"percentalong",type:"double"}),J.create("0",{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{Q=`((${E}='${F}') OR ( ${A}='${F}')) AND (${k} IN (4,6))`,K.codefield=J.create(`CASE WHEN (${E}='${F}') THEN ${L} ELSE ${C} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC});const e=B(U.findField(h.fields,A));e.name=G,e.alias=G,z=new Z(e,J.create(`CASE WHEN (${A}='${F}') THEN ${E} ELSE ${A} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC})),H=new Z(new X({name:"side",alias:"side",type:"string"}),J.create(`CASE WHEN (${k}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==b&&(e+=` AND ${S}=@A`,t+=` AND ${v}=@A`),Q="(("+e+") OR ("+t+"))",Q=j(Q,"@T",F??""),e=j(e,"@T",F??""),null!==b&&(e=j(e,"@A",b.toString()),Q=j(Q,"@A",b.toString())),K.codefield=J.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC});const n=B(U.findField(h.fields,A));n.name=G,n.alias=G,z=new Z(n,J.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}));break}case"container":Q=`${E}='${F}' AND ${k} = 2`,null!==b&&(Q+=` AND ${S} = `+b.toString()),K.codefield=L,Q="( "+Q+" )",z=new P(U.findField(h.fields,A),G,G);break;case"content":Q=`(${A}='${F}' AND ${k} = 2)`,null!==b&&(Q+=` AND ${v} = `+b.toString()),K.codefield=C,Q="( "+Q+" )",z=new P(U.findField(h.fields,E),G,G);break;case"structure":Q=`(${E}='${F}' AND ${k} = 3)`,null!==b&&(Q+=` AND ${S} = `+b.toString()),K.codefield=L,Q="( "+Q+" )",z=new P(U.findField(h.fields,A),G,_);break;case"attached":Q=`(${A}='${F}' AND ${k} = 3)`,null!==b&&(Q+=` AND ${v} = `+b.toString()),K.codefield=C,Q="( "+Q+" )",z=new P(U.findField(h.fields,E),G,_);break;default:throw new o("InvalidParameter",n)}T&&(Q="1 <> 1");return new U({parentfeatureset:h,adaptedFields:[new M(U.findField(h.fields,O)),new M(U.findField(h.fields,R)),z,H,K,W],extraFilter:Q?J.create(Q,{fieldsIndex:h.getFieldsIndex(),timeZone:h.dateFieldsTimeZoneDefaultUTC}):null})})},e.signatures.push({name:"featuresetbyassociation",min:2,max:6}),e.functions.groupby=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(y(s,3,3,n),!I(s[0]))throw new o("InvalidParameter",n);const l=await s[0].load(),f=[],d=[];let u=!1,c=[];if(ie(s[1]))c.push(s[1]);else if(s[1]instanceof i)c.push(s[1]);else if(ae(s[1]))c=s[1];else{if(!A(s[1]))throw new o("InvalidParameter",n);c=s[1].toArray()}for(const e of c)if(ie(e)){const t=J.create(g(e),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),n=!0===q(t)?g(e):"%%%%FIELDNAME";f.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(u=!0)}else{if(!(e instanceof i))throw new o("InvalidParameter",n);{const t=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",i=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===t&&(u=!0),!t||!ie(t)||!ie(i))throw new o("InvalidParameter",n);f.push({name:t,expression:J.create(i||t,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],ie(s[2]))c.push(s[2]);else if(ae(s[2]))c=s[2];else if(A(s[2]))c=s[2].toArray();else{if(!(s[2]instanceof i))throw new o("InvalidParameter",n);c.push(s[2])}for(const e of c){if(!(e instanceof i))throw new o("InvalidParameter",n);{const t=e.hasField("name")?e.field("name"):"",i=e.hasField("statistic")?e.field("statistic"):"",a=e.hasField("expression")?e.field("expression"):"";if(!(t&&ie(t)&&i&&ie(i)&&a&&ie(a)))throw new o("InvalidParameter",n);d.push({name:t,statistic:i,expression:J.create(a,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of f)se(n.expression,e,t);for(const n of d)se(n.expression,e,t);return new O({parentfeatureset:s[0],groupbyfields:f,statsfields:d})})},e.signatures.push({name:"groupby",min:3,max:3}),e.functions.distinct=function(t,n){return e.standardFunctionAsync(t,n,async(a,r,s)=>{if(I(s[0])){y(s,2,2,n);const a=await s[0].load(),r=[];let l=[];if(ie(s[1]))l.push(s[1]);else if(s[1]instanceof i)l.push(s[1]);else if(ae(s[1]))l=s[1];else{if(!A(s[1]))throw new o("InvalidParameter",n);l=s[1].toArray()}let f=!1;for(const e of l)if(ie(e)){const t=J.create(g(e),{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),n=!0===q(t)?g(e):"%%%%FIELDNAME";r.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(f=!0)}else{if(!(e instanceof i))throw new o("InvalidParameter",n);{const t=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",i=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===t&&(f=!0),!t||!ie(t)||!ie(i))throw new o("InvalidParameter",n);r.push({name:t,expression:J.create(i||t,{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC})})}}if(f){const e={};for(const n of a.fields)e[n.name.toLowerCase()]=1;for(const n of r)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of r)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of r)se(n.expression,e,t);return new O({parentfeatureset:s[0],groupbyfields:r,statsfields:[]})}return oe(s)})},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,a)=>{if(y(a,1,1,n),!I(a[0]))return null;const r=await a[0].getFeatureSetInfo();return r?i.createMutable({__proto__:null,layerId:r.layerId,layerName:r.layerName,itemId:r.itemId,serviceLayerUrl:r.serviceLayerUrl,webMapLayerId:r.webMapLayerId??null,webMapLayerTitle:r.webMapLayerTitle??null,className:null,objectClassId:null}):null})},e.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),e.functions.filterbysubtypecode=function(t,n){return e.standardFunctionAsync(t,n,async(e,t,i)=>{if(y(i,2,2,n),I(i[0])){const e=await i[0].load(),t=i[1];if(!re(t))throw new o("InvalidParameter",n);if(e.subtypeField){const t=J.create(`${e.subtypeField}= ${i[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new R({parentfeatureset:i[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new o("FeatureSetDoesNotHaveSubtypes",n);const a=J.create(`${e.typeIdField}= ${i[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new R({parentfeatureset:i[0],whereclause:a})}throw new o("InvalidParameter",n)})},e.signatures.push({name:"filterbysubtypecode",min:2,max:2})}}export{we as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{ArcadeExecutionError as e}from"../executionError.js";import{shapeExtent as t}from"../kernel.js";import{H as n,B as r,h as i,s as a,m as s}from"../../chunks/languageUtils.js";import o from"../featureset/actions/SpatialFilter.js";import l from"../featureset/sources/Empty.js";import{invokeRemoteGeometryOp as u}from"../geometry/operatorsWorkerConnection.js";function c(a){return async(c,f,p)=>{if(r(p,2,2,f),null===(p=n(p))[0]&&null===p[1])return!1;if(s(p[0])){if(i(p[1]))return new o({parentfeatureset:p[0],relation:a,relationGeom:p[1]});if(null===p[1])return new l({parentfeatureset:p[0]});throw new e("InvalidParameter",f)}if(i(p[0])){if(i(p[1])){switch(a){case"esriSpatialRelEnvelopeIntersects":{const e=t(p[0]),n=t(p[1]);return null!=e&&null!=n&&u("intersects",[e.toJSON(),n.toJSON()])}case"esriSpatialRelIntersects":return u("intersects",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelContains":return u("contains",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelOverlaps":return u("overlaps",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelWithin":return u("within",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelTouches":return u("touches",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelCrosses":return u("crosses",[p[0].toJSON(),p[1].toJSON()])}throw new e("InvalidParameter",f)}if(s(p[1]))return new o({parentfeatureset:p[1],relation:a,relationGeom:p[0]});if(null===p[1])return!1;throw new e("InvalidParameter",f)}if(null===p[0]){if(s(p[1]))return new l({parentfeatureset:p[1]});if(i(p[1])||null===p[1])return!1}throw new e("InvalidParameter",f)}}function f(t){"async"===t.mode&&(t.functions.intersects=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelIntersects"))},t.functions.envelopeintersects=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelEnvelopeIntersects"))},t.signatures.push({name:"envelopeintersects",min:2,max:2}),t.functions.contains=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelContains"))},t.functions.overlaps=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelOverlaps"))},t.functions.within=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelWithin"))},t.functions.touches=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelTouches"))},t.functions.crosses=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelCrosses"))},t.functions.relate=function(c,f){return t.standardFunctionAsync(c,f,async(t,c,p)=>{if(p=n(p),r(p,3,3,f),i(p[0])&&i(p[1]))return u("relate",[p[0].toJSON(),p[1].toJSON(),a(p[2])]);if(i(p[0])&&null===p[1])return!1;if(i(p[1])&&null===p[0])return!1;if(s(p[0])&&null===p[1])return new l({parentfeatureset:p[0]});if(s(p[1])&&null===p[0])return new l({parentfeatureset:p[1]});if(s(p[0])&&i(p[1]))return new o({parentfeatureset:p[0],relation:"esriSpatialRelRelation",relationGeom:p[1],relationString:a(p[2])});if(s(p[1])&&i(p[0]))return new o({parentfeatureset:p[1],relation:"esriSpatialRelRelation",relationGeom:p[0],relationString:a(p[2])});if(null===p[0]&&null===p[1])return!1;throw new e("InvalidParameter",f)})})}export{f as registerFunctions};
2
+ import{ArcadeExecutionError as e}from"../executionError.js";import{shapeExtent as t}from"../kernel.js";import{H as n,B as r,f as i,s as a,k as s}from"../../chunks/languageUtils.js";import o from"../featureset/actions/SpatialFilter.js";import l from"../featureset/sources/Empty.js";import{invokeRemoteGeometryOp as u}from"../geometry/operatorsWorkerConnection.js";function c(a){return async(c,f,p)=>{if(r(p,2,2,f),null===(p=n(p))[0]&&null===p[1])return!1;if(s(p[0])){if(i(p[1]))return new o({parentfeatureset:p[0],relation:a,relationGeom:p[1]});if(null===p[1])return new l({parentfeatureset:p[0]});throw new e("InvalidParameter",f)}if(i(p[0])){if(i(p[1])){switch(a){case"esriSpatialRelEnvelopeIntersects":{const e=t(p[0]),n=t(p[1]);return null!=e&&null!=n&&u("intersects",[e.toJSON(),n.toJSON()])}case"esriSpatialRelIntersects":return u("intersects",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelContains":return u("contains",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelOverlaps":return u("overlaps",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelWithin":return u("within",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelTouches":return u("touches",[p[0].toJSON(),p[1].toJSON()]);case"esriSpatialRelCrosses":return u("crosses",[p[0].toJSON(),p[1].toJSON()])}throw new e("InvalidParameter",f)}if(s(p[1]))return new o({parentfeatureset:p[1],relation:a,relationGeom:p[0]});if(null===p[1])return!1;throw new e("InvalidParameter",f)}if(null===p[0]){if(s(p[1]))return new l({parentfeatureset:p[1]});if(i(p[1])||null===p[1])return!1}throw new e("InvalidParameter",f)}}function f(t){"async"===t.mode&&(t.functions.intersects=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelIntersects"))},t.functions.envelopeintersects=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelEnvelopeIntersects"))},t.signatures.push({name:"envelopeintersects",min:2,max:2}),t.functions.contains=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelContains"))},t.functions.overlaps=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelOverlaps"))},t.functions.within=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelWithin"))},t.functions.touches=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelTouches"))},t.functions.crosses=function(e,n){return t.standardFunctionAsync(e,n,c("esriSpatialRelCrosses"))},t.functions.relate=function(c,f){return t.standardFunctionAsync(c,f,async(t,c,p)=>{if(p=n(p),r(p,3,3,f),i(p[0])&&i(p[1]))return u("relate",[p[0].toJSON(),p[1].toJSON(),a(p[2])]);if(i(p[0])&&null===p[1])return!1;if(i(p[1])&&null===p[0])return!1;if(s(p[0])&&null===p[1])return new l({parentfeatureset:p[0]});if(s(p[1])&&null===p[0])return new l({parentfeatureset:p[1]});if(s(p[0])&&i(p[1]))return new o({parentfeatureset:p[0],relation:"esriSpatialRelRelation",relationGeom:p[1],relationString:a(p[2])});if(s(p[1])&&i(p[0]))return new o({parentfeatureset:p[1],relation:"esriSpatialRelRelation",relationGeom:p[0],relationString:a(p[2])});if(null===p[0]&&null===p[1])return!1;throw new e("InvalidParameter",f)})})}export{f as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{ArcadeDate as n}from"../ArcadeDate.js";import{isEmpty as t}from"../containerUtils.js";import{ArcadeExecutionError as e}from"../executionError.js";import{B as r,m as a,j as i,n as o,O as s,Q as u,P as c}from"../../chunks/languageUtils.js";import{calculateStat as f}from"./fieldStats.js";import{SqlTimeStampOffset as m}from"../../core/sql/SqlTimestampOffset.js";import d from"../../core/sql/WhereClause.js";import{DateTime as l}from"luxon";import{isArray as g,isString as y,isBoolean as p,isDate as A}from"../../support/guards.js";async function F(n,t,e,r){if(1===e.length){if(g(e[0]))return f(n,e[0],s(e[1],-1));if(i(e[0]))return f(n,e[0].toArray(),s(e[1],-1))}else if(2===e.length){if(g(e[0]))return f(n,e[0],s(e[1],-1));if(i(e[0]))return f(n,e[0].toArray(),s(e[1],-1));if(a(e[0])){const a=await e[0].load(),i=await w(d.create(e[1],{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),r,t);return h(t,await e[0].calculateStatistic(n,i,s(e[2],1e3),t.abortSignal))}}else if(3===e.length&&a(e[0])){const a=await e[0].load(),i=await w(d.create(e[1],{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),r,t);return h(t,await e[0].calculateStatistic(n,i,s(e[2],1e3),t.abortSignal))}return f(n,e,-1)}function h(t,e){return m.isTimestampOffset(e)?n.fromReaderAsTimeStampOffset(e.toStorageFormat()):A(e)?n.dateJSAndZoneToArcadeDate(e,c(t)):l.isDateTime(e)?n.dateTimeToArcadeDate(e):e}async function w(n,t,e){const r=n.getVariables();if(r.length>0){const a={};for(const n of r)a[n]=t.evaluateIdentifier(e,{name:n});n.parameters=a}return n}function S(n){"async"===n.mode&&(n.functions.stdev=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("stdev",t,a,n))},n.functions.variance=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("variance",t,a,n))},n.functions.average=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("mean",t,a,n))},n.functions.mean=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("mean",t,a,n))},n.functions.sum=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("sum",t,a,n))},n.functions.min=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("min",t,a,n))},n.functions.max=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("max",t,a,n))},n.functions.count=function(t,s){return n.standardFunctionAsync(t,s,async(n,t,u)=>{if(r(u,1,1,s),null==u[0])return 0;if(a(u[0]))return u[0].count(n.abortSignal);if(g(u[0])||y(u[0]))return u[0].length;if(i(u[0]))return u[0].length();if(o(u[0]))return u[0].entryCount();throw new e("InvalidParameter",s)})},n.functions.isempty=function(i,o){return n.standardFunctionAsync(i,o,async(n,i,o)=>{if(r(o,1,2,i),o.length>=2&&!p(o[1]))throw new e("InvalidParameter",i);return s(o[1],!1)?a(o[0])?await o[0].isEmpty(n.abortSignal):t(o[0]):u(o[0])})})}export{S as registerFunctions};
2
+ import{ArcadeDate as n}from"../ArcadeDate.js";import{isEmpty as t}from"../containerUtils.js";import{ArcadeExecutionError as e}from"../executionError.js";import{B as r,k as a,g as i,l as o,O as s,P as u,T as c}from"../../chunks/languageUtils.js";import{calculateStat as f}from"./fieldStats.js";import{SqlTimeStampOffset as m}from"../../core/sql/SqlTimestampOffset.js";import d from"../../core/sql/WhereClause.js";import{DateTime as l}from"luxon";import{isArray as g,isString as y,isBoolean as p,isDate as A}from"../../support/guards.js";async function F(n,t,e,r){if(1===e.length){if(g(e[0]))return f(n,e[0],s(e[1],-1));if(i(e[0]))return f(n,e[0].toArray(),s(e[1],-1))}else if(2===e.length){if(g(e[0]))return f(n,e[0],s(e[1],-1));if(i(e[0]))return f(n,e[0].toArray(),s(e[1],-1));if(a(e[0])){const a=await e[0].load(),i=await h(d.create(e[1],{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),r,t);return T(t,await e[0].calculateStatistic(n,i,s(e[2],1e3),t.abortSignal))}}else if(3===e.length&&a(e[0])){const a=await e[0].load(),i=await h(d.create(e[1],{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),r,t);return T(t,await e[0].calculateStatistic(n,i,s(e[2],1e3),t.abortSignal))}return f(n,e,-1)}function T(t,e){return m.isTimestampOffset(e)?n.fromReaderAsTimeStampOffset(e.toStorageFormat()):A(e)?n.dateJSAndZoneToArcadeDate(e,c(t)):l.isDateTime(e)?n.dateTimeToArcadeDate(e):e}async function h(n,t,e){const r=n.getVariables();if(r.length>0){const a={};for(const n of r)a[n]=t.evaluateIdentifier(e,{name:n});n.parameters=a}return n}function w(n){"async"===n.mode&&(n.functions.stdev=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("stdev",t,a,n))},n.functions.variance=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("variance",t,a,n))},n.functions.average=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("mean",t,a,n))},n.functions.mean=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("mean",t,a,n))},n.functions.sum=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("sum",t,a,n))},n.functions.min=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("min",t,a,n))},n.functions.max=function(t,e){return n.standardFunctionAsync(t,e,(e,r,a)=>F("max",t,a,n))},n.functions.count=function(t,s){return n.standardFunctionAsync(t,s,async(n,t,u)=>{if(r(u,1,1,s),null==u[0])return 0;if(a(u[0]))return u[0].count(n.abortSignal);if(g(u[0])||y(u[0]))return u[0].length;if(i(u[0]))return u[0].length();if(o(u[0]))return u[0].entryCount();throw new e("InvalidParameter",s)})},n.functions.isempty=function(i,o){return n.standardFunctionAsync(i,o,async(n,i,o)=>{if(r(o,1,2,i),o.length>=2&&!p(o[1]))throw new e("InvalidParameter",i);return s(o[1],!1)?a(o[0])?await o[0].isEmpty(n.abortSignal):t(o[0]):u(o[0])})})}export{w as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,X as r,s as o,m as i,a6 as c,$ as s,P as d,Z as u,a7 as m,Y as f,a8 as l,O as y,t as v,_ as w}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as p}from"../featureset/support/shared.js";function h(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:p[a.field.type],codedValues:a.domain.codedValues.map(n=>({name:n.name,code:n.code}))},d(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:p[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},d(e)):null}function T(p){"async"===p.mode&&(p.functions.domain=function(n,s){return p.standardFunctionAsync(n,s,async(d,u,m)=>{if(e(m,2,3,s),t(m[0])){return h(r(m[0],o(m[1]),void 0===m[2]?void 0:m[2]),n)}if(i(m[0])){await m[0]._ensureLoaded();return h(c(o(m[1]),m[0],null,void 0===m[2]?void 0:m[2]),n)}throw new a("InvalidParameter",s)})},p.functions.subtypes=function(r,o){return p.standardFunctionAsync(r,o,async(c,u,m)=>{if(e(m,1,1,o),t(m[0])){const a=s(m[0]);return a?n.convertObjectToArcadeDictionary(a,d(r)):null}if(i(m[0])){await m[0]._ensureLoaded();const a=m[0].subtypeMetadata();return a?n.convertObjectToArcadeDictionary(a,d(r)):null}throw new a("InvalidParameter",o)})},p.functions.domainname=function(n,r){return p.standardFunctionAsync(n,r,async(n,s,d)=>{if(e(d,2,4,r),t(d[0]))return u(d[0],o(d[1]),d[2],void 0===d[3]?void 0:d[3]);if(i(d[0])){await d[0]._ensureLoaded();const n=c(o(d[1]),d[0],null,void 0===d[3]?void 0:d[3]);return m(n,d[2])}throw new a("InvalidParameter",r)})},p.signatures.push({name:"domainname",min:2,max:4}),p.functions.domaincode=function(n,r){return p.standardFunctionAsync(n,r,async(n,s,d)=>{if(e(d,2,4,r),t(d[0]))return f(d[0],o(d[1]),d[2],void 0===d[3]?void 0:d[3]);if(i(d[0])){await d[0]._ensureLoaded();const n=c(o(d[1]),d[0],null,void 0===d[3]?void 0:d[3]);return l(n,d[2])}throw new a("InvalidParameter",r)})},p.signatures.push({name:"domaincode",min:2,max:4}),p.functions.text=function(n,t){return p.standardFunctionAsync(n,t,async(n,r,o)=>{if(e(o,1,2,t),i(o[0])){const e=y(o[1],"");if(""===e)return o[0].castToText();if("schema"===e.toLowerCase())return o[0].convertToText("schema",n.abortSignal);if("featureset"===e.toLowerCase())return o[0].convertToText("featureset",n.abortSignal);throw new a("InvalidParameter",t)}return v(o[0],o[1])})},p.functions.gdbversion=function(n,r){return p.standardFunctionAsync(n,r,async(n,o,c)=>{if(e(c,1,1,r),t(c[0]))return c[0].gdbVersion();if(i(c[0])){return(await c[0].load()).gdbVersion}throw new a("InvalidParameter",r)})},p.functions.schema=function(r,o){return p.standardFunctionAsync(r,o,async(c,s,u)=>{if(e(u,1,1,o),i(u[0]))return await u[0].load(),n.convertObjectToArcadeDictionary(u[0].schema(),d(r));if(t(u[0])){const a=w(u[0]);return a?n.convertObjectToArcadeDictionary(a,d(r)):null}throw new a("InvalidParameter",o)})})}export{T as registerFunctions};
2
+ import{convertJsonValueToImmutableArcadeValue as n}from"../containerUtils.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,h as t,X as r,s as o,k as i,a6 as s,$ as d,Z as u,a7 as c,Y as m,a8 as f,O as l,t as y,_ as v}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as w}from"../featureset/support/shared.js";function p(a){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n({type:"codedValue",name:a.domain.name,dataType:w[a.field.type],codedValues:a.domain.codedValues.map(n=>({name:n.name,code:n.code}))}):n({type:"range",name:a.domain.name,dataType:w[a.field.type],min:a.domain.minValue,max:a.domain.maxValue}):null}function h(w){"async"===w.mode&&(w.functions.domain=function(n,d){return w.standardFunctionAsync(n,d,async(n,u,c)=>{if(e(c,2,3,d),t(c[0])){return p(r(c[0],o(c[1]),void 0===c[2]?void 0:c[2]))}if(i(c[0])){await c[0]._ensureLoaded();return p(s(o(c[1]),c[0],null,void 0===c[2]?void 0:c[2]))}throw new a("InvalidParameter",d)})},w.functions.subtypes=function(r,o){return w.standardFunctionAsync(r,o,async(r,s,u)=>{if(e(u,1,1,o),t(u[0]))return n(d(u[0]));if(i(u[0]))return await u[0]._ensureLoaded(),n(u[0].subtypeMetadata());throw new a("InvalidParameter",o)})},w.functions.domainname=function(n,r){return w.standardFunctionAsync(n,r,async(n,d,m)=>{if(e(m,2,4,r),t(m[0]))return u(m[0],o(m[1]),m[2],void 0===m[3]?void 0:m[3]);if(i(m[0])){await m[0]._ensureLoaded();const n=s(o(m[1]),m[0],null,void 0===m[3]?void 0:m[3]);return c(n,m[2])}throw new a("InvalidParameter",r)})},w.signatures.push({name:"domainname",min:2,max:4}),w.functions.domaincode=function(n,r){return w.standardFunctionAsync(n,r,async(n,d,u)=>{if(e(u,2,4,r),t(u[0]))return m(u[0],o(u[1]),u[2],void 0===u[3]?void 0:u[3]);if(i(u[0])){await u[0]._ensureLoaded();const n=s(o(u[1]),u[0],null,void 0===u[3]?void 0:u[3]);return f(n,u[2])}throw new a("InvalidParameter",r)})},w.signatures.push({name:"domaincode",min:2,max:4}),w.functions.text=function(n,t){return w.standardFunctionAsync(n,t,async(n,r,o)=>{if(e(o,1,2,t),i(o[0])){const e=l(o[1],"");if(""===e)return o[0].castToText();if("schema"===e.toLowerCase())return o[0].convertToText("schema",n.abortSignal);if("featureset"===e.toLowerCase())return o[0].convertToText("featureset",n.abortSignal);throw new a("InvalidParameter",t)}return y(o[0],o[1])})},w.functions.gdbversion=function(n,r){return w.standardFunctionAsync(n,r,async(n,o,s)=>{if(e(s,1,1,r),t(s[0]))return s[0].gdbVersion();if(i(s[0])){return(await s[0].load()).gdbVersion}throw new a("InvalidParameter",r)})},w.functions.schema=function(r,o){return w.standardFunctionAsync(r,o,async(r,s,d)=>{if(e(d,1,1,o),i(d[0]))return await d[0].load(),n(d[0].schema());if(t(d[0]))return n(v(d[0]));throw new a("InvalidParameter",o)})})}export{h as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import n from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as e}from"../executionError.js";import{cloneGeometry as r}from"../kernel.js";import{H as a,B as i,e as o,g as s,f as c,s as u,j as l,J as f,m as d,K as w,h as m,L as y,M as h,r as p,N as g,O as N,P as S}from"../../chunks/languageUtils.js";import{getPortal as O}from"../portalUtils.js";import{commonRelationsCheck as J,toCurveType as v,planarLength3D as P,toOffsetJoinType as A,toCentroidAlgorithm as I,measureToCoordinateFunc as F,pointToCoordinateFunc as j,distanceToCoordinateFunc as R}from"../geometry/functions.js";import{invokeRemoteGeometryOp as b}from"../geometry/operatorsWorkerConnection.js";import{equals as x}from"../../core/arrayUtils.js";import L from"../../geometry/Extent.js";import D from"../../geometry/Geometry.js";import C from"../../geometry/Multipoint.js";import U from"../../geometry/Point.js";import M from"../../geometry/Polygon.js";import k from"../../geometry/Polyline.js";import{fromJSON as E}from"../../geometry/support/jsonUtils.js";import{lookupUser as T}from"../../portal/support/utils.js";import{isArray as Z}from"../../support/guards.js";function q(n){if(null==n)return n;switch(typeof n){case"string":case"number":return n;default:throw new e("InvalidParameter",null)}}function z(z){"async"===z.mode&&(z.functions.disjoint=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null===r[0]||null===r[1]||b("disjoint",[r[0].toJSON(),r[1].toJSON()])))},z.functions.intersects=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null!==r[0]&&null!==r[1]&&b("intersects",[r[0].toJSON(),r[1].toJSON()])))},z.functions.touches=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null!==r[0]&&null!==r[1]&&b("touches",[r[0].toJSON(),r[1].toJSON()])))},z.functions.crosses=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null!==r[0]&&null!==r[1]&&b("crosses",[r[0].toJSON(),r[1].toJSON()])))},z.functions.within=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null!==r[0]&&null!==r[1]&&b("within",[r[0].toJSON(),r[1].toJSON()])))},z.functions.contains=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null!==r[0]&&null!==r[1]&&b("contains",[r[0].toJSON(),r[1].toJSON()])))},z.functions.overlaps=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=a(r),J(r,t),null!==r[0]&&null!==r[1]&&b("overlaps",[r[0].toJSON(),r[1].toJSON()])))},z.functions.equals=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(i(r,2,2,t),r[0]===r[1]||(r[0]instanceof D&&r[1]instanceof D?b("equals",[r[0].toJSON(),r[1].toJSON()]):(o(r[0])&&o(r[1])||!!(s(r[0])&&s(r[1])||c(r[0])&&c(r[1])))&&r[0].equals(r[1]))))},z.functions.relate=function(n,t){return z.standardFunctionAsync(n,t,(n,r,o)=>{if(o=a(o),i(o,3,3,t),o[0]instanceof D&&o[1]instanceof D)return b("relate",[o[0].toJSON(),o[1].toJSON(),u(o[2])]);if(o[0]instanceof D&&null===o[1])return!1;if(o[1]instanceof D&&null===o[0])return!1;if(null===o[0]&&null===o[1])return!1;throw new e("InvalidParameter",t)})},z.functions.intersection=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,r)=>(r=a(r),J(r,t),null===r[0]||null===r[1]?null:E(await b("intersection",[r[0].toJSON(),r[1].toJSON()]))))},z.functions.union=function(n,t){return z.standardFunctionAsync(n,t,async(i,o,s)=>{if(0===(s=a(s)).length)throw new e("WrongNumberOfParameters",t);const c=[];if(1===s.length)if(Z(s[0])){for(const n of a(s[0]))if(null!==n){if(!(n instanceof D))throw new e("InvalidParameter",t);c.push(n.toJSON())}}else{if(!l(s[0])){if(s[0]instanceof D)return f(r(s[0]),n.spatialReference);if(null===s[0])return null;throw new e("InvalidParameter",t)}for(const n of a(s[0].toArray()))if(null!==n){if(!(n instanceof D))throw new e("InvalidParameter",t);c.push(n.toJSON())}}else for(const n of s)if(null!==n){if(!(n instanceof D))throw new e("InvalidParameter",t);c.push(n.toJSON())}return 0===c.length?null:E(await b("union",[c]))})},z.functions.difference=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,i)=>(i=a(i),J(i,t),null===i[0]?null:null===i[1]?r(i[0]):E(await b("difference",[i[0].toJSON(),i[1].toJSON()]))))},z.functions.symmetricdifference=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,i)=>(i=a(i),J(i,t),null===i[0]&&null===i[1]?null:null===i[0]?r(i[1]):null===i[1]?r(i[0]):E(await b("symmetricDifference",[i[0].toJSON(),i[1].toJSON()]))))},z.functions.clip=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{if(o=a(o),i(o,2,2,t),!(o[1]instanceof L)&&null!==o[1])throw new e("InvalidParameter",t);if(null===o[0])return null;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);return null===o[1]?null:E(await b("clip",[o[0].toJSON(),o[1].toJSON()]))})},z.functions.cut=function(n,t){return z.standardFunctionAsync(n,t,async(n,o,s)=>{if(s=a(s),i(s,2,2,t),!(s[1]instanceof k)&&null!==s[1])throw new e("InvalidParameter",t);if(null===s[0])return[];if(!(s[0]instanceof D))throw new e("InvalidParameter",t);return null===s[1]?[r(s[0])]:(await b("cut",[s[0].toJSON(),s[1].toJSON()])).map(n=>E(n))})},z.functions.area=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{if(i(s,1,2,t),s=a(s),d(s[0])){const r=await s[0].sumArea(q(s[1]),null,n.abortSignal);if(n.abortSignal.aborted)throw new e("Cancelled",t);return r}let c=s[0];if((Z(c)||l(c))&&(c=w(s[0],n.spatialReference)),null===c)return 0;if(!(c instanceof D))throw new e("InvalidParameter",t);return b("area",[c.toJSON(),q(s[1])])})},z.functions.areageodetic=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{i(s,1,3,t);let c=(s=a(s))[0];(Z(c)||l(c))&&(c=w(c,n.spatialReference));const u=q(s[1]),f=v(s[2]);if(d(c)){const r=await c.sumArea(u,f,n.abortSignal);if(n.abortSignal.aborted)throw new e("Cancelled",t);return r}if(null==c)return 0;if(!m(c))throw new e("InvalidParameter",t);return b("geodeticArea",[c.toJSON(),u,f])})},z.functions.length=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{if(i(s,1,2,t),s=a(s),d(s[0])){const r=await s[0].sumLength(q(s[1]),null,n.abortSignal);if(n.abortSignal.aborted)throw new e("Cancelled",t);return r}let c=s[0];if((Z(s[0])||l(s[0]))&&(c=y(s[0],n.spatialReference)),null===c)return 0;if(!(c instanceof D))throw new e("InvalidParameter",t);return b("length",[c.toJSON(),q(s[1])])})},z.functions.length3d=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{if(i(s,1,2,t),null===(s=a(s))[0])return 0;let c=s[0];if((Z(s[0])||l(s[0]))&&(c=y(s[0],n.spatialReference)),null===c)return 0;if(!(c instanceof D))throw new e("InvalidParameter",t);if(!0===c.hasZ){const{convertFromSpatialReferenceUnit:n,toLengthUnit:t}=await import("../geometry/unitConversion.js"),e=P(c);return n(c.spatialReference,t(s[1]),e)}return b("length",[c.toJSON(),q(s[1])])})},z.functions.lengthgeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{i(s,1,3,t);let c=(s=a(s))[0];(Z(s[0])||l(s[0]))&&(c=y(s[0],n.spatialReference));const u=q(s[1]),f=v(s[2]);if(d(c)){const r=await c.sumLength(u,f,n.abortSignal);if(n.abortSignal.aborted)throw new e("Cancelled",t);return r}if(null===c)return 0;if(!m(c))throw new e("InvalidParameter",t);return b("geodeticLength",[c.toJSON(),u,f])})},z.functions.distance=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{s=a(s),i(s,2,3,t);let c=s[0];if((Z(s[0])||l(s[0]))&&(c=h(s[0],n.spatialReference)),!(c instanceof D))throw new e("InvalidParameter",t);let u=s[1];if((Z(s[1])||l(s[1]))&&(u=h(s[1],n.spatialReference)),!(u instanceof D))throw new e("InvalidParameter",t);return b("distance",[c.toJSON(),u.toJSON(),q(s[2])])})},z.functions.distancegeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{o=a(o),i(o,2,4,t);const s=o[0];if(!(s instanceof U))throw new e("InvalidParameter",t);const c=o[1];if(!(c instanceof U))throw new e("InvalidParameter",t);const u=new k({paths:[],spatialReference:s.spatialReference});return u.addPath([s,c]),b("geodeticLength",[u.toJSON(),q(o[2]),v(o[3])])})},z.functions.densify=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{if(o=a(o),i(o,2,3,t),null===o[0])return null;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);const s=p(o[1]);if(isNaN(s))throw new e("InvalidParameter",t);if(s<=0)throw new e("InvalidParameter",t);switch(o[0].type){case"polygon":case"polyline":case"extent":return E(await b("densify",[o[0].toJSON(),s,q(o[2])]));default:return o[0]}})},z.functions.densifygeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{o=a(o),i(o,2,4,t);const s=o[0];if(null==s)return null;if(!m(s))throw new e("InvalidParameter",t);const c=p(o[1]);if(isNaN(c))throw new e("InvalidParameter",t);if(c<=0)throw new e("InvalidParameter",t);const u=q(o[2]),l=v(o[3]);switch(s.type){case"polygon":case"polyline":case"extent":return E(await b("geodeticDensify",[s.toJSON(),c,u,l]));default:return s}})},z.functions.generalize=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{if(o=a(o),i(o,2,4,t),null===o[0])return null;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);const s=p(o[1]);if(isNaN(s))throw new e("InvalidParameter",t);const c=g(N(o[2],!0));return E(await b("generalize",[o[0].toJSON(),s,q(o[3]),{removeDegenerateParts:c}]))})},z.functions.buffer=function(n,t){return z.standardFunctionAsync(n,t,async(n,o,s)=>{if(s=a(s),i(s,2,3,t),null===s[0])return null;if(!(s[0]instanceof D))throw new e("InvalidParameter",t);const c=p(s[1]);if(isNaN(c))throw new e("InvalidParameter",t);return 0===c?r(s[0]):E(await b("buffer",[s[0].toJSON(),c,q(s[2])]))})},z.functions.buffergeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(n,o,s)=>{s=a(s),i(s,2,4,t);const c=s[0];if(null==c)return null;if(!m(c))throw new e("InvalidParameter",t);const u=p(s[1]);if(isNaN(u))throw new e("InvalidParameter",t);if(0===u)return r(c);const l=q(s[2]),f=v(s[3]);return E(await b("geodesicBuffer",[c.toJSON(),u,l,f]))})},z.functions.offset=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{o=a(o),i(o,2,6,t);const s=o[0];if(null===s)return null;if(!(s instanceof M||s instanceof k))throw new e("InvalidParameter",t);const c=p(o[1]);if(isNaN(c))throw new e("InvalidParameter",t);const u=o[2],l=A(o[3]),f=p(N(o[4],10));if(isNaN(f))throw new e("InvalidParameter",t);const d=p(N(o[5],0));if(isNaN(d))throw new e("InvalidParameter",t);return E(await b("offset",[s.toJSON(),c,q(u),l,f,d]))})},z.functions.rotate=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{if(o=a(o),i(o,2,3,t),null===o[0])return null;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);const s=o[0]instanceof L?M.fromExtent(o[0]):o[0],c=p(o[1]);if(isNaN(c))throw new e("InvalidParameter",t);const u=N(o[2],null);if(null===u){const n="point"===s.type?s:s.extent?.center;return E(await b("rotate",[s.toJSON(),c,n?.x,n?.y]))}if(u instanceof U)return E(await b("rotate",[s.toJSON(),c,u.x,u.y]));throw new e("InvalidParameter",t)})},z.functions.centroid=function(n,t){return z.standardFunctionAsync(n,t,async(r,o,s)=>{if(s=a(s),i(s,1,2,t),null===s[0])return null;const c=I(s[1]);let u=s[0];if((Z(s[0])||l(s[0]))&&(u="geometric"===c?h(s[0],n.spatialReference):w(s[0],n.spatialReference),null===u))return null;if(!(u instanceof D))throw new e("InvalidParameter",t);return E("geometric"===c?await b("centroid",[u.toJSON()]):await b("labelPoint",[u.toJSON()]))})},z.functions.measuretocoordinate=function(n,t){return z.standardFunctionAsync(n,t,F)},z.functions.pointtocoordinate=function(n,t){return z.standardFunctionAsync(n,t,j)},z.functions.distancetocoordinate=function(n,t){return z.standardFunctionAsync(n,t,R)},z.functions.multiparttosinglepart=function(n,t){return z.standardFunctionAsync(n,t,async(o,s,c)=>{if(c=a(c),i(c,1,1,t),null===c[0])return null;if(!(c[0]instanceof D))throw new e("InvalidParameter",t);if(c[0]instanceof U)return[f(r(c[0]),n.spatialReference)];if(c[0]instanceof L)return[f(r(c[0]),n.spatialReference)];const u=E(await b("simplify",[c[0].toJSON()]));if(u instanceof M){const n=[],t=[];for(let e=0;e<u.rings.length;e++)if(u.isClockwise(u.rings[e])){const t=E({rings:[u.rings[e]],hasZ:!0===u.hasZ,hasM:!0===u.hasM,spatialReference:u.spatialReference.toJSON()});n.push(t)}else t.push({ring:u.rings[e],pt:u.getPoint(e,0)});for(let e=0;e<t.length;e++)for(let r=0;r<n.length;r++)if(n[r].contains(t[e].pt)){n[r].addRing(t[e].ring);break}return n}if(u instanceof k){const n=[];for(let t=0;t<u.paths.length;t++){const e=E({paths:[u.paths[t]],hasZ:!0===u.hasZ,hasM:!0===u.hasM,spatialReference:u.spatialReference.toJSON()});n.push(e)}return n}if(c[0]instanceof C){const t=[],e=f(r(c[0]),n.spatialReference);for(let n=0;n<e.points.length;n++)t.push(e.getPoint(n));return t}return null})},z.functions.isselfintersecting=function(n,t){return z.standardFunctionAsync(n,t,async(n,t,e)=>{i(e,1,1,t);let r=(e=a(e))[0];if((Z(e[0])||l(e[0]))&&(r=y(e[0],n.spatialReference)),r instanceof C){const n=r.points;for(let t=0;t<n.length;t++)for(let e=t+1;e<n.length;e++)if(x(n[t],n[e]))return!0;return!1}return(r instanceof k||r instanceof M)&&await b("isSelfIntersecting",[r.toJSON()])})},z.functions.issimple=function(n,t){return z.standardFunctionAsync(n,t,(n,r,o)=>{if(o=a(o),i(o,1,1,t),null===o[0])return!0;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);return b("isSimple",[o[0].toJSON()])})},z.functions.simplify=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{if(o=a(o),i(o,1,1,t),null===o[0])return null;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);return E(await b("simplify",[o[0].toJSON()]))})},z.functions.convexhull=function(n,t){return z.standardFunctionAsync(n,t,async(n,r,o)=>{if(o=a(o),i(o,1,1,t),null===o[0])return null;if(!(o[0]instanceof D))throw new e("InvalidParameter",t);return E(await b("convexHull",[o[0].toJSON()]))})},z.functions.getuser=function(r,a){return z.standardFunctionAsync(r,a,async(o,s,c)=>{i(c,0,2,a);let l=N(c[1],""),f=!0===l;if(l=!0===l||!1===l?"":u(l),0===c.length||c[0]instanceof n){const n=O(r,c.length>0?c[0]:null),e=await T(n,l,f);if(e){const n=JSON.parse(JSON.stringify(e));for(const t of["lastLogin","created","modified"])void 0!==n[t]&&null!==n[t]&&(n[t]=new Date(n[t]));return t.convertObjectToArcadeDictionary(n,S(r))}return null}let w=null;if(d(c[0])&&(w=c[0]),w){if(f=!1,l)return null;await w.load();const e=await w.getOwningSystemUrl();if(!e){if(!l){const n=await w.getIdentityUser();return n?t.convertObjectToArcadeDictionary({username:n},S(r)):null}return null}const a=O(r,new n(e)),i=await T(a,l,f);if(i){const n=JSON.parse(JSON.stringify(i));for(const t of["lastLogin","created","modified"])void 0!==n[t]&&null!==n[t]&&(n[t]=new Date(n[t]));return t.convertObjectToArcadeDictionary(n,S(r))}return null}throw new e("InvalidParameter",a)})},z.functions.nearestcoordinate=function(n,r){return z.standardFunctionAsync(n,r,async(o,s,c)=>{if(c=a(c),i(c,2,2,r),!(c[0]instanceof D||null===c[0]))throw new e("InvalidParameter",r);if(!(c[1]instanceof U||null===c[1]))throw new e("InvalidParameter",r);if(null===c[0]||null===c[1])return null;const u=c[0]instanceof L?M.fromExtent(c[0]):c[0],l=await b("getNearestCoordinate",[u.toJSON(),c[1].toJSON(),{calculateLeftRightSide:!0}]);return null===l?null:t.convertObjectToArcadeDictionary({coordinate:E(l.coordinate),distance:l.distance,sideOfLine:0===l.distance?"straddle":l.isRightSide?"right":"left"},S(n),!1,!0)})},z.functions.nearestvertex=function(n,r){return z.standardFunctionAsync(n,r,async(o,s,c)=>{if(c=a(c),i(c,2,2,r),!(c[0]instanceof D||null===c[0]))throw new e("InvalidParameter",r);if(!(c[1]instanceof U||null===c[1]))throw new e("InvalidParameter",r);if(null===c[0]||null===c[1])return null;const u=c[0]instanceof L?M.fromExtent(c[0]):c[0],l=await b("getNearestVertex",[u.toJSON(),c[1].toJSON()]);return null==l?null:t.convertObjectToArcadeDictionary({coordinate:E(l.coordinate),distance:l.distance,sideOfLine:l.sideOfLine},S(n),!1,!0)})})}export{z as registerFunctions};
2
+ import n from"../ArcadePortal.js";import{convertJsonValueToImmutableArcadeValue as t}from"../containerUtils.js";import e from"../Dictionary.js";import{ArcadeExecutionError as r}from"../executionError.js";import{cloneGeometry as a}from"../kernel.js";import{H as i,B as o,e as s,n as u,o as c,s as l,g as f,J as d,k as w,K as m,f as y,L as h,M as p,r as g,N,O as S}from"../../chunks/languageUtils.js";import{getPortal as O}from"../portalUtils.js";import{commonRelationsCheck as J,toCurveType as P,planarLength3D as v,toOffsetJoinType as I,toCentroidAlgorithm as A,measureToCoordinateFunc as F,pointToCoordinateFunc as R,distanceToCoordinateFunc as j}from"../geometry/functions.js";import{invokeRemoteGeometryOp as b}from"../geometry/operatorsWorkerConnection.js";import{equals as x}from"../../core/arrayUtils.js";import L from"../../geometry/Extent.js";import U from"../../geometry/Geometry.js";import C from"../../geometry/Multipoint.js";import M from"../../geometry/Point.js";import _ from"../../geometry/Polygon.js";import k from"../../geometry/Polyline.js";import{fromJSON as E}from"../../geometry/support/jsonUtils.js";import{lookupUser as Z}from"../../portal/support/utils.js";import{isArray as D}from"../../support/guards.js";function q(n){if(null==n)return n;switch(typeof n){case"string":case"number":return n;default:throw new r("InvalidParameter",null)}}function z(z){"async"===z.mode&&(z.functions.disjoint=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null===r[0]||null===r[1]||b("disjoint",[r[0].toJSON(),r[1].toJSON()])))},z.functions.intersects=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null!==r[0]&&null!==r[1]&&b("intersects",[r[0].toJSON(),r[1].toJSON()])))},z.functions.touches=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null!==r[0]&&null!==r[1]&&b("touches",[r[0].toJSON(),r[1].toJSON()])))},z.functions.crosses=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null!==r[0]&&null!==r[1]&&b("crosses",[r[0].toJSON(),r[1].toJSON()])))},z.functions.within=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null!==r[0]&&null!==r[1]&&b("within",[r[0].toJSON(),r[1].toJSON()])))},z.functions.contains=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null!==r[0]&&null!==r[1]&&b("contains",[r[0].toJSON(),r[1].toJSON()])))},z.functions.overlaps=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(r=i(r),J(r,t),null!==r[0]&&null!==r[1]&&b("overlaps",[r[0].toJSON(),r[1].toJSON()])))},z.functions.equals=function(n,t){return z.standardFunctionAsync(n,t,(n,e,r)=>(o(r,2,2,t),r[0]===r[1]||(r[0]instanceof U&&r[1]instanceof U?b("equals",[r[0].toJSON(),r[1].toJSON()]):(s(r[0])&&s(r[1])||!!(u(r[0])&&u(r[1])||c(r[0])&&c(r[1])))&&r[0].equals(r[1]))))},z.functions.relate=function(n,t){return z.standardFunctionAsync(n,t,(n,e,a)=>{if(a=i(a),o(a,3,3,t),a[0]instanceof U&&a[1]instanceof U)return b("relate",[a[0].toJSON(),a[1].toJSON(),l(a[2])]);if(a[0]instanceof U&&null===a[1])return!1;if(a[1]instanceof U&&null===a[0])return!1;if(null===a[0]&&null===a[1])return!1;throw new r("InvalidParameter",t)})},z.functions.intersection=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,r)=>(r=i(r),J(r,t),null===r[0]||null===r[1]?null:E(await b("intersection",[r[0].toJSON(),r[1].toJSON()]))))},z.functions.union=function(n,t){return z.standardFunctionAsync(n,t,async(e,o,s)=>{if(0===(s=i(s)).length)throw new r("WrongNumberOfParameters",t);const u=[];if(1===s.length)if(D(s[0])){for(const n of i(s[0]))if(null!==n){if(!(n instanceof U))throw new r("InvalidParameter",t);u.push(n.toJSON())}}else{if(!f(s[0])){if(s[0]instanceof U)return d(a(s[0]),n.spatialReference);if(null===s[0])return null;throw new r("InvalidParameter",t)}for(const n of i(s[0].toArray()))if(null!==n){if(!(n instanceof U))throw new r("InvalidParameter",t);u.push(n.toJSON())}}else for(const n of s)if(null!==n){if(!(n instanceof U))throw new r("InvalidParameter",t);u.push(n.toJSON())}return 0===u.length?null:E(await b("union",[u]))})},z.functions.difference=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,r)=>(r=i(r),J(r,t),null===r[0]?null:null===r[1]?a(r[0]):E(await b("difference",[r[0].toJSON(),r[1].toJSON()]))))},z.functions.symmetricdifference=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,r)=>(r=i(r),J(r,t),null===r[0]&&null===r[1]?null:null===r[0]?a(r[1]):null===r[1]?a(r[0]):E(await b("symmetricDifference",[r[0].toJSON(),r[1].toJSON()]))))},z.functions.clip=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{if(a=i(a),o(a,2,2,t),!(a[1]instanceof L)&&null!==a[1])throw new r("InvalidParameter",t);if(null===a[0])return null;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);return null===a[1]?null:E(await b("clip",[a[0].toJSON(),a[1].toJSON()]))})},z.functions.cut=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,s)=>{if(s=i(s),o(s,2,2,t),!(s[1]instanceof k)&&null!==s[1])throw new r("InvalidParameter",t);if(null===s[0])return[];if(!(s[0]instanceof U))throw new r("InvalidParameter",t);return null===s[1]?[a(s[0])]:(await b("cut",[s[0].toJSON(),s[1].toJSON()])).map(n=>E(n))})},z.functions.area=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{if(o(s,1,2,t),s=i(s),w(s[0])){const e=await s[0].sumArea(q(s[1]),null,n.abortSignal);if(n.abortSignal.aborted)throw new r("Cancelled",t);return e}let u=s[0];if((D(u)||f(u))&&(u=m(s[0],n.spatialReference)),null===u)return 0;if(!(u instanceof U))throw new r("InvalidParameter",t);return b("area",[u.toJSON(),q(s[1])])})},z.functions.areageodetic=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{o(s,1,3,t);let u=(s=i(s))[0];(D(u)||f(u))&&(u=m(u,n.spatialReference));const c=q(s[1]),l=P(s[2]);if(w(u)){const e=await u.sumArea(c,l,n.abortSignal);if(n.abortSignal.aborted)throw new r("Cancelled",t);return e}if(null==u)return 0;if(!y(u))throw new r("InvalidParameter",t);return b("geodeticArea",[u.toJSON(),c,l])})},z.functions.length=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{if(o(s,1,2,t),s=i(s),w(s[0])){const e=await s[0].sumLength(q(s[1]),null,n.abortSignal);if(n.abortSignal.aborted)throw new r("Cancelled",t);return e}let u=s[0];if((D(s[0])||f(s[0]))&&(u=h(s[0],n.spatialReference)),null===u)return 0;if(!(u instanceof U))throw new r("InvalidParameter",t);return b("length",[u.toJSON(),q(s[1])])})},z.functions.length3d=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{if(o(s,1,2,t),null===(s=i(s))[0])return 0;let u=s[0];if((D(s[0])||f(s[0]))&&(u=h(s[0],n.spatialReference)),null===u)return 0;if(!(u instanceof U))throw new r("InvalidParameter",t);if(!0===u.hasZ){const{convertFromSpatialReferenceUnit:n,toLengthUnit:t}=await import("../geometry/unitConversion.js"),e=v(u);return n(u.spatialReference,t(s[1]),e)}return b("length",[u.toJSON(),q(s[1])])})},z.functions.lengthgeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{o(s,1,3,t);let u=(s=i(s))[0];(D(s[0])||f(s[0]))&&(u=h(s[0],n.spatialReference));const c=q(s[1]),l=P(s[2]);if(w(u)){const e=await u.sumLength(c,l,n.abortSignal);if(n.abortSignal.aborted)throw new r("Cancelled",t);return e}if(null===u)return 0;if(!y(u))throw new r("InvalidParameter",t);return b("geodeticLength",[u.toJSON(),c,l])})},z.functions.distance=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{s=i(s),o(s,2,3,t);let u=s[0];if((D(s[0])||f(s[0]))&&(u=p(s[0],n.spatialReference)),!(u instanceof U))throw new r("InvalidParameter",t);let c=s[1];if((D(s[1])||f(s[1]))&&(c=p(s[1],n.spatialReference)),!(c instanceof U))throw new r("InvalidParameter",t);return b("distance",[u.toJSON(),c.toJSON(),q(s[2])])})},z.functions.distancegeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{a=i(a),o(a,2,4,t);const s=a[0];if(!(s instanceof M))throw new r("InvalidParameter",t);const u=a[1];if(!(u instanceof M))throw new r("InvalidParameter",t);const c=new k({paths:[],spatialReference:s.spatialReference});return c.addPath([s,u]),b("geodeticLength",[c.toJSON(),q(a[2]),P(a[3])])})},z.functions.densify=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{if(a=i(a),o(a,2,3,t),null===a[0])return null;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);const s=g(a[1]);if(isNaN(s))throw new r("InvalidParameter",t);if(s<=0)throw new r("InvalidParameter",t);switch(a[0].type){case"polygon":case"polyline":case"extent":return E(await b("densify",[a[0].toJSON(),s,q(a[2])]));default:return a[0]}})},z.functions.densifygeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{a=i(a),o(a,2,4,t);const s=a[0];if(null==s)return null;if(!y(s))throw new r("InvalidParameter",t);const u=g(a[1]);if(isNaN(u))throw new r("InvalidParameter",t);if(u<=0)throw new r("InvalidParameter",t);const c=q(a[2]),l=P(a[3]);switch(s.type){case"polygon":case"polyline":case"extent":return E(await b("geodeticDensify",[s.toJSON(),u,c,l]));default:return s}})},z.functions.generalize=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{if(a=i(a),o(a,2,4,t),null===a[0])return null;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);const s=g(a[1]);if(isNaN(s))throw new r("InvalidParameter",t);const u=N(S(a[2],!0));return E(await b("generalize",[a[0].toJSON(),s,q(a[3]),{removeDegenerateParts:u}]))})},z.functions.buffer=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,s)=>{if(s=i(s),o(s,2,3,t),null===s[0])return null;if(!(s[0]instanceof U))throw new r("InvalidParameter",t);const u=g(s[1]);if(isNaN(u))throw new r("InvalidParameter",t);return 0===u?a(s[0]):E(await b("buffer",[s[0].toJSON(),u,q(s[2])]))})},z.functions.buffergeodetic=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,s)=>{s=i(s),o(s,2,4,t);const u=s[0];if(null==u)return null;if(!y(u))throw new r("InvalidParameter",t);const c=g(s[1]);if(isNaN(c))throw new r("InvalidParameter",t);if(0===c)return a(u);const l=q(s[2]),f=P(s[3]);return E(await b("geodesicBuffer",[u.toJSON(),c,l,f]))})},z.functions.offset=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{a=i(a),o(a,2,6,t);const s=a[0];if(null===s)return null;if(!(s instanceof _||s instanceof k))throw new r("InvalidParameter",t);const u=g(a[1]);if(isNaN(u))throw new r("InvalidParameter",t);const c=a[2],l=I(a[3]),f=g(S(a[4],10));if(isNaN(f))throw new r("InvalidParameter",t);const d=g(S(a[5],0));if(isNaN(d))throw new r("InvalidParameter",t);return E(await b("offset",[s.toJSON(),u,q(c),l,f,d]))})},z.functions.rotate=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{if(a=i(a),o(a,2,3,t),null===a[0])return null;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);const s=a[0]instanceof L?_.fromExtent(a[0]):a[0],u=g(a[1]);if(isNaN(u))throw new r("InvalidParameter",t);const c=S(a[2],null);if(null===c){const n="point"===s.type?s:s.extent?.center;return E(await b("rotate",[s.toJSON(),u,n?.x,n?.y]))}if(c instanceof M)return E(await b("rotate",[s.toJSON(),u,c.x,c.y]));throw new r("InvalidParameter",t)})},z.functions.centroid=function(n,t){return z.standardFunctionAsync(n,t,async(e,a,s)=>{if(s=i(s),o(s,1,2,t),null===s[0])return null;const u=A(s[1]);let c=s[0];if((D(s[0])||f(s[0]))&&(c="geometric"===u?p(s[0],n.spatialReference):m(s[0],n.spatialReference),null===c))return null;if(!(c instanceof U))throw new r("InvalidParameter",t);return E("geometric"===u?await b("centroid",[c.toJSON()]):await b("labelPoint",[c.toJSON()]))})},z.functions.measuretocoordinate=function(n,t){return z.standardFunctionAsync(n,t,F)},z.functions.pointtocoordinate=function(n,t){return z.standardFunctionAsync(n,t,R)},z.functions.distancetocoordinate=function(n,t){return z.standardFunctionAsync(n,t,j)},z.functions.multiparttosinglepart=function(n,t){return z.standardFunctionAsync(n,t,async(e,s,u)=>{if(u=i(u),o(u,1,1,t),null===u[0])return null;if(!(u[0]instanceof U))throw new r("InvalidParameter",t);if(u[0]instanceof M)return[d(a(u[0]),n.spatialReference)];if(u[0]instanceof L)return[d(a(u[0]),n.spatialReference)];const c=E(await b("simplify",[u[0].toJSON()]));if(c instanceof _){const n=[],t=[];for(let e=0;e<c.rings.length;e++)if(c.isClockwise(c.rings[e])){const t=E({rings:[c.rings[e]],hasZ:!0===c.hasZ,hasM:!0===c.hasM,spatialReference:c.spatialReference.toJSON()});n.push(t)}else t.push({ring:c.rings[e],pt:c.getPoint(e,0)});for(let e=0;e<t.length;e++)for(let r=0;r<n.length;r++)if(n[r].contains(t[e].pt)){n[r].addRing(t[e].ring);break}return n}if(c instanceof k){const n=[];for(let t=0;t<c.paths.length;t++){const e=E({paths:[c.paths[t]],hasZ:!0===c.hasZ,hasM:!0===c.hasM,spatialReference:c.spatialReference.toJSON()});n.push(e)}return n}if(u[0]instanceof C){const t=[],e=d(a(u[0]),n.spatialReference);for(let n=0;n<e.points.length;n++)t.push(e.getPoint(n));return t}return null})},z.functions.isselfintersecting=function(n,t){return z.standardFunctionAsync(n,t,async(n,t,e)=>{o(e,1,1,t);let r=(e=i(e))[0];if((D(e[0])||f(e[0]))&&(r=h(e[0],n.spatialReference)),r instanceof C){const n=r.points;for(let t=0;t<n.length;t++)for(let e=t+1;e<n.length;e++)if(x(n[t],n[e]))return!0;return!1}return(r instanceof k||r instanceof _)&&await b("isSelfIntersecting",[r.toJSON()])})},z.functions.issimple=function(n,t){return z.standardFunctionAsync(n,t,(n,e,a)=>{if(a=i(a),o(a,1,1,t),null===a[0])return!0;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);return b("isSimple",[a[0].toJSON()])})},z.functions.simplify=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{if(a=i(a),o(a,1,1,t),null===a[0])return null;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);return E(await b("simplify",[a[0].toJSON()]))})},z.functions.convexhull=function(n,t){return z.standardFunctionAsync(n,t,async(n,e,a)=>{if(a=i(a),o(a,1,1,t),null===a[0])return null;if(!(a[0]instanceof U))throw new r("InvalidParameter",t);return E(await b("convexHull",[a[0].toJSON()]))})},z.functions.getuser=function(e,a){return z.standardFunctionAsync(e,a,async(i,s,u)=>{o(u,0,2,a);let c=S(u[1],""),f=!0===c;if(c=!0===c||!1===c?"":l(c),0===u.length||u[0]instanceof n){const n=O(e,u.length>0?u[0]:null),r=await Z(n,c,f);return null!=r?t(JSON.parse(JSON.stringify(r))):null}let d=null;if(w(u[0])&&(d=u[0]),d){if(f=!1,c)return null;await d.load();const r=await d.getOwningSystemUrl();if(!r){if(!c){const n=await d.getIdentityUser();return null!=n?t({username:n}):null}return null}const a=O(e,new n(r)),i=await Z(a,c,f);return null!=i?t(JSON.parse(JSON.stringify(i))):null}throw new r("InvalidParameter",a)})},z.functions.nearestcoordinate=function(n,t){return z.standardFunctionAsync(n,t,async(n,a,s)=>{if(s=i(s),o(s,2,2,t),!(s[0]instanceof U||null===s[0]))throw new r("InvalidParameter",t);if(!(s[1]instanceof M||null===s[1]))throw new r("InvalidParameter",t);if(null===s[0]||null===s[1])return null;const u=s[0]instanceof L?_.fromExtent(s[0]):s[0],c=await b("getNearestCoordinate",[u.toJSON(),s[1].toJSON(),{calculateLeftRightSide:!0}]);return null===c?null:e.createMutable({__proto__:null,coordinate:E(c.coordinate),distance:c.distance,sideOfLine:0===c.distance?"straddle":c.isRightSide?"right":"left"})})},z.functions.nearestvertex=function(n,t){return z.standardFunctionAsync(n,t,async(n,a,s)=>{if(s=i(s),o(s,2,2,t),!(s[0]instanceof U||null===s[0]))throw new r("InvalidParameter",t);if(!(s[1]instanceof M||null===s[1]))throw new r("InvalidParameter",t);if(null===s[0]||null===s[1])return null;const u=s[0]instanceof L?_.fromExtent(s[0]):s[0],c=await b("getNearestVertex",[u.toJSON(),s[1].toJSON()]);return null==c?null:e.createMutable({__proto__:null,coordinate:E(c.coordinate),distance:c.distance,sideOfLine:c.sideOfLine})})})}export{z as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{getGeometryKeys as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r}from"../executionError.js";import{Feature as a}from"../Feature.js";import i from"../ImmutablePointArray.js";import{B as l,j as o,J as s,a0 as f,H as c,k as u,v as m,n as p,h as w,s as h,e as R,g,f as y,i as d,b as P,P as v,F as I,E as b,y as O,w as j}from"../../chunks/languageUtils.js";import{angle2D as N,angleBetween2D as S,bearing2D as x,bearingBetween2D as J}from"./centroid.js";import{constructGeometryFromDictionary as F}from"../geometry/constructors.js";import k from"../../geometry/Extent.js";import Z from"../../geometry/Geometry.js";import z from"../../geometry/Multipoint.js";import W from"../../geometry/Point.js";import A from"../../geometry/Polygon.js";import q from"../../geometry/Polyline.js";import{isClockwise as L}from"../../geometry/support/coordsUtils.js";import{fromJSON as M}from"../../geometry/support/jsonUtils.js";import{isArray as D,isString as G,isNumber as U,isBoolean as C}from"../../support/guards.js";function E(E,_){E.ringisclockwise=function(e,t){return _(e,t,(e,n,a)=>{l(a,1,1,t);let s=[];if(null===a[0])return!1;if(D(a[0]))for(const i of a[0]){if(!(i instanceof W))throw new r("InvalidParameter",t);s.push(i.hasZ?i.hasM?[i.x,i.y,i.z,i.m]:[i.x,i.y,i.z]:[i.x,i.y])}else if(a[0]instanceof i)s=a[0]._elements;else{if(!o(a[0]))throw new r("InvalidParameter",t);for(const e of a[0].toArray()){if(!(e instanceof W))throw new r("InvalidParameter",t);s.push(e.hasZ?e.hasM?[e.x,e.y,e.z,e.m]:[e.x,e.y,e.z]:[e.x,e.y])}}return!(s.length<3)&&L(s)})},E.polygon=function(e,t){return _(e,t,(a,i,o)=>{let c;if(l(o,1,1,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"polygon"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof A)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new A(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r("WrongSpatialReference",t);return f(c)})},E.polyline=function(e,t){return _(e,t,(a,i,o)=>{let c;if(l(o,1,1,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"polyline"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof q)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new q(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r("WrongSpatialReference",t);return f(c)})},E.point=function(e,t){return _(e,t,(a,i,o)=>{let c;if(l(o,1,1,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"point"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof W)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new W(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r("WrongSpatialReference",t);return f(c)})},E.multipoint=function(e,t){return _(e,t,(a,i,o)=>{let c;if(l(o,1,1,t),o[0]instanceof n){const t=s(F(o[0],e.spatialReference,"multipoint"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof z)c=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(new z(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r("WrongSpatialReference",t);return f(c)})},E.extent=function(e,t){return _(e,t,(a,i,o)=>{o=c(o),l(o,1,1,t);let u=null;if(o[0]instanceof n)u=s(F(o[0],e.spatialReference),e.spatialReference);else if(o[0]instanceof W){const e={xmin:o[0].x,ymin:o[0].y,xmax:o[0].x,ymax:o[0].y,spatialReference:o[0].spatialReference.toJSON()},t=o[0];t.hasZ&&(e.zmin=t.z,e.zmax=t.z),t.hasM&&(e.mmin=t.m,e.mmax=t.m),u=M(e)}else if(o[0]instanceof A)u=M(o[0].extent?.toJSON());else if(o[0]instanceof q)u=M(o[0].extent?.toJSON());else if(o[0]instanceof z)u=M(o[0].extent?.toJSON());else if(o[0]instanceof k)u=M(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=s(new k(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r("WrongSpatialReference",t);return f(u)})},E.geometry=function(e,t){return _(e,t,(a,i,o)=>{l(o,1,1,t);let c=null;if(null===o[0])return null;if(u(o[0]))c=s(o[0].geometry(),e.spatialReference);else if(o[0]instanceof n)c=s(F(o[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(M(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r("WrongSpatialReference",t);return f(c)})},E.setgeometry=function(e,t){return _(e,t,(e,n,a)=>{if(l(a,2,2,t),!u(a[0]))throw new r("InvalidParameter",t);if(!0===a[0].immutable)throw new r("Immutable",t);if(!(a[1]instanceof Z||null===a[1]))throw new r("InvalidParameter",t);return a[0]._geometry=a[1],m})},E.feature=function(e,t){return _(e,t,(i,l,o)=>{if(0===o.length)throw new r("WrongNumberOfParameters",t);let f;if(1===o.length)if(G(o[0]))f=a.fromJson(JSON.parse(o[0]),e.timeZone);else if(u(o[0]))f=a.createFromArcadeFeature(o[0]);else if(o[0]instanceof Z)f=a.createFromGraphicLikeObject(o[0],null,null,e.timeZone);else{if(!(o[0]instanceof n))throw new r("InvalidParameter",t);{const n=o[0].hasField("geometry")?o[0].field("geometry"):null,i=o[0].hasField("attributes")?o[0].field("attributes"):null;let l,s;if(p(n))l=F(n,e.spatialReference);else{if(null!=n&&!w(n))throw new r("InvalidParameter",t);l=n}if(p(i))s=a.parseAttributesFromDictionary(i);else{if(null!=i)throw new r("InvalidParameter",t);s=null}f=a.createFromGraphicLikeObject(l,s,null,e.timeZone)}}else if(2===o.length){let i=null,l=null;if(null!==o[0])if(o[0]instanceof Z)i=o[0];else{if(!(o[0]instanceof n))throw new r("InvalidParameter",t);i=F(o[0],e.spatialReference)}if(null!==o[1]){if(!(o[1]instanceof n))throw new r("InvalidParameter",t);l=a.parseAttributesFromDictionary(o[1])}f=a.createFromGraphicLikeObject(i,l,null,e.timeZone)}else{let i=null;const l={};if(null!==o[0])if(o[0]instanceof Z)i=o[0];else{if(!(o[0]instanceof n))throw new r("InvalidParameter",t);i=F(o[0],e.spatialReference)}for(let e=1;e<o.length;e+=2){const n=h(o[e]),a=o[e+1];if(!(null==a||G(a)||isNaN(a)||R(a)||U(a)||g(a)||y(a)||C(a)))throw new r("InvalidParameter",t);if(d(a)||!1===P(a))throw new r("InvalidParameter",t);l[n]=a===m?null:a}f=a.createFromGraphicLikeObject(i,l,null,e.timeZone)}return f._geometry=s(f.geometry(),e.spatialReference),f.immutable=!1,f})},E.dictionary=function(e,t){return _(e,t,(a,i,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new n;return e.immutable=!1,e}if(1===l.length&&G(l[0]))try{const t=JSON.parse(l[0]),r=n.convertObjectToArcadeDictionary(t,v(e),!1);return r.immutable=!1,r}catch(c){throw new r("InvalidParameter",t)}if(1===l.length&&l[0]instanceof Z)try{const t=l[0].toJSON();t.hasZ=!0===l[0].hasZ,t.hasM=!0===l[0].hasM;const r=n.convertObjectToArcadeDictionary(t,v(e),!1);return r.immutable=!1,r}catch(c){throw new r("InvalidParameter",t)}if(1===l.length&&u(l[0]))try{const e=new n;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new n;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(c){throw new r("InvalidParameter",t)}if(1===l.length&&(p(l[0])||I(l[0])||b(l[0])))try{const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(c){throw new r("InvalidParameter",t)}if(2===l.length&&l[0]instanceof n&&C(l[1]))try{if(!(!0===l[1])){const e=new n;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(c){throw new r("InvalidParameter",t)}if(l.length%2!=0)throw new r("WrongNumberOfParameters",t);const s=Object.create(null);for(let e=0;e<l.length;e+=2){const n=h(l[e]),a=l[e+1];if(!(null==a||G(a)||isNaN(a)||R(a)||U(a)||C(a)||y(a)||g(a)||D(a)||o(a)))throw new r("InvalidParameter",t);if(d(a))throw new r("InvalidParameter",t);s[n]=a===m?null:a}const f=new n(s);return f.immutable=!1,f})},E.haskey=function(t,a){return _(t,a,(t,i,o)=>{l(o,2,2,a);const s=h(o[1]);if(O(o[0])||o[0]instanceof n)return o[0].hasField(s);if(o[0]instanceof Z){const t=s.toLowerCase();for(const n of e(o[0]))if(n.toLowerCase()===t)return!0;return!1}throw new r("InvalidParameter",a)})},E.hasvalue=function(e,n){return _(e,n,(e,r,a)=>(l(a,2,2,n),null!=t(a[0],a[1])))},E.indexof=function(e,t){return _(e,t,(e,n,a)=>{l(a,2,2,t);const i=a[1];if(D(a[0])){for(let e=0;e<a[0].length;e++)if(j(i,a[0][e]))return e;return-1}if(o(a[0])){const e=a[0].length();for(let t=0;t<e;t++)if(j(i,a[0].get(t)))return t;return-1}throw new r("InvalidParameter",t)})},E.angle=function(e,t){return _(e,t,(e,n,a)=>{if(a=c(a),l(a,2,3,t),!(a[0]instanceof W))throw new r("InvalidParameter",t);if(!(a[1]instanceof W))throw new r("InvalidParameter",t);if(a.length>2&&!(a[2]instanceof W))throw new r("InvalidParameter",t);return 2===a.length?N(a[0],a[1]):S(a[0],a[1],a[2])})},E.bearing=function(e,t){return _(e,t,(e,n,a)=>{if(a=c(a),l(a,2,3,t),!(a[0]instanceof W))throw new r("InvalidParameter",t);if(!(a[1]instanceof W))throw new r("InvalidParameter",t);if(a.length>2&&!(a[2]instanceof W))throw new r("InvalidParameter",t);return 2===a.length?x(a[0],a[1]):J(a[0],a[1],a[2])})}}export{E as registerFunctions};
2
+ import{convertJsonValueToMutableArcadeValue as e,getGeometryKeys as t,getNestedOptionalValue as n}from"../containerUtils.js";import r from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{Feature as i}from"../Feature.js";import l from"../ImmutablePointArray.js";import{B as o,g as s,J as f,a0 as c,H as u,h as m,v as p,l as w,f as h,s as R,e as g,n as d,o as y,i as P,b as v,F as I,E as O,y as b,w as N}from"../../chunks/languageUtils.js";import{angle2D as S,angleBetween2D as j,bearing2D as x,bearingBetween2D as F}from"./centroid.js";import{constructGeometryFromDictionary as J}from"../geometry/constructors.js";import k from"../../geometry/Extent.js";import Z from"../../geometry/Geometry.js";import z from"../../geometry/Multipoint.js";import W from"../../geometry/Point.js";import q from"../../geometry/Polygon.js";import L from"../../geometry/Polyline.js";import{isClockwise as M}from"../../geometry/support/coordsUtils.js";import{fromJSON as A}from"../../geometry/support/jsonUtils.js";import{isArray as G,isString as U,isNumber as C,isBoolean as D}from"../../support/guards.js";function E(E,_){E.ringisclockwise=function(e,t){return _(e,t,(e,n,r)=>{o(r,1,1,t);let i=[];if(null===r[0])return!1;if(G(r[0]))for(const l of r[0]){if(!(l instanceof W))throw new a("InvalidParameter",t);i.push(l.hasZ?l.hasM?[l.x,l.y,l.z,l.m]:[l.x,l.y,l.z]:[l.x,l.y])}else if(r[0]instanceof l)i=r[0]._elements;else{if(!s(r[0]))throw new a("InvalidParameter",t);for(const e of r[0].toArray()){if(!(e instanceof W))throw new a("InvalidParameter",t);i.push(e.hasZ?e.hasM?[e.x,e.y,e.z,e.m]:[e.x,e.y,e.z]:[e.x,e.y])}}return!(i.length<3)&&M(i)})},E.polygon=function(e,t){return _(e,t,(n,i,l)=>{let s;if(o(l,1,1,t),l[0]instanceof r){const t=f(J(l[0],e.spatialReference,"polygon"),e.spatialReference);if(null==t)return null;s=t}else if(l[0]instanceof q)s=A(l[0].toJSON());else{const t=JSON.parse(l[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),s=f(new q(t),e.spatialReference)}if(null!==s&&!1===s.spatialReference.equals(e.spatialReference))throw new a("WrongSpatialReference",t);return c(s)})},E.polyline=function(e,t){return _(e,t,(n,i,l)=>{let s;if(o(l,1,1,t),l[0]instanceof r){const t=f(J(l[0],e.spatialReference,"polyline"),e.spatialReference);if(null==t)return null;s=t}else if(l[0]instanceof L)s=A(l[0].toJSON());else{const t=JSON.parse(l[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),s=f(new L(t),e.spatialReference)}if(null!==s&&!1===s.spatialReference.equals(e.spatialReference))throw new a("WrongSpatialReference",t);return c(s)})},E.point=function(e,t){return _(e,t,(n,i,l)=>{let s;if(o(l,1,1,t),l[0]instanceof r){const t=f(J(l[0],e.spatialReference,"point"),e.spatialReference);if(null==t)return null;s=t}else if(l[0]instanceof W)s=A(l[0].toJSON());else{const t=JSON.parse(l[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),s=f(new W(t),e.spatialReference)}if(null!==s&&!1===s.spatialReference.equals(e.spatialReference))throw new a("WrongSpatialReference",t);return c(s)})},E.multipoint=function(e,t){return _(e,t,(n,i,l)=>{let s;if(o(l,1,1,t),l[0]instanceof r){const t=f(J(l[0],e.spatialReference,"multipoint"),e.spatialReference);if(null==t)return null;s=t}else if(l[0]instanceof z)s=A(l[0].toJSON());else{const t=JSON.parse(l[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),s=f(new z(t),e.spatialReference)}if(null!==s&&!1===s.spatialReference.equals(e.spatialReference))throw new a("WrongSpatialReference",t);return c(s)})},E.extent=function(e,t){return _(e,t,(n,i,l)=>{l=u(l),o(l,1,1,t);let s=null;if(l[0]instanceof r)s=f(J(l[0],e.spatialReference),e.spatialReference);else if(l[0]instanceof W){const e={xmin:l[0].x,ymin:l[0].y,xmax:l[0].x,ymax:l[0].y,spatialReference:l[0].spatialReference.toJSON()},t=l[0];t.hasZ&&(e.zmin=t.z,e.zmax=t.z),t.hasM&&(e.mmin=t.m,e.mmax=t.m),s=A(e)}else if(l[0]instanceof q)s=A(l[0].extent?.toJSON());else if(l[0]instanceof L)s=A(l[0].extent?.toJSON());else if(l[0]instanceof z)s=A(l[0].extent?.toJSON());else if(l[0]instanceof k)s=A(l[0].toJSON());else{const t=JSON.parse(l[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),s=f(new k(t),e.spatialReference)}if(null!==s&&!1===s.spatialReference.equals(e.spatialReference))throw new a("WrongSpatialReference",t);return c(s)})},E.geometry=function(e,t){return _(e,t,(n,i,l)=>{o(l,1,1,t);let s=null;if(null===l[0])return null;if(m(l[0]))s=f(l[0].geometry(),e.spatialReference);else if(l[0]instanceof r)s=f(J(l[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(l[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),s=f(A(t),e.spatialReference)}if(null!==s&&!1===s.spatialReference.equals(e.spatialReference))throw new a("WrongSpatialReference",t);return c(s)})},E.setgeometry=function(e,t){return _(e,t,(e,n,r)=>{if(o(r,2,2,t),!m(r[0]))throw new a("InvalidParameter",t);if(!0===r[0].immutable)throw new a("Immutable",t);if(!(r[1]instanceof Z||null===r[1]))throw new a("InvalidParameter",t);return r[0]._geometry=r[1],p})},E.feature=function(e,t){return _(e,t,(n,l,o)=>{if(0===o.length)throw new a("WrongNumberOfParameters",t);let s;if(1===o.length)if(U(o[0]))s=i.fromJson(JSON.parse(o[0]),e.timeZone);else if(m(o[0]))s=i.createFromArcadeFeature(o[0]);else if(o[0]instanceof Z)s=i.createFromGraphicLikeObject(o[0],null,null,e.timeZone);else{if(!(o[0]instanceof r))throw new a("InvalidParameter",t);{const n=o[0].hasField("geometry")?o[0].field("geometry"):null,r=o[0].hasField("attributes")?o[0].field("attributes"):null;let l,f;if(w(n))l=J(n,e.spatialReference);else{if(null!=n&&!h(n))throw new a("InvalidParameter",t);l=n}if(w(r))f=i.parseAttributesFromDictionary(r);else{if(null!=r)throw new a("InvalidParameter",t);f=null}s=i.createFromGraphicLikeObject(l,f,null,e.timeZone)}}else if(2===o.length){let n=null,l=null;if(null!==o[0])if(o[0]instanceof Z)n=o[0];else{if(!(o[0]instanceof r))throw new a("InvalidParameter",t);n=J(o[0],e.spatialReference)}if(null!==o[1]){if(!(o[1]instanceof r))throw new a("InvalidParameter",t);l=i.parseAttributesFromDictionary(o[1])}s=i.createFromGraphicLikeObject(n,l,null,e.timeZone)}else{let n=null;const l={};if(null!==o[0])if(o[0]instanceof Z)n=o[0];else{if(!(o[0]instanceof r))throw new a("InvalidParameter",t);n=J(o[0],e.spatialReference)}for(let e=1;e<o.length;e+=2){const n=R(o[e]),r=o[e+1];if(!(null==r||U(r)||isNaN(r)||g(r)||C(r)||d(r)||y(r)||D(r)))throw new a("InvalidParameter",t);if(P(r)||!1===v(r))throw new a("InvalidParameter",t);l[n]=r===p?null:r}s=i.createFromGraphicLikeObject(n,l,null,e.timeZone)}return s._geometry=f(s.geometry(),e.spatialReference),s.immutable=!1,s})},E.dictionary=function(t,n){return _(t,n,(t,i,l)=>{if(0===l.length||1===l.length&&null===l[0]){const e=new r;return e.immutable=!1,e}if(1===l.length&&U(l[0]))try{const t=e(JSON.parse(l[0]));if(!w(t))throw new a("InvalidParameter",n);return t}catch(c){throw new a("InvalidParameter",n)}if(1===l.length&&l[0]instanceof Z)try{const t=e(l[0].toJSON());if(!w(t))throw new a("InvalidParameter",n);return t.setField("hasZ",!0===l[0].hasZ),t.setField("hasM",!0===l[0].hasM),t}catch(c){throw new a("InvalidParameter",n)}if(1===l.length&&m(l[0]))try{const e=new r;e.immutable=!1,e.setField("geometry",l[0].geometry());const t=new r;t.immutable=!1,e.setField("attributes",t);for(const n of l[0].keys())t.setField(n,l[0].field(n));return e}catch(c){throw new a("InvalidParameter",n)}if(1===l.length&&(w(l[0])||I(l[0])||O(l[0])))try{const e=new r;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}catch(c){throw new a("InvalidParameter",n)}if(2===l.length&&l[0]instanceof r&&D(l[1]))try{if(!(!0===l[1])){const e=new r;e.immutable=!1;for(const t of l[0].keys())e.setField(t,l[0].field(t));return e}return l[0].deepClone()}catch(c){throw new a("InvalidParameter",n)}if(l.length%2!=0)throw new a("WrongNumberOfParameters",n);const o=Object.create(null);for(let e=0;e<l.length;e+=2){const t=R(l[e]),r=l[e+1];if(!(null==r||U(r)||isNaN(r)||g(r)||C(r)||D(r)||y(r)||d(r)||G(r)||s(r)))throw new a("InvalidParameter",n);if(P(r))throw new a("InvalidParameter",n);o[t]=r===p?null:r}const f=new r(o);return f.immutable=!1,f})},E.haskey=function(e,n){return _(e,n,(e,i,l)=>{o(l,2,2,n);const s=R(l[1]);if(b(l[0])||l[0]instanceof r)return l[0].hasField(s);if(l[0]instanceof Z){const e=s.toLowerCase();for(const n of t(l[0]))if(n.toLowerCase()===e)return!0;return!1}throw new a("InvalidParameter",n)})},E.hasvalue=function(e,t){return _(e,t,(e,r,a)=>(o(a,2,2,t),null!=n(a[0],a[1])))},E.indexof=function(e,t){return _(e,t,(e,n,r)=>{o(r,2,2,t);const i=r[1];if(G(r[0])){for(let e=0;e<r[0].length;e++)if(N(i,r[0][e]))return e;return-1}if(s(r[0])){const e=r[0].length();for(let t=0;t<e;t++)if(N(i,r[0].get(t)))return t;return-1}throw new a("InvalidParameter",t)})},E.angle=function(e,t){return _(e,t,(e,n,r)=>{if(r=u(r),o(r,2,3,t),!(r[0]instanceof W))throw new a("InvalidParameter",t);if(!(r[1]instanceof W))throw new a("InvalidParameter",t);if(r.length>2&&!(r[2]instanceof W))throw new a("InvalidParameter",t);return 2===r.length?S(r[0],r[1]):j(r[0],r[1],r[2])})},E.bearing=function(e,t){return _(e,t,(e,n,r)=>{if(r=u(r),o(r,2,3,t),!(r[0]instanceof W))throw new a("InvalidParameter",t);if(!(r[1]instanceof W))throw new a("InvalidParameter",t);if(r.length>2&&!(r[2]instanceof W))throw new a("InvalidParameter",t);return 2===r.length?x(r[0],r[1]):F(r[0],r[1],r[2])})}}export{E as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../Dictionary.js";import{ArcadeExecutionError as n}from"../executionError.js";import{cloneGeometry as t}from"../kernel.js";import{H as r,B as i,e as a,g as l,f as o,s as u,j as f,J as c,K as s,h as m,L as d,M as w,r as h,N as p,O as g,P as v}from"../../chunks/languageUtils.js";import{commonRelationsCheck as P,toCurveType as x,planarLength3D as y,toOffsetJoinType as I,toCentroidAlgorithm as R,measureToCoordinateFunc as N,pointToCoordinateFunc as j,distanceToCoordinateFunc as O}from"../geometry/functions.js";import{convertFromSpatialReferenceUnit as b,toAreaUnit as D,convert as L,toLengthUnit as M,convertToSpatialReferenceUnit as T}from"../geometry/unitConversion.js";import{equals as E}from"../../core/arrayUtils.js";import S from"../../geometry/Extent.js";import A from"../../geometry/Geometry.js";import Z from"../../geometry/Multipoint.js";import k from"../../geometry/Point.js";import U from"../../geometry/Polygon.js";import q from"../../geometry/Polyline.js";import{fromJSON as C}from"../../geometry/support/jsonUtils.js";import{squareMeters as J,meters as z}from"../geometry/extendedUnitData.js";import{isArray as B}from"../../support/guards.js";let H;async function G(){null==H&&(H=await import("../geometry/operators.js"),await H.loadAll())}function K(G,K){G.disjoint=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null===i[0]||null===i[1]||H.disjoint.execute(i[0],i[1])))},G.intersects=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null!==i[0]&&null!==i[1]&&H.intersects.execute(i[0],i[1])))},G.touches=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null!==i[0]&&null!==i[1]&&H.touches.execute(i[0],i[1])))},G.crosses=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null!==i[0]&&null!==i[1]&&H.crosses.execute(i[0],i[1])))},G.within=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null!==i[0]&&null!==i[1]&&H.within.execute(i[0],i[1])))},G.contains=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null!==i[0]&&null!==i[1]&&H.contains.execute(i[0],i[1])))},G.overlaps=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null!==i[0]&&null!==i[1]&&H.overlaps.execute(i[0],i[1])))},G.equals=function(e,n){return K(e,n,(e,t,r)=>(i(r,2,2,n),r[0]===r[1]||(r[0]instanceof A&&r[1]instanceof A?H.equals.execute(r[0],r[1]):(a(r[0])&&a(r[1])||l(r[0])&&l(r[1])||!(!o(r[0])||!o(r[1])))&&r[0].equals(r[1]))))},G.relate=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,3,3,t),l[0]instanceof A&&l[1]instanceof A)return H.relate.execute(l[0],l[1],u(l[2]));if(l[0]instanceof A&&null===l[1])return!1;if(l[1]instanceof A&&null===l[0])return!1;if(null===l[0]&&null===l[1])return!1;throw new n("InvalidParameter",t)})},G.intersection=function(e,n){return K(e,n,(e,t,i)=>(i=r(i),P(i,n),null===i[0]||null===i[1]?null:H.intersection.execute(i[0],i[1])))},G.union=function(e,i){return K(e,i,(a,l,o)=>{if(0===(o=r(o)).length)throw new n("WrongNumberOfParameters",i);const u=[];if(1===o.length)if(B(o[0])){for(const e of r(o[0]))if(null!==e){if(!(e instanceof A))throw new n("InvalidParameter",i);u.push(e)}}else{if(!f(o[0])){if(o[0]instanceof A)return c(t(o[0]),e.spatialReference);if(null===o[0])return null;throw new n("InvalidParameter",i)}for(const e of r(o[0].toArray()))if(null!==e){if(!(e instanceof A))throw new n("InvalidParameter",i);u.push(e)}}else for(const e of o)if(null!==e){if(!(e instanceof A))throw new n("InvalidParameter",i);u.push(e)}return 0===u.length?null:H.union.executeMany(u)})},G.difference=function(e,n){return K(e,n,(e,i,a)=>(a=r(a),P(a,n),null===a[0]?null:null===a[1]?t(a[0]):H.difference.execute(a[0],a[1])))},G.symmetricdifference=function(e,n){return K(e,n,(e,i,a)=>(a=r(a),P(a,n),null===a[0]&&null===a[1]?null:null===a[0]?t(a[1]):null===a[1]?t(a[0]):H.symmetricDifference.execute(a[0],a[1])))},G.clip=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,2,2,t),!(l[1]instanceof S)&&null!==l[1])throw new n("InvalidParameter",t);if(null===l[0])return null;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);return null===l[1]?null:H.clip.execute(l[0],l[1])})},G.cut=function(e,a){return K(e,a,(e,l,o)=>{if(o=r(o),i(o,2,2,a),!(o[1]instanceof q)&&null!==o[1])throw new n("InvalidParameter",a);if(null===o[0])return[];if(!(o[0]instanceof A))throw new n("InvalidParameter",a);return null===o[1]?[t(o[0])]:H.cut.execute(o[0],o[1])})},G.area=function(e,t){return K(e,t,(a,l,o)=>{i(o,1,2,t);let u=(o=r(o))[0];if((B(o[0])||f(o[0]))&&(u=s(o[0],e.spatialReference)),null===u)return 0;if(!(u instanceof A))throw new n("InvalidParameter",t);return b(u.spatialReference,D(o[1]),H.area.execute(u))})},G.areageodetic=function(e,t){return K(e,t,(a,l,o)=>{i(o,1,3,t);let u=(o=r(o))[0];(B(u)||f(u))&&(u=s(u,e.spatialReference));const c=D(o[1]),d=x(o[2]);if(null==u)return 0;if(!m(u))throw new n("InvalidParameter",t);return L(J,c,H.geodeticArea.execute(u,{curveType:d}))})},G.length=function(e,t){return K(e,t,(a,l,o)=>{i(o,1,2,t);let u=(o=r(o))[0];if((B(o[0])||f(o[0]))&&(u=d(o[0],e.spatialReference)),null===u)return 0;if(!(u instanceof A))throw new n("InvalidParameter",t);return b(u.spatialReference,M(o[1]),H.length.execute(u))})},G.length3d=function(e,t){return K(e,t,(a,l,o)=>{i(o,1,2,t);let u=(o=r(o))[0];if((B(o[0])||f(o[0]))&&(u=d(o[0],e.spatialReference)),null===u)return 0;if(!(u instanceof A))throw new n("InvalidParameter",t);return!0===u.hasZ?b(u.spatialReference,M(o[1]),y(u)):b(u.spatialReference,M(o[1]),H.length.execute(u))})},G.lengthgeodetic=function(e,t){return K(e,t,(a,l,o)=>{i(o,1,3,t);let u=(o=r(o))[0];(B(o[0])||f(o[0]))&&(u=d(o[0],e.spatialReference));const c=x(o[2]);if(null==u)return 0;if(null!=u&&!m(u))throw new n("InvalidParameter",t);const s=M(o[1]);return L(z,s,H.geodeticLength.execute(u,{curveType:c}))})},G.distance=function(e,t){return K(e,t,(a,l,o)=>{o=r(o),i(o,2,3,t);let u=o[0];if((B(o[0])||f(o[0]))&&(u=w(o[0],e.spatialReference)),!(u instanceof A))throw new n("InvalidParameter",t);let c=o[1];if((B(o[1])||f(o[1]))&&(c=w(o[1],e.spatialReference)),!(c instanceof A))throw new n("InvalidParameter",t);return b(u.spatialReference,M(o[2]),H.distance.execute(u,c))})},G.distancegeodetic=function(e,t){return K(e,t,(e,a,l)=>{l=r(l),i(l,2,4,t);const o=l[0];if(!(o instanceof k))throw new n("InvalidParameter",t);const u=l[1];if(!(u instanceof k))throw new n("InvalidParameter",t);const f=M(l[2]),c=x(l[3]),s=new q({paths:[],spatialReference:o.spatialReference});return s.addPath([o,u]),L(z,f,H.geodeticLength.execute(s,{curveType:c}))})},G.densify=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,2,3,t),null===l[0])return null;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);const o=h(l[1]);if(isNaN(o))throw new n("InvalidParameter",t);if(o<=0)throw new n("InvalidParameter",t);const u=T(M(l[2]),l[0].spatialReference,o);switch(l[0].type){case"polygon":case"polyline":case"extent":return H.densify.execute(l[0],u);default:return l[0]}})},G.densifygeodetic=function(e,t){return K(e,t,(e,a,l)=>{l=r(l),i(l,2,4,t);const o=l[0];if(null==o)return null;if(!m(o))throw new n("InvalidParameter",t);const u=h(l[1]);if(isNaN(u))throw new n("InvalidParameter",t);if(u<=0)throw new n("InvalidParameter",t);const f=M(l[2]),c=x(l[3]),s=L(f,z,u);switch(o.type){case"polygon":case"polyline":case"extent":return H.geodeticDensify.execute(o,s,{curveType:c});default:return o}})},G.generalize=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,2,4,t),null===l[0])return null;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);const o=h(l[1]);if(isNaN(o))throw new n("InvalidParameter",t);const u=T(M(l[3]),l[0].spatialReference,o);return H.generalize.execute(l[0],u,{removeDegenerateParts:p(g(l[2],!0))})})},G.buffer=function(e,a){return K(e,a,(e,l,o)=>{if(o=r(o),i(o,2,3,a),null===o[0])return null;if(!(o[0]instanceof A))throw new n("InvalidParameter",a);const u=h(o[1]);if(isNaN(u))throw new n("InvalidParameter",a);return 0===u?t(o[0]):H.buffer.execute(o[0],T(M(o[2]),o[0].spatialReference,u))})},G.buffergeodetic=function(e,a){return K(e,a,(e,l,o)=>{o=r(o),i(o,2,4,a);const u=o[0];if(null==u)return null;if(!m(u))throw new n("InvalidParameter",a);const f=h(o[1]);if(isNaN(f))throw new n("InvalidParameter",a);if(0===f)return t(u);const c=M(o[2]),s=x(o[3]);return H.geodesicBuffer.execute(u,L(c,z,f),{curveType:s})})},G.offset=function(e,t){return K(e,t,(e,a,l)=>{l=r(l),i(l,2,6,t);const o=l[0];if(null===o)return null;if(!(o instanceof U||o instanceof q))throw new n("InvalidParameter",t);const u=h(l[1]);if(isNaN(u))throw new n("InvalidParameter",t);const f=l[2],c=I(l[3]),s=h(g(l[4],10));if(isNaN(s))throw new n("InvalidParameter",t);const m=h(g(l[5],0));if(isNaN(m))throw new n("InvalidParameter",t);return H.executeOffset(o,u,f,c,s,m)})},G.rotate=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,2,3,t),null===l[0])return null;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);const o=l[0]instanceof S?U.fromExtent(l[0]):l[0],u=h(l[1]);if(isNaN(u))throw new n("InvalidParameter",t);const f=g(l[2],null);if(null===f){const e="point"===o.type?o:o.extent?.center;return H.rotate(o,u,e?.x,e?.y)}if(f instanceof k)return H.rotate(o,u,f.x,f.y);throw new n("InvalidParameter",t)})},G.centroid=function(e,t){return K(e,t,(e,t,a)=>{if(a=r(a),i(a,1,2,t),null===a[0])return null;const l=R(a[1]);let o=a[0];if((B(a[0])||f(a[0]))&&(o="geometric"===l?w(a[0],e.spatialReference):s(a[0],e.spatialReference),null===o))return null;if(!(o instanceof A))throw new n("InvalidParameter",t);return"geometric"===l?H.centroid.execute(o):H.labelPoint.execute(o)})},G.measuretocoordinate=function(e,n){return K(e,n,N)},G.pointtocoordinate=function(e,n){return K(e,n,j)},G.distancetocoordinate=function(e,n){return K(e,n,O)},G.multiparttosinglepart=function(e,a){return K(e,a,(l,o,u)=>{if(u=r(u),i(u,1,1,a),null===u[0])return null;if(!(u[0]instanceof A))throw new n("InvalidParameter",a);if(u[0]instanceof k)return[c(t(u[0]),e.spatialReference)];if(u[0]instanceof S)return[c(t(u[0]),e.spatialReference)];const f=H.simplify.execute(u[0]);if(f instanceof U){const e=[],n=[];for(let t=0;t<f.rings.length;t++)if(f.isClockwise(f.rings[t])){const n=C({rings:[f.rings[t]],hasZ:!0===f.hasZ,hasM:!0===f.hasM,spatialReference:f.spatialReference.toJSON()});e.push(n)}else n.push({ring:f.rings[t],pt:f.getPoint(t,0)});for(let t=0;t<n.length;t++)for(let r=0;r<e.length;r++)if(e[r].contains(n[t].pt)){e[r].addRing(n[t].ring);break}return e}if(f instanceof q){const e=[];for(let n=0;n<f.paths.length;n++){const t=C({paths:[f.paths[n]],hasZ:!0===f.hasZ,hasM:!0===f.hasM,spatialReference:f.spatialReference.toJSON()});e.push(t)}return e}if(u[0]instanceof Z){const n=[],r=c(t(u[0]),e.spatialReference);for(let e=0;e<r.points.length;e++)n.push(r.getPoint(e));return n}return null})},G.isselfintersecting=function(e,n){return K(e,n,(e,n,t)=>{i(t,1,1,n);let a=(t=r(t))[0];if((B(t[0])||f(t[0]))&&(a=d(t[0],e.spatialReference)),a instanceof Z){const e=a.points;for(let n=0;n<e.length;n++)for(let t=n+1;t<e.length;t++)if(E(e[n],e[t]))return!0;return!1}return(a instanceof q||a instanceof U)&&H.isSelfIntersecting(a)})},G.issimple=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,1,1,t),null===l[0])return!0;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);return H.simplify.isSimple(l[0])})},G.simplify=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,1,1,t),null===l[0])return null;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);return H.simplify.execute(l[0])})},G.convexhull=function(e,t){return K(e,t,(e,a,l)=>{if(l=r(l),i(l,1,1,t),null===l[0])return null;if(!(l[0]instanceof A))throw new n("InvalidParameter",t);return H.convexHull.execute(l[0])})},G.nearestcoordinate=function(t,a){return K(t,a,(l,o,u)=>{if(u=r(u),i(u,2,2,a),!(u[0]instanceof A||null===u[0]))throw new n("InvalidParameter",a);if(!(u[1]instanceof k||null===u[1]))throw new n("InvalidParameter",a);if(null===u[0]||null===u[1])return null;const f=u[0]instanceof S?U.fromExtent(u[0]):u[0],c=H.proximity.getNearestCoordinate(f,u[1],{calculateLeftRightSide:!0});return null===c||c.isEmpty?null:e.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:0===c.distance?"straddle":c.isRightSide?"right":"left"},v(t),!1,!0)})},G.nearestvertex=function(t,a){return K(t,a,(l,o,u)=>{if(u=r(u),i(u,2,2,a),!(u[0]instanceof A||null===u[0]))throw new n("InvalidParameter",a);if(!(u[1]instanceof k||null===u[1]))throw new n("InvalidParameter",a);if(null===u[0]||null===u[1])return null;const f=u[0]instanceof S?U.fromExtent(u[0]):u[0],c=H.executeNearestVertex(f,u[1]);return null==c?null:e.convertObjectToArcadeDictionary({coordinate:c.coordinate,distance:c.distance,sideOfLine:c.sideOfLine},v(t),!1,!0)})}}export{G as loadOperators,K as registerFunctions};
2
+ import e from"../Dictionary.js";import{ArcadeExecutionError as n}from"../executionError.js";import{cloneGeometry as t}from"../kernel.js";import{H as r,B as i,e as a,n as l,o,s as u,g as f,J as s,K as c,f as m,L as d,M as w,r as p,N as h,O as g}from"../../chunks/languageUtils.js";import{commonRelationsCheck as v,toCurveType as P,planarLength3D as x,toOffsetJoinType as I,toCentroidAlgorithm as y,measureToCoordinateFunc as R,pointToCoordinateFunc as N,distanceToCoordinateFunc as j}from"../geometry/functions.js";import{convertFromSpatialReferenceUnit as M,toAreaUnit as b,convert as O,toLengthUnit as _,convertToSpatialReferenceUnit as L}from"../geometry/unitConversion.js";import{equals as E}from"../../core/arrayUtils.js";import S from"../../geometry/Extent.js";import D from"../../geometry/Geometry.js";import T from"../../geometry/Multipoint.js";import Z from"../../geometry/Point.js";import k from"../../geometry/Polygon.js";import U from"../../geometry/Polyline.js";import{fromJSON as q}from"../../geometry/support/jsonUtils.js";import{squareMeters as A,meters as C}from"../geometry/extendedUnitData.js";import{isArray as J}from"../../support/guards.js";let z;async function B(){null==z&&(z=await import("../geometry/operators.js"),await z.loadAll())}function H(B,H){B.disjoint=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null===i[0]||null===i[1]||z.disjoint.execute(i[0],i[1])))},B.intersects=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null!==i[0]&&null!==i[1]&&z.intersects.execute(i[0],i[1])))},B.touches=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null!==i[0]&&null!==i[1]&&z.touches.execute(i[0],i[1])))},B.crosses=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null!==i[0]&&null!==i[1]&&z.crosses.execute(i[0],i[1])))},B.within=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null!==i[0]&&null!==i[1]&&z.within.execute(i[0],i[1])))},B.contains=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null!==i[0]&&null!==i[1]&&z.contains.execute(i[0],i[1])))},B.overlaps=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null!==i[0]&&null!==i[1]&&z.overlaps.execute(i[0],i[1])))},B.equals=function(e,n){return H(e,n,(e,t,r)=>(i(r,2,2,n),r[0]===r[1]||(r[0]instanceof D&&r[1]instanceof D?z.equals.execute(r[0],r[1]):(a(r[0])&&a(r[1])||l(r[0])&&l(r[1])||!(!o(r[0])||!o(r[1])))&&r[0].equals(r[1]))))},B.relate=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,3,3,t),l[0]instanceof D&&l[1]instanceof D)return z.relate.execute(l[0],l[1],u(l[2]));if(l[0]instanceof D&&null===l[1])return!1;if(l[1]instanceof D&&null===l[0])return!1;if(null===l[0]&&null===l[1])return!1;throw new n("InvalidParameter",t)})},B.intersection=function(e,n){return H(e,n,(e,t,i)=>(i=r(i),v(i,n),null===i[0]||null===i[1]?null:z.intersection.execute(i[0],i[1])))},B.union=function(e,i){return H(e,i,(a,l,o)=>{if(0===(o=r(o)).length)throw new n("WrongNumberOfParameters",i);const u=[];if(1===o.length)if(J(o[0])){for(const e of r(o[0]))if(null!==e){if(!(e instanceof D))throw new n("InvalidParameter",i);u.push(e)}}else{if(!f(o[0])){if(o[0]instanceof D)return s(t(o[0]),e.spatialReference);if(null===o[0])return null;throw new n("InvalidParameter",i)}for(const e of r(o[0].toArray()))if(null!==e){if(!(e instanceof D))throw new n("InvalidParameter",i);u.push(e)}}else for(const e of o)if(null!==e){if(!(e instanceof D))throw new n("InvalidParameter",i);u.push(e)}return 0===u.length?null:z.union.executeMany(u)})},B.difference=function(e,n){return H(e,n,(e,i,a)=>(a=r(a),v(a,n),null===a[0]?null:null===a[1]?t(a[0]):z.difference.execute(a[0],a[1])))},B.symmetricdifference=function(e,n){return H(e,n,(e,i,a)=>(a=r(a),v(a,n),null===a[0]&&null===a[1]?null:null===a[0]?t(a[1]):null===a[1]?t(a[0]):z.symmetricDifference.execute(a[0],a[1])))},B.clip=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,2,2,t),!(l[1]instanceof S)&&null!==l[1])throw new n("InvalidParameter",t);if(null===l[0])return null;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);return null===l[1]?null:z.clip.execute(l[0],l[1])})},B.cut=function(e,a){return H(e,a,(e,l,o)=>{if(o=r(o),i(o,2,2,a),!(o[1]instanceof U)&&null!==o[1])throw new n("InvalidParameter",a);if(null===o[0])return[];if(!(o[0]instanceof D))throw new n("InvalidParameter",a);return null===o[1]?[t(o[0])]:z.cut.execute(o[0],o[1])})},B.area=function(e,t){return H(e,t,(a,l,o)=>{i(o,1,2,t);let u=(o=r(o))[0];if((J(o[0])||f(o[0]))&&(u=c(o[0],e.spatialReference)),null===u)return 0;if(!(u instanceof D))throw new n("InvalidParameter",t);return M(u.spatialReference,b(o[1]),z.area.execute(u))})},B.areageodetic=function(e,t){return H(e,t,(a,l,o)=>{i(o,1,3,t);let u=(o=r(o))[0];(J(u)||f(u))&&(u=c(u,e.spatialReference));const s=b(o[1]),d=P(o[2]);if(null==u)return 0;if(!m(u))throw new n("InvalidParameter",t);return O(A,s,z.geodeticArea.execute(u,{curveType:d}))})},B.length=function(e,t){return H(e,t,(a,l,o)=>{i(o,1,2,t);let u=(o=r(o))[0];if((J(o[0])||f(o[0]))&&(u=d(o[0],e.spatialReference)),null===u)return 0;if(!(u instanceof D))throw new n("InvalidParameter",t);return M(u.spatialReference,_(o[1]),z.length.execute(u))})},B.length3d=function(e,t){return H(e,t,(a,l,o)=>{i(o,1,2,t);let u=(o=r(o))[0];if((J(o[0])||f(o[0]))&&(u=d(o[0],e.spatialReference)),null===u)return 0;if(!(u instanceof D))throw new n("InvalidParameter",t);return!0===u.hasZ?M(u.spatialReference,_(o[1]),x(u)):M(u.spatialReference,_(o[1]),z.length.execute(u))})},B.lengthgeodetic=function(e,t){return H(e,t,(a,l,o)=>{i(o,1,3,t);let u=(o=r(o))[0];(J(o[0])||f(o[0]))&&(u=d(o[0],e.spatialReference));const s=P(o[2]);if(null==u)return 0;if(null!=u&&!m(u))throw new n("InvalidParameter",t);const c=_(o[1]);return O(C,c,z.geodeticLength.execute(u,{curveType:s}))})},B.distance=function(e,t){return H(e,t,(a,l,o)=>{o=r(o),i(o,2,3,t);let u=o[0];if((J(o[0])||f(o[0]))&&(u=w(o[0],e.spatialReference)),!(u instanceof D))throw new n("InvalidParameter",t);let s=o[1];if((J(o[1])||f(o[1]))&&(s=w(o[1],e.spatialReference)),!(s instanceof D))throw new n("InvalidParameter",t);return M(u.spatialReference,_(o[2]),z.distance.execute(u,s))})},B.distancegeodetic=function(e,t){return H(e,t,(e,a,l)=>{l=r(l),i(l,2,4,t);const o=l[0];if(!(o instanceof Z))throw new n("InvalidParameter",t);const u=l[1];if(!(u instanceof Z))throw new n("InvalidParameter",t);const f=_(l[2]),s=P(l[3]),c=new U({paths:[],spatialReference:o.spatialReference});return c.addPath([o,u]),O(C,f,z.geodeticLength.execute(c,{curveType:s}))})},B.densify=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,2,3,t),null===l[0])return null;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);const o=p(l[1]);if(isNaN(o))throw new n("InvalidParameter",t);if(o<=0)throw new n("InvalidParameter",t);const u=L(_(l[2]),l[0].spatialReference,o);switch(l[0].type){case"polygon":case"polyline":case"extent":return z.densify.execute(l[0],u);default:return l[0]}})},B.densifygeodetic=function(e,t){return H(e,t,(e,a,l)=>{l=r(l),i(l,2,4,t);const o=l[0];if(null==o)return null;if(!m(o))throw new n("InvalidParameter",t);const u=p(l[1]);if(isNaN(u))throw new n("InvalidParameter",t);if(u<=0)throw new n("InvalidParameter",t);const f=_(l[2]),s=P(l[3]),c=O(f,C,u);switch(o.type){case"polygon":case"polyline":case"extent":return z.geodeticDensify.execute(o,c,{curveType:s});default:return o}})},B.generalize=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,2,4,t),null===l[0])return null;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);const o=p(l[1]);if(isNaN(o))throw new n("InvalidParameter",t);const u=L(_(l[3]),l[0].spatialReference,o);return z.generalize.execute(l[0],u,{removeDegenerateParts:h(g(l[2],!0))})})},B.buffer=function(e,a){return H(e,a,(e,l,o)=>{if(o=r(o),i(o,2,3,a),null===o[0])return null;if(!(o[0]instanceof D))throw new n("InvalidParameter",a);const u=p(o[1]);if(isNaN(u))throw new n("InvalidParameter",a);return 0===u?t(o[0]):z.buffer.execute(o[0],L(_(o[2]),o[0].spatialReference,u))})},B.buffergeodetic=function(e,a){return H(e,a,(e,l,o)=>{o=r(o),i(o,2,4,a);const u=o[0];if(null==u)return null;if(!m(u))throw new n("InvalidParameter",a);const f=p(o[1]);if(isNaN(f))throw new n("InvalidParameter",a);if(0===f)return t(u);const s=_(o[2]),c=P(o[3]);return z.geodesicBuffer.execute(u,O(s,C,f),{curveType:c})})},B.offset=function(e,t){return H(e,t,(e,a,l)=>{l=r(l),i(l,2,6,t);const o=l[0];if(null===o)return null;if(!(o instanceof k||o instanceof U))throw new n("InvalidParameter",t);const u=p(l[1]);if(isNaN(u))throw new n("InvalidParameter",t);const f=l[2],s=I(l[3]),c=p(g(l[4],10));if(isNaN(c))throw new n("InvalidParameter",t);const m=p(g(l[5],0));if(isNaN(m))throw new n("InvalidParameter",t);return z.executeOffset(o,u,f,s,c,m)})},B.rotate=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,2,3,t),null===l[0])return null;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);const o=l[0]instanceof S?k.fromExtent(l[0]):l[0],u=p(l[1]);if(isNaN(u))throw new n("InvalidParameter",t);const f=g(l[2],null);if(null===f){const e="point"===o.type?o:o.extent?.center;return z.rotate(o,u,e?.x,e?.y)}if(f instanceof Z)return z.rotate(o,u,f.x,f.y);throw new n("InvalidParameter",t)})},B.centroid=function(e,t){return H(e,t,(e,t,a)=>{if(a=r(a),i(a,1,2,t),null===a[0])return null;const l=y(a[1]);let o=a[0];if((J(a[0])||f(a[0]))&&(o="geometric"===l?w(a[0],e.spatialReference):c(a[0],e.spatialReference),null===o))return null;if(!(o instanceof D))throw new n("InvalidParameter",t);return"geometric"===l?z.centroid.execute(o):z.labelPoint.execute(o)})},B.measuretocoordinate=function(e,n){return H(e,n,R)},B.pointtocoordinate=function(e,n){return H(e,n,N)},B.distancetocoordinate=function(e,n){return H(e,n,j)},B.multiparttosinglepart=function(e,a){return H(e,a,(l,o,u)=>{if(u=r(u),i(u,1,1,a),null===u[0])return null;if(!(u[0]instanceof D))throw new n("InvalidParameter",a);if(u[0]instanceof Z)return[s(t(u[0]),e.spatialReference)];if(u[0]instanceof S)return[s(t(u[0]),e.spatialReference)];const f=z.simplify.execute(u[0]);if(f instanceof k){const e=[],n=[];for(let t=0;t<f.rings.length;t++)if(f.isClockwise(f.rings[t])){const n=q({rings:[f.rings[t]],hasZ:!0===f.hasZ,hasM:!0===f.hasM,spatialReference:f.spatialReference.toJSON()});e.push(n)}else n.push({ring:f.rings[t],pt:f.getPoint(t,0)});for(let t=0;t<n.length;t++)for(let r=0;r<e.length;r++)if(e[r].contains(n[t].pt)){e[r].addRing(n[t].ring);break}return e}if(f instanceof U){const e=[];for(let n=0;n<f.paths.length;n++){const t=q({paths:[f.paths[n]],hasZ:!0===f.hasZ,hasM:!0===f.hasM,spatialReference:f.spatialReference.toJSON()});e.push(t)}return e}if(u[0]instanceof T){const n=[],r=s(t(u[0]),e.spatialReference);for(let e=0;e<r.points.length;e++)n.push(r.getPoint(e));return n}return null})},B.isselfintersecting=function(e,n){return H(e,n,(e,n,t)=>{i(t,1,1,n);let a=(t=r(t))[0];if((J(t[0])||f(t[0]))&&(a=d(t[0],e.spatialReference)),a instanceof T){const e=a.points;for(let n=0;n<e.length;n++)for(let t=n+1;t<e.length;t++)if(E(e[n],e[t]))return!0;return!1}return(a instanceof U||a instanceof k)&&z.isSelfIntersecting(a)})},B.issimple=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,1,1,t),null===l[0])return!0;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);return z.simplify.isSimple(l[0])})},B.simplify=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,1,1,t),null===l[0])return null;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);return z.simplify.execute(l[0])})},B.convexhull=function(e,t){return H(e,t,(e,a,l)=>{if(l=r(l),i(l,1,1,t),null===l[0])return null;if(!(l[0]instanceof D))throw new n("InvalidParameter",t);return z.convexHull.execute(l[0])})},B.nearestcoordinate=function(t,a){return H(t,a,(t,l,o)=>{if(o=r(o),i(o,2,2,a),!(o[0]instanceof D||null===o[0]))throw new n("InvalidParameter",a);if(!(o[1]instanceof Z||null===o[1]))throw new n("InvalidParameter",a);if(null===o[0]||null===o[1])return null;const u=o[0]instanceof S?k.fromExtent(o[0]):o[0],f=z.proximity.getNearestCoordinate(u,o[1],{calculateLeftRightSide:!0});return null===f||f.isEmpty?null:e.createMutable({__proto__:null,coordinate:f.coordinate,distance:f.distance,sideOfLine:0===f.distance?"straddle":f.isRightSide?"right":"left"})})},B.nearestvertex=function(t,a){return H(t,a,(t,l,o)=>{if(o=r(o),i(o,2,2,a),!(o[0]instanceof D||null===o[0]))throw new n("InvalidParameter",a);if(!(o[1]instanceof Z||null===o[1]))throw new n("InvalidParameter",a);if(null===o[0]||null===o[1])return null;const u=o[0]instanceof S?k.fromExtent(o[0]):o[0],f=z.executeNearestVertex(u,o[1]);return null==f?null:e.createMutable({__proto__:null,coordinate:f.coordinate,distance:f.distance,sideOfLine:f.sideOfLine})})}}export{B as loadOperators,H as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import e from"../../config.js";import r from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n}from"../executionError.js";import{B as o,s as a,o as i,O as s,P as p,e as c,f as l,g as f,n as u,h as m}from"../../chunks/languageUtils.js";import{getPortal as d}from"../portalUtils.js";import h from"../../geometry/Geometry.js";import{load as g,project as w,isLoaded as y}from"../../geometry/projectionUtils.js";import j from"../../geometry/SpatialReference.js";import{webMercatorToGeographic as S,geographicToWebMercator as R}from"../../geometry/support/webMercatorUtils.js";import G from"../../portal/PortalItem.js";import{project as v}from"../../rest/geometryService/project.js";import x from"../../rest/knowledgeGraph/Entity.js";import k from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import P from"../../rest/knowledgeGraph/ObjectValue.js";import b from"../../rest/knowledgeGraph/Path.js";import I from"../../rest/knowledgeGraph/Relationship.js";import W from"../../rest/support/ProjectParameters.js";import{isString as T,isArray as D,isNumber as U,isDate as q}from"../../support/guards.js";let A=null;async function N(r){const t=e.geometryServiceUrl??"";if(!t){y()||await g();for(const e of r)e.container[e.indexer]=w(e.container[e.indexer],j.WGS84);return}const n=r.map(e=>e.container[e.indexer]),o=new W({geometries:n,outSpatialReference:j.WGS84}),a=await v(t,o);for(let e=0;e<a.length;e++){const t=r[e];t.container[t.indexer]=a[e]}}async function F(e,r){const t=new G({portal:e,id:r});return await t.load(),null===A&&(A=await import("../../rest/knowledgeGraphService.js")),await A.fetchKnowledgeGraph(t.url)}function J(e,r,t,n,o){if(null===e)return null;if(T(e)||U(e))return e;if(c(e))return e.toJSDate();if(c(e))return e.toJSDate();if(l(e))return e.toStorageFormat();if(f(e))return e.toStorageString();if(u(e)){const a={};for(const i of e.keys())a[i]=J(e.field(i),r,t,n,o),a[i]instanceof h&&o.push({container:a,indexer:i});return a}if(D(e)){const a=e.map(e=>J(e,r,t,n,o));for(let e=0;e<a.length;e++)a[e]instanceof h&&o.push({container:a,indexer:e});return a}return m(e)?e.spatialReference.isWGS84?e:e.spatialReference.isWebMercator&&r?S(e):e:void 0}function M(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return R(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new n("WrongSpatialReference",null)}function Q(e,r){if(!e)return null;const t={};for(const n in e)t[n]=B(e[n],r);return t}function B(e,r){return null===e?null:D(e)?e.map(e=>B(e,r)):e instanceof x?{graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:Q(e.properties,r)}:e instanceof P?{graphType:"object",properties:Q(e.properties,r)}:e instanceof I?{graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:Q(e.properties,r)}:e instanceof b?{graphType:"path",path:e.path?e.path.map(e=>B(e,r)):null}:m(e)?M(e,r):T(e)||U(e)||q(e)?e:null}function E(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(t,i){return e.standardFunctionAsync(t,i,(e,s,p)=>{if(o(p,2,2,i),!(p[0]instanceof r))throw new n("PortalRequired",i);const c=a(p[1]);return F(d(t,p[0]),c)})},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,a){return e.standardFunctionAsync(r,a,async(e,c,l)=>{o(l,2,4,a);const f=l[0];if(!i(f))throw new n("InvalidParameter",a);const u=l[1];if(!T(u))throw new n("InvalidParameter",a);null===A&&(A=await import("../../rest/knowledgeGraphService.js"));let m=null;const d=s(l[2],null);if(!(d instanceof t||null===d))throw new n("InvalidParameter",a);if(d){let e=[];m=J(d,!0,!1,r,e),e=e.filter(e=>!e.container[e.indexer].spatialReference.isWGS84),e.length>0&&await N(e)}const h=s(l[3],!1),g=new k({openCypherQuery:u,bindParameters:m,provenanceBehavior:h?"include":"exclude"});(f?.serviceDefinition?.currentVersion??11.3)>11.2&&(g.outputSpatialReference=r.spatialReference);const w=(await A.executeQueryStreaming(f,g)).resultRowsStream.getReader(),y=[];try{for(;;){const{done:e,value:t}=await w.read();if(e)break;if(D(t))for(const n of t)y.push(B(n,r));else{const e=[];for(const n of t)e.push(B(t[n],r));y.push(e)}}}catch(j){throw j}return t.convertJsonToArcade(y,p(r),!1,!0)})},e.signatures.push({name:"querygraph",min:2,max:4}))}export{E as registerFunctions};
2
+ import e from"../../config.js";import{ArcadeDate as r}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as o}from"../executionError.js";import{B as a,s as i,m as s,O as p,e as l,o as c,n as u,l as f,f as m,T as g}from"../../chunks/languageUtils.js";import{getPortal as h}from"../portalUtils.js";import d from"../../geometry/Geometry.js";import{load as y,project as w,isLoaded as j}from"../../geometry/projectionUtils.js";import S from"../../geometry/SpatialReference.js";import{webMercatorToGeographic as b,geographicToWebMercator as R}from"../../geometry/support/webMercatorUtils.js";import _ from"../../portal/PortalItem.js";import{project as G}from"../../rest/geometryService/project.js";import k from"../../rest/knowledgeGraph/Entity.js";import v from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import A from"../../rest/knowledgeGraph/ObjectValue.js";import P from"../../rest/knowledgeGraph/Path.js";import I from"../../rest/knowledgeGraph/Relationship.js";import M from"../../rest/support/ProjectParameters.js";import{isString as T,isNumber as W,isArray as D}from"../../support/guards.js";let x=null;async function U(r){const t=e.geometryServiceUrl??"";if(!t){j()||await y();for(const e of r)e.set(w(e.get(),S.WGS84));return}const n=r.map(e=>e.get()),o=new M({geometries:n,outSpatialReference:S.WGS84}),a=await G(t,o);for(let e=0;e<a.length;e++)r[e].set(a[e])}async function q(e,r){const t=new _({portal:e,id:r});return await t.load(),null===x&&(x=await import("../../rest/knowledgeGraphService.js")),await x.fetchKnowledgeGraph(t.url)}function N(e,r,t,n){if(null===e)return null;if(T(e)||W(e))return e;if(l(e))return e.toJSDate();if(l(e))return e.toJSDate();if(c(e))return e.toStorageFormat();if(u(e))return e.toStorageString();if(f(e)){const o={};for(const a of e.keys())o[a]=N(e.field(a),r,t,n),o[a]instanceof d&&n.push({get:()=>o[a],set:e=>{o[a]=e}});return o}if(D(e)){const o=e.map(e=>N(e,r,t,n));for(let e=0;e<o.length;e++)o[e]instanceof d&&n.push({get:()=>o[e],set:r=>{o[e]=r}});return o}return m(e)?e.spatialReference.isWGS84?e:e.spatialReference.isWebMercator&&r?b(e):e:void 0}function F(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return R(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new o("WrongSpatialReference",null)}function J(e,r){if(!e)return null;const t=Object.create(null);for(const n in e)t[n]=O(e[n],r);return n.createMutable(t)}function O(e,t){return null===e?null:Array.isArray(e)?e.map(e=>O(e,t)):e instanceof k?n.createMutable({__proto__:null,graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:J(e.properties,t)}):e instanceof A?n.createMutable({__proto__:null,graphType:"object",properties:J(e.properties,t)}):e instanceof I?n.createMutable({__proto__:null,graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:J(e.properties,t)}):e instanceof P?n.createMutable({__proto__:null,graphType:"path",path:e.path?e.path.map(e=>O(e,t)):null}):e instanceof d?F(e,t):"string"==typeof e||"number"==typeof e?e:e instanceof Date?r.dateJSAndZoneToArcadeDate(e,g(t)):null}function Q(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(r,n){return e.standardFunctionAsync(r,n,(e,s,p)=>{if(a(p,2,2,n),!(p[0]instanceof t))throw new o("PortalRequired",n);const l=i(p[1]);return q(h(r,p[0]),l)})},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,t){return e.standardFunctionAsync(r,t,async(e,i,l)=>{a(l,2,4,t);const c=l[0];if(!s(c))throw new o("InvalidParameter",t);const u=l[1];if(!T(u))throw new o("InvalidParameter",t);null===x&&(x=await import("../../rest/knowledgeGraphService.js"));let f=null;const m=p(l[2],null);if(!(m instanceof n||null===m))throw new o("InvalidParameter",t);if(m){let e=[];f=N(m,!0,!1,e),e=e.filter(e=>!e.get().spatialReference.isWGS84),e.length>0&&await U(e)}const g=p(l[3],!1),h=new v({openCypherQuery:u,bindParameters:f,provenanceBehavior:g?"include":"exclude"});(c?.serviceDefinition?.currentVersion??11.3)>11.2&&(h.outputSpatialReference=r.spatialReference);const d=(await x.executeQueryStreaming(c,h)).resultRowsStream.getReader(),y=[];try{for(;;){const{done:e,value:t}=await d.read();if(e)break;if(Array.isArray(t))for(const n of t)y.push(O(n,r));else{const e=[];for(const n of t)e.push(O(t[n],r));y.push(e)}}}catch(w){throw w}return y})},e.signatures.push({name:"querygraph",min:2,max:4}))}export{Q as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{isEmpty as r}from"../containerUtils.js";import{ArcadeExecutionError as n}from"../executionError.js";import{B as t,e as u,g as e,f as o,a1 as i,r as a,O as s,Q as f,N as c,j as m}from"../../chunks/languageUtils.js";import{decimalAdjust as l}from"../../core/mathUtils.js";import{parse as h}from"../../core/number.js";import{isNumber as N,isBoolean as p,isArray as M,isString as b}from"../../support/guards.js";function g(g,d){function j(r,n,t){const u=a(r);return isNaN(u)?u:isNaN(n)||isNaN(t)||n>t?NaN:u<n?n:u>t?t:u}g.number=function(r,n){return d(r,n,(r,a,s)=>{t(s,1,2,n);const f=s[0];if(N(f))return f;if(null===f)return 0;if(u(f)||e(f)||o(f))return f.toNumber();if(p(f))return Number(f);if(M(f))return NaN;if(""===f)return Number(f);if(void 0===f)return Number(f);if(b(f)){if(void 0!==s[1]){let r=i(s[1],"‰","");return r=i(r,"¤",""),h(f,{pattern:r})}return Number(f.trim())}return Number(f)})},g.abs=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.abs(a(e[0]))))},g.acos=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.acos(a(e[0]))))},g.asin=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.asin(a(e[0]))))},g.atan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.atan(a(e[0]))))},g.atan2=function(r,n){return d(r,n,(r,u,e)=>(t(e,2,2,n),Math.atan2(a(e[0]),a(e[1]))))},g.ceil=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("ceil",a(e[0]),-1*r)}return Math.ceil(a(e[0]))})},g.round=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("round",a(e[0]),-1*r)}return Math.round(a(e[0]))})},g.floor=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("floor",a(e[0]),-1*r)}return Math.floor(a(e[0]))})},g.cos=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.cos(a(e[0]))))},g.isnan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),"number"==typeof e[0]&&isNaN(e[0])))},g.exp=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.exp(a(e[0]))))},g.log=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.log(a(e[0]))))},g.pow=function(r,n){return d(r,n,(r,u,e)=>(t(e,2,2,n),a(e[0])**a(e[1])))},g.random=function(r,n){return d(r,n,(r,u,e)=>(t(e,0,0,n),Math.random()))},g.sin=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.sin(a(e[0]))))},g.sqrt=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.sqrt(a(e[0]))))},g.tan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.tan(a(e[0]))))},g.isempty=function(u,e){return d(u,e,(u,e,o)=>{if(t(o,1,2,e),o.length>=2&&!p(o[1]))throw new n("InvalidParameter",e);return s(o[1],!1)?r(o[0]):f(o[0])})},g.boolean=function(r,n){return d(r,n,(r,u,e)=>{t(e,1,1,n);const o=e[0];return c(o)})},g.constrain=function(r,n){return d(r,n,(r,u,e)=>{t(e,3,3,n);const o=a(e[1]),i=a(e[2]);if(M(e[0])){const r=[];for(const n of e[0])r.push(j(n,o,i));return r}if(m(e[0])){const r=[];for(let n=0;n<e[0].length();n++)r.push(j(e[0].get(n),o,i));return r}return j(e[0],o,i)})}}export{g as registerFunctions};
2
+ import{isEmpty as r}from"../containerUtils.js";import{ArcadeExecutionError as n}from"../executionError.js";import{B as t,e as u,n as e,o,a1 as i,r as a,O as s,P as f,N as c,g as m}from"../../chunks/languageUtils.js";import{decimalAdjust as l}from"../../core/mathUtils.js";import{parse as h}from"../../core/number.js";import{isNumber as N,isBoolean as p,isArray as M,isString as b}from"../../support/guards.js";function g(g,d){function j(r,n,t){const u=a(r);return isNaN(u)?u:isNaN(n)||isNaN(t)||n>t?NaN:u<n?n:u>t?t:u}g.number=function(r,n){return d(r,n,(r,a,s)=>{t(s,1,2,n);const f=s[0];if(N(f))return f;if(null===f)return 0;if(u(f)||e(f)||o(f))return f.toNumber();if(p(f))return Number(f);if(M(f))return NaN;if(""===f)return Number(f);if(void 0===f)return Number(f);if(b(f)){if(void 0!==s[1]){let r=i(s[1],"‰","");return r=i(r,"¤",""),h(f,{pattern:r})}return Number(f.trim())}return Number(f)})},g.abs=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.abs(a(e[0]))))},g.acos=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.acos(a(e[0]))))},g.asin=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.asin(a(e[0]))))},g.atan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.atan(a(e[0]))))},g.atan2=function(r,n){return d(r,n,(r,u,e)=>(t(e,2,2,n),Math.atan2(a(e[0]),a(e[1]))))},g.ceil=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("ceil",a(e[0]),-1*r)}return Math.ceil(a(e[0]))})},g.round=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("round",a(e[0]),-1*r)}return Math.round(a(e[0]))})},g.floor=function(r,n){return d(r,n,(r,u,e)=>{if(t(e,1,2,n),2===e.length){let r=a(e[1]);return isNaN(r)&&(r=0),l("floor",a(e[0]),-1*r)}return Math.floor(a(e[0]))})},g.cos=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.cos(a(e[0]))))},g.isnan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),"number"==typeof e[0]&&isNaN(e[0])))},g.exp=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.exp(a(e[0]))))},g.log=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.log(a(e[0]))))},g.pow=function(r,n){return d(r,n,(r,u,e)=>(t(e,2,2,n),a(e[0])**a(e[1])))},g.random=function(r,n){return d(r,n,(r,u,e)=>(t(e,0,0,n),Math.random()))},g.sin=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.sin(a(e[0]))))},g.sqrt=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.sqrt(a(e[0]))))},g.tan=function(r,n){return d(r,n,(r,u,e)=>(t(e,1,1,n),Math.tan(a(e[0]))))},g.isempty=function(u,e){return d(u,e,(u,e,o)=>{if(t(o,1,2,e),o.length>=2&&!p(o[1]))throw new n("InvalidParameter",e);return s(o[1],!1)?r(o[0]):f(o[0])})},g.boolean=function(r,n){return d(r,n,(r,u,e)=>{t(e,1,1,n);const o=e[0];return c(o)})},g.constrain=function(r,n){return d(r,n,(r,u,e)=>{t(e,3,3,n);const o=a(e[1]),i=a(e[2]);if(M(e[0])){const r=[];for(const n of e[0])r.push(j(n,o,i));return r}if(m(e[0])){const r=[];for(let n=0;n<e[0].length();n++)r.push(j(e[0].get(n),o,i));return r}return j(e[0],o,i)})}}export{g as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{ArcadeExecutionError as n}from"../executionError.js";import{B as r,j as t,n as e}from"../../chunks/languageUtils.js";import{calculateStat as u}from"./fieldStats.js";import{isArray as i,isString as o}from"../../support/guards.js";function f(n,r){if(1===r.length){if(i(r[0]))return u(n,r[0],-1);if(t(r[0]))return u(n,r[0].toArray(),-1)}return u(n,r,-1)}function a(u,a){u.stdev=function(n,r){return a(n,r,(n,r,t)=>f("stdev",t))},u.variance=function(n,r){return a(n,r,(n,r,t)=>f("variance",t))},u.average=function(n,r){return a(n,r,(n,r,t)=>f("mean",t))},u.mean=function(n,r){return a(n,r,(n,r,t)=>f("mean",t))},u.sum=function(n,r){return a(n,r,(n,r,t)=>f("sum",t))},u.min=function(n,r){return a(n,r,(n,r,t)=>f("min",t))},u.max=function(n,r){return a(n,r,(n,r,t)=>f("max",t))},u.distinct=function(n,r){return a(n,r,(n,r,t)=>f("distinct",t))},u.count=function(u,f){return a(u,f,(u,a,c)=>{if(r(c,1,1,f),null==c[0])return 0;if(i(c[0])||o(c[0]))return c[0].length;if(t(c[0]))return c[0].length();if(e(c[0]))return c[0].entryCount();throw new n("InvalidParameter",f)})}}export{a as registerFunctions};
2
+ import{ArcadeExecutionError as n}from"../executionError.js";import{B as r,g as t,l as e}from"../../chunks/languageUtils.js";import{calculateStat as u}from"./fieldStats.js";import{isArray as i,isString as o}from"../../support/guards.js";function f(n,r){if(1===r.length){if(i(r[0]))return u(n,r[0],-1);if(t(r[0]))return u(n,r[0].toArray(),-1)}return u(n,r,-1)}function a(u,a){u.stdev=function(n,r){return a(n,r,(n,r,t)=>f("stdev",t))},u.variance=function(n,r){return a(n,r,(n,r,t)=>f("variance",t))},u.average=function(n,r){return a(n,r,(n,r,t)=>f("mean",t))},u.mean=function(n,r){return a(n,r,(n,r,t)=>f("mean",t))},u.sum=function(n,r){return a(n,r,(n,r,t)=>f("sum",t))},u.min=function(n,r){return a(n,r,(n,r,t)=>f("min",t))},u.max=function(n,r){return a(n,r,(n,r,t)=>f("max",t))},u.distinct=function(n,r){return a(n,r,(n,r,t)=>f("distinct",t))},u.count=function(u,f){return a(u,f,(u,a,c)=>{if(r(c,1,1,f),null==c[0])return 0;if(i(c[0])||o(c[0]))return c[0].length;if(t(c[0]))return c[0].length();if(e(c[0]))return c[0].entryCount();throw new n("InvalidParameter",f)})}}export{a as registerFunctions};
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import t from"../../config.js";import{version as e}from"../../kernel.js";import{ArcadeDate as r}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import a from"../Attachment.js";import o from"../Dictionary.js";import{StringEnum as i}from"../enum.js";import{ArcadeExecutionError as u}from"../executionError.js";import s from"../ImmutableArray.js";import{B as l,s as p,T as f,r as c,v as d,O as h,N as m,t as y,j as g,a1 as A,P as w,a2 as I,e as v,f as U,g as j,k as N,i as k,m as P,l as x}from"../../chunks/languageUtils.js";import{getDefaultArcadePortal as C,getDefaultPortal as T,isSamePortal as z}from"../portalUtils.js";import{convertDirection as O}from"./convertdirection.js";import{XXH as S}from"./hash.js";import{generateUUID as F}from"../../core/uuid.js";import R from"../../geometry/Extent.js";import L from"../../geometry/Multipoint.js";import b from"../../geometry/Point.js";import M from"../../geometry/Polygon.js";import _ from"../../geometry/Polyline.js";import H from"../../geometry/SpatialReference.js";import{getLocale as Z}from"../../intl/locale.js";import{isArray as D,isString as J,isBoolean as W,isNumber as B}from"../../support/guards.js";function E(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function V(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 $(t,e,r){if(null!==t)if(D(t)){if(e.updateUint8Array([61]),r.map.has(t)){const n=r.map.get(t);e.updateIntArray([61237541^n])}else{r.map.set(t,r.currentLength++);for(const n of t)$(n,e,r);r.map.delete(t),r.currentLength--}e.updateUint8Array([199])}else if(g(t)){if(e.updateUint8Array([61]),r.map.has(t)){const n=r.map.get(t);e.updateIntArray([61237541^n])}else{r.map.set(t,r.currentLength++);for(const n of t.toArray())$(n,e,r);r.map.delete(t),r.currentLength--}e.updateUint8Array([199])}else{if(v(t))return e.updateIntArray([t.toNumber()]),void e.updateUint8Array([241]);if(U(t))return e.updateIntArray([t.toNumber()]),void e.updateIntArray([257]);if(j(t))return e.updateIntArray([t.toNumber()]),void e.updateIntArray([263]);if(J(t))return e.updateIntArray([t.length]),e.updateWithString(t),void e.updateUint8Array([41]);if(W(t))e.updateUint8Array([!0===t?1:0,113]);else{if(B(t))return e.updateFloatArray([t]),void e.updateUint8Array([173]);if(t instanceof a)throw new u("UnsupportedHashType",r.node);if(t instanceof n)throw new u("UnsupportedHashType",r.node);if(!(t instanceof o)){if(N(t))throw new u("UnsupportedHashType",r.node);if(t instanceof b)return e.updateIntArray([3833836621]),e.updateIntArray([0]),e.updateFloatArray([t.x]),e.updateIntArray([1]),e.updateFloatArray([t.y]),t.hasZ&&(e.updateIntArray([2]),e.updateFloatArray([t.z])),t.hasM&&(e.updateIntArray([3]),e.updateFloatArray([t.m])),e.updateIntArray([3765347959]),void $(t.spatialReference.wkid,e,r);if(t instanceof M){e.updateIntArray([1266616829]);for(let n=0;n<t.rings.length;n++){const a=t.rings[n],o=[];let i=null,u=null;for(let e=0;e<a.length;e++){const r=t.getPoint(n,e);if(0===e)i=r;else if(V(u,r))continue;u=r,e===a.length-1&&V(i,r)||o.push(r)}e.updateIntArray([1397116793,o.length]);for(let t=0;t<o.length;t++){const n=o[t];e.updateIntArray([3962308117,t]),$(n,e,r),e.updateIntArray([2716288009])}e.updateIntArray([2278822459])}return e.updateIntArray([3878477243]),void $(t.spatialReference.wkid,e,r)}if(t instanceof _){e.updateIntArray([4106883559]);for(let n=0;n<t.paths.length;n++){const a=t.paths[n];e.updateIntArray([1397116793,a.length]);for(let o=0;o<a.length;o++)e.updateIntArray([3962308117,o]),$(t.getPoint(n,o),e,r),e.updateIntArray([2716288009]);e.updateIntArray([2278822459])}return e.updateIntArray([2568784753]),void $(t.spatialReference.wkid,e,r)}if(t instanceof L){e.updateIntArray([588535921,t.points.length]);for(let n=0;n<t.points.length;n++){const a=t.getPoint(n);e.updateIntArray([n]),$(a,e,r)}return e.updateIntArray([1700171621]),void $(t.spatialReference.wkid,e,r)}if(t instanceof R)return e.updateIntArray([3483648373]),e.updateIntArray([0]),e.updateFloatArray([t.xmax]),e.updateIntArray([1]),e.updateFloatArray([t.xmin]),e.updateIntArray([2]),e.updateFloatArray([t.ymax]),e.updateIntArray([3]),e.updateFloatArray([t.ymin]),t.hasZ&&(e.updateIntArray([4]),e.updateFloatArray([t.zmax]),e.updateIntArray([5]),e.updateFloatArray([t.zmin])),t.hasM&&(e.updateIntArray([6]),e.updateFloatArray([t.mmax]),e.updateIntArray([7]),e.updateFloatArray([t.mmin])),e.updateIntArray([3622027469]),void $(t.spatialReference.wkid,e,r);if(t instanceof H)return e.updateIntArray([14]),void 0!==t.wkid&&null!==t.wkid&&e.updateIntArray([t.wkid]),t.wkt&&e.updateWithString(t.wkt),void(t.wkt2&&e.updateWithString(t.wkt2));if(k(t))throw new u("UnsupportedHashType",r.node);if(P(t))throw new u("UnsupportedHashType",r.node);if(x(t))throw new u("UnsupportedHashType",r.node);if(t===d)throw new u("UnsupportedHashType",r.node);throw new u("UnsupportedHashType",r.node)}if(e.updateUint8Array([223]),r.map.has(t)){const n=r.map.get(t);e.updateIntArray([61237541^n])}else{r.map.set(t,r.currentLength++);for(const n of t.keys()){e.updateIntArray([n.length]),e.updateWithString(n),e.updateUint8Array([251]);$(t.field(n),e,r),e.updateUint8Array([239])}r.map.delete(t),r.currentLength--}e.updateUint8Array([73])}}else e.updateUint8Array([0,139])}function q(a,v){a.portal=function(t,e){return v(t,e,(r,a,o)=>(l(o,0,1,e),0===o.length?C(t):new n(p(o[0]))))},a.typeof=function(t,e){return v(t,e,(t,r,n)=>{l(n,1,1,e);const a=f(n[0]);if("Unrecognized Type"===a)throw new u("UnrecognizedType",e);return a})},a.trim=function(t,e){return v(t,e,(t,r,n)=>(l(n,1,1,e),p(n[0]).trim()))},a.tohex=function(t,e){return v(t,e,(t,r,n)=>{l(n,1,1,e);const a=c(n[0]);return isNaN(a)?a:a.toString(16)})},a.upper=function(t,e){return v(t,e,(t,r,n)=>(l(n,1,1,e),p(n[0]).toUpperCase()))};const U=new i(["every-word","first-word"]);a.proper=function(t,e){return v(t,e,(t,r,n)=>{l(n,1,2,e);const a=(n.length>=2?U.lookup(p(n[1])):null)??"every-word",o=/\s/,i=p(n[0]);let u="",s=!0;for(let e=0;e<i.length;e++){let t=i[e];if(o.test(t))"every-word"===a&&(s=!0);else{t.toUpperCase()!==t.toLowerCase()&&(s?(t=t.toUpperCase(),s=!1):t=t.toLowerCase())}u+=t}return u})},a.lower=function(t,e){return v(t,e,(t,r,n)=>(l(n,1,1,e),p(n[0]).toLowerCase()))};const j=new i(["digits","digits-hyphen","digits-hyphen-braces","digits-hyphen-parentheses"]);a.guid=function(t,e){return v(t,e,(t,r,n)=>{l(n,0,1,e);switch(n.length>0?j.lookup(p(n[0])):null){case"digits":return F().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return F();case"digits-hyphen-parentheses":return"("+F()+")";default:return"{"+F()+"}"}})},a.standardizeguid=function(t,e){return v(t,e,(t,r,n)=>{l(n,2,2,e);let a=p(n[0]);if(""===a||null===a)return"";const o=/^(\{|\()?(?<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(a);if(!o)return"";const i=o.groups;switch(a=i.partA+"-"+i.partB+"-"+i.partC+"-"+i.partD+"-"+i.partE,j.lookup(p(n[1]))){case"digits":return a.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return a;case"digits-hyphen-parentheses":return"("+a+")";default:return"{"+a+"}"}})},a.console=function(t,e){return v(t,e,(e,r,n)=>(0===n.length||(1===n.length?t.console(p(n[0])):t.console(p(n))),d))},a.mid=function(t,e){return v(t,e,(t,r,n)=>{l(n,2,3,e);let a=c(n[1]);if(isNaN(a))return"";if(a=Math.max(0,a),2===n.length)return p(n[0]).slice(a);let o=c(n[2]);return isNaN(o)?"":(o<0&&(o=0),p(n[0]).slice(a,a+o))})},a.find=function(t,e){return v(t,e,(t,r,n)=>{l(n,2,3,e);let a=0;if(n.length>2){if(a=c(h(n[2],0)),isNaN(a))return-1;a<0&&(a=0)}return p(n[1]).indexOf(p(n[0]),a)})},a.left=function(t,e){return v(t,e,(t,r,n)=>{l(n,2,2,e);let a=c(n[1]);return isNaN(a)?"":(a<0&&(a=0),p(n[0]).slice(0,a))})},a.right=function(t,e){return v(t,e,(t,r,n)=>{l(n,2,2,e);const a=c(n[1]);if(isNaN(a)||a<=0)return"";return p(n[0]).slice(-a)})},a.split=function(t,e){return v(t,e,(t,r,n)=>{let a;l(n,2,4,e);let o=c(h(n[2],-1));const i=m(h(n[3],!1));if(-1===o||null===o||!0===i?a=p(n[0]).split(p(n[1])):(isNaN(o)&&(o=-1),o<-1&&(o=-1),a=p(n[0]).split(p(n[1]),o)),!1===i)return a;const u=[];for(let e=0;e<a.length&&!(-1!==o&&u.length>=o);e++)""!==a[e]&&void 0!==a[e]&&u.push(a[e]);return u})},a.text=function(t,e){return v(t,e,(t,r,n)=>(l(n,1,2,e),y(n[0],n[1])))},a.concatenate=function(t,e){return v(t,e,(t,e,r)=>{const n=[];if(r.length<1)return"";if(D(r[0])){const t=h(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=y(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(g(r[0])){const t=h(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=y(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]=y(r[a]);return n.join("")})},a.reverse=function(t,e){return v(t,e,(t,r,n)=>{if(l(n,1,1,e),D(n[0])){const t=n[0].slice();return t.reverse(),t}if(g(n[0])){const t=n[0].toArray().slice();return t.reverse(),t}throw new u("InvalidParameter",e)})},a.replace=function(t,e){return v(t,e,(t,r,n)=>{l(n,3,4,e);const a=p(n[0]),o=p(n[1]),i=p(n[2]);return 4!==n.length||m(n[3])?A(a,o,i):a.replace(o,i)})},a.urlencode=function(t,e){return v(t,e,(t,r,n)=>{if(l(n,1,1,e),null===n[0])return"";if(n[0]instanceof o){let t="";for(const e of n[0].keys()){const r=n[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(p(n[0]))})},a.hash=function(t,e){return v(t,e,(t,r,n)=>{l(n,1,1,e);const a=new S(0);return $(n[0],a,{node:e,map:new Map,currentLength:0}),a.digest()})},a.convertdirection=function(t,e){return v(t,e,(t,r,n)=>(l(n,3,3,e),O(n[0],n[1],n[2])))},a.fromjson=function(t,e){return v(t,e,(r,n,a)=>{if(l(a,1,1,e),!1===J(a[0]))throw new u("InvalidParameter",e);return o.convertJsonToArcade(JSON.parse(p(a[0])),w(t))})},a.tocharcode=function(t,e){return v(t,e,(t,r,n)=>{l(n,1,2,e);const a=c(h(n[1],0)),o=p(n[0]);if(0===o.length&&1===n.length)return null;if(o.length<=a||a<0)throw new u("OutOfBounds",e);return o.charCodeAt(a)})},a.tocodepoint=function(t,e){return v(t,e,(t,r,n)=>{l(n,1,2,e);const a=c(h(n[1],0)),o=p(n[0]);if(0===o.length&&1===n.length)return null;if(o.length<=a||a<0)throw new u("OutOfBounds",e);return o.codePointAt(a)})},a.fromcharcode=function(t,e){return v(t,e,(t,r,n)=>{if(n.length<1)throw new u("WrongNumberOfParameters",e);const a=n.map(t=>Math.trunc(c(t))).filter(t=>t>=0&&t<=65535);return 0===a.length?null:String.fromCharCode.apply(null,a)})},a.fromcodepoint=function(t,e){return v(t,e,(t,r,n)=>{if(n.length<1)throw new u("WrongNumberOfParameters",e);let a;try{a=n.map(t=>Math.trunc(c(t))).filter(t=>t<=1114111&&t>>>0===t)}catch(o){return null}return 0===a.length?null:String.fromCodePoint.apply(null,a)})},a.getuser=function(t,e){return v(t,e,(r,a,i)=>{l(i,0,2,e);let s=h(i[1],"");if(s=!0===s||!1===s?"":p(s),null!==s&&""!==s)return null;if(0===i.length||i[0]instanceof n){const e=T(t);if(i.length>0&&!z(i[0],e))return null;if(""===s){const r=E(e);if(r){const e=JSON.parse(JSON.stringify(r));for(const t of["lastLogin","created","modified"])void 0!==e[t]&&null!==e[t]&&(e[t]=new Date(e[t]));return o.convertObjectToArcadeDictionary(e,w(t))}}return null}throw new u("InvalidParameter",e)})},a.getenvironment=function(n,a){return v(n,a,(i,u,p)=>{l(p,0,0,a);const f=r.systemTimeZoneCanonicalName;let c=w(n);"system"===c&&(c=f);const d=n.spatialReference,h=C(n);return new o({__proto__:null,version:I,engineVersion:e,timeZone:c,userTimeZone:f,spatialReference:new o({__proto__:null,wkt:d.wkt,wkid:d.wkid}),application:t.applicationName??"",engine:"web",locale:Z(),activePortal:h,availablePortals:new s([h])})})},a.standardizefilename=function(t,e){return v(t,e,(t,e,r)=>{l(r,1,1,e);const[n]=r;if(null==n)return"";if(!J(n))throw new u("InvalidParameter",e);return n.replaceAll(/[<>"?*]/g,"_").replaceAll(/[/\\|]/g,"-").replaceAll(":",", ")})}}export{q as registerFunctions};
2
+ import t from"../../config.js";import{version as e}from"../../kernel.js";import{ArcadeDate as r}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import a from"../Attachment.js";import{convertJsonValueToMutableArcadeValue as o,convertJsonValueToImmutableArcadeValue as i}from"../containerUtils.js";import u from"../Dictionary.js";import{StringEnum as s}from"../enum.js";import{ArcadeExecutionError as l}from"../executionError.js";import p from"../ImmutableArray.js";import{B as f,s as d,S as c,r as h,v as m,O as y,N as g,t as A,g as w,a1 as I,T as U,a2 as j,e as v,o as N,n as k,h as x,i as P,k as C,j as S}from"../../chunks/languageUtils.js";import{getDefaultArcadePortal as z,getDefaultPortal as F,isSamePortal as O}from"../portalUtils.js";import{convertDirection as T}from"./convertdirection.js";import{XXH as R}from"./hash.js";import{generateUUID as L}from"../../core/uuid.js";import b from"../../geometry/Extent.js";import M from"../../geometry/Multipoint.js";import _ from"../../geometry/Point.js";import H from"../../geometry/Polygon.js";import Z from"../../geometry/Polyline.js";import W from"../../geometry/SpatialReference.js";import{getLocale as B}from"../../intl/locale.js";import{isArray as J,isString as D,isBoolean as E,isNumber as V}from"../../support/guards.js";function $(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function q(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 G(t,e,r){if(null!==t)if(J(t)){if(e.updateUint8Array([61]),r.map.has(t)){const n=r.map.get(t);e.updateIntArray([61237541^n])}else{r.map.set(t,r.currentLength++);for(const n of t)G(n,e,r);r.map.delete(t),r.currentLength--}e.updateUint8Array([199])}else if(w(t)){if(e.updateUint8Array([61]),r.map.has(t)){const n=r.map.get(t);e.updateIntArray([61237541^n])}else{r.map.set(t,r.currentLength++);for(const n of t.toArray())G(n,e,r);r.map.delete(t),r.currentLength--}e.updateUint8Array([199])}else{if(v(t))return e.updateIntArray([t.toNumber()]),void e.updateUint8Array([241]);if(N(t))return e.updateIntArray([t.toNumber()]),void e.updateIntArray([257]);if(k(t))return e.updateIntArray([t.toNumber()]),void e.updateIntArray([263]);if(D(t))return e.updateIntArray([t.length]),e.updateWithString(t),void e.updateUint8Array([41]);if(E(t))e.updateUint8Array([!0===t?1:0,113]);else{if(V(t))return e.updateFloatArray([t]),void e.updateUint8Array([173]);if(t instanceof a)throw new l("UnsupportedHashType",r.node);if(t instanceof n)throw new l("UnsupportedHashType",r.node);if(!(t instanceof u)){if(x(t))throw new l("UnsupportedHashType",r.node);if(t instanceof _)return e.updateIntArray([3833836621]),e.updateIntArray([0]),e.updateFloatArray([t.x]),e.updateIntArray([1]),e.updateFloatArray([t.y]),t.hasZ&&(e.updateIntArray([2]),e.updateFloatArray([t.z])),t.hasM&&(e.updateIntArray([3]),e.updateFloatArray([t.m])),e.updateIntArray([3765347959]),void G(t.spatialReference.wkid,e,r);if(t instanceof H){e.updateIntArray([1266616829]);for(let n=0;n<t.rings.length;n++){const a=t.rings[n],o=[];let i=null,u=null;for(let e=0;e<a.length;e++){const r=t.getPoint(n,e);if(0===e)i=r;else if(q(u,r))continue;u=r,e===a.length-1&&q(i,r)||o.push(r)}e.updateIntArray([1397116793,o.length]);for(let t=0;t<o.length;t++){const n=o[t];e.updateIntArray([3962308117,t]),G(n,e,r),e.updateIntArray([2716288009])}e.updateIntArray([2278822459])}return e.updateIntArray([3878477243]),void G(t.spatialReference.wkid,e,r)}if(t instanceof Z){e.updateIntArray([4106883559]);for(let n=0;n<t.paths.length;n++){const a=t.paths[n];e.updateIntArray([1397116793,a.length]);for(let o=0;o<a.length;o++)e.updateIntArray([3962308117,o]),G(t.getPoint(n,o),e,r),e.updateIntArray([2716288009]);e.updateIntArray([2278822459])}return e.updateIntArray([2568784753]),void G(t.spatialReference.wkid,e,r)}if(t instanceof M){e.updateIntArray([588535921,t.points.length]);for(let n=0;n<t.points.length;n++){const a=t.getPoint(n);e.updateIntArray([n]),G(a,e,r)}return e.updateIntArray([1700171621]),void G(t.spatialReference.wkid,e,r)}if(t instanceof b)return e.updateIntArray([3483648373]),e.updateIntArray([0]),e.updateFloatArray([t.xmax]),e.updateIntArray([1]),e.updateFloatArray([t.xmin]),e.updateIntArray([2]),e.updateFloatArray([t.ymax]),e.updateIntArray([3]),e.updateFloatArray([t.ymin]),t.hasZ&&(e.updateIntArray([4]),e.updateFloatArray([t.zmax]),e.updateIntArray([5]),e.updateFloatArray([t.zmin])),t.hasM&&(e.updateIntArray([6]),e.updateFloatArray([t.mmax]),e.updateIntArray([7]),e.updateFloatArray([t.mmin])),e.updateIntArray([3622027469]),void G(t.spatialReference.wkid,e,r);if(t instanceof W)return e.updateIntArray([14]),void 0!==t.wkid&&null!==t.wkid&&e.updateIntArray([t.wkid]),t.wkt&&e.updateWithString(t.wkt),void(t.wkt2&&e.updateWithString(t.wkt2));if(P(t))throw new l("UnsupportedHashType",r.node);if(C(t))throw new l("UnsupportedHashType",r.node);if(S(t))throw new l("UnsupportedHashType",r.node);if(t===m)throw new l("UnsupportedHashType",r.node);throw new l("UnsupportedHashType",r.node)}if(e.updateUint8Array([223]),r.map.has(t)){const n=r.map.get(t);e.updateIntArray([61237541^n])}else{r.map.set(t,r.currentLength++);for(const n of t.keys()){e.updateIntArray([n.length]),e.updateWithString(n),e.updateUint8Array([251]);G(t.field(n),e,r),e.updateUint8Array([239])}r.map.delete(t),r.currentLength--}e.updateUint8Array([73])}}else e.updateUint8Array([0,139])}function K(a,v){a.portal=function(t,e){return v(t,e,(r,a,o)=>(f(o,0,1,e),0===o.length?z(t):new n(d(o[0]))))},a.typeof=function(t,e){return v(t,e,(t,r,n)=>{f(n,1,1,e);const a=c(n[0]);if("Unrecognized Type"===a)throw new l("UnrecognizedType",e);return a})},a.trim=function(t,e){return v(t,e,(t,r,n)=>(f(n,1,1,e),d(n[0]).trim()))},a.tohex=function(t,e){return v(t,e,(t,r,n)=>{f(n,1,1,e);const a=h(n[0]);return isNaN(a)?a:a.toString(16)})},a.upper=function(t,e){return v(t,e,(t,r,n)=>(f(n,1,1,e),d(n[0]).toUpperCase()))};const N=new s(["every-word","first-word"]);a.proper=function(t,e){return v(t,e,(t,r,n)=>{f(n,1,2,e);const a=(n.length>=2?N.lookup(d(n[1])):null)??"every-word",o=/\s/,i=d(n[0]);let u="",s=!0;for(let e=0;e<i.length;e++){let t=i[e];if(o.test(t))"every-word"===a&&(s=!0);else{t.toUpperCase()!==t.toLowerCase()&&(s?(t=t.toUpperCase(),s=!1):t=t.toLowerCase())}u+=t}return u})},a.lower=function(t,e){return v(t,e,(t,r,n)=>(f(n,1,1,e),d(n[0]).toLowerCase()))};const k=new s(["digits","digits-hyphen","digits-hyphen-braces","digits-hyphen-parentheses"]);a.guid=function(t,e){return v(t,e,(t,r,n)=>{f(n,0,1,e);switch(n.length>0?k.lookup(d(n[0])):null){case"digits":return L().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return L();case"digits-hyphen-parentheses":return"("+L()+")";default:return"{"+L()+"}"}})},a.standardizeguid=function(t,e){return v(t,e,(t,r,n)=>{f(n,2,2,e);let a=d(n[0]);if(""===a||null===a)return"";const o=/^(\{|\()?(?<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(a);if(!o)return"";const i=o.groups;switch(a=i.partA+"-"+i.partB+"-"+i.partC+"-"+i.partD+"-"+i.partE,k.lookup(d(n[1]))){case"digits":return a.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return a;case"digits-hyphen-parentheses":return"("+a+")";default:return"{"+a+"}"}})},a.console=function(t,e){return v(t,e,(e,r,n)=>(0===n.length||(1===n.length?t.console(d(n[0])):t.console(d(n))),m))},a.mid=function(t,e){return v(t,e,(t,r,n)=>{f(n,2,3,e);let a=h(n[1]);if(isNaN(a))return"";if(a=Math.max(0,a),2===n.length)return d(n[0]).slice(a);let o=h(n[2]);return isNaN(o)?"":(o<0&&(o=0),d(n[0]).slice(a,a+o))})},a.find=function(t,e){return v(t,e,(t,r,n)=>{f(n,2,3,e);let a=0;if(n.length>2){if(a=h(y(n[2],0)),isNaN(a))return-1;a<0&&(a=0)}return d(n[1]).indexOf(d(n[0]),a)})},a.left=function(t,e){return v(t,e,(t,r,n)=>{f(n,2,2,e);let a=h(n[1]);return isNaN(a)?"":(a<0&&(a=0),d(n[0]).slice(0,a))})},a.right=function(t,e){return v(t,e,(t,r,n)=>{f(n,2,2,e);const a=h(n[1]);if(isNaN(a)||a<=0)return"";return d(n[0]).slice(-a)})},a.split=function(t,e){return v(t,e,(t,r,n)=>{let a;f(n,2,4,e);let o=h(y(n[2],-1));const i=g(y(n[3],!1));if(-1===o||null===o||!0===i?a=d(n[0]).split(d(n[1])):(isNaN(o)&&(o=-1),o<-1&&(o=-1),a=d(n[0]).split(d(n[1]),o)),!1===i)return a;const u=[];for(let e=0;e<a.length&&!(-1!==o&&u.length>=o);e++)""!==a[e]&&void 0!==a[e]&&u.push(a[e]);return u})},a.text=function(t,e){return v(t,e,(t,r,n)=>(f(n,1,2,e),A(n[0],n[1])))},a.concatenate=function(t,e){return v(t,e,(t,e,r)=>{const n=[];if(r.length<1)return"";if(J(r[0])){const t=y(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=A(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(w(r[0])){const t=y(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=A(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]=A(r[a]);return n.join("")})},a.reverse=function(t,e){return v(t,e,(t,r,n)=>{if(f(n,1,1,e),J(n[0])){const t=n[0].slice();return t.reverse(),t}if(w(n[0])){const t=n[0].toArray().slice();return t.reverse(),t}throw new l("InvalidParameter",e)})},a.replace=function(t,e){return v(t,e,(t,r,n)=>{f(n,3,4,e);const a=d(n[0]),o=d(n[1]),i=d(n[2]);return 4!==n.length||g(n[3])?I(a,o,i):a.replace(o,i)})},a.urlencode=function(t,e){return v(t,e,(t,r,n)=>{if(f(n,1,1,e),null===n[0])return"";if(n[0]instanceof u){let t="";for(const e of n[0].keys()){const r=d(n[0].field(e));""!==t&&(t+="&"),t+=encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(d(n[0]))})},a.hash=function(t,e){return v(t,e,(t,r,n)=>{f(n,1,1,e);const a=new R(0);return G(n[0],a,{node:e,map:new Map,currentLength:0}),a.digest()})},a.convertdirection=function(t,e){return v(t,e,(t,r,n)=>(f(n,3,3,e),T(n[0],n[1],n[2])))},a.fromjson=function(t,e){return v(t,e,(t,r,n)=>{if(f(n,1,1,e),!1===D(n[0]))throw new l("InvalidParameter",e);return o(JSON.parse(n[0]))})},a.tocharcode=function(t,e){return v(t,e,(t,r,n)=>{f(n,1,2,e);const a=h(y(n[1],0)),o=d(n[0]);if(0===o.length&&1===n.length)return null;if(o.length<=a||a<0)throw new l("OutOfBounds",e);return o.charCodeAt(a)})},a.tocodepoint=function(t,e){return v(t,e,(t,r,n)=>{f(n,1,2,e);const a=h(y(n[1],0)),o=d(n[0]);if(0===o.length&&1===n.length)return null;if(o.length<=a||a<0)throw new l("OutOfBounds",e);return o.codePointAt(a)})},a.fromcharcode=function(t,e){return v(t,e,(t,r,n)=>{if(n.length<1)throw new l("WrongNumberOfParameters",e);const a=n.map(t=>Math.trunc(h(t))).filter(t=>t>=0&&t<=65535);return 0===a.length?null:String.fromCharCode.apply(null,a)})},a.fromcodepoint=function(t,e){return v(t,e,(t,r,n)=>{if(n.length<1)throw new l("WrongNumberOfParameters",e);let a;try{a=n.map(t=>Math.trunc(h(t))).filter(t=>t<=1114111&&t>>>0===t)}catch(o){return null}return 0===a.length?null:String.fromCodePoint.apply(null,a)})},a.getuser=function(t,e){return v(t,e,(r,a,o)=>{f(o,0,2,e);let u=y(o[1],"");if(u=!0===u||!1===u?"":d(u),null!==u&&""!==u)return null;if(0===o.length||o[0]instanceof n){const e=F(t);if(o.length>0&&!O(o[0],e))return null;if(""===u){const t=$(e);return null!=t?i(JSON.parse(JSON.stringify(t))):null}return null}throw new l("InvalidParameter",e)})},a.getenvironment=function(n,a){return v(n,a,(o,i,s)=>{f(s,0,0,a);const l=r.systemTimeZoneCanonicalName;let d=U(n);"system"===d&&(d=l);const c=n.spatialReference,h=z(n);return new u({__proto__:null,version:j,engineVersion:e,timeZone:d,userTimeZone:l,spatialReference:new u({__proto__:null,wkt:c.wkt,wkid:c.wkid}),application:t.applicationName??"",engine:"web",locale:B(),activePortal:h,availablePortals:new p([h])})})},a.standardizefilename=function(t,e){return v(t,e,(t,e,r)=>{f(r,1,1,e);const[n]=r;if(null==n)return"";if(!D(n))throw new l("InvalidParameter",e);return n.replaceAll(/[<>"?*]/g,"_").replaceAll(/[/\\|]/g,"-").replaceAll(":",", ")})}}export{K as registerFunctions};