@arcgis/core 4.34.0-next.74 → 4.34.0-next.75

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 (149) hide show
  1. package/PopupTemplate.js +1 -1
  2. package/applications/Components/QuantityFormatter.js +1 -1
  3. package/arcade/Pixel.js +5 -0
  4. package/arcade/featureSetUtils.js +1 -1
  5. package/arcade/featureset/actions/GroupBy.js +1 -1
  6. package/arcade/featureset/actions/OrderBy.js +1 -1
  7. package/arcade/functions/featuresetbase.js +1 -1
  8. package/arcade/functions/featuresetstring.js +1 -1
  9. package/arcade/functions/fieldStats.js +1 -1
  10. package/arcade/functions/geometry.js +1 -1
  11. package/arcade/functions/maths.js +1 -1
  12. package/arcade/functions/string.js +1 -1
  13. package/arcade/languageUtils.js +1 -1
  14. package/arcade.js +1 -1
  15. package/assets/esri/core/workers/RemoteClient.js +1 -1
  16. package/assets/esri/core/workers/chunks/009556f323e58271bc7a.js +1 -0
  17. package/assets/esri/core/workers/chunks/{11acefc48c0354e675df.js → 0309d008e50e55c7ff1d.js} +1 -1
  18. package/assets/esri/core/workers/chunks/{dd447dfc50ee7f511b84.js → 19c1f1431c0b2f4525a2.js} +1 -1
  19. package/assets/esri/core/workers/chunks/{7219ceab0b6fae2e69b6.js → 280af3640f8e93c1024e.js} +2 -2
  20. package/assets/esri/core/workers/chunks/{5a476e6743902e35f81a.js.LICENSE.txt → 280af3640f8e93c1024e.js.LICENSE.txt} +1 -1
  21. package/assets/esri/core/workers/chunks/{e3ad0a390387c5847aca.js → 356c96fad88558be9054.js} +1 -1
  22. package/assets/esri/core/workers/chunks/{ada8e07ff12bc5d4a1d9.js → 37ff19a9c5c99bd4e7c7.js} +1 -1
  23. package/assets/esri/core/workers/chunks/{d12f373fcf5848ddcd8a.js → 3f523bc8551e712c9bd4.js} +1 -1
  24. package/assets/esri/core/workers/chunks/{5b7e5ec6aea1f7f9b005.js → 3fecfe4f8ca2a5fd7360.js} +1 -1
  25. package/assets/esri/core/workers/chunks/{78b33c6d73824085c6d1.js → 48449abe795cb7a831eb.js} +1 -1
  26. package/assets/esri/core/workers/chunks/541bffd61006d0e36166.js +1 -0
  27. package/assets/esri/core/workers/chunks/{f4e9640306f64b1af7a3.js → 65ec21d29e8563fdbc55.js} +1 -1
  28. package/assets/esri/core/workers/chunks/67d9cfe02613cb73ee37.js.LICENSE.txt +1 -1
  29. package/assets/esri/core/workers/chunks/{fb669a2e50ca7aacac25.js → 71fef0a33b7ed9456e47.js} +1 -1
  30. package/assets/esri/core/workers/chunks/7430c462c350fdd26349.js +1 -0
  31. package/assets/esri/core/workers/chunks/{ff3fe5c97a98c8cab4ac.js → 7a23b127f551bf13ef54.js} +2 -2
  32. package/assets/esri/core/workers/chunks/{ff3fe5c97a98c8cab4ac.js.LICENSE.txt → 7a23b127f551bf13ef54.js.LICENSE.txt} +1 -1
  33. package/assets/esri/core/workers/chunks/{9c00c2263e52ad51c2a2.js → 8e428b0f33ef4688415e.js} +1 -1
  34. package/assets/esri/core/workers/chunks/{d682dd49bb9ee7f48f93.js → 9304c3cdf732745577fd.js} +1 -1
  35. package/assets/esri/core/workers/chunks/93b2e0a300b2758a1ca4.js +1 -0
  36. package/assets/esri/core/workers/chunks/{8d642b34d40edfe02d8e.js → 9c64b78c5c9b35b31d98.js} +2 -2
  37. package/assets/esri/core/workers/chunks/{8d642b34d40edfe02d8e.js.LICENSE.txt → 9c64b78c5c9b35b31d98.js.LICENSE.txt} +1 -1
  38. package/assets/esri/core/workers/chunks/{6dc62c170e9583222df2.js → a25b75de1bca1dd21941.js} +1 -1
  39. package/assets/esri/core/workers/chunks/a6533bab3b2fbc1e2a47.js +1 -0
  40. package/assets/esri/core/workers/chunks/{5c53deb45bc142219c76.js → b15ff6c9ef2de8a49853.js} +2 -2
  41. package/assets/esri/core/workers/chunks/{5c53deb45bc142219c76.js.LICENSE.txt → b15ff6c9ef2de8a49853.js.LICENSE.txt} +1 -1
  42. package/assets/esri/core/workers/chunks/bccecd678faff927ac76.js +1 -0
  43. package/assets/esri/core/workers/chunks/{ce1f4508487298ab57b6.js → bd2dc1282c49125ede89.js} +1 -1
  44. package/assets/esri/core/workers/chunks/{f542bdc994a5ea3aa9d1.js → c38360d912f256519e06.js} +1 -1
  45. package/assets/esri/core/workers/chunks/cd1869e183001266c4c1.js +2 -0
  46. package/assets/esri/core/workers/chunks/{626c18c1bbc50b3b16b2.js.LICENSE.txt → cd1869e183001266c4c1.js.LICENSE.txt} +1 -1
  47. package/assets/esri/core/workers/chunks/{90321feb56f3a84f6e58.js → d153b29c542c37ae1636.js} +2 -2
  48. package/assets/esri/core/workers/chunks/{90321feb56f3a84f6e58.js.LICENSE.txt → d153b29c542c37ae1636.js.LICENSE.txt} +1 -1
  49. package/assets/esri/core/workers/chunks/d55c55d39a253630d228.js +1 -0
  50. package/assets/esri/core/workers/chunks/{49f7a5523462aebf90fc.js → d66cdb9bb494da19696b.js} +2 -2
  51. package/assets/esri/core/workers/chunks/{49f7a5523462aebf90fc.js.LICENSE.txt → d66cdb9bb494da19696b.js.LICENSE.txt} +1 -1
  52. package/assets/esri/core/workers/chunks/ed773dab5965e42a2879.js +2 -0
  53. package/assets/esri/core/workers/chunks/{7219ceab0b6fae2e69b6.js.LICENSE.txt → ed773dab5965e42a2879.js.LICENSE.txt} +1 -1
  54. package/assets/esri/images/portal/xrexperience16.png +0 -0
  55. package/chunks/Fog.glsl.js +6 -6
  56. package/chunks/GlowComposition.glsl.js +31 -12
  57. package/chunks/LineMarker.glsl.js +37 -36
  58. package/chunks/RibbonLine.glsl.js +83 -83
  59. package/chunks/array.js +1 -1
  60. package/chunks/languageUtils.js +1 -1
  61. package/config.js +1 -1
  62. package/core/quantityFormatUtils.js +1 -1
  63. package/core/unitFormatUtils.js +1 -1
  64. package/core/unitUtils.js +1 -1
  65. package/form/FormTemplate.js +1 -1
  66. package/geometry/support/curves/circleUtils.js +1 -1
  67. package/geometry/support/curves/circularArcUtils.js +1 -1
  68. package/geometry/support/curves/closestPointOnCurve.js +1 -1
  69. package/geometry/support/curves/curveExtent.js +1 -1
  70. package/geometry/support/curves/lineUtils.js +5 -0
  71. package/interfaces.d.ts +270 -18
  72. package/kernel.js +1 -1
  73. package/layers/ImageryLayer.js +1 -1
  74. package/layers/ImageryTileLayer.js +1 -1
  75. package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
  76. package/layers/support/fieldUtils.js +1 -1
  77. package/package.json +2 -2
  78. package/portal/PortalItem.js +1 -1
  79. package/renderers/ClassBreaksRenderer.js +1 -1
  80. package/renderers/DictionaryRenderer.js +1 -1
  81. package/renderers/DotDensityRenderer.js +1 -1
  82. package/renderers/HeatmapRenderer.js +1 -1
  83. package/renderers/PieChartRenderer.js +1 -1
  84. package/renderers/UniqueValueRenderer.js +1 -1
  85. package/renderers/mixins/VisualVariablesMixin.js +1 -1
  86. package/support/arcadeUtils.js +1 -1
  87. package/support/loadArcade.js +1 -1
  88. package/support/revision.js +1 -1
  89. package/symbols/CIMSymbol.js +1 -1
  90. package/symbols/support/FeatureExpressionInfo.js +1 -1
  91. package/views/2d/layers/LayerView2D.js +1 -1
  92. package/views/3d/analysis/Dimension/DimensionVisualization.js +1 -1
  93. package/views/3d/analysis/Dimension/LengthDimensionSubTool.js +1 -1
  94. package/views/3d/analysis/Dimension/lengthDimensionManipulatorUtils.js +1 -1
  95. package/views/3d/analysis/Slice/ResizeManipulator.js +1 -1
  96. package/views/3d/analysis/Slice/RotateManipulator.js +1 -1
  97. package/views/3d/analysis/Slice/ShiftManipulator.js +1 -1
  98. package/views/3d/analysis/Viewshed/ViewshedFieldOfViewManipulation.js +1 -1
  99. package/views/3d/analysis/VolumeMeasurement/VolumeMeasurementTool.js +1 -1
  100. package/views/3d/environment/Fog.js +1 -1
  101. package/views/3d/interactive/visualElements/ExtendedLineVisualElement.js +1 -1
  102. package/views/3d/interactive/visualElements/LineVisualElement.js +1 -1
  103. package/views/3d/interactive/visualElements/MarkerVisualElement.js +1 -1
  104. package/views/3d/interactive/visualElements/OutlineVisualElement.js +1 -1
  105. package/views/3d/interactive/visualElements/ParallelLineVisualElement.js +1 -1
  106. package/views/3d/interactive/visualElements/RightAngleQuadVisualElement.js +1 -1
  107. package/views/3d/layers/FlowSubView3D.js +1 -1
  108. package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
  109. package/views/3d/layers/graphics/Graphics3DLineSymbolLayer.js +1 -1
  110. package/views/3d/layers/graphics/Graphics3DPolygonFillSymbolLayer.js +1 -1
  111. package/views/3d/layers/support/Tiles3DIntersectionHandler.js +1 -1
  112. package/views/3d/state/SurfaceCollisionConstraint.js +1 -1
  113. package/views/3d/state/ViewStateManager.js +1 -1
  114. package/views/3d/state/controllers/SurfaceCollisionCorrectionController.js +1 -1
  115. package/views/3d/support/flow/FlowSubViewExtent3D.js +1 -1
  116. package/views/3d/support/flow/FlowSubViewTiles3D.js +1 -1
  117. package/views/3d/support/flow/FlowWorker.js +1 -1
  118. package/views/3d/support/flow/geometryUtils.js +1 -1
  119. package/views/3d/support/flow/loadUtils.js +1 -1
  120. package/views/3d/webgl-engine/core/shaderLibrary/attributes/RibbonVertexPosition.glsl.js +23 -13
  121. package/views/3d/webgl-engine/core/shaderLibrary/shading/LineStipple.glsl.js +36 -23
  122. package/views/3d/webgl-engine/core/shaderLibrary/shading/MarkerSizing.glsl.js +11 -11
  123. package/views/3d/webgl-engine/core/shaderLibrary/util/NoPerspective.glsl.js +5 -0
  124. package/views/3d/webgl-engine/effects/glow/GlowComposition.glsl.js +1 -1
  125. package/views/3d/webgl-engine/effects/glow/GlowPresets.glsl.js +1 -1
  126. package/views/3d/webgl-engine/effects/glow/GlowRenderNode.js +1 -1
  127. package/views/3d/webgl-engine/lib/GridLocalOriginFactory.js +1 -1
  128. package/views/3d/webgl-engine/materials/LineMarkerMaterial.js +1 -1
  129. package/views/3d/webgl-engine/materials/RibbonLineMaterial.js +1 -1
  130. package/views/3d/webgl-engine/parts/RenderView.js +1 -1
  131. package/views/3d/webgl-engine/shaders/LineMarker.glsl.js +1 -1
  132. package/views/3d/webgl-engine/shaders/LineMarkerTechniqueConfiguration.js +1 -1
  133. package/views/3d/webgl-engine/shaders/RibbonLine.glsl.js +1 -1
  134. package/views/3d/webgl-engine/shaders/RibbonLineTechniqueConfiguration.js +1 -1
  135. package/views/GroundView.js +1 -1
  136. package/views/interactive/snapping/allLayerSnapping.js +1 -1
  137. package/views/layers/ImageryLayerView.js +1 -1
  138. package/views/support/LayerViewManager.js +1 -1
  139. package/widgets/Feature/support/arcadeFeatureUtils.js +1 -1
  140. package/widgets/Legend/support/ActiveLayerInfo.js +1 -1
  141. package/assets/esri/core/workers/chunks/5a476e6743902e35f81a.js +0 -2
  142. package/assets/esri/core/workers/chunks/5a95688651d7e8b7101d.js +0 -1
  143. package/assets/esri/core/workers/chunks/626c18c1bbc50b3b16b2.js +0 -2
  144. package/assets/esri/core/workers/chunks/6da298da2ec09cced0b5.js +0 -1
  145. package/assets/esri/core/workers/chunks/8b1d2bbb2b2eb1830921.js +0 -1
  146. package/assets/esri/core/workers/chunks/a2f4b6d8da93f106852c.js +0 -1
  147. package/assets/esri/core/workers/chunks/d305ca524837c5dc81c8.js +0 -1
  148. package/assets/esri/core/workers/chunks/e6f2ac738df16fb5e13a.js +0 -1
  149. package/assets/esri/core/workers/chunks/e8d25d4ca9b335883f34.js +0 -1
