@arcgis/core 4.27.0-next.20230520 → 4.27.0-next.20230522
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Graphic.js +1 -1
- package/arcade/featureset/actions/SpatialFilter.js +1 -1
- package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
- package/arcade/featureset/sources/FeatureLayerMemory.js +1 -1
- package/arcade/featureset/sources/FeatureLayerRelated.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/0d02856e55d20b99fc8b.js +1 -0
- package/assets/esri/core/workers/chunks/{69242c66492717c7388c.js → 0fcb8d408696075338e2.js} +1 -1
- package/assets/esri/core/workers/chunks/{1edc5c06874cb12c5478.js → 17f313e548281bb5db3e.js} +1 -1
- package/assets/esri/core/workers/chunks/{b91c155de9a89e4e6971.js → 187c3b971ed0fc4363ef.js} +1 -1
- package/assets/esri/core/workers/chunks/{85c6ce93aa41e6b65997.js → 18db07d739a713cc0465.js} +1 -1
- package/assets/esri/core/workers/chunks/28286014a575042619ee.js +1 -0
- package/assets/esri/core/workers/chunks/{692dfeb2e255fdc0ade2.js → 39288fa69561d21f04f8.js} +1 -1
- package/assets/esri/core/workers/chunks/{2b9d3e60977934a6d471.js → 3bc6b5f0643364749ef8.js} +1 -1
- package/assets/esri/core/workers/chunks/45e5ad704d18dd0857ce.js +1 -0
- package/assets/esri/core/workers/chunks/{62d9d15f0d00a75da42c.js → 4670b17ae2ed3c13d344.js} +1 -1
- package/assets/esri/core/workers/chunks/4d24efa01d1accc5a5f0.js +1 -0
- package/assets/esri/core/workers/chunks/52575f021a14dd961de8.js +1 -0
- package/assets/esri/core/workers/chunks/{6312783626bacf52df7a.js → 55486c644e8b01326a0d.js} +1 -1
- package/assets/esri/core/workers/chunks/5576858f56314afcb4d5.js +1 -0
- package/assets/esri/core/workers/chunks/5a4c04bf4f57e74457c5.js +1 -0
- package/assets/esri/core/workers/chunks/70d6e5edf05ef7079fa8.js +1 -0
- package/assets/esri/core/workers/chunks/71bdf8f10aee0077f681.js +1 -0
- package/assets/esri/core/workers/chunks/72b2c3c8e76da699690c.js +1 -0
- package/assets/esri/core/workers/chunks/78ce0b1af62435d8ebf4.js +1 -0
- package/assets/esri/core/workers/chunks/791f529e90135398b3d5.js +1 -0
- package/assets/esri/core/workers/chunks/8d3abfe6fdc5ac8d6cb7.js +1 -0
- package/assets/esri/core/workers/chunks/96d339abcd917f1f0ae1.js +1 -0
- package/assets/esri/core/workers/chunks/97cdbec7532cfcdf9ad2.js +1 -0
- package/assets/esri/core/workers/chunks/{f3f6035a17f7dcd19675.js → 9ab400a89dd701778d2c.js} +1 -1
- package/assets/esri/core/workers/chunks/{1488b3d48232844b8bb4.js → 9fe349f43d5ff5a4ac2d.js} +1 -1
- package/assets/esri/core/workers/chunks/{22396dd3717d17a5d235.js → a1c31bb8c12831539328.js} +1 -1
- package/assets/esri/core/workers/chunks/b4e2dc6b3d06b426e596.js +1 -0
- package/assets/esri/core/workers/chunks/{48abcb2d88f22e6e9fde.js → c2cb9fa18c77f0c5104e.js} +1 -1
- package/assets/esri/core/workers/chunks/cad7a2092ea7f51dbd8b.js +1 -0
- package/assets/esri/core/workers/chunks/d725dbbdeb05322e6d88.js +1 -0
- package/assets/esri/core/workers/chunks/df3e497d12ed77bae168.js +1 -0
- package/assets/esri/core/workers/chunks/{4d5f71d84c85f45c97ea.js → ed6f6e539a915ba9e64d.js} +1 -1
- package/assets/esri/core/workers/chunks/fb080339bfaf32731ca6.js +1 -0
- package/assets/esri/themes/base/_core.scss +2 -0
- package/assets/esri/themes/base/widgets/_FloorFilter.scss +6 -0
- package/assets/esri/themes/base/widgets/_UtilityNetworkValidateTopology.scss +40 -0
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_ar.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_bg.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_bs.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_ca.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_cs.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_da.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_de.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_el.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_es.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_et.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_fi.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_fr.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_he.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_hr.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_hu.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_id.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_it.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_ja.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_ko.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_lt.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_lv.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_nb.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_nl.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_pl.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_pt-BR.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_pt-PT.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_ro.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_ru.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_sk.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_sl.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_sr.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_sv.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_th.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_tr.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_uk.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_vi.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_zh-CN.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_zh-HK.json +1 -1
- package/assets/esri/widgets/Editor/t9n/Editor_zh-TW.json +1 -1
- package/assets/esri/widgets/UtilityNetworkValidateTopology/t9n/UtilityNetworkValidateTopology.json +1 -1
- package/assets/esri/widgets/UtilityNetworkValidateTopology/t9n/UtilityNetworkValidateTopology_en.json +1 -1
- package/chunks/mat4.js +1 -1
- package/core/accessorSupport/write.js +1 -1
- package/core/fontUtils.js +1 -1
- package/core/libs/gl-matrix-2/math/mat4.js +1 -1
- package/geometry/Mesh.js +1 -1
- package/geometry/support/MeshGeoreferencedRelativeVertexSpace.d.ts +4 -0
- package/geometry/support/MeshGeoreferencedRelativeVertexSpace.js +5 -0
- package/geometry/support/MeshGeoreferencedVertexSpace.d.ts +4 -0
- package/geometry/support/MeshGeoreferencedVertexSpace.js +5 -0
- package/geometry/support/MeshLocalVertexSpace.d.ts +4 -0
- package/geometry/support/MeshLocalVertexSpace.js +5 -0
- package/geometry/support/MeshTransform.d.ts +4 -0
- package/geometry/support/MeshTransform.js +1 -1
- package/geometry/support/meshUtils/ElevationSamplerWorker.js +1 -1
- package/geometry/support/meshUtils/centerAt.js +1 -1
- package/geometry/support/meshUtils/exporters/gltf/geometry.js +1 -1
- package/geometry/support/meshUtils/exporters/gltf/gltf.js +1 -1
- package/geometry/support/meshUtils/geographicUtils.js +1 -1
- package/geometry/support/meshUtils/georeference.js +1 -1
- package/geometry/support/meshUtils/loadGLTFMesh.js +1 -1
- package/geometry/support/meshUtils/merge.js +1 -1
- package/geometry/support/meshUtils/offset.js +1 -1
- package/geometry/support/meshUtils/primitives.js +1 -1
- package/geometry/support/meshUtils/rotate.js +1 -1
- package/geometry/support/meshUtils/scale.js +1 -1
- package/interfaces.d.ts +227 -1
- package/layers/VoxelWasmPerSceneView.js +1 -1
- package/layers/graphics/data/attributeSupport.js +1 -1
- package/layers/graphics/sources/FeatureLayerSource.js +1 -1
- package/networks/support/TopologyValidationJobInfo.js +1 -1
- package/package.json +1 -1
- package/popup/FieldInfo.js +1 -1
- package/portal/Portal.js +1 -1
- package/rest/support/FeatureSet.js +1 -1
- package/rest/support/meshFeatureSet.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/cimAnalyzer.js +1 -1
- package/views/3d/environment/EnvironmentRenderer.js +1 -1
- package/views/3d/interactive/editingTools/draw/DrawGraphicTool3D.js +1 -1
- package/views/3d/interactive/editingTools/meshFastUpdateUtils.js +1 -1
- package/views/3d/interactive/editingTools/moveGraphic/GraphicMoveTool.js +1 -1
- package/views/3d/interactive/editingTools/transformGraphic/GraphicTransformTool.js +1 -1
- package/views/3d/interactive/editingTools/transformGraphic/ScaleRotateMeshAdapter.js +1 -1
- package/views/3d/interactive/editingTools/transformGraphic/undoRecords.js +1 -1
- package/views/3d/layers/graphics/Graphics3DCore.js +1 -1
- package/views/3d/layers/graphics/Graphics3DMeshFillSymbolLayer.js +1 -1
- package/views/3d/layers/graphics/Graphics3DMeshObject3DGraphicLayer.js +1 -1
- package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
- package/views/3d/layers/i3s/I3SOverrides.js +1 -1
- package/views/3d/state/utils/navigationUtils.js +1 -1
- package/views/3d/support/DisplayQualityProfile.js +1 -1
- package/views/3d/support/QualitySettings.js +1 -1
- package/views/3d/webgl-engine/lib/Camera.js +1 -1
- package/views/3d/webgl-engine/lib/RenderFeature.js +1 -1
- package/views/3d/webgl-engine/lib/RenderPluginManager.js +1 -1
- package/views/3d/webgl-engine/lib/Renderer.js +1 -1
- package/views/3d/webgl-engine/lib/TextRenderParameters.js +1 -1
- package/views/interactive/dragEventPipeline.js +1 -1
- package/widgets/BasemapGallery/support/PortalBasemapsSource.js +1 -1
- package/widgets/Editor/Edits.js +1 -1
- package/widgets/Editor/Upload.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Feature/support/featureUtils.js +1 -1
- package/widgets/UtilityNetworkTrace/UtilityNetworkTraceViewModel.js +1 -1
- package/widgets/UtilityNetworkValidateTopology/UtilityNetworkValidateTopologyViewModel.js +5 -0
- package/widgets/UtilityNetworkValidateTopology.js +5 -0
- package/assets/esri/core/workers/chunks/163bf2e13abbdd298374.js +0 -1
- package/assets/esri/core/workers/chunks/23f73f81aea461c0c6e6.js +0 -1
- package/assets/esri/core/workers/chunks/2640204c4655aa535ccb.js +0 -1
- package/assets/esri/core/workers/chunks/2bf42d060f877566b989.js +0 -1
- package/assets/esri/core/workers/chunks/34ec9623a1bece86a82b.js +0 -1
- package/assets/esri/core/workers/chunks/3bf52139340827794c3b.js +0 -1
- package/assets/esri/core/workers/chunks/52d02021e858820bc4fa.js +0 -1
- package/assets/esri/core/workers/chunks/64b8f65e2ef6cbf08380.js +0 -1
- package/assets/esri/core/workers/chunks/78aede1e114deefacb54.js +0 -1
- package/assets/esri/core/workers/chunks/7ef100158ca28631fcaf.js +0 -1
- package/assets/esri/core/workers/chunks/93ad67930aa7d4a4b0ac.js +0 -1
- package/assets/esri/core/workers/chunks/964795dfb57f0d0635d0.js +0 -1
- package/assets/esri/core/workers/chunks/99ce0a202dcd3d7dc290.js +0 -1
- package/assets/esri/core/workers/chunks/abe6c99a1a719543dbe8.js +0 -1
- package/assets/esri/core/workers/chunks/c3bf44146fddfe8990f7.js +0 -1
- package/assets/esri/core/workers/chunks/cbe817e966b57599bafd.js +0 -1
- package/assets/esri/core/workers/chunks/e15b5d7e46a834eacc57.js +0 -1
- package/assets/esri/core/workers/chunks/e1e0b3580e2c3098c9f4.js +0 -1
- package/assets/esri/core/workers/chunks/e305d20e4424451cab5b.js +0 -1
- package/assets/esri/core/workers/chunks/e6836c84470fb6bd25bf.js +0 -1
package/Graphic.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.27/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{_ as t}from"./chunks/tslib.es6.js";import{geometryTypes as e}from"./geometry.js";import r from"./PopupTemplate.js";import{symbolTypes as
|
|
5
|
+
import{_ as t}from"./chunks/tslib.es6.js";import{geometryTypes as e}from"./geometry.js";import r from"./PopupTemplate.js";import{symbolTypes as o}from"./symbols.js";import{ClonableMixin as s}from"./core/Clonable.js";import{JSONSupport as i}from"./core/JSONSupport.js";import{generateUID as a}from"./core/uid.js";import{property as l}from"./core/accessorSupport/decorators/property.js";import"./core/accessorSupport/ensureType.js";import"./core/arrayUtils.js";import"./core/has.js";import{subclass as p}from"./core/accessorSupport/decorators/subclass.js";import{fromJSON as n}from"./geometry/support/jsonUtils.js";var u;function y(t){if(!t)return null;const e={};for(const r in t){const o=n(t[r]);o&&(e[r]=o)}return 0!==Object.keys(e).length?e:null}function m(t){if(null==t)return null;const e={};for(const r in t){const o=t[r];o&&(e[r]=o.toJSON())}return 0!==Object.keys(e).length?e:null}let g=u=class extends(s(i)){constructor(...t){super(...t),this.isAggregate=!1,this.layer=null,this.popupTemplate=null,this.sourceLayer=null,Object.defineProperty(this,"uid",{value:a(),configurable:!0})}normalizeCtorArgs(t,e,r,o){return t&&!t.declaredClass?t:{geometry:t,symbol:e,attributes:r,popupTemplate:o}}set aggregateGeometries(t){const e=this._get("aggregateGeometries");JSON.stringify(e)!==JSON.stringify(t)&&this._set("aggregateGeometries",t)}set attributes(t){const e=this._get("attributes");e!==t&&(this._set("attributes",t),this._notifyLayer("attributes",e,t))}set geometry(t){const e=this._get("geometry");e!==t&&(this._set("geometry",t),this._notifyLayer("geometry",e,t))}set symbol(t){const e=this._get("symbol");e!==t&&(this._set("symbol",t),this._notifyLayer("symbol",e,t))}set visible(t){const e=this._get("visible");e!==t&&(this._set("visible",t),this._notifyLayer("visible",e,t))}cloneShallow(){return new u({aggregateGeometries:this.aggregateGeometries,attributes:this.attributes,geometry:this.geometry,isAggregate:this.isAggregate,layer:this.layer,popupTemplate:this.popupTemplate,sourceLayer:this.sourceLayer,symbol:this.symbol,visible:this.visible})}getEffectivePopupTemplate(t=!1){if(this.popupTemplate)return this.popupTemplate;for(const e of[this.sourceLayer,this.layer])if(e){if("popupTemplate"in e&&e.popupTemplate)return e.popupTemplate;if(t&&"defaultPopupTemplate"in e&&null!=e.defaultPopupTemplate)return e.defaultPopupTemplate}return null}getAttribute(t){return this.attributes?.[t]}setAttribute(t,e){if(this.attributes){const r=this.getAttribute(t);this.attributes[t]=e,this._notifyLayer("attributes",r,e,t)}else this.attributes={[t]:e},this._notifyLayer("attributes",void 0,e,t)}getObjectId(){return this.sourceLayer&&"objectIdField"in this.sourceLayer&&this.sourceLayer.objectIdField?this.getAttribute(this.sourceLayer.objectIdField):null}toJSON(){return{aggregateGeometries:m(this.aggregateGeometries),geometry:null!=this.geometry?this.geometry.toJSON():null,symbol:null!=this.symbol?this.symbol.toJSON():null,attributes:{...this.attributes},popupTemplate:this.popupTemplate&&this.popupTemplate.toJSON()}}notifyGeometryChanged(){this._notifyLayer("geometry",this.geometry,this.geometry)}notifyMeshTransformChanged(t={}){const{geometry:e}=this;if("mesh"===e?.type){const r={origin:e.origin,transform:e.transform};this._notifyLayer("origin-transform",r,r,t.action)}}_notifyLayer(t,e,r,o){if(!this.layer||!("graphicChanged"in this.layer))return;const s={graphic:this,property:t,oldValue:e,newValue:r};"origin-transform"===t&&(s.action=o),"attributes"===t&&(s.attributeName=o),this.layer.graphicChanged(s)}};t([l({value:null,json:{read:y}})],g.prototype,"aggregateGeometries",null),t([l({value:null})],g.prototype,"attributes",null),t([l({value:null,types:e,json:{read:n}})],g.prototype,"geometry",null),t([l({type:Boolean})],g.prototype,"isAggregate",void 0),t([l({clonable:"reference"})],g.prototype,"layer",void 0),t([l({type:r})],g.prototype,"popupTemplate",void 0),t([l({clonable:"reference"})],g.prototype,"sourceLayer",void 0),t([l({value:null,types:o})],g.prototype,"symbol",null),t([l({type:Boolean,value:!0})],g.prototype,"visible",null),g=u=t([p("esri.Graphic")],g),function(t){t.generateUID=a}(g||(g={}));const h=g;export{h 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.27/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../sources/Empty.js";import{FeatureSetError as t,FeatureSetErrorCodes as i}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import n from"../support/IdSet.js";import{IdState as a,shapeExtent as s}from"../support/shared.js";import{relate as o,crosses as l,touches as u,within as h,overlaps as _,contains as c,intersects as p}from"../../../geometry/geometryEngineAsync.js";class f extends r{constructor(e){super(e),this._relation="",this._relationGeom=null,this._relationString="",this.declaredClass="esri.arcade.featureset.actions.SpatialFilter",this._relationString=e.relationString,this._parent=e.parentfeatureset,this._maxProcessing=40,this._relation=e.relation,this._relationGeom=e.relationGeom}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._parent._getFilteredSet("esriSpatialRelRelation"!==this._relation?this._relation:this._relation+":"+this._relationString,this._relationGeom,null,null,e);return this._checkCancelled(e),this._wset=new n(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){let t=this._parent._isInFeatureSet(e);return t===a.NotInFeatureSet?t:(t=this._idstates[e],void 0===t?a.Unknown:t)}_getFeature(e,t,i){return this._parent._getFeature(e,t,i)}_getFeatures(e,t,i,r){return this._parent._getFeatures(e,t,i,r)}_featureFromCache(e){return this._parent._featureFromCache(e)}async executeSpatialRelationTest(e){if(null===e.geometry)return!1;switch(this._relation){case"esriSpatialRelEnvelopeIntersects":
|
|
5
|
+
import e from"../sources/Empty.js";import{FeatureSetError as t,FeatureSetErrorCodes as i}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import n from"../support/IdSet.js";import{IdState as a,shapeExtent as s}from"../support/shared.js";import{relate as o,crosses as l,touches as u,within as h,overlaps as _,contains as c,intersects as p}from"../../../geometry/geometryEngineAsync.js";class f extends r{constructor(e){super(e),this._relation="",this._relationGeom=null,this._relationString="",this.declaredClass="esri.arcade.featureset.actions.SpatialFilter",this._relationString=e.relationString,this._parent=e.parentfeatureset,this._maxProcessing=40,this._relation=e.relation,this._relationGeom=e.relationGeom}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._parent._getFilteredSet("esriSpatialRelRelation"!==this._relation?this._relation:this._relation+":"+this._relationString,this._relationGeom,null,null,e);return this._checkCancelled(e),this._wset=new n(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){let t=this._parent._isInFeatureSet(e);return t===a.NotInFeatureSet?t:(t=this._idstates[e],void 0===t?a.Unknown:t)}_getFeature(e,t,i){return this._parent._getFeature(e,t,i)}_getFeatures(e,t,i,r){return this._parent._getFeatures(e,t,i,r)}_featureFromCache(e){return this._parent._featureFromCache(e)}async executeSpatialRelationTest(e){if(null===e.geometry)return!1;switch(this._relation){case"esriSpatialRelEnvelopeIntersects":return p(s(this._relationGeom),s(e.geometry));case"esriSpatialRelIntersects":return p(this._relationGeom,e.geometry);case"esriSpatialRelContains":return c(this._relationGeom,e.geometry);case"esriSpatialRelOverlaps":return _(this._relationGeom,e.geometry);case"esriSpatialRelWithin":return h(this._relationGeom,e.geometry);case"esriSpatialRelTouches":return u(this._relationGeom,e.geometry);case"esriSpatialRelCrosses":return l(this._relationGeom,e.geometry);case"esriSpatialRelRelation":return o(this._relationGeom,e.geometry,this._relationString??"")}}async _fetchAndRefineFeatures(e,t,i){const r=new n([],e,!1,null),s=Math.min(t,e.length);await(this._parent?._getFeatures(r,-1,s,i)),this._checkCancelled(i);const o=[];for(let n=0;n<s;n++){const t=this._parent._featureFromCache(e[n]);o.push(await this.executeSpatialRelationTest(t))}for(let n=0;n<t;n++)!0===o[n]?this._idstates[e[n]]=a.InFeatureSet:this._idstates[e[n]]=a.NotInFeatureSet;return"success"}async _getFilteredSet(e,t,i,r,a){await this._ensureLoaded();const s=await this._parent._getFilteredSet("esriSpatialRelRelation"!==this._relation?this._relation:this._relation+":"+this._relationString,this._relationGeom,i,r,a);let o;return this._checkCancelled(a),o=null!==t?new n(s._candidates.slice(0).concat(s._known.slice(0)),[],s._ordered,this._clonePageDefinition(s.pagesDefinition)):new n(s._candidates.slice(0),s._known.slice(0),s._ordered,this._clonePageDefinition(s.pagesDefinition)),o}async _stat(e,t,i,r,n,a,s){if(""!==i)return{calculated:!1};const o=await this._parent._stat(e,t,"esriSpatialRelRelation"!==this._relation?this._relation:this._relation+":"+this._relationString,this._relationGeom,n,a,s);return!1===o.calculated?null===n&&""===i&&null===r?this._manualStat(e,t,a,s):{calculated:!1}:o}async _canDoAggregates(e,t,i,r,n){return""===i&&null===r&&(null!==this._parent&&this._parent._canDoAggregates(e,t,"esriSpatialRelRelation"!==this._relation?this._relation:this._relation+":"+this._relationString,this._relationGeom,n))}async _getAggregatePagesDataSourceDefinition(e,r,n,a,s,o,l){if(null===this._parent)throw new t(i.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,r,"esriSpatialRelRelation"!==this._relation?this._relation:this._relation+":"+this._relationString,this._relationGeom,s,o,l)}static registerAction(){r._featuresetFunctions.intersects=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelIntersects",relationGeom:t})},r._featuresetFunctions.envelopeIntersects=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelEnvelopeIntersects",relationGeom:t})},r._featuresetFunctions.contains=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelContains",relationGeom:t})},r._featuresetFunctions.overlaps=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelOverlaps",relationGeom:t})},r._featuresetFunctions.within=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelWithin",relationGeom:t})},r._featuresetFunctions.touches=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelTouches",relationGeom:t})},r._featuresetFunctions.crosses=function(t){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelCrosses",relationGeom:t})},r._featuresetFunctions.relate=function(t,i){return null==t?new e({parentfeatureset:this}):new f({parentfeatureset:this,relation:"esriSpatialRelRelation",relationGeom:t,relationString:i})}}}export{f 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.27/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import t from"../../../request.js";import i from"../../Attachment.js";import r from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{defaultMaxRecords as a,stableStringify as n,FeatureServiceDatabaseType as l,IdState as o,extractServiceUrl as u}from"../support/shared.js";import{toWhereClause as d,isSingleField as c}from"../support/sqlUtils.js";import{decodeStatType as h}from"../support/stats.js";import{createMD5Hash as p,outputTypes as y}from"../../../core/MD5.js";import{id as f}from"../../../kernel.js";import{fromJSON as m}from"../../../geometry/support/jsonUtils.js";import _ from"../../../layers/FeatureLayer.js";import{convertToFeatureSet as g}from"../../../layers/graphics/featureConversionUtils.js";import"../../../core/Error.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../layers/support/source/DataLayerSource.js";import{executeQueryJSON as R}from"../../../rest/query/executeQueryJSON.js";import"../../../config.js";import"../../../core/arrayUtils.js";import"../../../core/urlUtils.js";import"../../../core/unitUtils.js";import"../../../geometry/support/spatialReferenceUtils.js";import{executeQueryPBF as S}from"../../../rest/query/operations/query.js";import w from"../../../rest/support/FeatureSet.js";import F from"../../../rest/support/Query.js";import"../../../rest/query/support/AttachmentInfo.js";import"../../../rest/support/AttachmentQuery.js";import{executeForCount as b}from"../../../rest/query/executeForCount.js";import"../../../geometry.js";import{executeForIds as D}from"../../../rest/query/executeForIds.js";import"../../../rest/support/RelationshipQuery.js";import"../../../geometry/support/normalizeUtils.js";import"../../../rest/support/TopFeaturesQuery.js";import{OptimizedFeatureSetParserContext as I}from"../../../rest/query/operations/pbfOptimizedFeatureSet.js";import x from"../../../rest/support/StatisticDefinition.js";import T from"../../Dictionary.js";import{FeatureSetError as C,FeatureSetErrorCodes as P}from"../support/errorsupport.js";import j from"../../../layers/SubtypeGroupLayer.js";class q extends r{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerDynamic",this._removeGeometry=!1,this._overrideFields=null,this.formulaCredential=null,this._pageJustIds=!1,this._requestStandardised=!1,this._useDefinitionExpression=!0,this._cachedDateMetaData={},e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}get urlQueryPath(){return this._layer.parsedUrl.path||""}convertQueryToLruCacheKey(e){const t=this.urlQueryPath+","+n(e.toJSON());return p(t,y.String)}async loadImpl(){return!0===this._layer.loaded?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const i of this.fields)if("oid"===i.type)e.push(i),t.push(i.name);else for(const r of this._overrideFields)if(r.toLowerCase()===i.name.toLowerCase()){e.push(i),t.push(i.name);break}this.fields=e,this._overrideFields=t}if(this._layer.source&&this._layer.source.sourceJSON){const e=this._layer.source.sourceJSON.currentVersion;!0===this._layer.source.sourceJSON.useStandardizedQueries?(this._databaseType=l.StandardisedNoInterval,null!=e&&e>=10.61&&(this._databaseType=l.Standardised)):null!=e&&(e>=10.5&&(this._databaseType=l.StandardisedNoInterval,this._requestStandardised=!0),e>=10.61&&(this._databaseType=l.Standardised))}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this.hasM=this._layer.supportsM,this.hasZ=this._layer.supportsZ,this._layer instanceof j?(this.typeIdField=this._layer.subtypeField??"",this.types=this._layer.subtypes):(this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types)}_isInFeatureSet(){return o.InFeatureSet}async _refineSetBlock(e){return e}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}async _runDatabaseProbe(e){await this._ensureLoaded();const t=new F;this.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),t.where=e.replace("OBJECTID",this._layer.objectIdField);try{return await this._layer.queryObjectIds(t),!0}catch(i){return!1}}_canUsePagination(){return!(!this._layer.capabilities||!this._layer.capabilities.query||!0!==this._layer.capabilities.query.supportsPagination)}_cacheableFeatureSetSourceKey(){return this._layer.url}pbfSupportedForQuery(e){const t=this._layer?.capabilities?.query;return!e.outStatistics&&!0===t?.supportsFormatPBF&&!0===t?.supportsQuantizationEditMode}async queryPBF(e){e.quantizationParameters={mode:"edit"};const t=await S(this._layer.parsedUrl,e,new I({}));return w.fromJSON(g(t.data)).unquantize()}get gdbVersion(){return this._layer&&this._layer.capabilities&&this._layer.capabilities.data&&this._layer.capabilities.data.isVersioned?this._layer.gdbVersion||"SDE.DEFAULT":""}nativeCapabilities(){return{title:this._layer.title??"",source:this,canQueryRelated:!0,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:this._requestStandardised}}executeQuery(e,t){const i="execute"===t?R:"executeForCount"===t?b:D,r="execute"===t&&this.pbfSupportedForQuery(e);let s=null;if(this.recentlyUsedQueries){const t=this.convertQueryToLruCacheKey(e);s=this.recentlyUsedQueries.getFromCache(t),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e),this.recentlyUsedQueries.addToCache(t,s),s=s.catch((e=>{throw this.recentlyUsedQueries?.removeFromCache(t),e})))}return this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:e,method:t}),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e)),s}async _getFilteredSet(e,t,i,r,a){const n=await this.databaseType();if(this.isTable()&&t&&null!==e&&""!==e){return new s([],[],!0,null)}if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,r,a);let l="",o=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(l=r.constructClause(),o=!0);const u=new F;this.datesInUnknownTimezone&&(u.timeReferenceUnknownClient=!0),u.where=null===i?null===t?"1=1":"":d(i,n),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==l?l.split(","):null,u.geometry=null===t?null:t,u.relationParameter=this._makeRelationshipParam(e);let c=await this.executeQuery(u,"executeForIds");null===c&&(c=[]),this._checkCancelled(a);return new s([],c,o,null)}_expandPagedSet(e,t,i,r,s){return this._expandPagedSetFeatureSet(e,t,i,r,s)}async _getFilteredSetUsingPaging(e,t,i,r,a){let n="",l=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(n=r.constructClause(),l=!0);const o=await this.databaseType();let u=null===i?null===t?"1=1":"":d(i,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=""!==u?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let c=this._maxQueryRate();const h=this._layer.capabilities?.query.maxRecordCount;null!=h&&h<c&&(c=h);let p=null;if(!0===this._pageJustIds)p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:c,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:!1,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}});else{let i=!0;!0===this._removeGeometry&&(i=!1);const r=this._overrideFields??this._fieldsIncludingObjectId(["*"]);p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:r.join(","),resultRecordCount:c,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:i,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(p,c,0,1,a),p}_clonePageDefinition(e){return null===e?null:!0!==e.groupbypage?{groupbypage:!1,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,i){const r=e.pagesDefinition.internal.lastRetrieved,s=r,a=e.pagesDefinition.internal.lastPage,n=new F;this._requestStandardised&&(n.sqlFormat="standard"),this.datesInUnknownTimezone&&(n.timeReferenceUnknownClient=!0),n.spatialRelationship=e.pagesDefinition.spatialRel,n.relationParameter=e.pagesDefinition.relationParam,n.outFields=e.pagesDefinition.outFields.split(","),n.num=e.pagesDefinition.resultRecordCount,n.start=e.pagesDefinition.internal.lastPage,n.geometry=e.pagesDefinition.geometry,n.where=e.pagesDefinition.where,n.orderByFields=""!==e.pagesDefinition.orderByFields?e.pagesDefinition.orderByFields.split(","):null,n.returnGeometry=e.pagesDefinition.returnGeometry,n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(i),e.pagesDefinition.internal.lastPage!==a)return"done";const o=this._layer.objectIdField;for(let u=0;u<l.features.length;u++)e.pagesDefinition.internal.set[s+u]=l.features[u].attributes[o];if(!1===this._pageJustIds)for(let u=0;u<l.features.length;u++)this._featureCache[l.features[u].attributes[o]]=l.features[u];return(void 0===l.exceededTransferLimit&&l.features.length!==e.pagesDefinition.resultRecordCount||!1===l.exceededTransferLimit)&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=r+l.features.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,"done"}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let i=!1;for(const r of t)if(r.toUpperCase()===this.objectIdField.toUpperCase()){i=!0;break}return!1===i&&t.push(this.objectIdField),t}async _getFeatures(e,t,i,r){const s=[];if(-1!==t&&void 0===this._featureCache[t]&&s.push(t),!0===this._checkIfNeedToExpandKnownPage(e,this._maxProcessingRate()))return await this._expandPagedSet(e,this._maxProcessingRate(),0,0,r),this._getFeatures(e,t,i,r);let a=0;for(let u=e._lastFetchedIndex;u<e._known.length;u++){if(e._lastFetchedIndex+=1,a++,void 0===this._featureCache[e._known[u]]){let i=!1;if(null!==this._layer._mode&&void 0!==this._layer._mode){const t=this._layer._mode;if(void 0!==t._featureMap[e._known[u]]){const r=t._featureMap[e._known[u]];null!==r&&(i=!0,this._featureCache[e._known[u]]=r)}}if(!1===i&&(e._known[u]!==t&&s.push(e._known[u]),s.length>=this._maxProcessingRate()-1))break}if(a>=i&&0===s.length)break}if(0===s.length)return"success";const n=new F;this._requestStandardised&&(n.sqlFormat="standard"),this.datesInUnknownTimezone&&(n.timeReferenceUnknownClient=!0),n.objectIds=s,n.outFields=this._overrideFields??this._fieldsIncludingObjectId(["*"]),n.returnGeometry=!0,!0===this._removeGeometry&&(n.returnGeometry=!1),n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(r),void 0!==l.error)throw new C(P.RequestFailed,{reason:l.error});const o=this._layer.objectIdField;for(let u=0;u<l.features.length;u++)this._featureCache[l.features[u].attributes[o]]=l.features[u];return"success"}async _getDistinctPages(e,t,i,r,s,a,n,l,o){await this._ensureLoaded();const u=await this.databaseType();let c=i.parseTree.column;const h=this._layer.fields??[];for(let d=0;d<h.length;d++)if(h[d].name.toLowerCase()===c.toLowerCase()){c=h[d].name;break}const p=new F;this._requestStandardised&&(p.sqlFormat="standard"),this.datesInUnknownTimezone&&(p.timeReferenceUnknownClient=!0);let y=null===a?null===s?"1=1":"":d(a,u);this._layer.definitionExpression&&this._useDefinitionExpression&&(y=""!==y?"(("+this._layer.definitionExpression+") AND ("+y+"))":this._layer.definitionExpression),p.where=y,p.spatialRelationship=this._makeRelationshipEnum(r),p.relationParameter=this._makeRelationshipParam(r),p.geometry=null===s?null:s,p.returnDistinctValues=!0,p.returnGeometry=!1,p.outFields=[c];const f=await this.executeQuery(p,"execute");if(this._checkCancelled(o),!f.hasOwnProperty("features"))throw new C(P.InvalidStatResponse);let m=!1;for(let d=0;d<h.length;d++)if(h[d].name===c){"date"===h[d].type&&(m=!0);break}for(let d=0;d<f.features.length;d++){if(m){const e=f.features[d].attributes[c];null!==e?l.push(new Date(e)):l.push(e)}else l.push(f.features[d].attributes[c]);if(l.length>=n)break}if(0===f.features.length)return l;if(f.features.length===this._layer.capabilities?.query.maxRecordCount&&l.length<n){return{calculated:!0,result:await this._getDistinctPages(e+f.features.length,t,i,r,s,a,n,l,o)}}return l}async _distinctStat(e,t,i,r,s,a,n){return{calculated:!0,result:await this._getDistinctPages(0,e,t,i,r,s,a,[],n)}}isTable(){return this._layer.isTable||null===this._layer.geometryType||"table"===this._layer.type||""===this._layer.geometryType||"esriGeometryNull"===this._layer.geometryType}async _countstat(e,t,i,r){const s=await this.databaseType(),a=new F;if(this._requestStandardised&&(a.sqlFormat="standard"),this.isTable()&&i&&null!==t&&""!==t)return{calculated:!0,result:0};let n=null===r?null===i?"1=1":"":d(r,s);this._layer.definitionExpression&&this._useDefinitionExpression&&(n=""!==n?"(("+this._layer.definitionExpression+") AND ("+n+"))":this._layer.definitionExpression),a.where=n,this.datesInUnknownTimezone&&(a.timeReferenceUnknownClient=!0),a.where=n,a.spatialRelationship=this._makeRelationshipEnum(t),a.relationParameter=this._makeRelationshipParam(t),a.geometry=null===i?null:i,a.returnGeometry=!1;return{calculated:!0,result:await this.executeQuery(a,"executeForCount")}}async _stats(e,t,i,r,s,a,n){await this._ensureLoaded();const l=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression,o=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics,u=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsDistinct;if("count"===e)return u?this._countstat(e,i,r,s):{calculated:!1};if(!1===o||!1===c(t)&&!1===l||!1===t.isStandardized)return""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n);if("distinct"===e)return!1===u?""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n):this._distinctStat(e,t,i,r,s,a,n);const p=await this.databaseType();if(this.isTable()&&r&&null!==i&&""!==i)return{calculated:!0,result:null};const y=new F;this._requestStandardised&&(y.sqlFormat="standard");let f=null===s?null===r?"1=1":"":d(s,p);this._layer.definitionExpression&&this._useDefinitionExpression&&(f=""!==f?"(("+this._layer.definitionExpression+") AND ("+f+"))":this._layer.definitionExpression),y.where=f,y.spatialRelationship=this._makeRelationshipEnum(i),y.relationParameter=this._makeRelationshipParam(i),y.geometry=null===r?null:r,this.datesInUnknownTimezone&&(y.timeReferenceUnknownClient=!0);const m=new x;m.statisticType=h(e),m.onStatisticField=d(t,p),m.outStatisticFieldName="ARCADE_STAT_RESULT",y.returnGeometry=!1;let _="ARCADE_STAT_RESULT";y.outStatistics=[m];const g=await this.executeQuery(y,"execute");if(!g.hasOwnProperty("features")||0===g.features.length)throw new C(P.InvalidStatResponse);let R=!1;const S=g.fields??[];for(let d=0;d<S.length;d++)if("ARCADE_STAT_RESULT"===S[d].name.toUpperCase()){_=S[d].name,"date"===S[d].type&&(R=!0);break}if(R){let e=g.features[0].attributes[_];return null!==e&&(e=new Date(g.features[0].attributes[_])),{calculated:!0,result:e}}return{calculated:!0,result:g.features[0].attributes[_]}}_stat(e,t,i,r,s,a,n){return this._stats(e,t,i,r,s,a,n)}async _canDoAggregates(e,t){await this._ensureLoaded();let i=!1;const r=this._layer.capabilities?.query,s=!0===r?.supportsSqlExpression;if(null!=r&&!0===r.supportsStatistics&&!0===r.supportsOrderBy&&(i=!0),i)for(let a=0;a<t.length-1;a++)(!1===t[a].workingexpr?.isStandardized||!1===c(t[a].workingexpr)&&!1===s)&&(i=!1);return!1!==i}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _getAggregatePagesDataSourceDefinition(e,t,i,r,a,n,l){await this._ensureLoaded();const o=await this.databaseType();let u="",c=!1,h=!1;null!==n&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(u=n.constructClause(),h=!0),this._layer.capabilities&&this._layer.capabilities.query&&!1===this._layer.capabilities.query.supportsPagination&&(h=!1,c=!0,u=this._layer.objectIdField);const p=[];for(let s=0;s<t.length;s++){const e=new x;e.onStatisticField=null!==t[s].workingexpr?d(t[s].workingexpr,o):"",e.outStatisticFieldName=t[s].field,e.statisticType=t[s].toStatisticsName(),p.push(e)}""===u&&(u=e.join(","));let y=this._maxQueryRate();const f=this._layer.capabilities?.query.maxRecordCount;null!=f&&f<y&&(y=f);let m=null===a?null===r?"1=1":"":d(a,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(m=""!==m?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression);return new s([],["GETPAGES"],h,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:c,generatedOid:l,resultRecordCount:y,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:p,geometry:null===r?null:r,where:m,orderByFields:u,returnGeometry:!1,returnIdsOnly:!1,internal:{lastMaxId:-1,set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}async _getAgregagtePhysicalPage(t,i,r){let s=t.pagesDefinition.where;!0===t.pagesDefinition.useOIDpagination&&(s=""!==s?"("+s+") AND ("+t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString()+")":t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString());const a=t.pagesDefinition.internal.lastRetrieved,n=a,l=t.pagesDefinition.internal.lastPage,o=new F;if(this._requestStandardised&&(o.sqlFormat="standard"),o.where=s,o.spatialRelationship=t.pagesDefinition.spatialRel,o.relationParameter=t.pagesDefinition.relationParam,o.outFields=t.pagesDefinition.outFields,o.outStatistics=t.pagesDefinition.outStatistics,o.geometry=t.pagesDefinition.geometry,o.groupByFieldsForStatistics=t.pagesDefinition.groupByFieldsForStatistics,o.num=t.pagesDefinition.resultRecordCount,o.start=t.pagesDefinition.internal.lastPage,o.returnGeometry=t.pagesDefinition.returnGeometry,this.datesInUnknownTimezone&&(o.timeReferenceUnknownClient=!0),o.orderByFields=""!==t.pagesDefinition.orderByFields?t.pagesDefinition.orderByFields.split(","):null,this.isTable()&&o.geometry&&o.spatialRelationship)return[];const u=await this.executeQuery(o,"execute");if(this._checkCancelled(r),!u.hasOwnProperty("features"))throw new C(P.InvalidStatResponse);const d=[];if(t.pagesDefinition.internal.lastPage!==l)return[];u.features.length>0&&void 0===u.features[0].attributes[t.pagesDefinition.generatedOid]&&(t.pagesDefinition.generatedOid=t.pagesDefinition.generatedOid.toLowerCase());for(let e=0;e<u.features.length;e++)t.pagesDefinition.internal.set[n+e]=u.features[e].attributes[t.pagesDefinition.generatedOid];for(let c=0;c<u.features.length;c++)d.push(new e({attributes:u.features[c].attributes,geometry:null}));return!0===t.pagesDefinition.useOIDpagination?0===u.features.length?t.pagesDefinition.internal.fullyResolved=!0:t.pagesDefinition.internal.lastMaxId=u.features[u.features.length-1].attributes[t.pagesDefinition.generatedOid]:(void 0===u.exceededTransferLimit&&u.features.length!==t.pagesDefinition.resultRecordCount||!1===u.exceededTransferLimit)&&(t.pagesDefinition.internal.fullyResolved=!0),t.pagesDefinition.internal.lastRetrieved=a+u.features.length,t.pagesDefinition.internal.lastPage+=t.pagesDefinition.resultRecordCount,d}static create(e,t,i,r,s){const a=new _({url:e,outFields:null===t?["*"]:t});return new q({layer:a,spatialReference:i,lrucache:r,interceptor:s})}relationshipMetaData(){return this._layer&&this._layer.source&&this._layer.source.sourceJSON&&this._layer.source.sourceJSON.relationships?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return u(this._layer.parsedUrl.path)}async queryAttachments(e,t,r,s,a){const n=this._layer.capabilities;if(n?.data.supportsAttachment&&n?.operations.supportsQueryAttachments){const n={objectIds:[e],returnMetadata:a};(t&&t>0||r&&r>0)&&(n.size=[t&&t>0?t:0,r&&r>0?r:t+1]),s&&s.length>0&&(n.attachmentTypes=s),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:n,method:"attachments"});const l=await this._layer.queryAttachments(n),o=[];return l&&l[e]&&l[e].forEach((t=>{const r=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+t.id.toString();let s=null;a&&t.exifInfo&&(s=T.convertJsonToArcade(t.exifInfo,"system",!0)),o.push(new i(t.id,t.name,t.contentType,t.size,r,s,t.keywords??null))})),o}return[]}async queryRelatedFeatures(i){const r={f:"json",relationshipId:i.relationshipId.toString(),definitionExpression:i.where,outFields:i.outFields?.join(","),returnGeometry:i.returnGeometry.toString()};void 0!==i.resultOffset&&null!==i.resultOffset&&(r.resultOffset=i.resultOffset.toString()),void 0!==i.resultRecordCount&&null!==i.resultRecordCount&&(r.resultRecordCount=i.resultRecordCount.toString()),i.orderByFields&&(r.orderByFields=i.orderByFields.join(",")),i.objectIds&&i.objectIds.length>0&&(r.objectIds=i.objectIds.join(",")),i.outSpatialReference&&(r.outSR=JSON.stringify(i.outSpatialReference.toJSON())),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:r,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await t(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:r});if(s.data){const t={},i=s.data;if(i&&i.relatedRecordGroups){const r=i.spatialReference;for(const s of i.relatedRecordGroups){const a=s.objectId,n=[];for(const t of s.relatedRecords){t.geometry&&(t.geometry.spatialReference=r);const i=new e({geometry:t.geometry?m(t.geometry):null,attributes:t.attributes});n.push(i)}t[a]={features:n,exceededTransferLimit:!0===i.exceededTransferLimit}}}return t}throw new C(P.InvalidRequest)}async getFeatureByObjectId(e,t){const i=new F;i.outFields=t,i.returnGeometry=!1,i.outSpatialReference=this.spatialReference,i.where=this.objectIdField+"="+e.toString(),this.datesInUnknownTimezone&&(i.timeReferenceUnknownClient=!0),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:i,method:"execute"});const r=await R(this._layer.parsedUrl.path,i);return 1===r.features.length?r.features[0]:null}async getIdentityUser(){await this.load();const e=f?.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){await this.load();const e=f?.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let i=this._layer.url;const r=i.toLowerCase().indexOf("/rest/services");if(i=r>-1?i.substring(0,r):i,i){i+="/rest/info";try{const e=await t(i,{query:{f:"json"}});let r="";return e.data&&e.data.owningSystemUrl&&(r=e.data.owningSystemUrl),r}catch(s){return""}}return""}getDataSourceFeatureSet(){const e=new q({layer:this._layer,spatialReference:this.spatialReference??void 0,outFields:this._overrideFields??void 0,includeGeometry:!this._removeGeometry,lrucache:this.recentlyUsedQueries??void 0,interceptor:this.featureSetQueryInterceptor??void 0});return e._useDefinitionExpression=!1,e}get preferredTimeReference(){return void 0===this._cachedDateMetaData.preferredTimeReference&&(this._cachedDateMetaData.preferredTimeReference=this._layer?.preferredTimeReference?.toJSON()??null),this._cachedDateMetaData.preferredTimeReference}get dateFieldsTimeReference(){return void 0===this._cachedDateMetaData.dateFieldsTimeReference&&(this._cachedDateMetaData.dateFieldsTimeReference=this._layer?.dateFieldsTimeReference?.toJSON()??null),this._cachedDateMetaData.dateFieldsTimeReference}get datesInUnknownTimezone(){return this._layer.datesInUnknownTimezone}get editFieldsInfo(){return void 0===this._cachedDateMetaData.editFieldsInfo&&(this._cachedDateMetaData.editFieldsInfo=this._layer?.editFieldsInfo?.toJSON()??null),this._cachedDateMetaData.editFieldsInfo}get timeInfo(){return void 0===this._cachedDateMetaData.timeInfo&&(this._cachedDateMetaData.timeInfo=this._layer?.timeInfo?.toJSON()??null),this._cachedDateMetaData.timeInfo}}export{q as default};
|
|
5
|
+
import e from"../../../Graphic.js";import t from"../../../request.js";import i from"../../Attachment.js";import r from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{defaultMaxRecords as a,stableStringify as n,FeatureServiceDatabaseType as l,IdState as o,extractServiceUrl as u}from"../support/shared.js";import{toWhereClause as d,isSingleField as c}from"../support/sqlUtils.js";import{decodeStatType as h}from"../support/stats.js";import{createMD5Hash as p,outputTypes as y}from"../../../core/MD5.js";import{id as f}from"../../../kernel.js";import{fromJSON as m}from"../../../geometry/support/jsonUtils.js";import _ from"../../../layers/FeatureLayer.js";import{executeQuery as g}from"../../../rest/query/executeQuery.js";import"../../../config.js";import"../../../core/arrayUtils.js";import"../../../core/has.js";import"../../../core/urlUtils.js";import"../../../rest/query/support/AttachmentInfo.js";import"../../../rest/support/AttachmentQuery.js";import{executeForCount as R}from"../../../rest/query/executeForCount.js";import"../../../geometry.js";import"../../../geometry/support/normalizeUtils.js";import"../../../core/Error.js";import"../../../core/pbf.js";import"../../../core/unitUtils.js";import"../../../geometry/support/spatialReferenceUtils.js";import w from"../../../rest/support/Query.js";import{executeForIds as S}from"../../../rest/query/executeForIds.js";import{executeQueryJSON as F}from"../../../rest/query/executeQueryJSON.js";import"../../../layers/graphics/featureConversionUtils.js";import"../../../rest/support/FeatureSet.js";import"../../../rest/support/RelationshipQuery.js";import"../../../rest/support/TopFeaturesQuery.js";import b from"../../../rest/support/StatisticDefinition.js";import D from"../../Dictionary.js";import{FeatureSetError as I,FeatureSetErrorCodes as x}from"../support/errorsupport.js";import T from"../../../layers/SubtypeGroupLayer.js";class C extends r{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerDynamic",this._removeGeometry=!1,this._overrideFields=null,this.formulaCredential=null,this._pageJustIds=!1,this._requestStandardised=!1,this._useDefinitionExpression=!0,this._cachedDateMetaData={},e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}get urlQueryPath(){return this._layer.parsedUrl.path||""}convertQueryToLruCacheKey(e){const t=this.urlQueryPath+","+n(e.toJSON());return p(t,y.String)}async loadImpl(){return!0===this._layer.loaded?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),this.hasZ=!0===this._layer?.capabilities?.data?.supportsZ,this.hasM=!0===this._layer?.capabilities?.data?.supportsM,null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const i of this.fields)if("oid"===i.type)e.push(i),t.push(i.name);else for(const r of this._overrideFields)if(r.toLowerCase()===i.name.toLowerCase()){e.push(i),t.push(i.name);break}this.fields=e,this._overrideFields=t}if(this._layer.source&&this._layer.source.sourceJSON){const e=this._layer.source.sourceJSON.currentVersion;!0===this._layer.source.sourceJSON.useStandardizedQueries?(this._databaseType=l.StandardisedNoInterval,null!=e&&e>=10.61&&(this._databaseType=l.Standardised)):null!=e&&(e>=10.5&&(this._databaseType=l.StandardisedNoInterval,this._requestStandardised=!0),e>=10.61&&(this._databaseType=l.Standardised))}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this._layer instanceof T?(this.typeIdField=this._layer.subtypeField??"",this.types=this._layer.subtypes):(this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types)}_isInFeatureSet(){return o.InFeatureSet}async _refineSetBlock(e){return e}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}async _runDatabaseProbe(e){await this._ensureLoaded();const t=new w;this.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),t.where=e.replace("OBJECTID",this._layer.objectIdField);try{return await this._layer.queryObjectIds(t),!0}catch(i){return!1}}_canUsePagination(){return!(!this._layer.capabilities||!this._layer.capabilities.query||!0!==this._layer.capabilities.query.supportsPagination)}_cacheableFeatureSetSourceKey(){return this._layer.url}pbfSupportedForQuery(e){const t=this._layer?.capabilities?.query;return!e.outStatistics&&!0===t?.supportsFormatPBF&&!0===t?.supportsQuantizationEditMode}async queryPBF(e){return e.quantizationParameters={mode:"edit"},(await g(this._layer.parsedUrl,e,{format:"pbf"},{})).unquantize()}get gdbVersion(){return this._layer&&this._layer.capabilities&&this._layer.capabilities.data&&this._layer.capabilities.data.isVersioned?this._layer.gdbVersion||"SDE.DEFAULT":""}nativeCapabilities(){return{title:this._layer.title??"",source:this,canQueryRelated:!0,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:this._requestStandardised}}executeQuery(e,t){e.returnZ=this.hasZ,e.returnM=this.hasM;const i="execute"===t?F:"executeForCount"===t?R:S,r="execute"===t&&this.pbfSupportedForQuery(e);let s=null;if(this.recentlyUsedQueries){const t=this.convertQueryToLruCacheKey(e);s=this.recentlyUsedQueries.getFromCache(t),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e),this.recentlyUsedQueries.addToCache(t,s),s=s.catch((e=>{throw this.recentlyUsedQueries?.removeFromCache(t),e})))}return this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:e,method:t}),null===s&&(s=!0!==r?i(this._layer.parsedUrl.path,e):this.queryPBF(e)),s}async _getFilteredSet(e,t,i,r,a){const n=await this.databaseType();if(this.isTable()&&t&&null!==e&&""!==e){return new s([],[],!0,null)}if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,r,a);let l="",o=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(l=r.constructClause(),o=!0);const u=new w;this.datesInUnknownTimezone&&(u.timeReferenceUnknownClient=!0),u.where=null===i?null===t?"1=1":"":d(i,n),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==l?l.split(","):null,u.geometry=null===t?null:t,u.relationParameter=this._makeRelationshipParam(e);let c=await this.executeQuery(u,"executeForIds");null===c&&(c=[]),this._checkCancelled(a);return new s([],c,o,null)}_expandPagedSet(e,t,i,r,s){return this._expandPagedSetFeatureSet(e,t,i,r,s)}async _getFilteredSetUsingPaging(e,t,i,r,a){let n="",l=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(n=r.constructClause(),l=!0);const o=await this.databaseType();let u=null===i?null===t?"1=1":"":d(i,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=""!==u?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let c=this._maxQueryRate();const h=this._layer.capabilities?.query.maxRecordCount;null!=h&&h<c&&(c=h);let p=null;if(!0===this._pageJustIds)p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:c,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:!1,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}});else{let i=!0;!0===this._removeGeometry&&(i=!1);const r=this._overrideFields??this._fieldsIncludingObjectId(["*"]);p=new s([],["GETPAGES"],l,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:r.join(","),resultRecordCount:c,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:n,returnGeometry:i,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(p,c,0,1,a),p}_clonePageDefinition(e){return null===e?null:!0!==e.groupbypage?{groupbypage:!1,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,spatialRel:e.spatialRel,relationParam:e.relationParam,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,i){const r=e.pagesDefinition.internal.lastRetrieved,s=r,a=e.pagesDefinition.internal.lastPage,n=new w;this._requestStandardised&&(n.sqlFormat="standard"),this.datesInUnknownTimezone&&(n.timeReferenceUnknownClient=!0),n.spatialRelationship=e.pagesDefinition.spatialRel,n.relationParameter=e.pagesDefinition.relationParam,n.outFields=e.pagesDefinition.outFields.split(","),n.num=e.pagesDefinition.resultRecordCount,n.start=e.pagesDefinition.internal.lastPage,n.geometry=e.pagesDefinition.geometry,n.where=e.pagesDefinition.where,n.orderByFields=""!==e.pagesDefinition.orderByFields?e.pagesDefinition.orderByFields.split(","):null,n.returnGeometry=e.pagesDefinition.returnGeometry,n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(i),e.pagesDefinition.internal.lastPage!==a)return"done";const o=this._layer.objectIdField;for(let u=0;u<l.features.length;u++)e.pagesDefinition.internal.set[s+u]=l.features[u].attributes[o];if(!1===this._pageJustIds)for(let u=0;u<l.features.length;u++)this._featureCache[l.features[u].attributes[o]]=l.features[u];return(void 0===l.exceededTransferLimit&&l.features.length!==e.pagesDefinition.resultRecordCount||!1===l.exceededTransferLimit)&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=r+l.features.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,"done"}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let i=!1;for(const r of t)if(r.toUpperCase()===this.objectIdField.toUpperCase()){i=!0;break}return!1===i&&t.push(this.objectIdField),t}async _getFeatures(e,t,i,r){const s=[];if(-1!==t&&void 0===this._featureCache[t]&&s.push(t),!0===this._checkIfNeedToExpandKnownPage(e,this._maxProcessingRate()))return await this._expandPagedSet(e,this._maxProcessingRate(),0,0,r),this._getFeatures(e,t,i,r);let a=0;for(let u=e._lastFetchedIndex;u<e._known.length;u++){if(e._lastFetchedIndex+=1,a++,void 0===this._featureCache[e._known[u]]){let i=!1;if(null!==this._layer._mode&&void 0!==this._layer._mode){const t=this._layer._mode;if(void 0!==t._featureMap[e._known[u]]){const r=t._featureMap[e._known[u]];null!==r&&(i=!0,this._featureCache[e._known[u]]=r)}}if(!1===i&&(e._known[u]!==t&&s.push(e._known[u]),s.length>=this._maxProcessingRate()-1))break}if(a>=i&&0===s.length)break}if(0===s.length)return"success";const n=new w;this._requestStandardised&&(n.sqlFormat="standard"),this.datesInUnknownTimezone&&(n.timeReferenceUnknownClient=!0),n.objectIds=s,n.outFields=this._overrideFields??this._fieldsIncludingObjectId(["*"]),n.returnGeometry=!0,!0===this._removeGeometry&&(n.returnGeometry=!1),n.outSpatialReference=this.spatialReference;const l=await this.executeQuery(n,"execute");if(this._checkCancelled(r),void 0!==l.error)throw new I(x.RequestFailed,{reason:l.error});const o=this._layer.objectIdField;for(let u=0;u<l.features.length;u++)this._featureCache[l.features[u].attributes[o]]=l.features[u];return"success"}async _getDistinctPages(e,t,i,r,s,a,n,l,o){await this._ensureLoaded();const u=await this.databaseType();let c=i.parseTree.column;const h=this._layer.fields??[];for(let d=0;d<h.length;d++)if(h[d].name.toLowerCase()===c.toLowerCase()){c=h[d].name;break}const p=new w;this._requestStandardised&&(p.sqlFormat="standard"),this.datesInUnknownTimezone&&(p.timeReferenceUnknownClient=!0);let y=null===a?null===s?"1=1":"":d(a,u);this._layer.definitionExpression&&this._useDefinitionExpression&&(y=""!==y?"(("+this._layer.definitionExpression+") AND ("+y+"))":this._layer.definitionExpression),p.where=y,p.spatialRelationship=this._makeRelationshipEnum(r),p.relationParameter=this._makeRelationshipParam(r),p.geometry=null===s?null:s,p.returnDistinctValues=!0,p.returnGeometry=!1,p.outFields=[c];const f=await this.executeQuery(p,"execute");if(this._checkCancelled(o),!f.hasOwnProperty("features"))throw new I(x.InvalidStatResponse);let m=!1;for(let d=0;d<h.length;d++)if(h[d].name===c){"date"===h[d].type&&(m=!0);break}for(let d=0;d<f.features.length;d++){if(m){const e=f.features[d].attributes[c];null!==e?l.push(new Date(e)):l.push(e)}else l.push(f.features[d].attributes[c]);if(l.length>=n)break}if(0===f.features.length)return l;if(f.features.length===this._layer.capabilities?.query.maxRecordCount&&l.length<n){return{calculated:!0,result:await this._getDistinctPages(e+f.features.length,t,i,r,s,a,n,l,o)}}return l}async _distinctStat(e,t,i,r,s,a,n){return{calculated:!0,result:await this._getDistinctPages(0,e,t,i,r,s,a,[],n)}}isTable(){return this._layer.isTable||null===this._layer.geometryType||"table"===this._layer.type||""===this._layer.geometryType||"esriGeometryNull"===this._layer.geometryType}async _countstat(e,t,i,r){const s=await this.databaseType(),a=new w;if(this._requestStandardised&&(a.sqlFormat="standard"),this.isTable()&&i&&null!==t&&""!==t)return{calculated:!0,result:0};let n=null===r?null===i?"1=1":"":d(r,s);this._layer.definitionExpression&&this._useDefinitionExpression&&(n=""!==n?"(("+this._layer.definitionExpression+") AND ("+n+"))":this._layer.definitionExpression),a.where=n,this.datesInUnknownTimezone&&(a.timeReferenceUnknownClient=!0),a.where=n,a.spatialRelationship=this._makeRelationshipEnum(t),a.relationParameter=this._makeRelationshipParam(t),a.geometry=null===i?null:i,a.returnGeometry=!1;return{calculated:!0,result:await this.executeQuery(a,"executeForCount")}}async _stats(e,t,i,r,s,a,n){await this._ensureLoaded();const l=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression,o=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics,u=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsDistinct;if("count"===e)return u?this._countstat(e,i,r,s):{calculated:!1};if(!1===o||!1===c(t)&&!1===l||!1===t.isStandardized)return""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n);if("distinct"===e)return!1===u?""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,a,n):this._distinctStat(e,t,i,r,s,a,n);const p=await this.databaseType();if(this.isTable()&&r&&null!==i&&""!==i)return{calculated:!0,result:null};const y=new w;this._requestStandardised&&(y.sqlFormat="standard");let f=null===s?null===r?"1=1":"":d(s,p);this._layer.definitionExpression&&this._useDefinitionExpression&&(f=""!==f?"(("+this._layer.definitionExpression+") AND ("+f+"))":this._layer.definitionExpression),y.where=f,y.spatialRelationship=this._makeRelationshipEnum(i),y.relationParameter=this._makeRelationshipParam(i),y.geometry=null===r?null:r,this.datesInUnknownTimezone&&(y.timeReferenceUnknownClient=!0);const m=new b;m.statisticType=h(e),m.onStatisticField=d(t,p),m.outStatisticFieldName="ARCADE_STAT_RESULT",y.returnGeometry=!1;let _="ARCADE_STAT_RESULT";y.outStatistics=[m];const g=await this.executeQuery(y,"execute");if(!g.hasOwnProperty("features")||0===g.features.length)throw new I(x.InvalidStatResponse);let R=!1;const S=g.fields??[];for(let d=0;d<S.length;d++)if("ARCADE_STAT_RESULT"===S[d].name.toUpperCase()){_=S[d].name,"date"===S[d].type&&(R=!0);break}if(R){let e=g.features[0].attributes[_];return null!==e&&(e=new Date(g.features[0].attributes[_])),{calculated:!0,result:e}}return{calculated:!0,result:g.features[0].attributes[_]}}_stat(e,t,i,r,s,a,n){return this._stats(e,t,i,r,s,a,n)}async _canDoAggregates(e,t){await this._ensureLoaded();let i=!1;const r=this._layer.capabilities?.query,s=!0===r?.supportsSqlExpression;if(null!=r&&!0===r.supportsStatistics&&!0===r.supportsOrderBy&&(i=!0),i)for(let a=0;a<t.length-1;a++)(!1===t[a].workingexpr?.isStandardized||!1===c(t[a].workingexpr)&&!1===s)&&(i=!1);return!1!==i}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _getAggregatePagesDataSourceDefinition(e,t,i,r,a,n,l){await this._ensureLoaded();const o=await this.databaseType();let u="",c=!1,h=!1;null!==n&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(u=n.constructClause(),h=!0),this._layer.capabilities&&this._layer.capabilities.query&&!1===this._layer.capabilities.query.supportsPagination&&(h=!1,c=!0,u=this._layer.objectIdField);const p=[];for(let s=0;s<t.length;s++){const e=new b;e.onStatisticField=null!==t[s].workingexpr?d(t[s].workingexpr,o):"",e.outStatisticFieldName=t[s].field,e.statisticType=t[s].toStatisticsName(),p.push(e)}""===u&&(u=e.join(","));let y=this._maxQueryRate();const f=this._layer.capabilities?.query.maxRecordCount;null!=f&&f<y&&(y=f);let m=null===a?null===r?"1=1":"":d(a,o);this._layer.definitionExpression&&this._useDefinitionExpression&&(m=""!==m?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression);return new s([],["GETPAGES"],h,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:c,generatedOid:l,resultRecordCount:y,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:p,geometry:null===r?null:r,where:m,orderByFields:u,returnGeometry:!1,returnIdsOnly:!1,internal:{lastMaxId:-1,set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}async _getAgregagtePhysicalPage(t,i,r){let s=t.pagesDefinition.where;!0===t.pagesDefinition.useOIDpagination&&(s=""!==s?"("+s+") AND ("+t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString()+")":t.pagesDefinition.generatedOid+">"+t.pagesDefinition.internal.lastMaxId.toString());const a=t.pagesDefinition.internal.lastRetrieved,n=a,l=t.pagesDefinition.internal.lastPage,o=new w;if(this._requestStandardised&&(o.sqlFormat="standard"),o.where=s,o.spatialRelationship=t.pagesDefinition.spatialRel,o.relationParameter=t.pagesDefinition.relationParam,o.outFields=t.pagesDefinition.outFields,o.outStatistics=t.pagesDefinition.outStatistics,o.geometry=t.pagesDefinition.geometry,o.groupByFieldsForStatistics=t.pagesDefinition.groupByFieldsForStatistics,o.num=t.pagesDefinition.resultRecordCount,o.start=t.pagesDefinition.internal.lastPage,o.returnGeometry=t.pagesDefinition.returnGeometry,this.datesInUnknownTimezone&&(o.timeReferenceUnknownClient=!0),o.orderByFields=""!==t.pagesDefinition.orderByFields?t.pagesDefinition.orderByFields.split(","):null,this.isTable()&&o.geometry&&o.spatialRelationship)return[];const u=await this.executeQuery(o,"execute");if(this._checkCancelled(r),!u.hasOwnProperty("features"))throw new I(x.InvalidStatResponse);const d=[];if(t.pagesDefinition.internal.lastPage!==l)return[];u.features.length>0&&void 0===u.features[0].attributes[t.pagesDefinition.generatedOid]&&(t.pagesDefinition.generatedOid=t.pagesDefinition.generatedOid.toLowerCase());for(let e=0;e<u.features.length;e++)t.pagesDefinition.internal.set[n+e]=u.features[e].attributes[t.pagesDefinition.generatedOid];for(let c=0;c<u.features.length;c++)d.push(new e({attributes:u.features[c].attributes,geometry:null}));return!0===t.pagesDefinition.useOIDpagination?0===u.features.length?t.pagesDefinition.internal.fullyResolved=!0:t.pagesDefinition.internal.lastMaxId=u.features[u.features.length-1].attributes[t.pagesDefinition.generatedOid]:(void 0===u.exceededTransferLimit&&u.features.length!==t.pagesDefinition.resultRecordCount||!1===u.exceededTransferLimit)&&(t.pagesDefinition.internal.fullyResolved=!0),t.pagesDefinition.internal.lastRetrieved=a+u.features.length,t.pagesDefinition.internal.lastPage+=t.pagesDefinition.resultRecordCount,d}static create(e,t,i,r,s){const a=new _({url:e,outFields:null===t?["*"]:t});return new C({layer:a,spatialReference:i,lrucache:r,interceptor:s})}relationshipMetaData(){return this._layer&&this._layer.source&&this._layer.source.sourceJSON&&this._layer.source.sourceJSON.relationships?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return u(this._layer.parsedUrl.path)}async queryAttachments(e,t,r,s,a){const n=this._layer.capabilities;if(n?.data.supportsAttachment&&n?.operations.supportsQueryAttachments){const n={objectIds:[e],returnMetadata:a};(t&&t>0||r&&r>0)&&(n.size=[t&&t>0?t:0,r&&r>0?r:t+1]),s&&s.length>0&&(n.attachmentTypes=s),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:n,method:"attachments"});const l=await this._layer.queryAttachments(n),o=[];return l&&l[e]&&l[e].forEach((t=>{const r=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+t.id.toString();let s=null;a&&t.exifInfo&&(s=D.convertJsonToArcade(t.exifInfo,"system",!0)),o.push(new i(t.id,t.name,t.contentType,t.size,r,s,t.keywords??null))})),o}return[]}async queryRelatedFeatures(i){const r={f:"json",relationshipId:i.relationshipId.toString(),definitionExpression:i.where,outFields:i.outFields?.join(","),returnGeometry:i.returnGeometry.toString()};void 0!==i.resultOffset&&null!==i.resultOffset&&(r.resultOffset=i.resultOffset.toString()),void 0!==i.resultRecordCount&&null!==i.resultRecordCount&&(r.resultRecordCount=i.resultRecordCount.toString()),i.orderByFields&&(r.orderByFields=i.orderByFields.join(",")),i.objectIds&&i.objectIds.length>0&&(r.objectIds=i.objectIds.join(",")),i.outSpatialReference&&(r.outSR=JSON.stringify(i.outSpatialReference.toJSON())),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:r,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await t(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:r});if(s.data){const t={},i=s.data;if(i&&i.relatedRecordGroups){const r=i.spatialReference;for(const s of i.relatedRecordGroups){const a=s.objectId,n=[];for(const t of s.relatedRecords){t.geometry&&(t.geometry.spatialReference=r);const i=new e({geometry:t.geometry?m(t.geometry):null,attributes:t.attributes});n.push(i)}t[a]={features:n,exceededTransferLimit:!0===i.exceededTransferLimit}}}return t}throw new I(x.InvalidRequest)}async getFeatureByObjectId(e,t){const i=new w;i.outFields=t,i.returnGeometry=!1,i.outSpatialReference=this.spatialReference,i.where=this.objectIdField+"="+e.toString(),this.datesInUnknownTimezone&&(i.timeReferenceUnknownClient=!0),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:i,method:"execute"});const r=await F(this._layer.parsedUrl.path,i);return 1===r.features.length?r.features[0]:null}async getIdentityUser(){await this.load();const e=f?.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){await this.load();const e=f?.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let i=this._layer.url;const r=i.toLowerCase().indexOf("/rest/services");if(i=r>-1?i.substring(0,r):i,i){i+="/rest/info";try{const e=await t(i,{query:{f:"json"}});let r="";return e.data&&e.data.owningSystemUrl&&(r=e.data.owningSystemUrl),r}catch(s){return""}}return""}getDataSourceFeatureSet(){const e=new C({layer:this._layer,spatialReference:this.spatialReference??void 0,outFields:this._overrideFields??void 0,includeGeometry:!this._removeGeometry,lrucache:this.recentlyUsedQueries??void 0,interceptor:this.featureSetQueryInterceptor??void 0});return e._useDefinitionExpression=!1,e}get preferredTimeReference(){return void 0===this._cachedDateMetaData.preferredTimeReference&&(this._cachedDateMetaData.preferredTimeReference=this._layer?.preferredTimeReference?.toJSON()??null),this._cachedDateMetaData.preferredTimeReference}get dateFieldsTimeReference(){return void 0===this._cachedDateMetaData.dateFieldsTimeReference&&(this._cachedDateMetaData.dateFieldsTimeReference=this._layer?.dateFieldsTimeReference?.toJSON()??null),this._cachedDateMetaData.dateFieldsTimeReference}get datesInUnknownTimezone(){return this._layer.datesInUnknownTimezone}get editFieldsInfo(){return void 0===this._cachedDateMetaData.editFieldsInfo&&(this._cachedDateMetaData.editFieldsInfo=this._layer?.editFieldsInfo?.toJSON()??null),this._cachedDateMetaData.editFieldsInfo}get timeInfo(){return void 0===this._cachedDateMetaData.timeInfo&&(this._cachedDateMetaData.timeInfo=this._layer?.timeInfo?.toJSON()??null),this._cachedDateMetaData.timeInfo}}export{C as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.27/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import s from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{defaultMaxRecords as a,FeatureServiceDatabaseType as
|
|
5
|
+
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import s from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{defaultMaxRecords as a,FeatureServiceDatabaseType as n,IdState as l}from"../support/shared.js";import{toWhereClause as o}from"../support/sqlUtils.js";import u from"../../../geometry/Geometry.js";import h from"../../../layers/FeatureLayer.js";import c from"../../../layers/SubtypeGroupLayer.js";import y from"../../../layers/support/FeatureType.js";import p from"../../../layers/support/Field.js";import d from"../../../rest/support/Query.js";class f extends s{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerMemory",this._removeGeometry=!1,this._overrideFields=null,this._forceIsTable=!1,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,!0===e.isTable&&(this._forceIsTable=!0),void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(){}async loadImpl(){return!0===this._layer.loaded?(this._initialiseFeatureSet(),this):(await this._layer.load(),this._initialiseFeatureSet(),this)}get gdbVersion(){return""}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._layer.geometryType,this.fields=this._layer.fields.slice(0),null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const r of this.fields)if("oid"===r.type)e.push(r),t.push(r.name);else for(const s of this._overrideFields)if(s.toLowerCase()===r.name.toLowerCase()){e.push(r),t.push(r.name);break}this.fields=e,this._overrideFields=t}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this._databaseType=n.Standardised,this.hasZ=!0===this._layer?.capabilities?.data?.supportsZ,this.hasM=!0===this._layer?.capabilities?.data?.supportsM,this._layer instanceof c?(this.typeIdField=this._layer.subtypeField??"",this.types=this._layer.subtypes):(this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types)}isTable(){return this._forceIsTable||this._layer.isTable||"table"===this._layer.type||!this._layer.geometryType}_isInFeatureSet(){return l.InFeatureSet}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}_changeFeature(t){const r={};for(const e of this.fields)r[e.name]=t.attributes[e.name];return new e({geometry:!0===this._removeGeometry?null:t.geometry,attributes:r})}async _getFilteredSet(e,t,r,s,a){let l="",u=!1;if(null!==s&&(l=s.constructClause(),u=!0),this.isTable()&&t&&null!==e&&""!==e){return new i([],[],!0,null)}const h=new d;h.returnZ=this.hasZ,h.returnM=this.hasM,h.where=null===r?null===t?"1=1":"":o(r,n.Standardised),h.spatialRelationship=this._makeRelationshipEnum(e),h.outSpatialReference=this.spatialReference,h.orderByFields=""!==l?l.split(","):null,h.geometry=null===t?null:t,h.returnGeometry=!0,h.relationParameter=this._makeRelationshipParam(e);const c=await this._layer.queryFeatures(h);if(null===c)return new i([],[],u,null);this._checkCancelled(a);const y=[];c.features.forEach((e=>{const t=e.attributes[this._layer.objectIdField];y.push(t),this._featureCache[t]=this._changeFeature(e)}));return new i([],y,u,null)}_makeRelationshipEnum(e){if(e.includes("esriSpatialRelRelation"))return"relation";switch(e){case"esriSpatialRelRelation":return"relation";case"esriSpatialRelIntersects":return"intersects";case"esriSpatialRelContains":return"contains";case"esriSpatialRelOverlaps":return"overlaps";case"esriSpatialRelWithin":return"within";case"esriSpatialRelTouches":return"touches";case"esriSpatialRelCrosses":return"crosses";case"esriSpatialRelEnvelopeIntersects":return"envelope-intersects"}return e}_makeRelationshipParam(e){return e.includes("esriSpatialRelRelation")?e.split(":")[1]:""}async _queryAllFeatures(){if(this._wset)return this._wset;const e=new d;if(e.where="1=1",await this._ensureLoaded(),this._layer.source&&this._layer.source.items){const e=[];return this._layer.source.items.forEach((t=>{const r=t.attributes[this._layer.objectIdField];e.push(r),this._featureCache[r]=this._changeFeature(t)})),this._wset=new i([],e,!1,null),this._wset}e.returnZ=this.hasZ,e.returnM=this.hasM;const t=await this._layer.queryFeatures(e),r=[];return t.features.forEach((e=>{const t=e.attributes[this._layer.objectIdField];r.push(t),this._featureCache[t]=this._changeFeature(e)})),this._wset=new i([],r,!1,null),this._wset}async _getFeatures(e,s,i){const a=[];-1!==s&&void 0===this._featureCache[s]&&a.push(s);for(let t=e._lastFetchedIndex;t<e._known.length&&(e._lastFetchedIndex+=1,!(void 0===this._featureCache[e._known[t]]&&(e._known[t]!==s&&a.push(e._known[t]),a.length>i)));t++);if(0===a.length)return"success";throw new t(r.MissingFeatures)}async _refineSetBlock(e){return e}async _stat(){return{calculated:!1}}async _canDoAggregates(){return!1}relationshipMetaData(){return[]}static _cloneAttr(e){const t={};for(const r in e)t[r]=e[r];return t}nativeCapabilities(){return{title:this._layer.title??"",canQueryRelated:!1,source:this,capabilities:this._layer.capabilities,databaseType:this._databaseType,requestStandardised:!0}}static create(e,t){let r=e.layerDefinition.objectIdField;const s=e.layerDefinition.typeIdField??"",i=[];if(e.layerDefinition.types)for(const u of e.layerDefinition.types)i.push(y.fromJSON(u));let a=e.layerDefinition.geometryType;void 0===a&&(a=e.featureSet.geometryType||"");let n=e.featureSet.features;const l=t.toJSON();if(!r){let t=!1;for(const s of e.layerDefinition.fields)if("oid"===s.type||"esriFieldTypeOID"===s.type){r=s.name,t=!0;break}if(!1===t){let t="FID",s=!0,i=0;for(;s;){let r=!0;for(const s of e.layerDefinition.fields)if(s.name===t){r=!1;break}!0===r?s=!1:(i++,t="FID"+i.toString())}e.layerDefinition.fields.push({type:"esriFieldTypeOID",name:t,alias:t});const a=[];for(let r=0;r<n.length;r++)a.push({geometry:e.featureSet.features[r].geometry,attributes:e.featureSet.features[r].attributes?this._cloneAttr(e.featureSet.features[r].attributes):{}}),a[r].attributes[t]=r;n=a,r=t}}const o=[];for(const u of e.layerDefinition.fields)u instanceof p?o.push(u):o.push(p.fromJSON(u));let c=a;switch(c||(c=""),c){case"esriGeometryPoint":c="point";break;case"esriGeometryPolyline":c="polyline";break;case"esriGeometryPolygon":c="polygon";break;case"esriGeometryEnvelope":c="extent";break;case"esriGeometryMultipoint":c="multipoint";break;case"":case"esriGeometryNull":c="esriGeometryNull"}if("esriGeometryNull"!==c)for(const h of n)h.geometry&&h.geometry instanceof u==!1&&(h.geometry.type=c,void 0===h.geometry.spatialReference&&(h.geometry.spatialReference=l));else for(const u of n)u.geometry&&(u.geometry=null);const d={outFields:["*"],source:n,fields:o,hasZ:!0===e?.layerDefinition?.hasZ||!0===e?.featureSet?.hasZ,hasM:!0===e?.layerDefinition?.hasM||!0===e?.featureSet?.hasM,types:i,typeIdField:s,objectIdField:r,spatialReference:t},m="esriGeometryNull"===c||null===c;m||(d.geometryType=c);const _=new h(d);return new f({layer:_,spatialReference:t,isTable:m})}async queryAttachments(){return[]}async getFeatureByObjectId(e){const t=new d;t.where=this.objectIdField+"="+e.toString(),t.returnZ=this.hasZ,t.returnM=this.hasM;const r=await this._layer.queryFeatures(t);return 1===r.features.length?r.features[0]:null}async getOwningSystemUrl(){return""}async getIdentityUser(){return""}get preferredTimeReference(){return this._layer?.preferredTimeReference?.toJSON()??null}get dateFieldsTimeReference(){return this._layer?.dateFieldsTimeReference?.toJSON()??null}get datesInUnknownTimezone(){return this._layer?.datesInUnknownTimezone}get editFieldsInfo(){return this._layer?.editFieldsInfo?.toJSON()??null}get timeInfo(){return this._layer?.timeInfo?.toJSON()??null}}export{f 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.27/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import i from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{defaultMaxRecords as a,IdState as n}from"../support/shared.js";import l from"../../../rest/support/RelationshipQuery.js";class d extends i{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerRelated",this._findObjectId=-1,this._requestStandardised=!1,this._removeGeometry=!1,this._overrideFields=null,this.featureObjectId=null,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,this._findObjectId=e.objectId,this.featureObjectId=e.objectId,this.relationship=e.relationship,this._relatedLayer=e.relatedLayer,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(){}async loadImpl(){return await Promise.all([this._layer.load(),this._relatedLayer?.load()]),this._initialiseFeatureSet(),this}nativeCapabilities(){return this._relatedLayer.nativeCapabilities()}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._relatedLayer.geometryType,this.fields=this._relatedLayer.fields.slice(0),null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const r of this.fields)if("oid"===r.type)e.push(r),t.push(r.name);else for(const i of this._overrideFields)if(i.toLowerCase()===r.name.toLowerCase()){e.push(r),t.push(r.name);break}this.fields=e,this._overrideFields=t}const e=this._layer.nativeCapabilities();e&&(this._databaseType=e.databaseType,this._requestStandardised=e.requestStandardised),this.objectIdField=this._relatedLayer.objectIdField,this.globalIdField=this._relatedLayer.globalIdField,this.hasM=this._relatedLayer.supportsM,this.hasZ=this._relatedLayer.supportsZ,this.typeIdField=this._relatedLayer.typeIdField,this.types=this._relatedLayer.types}async databaseType(){return await this._relatedLayer.databaseType(),this._databaseType=this._relatedLayer._databaseType,this._databaseType}isTable(){return this._relatedLayer.isTable()}_isInFeatureSet(){return n.InFeatureSet}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}_changeFeature(t){const r={};for(const e of this.fields)r[e.name]=t.attributes[e.name];return new e({geometry:!0===this._removeGeometry?null:t.geometry,attributes:r})}async _getFilteredSet(e,t,r,i,a){if(await this.databaseType(),this.isTable()&&t&&null!==e&&""!==e){return new s([],[],!0,null)}const n=this._layer.nativeCapabilities();if(!1===n.canQueryRelated){return new s([],[],!0,null)}if(n.capabilities?.queryRelated&&n.capabilities.queryRelated.supportsPagination)return this._getFilteredSetUsingPaging(e,t,r,i,a);let d="",o=!1;null!==i&&n.capabilities&&n.capabilities.queryRelated&&!0===n.capabilities.queryRelated.supportsOrderBy&&(d=i.constructClause(),o=!0);const u=new l;u.objectIds=[this._findObjectId];const h=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map((e=>e.name)):["*"]);u.outFields=h,u.relationshipId=this.relationship.id,u.where="1=1";let c=!0;!0===this._removeGeometry&&(c=!1),u.returnGeometry=c,this._requestStandardised&&(u.sqlFormat="standard"),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==d?d.split(","):null;const y=await n.source.queryRelatedFeatures(u);this._checkCancelled(a);const p=y[this._findObjectId]?y[this._findObjectId].features:[],_=[];for(let s=0;s<p.length;s++)this._featureCache[p[s].attributes[this._relatedLayer.objectIdField]]=p[s],_.push(p[s].attributes[this._relatedLayer.objectIdField]);const f=t&&null!==e&&""!==e,g=null!=r;return new s(f||g?_:[],f||g?[]:_,o,null)}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let r=!1;for(const i of t)if(i.toUpperCase()===this.objectIdField.toUpperCase()){r=!0;break}return!1===r&&t.push(this.objectIdField),t}async _getFilteredSetUsingPaging(e,t,r,i,a){let n="",l=!1;const d=this._layer.nativeCapabilities();null!==i&&d&&d.capabilities?.queryRelated&&!0===d.capabilities.queryRelated.supportsOrderBy&&(n=i.constructClause(),l=!0),await this.databaseType();const o="1=1";let u=this._maxQueryRate();const h=d.capabilities?.query.maxRecordCount;null!=h&&h<u&&(u=h);const c=t&&null!==e&&""!==e,y=null!=r;let p=null,_=!0;!0===this._removeGeometry&&(_=!1);const f=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map((e=>e.name)):["*"]);return p=new s(c||y?["GETPAGES"]:[],c||y?[]:["GETPAGES"],l,{outFields:f.join(","),resultRecordCount:u,resultOffset:0,objectIds:[this._findObjectId],where:o,orderByFields:n,returnGeometry:_,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}}),await this._expandPagedSet(p,u,0,0,a),p}_expandPagedSet(e,t,r,i,s){return this._expandPagedSetFeatureSet(e,t,r,i,s)}_clonePageDefinition(e){return null===e?null:!0!==e.groupbypage?{groupbypage:!1,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,where:e.where,objectIds:e.objectIds,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,objectIds:e.objectIds,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,r){const i=e.pagesDefinition.internal.lastRetrieved,s=i,a=e.pagesDefinition.internal.lastPage,n=this._layer.nativeCapabilities(),d=new l;!0===this._requestStandardised&&(d.sqlFormat="standard"),d.relationshipId=this.relationship.id,d.objectIds=e.pagesDefinition.objectIds,d.resultOffset=e.pagesDefinition.internal.lastPage,d.resultRecordCount=e.pagesDefinition.resultRecordCount,d.outFields=e.pagesDefinition.outFields.split(","),d.where=e.pagesDefinition.where,d.orderByFields=""!==e.pagesDefinition.orderByFields?e.pagesDefinition.orderByFields.split(","):null,d.returnGeometry=e.pagesDefinition.returnGeometry,d.outSpatialReference=this.spatialReference;const o=await n.source.queryRelatedFeatures(d);if(this._checkCancelled(r),e.pagesDefinition.internal.lastPage!==a)return 0;const u=o[this._findObjectId]?o[this._findObjectId].features:[];for(let l=0;l<u.length;l++)e.pagesDefinition.internal.set[s+l]=u[l].attributes[this._relatedLayer.objectIdField];for(let l=0;l<u.length;l++)this._featureCache[u[l].attributes[this._relatedLayer.objectIdField]]=u[l];const h=!o[this._findObjectId]||!1===o[this._findObjectId].exceededTransferLimit;return u.length!==e.pagesDefinition.resultRecordCount&&h&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=i+u.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,u.length}async _getFeatures(e,i,s,a){const n=[];-1!==i&&void 0===this._featureCache[i]&&n.push(i);const l=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(e,l))return await this._expandPagedSet(e,l,0,0,a),this._getFeatures(e,i,s,a);let d=0;for(let t=e._lastFetchedIndex;t<e._known.length&&(d++,d<=s&&(e._lastFetchedIndex+=1),!("GETPAGES"!==e._known[t]&&void 0===this._featureCache[e._known[t]]&&(e._known[t]!==i&&n.push(e._known[t]),n.length>s)))&&!(d>=s&&0===n.length);t++);if(0===n.length)return"success";throw new t(r.MissingFeatures)}async _refineSetBlock(e,t,r){return e}async _stat(e,t,r,i,s,a,n){return{calculated:!1}}get gdbVersion(){return this._relatedLayer.gdbVersion}async _canDoAggregates(e,t,r,i,s){return!1}relationshipMetaData(){return this._relatedLayer.relationshipMetaData()}serviceUrl(){return this._relatedLayer.serviceUrl()}queryAttachments(e,t,r,i,s){return this._relatedLayer.queryAttachments(e,t,r,i,s)}getFeatureByObjectId(e,t){return this._relatedLayer.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._relatedLayer.getOwningSystemUrl()}getIdentityUser(){return this._relatedLayer.getIdentityUser()}getDataSourceFeatureSet(){return this._relatedLayer}get preferredTimeReference(){return this._relatedLayer?.preferredTimeReference??null}get dateFieldsTimeReference(){return this._relatedLayer?.dateFieldsTimeReference??null}get datesInUnknownTimezone(){return this._relatedLayer?.datesInUnknownTimezone}get editFieldsInfo(){return this._relatedLayer?.editFieldsInfo??null}get timeInfo(){return this._relatedLayer?.timeInfo??null}}export{d as default};
|
|
5
|
+
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import i from"../support/FeatureSet.js";import s from"../support/IdSet.js";import{defaultMaxRecords as a,IdState as n}from"../support/shared.js";import l from"../../../rest/support/RelationshipQuery.js";class d extends i{constructor(e){super(e),this.declaredClass="esri.arcade.featureset.sources.FeatureLayerRelated",this._findObjectId=-1,this._requestStandardised=!1,this._removeGeometry=!1,this._overrideFields=null,this.featureObjectId=null,e.spatialReference&&(this.spatialReference=e.spatialReference),this._transparent=!0,this._maxProcessing=1e3,this._layer=e.layer,this._wset=null,this._findObjectId=e.objectId,this.featureObjectId=e.objectId,this.relationship=e.relationship,this._relatedLayer=e.relatedLayer,void 0!==e.outFields&&(this._overrideFields=e.outFields),void 0!==e.includeGeometry&&(this._removeGeometry=!1===e.includeGeometry)}_maxQueryRate(){return a}end(){return this._layer}optimisePagingFeatureQueries(){}async loadImpl(){return await Promise.all([this._layer.load(),this._relatedLayer?.load()]),this._initialiseFeatureSet(),this}nativeCapabilities(){return this._relatedLayer.nativeCapabilities()}_initialiseFeatureSet(){if(null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference),this.geometryType=this._relatedLayer.geometryType,this.fields=this._relatedLayer.fields.slice(0),this.hasZ=this._relatedLayer.hasZ,this.hasM=this._relatedLayer.hasM,null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{const e=[],t=[];for(const r of this.fields)if("oid"===r.type)e.push(r),t.push(r.name);else for(const i of this._overrideFields)if(i.toLowerCase()===r.name.toLowerCase()){e.push(r),t.push(r.name);break}this.fields=e,this._overrideFields=t}const e=this._layer.nativeCapabilities();e&&(this._databaseType=e.databaseType,this._requestStandardised=e.requestStandardised),this.objectIdField=this._relatedLayer.objectIdField,this.globalIdField=this._relatedLayer.globalIdField,this.hasM=this._relatedLayer.supportsM,this.hasZ=this._relatedLayer.supportsZ,this.typeIdField=this._relatedLayer.typeIdField,this.types=this._relatedLayer.types}async databaseType(){return await this._relatedLayer.databaseType(),this._databaseType=this._relatedLayer._databaseType,this._databaseType}isTable(){return this._relatedLayer.isTable()}_isInFeatureSet(){return n.InFeatureSet}_candidateIdTransform(e){return e}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,t}return this._wset}_changeFeature(t){const r={};for(const e of this.fields)r[e.name]=t.attributes[e.name];return new e({geometry:!0===this._removeGeometry?null:t.geometry,attributes:r})}async _getFilteredSet(e,t,r,i,a){if(await this.databaseType(),this.isTable()&&t&&null!==e&&""!==e){return new s([],[],!0,null)}const n=this._layer.nativeCapabilities();if(!1===n.canQueryRelated){return new s([],[],!0,null)}if(n.capabilities?.queryRelated&&n.capabilities.queryRelated.supportsPagination)return this._getFilteredSetUsingPaging(e,t,r,i,a);let d="",o=!1;null!==i&&n.capabilities&&n.capabilities.queryRelated&&!0===n.capabilities.queryRelated.supportsOrderBy&&(d=i.constructClause(),o=!0);const u=new l;u.objectIds=[this._findObjectId];const h=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map((e=>e.name)):["*"]);u.outFields=h,u.relationshipId=this.relationship.id,u.where="1=1";let c=!0;!0===this._removeGeometry&&(c=!1),u.returnGeometry=c,this._requestStandardised&&(u.sqlFormat="standard"),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==d?d.split(","):null;const y=await n.source.queryRelatedFeatures(u);this._checkCancelled(a);const p=y[this._findObjectId]?y[this._findObjectId].features:[],_=[];for(let s=0;s<p.length;s++)this._featureCache[p[s].attributes[this._relatedLayer.objectIdField]]=p[s],_.push(p[s].attributes[this._relatedLayer.objectIdField]);const f=t&&null!==e&&""!==e,g=null!=r;return new s(f||g?_:[],f||g?[]:_,o,null)}_fieldsIncludingObjectId(e){if(null===e)return[this.objectIdField];const t=e.slice(0);if(t.includes("*"))return t;let r=!1;for(const i of t)if(i.toUpperCase()===this.objectIdField.toUpperCase()){r=!0;break}return!1===r&&t.push(this.objectIdField),t}async _getFilteredSetUsingPaging(e,t,r,i,a){let n="",l=!1;const d=this._layer.nativeCapabilities();null!==i&&d&&d.capabilities?.queryRelated&&!0===d.capabilities.queryRelated.supportsOrderBy&&(n=i.constructClause(),l=!0),await this.databaseType();const o="1=1";let u=this._maxQueryRate();const h=d.capabilities?.query.maxRecordCount;null!=h&&h<u&&(u=h);const c=t&&null!==e&&""!==e,y=null!=r;let p=null,_=!0;!0===this._removeGeometry&&(_=!1);const f=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map((e=>e.name)):["*"]);return p=new s(c||y?["GETPAGES"]:[],c||y?[]:["GETPAGES"],l,{outFields:f.join(","),resultRecordCount:u,resultOffset:0,objectIds:[this._findObjectId],where:o,orderByFields:n,returnGeometry:_,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}}),await this._expandPagedSet(p,u,0,0,a),p}_expandPagedSet(e,t,r,i,s){return this._expandPagedSetFeatureSet(e,t,r,i,s)}_clonePageDefinition(e){return null===e?null:!0!==e.groupbypage?{groupbypage:!1,outFields:e.outFields,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,where:e.where,objectIds:e.objectIds,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}:{groupbypage:!0,outFields:e.outFields,resultRecordCount:e.resultRecordCount,useOIDpagination:e.useOIDpagination,generatedOid:e.generatedOid,groupByFieldsForStatistics:e.groupByFieldsForStatistics,resultOffset:e.resultOffset,outStatistics:e.outStatistics,geometry:e.geometry,where:e.where,objectIds:e.objectIds,orderByFields:e.orderByFields,returnGeometry:e.returnGeometry,returnIdsOnly:e.returnIdsOnly,internal:e.internal}}async _getPhysicalPage(e,t,r){const i=e.pagesDefinition.internal.lastRetrieved,s=i,a=e.pagesDefinition.internal.lastPage,n=this._layer.nativeCapabilities(),d=new l;!0===this._requestStandardised&&(d.sqlFormat="standard"),d.relationshipId=this.relationship.id,d.objectIds=e.pagesDefinition.objectIds,d.resultOffset=e.pagesDefinition.internal.lastPage,d.resultRecordCount=e.pagesDefinition.resultRecordCount,d.outFields=e.pagesDefinition.outFields.split(","),d.where=e.pagesDefinition.where,d.orderByFields=""!==e.pagesDefinition.orderByFields?e.pagesDefinition.orderByFields.split(","):null,d.returnGeometry=e.pagesDefinition.returnGeometry,d.outSpatialReference=this.spatialReference;const o=await n.source.queryRelatedFeatures(d);if(this._checkCancelled(r),e.pagesDefinition.internal.lastPage!==a)return 0;const u=o[this._findObjectId]?o[this._findObjectId].features:[];for(let l=0;l<u.length;l++)e.pagesDefinition.internal.set[s+l]=u[l].attributes[this._relatedLayer.objectIdField];for(let l=0;l<u.length;l++)this._featureCache[u[l].attributes[this._relatedLayer.objectIdField]]=u[l];const h=!o[this._findObjectId]||!1===o[this._findObjectId].exceededTransferLimit;return u.length!==e.pagesDefinition.resultRecordCount&&h&&(e.pagesDefinition.internal.fullyResolved=!0),e.pagesDefinition.internal.lastRetrieved=i+u.length,e.pagesDefinition.internal.lastPage+=e.pagesDefinition.resultRecordCount,u.length}async _getFeatures(e,i,s,a){const n=[];-1!==i&&void 0===this._featureCache[i]&&n.push(i);const l=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(e,l))return await this._expandPagedSet(e,l,0,0,a),this._getFeatures(e,i,s,a);let d=0;for(let t=e._lastFetchedIndex;t<e._known.length&&(d++,d<=s&&(e._lastFetchedIndex+=1),!("GETPAGES"!==e._known[t]&&void 0===this._featureCache[e._known[t]]&&(e._known[t]!==i&&n.push(e._known[t]),n.length>s)))&&!(d>=s&&0===n.length);t++);if(0===n.length)return"success";throw new t(r.MissingFeatures)}async _refineSetBlock(e,t,r){return e}async _stat(e,t,r,i,s,a,n){return{calculated:!1}}get gdbVersion(){return this._relatedLayer.gdbVersion}async _canDoAggregates(e,t,r,i,s){return!1}relationshipMetaData(){return this._relatedLayer.relationshipMetaData()}serviceUrl(){return this._relatedLayer.serviceUrl()}queryAttachments(e,t,r,i,s){return this._relatedLayer.queryAttachments(e,t,r,i,s)}getFeatureByObjectId(e,t){return this._relatedLayer.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._relatedLayer.getOwningSystemUrl()}getIdentityUser(){return this._relatedLayer.getIdentityUser()}getDataSourceFeatureSet(){return this._relatedLayer}get preferredTimeReference(){return this._relatedLayer?.preferredTimeReference??null}get dateFieldsTimeReference(){return this._relatedLayer?.dateFieldsTimeReference??null}get datesInUnknownTimezone(){return this._relatedLayer?.datesInUnknownTimezone}get editFieldsInfo(){return this._relatedLayer?.editFieldsInfo??null}get timeInfo(){return this._relatedLayer?.timeInfo??null}}export{d 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.27/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as a}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as l,constructFeatureSetFromPortalItem as o,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as d}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{C as p,r as y,c as g,j as h,l as w,G as I,k as F,D as E,h as D,m as b,p as x,o as A,i as N,g as S,_ as T,P as L}from"../../chunks/languageUtils.js";import{getPortal as $}from"../portalUtils.js";import{SqlExpressionAdapted as v,StringToCodeAdapted as P,FieldRename as R,AdaptedFeatureSet as j,OriginalField as C}from"../featureset/actions/Adapted.js";import M from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import k from"../featureset/actions/Top.js";import z from"../featureset/sources/Empty.js";import H from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as Z}from"../featureset/support/shared.js";import{isSingleField as _}from"../featureset/support/sqlUtils.js";import{calculateStat as W}from"./fieldStats.js";import{isPromiseLike as U}from"../../core/promiseUtils.js";import{WhereClause as B}from"../../core/sql/WhereClause.js";import q from"../../layers/FeatureLayer.js";import V from"../../layers/support/Field.js";import Q from"../../portal/Portal.js";function J(e,t,n,i){if(1===i.length){if(b(i[0]))return W(e,i[0],-1);if(A(i[0]))return W(e,i[0].toArray(),-1)}return W(e,i,-1)}async function K(e,t,n){const i=e.getVariables();if(i.length>0){const a=[];for(let e=0;e<i.length;e++){const r={name:i[e]};a.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<i.length;e++)r[i[e]]=a[e];return e.parameters=r,e}return e}function Y(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function X(e){if(null===e)return null;const t={type:Y(e,"type",""),name:Y(e,"name","")};if("range"===t.type)t.range=Y(e,"range",[]);else{t.codedValues=[];for(const n of Y(e,"codedValues",[]))t.codedValues.push({name:Y(n,"name",""),code:Y(n,"code",null)})}return t}function ee(e){if(null===e)return null;const t={},n=Y(e,"wkt",null);null!==n&&(t.wkt=n);const i=Y(e,"wkid",null);return null!==i&&(t.wkid=i),t}function te(e){if(null===e)return null;const t={hasZ:Y(e,"hasz",!1),hasM:Y(e,"hasm",!1)},n=Y(e,"spatialreference",null);n&&(t.spatialReference=ee(n));const i=Y(e,"x",null);if(null!==i)return t.x=i,t.y=Y(e,"y",null),t;const a=Y(e,"rings",null);if(null!==a)return t.rings=a,t;const r=Y(e,"paths",null);if(null!==r)return t.paths=r,t;const s=Y(e,"points",null);if(null!==s)return t.points=s,t;for(const l of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=Y(e,l,null);null!==n&&(t[l]=n)}return t}function ne(e,t){for(const n of t)if(n===e)return!0;return!1}function ie(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ne(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==b(e.layerDefinition.fields)&&!1!==b(e.featureSet.features))))}function ae(W){"async"===W.mode&&(W.functions.timezone=function(t,r){return W.standardFunctionAsync(t,r,(async(s,l,o)=>{if(p(o,1,2,t,r),y(o[0])){if(await o[0].load(),1===o.length||null===o[1])return o[0].dateTimeReferenceFieldIndex.layerDateFieldsTimeZone;if(!(o[1]instanceof n)||!1===o[1].hasField("type"))throw new i(t,a.InvalidParameter,r);const e=o[1].field("type");if(!1===g(e))throw new i(t,a.InvalidParameter,r);switch(h(e).toLowerCase()){case"preferredtimezone":return o[0].dateTimeReferenceFieldIndex.layerPreferredTimeZone;case"editfieldsinfo":return o[0].dateTimeReferenceFieldIndex.layerEditFieldsTimeZone;case"timeinfo":return o[0].dateTimeReferenceFieldIndex.layerTimeInfoTimeZone;case"field":if(o[1].hasField("fieldname")&&g(o[1].field("fieldname")))return o[0].dateTimeReferenceFieldIndex.fieldTimeZone(h(o[1].field("fieldname")))}throw new i(t,a.InvalidParameter,r)}const f=w(o[0],I(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:u}))},W.functions.sqltimestamp=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const l=s[0];if(F(l)){if(1===s.length)return l.toSQLString();if(2===s.length)return l.changeTimeZone(h(s[1])).toSQLString();throw new i(e,a.InvalidParameter,t)}if(y(l)){if(3!==s.length)throw new i(e,a.InvalidParameter,t);await l.load();const n=h(s[1]);if(!1===F(s[2]))throw new i(e,a.InvalidParameter,t);const r=l.fieldTimeZone(n);return null===r?s[2].toSQLString():s[2].changeTimeZone(r).toSQLString()}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"sqltimestamp",min:2,max:4}),W.functions.featuresetbyid=function(e,t){return W.standardFunctionAsync(e,t,((n,r,l)=>{if(p(l,2,4,e,t),l[0]instanceof s){const n=h(l[1]);let r=E(l[2],null);const s=D(E(l[3],!0));if(null===r&&(r=["*"]),!1===b(r))throw new i(e,a.InvalidParameter,t);return l[0].featureSetById(n,s,r)}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"featuresetbyid",min:2,max:4}),W.functions.getfeatureset=function(e,t){return W.standardFunctionAsync(e,t,((n,r,s)=>{if(p(s,1,2,e,t),x(s[0])){let t=E(s[1],"datasource");return null===t&&(t="datasource"),t=h(t).toLowerCase(),l(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference)}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"getfeatureset",min:1,max:2}),W.functions.featuresetbyportalitem=function(e,n){return W.standardFunctionAsync(e,n,((r,s,l)=>{if(p(l,2,5,e,n),null===l[0])throw new i(e,a.PortalRequired,n);if(l[0]instanceof t){const t=h(l[1]),r=h(l[2]);let s=E(l[3],null);const f=D(E(l[4],!0));if(null===s&&(s=["*"]),!1===b(s))throw new i(e,a.InvalidParameter,n);let u=null;return u=e.services&&e.services.portal?e.services.portal:Q.getDefault(),u=$(l[0],u),o(t,r,e.spatialReference,s,f,u,e.lrucache,e.interceptor)}if(!1===g(l[0]))throw new i(e,a.PortalRequired,n);const f=h(l[0]),u=h(l[1]);let c=E(l[2],null);const d=D(E(l[3],!0));if(null===c&&(c=["*"]),!1===b(c))throw new i(e,a.InvalidParameter,n);return o(f,u,e.spatialReference,c,d,e.services?.portal??Q.getDefault(),e.lrucache,e.interceptor)}))},W.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),W.functions.featuresetbyname=function(e,t){return W.standardFunctionAsync(e,t,((n,r,l)=>{if(p(l,2,4,e,t),l[0]instanceof s){const n=h(l[1]);let r=E(l[2],null);const s=D(E(l[3],!0));if(null===r&&(r=["*"]),!1===b(r))throw new i(e,a.InvalidParameter,t);return l[0].featureSetByName(n,s,r)}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"featuresetbyname",min:2,max:4}),W.functions.featureset=function(e,t){return W.standardFunction(e,t,((r,s,l)=>{p(l,1,1,e,t);let o=l[0];const f={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",fields:[]},featureSet:{geometryType:"",features:[]}};if(g(o))o=JSON.parse(o),void 0!==o.layerDefinition?(f.layerDefinition=o.layerDefinition,f.featureSet=o.featureSet,o.layerDefinition.spatialReference&&(f.layerDefinition.spatialReference=o.layerDefinition.spatialReference)):(f.featureSet.features=o.features,f.featureSet.geometryType=o.geometryType,f.layerDefinition.geometryType=f.featureSet.geometryType,f.layerDefinition.objectIdField=o.objectIdFieldName??"",f.layerDefinition.typeIdField=o.typeIdFieldName,f.layerDefinition.globalIdField=o.globalIdFieldName,f.layerDefinition.fields=o.fields,o.spatialReference&&(f.layerDefinition.spatialReference=o.spatialReference));else{if(!(l[0]instanceof n))throw new i(e,a.InvalidParameter,t);{o=JSON.parse(l[0].castToText(!0));const e=Y(o,"layerdefinition");if(null!==e){f.layerDefinition.geometryType=Y(e,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.globalIdField=Y(e,"globalidfield",""),f.layerDefinition.objectIdField=Y(e,"objectidfield",""),f.layerDefinition.typeIdField=Y(e,"typeidfield","");const t=Y(e,"spatialreference",null);t&&(f.layerDefinition.spatialReference=ee(t));for(const i of Y(e,"fields",[])){const e={name:Y(i,"name",""),alias:Y(i,"alias",""),type:Y(i,"type",""),nullable:Y(i,"nullable",!0),editable:Y(i,"editable",!0),length:Y(i,"length",null),domain:X(Y(i,"domain"))};f.layerDefinition.fields.push(e)}const n=Y(o,"featureset",null);if(n){const e={};for(const t of f.layerDefinition.fields)e[t.name.toLowerCase()]=t.name;for(const t of Y(n,"features",[])){const n={},i=Y(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];f.featureSet.features.push({attributes:n,geometry:te(Y(t,"geometry",null))})}}}else{f.layerDefinition.geometryType=Y(o,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.objectIdField=Y(o,"objectidfieldname",""),f.layerDefinition.typeIdField=Y(o,"typeidfieldname","");const e=Y(o,"spatialreference",null);e&&(f.layerDefinition.spatialReference=ee(e));let t=Y(o,"fields",null);if(b(t))for(const a of t){const e={name:Y(a,"name",""),alias:Y(a,"alias",""),type:Y(a,"type",""),nullable:Y(a,"nullable",!0),editable:Y(a,"editable",!0),length:Y(a,"length",null),domain:X(Y(a,"domain"))};f.layerDefinition.fields.push(e)}else t=null,f.layerDefinition.fields=t;const n={};for(const a of f.layerDefinition.fields)n[a.name.toLowerCase()]=a.name;let i=Y(o,"features",null);if(b(i))for(const a of i){const e={},t=Y(a,"attributes",{});for(const i in t)e[n[i.toLowerCase()]]=t[i];f.featureSet.features.push({attributes:e,geometry:te(Y(a,"geometry",null))})}else i=null,f.featureSet.features=i}}}if(!1===ie(f))throw new i(e,a.InvalidParameter,t);return""===(f?.layerDefinition?.geometryType||"")&&(f.layerDefinition.geometryType="esriGeometryNull"),H.create(f,e.spatialReference)}))},W.signatures.push({name:"featureset",min:1,max:1}),W.functions.filter=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),b(s[0])||A(s[0])){const n=[];let r=s[0];r instanceof m&&(r=r.toArray());let l=null;if(!N(s[1]))throw new i(e,a.InvalidParameter,t);l=s[1].createFunction(e);for(const e of r){const t=l(e);U(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(y(s[0])){const t=await s[0].load(),n=B.create(s[1],t.getFieldsIndex()),i=n.getVariables();if(i.length>0){const t=[];for(let n=0;n<i.length;n++){const a={name:i[n]};t.push(await W.evaluateIdentifier(e,a))}const a={};for(let e=0;e<i.length;e++)a[i[e]]=t[e];return n.parameters=a,new M({parentfeatureset:s[0],whereclause:n})}return new M({parentfeatureset:s[0],whereclause:n})}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"filter",min:2,max:2}),W.functions.orderby=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),y(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"orderby",min:2,max:2}),W.functions.top=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),y(s[0]))return new k({parentfeatureset:s[0],topnum:s[1]});if(b(s[0]))return S(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,S(s[1]));if(A(s[0]))return S(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,S(s[1]));throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"top",min:2,max:2}),W.functions.first=function(e,t){return W.standardFunctionAsync(e,t,(async(n,i,a)=>{if(p(a,1,1,e,t),y(a[0])){const t=await a[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,a[0],e.timeReference);return n._underlyingGraphic=t,n}return t}return b(a[0])?0===a[0].length?null:a[0][0]:A(a[0])?0===a[0].length()?null:a[0].get(0):null}))},W.signatures.push({name:"first",min:1,max:1}),W.functions.attachments=function(e,t){return W.standardFunctionAsync(e,t,(async(r,s,l)=>{p(l,1,2,e,t);const o={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(l.length>1)if(l[1]instanceof n){if(l[1].hasField("minsize")&&(o.minsize=S(l[1].field("minsize"))),l[1].hasField("metadata")&&(o.returnMetadata=D(l[1].field("metadata"))),l[1].hasField("maxsize")&&(o.maxsize=S(l[1].field("maxsize"))),l[1].hasField("types")){const e=T(l[1].field("types"),!1);e.length>0&&(o.types=e)}}else if(null!==l[1])throw new i(e,a.InvalidParameter,t);if(x(l[0])){let t=l[0]._layer;return t instanceof q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===y(t)?[]:(await t.load(),t.queryAttachments(l[0].field(t.objectIdField),o.minsize,o.maxsize,o.types,o.returnMetadata))}if(null===l[0])return[];throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"attachments",min:1,max:2}),W.functions.featuresetbyrelationshipname=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const l=s[0],o=h(s[1]);let d=E(s[2],null);const m=D(E(s[3],!0));if(null===d&&(d=["*"]),!1===b(d))throw new i(e,a.InvalidParameter,t);if(null===s[0])return null;if(!x(s[0]))throw new i(e,a.InvalidParameter,t);let g=l._layer;if(g instanceof q&&(g=f(g,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===g)return null;if(!1===y(g))return null;g=await g.load();const w=g.relationshipMetaData().filter((e=>e.name===o));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(g,w[0],l.field(g.objectIdField),g.spatialReference,d,m,e.lrucache,e.interceptor);let I=g.serviceUrl();if(!I)return null;I="/"===I.charAt(I.length-1)?I+w[0].relatedTableId.toString():I+"/"+w[0].relatedTableId.toString();const F=await c(I,g.spatialReference,d,m,e.lrucache,e.interceptor);await F.load();let A=F.relationshipMetaData();if(A=A.filter((e=>e.id===w[0].id)),!1===l.hasField(w[0].keyField)||null===l.field(w[0].keyField)){const e=await g.getFeatureByObjectId(l.field(g.objectIdField),[w[0].keyField]);if(e){const t=B.create(A[0].keyField+"= @id",F.getFieldsIndex());return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new z({parentfeatureset:F})}const N=B.create(A[0].keyField+"= @id",F.getFieldsIndex());return N.parameters={id:l.field(w[0].keyField)},F.filter(N)}))},W.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),W.functions.featuresetbyassociation=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const l=s[0],o=h(E(s[1],"")).toLowerCase(),u=g(s[2])?h(s[2]):null;if(null===s[0])return null;if(!x(s[0]))throw new i(e,a.InvalidParameter,t);let c=l._layer;if(c instanceof q&&(c=f(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===y(c))return null;await c.load();const m=c.serviceUrl(),w=await d(m,e.spatialReference);let I=null,F=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of w.terminals)e.terminalName===u&&(F=e.terminalId);null===F&&(D=!0)}const b=w.associations.getFieldsIndex(),A=b.get("TOGLOBALID").name,N=b.get("FROMGLOBALID").name,S=b.get("TOTERMINALID").name,T=b.get("FROMTERMINALID").name,$=b.get("FROMNETWORKSOURCEID").name,M=b.get("TONETWORKSOURCEID").name,O=b.get("ASSOCIATIONTYPE").name,k=b.get("ISCONTENTVISIBLE").name,z=b.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){I=l.field(e.name);break}let H=null,G=new v(new V({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",w.associations.getFieldsIndex())),_=new v(new V({name:"side",alias:"side",type:"string"}),B.create("''",w.associations.getFieldsIndex()));const W="globalid",U="globalId",Q={};for(const e in w.lkp)Q[e]=w.lkp[e].sourceId;const J=new P(new V({name:"classname",alias:"classname",type:"string"}),null,Q);let K="";switch(o){case"midspan":{K=`((${A}='${I}') OR ( ${N}='${I}')) AND (${O} IN (5))`,J.codefield=B.create(`CASE WHEN (${A}='${I}') THEN ${$} ELSE ${M} END`,w.associations.getFieldsIndex());const e=Z(j.findField(w.associations.fields,N));e.name=W,e.alias=W,H=new v(e,B.create(`CASE WHEN (${N}='${I}') THEN ${A} ELSE ${N} END`,w.associations.getFieldsIndex())),G=w.unVersion>=4?new C(j.findField(w.associations.fields,b.get("PERCENTALONG").name)):new v(new V({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",w.associations.getFieldsIndex()));break}case"junctionedge":{K=`((${A}='${I}') OR ( ${N}='${I}')) AND (${O} IN (4,6))`,J.codefield=B.create(`CASE WHEN (${A}='${I}') THEN ${$} ELSE ${M} END`,w.associations.getFieldsIndex());const e=Z(j.findField(w.associations.fields,N));e.name=W,e.alias=W,H=new v(e,B.create(`CASE WHEN (${N}='${I}') THEN ${A} ELSE ${N} END`,w.associations.getFieldsIndex())),_=new v(new V({name:"side",alias:"side",type:"string"}),B.create(`CASE WHEN (${O}=4) THEN 'from' ELSE 'to' END`,w.associations.getFieldsIndex()));break}case"connected":{let e=`${A}='@T'`,t=`${N}='@T'`;null!==F&&(e+=` AND ${S}=@A`,t+=` AND ${T}=@A`),K="(("+e+") OR ("+t+"))",K=L(K,"@T",I??""),e=L(e,"@T",I??""),null!==F&&(e=L(e,"@A",F.toString()),K=L(K,"@A",F.toString())),J.codefield=B.create("CASE WHEN "+e+` THEN ${$} ELSE ${M} END`,w.associations.getFieldsIndex());const n=Z(j.findField(w.associations.fields,N));n.name=W,n.alias=W,H=new v(n,B.create("CASE WHEN "+e+` THEN ${N} ELSE ${A} END`,w.associations.getFieldsIndex()));break}case"container":K=`${A}='${I}' AND ${O} = 2`,null!==F&&(K+=` AND ${S} = `+F.toString()),J.codefield=$,K="( "+K+" )",H=new R(j.findField(w.associations.fields,N),W,W);break;case"content":K=`(${N}='${I}' AND ${O} = 2)`,null!==F&&(K+=` AND ${T} = `+F.toString()),J.codefield=M,K="( "+K+" )",H=new R(j.findField(w.associations.fields,A),W,W);break;case"structure":K=`(${A}='${I}' AND ${O} = 3)`,null!==F&&(K+=` AND ${S} = `+F.toString()),J.codefield=$,K="( "+K+" )",H=new R(j.findField(w.associations.fields,N),W,U);break;case"attached":K=`(${N}='${I}' AND ${O} = 3)`,null!==F&&(K+=` AND ${T} = `+F.toString()),J.codefield=M,K="( "+K+" )",H=new R(j.findField(w.associations.fields,A),W,U);break;default:throw new i(e,a.InvalidParameter,t)}D&&(K="1 <> 1");return new j({parentfeatureset:w.associations,adaptedFields:[new C(j.findField(w.associations.fields,z)),new C(j.findField(w.associations.fields,k)),H,_,J,G],extraFilter:K?B.create(K,w.associations.getFieldsIndex()):null})}))},W.signatures.push({name:"featuresetbyassociation",min:2,max:6}),W.functions.groupby=function(e,t){return W.standardFunctionAsync(e,t,(async(r,s,l)=>{if(p(l,3,3,e,t),!y(l[0]))throw new i(e,a.InvalidParameter,t);const o=await l[0].load(),f=[],u=[];let c=!1,d=[];if(g(l[1]))d.push(l[1]);else if(l[1]instanceof n)d.push(l[1]);else if(b(l[1]))d=l[1];else{if(!A(l[1]))throw new i(e,a.InvalidParameter,t);d=l[1].toArray()}for(const m of d)if(g(m)){const e=B.create(h(m),o.getFieldsIndex()),t=!0===_(e)?h(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(c=!0)}else{if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(c=!0),!n)throw new i(e,a.InvalidParameter,t);f.push({name:n,expression:B.create(r||n,o.getFieldsIndex())})}}if(d=[],g(l[2]))d.push(l[2]);else if(b(l[2]))d=l[2];else if(A(l[2]))d=l[2].toArray();else{if(!(l[2]instanceof n))throw new i(e,a.InvalidParameter,t);d.push(l[2])}for(const m of d){if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new i(e,a.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:B.create(s,o.getFieldsIndex())})}}if(c){const e={};for(const n of o.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of u)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)await K(t.expression,W,e);for(const t of u)await K(t.expression,W,e);return l[0].groupby(f,u)}))},W.signatures.push({name:"groupby",min:3,max:3}),W.functions.distinct=function(e,t){return W.standardFunctionAsync(e,t,(async(r,s,l)=>{if(y(l[0])){p(l,2,2,e,t);const r=await l[0].load(),s=[];let o=[];if(g(l[1]))o.push(l[1]);else if(l[1]instanceof n)o.push(l[1]);else if(b(l[1]))o=l[1];else{if(!A(l[1]))throw new i(e,a.InvalidParameter,t);o=l[1].toArray()}let f=!1;for(const l of o)if(g(l)){const e=B.create(h(l),r.getFieldsIndex()),t=!0===_(e)?h(l):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(l instanceof n))throw new i(e,a.InvalidParameter,t);{const n=l.hasField("name")?l.field("name"):"%%%%FIELDNAME",o=l.hasField("expression")?l.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new i(e,a.InvalidParameter,t);s.push({name:n,expression:B.create(o||n,r.getFieldsIndex())})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await K(t.expression,W,e);return l[0].groupby(s,[])}return J("distinct",r,s,l)}))})}export{ae as registerFunctions};
|
|
5
|
+
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as a}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as l,constructFeatureSetFromPortalItem as o,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as d}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{C as p,r as y,c as h,j as g,l as w,G as I,k as F,D,h as E,m as b,p as x,o as A,i as N,g as S,_ as T,P as L}from"../../chunks/languageUtils.js";import{getPortal as $}from"../portalUtils.js";import{SqlExpressionAdapted as v,StringToCodeAdapted as P,FieldRename as R,AdaptedFeatureSet as j,OriginalField as C}from"../featureset/actions/Adapted.js";import M from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import k from"../featureset/actions/Top.js";import z from"../featureset/sources/Empty.js";import H from"../featureset/sources/FeatureLayerMemory.js";import Z from"../featureset/support/OrderbyClause.js";import{cloneField as G}from"../featureset/support/shared.js";import{isSingleField as _}from"../featureset/support/sqlUtils.js";import{calculateStat as W}from"./fieldStats.js";import{isPromiseLike as U}from"../../core/promiseUtils.js";import{WhereClause as B}from"../../core/sql/WhereClause.js";import q from"../../layers/FeatureLayer.js";import V from"../../layers/support/Field.js";import Q from"../../portal/Portal.js";function J(e,t,n,i){if(1===i.length){if(b(i[0]))return W(e,i[0],-1);if(A(i[0]))return W(e,i[0].toArray(),-1)}return W(e,i,-1)}async function K(e,t,n){const i=e.getVariables();if(i.length>0){const a=[];for(let e=0;e<i.length;e++){const r={name:i[e]};a.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<i.length;e++)r[i[e]]=a[e];return e.parameters=r,e}return e}function Y(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function X(e){if(null===e)return null;const t={type:Y(e,"type",""),name:Y(e,"name","")};if("range"===t.type)t.range=Y(e,"range",[]);else{t.codedValues=[];for(const n of Y(e,"codedValues",[]))t.codedValues.push({name:Y(n,"name",""),code:Y(n,"code",null)})}return t}function ee(e){if(null===e)return null;const t={},n=Y(e,"wkt",null);null!==n&&(t.wkt=n);const i=Y(e,"wkid",null);return null!==i&&(t.wkid=i),t}function te(e){if(null===e)return null;const t={hasZ:Y(e,"hasz",!1),hasM:Y(e,"hasm",!1)},n=Y(e,"spatialreference",null);n&&(t.spatialReference=ee(n));const i=Y(e,"x",null);if(null!==i)return t.x=i,t.y=Y(e,"y",null),t;const a=Y(e,"rings",null);if(null!==a)return t.rings=a,t;const r=Y(e,"paths",null);if(null!==r)return t.paths=r,t;const s=Y(e,"points",null);if(null!==s)return t.points=s,t;for(const l of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=Y(e,l,null);null!==n&&(t[l]=n)}return t}function ne(e,t){for(const n of t)if(n===e)return!0;return!1}function ie(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==ne(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==b(e.layerDefinition.fields)&&!1!==b(e.featureSet.features))))}function ae(W){"async"===W.mode&&(W.functions.timezone=function(t,r){return W.standardFunctionAsync(t,r,(async(s,l,o)=>{if(p(o,1,2,t,r),y(o[0])){if(await o[0].load(),1===o.length||null===o[1])return o[0].dateTimeReferenceFieldIndex.layerDateFieldsTimeZone;if(!(o[1]instanceof n)||!1===o[1].hasField("type"))throw new i(t,a.InvalidParameter,r);const e=o[1].field("type");if(!1===h(e))throw new i(t,a.InvalidParameter,r);switch(g(e).toLowerCase()){case"preferredtimezone":return o[0].dateTimeReferenceFieldIndex.layerPreferredTimeZone;case"editfieldsinfo":return o[0].dateTimeReferenceFieldIndex.layerEditFieldsTimeZone;case"timeinfo":return o[0].dateTimeReferenceFieldIndex.layerTimeInfoTimeZone;case"field":if(o[1].hasField("fieldname")&&h(o[1].field("fieldname")))return o[0].dateTimeReferenceFieldIndex.fieldTimeZone(g(o[1].field("fieldname")))}throw new i(t,a.InvalidParameter,r)}const f=w(o[0],I(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:u}))},W.functions.sqltimestamp=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const l=s[0];if(F(l)){if(1===s.length)return l.toSQLString();if(2===s.length)return l.changeTimeZone(g(s[1])).toSQLString();throw new i(e,a.InvalidParameter,t)}if(y(l)){if(3!==s.length)throw new i(e,a.InvalidParameter,t);await l.load();const n=g(s[1]);if(!1===F(s[2]))throw new i(e,a.InvalidParameter,t);const r=l.fieldTimeZone(n);return null===r?s[2].toSQLString():s[2].changeTimeZone(r).toSQLString()}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"sqltimestamp",min:2,max:4}),W.functions.featuresetbyid=function(e,t){return W.standardFunctionAsync(e,t,((n,r,l)=>{if(p(l,2,4,e,t),l[0]instanceof s){const n=g(l[1]);let r=D(l[2],null);const s=E(D(l[3],!0));if(null===r&&(r=["*"]),!1===b(r))throw new i(e,a.InvalidParameter,t);return l[0].featureSetById(n,s,r)}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"featuresetbyid",min:2,max:4}),W.functions.getfeatureset=function(e,t){return W.standardFunctionAsync(e,t,((n,r,s)=>{if(p(s,1,2,e,t),x(s[0])){let t=D(s[1],"datasource");return null===t&&(t="datasource"),t=g(t).toLowerCase(),l(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference)}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"getfeatureset",min:1,max:2}),W.functions.featuresetbyportalitem=function(e,n){return W.standardFunctionAsync(e,n,((r,s,l)=>{if(p(l,2,5,e,n),null===l[0])throw new i(e,a.PortalRequired,n);if(l[0]instanceof t){const t=g(l[1]),r=g(l[2]);let s=D(l[3],null);const f=E(D(l[4],!0));if(null===s&&(s=["*"]),!1===b(s))throw new i(e,a.InvalidParameter,n);let u=null;return u=e.services&&e.services.portal?e.services.portal:Q.getDefault(),u=$(l[0],u),o(t,r,e.spatialReference,s,f,u,e.lrucache,e.interceptor)}if(!1===h(l[0]))throw new i(e,a.PortalRequired,n);const f=g(l[0]),u=g(l[1]);let c=D(l[2],null);const d=E(D(l[3],!0));if(null===c&&(c=["*"]),!1===b(c))throw new i(e,a.InvalidParameter,n);return o(f,u,e.spatialReference,c,d,e.services?.portal??Q.getDefault(),e.lrucache,e.interceptor)}))},W.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),W.functions.featuresetbyname=function(e,t){return W.standardFunctionAsync(e,t,((n,r,l)=>{if(p(l,2,4,e,t),l[0]instanceof s){const n=g(l[1]);let r=D(l[2],null);const s=E(D(l[3],!0));if(null===r&&(r=["*"]),!1===b(r))throw new i(e,a.InvalidParameter,t);return l[0].featureSetByName(n,s,r)}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"featuresetbyname",min:2,max:4}),W.functions.featureset=function(e,t){return W.standardFunction(e,t,((r,s,l)=>{p(l,1,1,e,t);let o=l[0];const f={layerDefinition:{geometryType:"",objectIdField:"",hasM:!1,hasZ:!1,globalIdField:"",typeIdField:"",fields:[]},featureSet:{geometryType:"",features:[]}};if(h(o))o=JSON.parse(o),void 0!==o.layerDefinition?(f.layerDefinition=o.layerDefinition,f.featureSet=o.featureSet,o.layerDefinition.spatialReference&&(f.layerDefinition.spatialReference=o.layerDefinition.spatialReference)):(f.featureSet.features=o.features,f.featureSet.geometryType=o.geometryType,f.layerDefinition.geometryType=f.featureSet.geometryType,f.layerDefinition.objectIdField=o.objectIdFieldName??"",f.layerDefinition.typeIdField=o.typeIdFieldName,f.layerDefinition.globalIdField=o.globalIdFieldName,f.layerDefinition.fields=o.fields,o.spatialReference&&(f.layerDefinition.spatialReference=o.spatialReference));else{if(!(l[0]instanceof n))throw new i(e,a.InvalidParameter,t);{o=JSON.parse(l[0].castToText(!0));const e=Y(o,"layerdefinition");if(null!==e){f.layerDefinition.geometryType=Y(e,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.globalIdField=Y(e,"globalidfield",""),f.layerDefinition.objectIdField=Y(e,"objectidfield",""),f.layerDefinition.typeIdField=Y(e,"typeidfield",""),f.layerDefinition.hasZ=!0===Y(e,"hasz",!1),f.layerDefinition.hasM=!0===Y(e,"hasm",!1);const t=Y(e,"spatialreference",null);t&&(f.layerDefinition.spatialReference=ee(t));for(const i of Y(e,"fields",[])){const e={name:Y(i,"name",""),alias:Y(i,"alias",""),type:Y(i,"type",""),nullable:Y(i,"nullable",!0),editable:Y(i,"editable",!0),length:Y(i,"length",null),domain:X(Y(i,"domain"))};f.layerDefinition.fields.push(e)}const n=Y(o,"featureset",null);if(n){const e={};for(const t of f.layerDefinition.fields)e[t.name.toLowerCase()]=t.name;for(const t of Y(n,"features",[])){const n={},i=Y(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];f.featureSet.features.push({attributes:n,geometry:te(Y(t,"geometry",null))})}}}else{f.layerDefinition.hasZ=!0===Y(o,"hasz",!1),f.layerDefinition.hasM=!0===Y(o,"hasm",!1),f.layerDefinition.geometryType=Y(o,"geometrytype",""),f.featureSet.geometryType=f.layerDefinition.geometryType,f.layerDefinition.objectIdField=Y(o,"objectidfieldname",""),f.layerDefinition.typeIdField=Y(o,"typeidfieldname","");const e=Y(o,"spatialreference",null);e&&(f.layerDefinition.spatialReference=ee(e));let t=Y(o,"fields",null);if(b(t))for(const a of t){const e={name:Y(a,"name",""),alias:Y(a,"alias",""),type:Y(a,"type",""),nullable:Y(a,"nullable",!0),editable:Y(a,"editable",!0),length:Y(a,"length",null),domain:X(Y(a,"domain"))};f.layerDefinition.fields.push(e)}else t=null,f.layerDefinition.fields=t;const n={};for(const a of f.layerDefinition.fields)n[a.name.toLowerCase()]=a.name;let i=Y(o,"features",null);if(b(i))for(const a of i){const e={},t=Y(a,"attributes",{});for(const i in t)e[n[i.toLowerCase()]]=t[i];f.featureSet.features.push({attributes:e,geometry:te(Y(a,"geometry",null))})}else i=null,f.featureSet.features=i}}}if(!1===ie(f))throw new i(e,a.InvalidParameter,t);return""===(f?.layerDefinition?.geometryType||"")&&(f.layerDefinition.geometryType="esriGeometryNull"),H.create(f,e.spatialReference)}))},W.signatures.push({name:"featureset",min:1,max:1}),W.functions.filter=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),b(s[0])||A(s[0])){const n=[];let r=s[0];r instanceof m&&(r=r.toArray());let l=null;if(!N(s[1]))throw new i(e,a.InvalidParameter,t);l=s[1].createFunction(e);for(const e of r){const t=l(e);U(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(y(s[0])){const t=await s[0].load(),n=B.create(s[1],t.getFieldsIndex()),i=n.getVariables();if(i.length>0){const t=[];for(let n=0;n<i.length;n++){const a={name:i[n]};t.push(await W.evaluateIdentifier(e,a))}const a={};for(let e=0;e<i.length;e++)a[i[e]]=t[e];return n.parameters=a,new M({parentfeatureset:s[0],whereclause:n})}return new M({parentfeatureset:s[0],whereclause:n})}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"filter",min:2,max:2}),W.functions.orderby=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),y(s[0])){const e=new Z(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"orderby",min:2,max:2}),W.functions.top=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),y(s[0]))return new k({parentfeatureset:s[0],topnum:s[1]});if(b(s[0]))return S(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,S(s[1]));if(A(s[0]))return S(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,S(s[1]));throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"top",min:2,max:2}),W.functions.first=function(e,t){return W.standardFunctionAsync(e,t,(async(n,i,a)=>{if(p(a,1,1,e,t),y(a[0])){const t=await a[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,a[0],e.timeReference);return n._underlyingGraphic=t,n}return t}return b(a[0])?0===a[0].length?null:a[0][0]:A(a[0])?0===a[0].length()?null:a[0].get(0):null}))},W.signatures.push({name:"first",min:1,max:1}),W.functions.attachments=function(e,t){return W.standardFunctionAsync(e,t,(async(r,s,l)=>{p(l,1,2,e,t);const o={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(l.length>1)if(l[1]instanceof n){if(l[1].hasField("minsize")&&(o.minsize=S(l[1].field("minsize"))),l[1].hasField("metadata")&&(o.returnMetadata=E(l[1].field("metadata"))),l[1].hasField("maxsize")&&(o.maxsize=S(l[1].field("maxsize"))),l[1].hasField("types")){const e=T(l[1].field("types"),!1);e.length>0&&(o.types=e)}}else if(null!==l[1])throw new i(e,a.InvalidParameter,t);if(x(l[0])){let t=l[0]._layer;return t instanceof q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===y(t)?[]:(await t.load(),t.queryAttachments(l[0].field(t.objectIdField),o.minsize,o.maxsize,o.types,o.returnMetadata))}if(null===l[0])return[];throw new i(e,a.InvalidParameter,t)}))},W.signatures.push({name:"attachments",min:1,max:2}),W.functions.featuresetbyrelationshipname=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const l=s[0],o=g(s[1]);let d=D(s[2],null);const m=E(D(s[3],!0));if(null===d&&(d=["*"]),!1===b(d))throw new i(e,a.InvalidParameter,t);if(null===s[0])return null;if(!x(s[0]))throw new i(e,a.InvalidParameter,t);let h=l._layer;if(h instanceof q&&(h=f(h,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===h)return null;if(!1===y(h))return null;h=await h.load();const w=h.relationshipMetaData().filter((e=>e.name===o));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(h,w[0],l.field(h.objectIdField),h.spatialReference,d,m,e.lrucache,e.interceptor);let I=h.serviceUrl();if(!I)return null;I="/"===I.charAt(I.length-1)?I+w[0].relatedTableId.toString():I+"/"+w[0].relatedTableId.toString();const F=await c(I,h.spatialReference,d,m,e.lrucache,e.interceptor);await F.load();let A=F.relationshipMetaData();if(A=A.filter((e=>e.id===w[0].id)),!1===l.hasField(w[0].keyField)||null===l.field(w[0].keyField)){const e=await h.getFeatureByObjectId(l.field(h.objectIdField),[w[0].keyField]);if(e){const t=B.create(A[0].keyField+"= @id",F.getFieldsIndex());return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new z({parentfeatureset:F})}const N=B.create(A[0].keyField+"= @id",F.getFieldsIndex());return N.parameters={id:l.field(w[0].keyField)},F.filter(N)}))},W.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),W.functions.featuresetbyassociation=function(e,t){return W.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const l=s[0],o=g(D(s[1],"")).toLowerCase(),u=h(s[2])?g(s[2]):null;if(null===s[0])return null;if(!x(s[0]))throw new i(e,a.InvalidParameter,t);let c=l._layer;if(c instanceof q&&(c=f(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===y(c))return null;await c.load();const m=c.serviceUrl(),w=await d(m,e.spatialReference);let I=null,F=null,E=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of w.terminals)e.terminalName===u&&(F=e.terminalId);null===F&&(E=!0)}const b=w.associations.getFieldsIndex(),A=b.get("TOGLOBALID").name,N=b.get("FROMGLOBALID").name,S=b.get("TOTERMINALID").name,T=b.get("FROMTERMINALID").name,$=b.get("FROMNETWORKSOURCEID").name,M=b.get("TONETWORKSOURCEID").name,O=b.get("ASSOCIATIONTYPE").name,k=b.get("ISCONTENTVISIBLE").name,z=b.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){I=l.field(e.name);break}let H=null,Z=new v(new V({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",w.associations.getFieldsIndex())),_=new v(new V({name:"side",alias:"side",type:"string"}),B.create("''",w.associations.getFieldsIndex()));const W="globalid",U="globalId",Q={};for(const e in w.lkp)Q[e]=w.lkp[e].sourceId;const J=new P(new V({name:"classname",alias:"classname",type:"string"}),null,Q);let K="";switch(o){case"midspan":{K=`((${A}='${I}') OR ( ${N}='${I}')) AND (${O} IN (5))`,J.codefield=B.create(`CASE WHEN (${A}='${I}') THEN ${$} ELSE ${M} END`,w.associations.getFieldsIndex());const e=G(j.findField(w.associations.fields,N));e.name=W,e.alias=W,H=new v(e,B.create(`CASE WHEN (${N}='${I}') THEN ${A} ELSE ${N} END`,w.associations.getFieldsIndex())),Z=w.unVersion>=4?new C(j.findField(w.associations.fields,b.get("PERCENTALONG").name)):new v(new V({name:"percentalong",alias:"percentalong",type:"double"}),B.create("0",w.associations.getFieldsIndex()));break}case"junctionedge":{K=`((${A}='${I}') OR ( ${N}='${I}')) AND (${O} IN (4,6))`,J.codefield=B.create(`CASE WHEN (${A}='${I}') THEN ${$} ELSE ${M} END`,w.associations.getFieldsIndex());const e=G(j.findField(w.associations.fields,N));e.name=W,e.alias=W,H=new v(e,B.create(`CASE WHEN (${N}='${I}') THEN ${A} ELSE ${N} END`,w.associations.getFieldsIndex())),_=new v(new V({name:"side",alias:"side",type:"string"}),B.create(`CASE WHEN (${O}=4) THEN 'from' ELSE 'to' END`,w.associations.getFieldsIndex()));break}case"connected":{let e=`${A}='@T'`,t=`${N}='@T'`;null!==F&&(e+=` AND ${S}=@A`,t+=` AND ${T}=@A`),K="(("+e+") OR ("+t+"))",K=L(K,"@T",I??""),e=L(e,"@T",I??""),null!==F&&(e=L(e,"@A",F.toString()),K=L(K,"@A",F.toString())),J.codefield=B.create("CASE WHEN "+e+` THEN ${$} ELSE ${M} END`,w.associations.getFieldsIndex());const n=G(j.findField(w.associations.fields,N));n.name=W,n.alias=W,H=new v(n,B.create("CASE WHEN "+e+` THEN ${N} ELSE ${A} END`,w.associations.getFieldsIndex()));break}case"container":K=`${A}='${I}' AND ${O} = 2`,null!==F&&(K+=` AND ${S} = `+F.toString()),J.codefield=$,K="( "+K+" )",H=new R(j.findField(w.associations.fields,N),W,W);break;case"content":K=`(${N}='${I}' AND ${O} = 2)`,null!==F&&(K+=` AND ${T} = `+F.toString()),J.codefield=M,K="( "+K+" )",H=new R(j.findField(w.associations.fields,A),W,W);break;case"structure":K=`(${A}='${I}' AND ${O} = 3)`,null!==F&&(K+=` AND ${S} = `+F.toString()),J.codefield=$,K="( "+K+" )",H=new R(j.findField(w.associations.fields,N),W,U);break;case"attached":K=`(${N}='${I}' AND ${O} = 3)`,null!==F&&(K+=` AND ${T} = `+F.toString()),J.codefield=M,K="( "+K+" )",H=new R(j.findField(w.associations.fields,A),W,U);break;default:throw new i(e,a.InvalidParameter,t)}E&&(K="1 <> 1");return new j({parentfeatureset:w.associations,adaptedFields:[new C(j.findField(w.associations.fields,z)),new C(j.findField(w.associations.fields,k)),H,_,J,Z],extraFilter:K?B.create(K,w.associations.getFieldsIndex()):null})}))},W.signatures.push({name:"featuresetbyassociation",min:2,max:6}),W.functions.groupby=function(e,t){return W.standardFunctionAsync(e,t,(async(r,s,l)=>{if(p(l,3,3,e,t),!y(l[0]))throw new i(e,a.InvalidParameter,t);const o=await l[0].load(),f=[],u=[];let c=!1,d=[];if(h(l[1]))d.push(l[1]);else if(l[1]instanceof n)d.push(l[1]);else if(b(l[1]))d=l[1];else{if(!A(l[1]))throw new i(e,a.InvalidParameter,t);d=l[1].toArray()}for(const m of d)if(h(m)){const e=B.create(g(m),o.getFieldsIndex()),t=!0===_(e)?g(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(c=!0)}else{if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(c=!0),!n)throw new i(e,a.InvalidParameter,t);f.push({name:n,expression:B.create(r||n,o.getFieldsIndex())})}}if(d=[],h(l[2]))d.push(l[2]);else if(b(l[2]))d=l[2];else if(A(l[2]))d=l[2].toArray();else{if(!(l[2]instanceof n))throw new i(e,a.InvalidParameter,t);d.push(l[2])}for(const m of d){if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new i(e,a.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:B.create(s,o.getFieldsIndex())})}}if(c){const e={};for(const n of o.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of u)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)await K(t.expression,W,e);for(const t of u)await K(t.expression,W,e);return l[0].groupby(f,u)}))},W.signatures.push({name:"groupby",min:3,max:3}),W.functions.distinct=function(e,t){return W.standardFunctionAsync(e,t,(async(r,s,l)=>{if(y(l[0])){p(l,2,2,e,t);const r=await l[0].load(),s=[];let o=[];if(h(l[1]))o.push(l[1]);else if(l[1]instanceof n)o.push(l[1]);else if(b(l[1]))o=l[1];else{if(!A(l[1]))throw new i(e,a.InvalidParameter,t);o=l[1].toArray()}let f=!1;for(const l of o)if(h(l)){const e=B.create(g(l),r.getFieldsIndex()),t=!0===_(e)?g(l):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(l instanceof n))throw new i(e,a.InvalidParameter,t);{const n=l.hasField("name")?l.field("name"):"%%%%FIELDNAME",o=l.hasField("expression")?l.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new i(e,a.InvalidParameter,t);s.push({name:n,expression:B.create(o||n,r.getFieldsIndex())})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await K(t.expression,W,e);return l[0].groupby(s,[])}return J("distinct",r,s,l)}))})}export{ae as registerFunctions};
|