package/PopupTemplate.js CHANGED
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as t}from"tslib";import{ClonableMixin as e}from"./core/Clonable.js";import o from"./core/Collection.js";import{JSONSupport as s}from"./core/JSONSupport.js";import{clone as i}from"./core/lang.js";import r from"./core/Logger.js";import{isPromiseLike as n}from"./core/promiseUtils.js";import{property as p}from"./core/accessorSupport/decorators/property.js";import{cast as l}from"./core/accessorSupport/decorators/cast.js";import{reader as a}from"./core/accessorSupport/decorators/reader.js";import{subclass as d}from"./core/accessorSupport/decorators/subclass.js";import{writer as c}from"./core/accessorSupport/decorators/writer.js";import{ensureOneOfType as f}from"./core/accessorSupport/ensureType.js";import{collectFields as m,collectArcadeFieldNames as u,extractSubstitutionTemplatesFromString as h}from"./layers/support/fieldUtils.js";import{persistableWebSceneTypes as y,persistableTypes as I}from"./popup/content.js";import F from"./popup/ExpressionInfo.js";import _ from"./popup/FieldInfo.js";import w from"./popup/LayerOptions.js";import x from"./popup/RelatedRecordsInfo.js";import{types as g}from"./popup/content/support/mediaInfoTypes.js";import N from"./support/actions/ActionBase.js";import A from"./support/actions/ActionButton.js";import C from"./support/actions/ActionToggle.js";import j from"./popup/content/UtilityNetworkAssociationsContent.js";import S from"./popup/content/RelationshipContent.js";import E from"./popup/content/ExpressionContent.js";import R from"./popup/content/FieldsContent.js";import O from"./popup/content/AttachmentsContent.js";import T from"./popup/content/TextContent.js";import v from"./popup/content/CustomContent.js";import b from"./popup/content/MediaContent.js";import J from"./popup/content/Content.js";const B="relationships/",L="expression/",M=o.ofType({key:"type",defaultKeyValue:"button",base:N,typeMap:{button:A,toggle:C}}),P={base:J,key:"type",typeMap:{media:b,custom:v,text:T,attachments:O,fields:R,expression:E,relationship:S,utilityNetworkAssociations:j}},W=new Set(["attachments","fields","media","text","expression","relationship"]),k=new Set([...W,"utility-network-associations"]);let U=class extends(e(s)){constructor(t){super(t),this.actions=null,this.content="",this.expressionInfos=null,this.fieldInfos=null,this.layerOptions=null,this.lastEditInfoEnabled=!0,this.outFields=null,this.overwriteActions=!1,this.returnGeometry=!1,this.title=""}castContent(t){return Array.isArray(t)?t.map(t=>f(P,t)):"string"==typeof t||"function"==typeof t||t instanceof HTMLElement||n(t)?t:(r.getLogger(this).error("content error","unsupported content value",{value:t}),null)}readContent(t,e){const{popupElements:o}=e;return Array.isArray(o)&&o.length>0?this._readPopupInfoElements(e.description,e.mediaInfos,o):this._readPopupInfo(e)}writeWebSceneContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeWebMapContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeFieldInfos(t,e,o,s){const{content:i}=this,r=Array.isArray(i)?i:null;if(t){const o=r?r.filter(t=>"fields"===t.type):[],i=o.length&&o.every(t=>t.fieldInfos?.length);e.fieldInfos=t.filter(Boolean).map(t=>{const e=t.toJSON(s);return i&&(e.visible=!1),e})}if(r)for(const n of r)"fields"===n.type&&this._writeFieldsContent(n,e)}writeLayerOptions(t,e,o,s){e[o]=!t||null===t.showNoDataRecords&&null===t.returnTopmostRaster?null:t.toJSON(s)}writeTitle(t,e){e.title=t||""}async collectRequiredFields(t,e){const o=this.expressionInfos||[];await this._collectExpressionInfoFields(t,e,[...o,...this._getContentExpressionInfos(this.content,o)]),m(t,e,[...this.outFields||[],...this._getActionsFields(this.actions),...this._getTitleFields(this.title),...this._getContentFields(this.content)])}async getRequiredFields(t){const e=new Set;return await this.collectRequiredFields(e,t),[...e].sort()}_writePopupTemplateContent(t,e,o){"string"!=typeof t?Array.isArray(t)&&(e.popupElements=t.filter(t=>"web-scene"===o?.origin?W.has(t.type):k.has(t.type)).map(t=>t?.toJSON(o)),e.popupElements.forEach(t=>{"attachments"===t.type?this._writeAttachmentContent(e):"media"===t.type?this._writeMediaContent(t,e):"text"===t.type?this._writeTextContent(t,e):"relationship"===t.type&&this._writeRelationshipContent(t,e)})):e.description=t}_writeFieldsContent(t,e){if(!Array.isArray(t.fieldInfos)||!t.fieldInfos.length)return;const o=i(t.fieldInfos);Array.isArray(e.fieldInfos)?o.forEach(t=>{const o=e.fieldInfos.find(e=>e.fieldName?.toLowerCase()===t.fieldName?.toLowerCase());o?o.visible=!0:e.fieldInfos.push(t)}):e.fieldInfos=o}_writeAttachmentContent(t){t.showAttachments||(t.showAttachments=!0)}_writeRelationshipContent(t,e){const o=t.orderByFields?.map(e=>this._toFieldOrderJSON(e,t.relationshipId))||[],s=[...e.relatedRecordsInfo?.orderByFields||[],...o];e.relatedRecordsInfo={showRelatedRecords:!0,...s?.length&&{orderByFields:s}}}_writeTextContent(t,e){!e.description&&t.text&&(e.description=t.text)}_writeMediaContent(t,e){if(!Array.isArray(t.mediaInfos)||!t.mediaInfos.length)return;const o=i(t.mediaInfos);Array.isArray(e.mediaInfos)?e.mediaInfos=[...e.mediaInfos,...o]:e.mediaInfos=o}_readPopupInfoElements(t,e,o){const s={description:!1,mediaInfos:!1};return o.map(o=>"media"===o.type?(o.mediaInfos||!e||s.mediaInfos||(o.mediaInfos=e,s.mediaInfos=!0),b.fromJSON(o)):"text"===o.type?(o.text||!t||s.description||(o.text=t,s.description=!0),T.fromJSON(o)):"attachments"===o.type?O.fromJSON(o):"fields"===o.type?R.fromJSON(o):"expression"===o.type?E.fromJSON(o):"relationship"===o.type?S.fromJSON(o):"utilityNetworkAssociations"===o.type?j.fromJSON(o):void 0).filter(Boolean)}_toRelationshipContent(t){const{field:e,order:o}=t;if(!e?.startsWith(B))return null;const s=e.replace(B,"").split("/");if(2!==s.length)return null;const i=parseInt(s[0],10),r=s[1];return!Number.isNaN(i)&&r?S.fromJSON({relationshipId:i,orderByFields:[{field:r,order:o}]}):null}_toFieldOrderJSON(t,e){const{order:o,field:s}=t;return{field:`${B}${e}/${s}`,order:o}}_readPopupInfo({description:t,mediaInfos:e,showAttachments:o,relatedRecordsInfo:s={showRelatedRecords:!1}}){const i=[];t?i.push(new T({text:t})):i.push(new R),Array.isArray(e)&&e.length&&i.push(b.fromJSON({mediaInfos:e})),o&&i.push(O.fromJSON({displayType:"auto"}));const{showRelatedRecords:r,orderByFields:n}=s;return r&&n?.length&&n.forEach(t=>{const e=this._toRelationshipContent(t);e&&i.push(e)}),i.length?i:t}_getContentElementFields(t){const e=t?.type;if("attachments"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)];if("custom"===e)return t.outFields||[];if("fields"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...this._getFieldInfoFields(t.fieldInfos??this.fieldInfos)];if("media"===e){const e=t.mediaInfos||[];return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...e.reduce((t,e)=>[...t,...this._getMediaInfoFields(e)],[])]}return"text"===e?this._extractFieldNames(t.text):"relationship"===e||"utility-network-associations"===e?[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)]:[]}_getMediaInfoFields(t){const{caption:e,title:o,value:s}=t,i=s||{},{fields:r,normalizeField:n,tooltipField:p,sourceURL:l,linkURL:a}=i,d=[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(l),...this._extractFieldNames(a),...r??[]];return n&&d.push(n),p&&d.push(p),d}_getContentExpressionInfos(t,e){return Array.isArray(t)?t.reduce((t,e)=>[...t,..."expression"===e.type&&e.expressionInfo?[e.expressionInfo]:[]],e):[]}_getContentFields(t){return"string"==typeof t?this._extractFieldNames(t):Array.isArray(t)?t.reduce((t,e)=>[...t,...this._getContentElementFields(e)],[]):[]}async _collectExpressionInfoFields(t,e,o){o&&await Promise.all(o.map(o=>u(t,e,o.expression)))}_getFieldInfoFields(t){return t?t.filter(({fieldName:t,visible:e})=>!(void 0!==e&&!e||!t||t.startsWith(B)||t.startsWith(L))).map(t=>t.fieldName):[]}_getActionsFields(t){return t?t.toArray().reduce((t,e)=>[...t,...this._getActionFields(e)],[]):[]}_getActionFields(t){const{className:e,title:o,type:s}=t,i="button"===s||"toggle"===s?t.image:"";return[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(i)]}_getTitleFields(t){return"string"==typeof t?this._extractFieldNames(t):[]}_extractFieldNames(t){return h(t).filter(t=>!(t.startsWith(B)||t.startsWith(L)))}};t([p({type:M})],U.prototype,"actions",void 0),t([p()],U.prototype,"content",void 0),t([l("content")],U.prototype,"castContent",null),t([a("content",["description","fieldInfos","popupElements","mediaInfos","showAttachments","relatedRecordsInfo"])],U.prototype,"readContent",null),t([c("web-scene","content",{popupElements:{type:o.ofType(y)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebSceneContent",null),t([c("content",{popupElements:{type:o.ofType(I)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebMapContent",null),t([p({type:[F],json:{write:!0}})],U.prototype,"expressionInfos",void 0),t([p({type:[_]})],U.prototype,"fieldInfos",void 0),t([c("fieldInfos")],U.prototype,"writeFieldInfos",null),t([p({type:w})],U.prototype,"layerOptions",void 0),t([c("layerOptions")],U.prototype,"writeLayerOptions",null),t([p({type:Boolean,json:{read:{source:"showLastEditInfo"},write:{target:"showLastEditInfo"},default:!0}})],U.prototype,"lastEditInfoEnabled",void 0),t([p()],U.prototype,"outFields",void 0),t([p()],U.prototype,"overwriteActions",void 0),t([p()],U.prototype,"returnGeometry",void 0),t([p({json:{type:String}})],U.prototype,"title",void 0),t([c("title")],U.prototype,"writeTitle",null),U=t([d("esri.PopupTemplate")],U);const q=U;export{q as default};
5
+ import{__decorate as t}from"tslib";import{ClonableMixin as e}from"./core/Clonable.js";import o from"./core/Collection.js";import{JSONSupport as s}from"./core/JSONSupport.js";import{clone as i}from"./core/lang.js";import r from"./core/Logger.js";import{isPromiseLike as n}from"./core/promiseUtils.js";import{property as p}from"./core/accessorSupport/decorators/property.js";import{cast as l}from"./core/accessorSupport/decorators/cast.js";import{reader as a}from"./core/accessorSupport/decorators/reader.js";import{subclass as d}from"./core/accessorSupport/decorators/subclass.js";import{writer as c}from"./core/accessorSupport/decorators/writer.js";import{ensureOneOfType as f}from"./core/accessorSupport/ensureType.js";import{collectFields as m,collectArcadeFieldNames as u,extractSubstitutionTemplatesFromString as h}from"./layers/support/fieldUtils.js";import{persistableWebSceneTypes as y,persistableTypes as I}from"./popup/content.js";import F from"./popup/ExpressionInfo.js";import _ from"./popup/FieldInfo.js";import w from"./popup/LayerOptions.js";import x from"./popup/RelatedRecordsInfo.js";import{types as g}from"./popup/content/support/mediaInfoTypes.js";import N from"./support/actions/ActionBase.js";import A from"./support/actions/ActionButton.js";import C from"./support/actions/ActionToggle.js";import j from"./popup/content/UtilityNetworkAssociationsContent.js";import S from"./popup/content/RelationshipContent.js";import E from"./popup/content/ExpressionContent.js";import R from"./popup/content/FieldsContent.js";import O from"./popup/content/AttachmentsContent.js";import T from"./popup/content/TextContent.js";import v from"./popup/content/CustomContent.js";import b from"./popup/content/MediaContent.js";import J from"./popup/content/Content.js";const B="relationships/",L="expression/",M=o.ofType({key:"type",defaultKeyValue:"button",base:N,typeMap:{button:A,toggle:C}}),P={base:J,key:"type",typeMap:{media:b,custom:v,text:T,attachments:O,fields:R,expression:E,relationship:S,utilityNetworkAssociations:j}},W=new Set(["attachments","fields","media","text","expression","relationship"]),k=new Set([...W,"utility-network-associations"]);let U=class extends(e(s)){constructor(t){super(t),this.actions=null,this.content="",this.expressionInfos=null,this.fieldInfos=null,this.layerOptions=null,this.lastEditInfoEnabled=!0,this.outFields=null,this.overwriteActions=!1,this.returnGeometry=!1,this.title=""}castContent(t){return Array.isArray(t)?t.map(t=>f(P,t)):"string"==typeof t||"function"==typeof t||t instanceof HTMLElement||n(t)?t:(r.getLogger(this).error("content error","unsupported content value",{value:t}),null)}readContent(t,e){const{popupElements:o}=e;return Array.isArray(o)&&o.length>0?this._readPopupInfoElements(e.description,e.mediaInfos,o):this._readPopupInfo(e)}writeWebSceneContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeWebMapContent(t,e,o,s){this._writePopupTemplateContent(t,e,s)}writeFieldInfos(t,e,o,s){const{content:i}=this,r=Array.isArray(i)?i:null;if(t){const o=r?r.filter(t=>"fields"===t.type):[],i=o.length&&o.every(t=>t.fieldInfos?.length);e.fieldInfos=t.filter(Boolean).map(t=>{const e=t.toJSON(s);return i&&(e.visible=!1),e})}if(r)for(const n of r)"fields"===n.type&&this._writeFieldsContent(n,e)}writeLayerOptions(t,e,o,s){e[o]=!t||null===t.showNoDataRecords&&null===t.returnTopmostRaster?null:t.toJSON(s)}writeTitle(t,e){e.title=t||""}async collectRequiredFields(t,e,o){const s=this.expressionInfos||[];await this._collectExpressionInfoFields(t,e,o,[...s,...this._getContentExpressionInfos(this.content,s)]),m(t,e,[...this.outFields||[],...this._getActionsFields(this.actions),...this._getTitleFields(this.title),...this._getContentFields(this.content)])}async getRequiredFields(t,e){const o=new Set;return await this.collectRequiredFields(o,t,e),[...o].sort()}_writePopupTemplateContent(t,e,o){"string"!=typeof t?Array.isArray(t)&&(e.popupElements=t.filter(t=>"web-scene"===o?.origin?W.has(t.type):k.has(t.type)).map(t=>t?.toJSON(o)),e.popupElements.forEach(t=>{"attachments"===t.type?this._writeAttachmentContent(e):"media"===t.type?this._writeMediaContent(t,e):"text"===t.type?this._writeTextContent(t,e):"relationship"===t.type&&this._writeRelationshipContent(t,e)})):e.description=t}_writeFieldsContent(t,e){if(!Array.isArray(t.fieldInfos)||!t.fieldInfos.length)return;const o=i(t.fieldInfos);Array.isArray(e.fieldInfos)?o.forEach(t=>{const o=e.fieldInfos.find(e=>e.fieldName?.toLowerCase()===t.fieldName?.toLowerCase());o?o.visible=!0:e.fieldInfos.push(t)}):e.fieldInfos=o}_writeAttachmentContent(t){t.showAttachments||(t.showAttachments=!0)}_writeRelationshipContent(t,e){const o=t.orderByFields?.map(e=>this._toFieldOrderJSON(e,t.relationshipId))||[],s=[...e.relatedRecordsInfo?.orderByFields||[],...o];e.relatedRecordsInfo={showRelatedRecords:!0,...s?.length&&{orderByFields:s}}}_writeTextContent(t,e){!e.description&&t.text&&(e.description=t.text)}_writeMediaContent(t,e){if(!Array.isArray(t.mediaInfos)||!t.mediaInfos.length)return;const o=i(t.mediaInfos);Array.isArray(e.mediaInfos)?e.mediaInfos=[...e.mediaInfos,...o]:e.mediaInfos=o}_readPopupInfoElements(t,e,o){const s={description:!1,mediaInfos:!1};return o.map(o=>"media"===o.type?(o.mediaInfos||!e||s.mediaInfos||(o.mediaInfos=e,s.mediaInfos=!0),b.fromJSON(o)):"text"===o.type?(o.text||!t||s.description||(o.text=t,s.description=!0),T.fromJSON(o)):"attachments"===o.type?O.fromJSON(o):"fields"===o.type?R.fromJSON(o):"expression"===o.type?E.fromJSON(o):"relationship"===o.type?S.fromJSON(o):"utilityNetworkAssociations"===o.type?j.fromJSON(o):void 0).filter(Boolean)}_toRelationshipContent(t){const{field:e,order:o}=t;if(!e?.startsWith(B))return null;const s=e.replace(B,"").split("/");if(2!==s.length)return null;const i=parseInt(s[0],10),r=s[1];return!Number.isNaN(i)&&r?S.fromJSON({relationshipId:i,orderByFields:[{field:r,order:o}]}):null}_toFieldOrderJSON(t,e){const{order:o,field:s}=t;return{field:`${B}${e}/${s}`,order:o}}_readPopupInfo({description:t,mediaInfos:e,showAttachments:o,relatedRecordsInfo:s={showRelatedRecords:!1}}){const i=[];t?i.push(new T({text:t})):i.push(new R),Array.isArray(e)&&e.length&&i.push(b.fromJSON({mediaInfos:e})),o&&i.push(O.fromJSON({displayType:"auto"}));const{showRelatedRecords:r,orderByFields:n}=s;return r&&n?.length&&n.forEach(t=>{const e=this._toRelationshipContent(t);e&&i.push(e)}),i.length?i:t}_getContentElementFields(t){const e=t?.type;if("attachments"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)];if("custom"===e)return t.outFields||[];if("fields"===e)return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...this._getFieldInfoFields(t.fieldInfos??this.fieldInfos)];if("media"===e){const e=t.mediaInfos||[];return[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description),...e.reduce((t,e)=>[...t,...this._getMediaInfoFields(e)],[])]}return"text"===e?this._extractFieldNames(t.text):"relationship"===e||"utility-network-associations"===e?[...this._extractFieldNames(t.title),...this._extractFieldNames(t.description)]:[]}_getMediaInfoFields(t){const{caption:e,title:o,value:s}=t,i=s||{},{fields:r,normalizeField:n,tooltipField:p,sourceURL:l,linkURL:a}=i,d=[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(l),...this._extractFieldNames(a),...r??[]];return n&&d.push(n),p&&d.push(p),d}_getContentExpressionInfos(t,e){return Array.isArray(t)?t.reduce((t,e)=>[...t,..."expression"===e.type&&e.expressionInfo?[e.expressionInfo]:[]],e):[]}_getContentFields(t){return"string"==typeof t?this._extractFieldNames(t):Array.isArray(t)?t.reduce((t,e)=>[...t,...this._getContentElementFields(e)],[]):[]}async _collectExpressionInfoFields(t,e,o,s){s&&await Promise.all(s.map(s=>u(t,e,o,s.expression)))}_getFieldInfoFields(t){return t?t.filter(({fieldName:t,visible:e})=>!(void 0!==e&&!e||!t||t.startsWith(B)||t.startsWith(L))).map(t=>t.fieldName):[]}_getActionsFields(t){return t?t.toArray().reduce((t,e)=>[...t,...this._getActionFields(e)],[]):[]}_getActionFields(t){const{className:e,title:o,type:s}=t,i="button"===s||"toggle"===s?t.image:"";return[...this._extractFieldNames(o),...this._extractFieldNames(e),...this._extractFieldNames(i)]}_getTitleFields(t){return"string"==typeof t?this._extractFieldNames(t):[]}_extractFieldNames(t){return h(t).filter(t=>!(t.startsWith(B)||t.startsWith(L)))}};t([p({type:M})],U.prototype,"actions",void 0),t([p()],U.prototype,"content",void 0),t([l("content")],U.prototype,"castContent",null),t([a("content",["description","fieldInfos","popupElements","mediaInfos","showAttachments","relatedRecordsInfo"])],U.prototype,"readContent",null),t([c("web-scene","content",{popupElements:{type:o.ofType(y)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebSceneContent",null),t([c("content",{popupElements:{type:o.ofType(I)},showAttachments:{type:Boolean},mediaInfos:{type:o.ofType(g)},description:{type:String},relatedRecordsInfo:{type:x}})],U.prototype,"writeWebMapContent",null),t([p({type:[F],json:{write:!0}})],U.prototype,"expressionInfos",void 0),t([p({type:[_]})],U.prototype,"fieldInfos",void 0),t([c("fieldInfos")],U.prototype,"writeFieldInfos",null),t([p({type:w})],U.prototype,"layerOptions",void 0),t([c("layerOptions")],U.prototype,"writeLayerOptions",null),t([p({type:Boolean,json:{read:{source:"showLastEditInfo"},write:{target:"showLastEditInfo"},default:!0}})],U.prototype,"lastEditInfoEnabled",void 0),t([p()],U.prototype,"outFields",void 0),t([p()],U.prototype,"overwriteActions",void 0),t([p()],U.prototype,"returnGeometry",void 0),t([p({json:{type:String}})],U.prototype,"title",void 0),t([c("title")],U.prototype,"writeTitle",null),U=t([d("esri.PopupTemplate")],U);const q=U;export{q as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{__decorate as s}from"tslib";import"../../intl.js";import e from"../../core/Accessor.js";import{createTask as t}from"../../core/asyncUtils.js";import{formatLength as r,formatVerticalLength as o,formatArea as a,formatDecimal as i}from"../../core/quantityFormatUtils.js";import{formatAngleDegrees as m}from"../../core/unitFormatUtils.js";import{property as n}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as p}from"../../core/accessorSupport/decorators/subclass.js";import{onLocaleChange as c}from"../../intl/locale.js";import{fetchMessageBundle as l}from"../../intl/messages.js";let g=class extends e{constructor(s){super(s)}initialize(){this.addHandles(c(()=>this._load())),this._load()}destroy(){this._messagesTask.abort()}async when(){await this._messagesTask.promise}_load(){return null!=this._messagesTask&&this._messagesTask.abort(),this._messagesTask=t(()=>l("esri/core/t9n/Units")),this._messagesTask.promise}get _messages(){return this._messagesTask.value}formatLength(s,e,t){return this._messages?r(this._messages,s,s.unit,e,t):""}formatVerticalLength(s,e,t){return this._messages?o(this._messages,s,s.unit,e,t):""}formatArea(s,e,t){return this._messages?a(this._messages,s,s.unit,e,t):""}formatDecimal(s,e,t){return this._messages?i(this._messages,s,s.unit,e,t):""}formatAngleDegrees(s,e,t,r,o){return m(s,e,t,r,o)}};s([n()],g.prototype,"_messagesTask",void 0),s([n()],g.prototype,"_messages",null),g=s([p("esri.applications.Components.QuantityFormatter")],g);const u=g;export{u as default};
5
+ import{__decorate as s}from"tslib";import"../../intl.js";import e from"../../core/Accessor.js";import{createTask as t}from"../../core/asyncUtils.js";import{formatLength as r,formatVerticalLength as o,formatArea as a,formatVolume as i,formatDecimal as m}from"../../core/quantityFormatUtils.js";import{formatAngleDegrees as n}from"../../core/unitFormatUtils.js";import{property as p}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/Logger.js";import"../../core/RandomLCG.js";import{subclass as c}from"../../core/accessorSupport/decorators/subclass.js";import{onLocaleChange as g}from"../../intl/locale.js";import{fetchMessageBundle as l}from"../../intl/messages.js";let u=class extends e{constructor(s){super(s)}initialize(){this.addHandles(g(()=>this._load())),this._load()}destroy(){this._messagesTask.abort()}async when(){await this._messagesTask.promise}_load(){return null!=this._messagesTask&&this._messagesTask.abort(),this._messagesTask=t(()=>l("esri/core/t9n/Units")),this._messagesTask.promise}get _messages(){return this._messagesTask.value}formatLength(s,e,t){return this._messages?r(this._messages,s,s.unit,e,t):""}formatVerticalLength(s,e,t){return this._messages?o(this._messages,s,s.unit,e,t):""}formatArea(s,e,t){return this._messages?a(this._messages,s,s.unit,e,t):""}formatVolume(s,e,t){return this._messages?i(this._messages,s,s.unit,e,t):""}formatDecimal(s,e,t){return this._messages?m(this._messages,s,s.unit,e,t):""}formatAngleDegrees(s,e,t,r,o){return n(s,e,t,r,o)}};s([p()],u.prototype,"_messagesTask",void 0),s([p()],u.prototype,"_messages",null),u=s([c("esri.applications.Components.QuantityFormatter")],u);const h=u;export{h as default};
@@ -0,0 +1,5 @@
1
+ /*
2
+ All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
+ See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
+ */
5
+ import{ArcadeDate as r}from"./ArcadeDate.js";import{toSymbolId as e}from"./arcadeEnvironment.js";import{ArcadeExecutionError as t}from"./executionError.js";import s from"./ImmutableArray.js";import{d as i,c as a}from"../chunks/languageUtils.js";import o from"../core/Logger.js";import{getOrCreateMapValue as n}from"../core/MapUtils.js";import{isImageryGraphicOrigin as m}from"../graphic/isImageryGraphicOrigin.js";import{isImageryTileGraphicOrigin as l}from"../graphic/isImageryTileGraphicOrigin.js";import{isRasterPixelValueField as p}from"../layers/support/fieldUtils.js";import{rasterFieldPrefix as u}from"../layers/support/rasterFieldUtils.js";import{isDate as c}from"../support/guards.js";const f=()=>o.getLogger("esri.arcade.Pixel");class d{constructor(r,t,s){this._graphic=t,this._timeZone=s,this.arcadeDeclaredClass="esri.arcade.Pixel",this._values=new Map,this._fields=new Map(r.map(r=>[e(r.name),r]))}static fromImageryGraphic(r,e){if(!m(r.origin)&&!l(r.origin))throw new t(null,"InvalidParameter",null);const s=r.origin.layer.rasterFields.filter(r=>r.name.startsWith(u));return new d(s,r,e)}keys(){return Array.from(this._fields.values()).map(r=>r.name).sort()}hasField(r){return this._fields.has(e(r))}field(a){const o=this._fields.get(e(a));if(null==o)throw new t(null,"FieldNotFound",null,{key:a});return n(this._values,o.name,()=>{const e=this._graphic.getAttribute(o.name);return p(o.name)&&"string"==typeof e?new s(e.split(/,\s*|\s+/)):c(e)?r.dateJSAndZoneToArcadeDate(e,this._timeZone??"system"):i(e)?e:(f().warn(`Unsupported type for attribute: ${o.name}. Ignoring value.`),null)})}castToText(r=!1){const e={};for(const t of this._fields.values())e[t.name]=this.field(t.name);return a(e,{useNumbersForDates:r})}}export{d as Pixel};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import e from"../request.js";import t from"./featureSetCollection.js";import{m as a,$ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import l from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import i from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import p from"./featureset/support/cache.js";import{FeatureSetError as f}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,isSupportedLayer as m,extractServiceUrl as h}from"./featureset/support/shared.js";import{isLoadable as I}from"../core/Loadable.js";import w from"../core/sql/WhereClause.js";import L from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import _ from"../portal/PortalItem.js";function C(){null===p.applicationCache&&(p.applicationCache=new p)}async function g(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new L({url:e,outFields:t,sourceJSON:r})}const n=new L({url:e,outFields:t}),l=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,l);try{return await l,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await l,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new L({url:e,outFields:t,sourceJSON:a})}const l=new L({url:e,outFields:t}),s=(async()=>(await l.load(),l.sourceJSON))();a.setCachedLayerMetadata(e,s);try{return await s,l}catch(n){throw a.removeCachedLayerMetadata(e,s),n}}return new L({url:e,outFields:t})}async function k(e,t,a,r,n,l=null){return F(await g(e,["*"],n),t,a,r,n,l)}function F(e,t=null,a=null,r=!0,n=null,l=null){switch(e.type){case"catalog-footprint":return F(e.parent,t,a,r,n,l);case"subtype-sublayer":{const s=F(e.parent,t,a,r,n,l);return s.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:s.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"knowledge-graph-sublayer":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:l});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:l};return!e.url&&e.source?new c(s):new u(s)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function N(t){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw p.applicationCache.clearLayerInfo(t),r}}return a}async function T(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new f("DataElementsNotFound")})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(l){throw p.applicationCache.clearLayerInfo(r),l}}return n}async function A(t,a){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw p.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(l){throw a.removeCachedServiceMetadata(t,r),l}}return r}async function O(e,t,a){const r={metadata:null,networkId:-1,unVersion:3,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map,queryelem:null,layerNameLkp:{},lkp:null},n=await A(e,null);if(r.metadata=n,void 0!==n.controllerDatasetLayers?.utilityNetworkLayerId&&null!==n.controllerDatasetLayers.utilityNetworkLayerId){if(n.layers)for(const e of n.layers)r.layerNameLkp[e.id]=e.name;if(n.tables)for(const e of n.tables)r.layerNameLkp[e.id]=e.name;const l=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=l;const s=await T(e,l);if(s){r.queryelem=s,r.queryelem?.dataElement&&void 0!==r.queryelem.dataElement.schemaGeneration&&(r.unVersion=r.queryelem.dataElement.schemaGeneration),r.lkp={},r.queryelem.dataElement.domainNetworks||(r.queryelem.dataElement.domainNetworks=[]);for(const e of r.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}}if(r.queryelem.dataElement.terminalConfigurations)for(const e of r.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)r.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const n=await N(e+"/"+l);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let l=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),l=await k(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await l.load(),r.unVersion>=4&&(l=l.filter(w.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})),await l.load())}return{lkp:r.lkp,associations:l,unVersion:r.unVersion,terminals:r.terminals,layerIdLookup:r.layerIdLookup,sourceIdLookup:r.sourceIdLookup}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}async function E(e,t,a,r=null,n=null,l=!0,s=null,i=null){let o=e.serviceUrl();if(!o)return null;o=o.endsWith("/")?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await k(o,r,n,l,s,i);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:l,lrucache:s,interceptor:i})}n.registerAction(),l.registerAction(),s.registerAction(),i.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=F(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(I(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=this._map.allLayers.find(t=>m(t)&&t.title===e);if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(t)&&t.title===e);if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){if(I(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=this._map.allLayers.find(t=>m(t)&&t.id===e);if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(t)&&t.id===e);if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=F(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await A(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])s.name===e&&(l=s);if(!l)for(const s of n.tables??[])s.name===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(!l)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new j(e,t,a,r)}function b(e,t,a=null,r=null){return new D(e,t,a,r)}function v(e,t,n,l,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l)}return null}if(r(e)){switch(t){case"datasource":return F(e.parent,s,e.parent.outFields,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(e,s,e.parent.outFields,!0,n,l)}return null}return null}async function R(e,t,a,r,n,l,s,i=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+l.url);if(o)return q(await o,t,a,r,n,s,i)}if(null!=s){const o=s.getCachedPortalItem(l.url,e);if(null!=o)return await q(await o,t,a,r,n,s,i)}const o=new _({id:e,portal:l}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+l.url,o):null!=s&&s.setCachedPortalItem(l.url,e,o);try{return await q(await o,t,a,r,n,s,i)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+l.url),null!=s&&s.removeCachedPortalItem(l.url,e,o),u}}async function q(e,t,a,r,n,l,s){let i;if("Feature Service"===e.type||"Map Service"===e.type)i=await g(h(e.url??"")+"/"+t,["*"],l);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=l){const t=l.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)i=await t;else{const t=S.fromPortalItem(e);l.setCachedPortalItemLayer(e.portal.url,e.id,t);try{i=await t}catch(o){throw l.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else i=await S.fromPortalItem(e)}return F(i,a,r,n,l,s)}export{O as constructAssociationMetaDataFeatureSetFromUrl,F as constructFeatureSet,R as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,k as constructFeatureSetFromUrl,v as convertToFeatureSet,M as createFeatureSetCollectionFromMap,b as createFeatureSetCollectionFromService,C as initialiseMetaDataCache};
5
+ import e from"../request.js";import t from"./featureSetCollection.js";import{m as a,a0 as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import l from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import i from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import p from"./featureset/support/cache.js";import{FeatureSetError as f}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,isSupportedLayer as m,extractServiceUrl as h}from"./featureset/support/shared.js";import{isLoadable as I}from"../core/Loadable.js";import w from"../core/sql/WhereClause.js";import L from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import _ from"../portal/PortalItem.js";function C(){null===p.applicationCache&&(p.applicationCache=new p)}async function g(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new L({url:e,outFields:t,sourceJSON:r})}const n=new L({url:e,outFields:t}),l=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,l);try{return await l,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await l,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new L({url:e,outFields:t,sourceJSON:a})}const l=new L({url:e,outFields:t}),s=(async()=>(await l.load(),l.sourceJSON))();a.setCachedLayerMetadata(e,s);try{return await s,l}catch(n){throw a.removeCachedLayerMetadata(e,s),n}}return new L({url:e,outFields:t})}async function k(e,t,a,r,n,l=null){return F(await g(e,["*"],n),t,a,r,n,l)}function F(e,t=null,a=null,r=!0,n=null,l=null){switch(e.type){case"catalog-footprint":return F(e.parent,t,a,r,n,l);case"subtype-sublayer":{const s=F(e.parent,t,a,r,n,l);return s.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:s.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"knowledge-graph-sublayer":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:l});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:l};return!e.url&&e.source?new c(s):new u(s)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function N(t){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw p.applicationCache.clearLayerInfo(t),r}}return a}async function T(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new f("DataElementsNotFound")})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(l){throw p.applicationCache.clearLayerInfo(r),l}}return n}async function A(t,a){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw p.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(l){throw a.removeCachedServiceMetadata(t,r),l}}return r}async function O(e,t,a){const r={metadata:null,networkId:-1,unVersion:3,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map,queryelem:null,layerNameLkp:{},lkp:null},n=await A(e,null);if(r.metadata=n,void 0!==n.controllerDatasetLayers?.utilityNetworkLayerId&&null!==n.controllerDatasetLayers.utilityNetworkLayerId){if(n.layers)for(const e of n.layers)r.layerNameLkp[e.id]=e.name;if(n.tables)for(const e of n.tables)r.layerNameLkp[e.id]=e.name;const l=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=l;const s=await T(e,l);if(s){r.queryelem=s,r.queryelem?.dataElement&&void 0!==r.queryelem.dataElement.schemaGeneration&&(r.unVersion=r.queryelem.dataElement.schemaGeneration),r.lkp={},r.queryelem.dataElement.domainNetworks||(r.queryelem.dataElement.domainNetworks=[]);for(const e of r.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}}if(r.queryelem.dataElement.terminalConfigurations)for(const e of r.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)r.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const n=await N(e+"/"+l);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let l=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),l=await k(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await l.load(),r.unVersion>=4&&(l=l.filter(w.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})),await l.load())}return{lkp:r.lkp,associations:l,unVersion:r.unVersion,terminals:r.terminals,layerIdLookup:r.layerIdLookup,sourceIdLookup:r.sourceIdLookup}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}async function E(e,t,a,r=null,n=null,l=!0,s=null,i=null){let o=e.serviceUrl();if(!o)return null;o=o.endsWith("/")?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await k(o,r,n,l,s,i);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:l,lrucache:s,interceptor:i})}n.registerAction(),l.registerAction(),s.registerAction(),i.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=F(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(I(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=this._map.allLayers.find(t=>m(t)&&t.title===e);if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(t)&&t.title===e);if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){if(I(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=this._map.allLayers.find(t=>m(t)&&t.id===e);if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.allTables){const r=this._map.allTables.find(t=>m(t)&&t.id===e);if(null!=r)return this._makeAndAddFeatureSet(r,t,a)}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=F(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await A(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])s.name===e&&(l=s);if(!l)for(const s of n.tables??[])s.name===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let l=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(!l)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(l=s);if(l){const e=await g(this._url+"/"+l.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new j(e,t,a,r)}function b(e,t,a=null,r=null){return new D(e,t,a,r)}function v(e,t,n,l,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(a,s,"outFields"in a?a.outFields:null,!0,n,l)}return null}if(r(e)){switch(t){case"datasource":return F(e.parent,s,e.parent.outFields,!0,n,l).getDataSourceFeatureSet();case"parent":case"root":return F(e,s,e.parent.outFields,!0,n,l)}return null}return null}async function R(e,t,a,r,n,l,s,i=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+l.url);if(o)return q(await o,t,a,r,n,s,i)}if(null!=s){const o=s.getCachedPortalItem(l.url,e);if(null!=o)return await q(await o,t,a,r,n,s,i)}const o=new _({id:e,portal:l}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+l.url,o):null!=s&&s.setCachedPortalItem(l.url,e,o);try{return await q(await o,t,a,r,n,s,i)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+l.url),null!=s&&s.removeCachedPortalItem(l.url,e,o),u}}async function q(e,t,a,r,n,l,s){let i;if("Feature Service"===e.type||"Map Service"===e.type)i=await g(h(e.url??"")+"/"+t,["*"],l);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=l){const t=l.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)i=await t;else{const t=S.fromPortalItem(e);l.setCachedPortalItemLayer(e.portal.url,e.id,t);try{i=await t}catch(o){throw l.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else i=await S.fromPortalItem(e)}return F(i,a,r,n,l,s)}export{O as constructAssociationMetaDataFeatureSetFromUrl,F as constructFeatureSet,R as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,k as constructFeatureSetFromUrl,v as convertToFeatureSet,M as createFeatureSetCollectionFromMap,b as createFeatureSetCollectionFromService,C as initialiseMetaDataCache};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../Graphic.js";import{StringEnum as t}from"../../enum.js";import{a0 as i}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as s,OriginalField as n,AdaptedFeatureSet as r}from"./Adapted.js";import a from"./AttributeFilter.js";import o from"./OrderBy.js";import{FeatureSetError as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{layerGeometryEsriConstants as p}from"../support/shared.js";import{isSingleField as h,toWhereClause as c,predictType as g,scanForField as _,reformulateWithoutField as m}from"../support/sqlUtils.js";import y from"../support/StatsField.js";import{createMD5Hash as b,outputTypes as w}from"../../../core/MD5.js";import{aggregateFunction as F}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as I}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as S}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as x}from"../../../core/sql/TimeOnly.js";import D from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import j from"../../../layers/support/Field.js";import k from"../../../layers/support/FieldsIndex.js";const C=new t(["MIN","MAX","VAR","STDDEV","COUNT","SUM","AVG"],[["VARIANCE","VAR"],["AVERAGE","AVG"],["MEAN","AVG"],["STDEV","STDDEV"]]);class T extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return 0}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,i=1;const r=this._parent?this._parent.getFieldsIndex():new k([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+i.toString(),i++)}for(const s of this._config.statsfields){const e=new y;e.field=s.name,e.tofieldname=s.name,e.workingexpr=s.expression instanceof D?s.expression:D.create(s.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=C.lookup(s.statistic)??"COUNT",this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const s of this._config.groupbyfields){const e={name:s.name,singlefield:null,tofieldname:s.name,expression:s.expression instanceof D?s.expression:D.create(s.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new y;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=D.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const n of this._decodedGroupbyfield){const t=new j;if(n.name=this._nextUniqueName(e),t.name=n.tofieldname,t.alias=t.name,h(n.expression)){const e=this._parent.getField(c(n.expression,0));if(!e)throw new l("AggregationFieldNotFound");n.name=e.name,n.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,n.sqlType=e.type}else{t.type=this._convertToEsriFieldType(g(n.expression,this._parent.fields));const e=new j;e.name=n.name,e.alias=e.name,this.phsyicalgroupbyfields.push(n.name),this._adaptedFields.push(new s(e,n.expression)),this._candosimplegroupby=!1,n.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const s of this._parent.fields)this._adaptedFields.push(new n(s));for(let s=0;s<this._decodedStatsfield.length;s++){const t=new j;let i=null;const n=this._decodedStatsfield[s];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&h(n.workingexpr)?c(n.workingexpr,0):"";switch(this._decodedStatsfield[s].typeofstat){case"SUM":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(i=this._parent.getField(r),!i))throw new l("AggregationFieldNotFound");t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,n){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let r=0;r<this._decodedStatsfield.length;r++)if(!0===_(i,this._decodedStatsfield[r].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const r=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(n),l=!0===d.nowhereclause?new u(r._candidates.slice().concat(r._known.slice()),[],!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)):new u(r._candidates.slice(),r._known.slice(),!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)),l}let p=this._parent;if(this._adaptedFields.length>0&&(p=new r({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new o({parentfeatureset:p,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=p;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new a({parentfeatureset:e,whereclause:t})}l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new o({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=m(e,t.tofieldname,c(t.workingexpr,0),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=m(e,t.tofieldname,c(t.expression,0),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))},r)})}_nextAggregateItem(e,t,s,n,r,a){try{i(e.pagesDefinition.internal.iterator.next()).then(i=>{if(null===i)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const o=this._generateAggregateHash(i);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[i],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),t-=1,e.pagesDefinition.internal.workingItem={features:[i],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(i)}this._nextAggregateItem(e,t,s,n,r,a)}},a)}catch(o){a(o)}}_calculateFieldStat(e,t,i){const s=[];for(const n of e.features)if(null!==t.workingexpr){const e=t.workingexpr.calculateValue(n);null!==e&&(e instanceof I||e instanceof x?s.push(e.toNumber()):e instanceof S?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=F(t.typeofstat,[s])}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:D.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return b(t,w.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new T({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{T as default};
5
+ import e from"../../../Graphic.js";import{StringEnum as t}from"../../enum.js";import{a1 as i}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as s,OriginalField as n,AdaptedFeatureSet as r}from"./Adapted.js";import a from"./AttributeFilter.js";import o from"./OrderBy.js";import{FeatureSetError as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{layerGeometryEsriConstants as p}from"../support/shared.js";import{isSingleField as h,toWhereClause as c,predictType as g,scanForField as _,reformulateWithoutField as m}from"../support/sqlUtils.js";import y from"../support/StatsField.js";import{createMD5Hash as b,outputTypes as w}from"../../../core/MD5.js";import{aggregateFunction as F}from"../../../core/sql/AggregateFunctions.js";import{DateOnly as I}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as S}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as x}from"../../../core/sql/TimeOnly.js";import D from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import j from"../../../layers/support/Field.js";import k from"../../../layers/support/FieldsIndex.js";const C=new t(["MIN","MAX","VAR","STDDEV","COUNT","SUM","AVG"],[["VARIANCE","VAR"],["AVERAGE","AVG"],["MEAN","AVG"],["STDEV","STDDEV"]]);class T extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return 0}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,i=1;const r=this._parent?this._parent.getFieldsIndex():new k([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+i.toString(),i++)}for(const s of this._config.statsfields){const e=new y;e.field=s.name,e.tofieldname=s.name,e.workingexpr=s.expression instanceof D?s.expression:D.create(s.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),e.typeofstat=C.lookup(s.statistic)??"COUNT",this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const s of this._config.groupbyfields){const e={name:s.name,singlefield:null,tofieldname:s.name,expression:s.expression instanceof D?s.expression:D.create(s.expression,{fieldsIndex:r,timeZone:this.dateFieldsTimeZoneDefaultUTC}),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new y;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=D.create(this._parent.objectIdField,{fieldsIndex:this._parent.getFieldsIndex(),timeZone:this.dateFieldsTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const n of this._decodedGroupbyfield){const t=new j;if(n.name=this._nextUniqueName(e),t.name=n.tofieldname,t.alias=t.name,h(n.expression)){const e=this._parent.getField(c(n.expression,0));if(!e)throw new l("AggregationFieldNotFound");n.name=e.name,n.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,n.sqlType=e.type}else{t.type=this._convertToEsriFieldType(g(n.expression,this._parent.fields));const e=new j;e.name=n.name,e.alias=e.name,this.phsyicalgroupbyfields.push(n.name),this._adaptedFields.push(new s(e,n.expression)),this._candosimplegroupby=!1,n.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const s of this._parent.fields)this._adaptedFields.push(new n(s));for(let s=0;s<this._decodedStatsfield.length;s++){const t=new j;let i=null;const n=this._decodedStatsfield[s];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&h(n.workingexpr)?c(n.workingexpr,0):"";switch(this._decodedStatsfield[s].typeofstat){case"SUM":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(i=this._parent.getField(r),!i)throw new l("AggregationFieldNotFound");t.type=i.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(i=this._parent.getField(r),!i))throw new l("AggregationFieldNotFound");t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,n){if(""!==e)return new u([],[],!0,null);let l=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let r=0;r<this._decodedStatsfield.length;r++)if(!0===_(i,this._decodedStatsfield[r].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const r=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(n),l=!0===d.nowhereclause?new u(r._candidates.slice().concat(r._known.slice()),[],!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)):new u(r._candidates.slice(),r._known.slice(),!0===d.ordered&&r._ordered,this._clonePageDefinition(r.pagesDefinition)),l}let p=this._parent;if(this._adaptedFields.length>0&&(p=new r({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new o({parentfeatureset:p,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=p;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new a({parentfeatureset:e,whereclause:t})}l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new o({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=m(e,t.tofieldname,c(t.workingexpr,0),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=m(e,t.tofieldname,c(t.expression,0),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))},r)})}_nextAggregateItem(e,t,s,n,r,a){try{i(e.pagesDefinition.internal.iterator.next()).then(i=>{if(null===i)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const o=this._generateAggregateHash(i);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[i],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),t-=1,e.pagesDefinition.internal.workingItem={features:[i],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(i)}this._nextAggregateItem(e,t,s,n,r,a)}},a)}catch(o){a(o)}}_calculateFieldStat(e,t,i){const s=[];for(const n of e.features)if(null!==t.workingexpr){const e=t.workingexpr.calculateValue(n);null!==e&&(e instanceof I||e instanceof x?s.push(e.toNumber()):e instanceof S?s.push(e.toMilliseconds()):s.push(e))}else s.push(null);i.attributes[t.tofieldname]=F(t.typeofstat,[s])}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:D.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return b(t,w.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new T({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{T as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{a0 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import n from"../support/IdSet.js";import s from"../support/OrderbyClause.js";class i extends r{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const s=new n([],[],!0,null);for(let n=0;n<r.length;n++)s._known.push(r[n].id);return s}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t("NeverReach")}async _getFilteredSet(e,t,r,s,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===s?this._orderbyclause:s,i);this._checkCancelled(i);const o=new n(a._candidates.slice(),a._known.slice(),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new n(e._candidates.slice().concat(e._known.slice()),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){r._featuresetFunctions.orderBy=function(e){return""===e?this:new i({parentfeatureset:this,orderbyclause:new s(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{i as default};
5
+ import{a1 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import n from"../support/IdSet.js";import s from"../support/OrderbyClause.js";class i extends r{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const s=new n([],[],!0,null);for(let n=0;n<r.length;n++)s._known.push(r[n].id);return s}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t("NeverReach")}async _getFilteredSet(e,t,r,s,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===s?this._orderbyclause:s,i);this._checkCancelled(i);const o=new n(a._candidates.slice(),a._known.slice(),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new n(e._candidates.slice().concat(e._known.slice()),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){r._featuresetFunctions.orderBy=function(e){return""===e?this:new i({parentfeatureset:this,orderbyclause:new s(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{i as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- 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 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 I,m as h,u as g,N as F,K as b,e as T,l as D,J as x,H as E,k as N,j as A,i as v,s as S,L,Y as j}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as k,StringToCodeAdapted as Z,FieldRename as $,AdaptedFeatureSet as P,OriginalField as U}from"../featureset/actions/Adapted.js";import M from"../featureset/actions/AttributeFilter.js";import R from"../featureset/actions/OrderBy.js";import O from"../featureset/actions/Top.js";import z from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import H from"../featureset/support/OrderbyClause.js";import{isSupportedLayer as G,cloneField as V}from"../featureset/support/shared.js";import{isSingleField as _}from"../featureset/support/sqlUtils.js";import{calculateStat as B}from"./fieldStats.js";import{isPromiseLike as K}from"../../core/promiseUtils.js";import q from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";import{queryAssociations as X}from"../../rest/networks/queryAssociations.js";import ee from"../../rest/networks/support/NetworkElement.js";import te from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ne,isArray as ie,isInteger as ae}from"../../support/guards.js";function re(e){if(1===e.length){if(ie(e[0]))return B("distinct",e[0],-1);if(A(e[0]))return B("distinct",e[0].toArray(),-1)}return B("distinct",e,-1)}function oe(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 se(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function le(e){if(null===e)return null;const t={type:se(e,"type",""),name:se(e,"name","")};if("range"===t.type)t.range=se(e,"range",[]);else{t.codedValues=[];for(const n of se(e,"codedValues",[]))t.codedValues.push({name:se(n,"name",""),code:se(n,"code",null)})}return t}function fe(e){if(null===e)return null;const t={},n=se(e,"wkt");null!==n&&(t.wkt=n);const i=se(e,"wkid");return null!==i&&(t.wkid=i),t}function de(e){if(null===e)return null;const t={hasZ:se(e,"hasz",!1),hasM:se(e,"hasm",!1)},n=se(e,"spatialreference");null!=n&&(t.spatialReference=fe(n));const i=se(e,"x",null);if(null!==i)return t.x=i,t.y=se(e,"y",null),t.hasZ&&(t.z=se(e,"z",null)),t.hasM&&(t.m=se(e,"m",null)),t;const a=se(e,"rings",null);if(null!==a)return t.rings=a,t;const r=se(e,"paths",null);if(null!==r)return t.paths=r,t;const o=se(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=se(e,s,null);null!==n&&(t[s]=n)}return t}function ue(e,t){for(const n of t)if(n===e)return!0;return!1}function ce(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ue(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==ie(e.layerDefinition.fields)&&!1!==ie(e.featureSet.features))))}function me(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function pe(t,n,i,a,r,s,l){const f=await t.getFeatureSetInfo();if(null===(f?.layerId??null))return null;if(!r.layerIdLookup.get(f.layerId))return null;const u=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),c=[];switch(i){case"connected":c.push("connectivity"),c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity"),c.push("junction-edge-midspan-connectivity"),c.push("junction-junction-connectivity");break;case"container":case"content":c.push("containment");break;case"structure":case"attached":c.push("attachment");break;case"junctionedge":c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity");break;case"midspan":c.push("junction-edge-midspan-connectivity");break;default:throw new o(s,"InvalidParameter",l)}let m=null,p=!1;if(null!==a&&""!==a&&void 0!==a){for(const e of r.terminals)e.terminalName===a&&(m=e.terminalId);null===m&&(p=!0)}const y=[];if(!p){const a=new ee({globalId:n.field(t.globalIdField),networkSourceId:r.layerIdLookup.get(f.layerId).sourceId,...m?{terminalId:m}:""}),o=await X(u,new te({types:c,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??"";y.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 w=new Q({source:y,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new J({name:"objectId",alias:"objectId",type:"oid"}),new J({name:"globalId",alias:"globalId",type:"global-id"}),new J({name:"percentAlong",alias:"percentAlong",type:"double"}),new J({name:"side",alias:"side",type:"string"}),new J({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new J({name:"className",alias:"className",type:"string"})]});return d(w)}function ye(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,n,a),w(s[0]))return"Unknown";if(I(s[0]))return"Unknown";if(h(s[0])){if(await s[0].load(),1===s.length||null===s[1])return s[0].datesInUnknownTimezone?me("unknown"):me(s[0].dateFieldsTimeZone);if(!(s[1]instanceof i)||!1===s[1].hasField("type"))throw new o(n,"InvalidParameter",a);const e=s[1].field("type");if(!1===ne(e))throw new o(n,"InvalidParameter",a);switch(g(e).toLowerCase()){case"preferredtimezone":return me(s[0].preferredTimeZone);case"editfieldsinfo":return me(s[0].editFieldsInfo?.timeZone??null);case"timeinfo":return me(s[0].timeInfo?.timeZone??null);case"field":if(s[1].hasField("fieldname")&&ne(s[1].field("fieldname")))return me(s[0].fieldTimeZone(g(s[1].field("fieldname"))))}throw new o(n,"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,i,a)=>{y(a,1,3,t,n);const r=a[0];if(T(r)){if(1===a.length)return r.toSQLWithKeyword();if(2===a.length)return r.changeTimeZone(g(a[1])).toSQLWithKeyword();throw new o(t,"InvalidParameter",n)}if(I(r))return r.toSQLWithKeyword();if(h(r)){if(3!==a.length)throw new o(t,"InvalidParameter",n);await r.load();const e=g(a[1]);if(I(a[2]))return a[2].toSQLWithKeyword();if(!1===T(a[2]))throw new o(t,"InvalidParameter",n);const i=r.fieldTimeZone(e);return null==i?a[2].toSQLWithKeyword():a[2].changeTimeZone(i).toSQLWithKeyword()}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,(e,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetById(e,r,i)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"featuresetbyid",min:2,max:4});const B=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,t,n),N(a[0])){const e=null==a[1]?"datasource":B.lookup(g(a[1]));return l(a[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new o(t,"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,t,i),null===r[0])throw new o(t,"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===ie(a))throw new o(t,"InvalidParameter",i);let l;return l=t.services?.portal?t.services.portal:Y.getDefault(),l=C(r[0],l),f(e,n,t.spatialReference,a,s,l,t.lrucache,t.interceptor)}if(!1===ne(r[0]))throw new o(t,"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===ie(d))throw new o(t,"InvalidParameter",i);return f(s,l,t.spatialReference,d,u,t.services?.portal??Y.getDefault(),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,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetByName(e,r,i)}throw new o(t,"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,t,n);const s={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ne(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(t,"InvalidParameter",n);{const e=JSON.parse(r[0].castToText(!0)),i=se(e,"layerdefinition");if(null!==i){s.layerDefinition.geometryType=se(i,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.globalIdField=se(i,"globalidfield",""),s.layerDefinition.objectIdField=se(i,"objectidfield",""),s.layerDefinition.typeIdField=se(i,"typeidfield",""),s.layerDefinition.hasZ=!0===se(i,"hasz",!1),s.layerDefinition.hasM=!0===se(i,"hasm",!1);const t=se(i,"spatialreference");t&&(s.layerDefinition.spatialReference=fe(t));const n=[];for(const e of se(i,"fields",[])){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};n.push(t)}s.layerDefinition.fields=n;const a=se(e,"featureset");if(a){const e={};for(const t of n)e[t.name.toLowerCase()]=t.name;for(const t of se(a,"features",[])){const n={},i=se(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];s.featureSet.features.push({attributes:n,geometry:de(se(t,"geometry"))})}}}else{s.layerDefinition.hasZ=!0===se(e,"hasz",!1),s.layerDefinition.hasM=!0===se(e,"hasm",!1),s.layerDefinition.geometryType=se(e,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.objectIdField=se(e,"objectidfieldname",""),s.layerDefinition.typeIdField=se(e,"typeidfieldname","");const i=se(e,"spatialreference");i&&(s.layerDefinition.spatialReference=fe(i));const a=[],r=se(e,"fields",null);if(!ie(r))throw new o(t,"InvalidParameter",n);for(const e of r){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};a.push(t)}s.layerDefinition.fields=a;const l={};for(const e of a)l[e.name.toLowerCase()]=e.name;let f=se(e,"features",null);if(ie(f))for(const e of f){const t={},n=se(e,"attributes",{});for(const e in n)t[l[e.toLowerCase()]]=n[e];s.featureSet.features.push({attributes:t,geometry:de(se(e,"geometry",null))})}else f=null,s.featureSet.features=f}}}if(!1===ce(s))throw new o(t,"InvalidParameter",n);return s.layerDefinition.geometryType||(s.layerDefinition.geometryType="esriGeometryNull"),W.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,t,n),ie(r[0])||A(r[0])){const e=[];let i,a=r[0];if(a instanceof p&&(a=a.toArray()),!v(r[1]))throw new o(t,"InvalidParameter",n);i=r[1].createFunction(t);for(const t of a){const n=i(t);K(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(h(r[0])){const n=await r[0].load(),i=q.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 M({parentfeatureset:r[0],whereclause:i})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=new H(a[1]);return new R({parentfeatureset:a[0],orderbyclause:e})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0]))return new O({parentfeatureset:a[0],topnum:a[1]});if(ie(a[0]))return S(a[1])>=a[0].length?a[0].slice():a[0].slice(0,S(a[1]));if(A(a[0]))return S(a[1])>=a[0].length()?a[0].slice():a[0].slice(0,S(a[1]));throw new o(t,"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,t,n),h(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 ie(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,t,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=S(r[1].field("minsize"))),r[1].hasField("metadata")&&(s.returnMetadata=E(r[1].field("metadata"))),r[1].hasField("maxsize")&&(s.maxsize=S(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(t,"InvalidParameter",n);if(N(r[0])){const e=r[0]._layer;let n;if(h(e))n=e;else{if(null==e||!G(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(t,"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,t,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===ie(l))throw new o(t,"InvalidParameter",n);if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);const m=r._layer;let p;if(h(m))p=m;else{if(null==m||!G(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 I=p.serviceUrl();if(!I)return null;I=I.endsWith("/")?I+w[0].relatedTableId.toString():I+"/"+w[0].relatedTableId.toString();const F=await c(I,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=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new z({parentfeatureset:F})}const T=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:r.field(w[0].keyField)},F.filter(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,t,n);const s=a[0],l=r(g(x(a[1],""))),f=ne(a[2])?g(a[2]):null;if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);let u=s._layer;if(u instanceof Q&&(u=d(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)),null===u)return null;if(!1===h(u))return null;await u.load();const c=u.serviceUrl(),p=await m(c,t.spatialReference,!0);if(p.unVersion>=8)return await pe(u,s,l,f,p,t,n);const w=p.associations;let I=null,F=null,b=!1;if(null!==f&&""!==f&&void 0!==f){for(const e of p.terminals)e.terminalName===f&&(F=e.terminalId);null===F&&(b=!0)}const T=w.getFieldsIndex(),D=T.get("TOGLOBALID").name,E=T.get("FROMGLOBALID").name,A=T.get("TOTERMINALID").name,v=T.get("FROMTERMINALID").name,S=T.get("FROMNETWORKSOURCEID").name,L=T.get("TONETWORKSOURCEID").name,C=T.get("ASSOCIATIONTYPE").name,M=T.get("ISCONTENTVISIBLE").name,R=T.get("OBJECTID").name;for(const t of u.fields)if("global-id"===t.type){I=s.field(t.name);break}let O=null,z=new k(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new k(new J({name:"side",alias:"side",type:"string"}),q.create("''",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));const H="globalid",G="globalId",_={};for(const t in p.lkp)_[t]=p.lkp[t].sourceId;const B=new Z(new J({name:"classname",alias:"classname",type:"string"}),null,_);let K="";switch(l){case"midspan":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (5))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new k(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),z=p.unVersion>=4?new U(P.findField(w.fields,T.get("PERCENTALONG").name)):new k(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (4,6))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new k(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new k(new J({name:"side",alias:"side",type:"string"}),q.create(`CASE WHEN (${C}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${D}='@T'`,t=`${E}='@T'`;null!==F&&(e+=` AND ${A}=@A`,t+=` AND ${v}=@A`),K="(("+e+") OR ("+t+"))",K=j(K,"@T",I??""),e=j(e,"@T",I??""),null!==F&&(e=j(e,"@A",F.toString()),K=j(K,"@A",F.toString())),B.codefield=q.create("CASE WHEN "+e+` THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const n=V(P.findField(w.fields,E));n.name=H,n.alias=H,O=new k(n,q.create("CASE WHEN "+e+` THEN ${E} ELSE ${D} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"container":K=`${D}='${I}' AND ${C} = 2`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,H);break;case"content":K=`(${E}='${I}' AND ${C} = 2)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,H);break;case"structure":K=`(${D}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,G);break;case"attached":K=`(${E}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,G);break;default:throw new o(t,"InvalidParameter",n)}b&&(K="1 <> 1");return new P({parentfeatureset:w,adaptedFields:[new U(P.findField(w.fields,R)),new U(P.findField(w.fields,M)),O,W,B,z],extraFilter:K?q.create(K,{fieldsIndex:w.getFieldsIndex(),timeZone:w.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,t,n),!h(s[0]))throw new o(t,"InvalidParameter",n);const l=await s[0].load(),f=[],d=[];let u=!1,c=[];if(ne(s[1]))c.push(s[1]);else if(s[1]instanceof i)c.push(s[1]);else if(ie(s[1]))c=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);c=s[1].toArray()}for(const e of c)if(ne(e)){const t=q.create(g(e),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";f.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(u=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",a=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(u=!0),!i)throw new o(t,"InvalidParameter",n);f.push({name:i,expression:q.create(a||i,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],ne(s[2]))c.push(s[2]);else if(ie(s[2]))c=s[2];else if(A(s[2]))c=s[2].toArray();else{if(!(s[2]instanceof i))throw new o(t,"InvalidParameter",n);c.push(s[2])}for(const e of c){if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"",a=e.hasField("statistic")?e.field("statistic"):"",r=e.hasField("expression")?e.field("expression"):"";if(!(i&&a&&ne(a)&&r))throw new o(t,"InvalidParameter",n);d.push({name:i,statistic:a,expression:q.create(r,{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)oe(n.expression,e,t);for(const n of d)oe(n.expression,e,t);return s[0].groupby(f,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(h(s[0])){y(s,2,2,t,n);const a=await s[0].load(),r=[];let l=[];if(ne(s[1]))l.push(s[1]);else if(s[1]instanceof i)l.push(s[1]);else if(ie(s[1]))l=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);l=s[1].toArray()}let f=!1;for(const e of l)if(ne(e)){const t=q.create(g(e),{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";r.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(f=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",s=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(f=!0),!i)throw new o(t,"InvalidParameter",n);r.push({name:i,expression:q.create(s||i,{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)oe(n.expression,e,t);return s[0].groupby(r,[])}return re(s)})},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{if(y(r,1,1,t,n),!h(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,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=await a[0].load(),i=a[1];if(!ae(i))throw new o(t,"InvalidParameter",n);if(e.subtypeField){const t=q.create(`${e.subtypeField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new o(t,"FeatureSetDoesNotHaveSubtypes",n);const r=q.create(`${e.typeIdField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:r})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filterbysubtypecode",min:2,max:2})}}export{ye as registerFunctions};
5
+ 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 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 I,m as h,u as g,N as F,K as b,e as T,l as D,J as x,H as E,k as N,j as A,i as v,s as S,L,Z as j}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as k,FieldRename as $,AdaptedFeatureSet as P,OriginalField as U}from"../featureset/actions/Adapted.js";import M from"../featureset/actions/AttributeFilter.js";import R from"../featureset/actions/OrderBy.js";import O from"../featureset/actions/Top.js";import z from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import H from"../featureset/support/OrderbyClause.js";import{isSupportedLayer as G,cloneField as V}from"../featureset/support/shared.js";import{isSingleField as _}from"../featureset/support/sqlUtils.js";import{calculateStat as B}from"./fieldStats.js";import{isPromiseLike as K}from"../../core/promiseUtils.js";import q from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";import{queryAssociations as X}from"../../rest/networks/queryAssociations.js";import ee from"../../rest/networks/support/NetworkElement.js";import te from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ne,isArray as ie,isInteger as ae}from"../../support/guards.js";function re(e){if(1===e.length){if(ie(e[0]))return B("distinct",e[0],-1);if(A(e[0]))return B("distinct",e[0].toArray(),-1)}return B("distinct",e,-1)}function oe(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 se(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function le(e){if(null===e)return null;const t={type:se(e,"type",""),name:se(e,"name","")};if("range"===t.type)t.range=se(e,"range",[]);else{t.codedValues=[];for(const n of se(e,"codedValues",[]))t.codedValues.push({name:se(n,"name",""),code:se(n,"code",null)})}return t}function fe(e){if(null===e)return null;const t={},n=se(e,"wkt");null!==n&&(t.wkt=n);const i=se(e,"wkid");return null!==i&&(t.wkid=i),t}function de(e){if(null===e)return null;const t={hasZ:se(e,"hasz",!1),hasM:se(e,"hasm",!1)},n=se(e,"spatialreference");null!=n&&(t.spatialReference=fe(n));const i=se(e,"x",null);if(null!==i)return t.x=i,t.y=se(e,"y",null),t.hasZ&&(t.z=se(e,"z",null)),t.hasM&&(t.m=se(e,"m",null)),t;const a=se(e,"rings",null);if(null!==a)return t.rings=a,t;const r=se(e,"paths",null);if(null!==r)return t.paths=r,t;const o=se(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=se(e,s,null);null!==n&&(t[s]=n)}return t}function ue(e,t){for(const n of t)if(n===e)return!0;return!1}function ce(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ue(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==ie(e.layerDefinition.fields)&&!1!==ie(e.featureSet.features))))}function me(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function pe(t,n,i,a,r,s,l){const f=await t.getFeatureSetInfo();if(null===(f?.layerId??null))return null;if(!r.layerIdLookup.get(f.layerId))return null;const u=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),c=[];switch(i){case"connected":c.push("connectivity"),c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity"),c.push("junction-edge-midspan-connectivity"),c.push("junction-junction-connectivity");break;case"container":case"content":c.push("containment");break;case"structure":case"attached":c.push("attachment");break;case"junctionedge":c.push("junction-edge-from-connectivity"),c.push("junction-edge-to-connectivity");break;case"midspan":c.push("junction-edge-midspan-connectivity");break;default:throw new o(s,"InvalidParameter",l)}let m=null,p=!1;if(null!==a&&""!==a&&void 0!==a){for(const e of r.terminals)e.terminalName===a&&(m=e.terminalId);null===m&&(p=!0)}const y=[];if(!p){const a=new ee({globalId:n.field(t.globalIdField),networkSourceId:r.layerIdLookup.get(f.layerId).sourceId,...m?{terminalId:m}:""}),o=await X(u,new te({types:c,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??"";y.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 w=new Q({source:y,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new J({name:"objectId",alias:"objectId",type:"oid"}),new J({name:"globalId",alias:"globalId",type:"global-id"}),new J({name:"percentAlong",alias:"percentAlong",type:"double"}),new J({name:"side",alias:"side",type:"string"}),new J({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new J({name:"className",alias:"className",type:"string"})]});return d(w)}function ye(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,n,a),w(s[0]))return"Unknown";if(I(s[0]))return"Unknown";if(h(s[0])){if(await s[0].load(),1===s.length||null===s[1])return s[0].datesInUnknownTimezone?me("unknown"):me(s[0].dateFieldsTimeZone);if(!(s[1]instanceof i)||!1===s[1].hasField("type"))throw new o(n,"InvalidParameter",a);const e=s[1].field("type");if(!1===ne(e))throw new o(n,"InvalidParameter",a);switch(g(e).toLowerCase()){case"preferredtimezone":return me(s[0].preferredTimeZone);case"editfieldsinfo":return me(s[0].editFieldsInfo?.timeZone??null);case"timeinfo":return me(s[0].timeInfo?.timeZone??null);case"field":if(s[1].hasField("fieldname")&&ne(s[1].field("fieldname")))return me(s[0].fieldTimeZone(g(s[1].field("fieldname"))))}throw new o(n,"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,i,a)=>{y(a,1,3,t,n);const r=a[0];if(T(r)){if(1===a.length)return r.toSQLWithKeyword();if(2===a.length)return r.changeTimeZone(g(a[1])).toSQLWithKeyword();throw new o(t,"InvalidParameter",n)}if(I(r))return r.toSQLWithKeyword();if(h(r)){if(3!==a.length)throw new o(t,"InvalidParameter",n);await r.load();const e=g(a[1]);if(I(a[2]))return a[2].toSQLWithKeyword();if(!1===T(a[2]))throw new o(t,"InvalidParameter",n);const i=r.fieldTimeZone(e);return null==i?a[2].toSQLWithKeyword():a[2].changeTimeZone(i).toSQLWithKeyword()}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,(e,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetById(e,r,i)}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"featuresetbyid",min:2,max:4});const B=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,t,n),N(a[0])){const e=null==a[1]?"datasource":B.lookup(g(a[1]));return l(a[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new o(t,"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,t,i),null===r[0])throw new o(t,"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===ie(a))throw new o(t,"InvalidParameter",i);let l;return l=t.services?.portal?t.services.portal:Y.getDefault(),l=C(r[0],l),f(e,n,t.spatialReference,a,s,l,t.lrucache,t.interceptor)}if(!1===ne(r[0]))throw new o(t,"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===ie(d))throw new o(t,"InvalidParameter",i);return f(s,l,t.spatialReference,d,u,t.services?.portal??Y.getDefault(),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,i,a)=>{if(y(a,2,4,t,n),D(a[0])){const e=g(a[1]);let i=x(a[2],null);const r=E(x(a[3],!0));if(null===i&&(i=["*"]),!1===ie(i))throw new o(t,"InvalidParameter",n);return a[0].featureSetByName(e,r,i)}throw new o(t,"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,t,n);const s={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ne(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(t,"InvalidParameter",n);{const e=JSON.parse(r[0].castToText(!0)),i=se(e,"layerdefinition");if(null!==i){s.layerDefinition.geometryType=se(i,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.globalIdField=se(i,"globalidfield",""),s.layerDefinition.objectIdField=se(i,"objectidfield",""),s.layerDefinition.typeIdField=se(i,"typeidfield",""),s.layerDefinition.hasZ=!0===se(i,"hasz",!1),s.layerDefinition.hasM=!0===se(i,"hasm",!1);const t=se(i,"spatialreference");t&&(s.layerDefinition.spatialReference=fe(t));const n=[];for(const e of se(i,"fields",[])){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};n.push(t)}s.layerDefinition.fields=n;const a=se(e,"featureset");if(a){const e={};for(const t of n)e[t.name.toLowerCase()]=t.name;for(const t of se(a,"features",[])){const n={},i=se(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];s.featureSet.features.push({attributes:n,geometry:de(se(t,"geometry"))})}}}else{s.layerDefinition.hasZ=!0===se(e,"hasz",!1),s.layerDefinition.hasM=!0===se(e,"hasm",!1),s.layerDefinition.geometryType=se(e,"geometrytype",""),s.featureSet.geometryType=s.layerDefinition.geometryType,s.layerDefinition.objectIdField=se(e,"objectidfieldname",""),s.layerDefinition.typeIdField=se(e,"typeidfieldname","");const i=se(e,"spatialreference");i&&(s.layerDefinition.spatialReference=fe(i));const a=[],r=se(e,"fields",null);if(!ie(r))throw new o(t,"InvalidParameter",n);for(const e of r){const t={name:se(e,"name",""),alias:se(e,"alias",""),type:se(e,"type",""),nullable:se(e,"nullable",!0),editable:se(e,"editable",!0),length:se(e,"length",null),domain:le(se(e,"domain"))};a.push(t)}s.layerDefinition.fields=a;const l={};for(const e of a)l[e.name.toLowerCase()]=e.name;let f=se(e,"features",null);if(ie(f))for(const e of f){const t={},n=se(e,"attributes",{});for(const e in n)t[l[e.toLowerCase()]]=n[e];s.featureSet.features.push({attributes:t,geometry:de(se(e,"geometry",null))})}else f=null,s.featureSet.features=f}}}if(!1===ce(s))throw new o(t,"InvalidParameter",n);return s.layerDefinition.geometryType||(s.layerDefinition.geometryType="esriGeometryNull"),W.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,t,n),ie(r[0])||A(r[0])){const e=[];let i,a=r[0];if(a instanceof p&&(a=a.toArray()),!v(r[1]))throw new o(t,"InvalidParameter",n);i=r[1].createFunction(t);for(const t of a){const n=i(t);K(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(h(r[0])){const n=await r[0].load(),i=q.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 M({parentfeatureset:r[0],whereclause:i})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=new H(a[1]);return new R({parentfeatureset:a[0],orderbyclause:e})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,async(e,i,a)=>{if(y(a,2,2,t,n),h(a[0]))return new O({parentfeatureset:a[0],topnum:a[1]});if(ie(a[0]))return S(a[1])>=a[0].length?a[0].slice():a[0].slice(0,S(a[1]));if(A(a[0]))return S(a[1])>=a[0].length()?a[0].slice():a[0].slice(0,S(a[1]));throw new o(t,"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,t,n),h(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 ie(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,t,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=S(r[1].field("minsize"))),r[1].hasField("metadata")&&(s.returnMetadata=E(r[1].field("metadata"))),r[1].hasField("maxsize")&&(s.maxsize=S(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(t,"InvalidParameter",n);if(N(r[0])){const e=r[0]._layer;let n;if(h(e))n=e;else{if(null==e||!G(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(t,"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,t,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===ie(l))throw new o(t,"InvalidParameter",n);if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);const m=r._layer;let p;if(h(m))p=m;else{if(null==m||!G(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 I=p.serviceUrl();if(!I)return null;I=I.endsWith("/")?I+w[0].relatedTableId.toString():I+"/"+w[0].relatedTableId.toString();const F=await c(I,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=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new z({parentfeatureset:F})}const T=q.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:r.field(w[0].keyField)},F.filter(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,t,n);const s=a[0],l=r(g(x(a[1],""))),f=ne(a[2])?g(a[2]):null;if(null===a[0])return null;if(!N(a[0]))throw new o(t,"InvalidParameter",n);let u=s._layer;if(u instanceof Q&&(u=d(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)),null===u)return null;if(!1===h(u))return null;await u.load();const c=u.serviceUrl(),p=await m(c,t.spatialReference,!0);if(p.unVersion>=8)return await pe(u,s,l,f,p,t,n);const w=p.associations;let I=null,F=null,b=!1;if(null!==f&&""!==f&&void 0!==f){for(const e of p.terminals)e.terminalName===f&&(F=e.terminalId);null===F&&(b=!0)}const T=w.getFieldsIndex(),D=T.get("TOGLOBALID").name,E=T.get("FROMGLOBALID").name,A=T.get("TOTERMINALID").name,v=T.get("FROMTERMINALID").name,S=T.get("FROMNETWORKSOURCEID").name,L=T.get("TONETWORKSOURCEID").name,C=T.get("ASSOCIATIONTYPE").name,M=T.get("ISCONTENTVISIBLE").name,R=T.get("OBJECTID").name;for(const t of u.fields)if("global-id"===t.type){I=s.field(t.name);break}let O=null,z=new Z(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new Z(new J({name:"side",alias:"side",type:"string"}),q.create("''",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));const H="globalid",G="globalId",_={};for(const t in p.lkp)_[t]=p.lkp[t].sourceId;const B=new k(new J({name:"classname",alias:"classname",type:"string"}),null,_);let K="";switch(l){case"midspan":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (5))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new Z(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),z=p.unVersion>=4?new U(P.findField(w.fields,T.get("PERCENTALONG").name)):new Z(new J({name:"percentalong",alias:"percentalong",type:"double"}),q.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{K=`((${D}='${I}') OR ( ${E}='${I}')) AND (${C} IN (4,6))`,B.codefield=q.create(`CASE WHEN (${D}='${I}') THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=V(P.findField(w.fields,E));e.name=H,e.alias=H,O=new Z(e,q.create(`CASE WHEN (${E}='${I}') THEN ${D} ELSE ${E} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new Z(new J({name:"side",alias:"side",type:"string"}),q.create(`CASE WHEN (${C}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${D}='@T'`,t=`${E}='@T'`;null!==F&&(e+=` AND ${A}=@A`,t+=` AND ${v}=@A`),K="(("+e+") OR ("+t+"))",K=j(K,"@T",I??""),e=j(e,"@T",I??""),null!==F&&(e=j(e,"@A",F.toString()),K=j(K,"@A",F.toString())),B.codefield=q.create("CASE WHEN "+e+` THEN ${S} ELSE ${L} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const n=V(P.findField(w.fields,E));n.name=H,n.alias=H,O=new Z(n,q.create("CASE WHEN "+e+` THEN ${E} ELSE ${D} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"container":K=`${D}='${I}' AND ${C} = 2`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,H);break;case"content":K=`(${E}='${I}' AND ${C} = 2)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,H);break;case"structure":K=`(${D}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${A} = `+F.toString()),B.codefield=S,K="( "+K+" )",O=new $(P.findField(w.fields,E),H,G);break;case"attached":K=`(${E}='${I}' AND ${C} = 3)`,null!==F&&(K+=` AND ${v} = `+F.toString()),B.codefield=L,K="( "+K+" )",O=new $(P.findField(w.fields,D),H,G);break;default:throw new o(t,"InvalidParameter",n)}b&&(K="1 <> 1");return new P({parentfeatureset:w,adaptedFields:[new U(P.findField(w.fields,R)),new U(P.findField(w.fields,M)),O,W,B,z],extraFilter:K?q.create(K,{fieldsIndex:w.getFieldsIndex(),timeZone:w.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,t,n),!h(s[0]))throw new o(t,"InvalidParameter",n);const l=await s[0].load(),f=[],d=[];let u=!1,c=[];if(ne(s[1]))c.push(s[1]);else if(s[1]instanceof i)c.push(s[1]);else if(ie(s[1]))c=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);c=s[1].toArray()}for(const e of c)if(ne(e)){const t=q.create(g(e),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";f.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(u=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",a=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(u=!0),!i)throw new o(t,"InvalidParameter",n);f.push({name:i,expression:q.create(a||i,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],ne(s[2]))c.push(s[2]);else if(ie(s[2]))c=s[2];else if(A(s[2]))c=s[2].toArray();else{if(!(s[2]instanceof i))throw new o(t,"InvalidParameter",n);c.push(s[2])}for(const e of c){if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"",a=e.hasField("statistic")?e.field("statistic"):"",r=e.hasField("expression")?e.field("expression"):"";if(!(i&&a&&ne(a)&&r))throw new o(t,"InvalidParameter",n);d.push({name:i,statistic:a,expression:q.create(r,{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)oe(n.expression,e,t);for(const n of d)oe(n.expression,e,t);return s[0].groupby(f,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(h(s[0])){y(s,2,2,t,n);const a=await s[0].load(),r=[];let l=[];if(ne(s[1]))l.push(s[1]);else if(s[1]instanceof i)l.push(s[1]);else if(ie(s[1]))l=s[1];else{if(!A(s[1]))throw new o(t,"InvalidParameter",n);l=s[1].toArray()}let f=!1;for(const e of l)if(ne(e)){const t=q.create(g(e),{fieldsIndex:a.getFieldsIndex(),timeZone:a.dateFieldsTimeZoneDefaultUTC}),n=!0===_(t)?g(e):"%%%%FIELDNAME";r.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(f=!0)}else{if(!(e instanceof i))throw new o(t,"InvalidParameter",n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",s=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(f=!0),!i)throw new o(t,"InvalidParameter",n);r.push({name:i,expression:q.create(s||i,{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)oe(n.expression,e,t);return s[0].groupby(r,[])}return re(s)})},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,async(e,a,r)=>{if(y(r,1,1,t,n),!h(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,i,a)=>{if(y(a,2,2,t,n),h(a[0])){const e=await a[0].load(),i=a[1];if(!ae(i))throw new o(t,"InvalidParameter",n);if(e.subtypeField){const t=q.create(`${e.subtypeField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new o(t,"FeatureSetDoesNotHaveSubtypes",n);const r=q.create(`${e.typeIdField}= ${a[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new M({parentfeatureset:a[0],whereclause:r})}throw new o(t,"InvalidParameter",n)})},e.signatures.push({name:"filterbysubtypecode",min:2,max:2})}}export{ye as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,Q as r,u as o,m as i,a1 as c,V as s,K as d,T as u,a2 as m,S as f,a3 as l,J as y,t as v,U 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,n,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(n,"InvalidParameter",s)})},p.functions.subtypes=function(r,o){return p.standardFunctionAsync(r,o,async(c,u,m)=>{if(e(m,1,1,r,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(r,"InvalidParameter",o)})},p.functions.domainname=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,f)=>{if(e(f,2,4,n,r),t(f[0]))return u(f[0],o(f[1]),f[2],void 0===f[3]?void 0:f[3]);if(i(f[0])){await f[0]._ensureLoaded();const n=c(o(f[1]),f[0],null,void 0===f[3]?void 0:f[3]);return m(n,f[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domainname",min:2,max:4}),p.functions.domaincode=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,u)=>{if(e(u,2,4,n,r),t(u[0]))return f(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=c(o(u[1]),u[0],null,void 0===u[3]?void 0:u[3]);return l(n,u[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domaincode",min:2,max:4}),p.functions.text=function(n,t){return p.standardFunctionAsync(n,t,async(r,o,c)=>{if(e(c,1,2,n,t),i(c[0])){const e=y(c[1],"");if(""===e)return c[0].castToText();if("schema"===e.toLowerCase())return c[0].convertToText("schema",r.abortSignal);if("featureset"===e.toLowerCase())return c[0].convertToText("featureset",r.abortSignal);throw new a(n,"InvalidParameter",t)}return v(c[0],c[1])})},p.functions.gdbversion=function(n,r){return p.standardFunctionAsync(n,r,async(o,c,s)=>{if(e(s,1,1,n,r),t(s[0]))return s[0].gdbVersion();if(i(s[0])){return(await s[0].load()).gdbVersion}throw new a(n,"InvalidParameter",r)})},p.functions.schema=function(r,o){return p.standardFunctionAsync(r,o,async(c,s,u)=>{if(e(u,1,1,r,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(r,"InvalidParameter",o)})})}export{T as registerFunctions};
5
+ import n from"../Dictionary.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as e,k as t,Q as r,u as o,m as i,a2 as c,V as s,K as d,T as u,a3 as m,S as f,a4 as l,J as y,t as v,U 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,n,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(n,"InvalidParameter",s)})},p.functions.subtypes=function(r,o){return p.standardFunctionAsync(r,o,async(c,u,m)=>{if(e(m,1,1,r,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(r,"InvalidParameter",o)})},p.functions.domainname=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,f)=>{if(e(f,2,4,n,r),t(f[0]))return u(f[0],o(f[1]),f[2],void 0===f[3]?void 0:f[3]);if(i(f[0])){await f[0]._ensureLoaded();const n=c(o(f[1]),f[0],null,void 0===f[3]?void 0:f[3]);return m(n,f[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domainname",min:2,max:4}),p.functions.domaincode=function(n,r){return p.standardFunctionAsync(n,r,async(s,d,u)=>{if(e(u,2,4,n,r),t(u[0]))return f(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=c(o(u[1]),u[0],null,void 0===u[3]?void 0:u[3]);return l(n,u[2])}throw new a(n,"InvalidParameter",r)})},p.signatures.push({name:"domaincode",min:2,max:4}),p.functions.text=function(n,t){return p.standardFunctionAsync(n,t,async(r,o,c)=>{if(e(c,1,2,n,t),i(c[0])){const e=y(c[1],"");if(""===e)return c[0].castToText();if("schema"===e.toLowerCase())return c[0].convertToText("schema",r.abortSignal);if("featureset"===e.toLowerCase())return c[0].convertToText("featureset",r.abortSignal);throw new a(n,"InvalidParameter",t)}return v(c[0],c[1])})},p.functions.gdbversion=function(n,r){return p.standardFunctionAsync(n,r,async(o,c,s)=>{if(e(s,1,1,n,r),t(s[0]))return s[0].gdbVersion();if(i(s[0])){return(await s[0].load()).gdbVersion}throw new a(n,"InvalidParameter",r)})},p.functions.schema=function(r,o){return p.standardFunctionAsync(r,o,async(c,s,u)=>{if(e(u,1,1,r,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(r,"InvalidParameter",o)})})}export{T as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e,v as t,x as r}from"../../chunks/languageUtils.js";import{isNumber as n,isString as s}from"../../support/guards.js";function a(e){let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t/e.length}function u(e){const t=a(e);let r=0;for(let n=0;n<e.length;n++)r+=(t-e[n])**2;return r/e.length}function c(e){let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t}function o(e,a){const u=[],c={},o=[];for(let i=0;i<e.length;i++){if(void 0!==e[i]&&null!==e[i]&&e[i]!==t){const t=e[i];if(n(t)||s(t))void 0===c[t]&&(u.push(t),c[t]=1);else{let e=!1;for(let n=0;n<o.length;n++)!0===r(o[n],t)&&(e=!0);!1===e&&(o.push(t),u.push(t))}}if(u.length>=a&&-1!==a)return u}return u}function i(e){switch(e.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function l(t,r,n=1e3){switch(t.toLowerCase()){case"distinct":return o(r,n);case"avg":case"mean":return a(e(r));case"min":return Math.min.apply(Math,e(r));case"sum":return c(e(r));case"max":return Math.max.apply(Math,e(r));case"stdev":case"stddev":return Math.sqrt(u(e(r)));case"var":case"variance":return u(e(r));case"count":return r.length}return 0}export{l as calculateStat,i as decodeStatType};
5
+ import{$ as e,v as t,x as r}from"../../chunks/languageUtils.js";import{isNumber as n,isString as s}from"../../support/guards.js";function a(e){let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t/e.length}function u(e){const t=a(e);let r=0;for(let n=0;n<e.length;n++)r+=(t-e[n])**2;return r/e.length}function c(e){let t=0;for(let r=0;r<e.length;r++)t+=e[r];return t}function o(e,a){const u=[],c={},o=[];for(let i=0;i<e.length;i++){if(void 0!==e[i]&&null!==e[i]&&e[i]!==t){const t=e[i];if(n(t)||s(t))void 0===c[t]&&(u.push(t),c[t]=1);else{let e=!1;for(let n=0;n<o.length;n++)!0===r(o[n],t)&&(e=!0);!1===e&&(o.push(t),u.push(t))}}if(u.length>=a&&-1!==a)return u}return u}function i(e){switch(e.toLowerCase()){case"distinct":return"distinct";case"avg":case"mean":return"avg";case"min":return"min";case"sum":return"sum";case"max":return"max";case"stdev":case"stddev":return"stddev";case"var":case"variance":return"var";case"count":return"count"}return""}function l(t,r,n=1e3){switch(t.toLowerCase()){case"distinct":return o(r,n);case"avg":case"mean":return a(e(r));case"min":return Math.min.apply(Math,e(r));case"sum":return c(e(r));case"max":return Math.max.apply(Math,e(r));case"stdev":case"stddev":return Math.sqrt(u(e(r)));case"var":case"variance":return u(e(r));case"count":return r.length}return 0}export{l as calculateStat,i as decodeStatType};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r}from"../executionError.js";import a from"../Feature.js";import i from"../ImmutablePointArray.js";import{B as l,j as o,D as s,W as f,C as c,k as u,v as m,n as p,h as w,u as h,e as R,g,f as y,i as d,d as P,K as v,X as I,r as b,x as O}from"../../chunks/languageUtils.js";import{angle2D as j,angleBetween2D as N,bearing2D as S,bearingBetween2D as x}from"./centroid.js";import{constructGeometryFromDictionary as J}from"../geometry/constructors.js";import F from"../../geometry/Extent.js";import k from"../../geometry/Geometry.js";import Z from"../../geometry/Multipoint.js";import W from"../../geometry/Point.js";import z from"../../geometry/Polygon.js";import A from"../../geometry/Polyline.js";import{isClockwise as q}from"../../geometry/support/coordsUtils.js";import{fromJSON as D}from"../../geometry/support/jsonUtils.js";import{isArray as M,isString as G,isNumber as L,isBoolean as U}from"../../support/guards.js";function _(_,C){_.ringisclockwise=function(e,t){return C(e,t,(n,a,s)=>{l(s,1,1,e,t);let f=[];if(null===s[0])return!1;if(M(s[0]))for(const i of s[0]){if(!(i instanceof W))throw new r(e,"InvalidParameter",t);f.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(s[0]instanceof i)f=s[0]._elements;else{if(!o(s[0]))throw new r(e,"InvalidParameter",t);for(const n of s[0].toArray()){if(!(n instanceof W))throw new r(e,"InvalidParameter",t);f.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(f.length<3)&&q(f)})},_.polygon=function(e,t){return C(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(J(o[0],e.spatialReference,"polygon"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof z)c=D(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(e,"WrongSpatialReference",t);return f(c)})},_.polyline=function(e,t){return C(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(J(o[0],e.spatialReference,"polyline"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof A)c=D(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(e,"WrongSpatialReference",t);return f(c)})},_.point=function(e,t){return C(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(J(o[0],e.spatialReference,"point"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof W)c=D(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(e,"WrongSpatialReference",t);return f(c)})},_.multipoint=function(e,t){return C(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,t),o[0]instanceof n){const t=s(J(o[0],e.spatialReference,"multipoint"),e.spatialReference);if(null==t)return null;c=t}else if(o[0]instanceof Z)c=D(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(e,"WrongSpatialReference",t);return f(c)})},_.extent=function(e,t){return C(e,t,(a,i,o)=>{o=c(o),l(o,1,1,e,t);let u=null;if(o[0]instanceof n)u=s(J(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=D(e)}else if(o[0]instanceof z)u=D(o[0].extent?.toJSON());else if(o[0]instanceof A)u=D(o[0].extent?.toJSON());else if(o[0]instanceof Z)u=D(o[0].extent?.toJSON());else if(o[0]instanceof F)u=D(o[0].toJSON());else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),u=s(new F(t),e.spatialReference)}if(null!==u&&!1===u.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(u)})},_.geometry=function(e,t){return C(e,t,(a,i,o)=>{l(o,1,1,e,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(J(o[0],e.spatialReference),e.spatialReference);else{const t=JSON.parse(o[0]);t&&!t.spatialReference&&(t.spatialReference=e.spatialReference),c=s(D(t),e.spatialReference)}if(null!==c&&!1===c.spatialReference.equals(e.spatialReference))throw new r(e,"WrongSpatialReference",t);return f(c)})},_.setgeometry=function(e,t){return C(e,t,(n,a,i)=>{if(l(i,2,2,e,t),!u(i[0]))throw new r(e,"InvalidParameter",t);if(!0===i[0].immutable)throw new r(e,"Immutable",t);if(!(i[1]instanceof k||null===i[1]))throw new r(e,"InvalidParameter",t);return i[0]._geometry=i[1],m})},_.feature=function(e,t){return C(e,t,(i,l,o)=>{if(0===o.length)throw new r(e,"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 k)f=a.createFromGraphicLikeObject(o[0],null,null,e.timeZone);else{if(!(o[0]instanceof n))throw new r(e,"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=J(n,e.spatialReference);else{if(null!=n&&!w(n))throw new r(e,"InvalidParameter",t);l=n}if(p(i))s=a.parseAttributesFromDictionary(i);else{if(null!=i)throw new r(e,"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 k)i=o[0];else{if(!(o[0]instanceof n))throw new r(e,"InvalidParameter",t);i=J(o[0],e.spatialReference)}if(null!==o[1]){if(!(o[1]instanceof n))throw new r(e,"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 k)i=o[0];else{if(!(o[0]instanceof n))throw new r(e,"InvalidParameter",t);i=J(o[0],e.spatialReference)}for(let n=1;n<o.length;n+=2){const a=h(o[n]),i=o[n+1];if(!(null==i||G(i)||isNaN(i)||R(i)||L(i)||g(i)||y(i)||U(i)))throw new r(e,"InvalidParameter",t);if(d(i)||!1===P(i))throw new r(e,"InvalidParameter",t);l[a]=i===m?null:i}f=a.createFromGraphicLikeObject(i,l,null,e.timeZone)}return f._geometry=s(f.geometry(),e.spatialReference),f.immutable=!1,f})},_.dictionary=function(e,t){return C(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(e,"InvalidParameter",t)}if(1===l.length&&l[0]instanceof k)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(e,"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(e,"InvalidParameter",t)}if(1===l.length&&(p(l[0])||I(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(e,"InvalidParameter",t)}if(2===l.length&&l[0]instanceof n&&U(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(e,"InvalidParameter",t)}if(l.length%2!=0)throw new r(e,"WrongNumberOfParameters",t);const s=Object.create(null);for(let n=0;n<l.length;n+=2){const a=h(l[n]),i=l[n+1];if(!(null==i||G(i)||isNaN(i)||R(i)||L(i)||U(i)||y(i)||g(i)||M(i)||o(i)))throw new r(e,"InvalidParameter",t);if(d(i))throw new r(e,"InvalidParameter",t);s[a]=i===m?null:i}const f=new n(s);return f.immutable=!1,f})},_.haskey=function(t,a){return C(t,a,(i,o,s)=>{l(s,2,2,t,a);const f=h(s[1]);if(b(s[0])||s[0]instanceof n)return s[0].hasField(f);if(s[0]instanceof k){const t=e(s[0],f,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,"InvalidParameter",a)})},_.hasvalue=function(e,n){return C(e,n,(r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1])))},_.indexof=function(e,t){return C(e,t,(n,a,i)=>{l(i,2,2,e,t);const s=i[1];if(M(i[0])){for(let e=0;e<i[0].length;e++)if(O(s,i[0][e]))return e;return-1}if(o(i[0])){const e=i[0].length();for(let t=0;t<e;t++)if(O(s,i[0].get(t)))return t;return-1}throw new r(e,"InvalidParameter",t)})},_.angle=function(e,t){return C(e,t,(n,a,i)=>{if(i=c(i),l(i,2,3,e,t),!(i[0]instanceof W))throw new r(e,"InvalidParameter",t);if(!(i[1]instanceof W))throw new r(e,"InvalidParameter",t);if(i.length>2&&!(i[2]instanceof W))throw new r(e,"InvalidParameter",t);return 2===i.length?j(i[0],i[1]):N(i[0],i[1],i[2])})},_.bearing=function(e,t){return C(e,t,(n,a,i)=>{if(i=c(i),l(i,2,3,e,t),!(i[0]instanceof W))throw new r(e,"InvalidParameter",t);if(!(i[1]instanceof W))throw new r(e,"InvalidParameter",t);if(i.length>2&&!(i[2]instanceof W))throw new r(e,"InvalidParameter",t);return 2===i.length?S(i[0],i[1]):x(i[0],i[1],i[2])})}}export{_ as registerFunctions};
5
+ import{geometryMember as e,getNestedOptionalValue as t}from"../containerUtils.js";import n from"../Dictionary.js";import{ArcadeExecutionError as r}from"../executionError.js";import a from"../Feature.js";import i from"../ImmutablePointArray.js";import{B as l,j as o,D as s,W as f,C as c,k as u,v as m,n as p,h as w,u as h,e as R,g,f as y,i as d,d as P,K as v,X as I,Y as b,r as O,x 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 W from"../../geometry/Multipoint.js";import z from"../../geometry/Point.js";import A from"../../geometry/Polygon.js";import q from"../../geometry/Polyline.js";import{isClockwise as D}from"../../geometry/support/coordsUtils.js";import{fromJSON as M}from"../../geometry/support/jsonUtils.js";import{isArray as G,isString as L,isNumber as U,isBoolean as _}from"../../support/guards.js";function C(C,E){C.ringisclockwise=function(e,t){return E(e,t,(n,a,s)=>{l(s,1,1,e,t);let f=[];if(null===s[0])return!1;if(G(s[0]))for(const i of s[0]){if(!(i instanceof z))throw new r(e,"InvalidParameter",t);f.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(s[0]instanceof i)f=s[0]._elements;else{if(!o(s[0]))throw new r(e,"InvalidParameter",t);for(const n of s[0].toArray()){if(!(n instanceof z))throw new r(e,"InvalidParameter",t);f.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}}return!(f.length<3)&&D(f)})},C.polygon=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,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(e,"WrongSpatialReference",t);return f(c)})},C.polyline=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,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(e,"WrongSpatialReference",t);return f(c)})},C.point=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,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 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(e,"WrongSpatialReference",t);return f(c)})},C.multipoint=function(e,t){return E(e,t,(a,i,o)=>{let c;if(l(o,1,1,e,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 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(e,"WrongSpatialReference",t);return f(c)})},C.extent=function(e,t){return E(e,t,(a,i,o)=>{o=c(o),l(o,1,1,e,t);let u=null;if(o[0]instanceof n)u=s(F(o[0],e.spatialReference),e.spatialReference);else if(o[0]instanceof z){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 W)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(e,"WrongSpatialReference",t);return f(u)})},C.geometry=function(e,t){return E(e,t,(a,i,o)=>{l(o,1,1,e,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(e,"WrongSpatialReference",t);return f(c)})},C.setgeometry=function(e,t){return E(e,t,(n,a,i)=>{if(l(i,2,2,e,t),!u(i[0]))throw new r(e,"InvalidParameter",t);if(!0===i[0].immutable)throw new r(e,"Immutable",t);if(!(i[1]instanceof Z||null===i[1]))throw new r(e,"InvalidParameter",t);return i[0]._geometry=i[1],m})},C.feature=function(e,t){return E(e,t,(i,l,o)=>{if(0===o.length)throw new r(e,"WrongNumberOfParameters",t);let f;if(1===o.length)if(L(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(e,"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(e,"InvalidParameter",t);l=n}if(p(i))s=a.parseAttributesFromDictionary(i);else{if(null!=i)throw new r(e,"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(e,"InvalidParameter",t);i=F(o[0],e.spatialReference)}if(null!==o[1]){if(!(o[1]instanceof n))throw new r(e,"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(e,"InvalidParameter",t);i=F(o[0],e.spatialReference)}for(let n=1;n<o.length;n+=2){const a=h(o[n]),i=o[n+1];if(!(null==i||L(i)||isNaN(i)||R(i)||U(i)||g(i)||y(i)||_(i)))throw new r(e,"InvalidParameter",t);if(d(i)||!1===P(i))throw new r(e,"InvalidParameter",t);l[a]=i===m?null:i}f=a.createFromGraphicLikeObject(i,l,null,e.timeZone)}return f._geometry=s(f.geometry(),e.spatialReference),f.immutable=!1,f})},C.dictionary=function(e,t){return E(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&&L(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(e,"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(e,"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(e,"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(e,"InvalidParameter",t)}if(2===l.length&&l[0]instanceof n&&_(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(e,"InvalidParameter",t)}if(l.length%2!=0)throw new r(e,"WrongNumberOfParameters",t);const s=Object.create(null);for(let n=0;n<l.length;n+=2){const a=h(l[n]),i=l[n+1];if(!(null==i||L(i)||isNaN(i)||R(i)||U(i)||_(i)||y(i)||g(i)||G(i)||o(i)))throw new r(e,"InvalidParameter",t);if(d(i))throw new r(e,"InvalidParameter",t);s[a]=i===m?null:i}const f=new n(s);return f.immutable=!1,f})},C.haskey=function(t,a){return E(t,a,(i,o,s)=>{l(s,2,2,t,a);const f=h(s[1]);if(O(s[0])||s[0]instanceof n)return s[0].hasField(f);if(s[0]instanceof Z){const t=e(s[0],f,null,null,2);return!t||"notfound"!==t.keystate}throw new r(t,"InvalidParameter",a)})},C.hasvalue=function(e,n){return E(e,n,(r,a,i)=>(l(i,2,2,e,n),null!=t(i[0],i[1])))},C.indexof=function(e,t){return E(e,t,(n,a,i)=>{l(i,2,2,e,t);const s=i[1];if(G(i[0])){for(let e=0;e<i[0].length;e++)if(j(s,i[0][e]))return e;return-1}if(o(i[0])){const e=i[0].length();for(let t=0;t<e;t++)if(j(s,i[0].get(t)))return t;return-1}throw new r(e,"InvalidParameter",t)})},C.angle=function(e,t){return E(e,t,(n,a,i)=>{if(i=c(i),l(i,2,3,e,t),!(i[0]instanceof z))throw new r(e,"InvalidParameter",t);if(!(i[1]instanceof z))throw new r(e,"InvalidParameter",t);if(i.length>2&&!(i[2]instanceof z))throw new r(e,"InvalidParameter",t);return 2===i.length?N(i[0],i[1]):S(i[0],i[1],i[2])})},C.bearing=function(e,t){return E(e,t,(n,a,i)=>{if(i=c(i),l(i,2,3,e,t),!(i[0]instanceof z))throw new r(e,"InvalidParameter",t);if(!(i[1]instanceof z))throw new r(e,"InvalidParameter",t);if(i.length>2&&!(i[2]instanceof z))throw new r(e,"InvalidParameter",t);return 2===i.length?x(i[0],i[1]):J(i[0],i[1],i[2])})}}export{C as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import{B as n,e as r,g as t,f as u,Y as e,s as o,v as i,H as a,j as s}from"../../chunks/languageUtils.js";import{decimalAdjust as f}from"../../core/mathUtils.js";import{parse as c}from"../../core/number.js";import{isNumber as l,isBoolean as N,isArray as h,isString as m}from"../../support/guards.js";function p(p,M){function b(n,r,t){const u=o(n);return isNaN(u)?u:isNaN(r)||isNaN(t)||r>t?NaN:u<r?r:u>t?t:u}p.number=function(o,i){return M(o,i,(a,s,f)=>{n(f,1,2,o,i);const p=f[0];if(l(p))return p;if(null===p)return 0;if(r(p)||t(p)||u(p))return p.toNumber();if(N(p))return Number(p);if(h(p))return NaN;if(""===p)return Number(p);if(void 0===p)return Number(p);if(m(p)){if(void 0!==f[1]){let n=e(f[1],"‰","");return n=e(n,"¤",""),c(p,{pattern:n})}return Number(p.trim())}return Number(p)})},p.abs=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.abs(o(i[0]))))},p.acos=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.acos(o(i[0]))))},p.asin=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.asin(o(i[0]))))},p.atan=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.atan(o(i[0]))))},p.atan2=function(r,t){return M(r,t,(u,e,i)=>(n(i,2,2,r,t),Math.atan2(o(i[0]),o(i[1]))))},p.ceil=function(r,t){return M(r,t,(u,e,i)=>{if(n(i,1,2,r,t),2===i.length){let n=o(i[1]);return isNaN(n)&&(n=0),f("ceil",o(i[0]),-1*n)}return Math.ceil(o(i[0]))})},p.round=function(r,t){return M(r,t,(u,e,i)=>{if(n(i,1,2,r,t),2===i.length){let n=o(i[1]);return isNaN(n)&&(n=0),f("round",o(i[0]),-1*n)}return Math.round(o(i[0]))})},p.floor=function(r,t){return M(r,t,(u,e,i)=>{if(n(i,1,2,r,t),2===i.length){let n=o(i[1]);return isNaN(n)&&(n=0),f("floor",o(i[0]),-1*n)}return Math.floor(o(i[0]))})},p.cos=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.cos(o(i[0]))))},p.isnan=function(r,t){return M(r,t,(u,e,o)=>(n(o,1,1,r,t),"number"==typeof o[0]&&isNaN(o[0])))},p.exp=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.exp(o(i[0]))))},p.log=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.log(o(i[0]))))},p.pow=function(r,t){return M(r,t,(u,e,i)=>(n(i,2,2,r,t),o(i[0])**o(i[1])))},p.random=function(r,t){return M(r,t,(u,e,o)=>(n(o,0,0,r,t),Math.random()))},p.sin=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.sin(o(i[0]))))},p.sqrt=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.sqrt(o(i[0]))))},p.tan=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.tan(o(i[0]))))},p.isempty=function(r,t){return M(r,t,(u,e,o)=>(n(o,1,1,r,t),null===o[0]||(""===o[0]||(void 0===o[0]||o[0]===i))))},p.boolean=function(r,t){return M(r,t,(u,e,o)=>{n(o,1,1,r,t);const i=o[0];return a(i)})},p.constrain=function(r,t){return M(r,t,(u,e,i)=>{n(i,3,3,r,t);const a=o(i[1]),f=o(i[2]);if(h(i[0])){const n=[];for(const r of i[0])n.push(b(r,a,f));return n}if(s(i[0])){const n=[];for(let r=0;r<i[0].length();r++)n.push(b(i[0].get(r),a,f));return n}return b(i[0],a,f)})}}export{p as registerFunctions};
5
+ import{B as n,e as r,g as t,f as u,Z as e,s as o,v as i,H as a,j as s}from"../../chunks/languageUtils.js";import{decimalAdjust as f}from"../../core/mathUtils.js";import{parse as c}from"../../core/number.js";import{isNumber as l,isBoolean as N,isArray as h,isString as m}from"../../support/guards.js";function p(p,M){function b(n,r,t){const u=o(n);return isNaN(u)?u:isNaN(r)||isNaN(t)||r>t?NaN:u<r?r:u>t?t:u}p.number=function(o,i){return M(o,i,(a,s,f)=>{n(f,1,2,o,i);const p=f[0];if(l(p))return p;if(null===p)return 0;if(r(p)||t(p)||u(p))return p.toNumber();if(N(p))return Number(p);if(h(p))return NaN;if(""===p)return Number(p);if(void 0===p)return Number(p);if(m(p)){if(void 0!==f[1]){let n=e(f[1],"‰","");return n=e(n,"¤",""),c(p,{pattern:n})}return Number(p.trim())}return Number(p)})},p.abs=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.abs(o(i[0]))))},p.acos=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.acos(o(i[0]))))},p.asin=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.asin(o(i[0]))))},p.atan=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.atan(o(i[0]))))},p.atan2=function(r,t){return M(r,t,(u,e,i)=>(n(i,2,2,r,t),Math.atan2(o(i[0]),o(i[1]))))},p.ceil=function(r,t){return M(r,t,(u,e,i)=>{if(n(i,1,2,r,t),2===i.length){let n=o(i[1]);return isNaN(n)&&(n=0),f("ceil",o(i[0]),-1*n)}return Math.ceil(o(i[0]))})},p.round=function(r,t){return M(r,t,(u,e,i)=>{if(n(i,1,2,r,t),2===i.length){let n=o(i[1]);return isNaN(n)&&(n=0),f("round",o(i[0]),-1*n)}return Math.round(o(i[0]))})},p.floor=function(r,t){return M(r,t,(u,e,i)=>{if(n(i,1,2,r,t),2===i.length){let n=o(i[1]);return isNaN(n)&&(n=0),f("floor",o(i[0]),-1*n)}return Math.floor(o(i[0]))})},p.cos=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.cos(o(i[0]))))},p.isnan=function(r,t){return M(r,t,(u,e,o)=>(n(o,1,1,r,t),"number"==typeof o[0]&&isNaN(o[0])))},p.exp=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.exp(o(i[0]))))},p.log=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.log(o(i[0]))))},p.pow=function(r,t){return M(r,t,(u,e,i)=>(n(i,2,2,r,t),o(i[0])**o(i[1])))},p.random=function(r,t){return M(r,t,(u,e,o)=>(n(o,0,0,r,t),Math.random()))},p.sin=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.sin(o(i[0]))))},p.sqrt=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.sqrt(o(i[0]))))},p.tan=function(r,t){return M(r,t,(u,e,i)=>(n(i,1,1,r,t),Math.tan(o(i[0]))))},p.isempty=function(r,t){return M(r,t,(u,e,o)=>(n(o,1,1,r,t),null===o[0]||(""===o[0]||(void 0===o[0]||o[0]===i))))},p.boolean=function(r,t){return M(r,t,(u,e,o)=>{n(o,1,1,r,t);const i=o[0];return a(i)})},p.constrain=function(r,t){return M(r,t,(u,e,i)=>{n(i,3,3,r,t);const a=o(i[1]),f=o(i[2]);if(h(i[0])){const n=[];for(const r of i[0])n.push(b(r,a,f));return n}if(s(i[0])){const n=[];for(let r=0;r<i[0].length();r++)n.push(b(i[0].get(r),a,f));return n}return b(i[0],a,f)})}}export{p as registerFunctions};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.34/esri/copyright.txt for details.
4
4
  */
5
- import t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{StringEnum as n}from"../enum.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as o,u as i,M as u,s,v as l,J as p,H as f,t as c,j as d,Y as h,K as y,Z as g,e as m,f as A,g as w,k as I,i as v,m as U,l as j}from"../../chunks/languageUtils.js";import{convertDirection as x}from"./convertdirection.js";import{XXH as N}from"./hash.js";import{hasSamePortal as k}from"../../core/urlUtils.js";import{generateUUID as C}from"../../core/uuid.js";import P from"../../geometry/Extent.js";import z from"../../geometry/Multipoint.js";import O from"../../geometry/Point.js";import S from"../../geometry/Polygon.js";import F from"../../geometry/Polyline.js";import T from"../../geometry/SpatialReference.js";import L from"../../portal/Portal.js";import{isArray as R,isString as M,isBoolean as H,isNumber as b}from"../../support/guards.js";function D(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function J(t,e){return!!t&&k(t,e?.restUrl||"")}function W(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 B(n,o,i){if(null!==n)if(R(n)){if(o.updateUint8Array([61]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n)B(t,o,i);i.map.delete(n),i.currentLength--}o.updateUint8Array([199])}else if(d(n)){if(o.updateUint8Array([61]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n.toArray())B(t,o,i);i.map.delete(n),i.currentLength--}o.updateUint8Array([199])}else{if(m(n))return o.updateIntArray([n.toNumber()]),void o.updateUint8Array([241]);if(A(n))return o.updateIntArray([n.toNumber()]),void o.updateIntArray([257]);if(w(n))return o.updateIntArray([n.toNumber()]),void o.updateIntArray([263]);if(M(n))return o.updateIntArray([n.length]),o.updateWithString(n),void o.updateUint8Array([41]);if(H(n))o.updateUint8Array([!0===n?1:0,113]);else{if(b(n))return o.updateFloatArray([n]),void o.updateUint8Array([173]);if(n instanceof e)throw new a(i.context,"UnsupportedHashType",i.node);if(n instanceof t)throw new a(i.context,"UnsupportedHashType",i.node);if(!(n instanceof r)){if(I(n))throw new a(i.context,"UnsupportedHashType",i.node);if(n instanceof O)return o.updateIntArray([3833836621]),o.updateIntArray([0]),o.updateFloatArray([n.x]),o.updateIntArray([1]),o.updateFloatArray([n.y]),n.hasZ&&(o.updateIntArray([2]),o.updateFloatArray([n.z])),n.hasM&&(o.updateIntArray([3]),o.updateFloatArray([n.m])),o.updateIntArray([3765347959]),void B(n.spatialReference.wkid,o,i);if(n instanceof S){o.updateIntArray([1266616829]);for(let t=0;t<n.rings.length;t++){const e=n.rings[t],r=[];let a=null,u=null;for(let o=0;o<e.length;o++){const i=n.getPoint(t,o);if(0===o)a=i;else if(W(u,i))continue;u=i,o===e.length-1&&W(a,i)||r.push(i)}o.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];o.updateIntArray([3962308117,t]),B(e,o,i),o.updateIntArray([2716288009])}o.updateIntArray([2278822459])}return o.updateIntArray([3878477243]),void B(n.spatialReference.wkid,o,i)}if(n instanceof F){o.updateIntArray([4106883559]);for(let t=0;t<n.paths.length;t++){const e=n.paths[t];o.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)o.updateIntArray([3962308117,r]),B(n.getPoint(t,r),o,i),o.updateIntArray([2716288009]);o.updateIntArray([2278822459])}return o.updateIntArray([2568784753]),void B(n.spatialReference.wkid,o,i)}if(n instanceof z){o.updateIntArray([588535921,n.points.length]);for(let t=0;t<n.points.length;t++){const e=n.getPoint(t);o.updateIntArray([t]),B(e,o,i)}return o.updateIntArray([1700171621]),void B(n.spatialReference.wkid,o,i)}if(n instanceof P)return o.updateIntArray([3483648373]),o.updateIntArray([0]),o.updateFloatArray([n.xmax]),o.updateIntArray([1]),o.updateFloatArray([n.xmin]),o.updateIntArray([2]),o.updateFloatArray([n.ymax]),o.updateIntArray([3]),o.updateFloatArray([n.ymin]),n.hasZ&&(o.updateIntArray([4]),o.updateFloatArray([n.zmax]),o.updateIntArray([5]),o.updateFloatArray([n.zmin])),n.hasM&&(o.updateIntArray([6]),o.updateFloatArray([n.mmax]),o.updateIntArray([7]),o.updateFloatArray([n.mmin])),o.updateIntArray([3622027469]),void B(n.spatialReference.wkid,o,i);if(n instanceof T)return o.updateIntArray([14]),void 0!==n.wkid&&null!==n.wkid&&o.updateIntArray([n.wkid]),n.wkt&&o.updateWithString(n.wkt),void(n.wkt2&&o.updateWithString(n.wkt2));if(v(n))throw new a(i.context,"UnsupportedHashType",i.node);if(U(n))throw new a(i.context,"UnsupportedHashType",i.node);if(j(n))throw new a(i.context,"UnsupportedHashType",i.node);if(n===l)throw new a(i.context,"UnsupportedHashType",i.node);throw new a(i.context,"UnsupportedHashType",i.node)}if(o.updateUint8Array([223]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n.keys()){o.updateIntArray([t.length]),o.updateWithString(t),o.updateUint8Array([251]);B(n.field(t),o,i),o.updateUint8Array([239])}i.map.delete(n),i.currentLength--}o.updateUint8Array([73])}}else o.updateUint8Array([0,139])}function Z(e,m){e.portal=function(e,r){return m(e,r,(n,a,u)=>(o(u,1,1,e,r),new t(i(u[0]))))},e.typeof=function(t,e){return m(t,e,(r,n,i)=>{o(i,1,1,t,e);const s=u(i[0]);if("Unrecognized Type"===s)throw new a(t,"UnrecognizedType",e);return s})},e.trim=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim()))},e.tohex=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)})},e.upper=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase()))};const A=new n(["every-word","first-word"]);e.proper=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,2,t,e);const u=(a.length>=2?A.lookup(i(a[1])):null)??"every-word",s=/\s/,l=i(a[0]);let p="",f=!0;for(let t=0;t<l.length;t++){let e=l[t];if(s.test(e))"every-word"===u&&(f=!0);else{e.toUpperCase()!==e.toLowerCase()&&(f?(e=e.toUpperCase(),f=!1):e=e.toLowerCase())}p+=e}return p})},e.lower=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase()))};const w=new n(["digits","digits-hyphen","digits-hyphen-braces","digits-hyphen-parentheses"]);e.guid=function(t,e){return m(t,e,(r,n,a)=>{o(a,0,1,t,e);switch(a.length>0?w.lookup(i(a[0])):null){case"digits":return C().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return C();case"digits-hyphen-parentheses":return"("+C()+")";default:return"{"+C()+"}"}})},e.standardizeguid=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(-?)(?<partB>[0-9a-z]{4})(-?)(?<partC>[0-9a-z]{4})(-?)(?<partD>[0-9a-z]{4})(-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const l=s.groups;switch(u=l.partA+"-"+l.partB+"-"+l.partC+"-"+l.partD+"-"+l.partE,w.lookup(i(a[1]))){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-parentheses":return"("+u+")";default:return"{"+u+"}"}})},e.console=function(t,e){return m(t,e,(e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),l))},e.mid=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u=Math.max(0,u),2===a.length)return i(a[0]).slice(u);let l=s(a[2]);return isNaN(l)?"":(l<0&&(l=0),i(a[0]).slice(u,u+l))})},e.find=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(p(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)})},e.left=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).slice(0,u))})},e.right=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);const u=s(a[1]);if(isNaN(u)||u<=0)return"";return i(a[0]).slice(-u)})},e.split=function(t,e){return m(t,e,(r,n,a)=>{let u;o(a,2,4,t,e);let l=s(p(a[2],-1));const c=f(p(a[3],!1));if(-1===l||null===l||!0===c?u=i(a[0]).split(i(a[1])):(isNaN(l)&&(l=-1),l<-1&&(l=-1),u=i(a[0]).split(i(a[1]),l)),!1===c)return u;const d=[];for(let t=0;t<u.length&&!(-1!==l&&d.length>=l);t++)""!==u[t]&&void 0!==u[t]&&d.push(u[t]);return d})},e.text=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,2,t,e),c(a[0],a[1])))},e.concatenate=function(t,e){return m(t,e,(t,e,r)=>{const n=[];if(r.length<1)return"";if(R(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=c(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(d(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=c(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=c(r[a]);return n.join("")})},e.reverse=function(t,e){return m(t,e,(r,n,i)=>{if(o(i,1,1,t,e),R(i[0])){const t=i[0].slice();return t.reverse(),t}if(d(i[0])){const t=i[0].toArray().slice();return t.reverse(),t}throw new a(t,"InvalidParameter",e)})},e.replace=function(t,e){return m(t,e,(r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),l=i(a[2]);return 4!==a.length||f(a[3])?h(u,s,l):u.replace(s,l)})},e.urlencode=function(t,e){return m(t,e,(n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))})},e.hash=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,1,t,e);const i=new N(0);return B(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()})},e.convertdirection=function(t,e){return m(t,e,(r,n,a)=>(o(a,3,3,t,e),x(a[0],a[1],a[2])))},e.fromjson=function(t,e){return m(t,e,(n,u,s)=>{if(o(s,1,1,t,e),!1===M(s[0]))throw new a(t,"InvalidParameter",e);return r.convertJsonToArcade(JSON.parse(i(s[0])),y(t))})},e.tocharcode=function(t,e){return m(t,e,(r,n,u)=>{o(u,1,2,t,e);const l=s(p(u[1],0)),f=i(u[0]);if(0===f.length&&1===u.length)return null;if(f.length<=l||l<0)throw new a(t,"OutOfBounds",e);return f.charCodeAt(l)})},e.tocodepoint=function(t,e){return m(t,e,(r,n,u)=>{o(u,1,2,t,e);const l=s(p(u[1],0)),f=i(u[0]);if(0===f.length&&1===u.length)return null;if(f.length<=l||l<0)throw new a(t,"OutOfBounds",e);return f.codePointAt(l)})},e.fromcharcode=function(t,e){return m(t,e,(r,n,o)=>{if(o.length<1)throw new a(t,"WrongNumberOfParameters",e);const i=o.map(t=>Math.trunc(s(t))).filter(t=>t>=0&&t<=65535);return 0===i.length?null:String.fromCharCode.apply(null,i)})},e.fromcodepoint=function(t,e){return m(t,e,(r,n,o)=>{if(o.length<1)throw new a(t,"WrongNumberOfParameters",e);let i;try{i=o.map(t=>Math.trunc(s(t))).filter(t=>t<=1114111&&t>>>0===t)}catch(u){return null}return 0===i.length?null:String.fromCodePoint.apply(null,i)})},e.getuser=function(e,n){return m(e,n,(u,s,l)=>{o(l,0,2,e,n);let f=p(l[1],"");if(f=!0===f||!1===f?"":i(f),null!==f&&""!==f)return null;if(0===l.length||l[0]instanceof t){let t=null;if(t=e.services?.portal?e.services.portal:L.getDefault(),l.length>0){if(!J(l[0].field("url"),t))return null}if(!t)return null;if(""===f){const n=D(t);if(n){const t=JSON.parse(JSON.stringify(n));for(const e of["lastLogin","created","modified"])void 0!==t[e]&&null!==t[e]&&(t[e]=new Date(t[e]));return r.convertObjectToArcadeDictionary(t,y(e))}}return null}throw new a(e,"InvalidParameter",n)})},e.getenvironment=function(t,e){return m(t,e,(n,a,i)=>(o(i,0,0,t,e),r.convertObjectToArcadeDictionary(g(y(t),t.spatialReference),y(t),!0)))},e.standardizefilename=function(t,e){return m(t,e,(t,e,r)=>{o(r,1,1,t,e);const[n]=r;if(null==n)return"";if(!M(n))throw new a(t,"InvalidParameter",e);return n.replaceAll(/[<>"?*]/g,"_").replaceAll(/[/\\|]/g,"-").replaceAll(":",", ")})}}export{Z as registerFunctions};
5
+ import t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{StringEnum as n}from"../enum.js";import{ArcadeExecutionError as a}from"../executionError.js";import{B as o,u as i,M as u,s,v as l,J as p,H as f,t as c,j as d,Z as h,K as y,_ as g,e as m,f as A,g as w,k as I,i as v,m as U,l as j}from"../../chunks/languageUtils.js";import{convertDirection as x}from"./convertdirection.js";import{XXH as N}from"./hash.js";import{hasSamePortal as k}from"../../core/urlUtils.js";import{generateUUID as C}from"../../core/uuid.js";import P from"../../geometry/Extent.js";import z from"../../geometry/Multipoint.js";import O from"../../geometry/Point.js";import S from"../../geometry/Polygon.js";import F from"../../geometry/Polyline.js";import T from"../../geometry/SpatialReference.js";import L from"../../portal/Portal.js";import{isArray as R,isString as M,isBoolean as H,isNumber as b}from"../../support/guards.js";function D(t){if("loaded"===t.loadStatus&&t.user?.sourceJSON){return t.user.sourceJSON}return null}function J(t,e){return!!t&&k(t,e?.restUrl||"")}function W(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 B(n,o,i){if(null!==n)if(R(n)){if(o.updateUint8Array([61]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n)B(t,o,i);i.map.delete(n),i.currentLength--}o.updateUint8Array([199])}else if(d(n)){if(o.updateUint8Array([61]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n.toArray())B(t,o,i);i.map.delete(n),i.currentLength--}o.updateUint8Array([199])}else{if(m(n))return o.updateIntArray([n.toNumber()]),void o.updateUint8Array([241]);if(A(n))return o.updateIntArray([n.toNumber()]),void o.updateIntArray([257]);if(w(n))return o.updateIntArray([n.toNumber()]),void o.updateIntArray([263]);if(M(n))return o.updateIntArray([n.length]),o.updateWithString(n),void o.updateUint8Array([41]);if(H(n))o.updateUint8Array([!0===n?1:0,113]);else{if(b(n))return o.updateFloatArray([n]),void o.updateUint8Array([173]);if(n instanceof e)throw new a(i.context,"UnsupportedHashType",i.node);if(n instanceof t)throw new a(i.context,"UnsupportedHashType",i.node);if(!(n instanceof r)){if(I(n))throw new a(i.context,"UnsupportedHashType",i.node);if(n instanceof O)return o.updateIntArray([3833836621]),o.updateIntArray([0]),o.updateFloatArray([n.x]),o.updateIntArray([1]),o.updateFloatArray([n.y]),n.hasZ&&(o.updateIntArray([2]),o.updateFloatArray([n.z])),n.hasM&&(o.updateIntArray([3]),o.updateFloatArray([n.m])),o.updateIntArray([3765347959]),void B(n.spatialReference.wkid,o,i);if(n instanceof S){o.updateIntArray([1266616829]);for(let t=0;t<n.rings.length;t++){const e=n.rings[t],r=[];let a=null,u=null;for(let o=0;o<e.length;o++){const i=n.getPoint(t,o);if(0===o)a=i;else if(W(u,i))continue;u=i,o===e.length-1&&W(a,i)||r.push(i)}o.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];o.updateIntArray([3962308117,t]),B(e,o,i),o.updateIntArray([2716288009])}o.updateIntArray([2278822459])}return o.updateIntArray([3878477243]),void B(n.spatialReference.wkid,o,i)}if(n instanceof F){o.updateIntArray([4106883559]);for(let t=0;t<n.paths.length;t++){const e=n.paths[t];o.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)o.updateIntArray([3962308117,r]),B(n.getPoint(t,r),o,i),o.updateIntArray([2716288009]);o.updateIntArray([2278822459])}return o.updateIntArray([2568784753]),void B(n.spatialReference.wkid,o,i)}if(n instanceof z){o.updateIntArray([588535921,n.points.length]);for(let t=0;t<n.points.length;t++){const e=n.getPoint(t);o.updateIntArray([t]),B(e,o,i)}return o.updateIntArray([1700171621]),void B(n.spatialReference.wkid,o,i)}if(n instanceof P)return o.updateIntArray([3483648373]),o.updateIntArray([0]),o.updateFloatArray([n.xmax]),o.updateIntArray([1]),o.updateFloatArray([n.xmin]),o.updateIntArray([2]),o.updateFloatArray([n.ymax]),o.updateIntArray([3]),o.updateFloatArray([n.ymin]),n.hasZ&&(o.updateIntArray([4]),o.updateFloatArray([n.zmax]),o.updateIntArray([5]),o.updateFloatArray([n.zmin])),n.hasM&&(o.updateIntArray([6]),o.updateFloatArray([n.mmax]),o.updateIntArray([7]),o.updateFloatArray([n.mmin])),o.updateIntArray([3622027469]),void B(n.spatialReference.wkid,o,i);if(n instanceof T)return o.updateIntArray([14]),void 0!==n.wkid&&null!==n.wkid&&o.updateIntArray([n.wkid]),n.wkt&&o.updateWithString(n.wkt),void(n.wkt2&&o.updateWithString(n.wkt2));if(v(n))throw new a(i.context,"UnsupportedHashType",i.node);if(U(n))throw new a(i.context,"UnsupportedHashType",i.node);if(j(n))throw new a(i.context,"UnsupportedHashType",i.node);if(n===l)throw new a(i.context,"UnsupportedHashType",i.node);throw new a(i.context,"UnsupportedHashType",i.node)}if(o.updateUint8Array([223]),i.map.has(n)){const t=i.map.get(n);o.updateIntArray([61237541^t])}else{i.map.set(n,i.currentLength++);for(const t of n.keys()){o.updateIntArray([t.length]),o.updateWithString(t),o.updateUint8Array([251]);B(n.field(t),o,i),o.updateUint8Array([239])}i.map.delete(n),i.currentLength--}o.updateUint8Array([73])}}else o.updateUint8Array([0,139])}function Z(e,m){e.portal=function(e,r){return m(e,r,(n,a,u)=>(o(u,1,1,e,r),new t(i(u[0]))))},e.typeof=function(t,e){return m(t,e,(r,n,i)=>{o(i,1,1,t,e);const s=u(i[0]);if("Unrecognized Type"===s)throw new a(t,"UnrecognizedType",e);return s})},e.trim=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim()))},e.tohex=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)})},e.upper=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase()))};const A=new n(["every-word","first-word"]);e.proper=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,2,t,e);const u=(a.length>=2?A.lookup(i(a[1])):null)??"every-word",s=/\s/,l=i(a[0]);let p="",f=!0;for(let t=0;t<l.length;t++){let e=l[t];if(s.test(e))"every-word"===u&&(f=!0);else{e.toUpperCase()!==e.toLowerCase()&&(f?(e=e.toUpperCase(),f=!1):e=e.toLowerCase())}p+=e}return p})},e.lower=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase()))};const w=new n(["digits","digits-hyphen","digits-hyphen-braces","digits-hyphen-parentheses"]);e.guid=function(t,e){return m(t,e,(r,n,a)=>{o(a,0,1,t,e);switch(a.length>0?w.lookup(i(a[0])):null){case"digits":return C().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return C();case"digits-hyphen-parentheses":return"("+C()+")";default:return"{"+C()+"}"}})},e.standardizeguid=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(-?)(?<partB>[0-9a-z]{4})(-?)(?<partC>[0-9a-z]{4})(-?)(?<partD>[0-9a-z]{4})(-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const l=s.groups;switch(u=l.partA+"-"+l.partB+"-"+l.partC+"-"+l.partD+"-"+l.partE,w.lookup(i(a[1]))){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-parentheses":return"("+u+")";default:return"{"+u+"}"}})},e.console=function(t,e){return m(t,e,(e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),l))},e.mid=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u=Math.max(0,u),2===a.length)return i(a[0]).slice(u);let l=s(a[2]);return isNaN(l)?"":(l<0&&(l=0),i(a[0]).slice(u,u+l))})},e.find=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(p(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)})},e.left=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).slice(0,u))})},e.right=function(t,e){return m(t,e,(r,n,a)=>{o(a,2,2,t,e);const u=s(a[1]);if(isNaN(u)||u<=0)return"";return i(a[0]).slice(-u)})},e.split=function(t,e){return m(t,e,(r,n,a)=>{let u;o(a,2,4,t,e);let l=s(p(a[2],-1));const c=f(p(a[3],!1));if(-1===l||null===l||!0===c?u=i(a[0]).split(i(a[1])):(isNaN(l)&&(l=-1),l<-1&&(l=-1),u=i(a[0]).split(i(a[1]),l)),!1===c)return u;const d=[];for(let t=0;t<u.length&&!(-1!==l&&d.length>=l);t++)""!==u[t]&&void 0!==u[t]&&d.push(u[t]);return d})},e.text=function(t,e){return m(t,e,(r,n,a)=>(o(a,1,2,t,e),c(a[0],a[1])))},e.concatenate=function(t,e){return m(t,e,(t,e,r)=>{const n=[];if(r.length<1)return"";if(R(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=c(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(d(r[0])){const t=p(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=c(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=c(r[a]);return n.join("")})},e.reverse=function(t,e){return m(t,e,(r,n,i)=>{if(o(i,1,1,t,e),R(i[0])){const t=i[0].slice();return t.reverse(),t}if(d(i[0])){const t=i[0].toArray().slice();return t.reverse(),t}throw new a(t,"InvalidParameter",e)})},e.replace=function(t,e){return m(t,e,(r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),l=i(a[2]);return 4!==a.length||f(a[3])?h(u,s,l):u.replace(s,l)})},e.urlencode=function(t,e){return m(t,e,(n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))})},e.hash=function(t,e){return m(t,e,(r,n,a)=>{o(a,1,1,t,e);const i=new N(0);return B(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()})},e.convertdirection=function(t,e){return m(t,e,(r,n,a)=>(o(a,3,3,t,e),x(a[0],a[1],a[2])))},e.fromjson=function(t,e){return m(t,e,(n,u,s)=>{if(o(s,1,1,t,e),!1===M(s[0]))throw new a(t,"InvalidParameter",e);return r.convertJsonToArcade(JSON.parse(i(s[0])),y(t))})},e.tocharcode=function(t,e){return m(t,e,(r,n,u)=>{o(u,1,2,t,e);const l=s(p(u[1],0)),f=i(u[0]);if(0===f.length&&1===u.length)return null;if(f.length<=l||l<0)throw new a(t,"OutOfBounds",e);return f.charCodeAt(l)})},e.tocodepoint=function(t,e){return m(t,e,(r,n,u)=>{o(u,1,2,t,e);const l=s(p(u[1],0)),f=i(u[0]);if(0===f.length&&1===u.length)return null;if(f.length<=l||l<0)throw new a(t,"OutOfBounds",e);return f.codePointAt(l)})},e.fromcharcode=function(t,e){return m(t,e,(r,n,o)=>{if(o.length<1)throw new a(t,"WrongNumberOfParameters",e);const i=o.map(t=>Math.trunc(s(t))).filter(t=>t>=0&&t<=65535);return 0===i.length?null:String.fromCharCode.apply(null,i)})},e.fromcodepoint=function(t,e){return m(t,e,(r,n,o)=>{if(o.length<1)throw new a(t,"WrongNumberOfParameters",e);let i;try{i=o.map(t=>Math.trunc(s(t))).filter(t=>t<=1114111&&t>>>0===t)}catch(u){return null}return 0===i.length?null:String.fromCodePoint.apply(null,i)})},e.getuser=function(e,n){return m(e,n,(u,s,l)=>{o(l,0,2,e,n);let f=p(l[1],"");if(f=!0===f||!1===f?"":i(f),null!==f&&""!==f)return null;if(0===l.length||l[0]instanceof t){let t=null;if(t=e.services?.portal?e.services.portal:L.getDefault(),l.length>0){if(!J(l[0].field("url"),t))return null}if(!t)return null;if(""===f){const n=D(t);if(n){const t=JSON.parse(JSON.stringify(n));for(const e of["lastLogin","created","modified"])void 0!==t[e]&&null!==t[e]&&(t[e]=new Date(t[e]));return r.convertObjectToArcadeDictionary(t,y(e))}}return null}throw new a(e,"InvalidParameter",n)})},e.getenvironment=function(t,e){return m(t,e,(n,a,i)=>(o(i,0,0,t,e),r.convertObjectToArcadeDictionary(g(y(t),t.spatialReference),y(t),!0)))},e.standardizefilename=function(t,e){return m(t,e,(t,e,r)=>{o(r,1,1,t,e);const[n]=r;if(null==n)return"";if(!M(n))throw new a(t,"InvalidParameter",e);return n.replaceAll(/[<>"?*]/g,"_").replaceAll(/[/\\|]/g,"-").replaceAll(":",", ")})}}export{Z as registerFunctions};