@arcgis/core 4.30.0-next.20240503 → 4.30.0-next.20240504
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/arcade/featureSetUtils.js +1 -1
- package/arcade/featureset/actions/GroupBy.js +1 -1
- package/arcade/featureset/actions/OrderBy.js +1 -1
- package/arcade/featureset/sources/FeatureLayerDynamic.js +1 -1
- package/arcade/featureset/sources/FeatureLayerMemory.js +1 -1
- package/arcade/featureset/support/shared.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/arcade/functions/featuresetstring.js +1 -1
- package/arcade/functions/knowledgegraph.js +1 -1
- package/arcade/languageUtils.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/{55cd899ecf5dc4fe45ce.js → 016af6d848af3e3582bf.js} +1 -1
- package/assets/esri/core/workers/chunks/16655015beb553c3b4ff.js +1 -0
- package/assets/esri/core/workers/chunks/{28216bcef616cf8f6803.js → 3dd4b58e85255d3026be.js} +1 -1
- package/assets/esri/core/workers/chunks/3f78593d171f25a5617b.js +1 -0
- package/assets/esri/core/workers/chunks/71c855e591e282f866e8.js +1 -0
- package/assets/esri/core/workers/chunks/7a108eafd620d52df670.js +1 -0
- package/assets/esri/core/workers/chunks/7e8a286eda7a0e69a662.js +1 -0
- package/assets/esri/core/workers/chunks/{b145b5410b4b3e1e4704.js → 8c0cf61373f9f2532da4.js} +1 -1
- package/assets/esri/core/workers/chunks/8c50effbe249dc57ad3b.js +1 -0
- package/assets/esri/core/workers/chunks/916bb9d2ea06c4c1668a.js +1 -0
- package/assets/esri/core/workers/chunks/b43945dd02f8a5203a43.js +1 -0
- package/assets/esri/core/workers/chunks/{06fbb9155b935c1e8dda.js → d1d6dc366806f7c49997.js} +1 -1
- package/assets/esri/core/workers/chunks/d6cf984755e8656562fb.js +1 -0
- package/assets/esri/core/workers/chunks/da69d3089ff10671ec61.js +1 -0
- package/assets/esri/core/workers/chunks/{4bf0fbf54749d03629a9.js → dda5f376a1bc9dd6c438.js} +1 -1
- package/assets/esri/core/workers/chunks/ea05cd5641bd032565cc.js +1 -0
- package/assets/esri/t9n/common_ar.json +1 -1
- package/assets/esri/t9n/common_bg.json +1 -1
- package/assets/esri/t9n/common_bs.json +1 -1
- package/assets/esri/t9n/common_ca.json +1 -1
- package/assets/esri/t9n/common_cs.json +1 -1
- package/assets/esri/t9n/common_da.json +1 -1
- package/assets/esri/t9n/common_de.json +1 -1
- package/assets/esri/t9n/common_el.json +1 -1
- package/assets/esri/t9n/common_es.json +1 -1
- package/assets/esri/t9n/common_et.json +1 -1
- package/assets/esri/t9n/common_fi.json +1 -1
- package/assets/esri/t9n/common_fr.json +1 -1
- package/assets/esri/t9n/common_he.json +1 -1
- package/assets/esri/t9n/common_hr.json +1 -1
- package/assets/esri/t9n/common_hu.json +1 -1
- package/assets/esri/t9n/common_id.json +1 -1
- package/assets/esri/t9n/common_it.json +1 -1
- package/assets/esri/t9n/common_ja.json +1 -1
- package/assets/esri/t9n/common_ko.json +1 -1
- package/assets/esri/t9n/common_lt.json +1 -1
- package/assets/esri/t9n/common_lv.json +1 -1
- package/assets/esri/t9n/common_nb.json +1 -1
- package/assets/esri/t9n/common_nl.json +1 -1
- package/assets/esri/t9n/common_pl.json +1 -1
- package/assets/esri/t9n/common_pt-BR.json +1 -1
- package/assets/esri/t9n/common_pt-PT.json +1 -1
- package/assets/esri/t9n/common_ro.json +1 -1
- package/assets/esri/t9n/common_ru.json +1 -1
- package/assets/esri/t9n/common_sk.json +1 -1
- package/assets/esri/t9n/common_sl.json +1 -1
- package/assets/esri/t9n/common_sr.json +1 -1
- package/assets/esri/t9n/common_sv.json +1 -1
- package/assets/esri/t9n/common_th.json +1 -1
- package/assets/esri/t9n/common_tr.json +1 -1
- package/assets/esri/t9n/common_uk.json +1 -1
- package/assets/esri/t9n/common_vi.json +1 -1
- package/assets/esri/t9n/common_zh-CN.json +1 -1
- package/assets/esri/t9n/common_zh-HK.json +1 -1
- package/assets/esri/t9n/common_zh-TW.json +1 -1
- package/chunks/languageUtils.js +1 -1
- package/config.js +1 -1
- package/interfaces.d.ts +134 -129
- package/layers/LinkChartLayer.js +1 -1
- package/layers/RouteLayer.js +1 -1
- package/layers/WMSLayer.js +1 -1
- package/layers/catalog/CatalogDynamicGroupLayer.js +1 -1
- package/layers/catalog/CatalogFootprintLayer.js +1 -1
- package/layers/support/mediaUtils.js +1 -1
- package/layers/support/wmsUtils.js +1 -1
- package/package.json +1 -1
- package/rest/support/DirectionLine.js +1 -1
- package/rest/support/DirectionPoint.js +1 -1
- package/rest/support/PointBarrier.js +1 -1
- package/rest/support/PolygonBarrier.js +1 -1
- package/rest/support/PolylineBarrier.js +1 -1
- package/rest/support/RouteInfo.js +1 -1
- package/rest/support/Stop.js +1 -1
- package/support/revision.js +1 -1
- package/symbols/cim/CIMSymbolHelper.js +1 -1
- package/symbols/cim/effects/EffectControlMeasureLine.js +1 -1
- package/views/2d/engine/webgl/Overlay.js +1 -1
- package/views/2d/engine/webgl/OverlayContainer.js +1 -1
- package/views/2d/engine/webgl/OverlayMultipoint.js +5 -0
- package/views/2d/engine/webgl/brushes/BrushOverlay.js +1 -1
- package/views/2d/engine/webgl/shaders/sources/shaderRepository.js +1 -1
- package/views/2d/interactive/editingTools/draw/DrawGraphicTool2D.js +1 -1
- package/views/2d/layers/CatalogDynamicGroupLayerView2D.js +1 -1
- package/views/2d/layers/VideoLayerView2D.js +1 -1
- package/views/3d/environment/EnvironmentRenderer.js +1 -1
- package/views/3d/layers/support/FeatureVisibilityFilter.js +1 -1
- package/views/3d/support/DisplayQualityProfile.js +1 -1
- package/views/draw/DrawGraphicTool.js +1 -1
- package/views/draw/DrawOperation.js +1 -1
- package/views/interactive/editGeometry/EditGeometryOperations.js +1 -1
- package/views/interactive/editGeometry/operations/UndoGroup.js +1 -1
- package/views/layers/CatalogDynamicGroupLayerView.js +1 -1
- package/widgets/Expand.js +1 -1
- package/widgets/Feature/support/featureUtils.js +1 -1
- package/widgets/FeatureTable/FeatureTableViewModel.js +1 -1
- package/widgets/FeatureTable/FieldColumn.js +1 -1
- package/widgets/FeatureTable/support/FeatureStore.js +1 -1
- package/widgets/FeatureTable/support/TableTemplate.js +1 -1
- package/widgets/FeatureTable/support/tableUtils.js +1 -1
- package/assets/esri/core/workers/chunks/066b71430e38c5035212.js +0 -1
- package/assets/esri/core/workers/chunks/2298836795cb1efc3b2f.js +0 -1
- package/assets/esri/core/workers/chunks/377023c94e5750aeaeda.js +0 -1
- package/assets/esri/core/workers/chunks/47927c18a18b0ad7282b.js +0 -1
- package/assets/esri/core/workers/chunks/635b2f092af7a2f0aa50.js +0 -1
- package/assets/esri/core/workers/chunks/884a7264feb6ab76e6d0.js +0 -1
- package/assets/esri/core/workers/chunks/98b31a0c6d7324c2ea58.js +0 -1
- package/assets/esri/core/workers/chunks/9bd1b418d5ce4236031f.js +0 -1
- package/assets/esri/core/workers/chunks/a04802fa0d5876e22956.js +0 -1
- package/assets/esri/core/workers/chunks/a64e5463214131bf930a.js +0 -1
- package/assets/esri/core/workers/chunks/e607c767763e36e5b614.js +0 -1
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../request.js";import t from"./featureSetCollection.js";import{$ as a,a0 as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import l from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import f from"./featureset/support/cache.js";import{FeatureSetError as p,FeatureSetErrorCodes as m}from"./featureset/support/errorsupport.js";import y from"./featureset/support/FeatureSet.js";import{extractServiceUrl as h}from"./featureset/support/shared.js";import{WhereClause as _}from"../core/sql/WhereClause.js";import w from"../layers/FeatureLayer.js";import L from"../portal/PortalItem.js";function I(){null===f.applicationCache&&(f.applicationCache=new f)}async function S(e,t){if(f.applicationCache){const r=f.applicationCache.getLayerInfo(e);if(r){const a=await r;return new w({url:e,outFields:t,sourceJSON:a})}const n=new w({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(f.applicationCache){f.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(a){throw f.applicationCache.clearLayerInfo(e),a}}return await i,n}return new w({url:e,outFields:t})}async function F(e,t,a,r,n,i=null){return g(await S(e,["*"]),t,a,r,n,i)}function g(e,t=null,r=null,n=!0,i=null,s=null){if(e instanceof w||a(e)){const a={layer:e,spatialReference:t,outFields:r,includeGeometry:n,lrucache:i,interceptor:s};return!0==!(e.url||!e.source)?new c(a):new u(a)}const l=g(e.parent,t,r,n,i,s);return l.filter(_.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),e.parent.fieldsIndex,l.dateFieldsTimeZoneDefaultUTC))}async function N(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function C(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new p(m.DataElementsNotFound)})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw f.applicationCache.clearLayerInfo(r),i}}return n}async function T(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function A(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await T(e);if(a.metadata=r,void 0!==r.controllerDatasetLayers?.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await C(e,n);if(i){a.queryelem=i,a.queryelem?.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await N(e+"/"+n);if(void 0!==r.systemLayers?.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await F(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(_.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",i.getFieldsIndex(),i.dateFieldsTimeZoneDefaultUTC)),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function k(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await F(o,r,n,i,s,l);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}n.registerAction(),i.registerAction(),s.registerAction(),l.registerAction(),o.registerAction();class O extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=g(e,this._overridespref,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,r=null){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,r);null===r&&(r=["*"]),r=(r=r.slice(0)).sort();const n=JSON.stringify(r);for(let a=0;a<this._instantLayers.length;a++){const r=this._instantLayers[a];if(r.opitem.title===e&&r.includeGeometry===t&&r.outFields===n)return this._instantLayers[a].featureset}const i=this._map.allLayers.find((t=>{if(t instanceof w){if(t.title===e)return!0}else if(a(t)&&t.title===e)return!0;return!1}));if(i)return this._makeAndAddFeatureSet(i,t,r);if(this._map.tables){const a=this._map.tables.find((t=>!!(t.title&&t.title===e||t.title&&t.title===e)));if(a){if(a instanceof w)return this._makeAndAddFeatureSet(a,t,r);if(a._materializedTable);else{const e=a.outFields?a:{...a,outFields:["*"]};a._materializedTable=new w(e)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,r)}}return null}async featureSetById(e,t=!0,r=["*"]){if(void 0!==this._map.loaded&&void 0!==this._map.load&&!1===this._map.loaded)return await this._map.load(),this.featureSetById(e,t,r);null===r&&(r=["*"]),r=(r=r.slice(0)).sort();const n=JSON.stringify(r);for(let a=0;a<this._instantLayers.length;a++){const r=this._instantLayers[a];if(r.opitem.id===e&&r.includeGeometry===t&&r.outFields===n)return this._instantLayers[a].featureset}const i=this._map.allLayers.find((t=>{if(t instanceof w){if(t.id===e)return!0}else if(a(t)&&t.id===e)return!0;return!1}));if(i)return this._makeAndAddFeatureSet(i,t,r);if(this._map.tables){const a=this._map.tables.find((t=>t.id===e));if(a){if(a instanceof w)return this._makeAndAddFeatureSet(a,t,r);if(a._materializedTable);else{const e={...a,outFields:["*"]};a._materializedTable=new w(e)}return await a._materializedTable.load(),this._makeAndAddFeatureSet(a._materializedTable,t,r)}}return null}}class b extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=g(e,this._overridespref,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await T(this._url);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new b(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])s.name===e&&(i=s);if(!i)for(const s of n.tables??[])s.name===e&&(i=s);if(i){const e=await S(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await S(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function D(e,t,a=null,r=null){return new O(e,t,a,r)}function E(e,t,a=null,r=null){return new b(e,t,a,r)}function j(e,t,n,i,s){if(null===e)return null;if(e instanceof w){switch(t){case"datasource":return g(e,s,e.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.outFields,!0,n,i)}return null}if(a(e)){switch(t){case"datasource":return g(e,s,e.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return g(e.parent,s,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return g(e,s,e.parent.outFields,!0,n,i)}return null}if(e instanceof y)switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}async function q(e,t,a,r,n,i,s,l=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return g(new w({url:h(e.url)+"/"+t,outFields:["*"]}),a,r,n,s,l)}}const o=new L({id:e,portal:i}).load();f.applicationCache&&f.applicationCache.setLayerInfo(e+":"+i.url,o);try{const e=await o;return g(new w({url:h(e.url??"")+"/"+t,outFields:["*"]}),a,r,n,s,l)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),u}}export{A as constructAssociationMetaDataFeatureSetFromUrl,g as constructFeatureSet,q as constructFeatureSetFromPortalItem,k as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,j as convertToFeatureSet,D as createFeatureSetCollectionFromMap,E as createFeatureSetCollectionFromService,I as initialiseMetaDataCache};
|
|
5
|
+
import e from"../request.js";import t from"./featureSetCollection.js";import{u as a,$ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import s from"./featureset/actions/OrderBy.js";import l from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import f from"./featureset/support/cache.js";import{FeatureSetError as p,FeatureSetErrorCodes as m}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as y,extractServiceUrl as h,isSupportedLayer as _}from"./featureset/support/shared.js";import L from"../core/Loadable.js";import{WhereClause as w}from"../core/sql/WhereClause.js";import I from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import F from"../portal/PortalItem.js";function g(){null===f.applicationCache&&(f.applicationCache=new f)}async function N(e,t){if(f.applicationCache){const r=f.applicationCache.getLayerInfo(e);if(r){const a=await r;return new I({url:e,outFields:t,sourceJSON:a})}const n=new I({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(f.applicationCache){f.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(a){throw f.applicationCache.clearLayerInfo(e),a}}return await i,n}return new I({url:e,outFields:t})}async function C(e,t,a,r,n,i=null){return T(await N(e,["*"]),t,a,r,n,i)}function T(e,t=null,a=null,r=!0,n=null,i=null){if("catalog-footprint"===e.type)return T(e.parent,t,a,r,n,i);if("subtype-sublayer"===e.type){const s=T(e.parent,t,a,r,n,i);return s.filter(w.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),e.parent.fieldsIndex,s.dateFieldsTimeZoneDefaultUTC))}if(y(e)){const s={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!0==!(e.url||!e.source)?new c(s):new u(s)}throw new Error(`Unsupported layer type: ${e.type}`)}async function A(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function b(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new p(m.DataElementsNotFound)})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw f.applicationCache.clearLayerInfo(r),i}}return n}async function k(t){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw f.applicationCache.clearLayerInfo(t),r}}return a}async function O(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await k(e);if(a.metadata=r,void 0!==r.controllerDatasetLayers?.utilityNetworkLayerId&&null!==r.controllerDatasetLayers.utilityNetworkLayerId){if(r.layers)for(const e of r.layers)a.layerNameLkp[e.id]=e.name;if(r.tables)for(const e of r.tables)a.layerNameLkp[e.id]=e.name;const n=r.controllerDatasetLayers.utilityNetworkLayerId;a.networkId=n;const i=await b(e,n);if(i){a.queryelem=i,a.queryelem?.dataElement&&void 0!==a.queryelem.dataElement.schemaGeneration&&(a.unVersion=a.queryelem.dataElement.schemaGeneration),a.lkp={},a.queryelem.dataElement.domainNetworks||(a.queryelem.dataElement.domainNetworks=[]);for(const e of a.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:a.layerNameLkp[t.layerId]??null};e.className&&(a.lkp[e.className]=e)}}if(a.queryelem.dataElement.terminalConfigurations)for(const e of a.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)a.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const r=await A(e+"/"+n);if(void 0!==r.systemLayers?.associationsTableId&&null!==r.systemLayers.associationsTableId){const n=[];a.unVersion>=4&&(n.push("STATUS"),n.push("PERCENTALONG"));let i=await C(e+"/"+r.systemLayers.associationsTableId.toString(),t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...n],!1,null,null);return await i.load(),a.unVersion>=4&&(i=i.filter(w.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",i.getFieldsIndex(),i.dateFieldsTimeZoneDefaultUTC)),await i.load()),{lkp:a.lkp,associations:i,unVersion:a.unVersion,terminals:a.terminals}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}return{associations:null,unVersion:a.unVersion,lkp:null,terminals:[]}}async function E(e,t,a,r=null,n=null,i=!0,s=null,l=null){let o=e.serviceUrl();if(!o)return null;o="/"===o.charAt(o.length-1)?o+t.relatedTableId.toString():o+"/"+t.relatedTableId.toString();const u=await C(o,r,n,i,s,l);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:s,interceptor:l})}n.registerAction(),i.registerAction(),s.registerAction(),l.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overridespref,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(L.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>_(t)&&t.title===e));if(null!=n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.title===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(L.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let i=0;i<this._instantLayers.length;i++){const a=this._instantLayers[i];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[i].featureset}const n=this._map.allLayers.find((t=>_(t)&&t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,a);if(this._map.tables){const r=this._map.tables.find((t=>t.id===e));if(null!=r){if(r instanceof I)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e={...r,outFields:["*"]};r._materializedTable=new I(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}}class D extends t{constructor(e,t=null,a=null,r=null){super(),this._url=e,this._overridespref=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overridespref,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await k(this._url);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overridespref,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])s.name===e&&(i=s);if(!i)for(const s of n.tables??[])s.name===e&&(i=s);if(i){const e=await N(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice(0)).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let s=0;s<this._instantLayers.length;s++){const a=this._instantLayers[s];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[s].featureset}const n=await this._loadMetaData();let i=null;for(const s of n.layers??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(!i)for(const s of n.tables??[])null!==s.id&&void 0!==s.id&&s.id.toString()===e&&(i=s);if(i){const e=await N(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function q(e,t,a=null,r=null){return new j(e,t,a,r)}function G(e,t,a=null,r=null){return new D(e,t,a,r)}function R(e,t,n,i,s){if(null===e)return null;if(a(e)){switch(t){case"datasource":return e.getDataSourceFeatureSet();case"parent":return e;case"root":return e.getRootFeatureSet()}return null}if(e instanceof S&&y(e)){const a=e;switch(t){case"datasource":return T(a,s,a.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(a,s,a.outFields,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return T(e.parent,s,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(e,s,e.parent.outFields,!0,n,i)}return null}return null}async function B(e,t,a,r,n,i,s,l=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o){const e=await o;return T(new I({url:h(e.url)+"/"+t,outFields:["*"]}),a,r,n,s,l)}}const o=new F({id:e,portal:i}).load();f.applicationCache&&f.applicationCache.setLayerInfo(e+":"+i.url,o);try{const e=await o;return T(new I({url:h(e.url??"")+"/"+t,outFields:["*"]}),a,r,n,s,l)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),u}}export{O as constructAssociationMetaDataFeatureSetFromUrl,T as constructFeatureSet,B as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,C as constructFeatureSetFromUrl,R as convertToFeatureSet,q as createFeatureSetCollectionFromMap,G as createFeatureSetCollectionFromService,g as initialiseMetaDataCache};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{a1 as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as l,FeatureSetErrorCodes as o}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import{calculateStat as w}from"../support/stats.js";import F from"../support/StatsField.js";import{createMD5Hash as I,outputTypes as S}from"../../../core/MD5.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as k}from"../../../core/sql/TimeOnly.js";import{WhereClause as j}from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class O extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new F;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new F;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=j.create(this._parent.objectIdField,this._parent.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new C;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new l(o.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new C;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new C;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new l(o.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,l){if(""!==e)return new u([],[],!0,null);let o=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(l),o=!0===d.nowhereclause?new u(n._candidates.slice(0).concat(n._known.slice(0)),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(0),n._known.slice(0),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),o}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return o}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const l=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:l};else{if(l!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:l},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(l){a(l)}}_calculateFieldStat(e,t,i){const s=[];for(let n=0;n<e.features.length;n++)if(null!==t.workingexpr){const i=t.workingexpr.calculateValue(e.features[n]);null!==i&&(i instanceof x||i instanceof k?s.push(i.toNumber()):i instanceof D?s.push(i.toMilliseconds()):s.push(i))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=w("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=w("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=w("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=w("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=w("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=w("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:j.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return I(t,S.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
|
|
5
|
+
import e from"../../../Graphic.js";import{a0 as t}from"../../../chunks/languageUtils.js";import{SqlExpressionAdapted as i,OriginalField as s,AdaptedFeatureSet as n}from"./Adapted.js";import r from"./AttributeFilter.js";import a from"./OrderBy.js";import{FeatureSetError as l,FeatureSetErrorCodes as o}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as _,predictType as m,scanForField as y,reformulateWithoutField as b}from"../support/sqlUtils.js";import{calculateStat as w}from"../support/stats.js";import F from"../support/StatsField.js";import{createMD5Hash as I,outputTypes as S}from"../../../core/MD5.js";import{DateOnly as x}from"../../../core/sql/DateOnly.js";import{SqlTimeStampOffset as D}from"../../../core/sql/SqlTimestampOffset.js";import{TimeOnly as k}from"../../../core/sql/TimeOnly.js";import{WhereClause as j}from"../../../core/sql/WhereClause.js";import A from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/Field.js";import T from"../../../layers/support/FieldsIndex.js";function G(e){if(!e)return"COUNT";switch(e.toLowerCase()){case"max":return"MAX";case"var":case"variance":return"VAR";case"avg":case"average":case"mean":return"AVG";case"min":return"MIN";case"sum":return"SUM";case"stdev":case"stddev":return"STDDEV";case"count":return"COUNT"}return"COUNT"}class O extends d{constructor(e){super(e),this._decodedStatsfield=[],this._decodedGroupbyfield=[],this._candosimplegroupby=!0,this.phsyicalgroupbyfields=[],this.objectIdField="ROW__ID",this._internalObjectIdField="ROW__ID",this._adaptedFields=[],this.declaredClass="esri.arcade.featureset.actions.Aggregate",this._uniqueIds=1,this._maxQuery=10,this._maxProcessing=10,this._parent=e.parentfeatureset,this._config=e}isTable(){return!0}async _getSet(e){if(null===this._wset){const t=await this._getFilteredSet("",null,null,null,e);return this._wset=t,this._wset}return this._wset}_isInFeatureSet(){return c.InFeatureSet}_nextUniqueName(e){for(;1===e["T"+this._uniqueIds.toString()];)this._uniqueIds++;const t="T"+this._uniqueIds.toString();return e[t]=1,t}_convertToEsriFieldType(e){return e}_initialiseFeatureSet(){const e={};let t=!1,n=1;const r=this._parent?this._parent.getFieldsIndex():new T([]);for(this.objectIdField="ROW__ID",this.globalIdField="";!1===t;){let e=!1;for(let t=0;t<this._config.groupbyfields.length;t++)if(this._config.groupbyfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}if(!1===e)for(let t=0;t<this._config.statsfields.length;t++)if(this._config.statsfields[t].name.toLowerCase()===this.objectIdField.toLowerCase()){e=!0;break}!1===e?t=!0:(this.objectIdField="ROW__ID"+n.toString(),n++)}for(const i of this._config.statsfields){const e=new F;e.field=i.name,e.tofieldname=i.name,e.workingexpr=i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),e.typeofstat=G(i.statistic),this._decodedStatsfield.push(e)}this._decodedGroupbyfield=[];for(const i of this._config.groupbyfields){const e={name:i.name,singlefield:null,tofieldname:i.name,expression:i.expression instanceof j?i.expression:j.create(i.expression,r,this.dateFieldsTimeZoneDefaultUTC),sqlType:null};this._decodedGroupbyfield.push(e)}if(null!==this._parent){this.geometryType=this._parent.geometryType,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField="";for(const t of this._parent.fields)e[t.name.toUpperCase()]=1;this.types=null,this.subtypes=null,this.subtypeField=""}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.subtypes=null,this.subtypeField="",this.spatialReference=new A({wkid:4326});this.fields=[];const a=new F;a.field=this._nextUniqueName(e),a.tofieldname=this.objectIdField,a.workingexpr=j.create(this._parent.objectIdField,this._parent.getFieldsIndex(),this.dateFieldsTimeZoneDefaultUTC),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new C;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(_(s.expression,h.Standardised));if(!e)throw new l(o.AggregationFieldNotFound);s.name=e.name,s.singlefield=e.name,this.phsyicalgroupbyfields.push(e.name),t.type=e.type,s.sqlType=e.type}else{t.type=this._convertToEsriFieldType(m(s.expression,this._parent.fields));const e=new C;e.name=s.name,e.alias=e.name,this.phsyicalgroupbyfields.push(s.name),this._adaptedFields.push(new i(e,s.expression)),this._candosimplegroupby=!1,s.sqlType=t.type}this.fields.push(t)}if(this._adaptedFields.length>0)for(const i of this._parent.fields)this._adaptedFields.push(new s(i));for(let i=0;i<this._decodedStatsfield.length;i++){const t=new C;let s=null;const n=this._decodedStatsfield[i];n.field=this._nextUniqueName(e),n.tofieldname===this.objectIdField&&(this._internalObjectIdField=n.field),t.name=n.tofieldname,t.alias=t.name;const r=null!==n.workingexpr&&g(n.workingexpr)?_(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"MIN":case"MAX":if(""!==r){if(s=this._parent.getField(r),!s)throw new l(o.AggregationFieldNotFound);t.type=s.type}else t.type="double";break;case"COUNT":t.type="integer";break;case"STDDEV":case"VAR":case"AVG":if(""!==r&&(s=this._parent.getField(r),!s))throw new l(o.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,l){if(""!==e)return new u([],[],!0,null);let o=null;const d={ordered:!1,nowhereclause:!1};if(await this._ensureLoaded(),null!==i)for(let n=0;n<this._decodedStatsfield.length;n++)if(!0===y(i,this._decodedStatsfield[n].tofieldname)){d.nowhereclause=!0,i=null;break}if(null!==s){d.ordered=!0;for(let e=0;e<this._decodedStatsfield.length;e++)if(!0===s.scanForField(this._decodedStatsfield[e].tofieldname)){s=null,d.ordered=!1;break}if(null!==s)for(const e of this._decodedGroupbyfield)if(null===e.singlefield&&!0===s.scanForField(e.tofieldname)){s=null,d.ordered=!1;break}}if(!1!==this._candosimplegroupby&&await this._parent._canDoAggregates(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,null)){let e=null;i&&(e=this._reformulateWhereClauseWithoutGroupByFields(i));let t=null;s&&(t=this._reformulateOrderClauseWithoutGroupByFields(s));const n=await this._parent._getAggregatePagesDataSourceDefinition(this.phsyicalgroupbyfields,this._decodedStatsfield,"",null,e,t,this._internalObjectIdField);return this._checkCancelled(l),o=!0===d.nowhereclause?new u(n._candidates.slice(0).concat(n._known.slice(0)),[],!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)):new u(n._candidates.slice(0),n._known.slice(0),!0===d.ordered&&n._ordered,this._clonePageDefinition(n.pagesDefinition)),o}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:c,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}});else{let e=c;if(null!==i){let t=null;i&&(t=this._reformulateWhereClauseWithoutGroupByFields(i)),e=new r({parentfeatureset:e,whereclause:t})}o=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new a({parentfeatureset:e,orderbyclause:new f(this.phsyicalgroupbyfields.join(",")+","+this._parent.objectIdField+" ASC")})}})}return o}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,_(t.workingexpr,h.Standardised),this._parent.getFieldsIndex());return e}_reformulateWhereClauseWithoutGroupByFields(e){for(const t of this._decodedGroupbyfield)t.tofieldname!==t.name&&(e=b(e,t.tofieldname,_(t.expression,h.Standardised),this._parent.getFieldsIndex()));return e}_reformulateOrderClauseWithoutGroupByFields(e){const t=[];for(const i of this._decodedGroupbyfield)i.tofieldname!==i.name&&t.push({field:i.tofieldname,newfield:i.name});return t.length>0?e.replaceFields(t):e}_clonePageDefinition(e){return null===e?null:!0===e.aggregatefeaturesetpagedefinition?{aggregatefeaturesetpagedefinition:!0,resultRecordCount:e.resultRecordCount,resultOffset:e.resultOffset,internal:e.internal}:this._parent._clonePageDefinition(e)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQuery))return await this._expandPagedSet(e,this._maxQuery,0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const s=e._candidates.length;this._refineKnowns(e,t);e._candidates.length;return e._candidates.length,e}_expandPagedSet(e,t,i,s,n){return this._expandPagedSetFeatureSet(e,t,i,s,n)}async _getPhysicalPage(t,i,s){if(!0===t.pagesDefinition.aggregatefeaturesetpagedefinition)return this._sequentialGetPhysicalItem(t,t.pagesDefinition.resultRecordCount,s,[]);const n=await this._getAgregagtePhysicalPage(t,i,s);for(const r of n){const t={geometry:r.geometry,attributes:{}},i={};for(const e in r.attributes)i[e.toLowerCase()]=r.attributes[e];for(const e of this._decodedGroupbyfield)t.attributes[e.tofieldname]=i[e.name.toLowerCase()];for(const e of this._decodedStatsfield)t.attributes[e.tofieldname]=i[e.field.toLowerCase()];this._featureCache[t.attributes[this.objectIdField]]=new e(t)}return n.length}_sequentialGetPhysicalItem(e,t,i,s){return new Promise(((n,r)=>{null===e.pagesDefinition.internal.iterator&&(e.pagesDefinition.internal.iterator=e.pagesDefinition.internal.subfeatureset.iterator(i)),!0===e.pagesDefinition.internal.fullyResolved||0===t?n(s.length):this._nextAggregateItem(e,t,i,s,(r=>{null===r?n(s.length):(t-=1,n(this._sequentialGetPhysicalItem(e,t,i,s)))}),r)}))}_nextAggregateItem(e,i,s,n,r,a){try{t(e.pagesDefinition.internal.iterator.next()).then((t=>{if(null===t)if(null!==e.pagesDefinition.internal.workingItem){const t=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);n.push(t),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(t.attributes[this.objectIdField]),e.pagesDefinition.internal.fullyResolved=!0,r(null)}else e.pagesDefinition.internal.fullyResolved=!0,r(null);else{const l=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:l};else{if(l!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:l},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(l){a(l)}}_calculateFieldStat(e,t,i){const s=[];for(let n=0;n<e.features.length;n++)if(null!==t.workingexpr){const i=t.workingexpr.calculateValue(e.features[n]);null!==i&&(i instanceof x||i instanceof k?s.push(i.toNumber()):i instanceof D?s.push(i.toMilliseconds()):s.push(i))}else s.push(null);switch(t.typeofstat){case"MIN":i.attributes[t.tofieldname]=w("min",s,-1);break;case"MAX":i.attributes[t.tofieldname]=w("max",s,-1);break;case"SUM":i.attributes[t.tofieldname]=w("sum",s,-1);break;case"COUNT":i.attributes[t.tofieldname]=s.length;break;case"VAR":i.attributes[t.tofieldname]=w("var",s,-1);break;case"STDDEV":i.attributes[t.tofieldname]=w("stddev",s,-1);break;case"AVG":i.attributes[t.tofieldname]=w("avg",s,-1)}return!0}_calculateAndAppendAggregateItem(t){const i={attributes:{},geometry:null};for(const e of this._decodedGroupbyfield){const s=e.singlefield?t.features[0].attributes[e.singlefield]:j.convertValueToStorageFormat(e.expression.calculateValue(t.features[0]),e.sqlType);i.attributes[e.tofieldname]=s}for(const e of this._decodedStatsfield)this._calculateFieldStat(t,e,i);const s=[];for(let e=0;e<this._decodedStatsfield.length;e++)s.push(this._calculateFieldStat(t,this._decodedStatsfield[e],i));return this._featureCache[i.attributes[this.objectIdField]]=new e({attributes:i.attributes,geometry:i.geometry}),i}_generateAggregateHash(e){let t="";for(const i of this._decodedGroupbyfield){const s=i.singlefield?e.attributes[i.singlefield]:i.expression.calculateValue(e);t+=null==s?":":":"+s.toString()}return I(t,S.String)}async _stat(){return{calculated:!1}}async getFeatureByObjectId(){return null}static registerAction(){d._featuresetFunctions.groupby=function(e,t){return new O({parentfeatureset:this,groupbyfields:e,statsfields:t})}}}export{O as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{
|
|
5
|
+
import{a0 as e}from"../../../chunks/languageUtils.js";import{FeatureSetError as t,FeatureSetErrorCodes as r}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import s from"../support/IdSet.js";import i from"../support/OrderbyClause.js";class a extends n{constructor(e){super(e),this._orderbyclause=null,this.declaredClass="esri.arcade.featureset.actions.OrderBy",this._maxProcessing=100,this._orderbyclause=e.orderbyclause,this._parent=e.parentfeatureset}async _getSet(e){if(null===this._wset){await this._ensureLoaded();const t=await this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}async manualOrderSet(e,t){const r=await this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause?.order(r);const n=new s([],[],!0,null);for(let s=0;s<r.length;s++)n._known.push(r[s].id);return n}async getIdColumnDictionary(t,r,n,s){if(n<t._known.length-1){const i=this._maxQueryRate();if("GETPAGES"===t._known[n+1])return await e(this._parent._expandPagedSet(t,i,0,0,s)),this.getIdColumnDictionary(t,r,n,s);let a=n+1;const o=[];for(;a<t._known.length&&"GETPAGES"!==t._known[a];)o.push(t._known[a]),a++;n+=o.length;const u=await e(this._parent._getFeatureBatch(o,s));this._checkCancelled(s);for(const e of u)r.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(t,r,n,s)}return t._candidates.length>0?(await e(this._refineSetBlock(t,this._maxProcessingRate(),s)),this._checkCancelled(s),this.getIdColumnDictionary(t,r,n,s)):r}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}_getFeatures(e,t,r,n){return this._parent._getFeatures(e,t,r,n)}_featureFromCache(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]}async _fetchAndRefineFeatures(){throw new t(r.NeverReach)}async _getFilteredSet(e,t,r,n,i){await this._ensureLoaded();const a=await this._parent._getFilteredSet(e,t,r,null===n?this._orderbyclause:n,i);this._checkCancelled(i);const o=new s(a._candidates.slice(0),a._known.slice(0),a._ordered,this._clonePageDefinition(a.pagesDefinition));let u=!0;if(a._candidates.length>0&&(u=!1),!1===o._ordered){let e=await this.manualOrderSet(o,i);return!1===u&&(null===t&&null===r||(e=new s(e._candidates.slice(0).concat(e._known.slice(0)),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return o}static registerAction(){n._featuresetFunctions.orderBy=function(e){return""===e?this:new a({parentfeatureset:this,orderbyclause:new i(e)})}}getFieldsIndex(){return this._parent.getFieldsIndex()}}export{a as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{id as t}from"../../../kernel.js";import i from"../../../request.js";import r from"../../Attachment.js";import s from"../../Dictionary.js";import{FeatureSetError as a,FeatureSetErrorCodes as n}from"../support/errorsupport.js";import l from"../support/FeatureSet.js";import o from"../support/IdSet.js";import{defaultMaxRecords as u,stableStringify as d,FeatureServiceDatabaseType as p,IdState as h,extractServiceUrl as c}from"../support/shared.js";import{toWhereClause as y,isSingleField as f}from"../support/sqlUtils.js";import{decodeStatType as m}from"../support/stats.js";import{createMD5Hash as _,outputTypes as g}from"../../../core/MD5.js";import{fromJSON as w}from"../../../geometry/support/jsonUtils.js";import{srToRESTValue as R}from"../../../geometry/support/spatialReferenceUtils.js";import b from"../../../layers/FeatureLayer.js";import S from"../../../layers/SubtypeGroupLayer.js";import{executeQuery as F}from"../../../rest/query/executeQuery.js";import"../../../config.js";import"../../../core/RandomLCG.js";import"../../../core/has.js";import"../../../core/urlUtils.js";import"../../../rest/query/support/AttachmentInfo.js";import"../../../rest/support/AttachmentQuery.js";import{executeForCount as I}from"../../../rest/query/executeForCount.js";import"../../../geometry.js";import"../../../core/Error.js";import"../../../core/Logger.js";import"../../../geometry/Polygon.js";import"../../../geometry/Polyline.js";import"../../../geometry/support/normalizeUtilsCommon.js";import"../../../geometry/SpatialReference.js";import"../../../geometry/support/Ellipsoid.js";import"../../../core/pbf.js";import"../../../core/unitUtils.js";import"../../../geometry/ellipsoidUtils.js";import D from"../../../rest/support/Query.js";import{executeForIds as x}from"../../../rest/query/executeForIds.js";import{executeQueryJSON as j}from"../../../rest/query/executeQueryJSON.js";import"../../../geometry/support/aaBoundingBox.js";import"../../../core/mathUtils.js";import"../../../geometry/Extent.js";import"../../../rest/support/FeatureSet.js";import"../../../rest/support/RelationshipQuery.js";import"../../../rest/support/TopFeaturesQuery.js";import C from"../../../rest/support/StatisticDefinition.js";class P extends l{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,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 u}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}get urlQueryPath(){return this._layer.parsedUrl?.path||""}convertQueryToLruCacheKey(e){const t=this.urlQueryPath+","+d(e.toJSON());return _(t,g.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=p.StandardisedNoInterval,null!=e&&e>=10.61&&(this._databaseType=p.Standardised)):null!=e&&(e>=10.5&&(this._databaseType=p.StandardisedNoInterval,this._requestStandardised=!0),e>=10.61&&(this._databaseType=p.Standardised))}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);this._layer instanceof S?(this.subtypeField=this._layer.subtypeField??"",this.subtypes=this._layer.subtypes,this.types=null,this.typeIdField=null):(this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types,this.subtypeField=this._layer.subtypeField,this.subtypes=this._layer.subtypes)}_isInFeatureSet(){return h.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 D;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 F(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?j:"executeForCount"===t?I:x,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,s){const a=await this.databaseType();if(this.isTable()&&t&&null!==e&&""!==e){return new o([],[],!0,null)}if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,r,s);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 u=new D;this.datesInUnknownTimezone&&(u.timeReferenceUnknownClient=!0),u.where=null===i?null===t?"1=1":"":y(i,a),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==n?n.split(","):null,u.geometry=null===t?null:t,u.relationParameter=this._makeRelationshipParam(e);let d=await this.executeQuery(u,"executeForIds");null===d&&(d=[]),this._checkCancelled(s);return new o([],d,l,null)}_expandPagedSet(e,t,i,r,s){return this._expandPagedSetFeatureSet(e,t,i,r,s)}async _getFilteredSetUsingPaging(e,t,i,r,s){let a="",n=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(a=r.constructClause(),n=!0);const l=await this.databaseType();let u=null===i?null===t?"1=1":"":y(i,l);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=""!==u?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let d=this._maxQueryRate();const p=this._layer.capabilities?.query.maxRecordCount;null!=p&&p<d&&(d=p);let h=null;if(!0===this._pageJustIds)h=new o([],["GETPAGES"],n,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:d,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:a,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(["*"]);h=new o([],["GETPAGES"],n,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:r.join(","),resultRecordCount:d,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:a,returnGeometry:i,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(h,d,0,1,s),h}_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 D;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 l=0;for(let a=e._lastFetchedIndex;a<e._known.length;a++){if(e._lastFetchedIndex+=1,l++,void 0===this._featureCache[e._known[a]]){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[a]]){const r=t._featureMap[e._known[a]];null!==r&&(i=!0,this._featureCache[e._known[a]]=r)}}if(!1===i&&(e._known[a]!==t&&s.push(e._known[a]),s.length>=this._maxProcessingRate()-1))break}if(l>=i&&0===s.length)break}if(0===s.length)return"success";const o=new D;this._requestStandardised&&(o.sqlFormat="standard"),this.datesInUnknownTimezone&&(o.timeReferenceUnknownClient=!0),o.objectIds=s,o.outFields=this._overrideFields??this._fieldsIncludingObjectId(["*"]),o.returnGeometry=!0,!0===this._removeGeometry&&(o.returnGeometry=!1),o.outSpatialReference=this.spatialReference;const u=await this.executeQuery(o,"execute");if(this._checkCancelled(r),void 0!==u.error)throw new a(n.RequestFailed,{reason:u.error});const d=this._layer.objectIdField;for(let a=0;a<u.features.length;a++)this._featureCache[u.features[a].attributes[d]]=u.features[a];return"success"}async _getDistinctPages(e,t,i,r,s,l,o,u,d){await this._ensureLoaded();const p=await this.databaseType();let h=i.parseTree.column;const c=this._layer.fields??[];for(let a=0;a<c.length;a++)if(c[a].name.toLowerCase()===h.toLowerCase()){h=c[a].name;break}const f=new D;this._requestStandardised&&(f.sqlFormat="standard"),this.datesInUnknownTimezone&&(f.timeReferenceUnknownClient=!0);let m=null===l?null===s?"1=1":"":y(l,p);this._layer.definitionExpression&&this._useDefinitionExpression&&(m=""!==m?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression),f.where=m,f.spatialRelationship=this._makeRelationshipEnum(r),f.relationParameter=this._makeRelationshipParam(r),f.geometry=null===s?null:s,f.returnDistinctValues=!0,f.returnGeometry=!1,f.outFields=[h];const _=await this.executeQuery(f,"execute");if(this._checkCancelled(d),!_.hasOwnProperty("features"))throw new a(n.InvalidStatResponse);let g=!1;for(let a=0;a<c.length;a++)if(c[a].name===h){"date"===c[a].type&&(g=!0);break}for(let a=0;a<_.features.length;a++){if(g){const e=_.features[a].attributes[h];null!==e?u.push(new Date(e)):u.push(e)}else u.push(_.features[a].attributes[h]);if(u.length>=o)break}if(0===_.features.length)return u;if(_.features.length===this._layer.capabilities?.query.maxRecordCount&&u.length<o){return{calculated:!0,result:await this._getDistinctPages(e+_.features.length,t,i,r,s,l,o,u,d)}}return u}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 D;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":"":y(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,l,o){await this._ensureLoaded();const u=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression,d=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics,p=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsDistinct;if("count"===e)return p?this._countstat(e,i,r,s):{calculated:!1};if(!1===d||!1===f(t)&&!1===u||!1===t.isStandardized)return""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,l,o);if("distinct"===e)return!1===p?""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,l,o):this._distinctStat(e,t,i,r,s,l,o);const h=await this.databaseType();if(this.isTable()&&r&&null!==i&&""!==i)return{calculated:!0,result:null};const c=new D;this._requestStandardised&&(c.sqlFormat="standard");let _=null===s?null===r?"1=1":"":y(s,h);this._layer.definitionExpression&&this._useDefinitionExpression&&(_=""!==_?"(("+this._layer.definitionExpression+") AND ("+_+"))":this._layer.definitionExpression),c.where=_,c.spatialRelationship=this._makeRelationshipEnum(i),c.relationParameter=this._makeRelationshipParam(i),c.geometry=null===r?null:r,this.datesInUnknownTimezone&&(c.timeReferenceUnknownClient=!0);const g=new C;g.statisticType=m(e),g.onStatisticField=y(t,h),g.outStatisticFieldName="ARCADE_STAT_RESULT",c.returnGeometry=!1;let w="ARCADE_STAT_RESULT";c.outStatistics=[g];const R=await this.executeQuery(c,"execute");if(!R.hasOwnProperty("features")||0===R.features.length)throw new a(n.InvalidStatResponse);let b=!1;const S=R.fields??[];for(let a=0;a<S.length;a++)if("ARCADE_STAT_RESULT"===S[a].name.toUpperCase()){w=S[a].name,"date"===S[a].type&&(b=!0);break}if(b){let e=R.features[0].attributes[w];return null!==e&&(e=new Date(R.features[0].attributes[w])),{calculated:!0,result:e}}return{calculated:!0,result:R.features[0].attributes[w]}}_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===f(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,s,a,n){await this._ensureLoaded();const l=await this.databaseType();let u="",d=!1,p=!1;null!==a&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(u=a.constructClause(),p=!0),this._layer.capabilities&&this._layer.capabilities.query&&!1===this._layer.capabilities.query.supportsPagination&&(p=!1,d=!0,u=this._layer.objectIdField);const h=[];for(let o=0;o<t.length;o++){const e=new C;e.onStatisticField=null!==t[o].workingexpr?y(t[o].workingexpr,l):"",e.outStatisticFieldName=t[o].field,e.statisticType=t[o].toStatisticsName(),h.push(e)}""===u&&(u=e.join(","));let c=this._maxQueryRate();const f=this._layer.capabilities?.query.maxRecordCount;null!=f&&f<c&&(c=f);let m=null===s?null===r?"1=1":"":y(s,l);this._layer.definitionExpression&&this._useDefinitionExpression&&(m=""!==m?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression);return new o([],["GETPAGES"],p,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:d,generatedOid:n,resultRecordCount:c,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:h,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 l=t.pagesDefinition.internal.lastRetrieved,o=l,u=t.pagesDefinition.internal.lastPage,d=new D;if(this._requestStandardised&&(d.sqlFormat="standard"),d.where=s,d.spatialRelationship=t.pagesDefinition.spatialRel,d.relationParameter=t.pagesDefinition.relationParam,d.outFields=t.pagesDefinition.outFields,d.outStatistics=t.pagesDefinition.outStatistics,d.geometry=t.pagesDefinition.geometry,d.groupByFieldsForStatistics=t.pagesDefinition.groupByFieldsForStatistics,d.num=t.pagesDefinition.resultRecordCount,d.start=t.pagesDefinition.internal.lastPage,d.returnGeometry=t.pagesDefinition.returnGeometry,this.datesInUnknownTimezone&&(d.timeReferenceUnknownClient=!0),d.orderByFields=""!==t.pagesDefinition.orderByFields?t.pagesDefinition.orderByFields.split(","):null,this.isTable()&&d.geometry&&d.spatialRelationship)return[];const p=await this.executeQuery(d,"execute");if(this._checkCancelled(r),!p.hasOwnProperty("features"))throw new a(n.InvalidStatResponse);const h=[];if(t.pagesDefinition.internal.lastPage!==u)return[];p.features.length>0&&void 0===p.features[0].attributes[t.pagesDefinition.generatedOid]&&(t.pagesDefinition.generatedOid=t.pagesDefinition.generatedOid.toLowerCase());for(let e=0;e<p.features.length;e++)t.pagesDefinition.internal.set[o+e]=p.features[e].attributes[t.pagesDefinition.generatedOid];for(let a=0;a<p.features.length;a++)h.push(new e({attributes:p.features[a].attributes,geometry:null}));return!0===t.pagesDefinition.useOIDpagination?0===p.features.length?t.pagesDefinition.internal.fullyResolved=!0:t.pagesDefinition.internal.lastMaxId=p.features[p.features.length-1].attributes[t.pagesDefinition.generatedOid]:(void 0===p.exceededTransferLimit&&p.features.length!==t.pagesDefinition.resultRecordCount||!1===p.exceededTransferLimit)&&(t.pagesDefinition.internal.fullyResolved=!0),t.pagesDefinition.internal.lastRetrieved=l+p.features.length,t.pagesDefinition.internal.lastPage+=t.pagesDefinition.resultRecordCount,h}static create(e,t,i,r,s){const a=new b({url:e,outFields:null===t?["*"]:t});return new P({layer:a,spatialReference:i,lrucache:r,interceptor:s})}relationshipMetaData(){return this._layer&&this._layer.source&&this._layer.source.sourceJSON?.relationships?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return c(this._layer.parsedUrl.path)}async queryAttachments(e,t,i,a,n){const l=this._layer.capabilities;if(l?.data.supportsAttachment&&l?.operations.supportsQueryAttachments){const l={objectIds:[e],returnMetadata:n};(t&&t>0||i&&i>0)&&(l.size=[t&&t>0?t:0,i&&i>0?i:t+1]),a&&a.length>0&&(l.attachmentTypes=a),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:this._layer,query:l,method:"attachments"});const o=await this._layer.queryAttachments(l),u=[];return o&&o[e]&&o[e].forEach((t=>{const i=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+t.id.toString();let a=null;n&&t.exifInfo&&(a=s.convertJsonToArcade(t.exifInfo,"system",!0)),u.push(new r(t.id,t.name,t.contentType,t.size,i,a,t.keywords??null))})),u}return[]}async queryRelatedFeatures(t){const r={f:"json",relationshipId:t.relationshipId.toString(),definitionExpression:t.where,outFields:t.outFields?.join(","),returnGeometry:t.returnGeometry.toString()};void 0!==t.resultOffset&&null!==t.resultOffset&&(r.resultOffset=t.resultOffset.toString()),void 0!==t.resultRecordCount&&null!==t.resultRecordCount&&(r.resultRecordCount=t.resultRecordCount.toString()),t.orderByFields&&(r.orderByFields=t.orderByFields.join(",")),t.objectIds&&t.objectIds.length>0&&(r.objectIds=t.objectIds.join(",")),t.outSpatialReference&&(r.outSR=R(t.outSpatialReference)),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:r,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await i(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:r});if(s.data){const t={},i=s.data;if(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?w(t.geometry):null,attributes:t.attributes});n.push(i)}t[a]={features:n,exceededTransferLimit:!0===i.exceededTransferLimit}}}return t}throw new a(n.InvalidRequest)}async getFeatureByObjectId(e,t){const i=new D;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 j(this._layer.parsedUrl.path,i);return 1===r.features.length?r.features[0]:null}async getIdentityUser(){await this.load();const e=t?.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){await this.load();const e=t?.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let r=this._layer.url;const s=r?.toLowerCase().indexOf("/rest/services")??-1;if(r=s>-1?r?.substring(0,s):r,r){r+="/rest/info";try{const e=await i(r,{query:{f:"json"}});let t="";return e.data?.owningSystemUrl&&(t=e.data.owningSystemUrl),t}catch(a){return""}}return""}getDataSourceFeatureSet(){const e=new P({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 preferredTimeZone(){return this._layer.preferredTimeZone??null}get dateFieldsTimeZone(){return this._layer.dateFieldsTimeZone??null}get datesInUnknownTimezone(){return this._layer.datesInUnknownTimezone}get editFieldsInfo(){return this._layer.editFieldsInfo??null}get timeInfo(){return this._layer.timeInfo??null}async getFeatureSetInfo(){if(this.fsetInfo)return this.fsetInfo;let e=null,{parsedUrl:t,serviceItemId:r=null}=this._layer;if(t){const s=await i(t.path,{responseType:"json",query:{f:"json"}});e=s?.data?.name??null,r=s?.data?.serviceItemId??null}const s=this._layer.title&&null!==(this._layer.parent??null);return this.featureSetInfo={layerId:this._layer.layerId,layerName:""===e?null:e,itemId:""===r?null:r,serviceLayerUrl:t?.path||null,webMapLayerId:s?this._layer.id??null:null,webMapLayerTitle:s?this._layer.title??null:null,className:null,objectClassId:null},this.fsetInfo}}export{P as default};
|
|
5
|
+
import e from"../../../Graphic.js";import{id as t}from"../../../kernel.js";import i from"../../../request.js";import r from"../../Attachment.js";import s from"../../Dictionary.js";import{FeatureSetError as a,FeatureSetErrorCodes as n}from"../support/errorsupport.js";import l from"../support/FeatureSet.js";import o from"../support/IdSet.js";import{defaultMaxRecords as u,stableStringify as d,FeatureServiceDatabaseType as p,IdState as h,extractServiceUrl as c}from"../support/shared.js";import{toWhereClause as y,isSingleField as f}from"../support/sqlUtils.js";import{decodeStatType as m}from"../support/stats.js";import{createMD5Hash as _,outputTypes as g}from"../../../core/MD5.js";import{fromJSON as w}from"../../../geometry/support/jsonUtils.js";import{srToRESTValue as R}from"../../../geometry/support/spatialReferenceUtils.js";import b from"../../../layers/FeatureLayer.js";import{executeQuery as F}from"../../../rest/query/executeQuery.js";import"../../../config.js";import"../../../core/RandomLCG.js";import"../../../core/has.js";import"../../../core/urlUtils.js";import"../../../rest/query/support/AttachmentInfo.js";import S from"../../../rest/support/AttachmentQuery.js";import{executeForCount as I}from"../../../rest/query/executeForCount.js";import"../../../geometry.js";import"../../../core/Error.js";import"../../../core/Logger.js";import"../../../geometry/Polygon.js";import"../../../geometry/Polyline.js";import"../../../geometry/support/normalizeUtilsCommon.js";import"../../../geometry/SpatialReference.js";import"../../../geometry/support/Ellipsoid.js";import"../../../core/pbf.js";import"../../../core/unitUtils.js";import"../../../geometry/ellipsoidUtils.js";import D from"../../../rest/support/Query.js";import{executeForIds as x}from"../../../rest/query/executeForIds.js";import{executeQueryJSON as j}from"../../../rest/query/executeQueryJSON.js";import"../../../geometry/support/aaBoundingBox.js";import"../../../core/mathUtils.js";import"../../../geometry/Extent.js";import"../../../rest/support/FeatureSet.js";import"../../../rest/support/RelationshipQuery.js";import"../../../rest/support/TopFeaturesQuery.js";import C from"../../../rest/support/StatisticDefinition.js";class P extends l{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,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 u}end(){return this._layer}optimisePagingFeatureQueries(e){this._pageJustIds=e}get urlQueryPath(){return this._layer.parsedUrl.path||""}convertQueryToLruCacheKey(e){const t=this.urlQueryPath+","+d(e.toJSON());return _(t,g.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=p.StandardisedNoInterval,null!=e&&e>=10.61&&(this._databaseType=p.Standardised)):null!=e&&(e>=10.5&&(this._databaseType=p.StandardisedNoInterval,this._requestStandardised=!0),e>=10.61&&(this._databaseType=p.Standardised))}this.objectIdField=this._layer.objectIdField;for(const e of this.fields)"global-id"===e.type&&(this.globalIdField=e.name);"subtype-group"===this._layer.type?(this.subtypeField=this._layer.subtypeField??"",this.subtypes=this._layer.subtypes,this.types=null,this.typeIdField=null):"oriented-imagery"===this._layer.type?(this.subtypeField=null,this.subtypes=null,this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types):(this.subtypeField=this._layer.subtypeField,this.subtypes=this._layer.subtypes,this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types)}_isInFeatureSet(){return h.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 D;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 F(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?j:"executeForCount"===t?I:x,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,s){const a=await this.databaseType();if(this.isTable()&&t&&null!==e&&""!==e){return new o([],[],!0,null)}if(this._canUsePagination())return this._getFilteredSetUsingPaging(e,t,i,r,s);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 u=new D;this.datesInUnknownTimezone&&(u.timeReferenceUnknownClient=!0),u.where=null===i?null===t?"1=1":"":y(i,a),this._requestStandardised&&(u.sqlFormat="standard"),u.spatialRelationship=this._makeRelationshipEnum(e),u.outSpatialReference=this.spatialReference,u.orderByFields=""!==n?n.split(","):null,u.geometry=null===t?null:t,u.relationParameter=this._makeRelationshipParam(e);let d=await this.executeQuery(u,"executeForIds");null===d&&(d=[]),this._checkCancelled(s);return new o([],d,l,null)}_expandPagedSet(e,t,i,r,s){return this._expandPagedSetFeatureSet(e,t,i,r,s)}async _getFilteredSetUsingPaging(e,t,i,r,s){let a="",n=!1;null!==r&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(a=r.constructClause(),n=!0);const l=await this.databaseType();let u=null===i?null===t?"1=1":"":y(i,l);this._layer.definitionExpression&&this._useDefinitionExpression&&(u=""!==u?"(("+this._layer.definitionExpression+") AND ("+u+"))":this._layer.definitionExpression);let d=this._maxQueryRate();const p=this._layer.capabilities?.query.maxRecordCount;null!=p&&p<d&&(d=p);let h=null;if(!0===this._pageJustIds)h=new o([],["GETPAGES"],n,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:this._layer.objectIdField,resultRecordCount:d,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:a,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(["*"]);h=new o([],["GETPAGES"],n,{spatialRel:this._makeRelationshipEnum(e),relationParam:this._makeRelationshipParam(e),outFields:r.join(","),resultRecordCount:d,resultOffset:0,geometry:null===t?null:t,where:u,orderByFields:a,returnGeometry:i,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}})}return await this._expandPagedSet(h,d,0,1,s),h}_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 D;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 l=0;for(let a=e._lastFetchedIndex;a<e._known.length;a++){if(e._lastFetchedIndex+=1,l++,void 0===this._featureCache[e._known[a]]){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[a]]){const r=t._featureMap[e._known[a]];null!==r&&(i=!0,this._featureCache[e._known[a]]=r)}}if(!1===i&&(e._known[a]!==t&&s.push(e._known[a]),s.length>=this._maxProcessingRate()-1))break}if(l>=i&&0===s.length)break}if(0===s.length)return"success";const o=new D;this._requestStandardised&&(o.sqlFormat="standard"),this.datesInUnknownTimezone&&(o.timeReferenceUnknownClient=!0),o.objectIds=s,o.outFields=this._overrideFields??this._fieldsIncludingObjectId(["*"]),o.returnGeometry=!0,!0===this._removeGeometry&&(o.returnGeometry=!1),o.outSpatialReference=this.spatialReference;const u=await this.executeQuery(o,"execute");if(this._checkCancelled(r),void 0!==u.error)throw new a(n.RequestFailed,{reason:u.error});const d=this._layer.objectIdField;for(let a=0;a<u.features.length;a++)this._featureCache[u.features[a].attributes[d]]=u.features[a];return"success"}async _getDistinctPages(e,t,i,r,s,l,o,u,d){await this._ensureLoaded();const p=await this.databaseType();let h=i.parseTree.column;const c=this._layer.fields??[];for(let a=0;a<c.length;a++)if(c[a].name.toLowerCase()===h.toLowerCase()){h=c[a].name;break}const f=new D;this._requestStandardised&&(f.sqlFormat="standard"),this.datesInUnknownTimezone&&(f.timeReferenceUnknownClient=!0);let m=null===l?null===s?"1=1":"":y(l,p);this._layer.definitionExpression&&this._useDefinitionExpression&&(m=""!==m?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression),f.where=m,f.spatialRelationship=this._makeRelationshipEnum(r),f.relationParameter=this._makeRelationshipParam(r),f.geometry=null===s?null:s,f.returnDistinctValues=!0,f.returnGeometry=!1,f.outFields=[h];const _=await this.executeQuery(f,"execute");if(this._checkCancelled(d),!_.hasOwnProperty("features"))throw new a(n.InvalidStatResponse);let g=!1;for(let a=0;a<c.length;a++)if(c[a].name===h){"date"===c[a].type&&(g=!0);break}for(let a=0;a<_.features.length;a++){if(g){const e=_.features[a].attributes[h];null!==e?u.push(new Date(e)):u.push(e)}else u.push(_.features[a].attributes[h]);if(u.length>=o)break}if(0===_.features.length)return u;if(_.features.length===this._layer.capabilities?.query.maxRecordCount&&u.length<o){return{calculated:!0,result:await this._getDistinctPages(e+_.features.length,t,i,r,s,l,o,u,d)}}return u}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 D;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":"":y(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,l,o){await this._ensureLoaded();const u=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsSqlExpression,d=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsStatistics,p=this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsDistinct;if("count"===e)return p?this._countstat(e,i,r,s):{calculated:!1};if(!1===d||!1===f(t)&&!1===u||!1===t.isStandardized)return""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,l,o);if("distinct"===e)return!1===p?""!==i||null!==s?{calculated:!1}:this._manualStat(e,t,l,o):this._distinctStat(e,t,i,r,s,l,o);const h=await this.databaseType();if(this.isTable()&&r&&null!==i&&""!==i)return{calculated:!0,result:null};const c=new D;this._requestStandardised&&(c.sqlFormat="standard");let _=null===s?null===r?"1=1":"":y(s,h);this._layer.definitionExpression&&this._useDefinitionExpression&&(_=""!==_?"(("+this._layer.definitionExpression+") AND ("+_+"))":this._layer.definitionExpression),c.where=_,c.spatialRelationship=this._makeRelationshipEnum(i),c.relationParameter=this._makeRelationshipParam(i),c.geometry=null===r?null:r,this.datesInUnknownTimezone&&(c.timeReferenceUnknownClient=!0);const g=new C;g.statisticType=m(e),g.onStatisticField=y(t,h),g.outStatisticFieldName="ARCADE_STAT_RESULT",c.returnGeometry=!1;let w="ARCADE_STAT_RESULT";c.outStatistics=[g];const R=await this.executeQuery(c,"execute");if(!R.hasOwnProperty("features")||0===R.features.length)throw new a(n.InvalidStatResponse);let b=!1;const F=R.fields??[];for(let a=0;a<F.length;a++)if("ARCADE_STAT_RESULT"===F[a].name.toUpperCase()){w=F[a].name,"date"===F[a].type&&(b=!0);break}if(b){let e=R.features[0].attributes[w];return null!==e&&(e=new Date(R.features[0].attributes[w])),{calculated:!0,result:e}}return{calculated:!0,result:R.features[0].attributes[w]}}_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===f(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,s,a,n){await this._ensureLoaded();const l=await this.databaseType();let u="",d=!1,p=!1;null!==a&&this._layer.capabilities&&this._layer.capabilities.query&&!0===this._layer.capabilities.query.supportsOrderBy&&(u=a.constructClause(),p=!0),this._layer.capabilities&&this._layer.capabilities.query&&!1===this._layer.capabilities.query.supportsPagination&&(p=!1,d=!0,u=this._layer.objectIdField);const h=[];for(let o=0;o<t.length;o++){const e=new C;e.onStatisticField=null!==t[o].workingexpr?y(t[o].workingexpr,l):"",e.outStatisticFieldName=t[o].field,e.statisticType=t[o].toStatisticsName(),h.push(e)}""===u&&(u=e.join(","));let c=this._maxQueryRate();const f=this._layer.capabilities?.query.maxRecordCount;null!=f&&f<c&&(c=f);let m=null===s?null===r?"1=1":"":y(s,l);this._layer.definitionExpression&&this._useDefinitionExpression&&(m=""!==m?"(("+this._layer.definitionExpression+") AND ("+m+"))":this._layer.definitionExpression);return new o([],["GETPAGES"],p,{groupbypage:!0,spatialRel:this._makeRelationshipEnum(i),relationParam:this._makeRelationshipParam(i),outFields:["*"],useOIDpagination:d,generatedOid:n,resultRecordCount:c,resultOffset:0,groupByFieldsForStatistics:e,outStatistics:h,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 l=t.pagesDefinition.internal.lastRetrieved,o=l,u=t.pagesDefinition.internal.lastPage,d=new D;if(this._requestStandardised&&(d.sqlFormat="standard"),d.where=s,d.spatialRelationship=t.pagesDefinition.spatialRel,d.relationParameter=t.pagesDefinition.relationParam,d.outFields=t.pagesDefinition.outFields,d.outStatistics=t.pagesDefinition.outStatistics,d.geometry=t.pagesDefinition.geometry,d.groupByFieldsForStatistics=t.pagesDefinition.groupByFieldsForStatistics,d.num=t.pagesDefinition.resultRecordCount,d.start=t.pagesDefinition.internal.lastPage,d.returnGeometry=t.pagesDefinition.returnGeometry,this.datesInUnknownTimezone&&(d.timeReferenceUnknownClient=!0),d.orderByFields=""!==t.pagesDefinition.orderByFields?t.pagesDefinition.orderByFields.split(","):null,this.isTable()&&d.geometry&&d.spatialRelationship)return[];const p=await this.executeQuery(d,"execute");if(this._checkCancelled(r),!p.hasOwnProperty("features"))throw new a(n.InvalidStatResponse);const h=[];if(t.pagesDefinition.internal.lastPage!==u)return[];p.features.length>0&&void 0===p.features[0].attributes[t.pagesDefinition.generatedOid]&&(t.pagesDefinition.generatedOid=t.pagesDefinition.generatedOid.toLowerCase());for(let e=0;e<p.features.length;e++)t.pagesDefinition.internal.set[o+e]=p.features[e].attributes[t.pagesDefinition.generatedOid];for(let a=0;a<p.features.length;a++)h.push(new e({attributes:p.features[a].attributes,geometry:null}));return!0===t.pagesDefinition.useOIDpagination?0===p.features.length?t.pagesDefinition.internal.fullyResolved=!0:t.pagesDefinition.internal.lastMaxId=p.features[p.features.length-1].attributes[t.pagesDefinition.generatedOid]:(void 0===p.exceededTransferLimit&&p.features.length!==t.pagesDefinition.resultRecordCount||!1===p.exceededTransferLimit)&&(t.pagesDefinition.internal.fullyResolved=!0),t.pagesDefinition.internal.lastRetrieved=l+p.features.length,t.pagesDefinition.internal.lastPage+=t.pagesDefinition.resultRecordCount,h}static create(e,t,i,r,s){const a=new b({url:e,outFields:null===t?["*"]:t});return new P({layer:a,spatialReference:i,lrucache:r,interceptor:s})}relationshipMetaData(){return this._layer&&this._layer.source&&this._layer.source.sourceJSON?.relationships?this._layer.source.sourceJSON.relationships:[]}serviceUrl(){return c(this._layer.parsedUrl.path)}async queryAttachments(e,t,i,a,n){function l(e){const t=e.capabilities;return t?.data.supportsAttachment&&t?.operations.supportsQueryAttachments}const o=this._layer;if(l(o)){const l={objectIds:[e],returnMetadata:n};(t&&t>0||i&&i>0)&&(l.size=[t&&t>0?t:0,i&&i>0?i:t+1]),a&&a.length>0&&(l.attachmentTypes=a),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preLayerQueryCallback({layer:o,query:l,method:"attachments"});const u=await o.queryAttachments(new S(l)),d=[];return u&&u[e]&&u[e].forEach((t=>{const i=this._layer.parsedUrl.path+"/"+e.toString()+"/attachments/"+t.id.toString();let a=null;n&&t.exifInfo&&(a=s.convertJsonToArcade(t.exifInfo,"system",!0)),d.push(new r(t.id,t.name,t.contentType,t.size,i,a,t.keywords??null))})),d}return[]}async queryRelatedFeatures(t){const r={f:"json",relationshipId:t.relationshipId.toString(),definitionExpression:t.where,outFields:t.outFields?.join(","),returnGeometry:t.returnGeometry.toString()};void 0!==t.resultOffset&&null!==t.resultOffset&&(r.resultOffset=t.resultOffset.toString()),void 0!==t.resultRecordCount&&null!==t.resultRecordCount&&(r.resultRecordCount=t.resultRecordCount.toString()),t.orderByFields&&(r.orderByFields=t.orderByFields.join(",")),t.objectIds&&t.objectIds.length>0&&(r.objectIds=t.objectIds.join(",")),t.outSpatialReference&&(r.outSR=R(t.outSpatialReference)),this.featureSetQueryInterceptor&&this.featureSetQueryInterceptor.preRequestCallback({layer:this._layer,queryPayload:r,method:"relatedrecords",url:this._layer.parsedUrl.path+"/queryRelatedRecords"});const s=await i(this._layer.parsedUrl.path+"/queryRelatedRecords",{responseType:"json",query:r});if(s.data){const t={},i=s.data;if(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?w(t.geometry):null,attributes:t.attributes});n.push(i)}t[a]={features:n,exceededTransferLimit:!0===i.exceededTransferLimit}}}return t}throw new a(n.InvalidRequest)}async getFeatureByObjectId(e,t){const i=new D;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 j(this._layer.parsedUrl.path,i);return 1===r.features.length?r.features[0]:null}async getIdentityUser(){await this.load();const e=t?.findCredential(this._layer.url);return e?e.userId:null}async getOwningSystemUrl(){await this.load();const e=t?.findServerInfo(this._layer.url);if(e)return e.owningSystemUrl;let r=this._layer.url;const s=r.toLowerCase().indexOf("/rest/services");if(r=s>-1?r.substring(0,s):r,r){r+="/rest/info";try{const e=await i(r,{query:{f:"json"}});let t="";return e.data?.owningSystemUrl&&(t=e.data.owningSystemUrl),t}catch(a){return""}}return""}getDataSourceFeatureSet(){const e=new P({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 preferredTimeZone(){return this._layer.preferredTimeZone??null}get dateFieldsTimeZone(){return this._layer.dateFieldsTimeZone??null}get datesInUnknownTimezone(){return this._layer.datesInUnknownTimezone??!1}get editFieldsInfo(){return this._layer.editFieldsInfo??null}get timeInfo(){return this._layer.timeInfo??null}async getFeatureSetInfo(){if(this.fsetInfo)return this.fsetInfo;let e=null,t=this._layer.serviceItemId??null;const r=this._layer.parsedUrl.path;if(r){const s=await i(r,{responseType:"json",query:{f:"json"}});e=s?.data?.name??null,t=s?.data?.serviceItemId??null}const s=this._layer.title&&null!==(this._layer.parent??null);return this.featureSetInfo={layerId:this._layer.layerId,layerName:""===e?null:e,itemId:""===t?null:t,serviceLayerUrl:""===r?null:r,webMapLayerId:s?this._layer.id??null:null,webMapLayerTitle:s?this._layer.title??null:null,className:null,objectClassId:null},this.fsetInfo}}export{P as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as s}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{defaultMaxRecords as a,FeatureServiceDatabaseType as l,IdState as n}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 y from"../../../layers/
|
|
5
|
+
import e from"../../../Graphic.js";import{FeatureSetError as t,FeatureSetErrorCodes as s}from"../support/errorsupport.js";import r from"../support/FeatureSet.js";import i from"../support/IdSet.js";import{defaultMaxRecords as a,FeatureServiceDatabaseType as l,IdState as n}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 y from"../../../layers/support/FeatureType.js";import p from"../../../layers/support/Field.js";import c from"../../../rest/support/Query.js";class d extends r{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 s of this.fields)if("oid"===s.type)e.push(s),t.push(s.name);else for(const r of this._overrideFields)if(r.toLowerCase()===s.name.toLowerCase()){e.push(s),t.push(s.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=l.Standardised,this.hasZ=!0===this._layer?.capabilities?.data?.supportsZ,this.hasM=!0===this._layer?.capabilities?.data?.supportsM,"subtype-group"===this._layer.type?(this.subtypeField=this._layer.subtypeField??"",this.subtypes=this._layer.subtypes,this.types=null,this.typeIdField=null):"oriented-imagery"===this._layer.type?(this.subtypeField=null,this.subtypes=null,this.typeIdField=this._layer.typeIdField??"",this.types=this._layer.types):(this.subtypeField=this._layer.subtypeField,this.subtypes=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 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 s={};for(const e of this.fields)s[e.name]=t.attributes[e.name];return new e({geometry:!0===this._removeGeometry?null:t.geometry,attributes:s})}async _getFilteredSet(e,t,s,r,a){let n="",u=!1;if(null!==r&&(n=r.constructClause(),u=!0),this.isTable()&&t&&null!==e&&""!==e){return new i([],[],!0,null)}const h=new c;h.returnZ=this.hasZ,h.returnM=this.hasM,h.where=null===s?null===t?"1=1":"":o(s,l.Standardised),h.spatialRelationship=this._makeRelationshipEnum(e),h.outSpatialReference=this.spatialReference,h.orderByFields=""!==n?n.split(","):null,h.geometry=null===t?null:t,h.returnGeometry=!0,h.relationParameter=this._makeRelationshipParam(e);const y=await this._layer.queryFeatures(h);if(null===y)return new i([],[],u,null);this._checkCancelled(a);const p=[];y.features.forEach((e=>{const t=e.attributes[this._layer.objectIdField];p.push(t),this._featureCache[t]=this._changeFeature(e)}));return new i([],p,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 c;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 s=t.attributes[this._layer.objectIdField];e.push(s),this._featureCache[s]=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),s=[];return t.features.forEach((e=>{const t=e.attributes[this._layer.objectIdField];s.push(t),this._featureCache[t]=this._changeFeature(e)})),this._wset=new i([],s,!1,null),this._wset}async _getFeatures(e,r,i){const a=[];-1!==r&&void 0===this._featureCache[r]&&a.push(r);for(let t=e._lastFetchedIndex;t<e._known.length&&(e._lastFetchedIndex+=1,!(void 0===this._featureCache[e._known[t]]&&(e._known[t]!==r&&a.push(e._known[t]),a.length>i)));t++);if(0===a.length)return"success";throw new t(s.MissingFeatures)}async _refineSetBlock(e){return e}async _stat(){return{calculated:!1}}async _canDoAggregates(){return!1}relationshipMetaData(){return[]}static _cloneAttr(e){const t={};for(const s in e)t[s]=e[s];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 s=e.layerDefinition.objectIdField;const r=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 l=e.featureSet.features;const n=t.toJSON();if(!s){let t=!1;for(const r of e.layerDefinition.fields)if("oid"===r.type||"esriFieldTypeOID"===r.type){s=r.name,t=!0;break}if(!1===t){let t="FID",r=!0,i=0;for(;r;){let s=!0;for(const r of e.layerDefinition.fields)if(r.name===t){s=!1;break}!0===s?r=!1:(i++,t="FID"+i.toString())}e.layerDefinition.fields.push({type:"esriFieldTypeOID",name:t,alias:t});const a=[];for(let s=0;s<l.length;s++)a.push({geometry:e.featureSet.features[s].geometry,attributes:e.featureSet.features[s].attributes?this._cloneAttr(e.featureSet.features[s].attributes):{}}),a[s].attributes[t]=s;l=a,s=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 l)h.geometry&&h.geometry instanceof u==!1&&(h.geometry.type=c,void 0===h.geometry.spatialReference&&(h.geometry.spatialReference=n));else for(const u of l)u.geometry&&(u.geometry=null);const f={outFields:["*"],source:l,fields:o,hasZ:!0===e?.layerDefinition?.hasZ||!0===e?.featureSet?.hasZ,hasM:!0===e?.layerDefinition?.hasM||!0===e?.featureSet?.hasM,types:i,typeIdField:r,objectIdField:s,spatialReference:t},_="esriGeometryNull"===c||null===c;_||(f.geometryType=c);const m=new h(f);e?.layerDefinition?.subtypeField&&e?.layerDefinition?.subtypes&&m.read({subtypes:e.layerDefinition.subtypes,subtypeField:e.layerDefinition.subtypeField});return new d({layer:m,spatialReference:t,isTable:_})}async queryAttachments(){return[]}async getFeatureByObjectId(e){const t=new c;t.where=this.objectIdField+"="+e.toString(),t.returnZ=this.hasZ,t.returnM=this.hasM;const s=await this._layer.queryFeatures(t);return 1===s.features.length?s.features[0]:null}async getOwningSystemUrl(){return""}async getIdentityUser(){return""}get preferredTimeZone(){return this._layer.preferredTimeZone??null}get dateFieldsTimeZone(){return this._layer.dateFieldsTimeZone??null}get datesInUnknownTimezone(){return this._layer.datesInUnknownTimezone??!1}get editFieldsInfo(){return this._layer.editFieldsInfo}get timeInfo(){return this._layer?.timeInfo}async getFeatureSetInfo(){const e=this._layer.title&&this._layer.parent;return this.fsetInfo??{layerId:null,layerName:null,itemId:null,serviceLayerUrl:null,webMapLayerId:e?this._layer.id??null:null,webMapLayerTitle:e?this._layer.title??null:null,className:null,objectClassId: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.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../../ArcadeDate.js";import{DateOnly as r}from"../../../core/sql/DateOnly.js";import{TimeOnly as
|
|
5
|
+
import{ArcadeDate as e}from"../../ArcadeDate.js";import{DateOnly as r}from"../../../core/sql/DateOnly.js";import{TimeOnly as t}from"../../../core/sql/TimeOnly.js";import i from"../../../geometry/Extent.js";import n from"../../../layers/support/Field.js";import{DateTime as o}from"luxon";var l,s;function y(e){return n.fromJSON(e.toJSON())}function u(e){return e.toJSON?e.toJSON():e}function p(e){return"string"==typeof e||e instanceof String}function a(e){return"boolean"==typeof e}function c(e){return"number"==typeof e}function m(e){return Array.isArray(e)}function f(e){return e instanceof Date}function d(e){return e instanceof o}function T(r){return r instanceof e}function g(e){return e instanceof r}function F(e){return e instanceof t}function G(e,r){return e===r||!(!f(e)&&!T(e)||!f(r)&&!T(r))&&e.getTime()===r.getTime()}function S(e){const r={};for(const t in e)r[t]=e[t];return r}function O(e){if(null==e)return null;if("number"==typeof e)return e;switch(e.toLowerCase()){case"meters":case"meter":return 109404;case"miles":case"mile":return 109439;case"kilometers":case"kilometer":case"km":return 109414}return null}function b(e){if(null==e)return null;switch(e.type){case"polygon":case"multipoint":case"polyline":return e.extent;case"point":return new i({xmin:e.x,ymin:e.y,xmax:e.x,ymax:e.y,spatialReference:e.spatialReference});case"extent":return e}return null}function v(e){if(null==e)return null;if("number"==typeof e)return e;if("number"==typeof e)return e;switch(e.toLowerCase()){case"meters":case"meter":return 9001;case"miles":case"mile":return 9093;case"kilometers":case"kilometer":case"km":return 9036}return null}function I(e,r){return e===r||("point"===e&&"esriGeometryPoint"===r||("polyline"===e&&"esriGeometryPolyline"===r||("polygon"===e&&"esriGeometryPolygon"===r||("extent"===e&&"esriGeometryEnvelope"===r||("multipoint"===e&&"esriGeometryMultipoint"===r||("point"===r&&"esriGeometryPoint"===e||("polyline"===r&&"esriGeometryPolyline"===e||("polygon"===r&&"esriGeometryPolygon"===e||("extent"===r&&"esriGeometryEnvelope"===e||"multipoint"===r&&"esriGeometryMultipoint"===e)))))))))}!function(e){e[e.Standardised=0]="Standardised",e[e.StandardisedNoInterval=1]="StandardisedNoInterval",e[e.SqlServer=2]="SqlServer",e[e.Oracle=3]="Oracle",e[e.Postgres=4]="Postgres",e[e.PGDB=5]="PGDB",e[e.FILEGDB=6]="FILEGDB",e[e.NotEvaluated=7]="NotEvaluated"}(l||(l={})),function(e){e[e.InFeatureSet=0]="InFeatureSet",e[e.NotInFeatureSet=1]="NotInFeatureSet",e[e.Unknown=2]="Unknown"}(s||(s={}));const D=1e3;function P(e){return function(r){e.reject(r)}}function x(e,r){return function(){try{e.apply(null,arguments)}catch(t){r.reject(t)}}}const N={point:"point",polygon:"polygon",polyline:"polyline",multipoint:"multipoint",extent:"extent",esriGeometryPoint:"point",esriGeometryPolygon:"polygon",esriGeometryPolyline:"polyline",esriGeometryMultipoint:"multipoint",esriGeometryEnvelope:"extent",envelope:"extent"},w={point:"esriGeometryPoint",polygon:"esriGeometryPolygon",polyline:"esriGeometryPolyline",multipoint:"esriGeometryMultipoint",extent:"esriGeometryEnvelope",esriGeometryPoint:"esriGeometryPoint",esriGeometryPolygon:"esriGeometryPolygon",esriGeometryPolyline:"esriGeometryPolyline",esriGeometryMultipoint:"esriGeometryMultipoint",esriGeometryEnvelope:"esriGeometryEnvelope",envelope:"esriGeometryEnvelope"},E={"small-integer":"esriFieldTypeSmallInteger",integer:"esriFieldTypeInteger",long:"esriFieldTypeLong",single:"esriFieldTypeSingle",double:"esriFieldTypeDouble",string:"esriFieldTypeString",date:"esriFieldTypeDate","date-only":"esriFieldTypeDateOnly","time-only":"esriFieldTypeTimeOnly","timestamp-offset":"esriFieldTypeTimestampOffset",oid:"esriFieldTypeOID",geometry:"esriFieldTypeGeometry",blob:"esriFieldTypeBlob",raster:"esriFieldTypeRaster",guid:"esriFieldTypeGUID","global-id":"esriFieldTypeGlobalID",xml:"esriFieldTypeXML","big-integer":"esriFieldTypeBigInteger",esriFieldTypeSmallInteger:"esriFieldTypeSmallInteger",esriFieldTypeInteger:"esriFieldTypeInteger",esriFieldTypeLong:"esriFieldTypeLong",esriFieldTypeSingle:"esriFieldTypeSingle",esriFieldTypeDouble:"esriFieldTypeDouble",esriFieldTypeString:"esriFieldTypeString",esriFieldTypeDate:"esriFieldTypeDate",esriFieldTypeDateOnly:"esriFieldTypeDateOnly",esriFieldTypeTimeOnly:"esriFieldTypeTimeOnly",esriFieldTypeTimestampOffset:"esriFieldTypeTimestampOffset",esriFieldTypeOID:"esriFieldTypeOID",esriFieldTypeGeometry:"esriFieldTypeGeometry",esriFieldTypeBlob:"esriFieldTypeBlob",esriFieldTypeRaster:"esriFieldTypeRaster",esriFieldTypeGUID:"esriFieldTypeGUID",esriFieldTypeGlobalID:"esriFieldTypeGlobalID",esriFieldTypeXML:"esriFieldTypeXML",esriFieldTypeBigInteger:"esriFieldTypeBigInteger"};function h(e){switch(e){case"point":default:return"esriGeometryPoint";case"polygon":return"esriGeometryPolygon";case"multipoint":return"esriGeometryMultipoint";case"polyline":return"esriGeometryPolyline"}}function k(e){return void 0===e?"":e=(e=(e=e.replace(/\/featureserver\/[0-9]*/i,"/FeatureServer")).replace(/\/mapserver\/[0-9]*/i,"/MapServer")).split("?")[0]}function J(e,r){r||(r={}),"function"==typeof r&&(r={cmp:r});const t="boolean"==typeof r.cycles&&r.cycles,i=r.cmp&&(n=r.cmp,function(e){return function(r,t){const i={key:r,value:e[r]},o={key:t,value:e[t]};return n(i,o)}});var n;const o=[];return function e(r){if(r?.toJSON&&"function"==typeof r.toJSON&&(r=r.toJSON()),void 0===r)return;if("number"==typeof r)return isFinite(r)?""+r:"null";if("object"!=typeof r)return JSON.stringify(r);let n,l;if(Array.isArray(r)){for(l="[",n=0;n<r.length;n++)n&&(l+=","),l+=e(r[n])||"null";return l+"]"}if(null===r)return"null";if(o.includes(r)){if(t)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const s=o.push(r)-1,y=Object.keys(r).sort(i?.(r));for(l="",n=0;n<y.length;n++){const t=y[n],i=e(r[t]);i&&(l&&(l+=","),l+=JSON.stringify(t)+":"+i)}return o.splice(s,1),"{"+l+"}"}(e)}function M(e){switch(e.type){case"catalog":case"feature":case"oriented-imagery":case"subtype-group":return!0;default:return!1}}function B(e){switch(e.type){case"catalog-footprint":case"subtype-sublayer":return!0;default:return M(e)}}export{l as FeatureServiceDatabaseType,s as IdState,x as callback,S as cloneAttributes,y as cloneField,v as convertLinearUnitsToCode,O as convertSquareUnitsToCode,D as defaultMaxRecords,G as equalityTest,P as errback,u as esriFieldToJson,k as extractServiceUrl,T as isArcadeDate,g as isArcadeDateOnly,F as isArcadeTime,m as isArray,a as isBoolean,f as isDate,d as isLuxonDate,c as isNumber,p as isString,B as isSupportedLayer,M as isSupportedSourceLayer,E as layerFieldEsriConstants,N as layerGeometryEsriConstants,w as layerGeometryEsriRestConstants,I as sameGeomType,b as shapeExtent,J as stableStringify,h as toEsriGeometryType};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i}from"../executionError.js";import r from"../Feature.js";import s from"../featureSetCollection.js";import{convertToFeatureSet as o,constructFeatureSetFromPortalItem as l,constructFeatureSet as f,constructFeatureSetFromRelationship as u,constructFeatureSetFromUrl as c,constructAssociationMetaDataFeatureSetFromUrl as d}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{H as p,n as y,m as w,u as h,c as g,j as F,l as I,N as D,k as T,K as b,h as E,o as A,r as N,q as x,i as S,g as L,a2 as C,T as $,O as v}from"../../chunks/languageUtils.js";import{getPortal as P}from"../portalUtils.js";import{SqlExpressionAdapted as j,StringToCodeAdapted as U,FieldRename as Z,AdaptedFeatureSet as M,OriginalField as R}from"../featureset/actions/Adapted.js";import k from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import z from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as _}from"../featureset/support/shared.js";import{isSingleField as K}from"../featureset/support/sqlUtils.js";import{calculateStat as q}from"./fieldStats.js";import{isPromiseLike as B}from"../../core/promiseUtils.js";import{WhereClause as V}from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";function X(e){if(1===e.length){if(A(e[0]))return q("distinct",e[0],-1);if(x(e[0]))return q("distinct",e[0].toArray(),-1)}return q("distinct",e,-1)}async function ee(e,t,n){const a=e.getVariables();if(a.length>0){const i=[];for(let e=0;e<a.length;e++){const r={name:a[e]};i.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<a.length;e++)r[a[e]]=i[e];return e.parameters=r,e}return e}function te(e,t,n=null){for(const a in e)if(a.toLowerCase()===t.toLowerCase())return e[a];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ae(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const a=te(e,"wkid");return null!==a&&(t.wkid=a),t}function ie(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference");null!=n&&(t.spatialReference=ae(n));const a=te(e,"x",null);if(null!==a)return t.x=a,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const i=te(e,"rings",null);if(null!==i)return t.rings=i,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==A(e.layerDefinition.fields)&&!1!==A(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(q){"async"===q.mode&&(q.functions.timezone=function(t,r){return q.standardFunctionAsync(t,r,(async(s,o,l)=>{if(p(l,1,2,t,r),y(l[0]))return"Unknown";if(w(l[0]))return"Unknown";if(h(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new a(t,i.InvalidParameter,r);const e=l[1].field("type");if(!1===g(e))throw new a(t,i.InvalidParameter,r);switch(F(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&g(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(F(l[1].field("fieldname"))))}throw new a(t,i.InvalidParameter,r)}const f=I(l[0],D(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:"utc"===u.toLowerCase()?"UTC":"unknown"===u.toLowerCase()?"Unknown":u}))},q.functions.sqltimestamp=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,1,3,e,t);const o=s[0];if(T(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(F(s[1])).toSQLWithKeyword();throw new a(e,i.InvalidParameter,t)}if(w(o))return o.toSQLWithKeyword();if(h(o)){if(3!==s.length)throw new a(e,i.InvalidParameter,t);await o.load();const n=F(s[1]);if(w(s[2]))return s[2].toSQLWithKeyword();if(!1===T(s[2]))throw new a(e,i.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"sqltimestamp",min:2,max:4}),q.functions.featuresetbyid=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetById(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyid",min:2,max:4}),q.functions.getfeatureset=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,1,2,e,t),N(s[0])){let t=b(s[1],"datasource");return null===t&&(t="datasource"),t=F(t).toLowerCase(),o(s[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference??null)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"getfeatureset",min:1,max:2}),q.functions.featuresetbyportalitem=function(e,n){return q.standardFunctionAsync(e,n,((r,s,o)=>{if(p(o,2,5,e,n),null===o[0])throw new a(e,i.PortalRequired,n);if(o[0]instanceof t){const t=F(o[1]),r=F(o[2]);let s=b(o[3],null);const f=E(b(o[4],!0));if(null===s&&(s=["*"]),!1===A(s))throw new a(e,i.InvalidParameter,n);let u;return u=e.services?.portal?e.services.portal:Y.getDefault(),u=P(o[0],u),l(t,r,e.spatialReference??null,s,f,u,e.lrucache,e.interceptor)}if(!1===g(o[0]))throw new a(e,i.PortalRequired,n);const f=F(o[0]),u=F(o[1]);let c=b(o[2],null);const d=E(b(o[3],!0));if(null===c&&(c=["*"]),!1===A(c))throw new a(e,i.InvalidParameter,n);return l(f,u,e.spatialReference??null,c,d,e.services?.portal??Y.getDefault(),e.lrucache,e.interceptor)}))},q.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),q.functions.featuresetbyname=function(e,t){return q.standardFunctionAsync(e,t,((n,r,o)=>{if(p(o,2,4,e,t),o[0]instanceof s){const n=F(o[1]);let r=b(o[2],null);const s=E(b(o[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return o[0].featureSetByName(n,s,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyname",min:2,max:4}),q.functions.featureset=function(e,t){return q.standardFunction(e,t,((r,s,o)=>{p(o,1,1,e,t);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(g(o[0])){const e=JSON.parse(o[0]);void 0!==e.layerDefinition?(l.layerDefinition=e.layerDefinition,l.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(l.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(l.featureSet.features=e.features,l.featureSet.geometryType=e.geometryType,l.layerDefinition.geometryType=l.featureSet.geometryType,l.layerDefinition.objectIdField=e.objectIdFieldName??"",l.layerDefinition.typeIdField=e.typeIdFieldName,l.layerDefinition.globalIdField=e.globalIdFieldName,l.layerDefinition.fields=e.fields,e.spatialReference&&(l.layerDefinition.spatialReference=e.spatialReference))}else{if(!(o[0]instanceof n))throw new a(e,i.InvalidParameter,t);{const n=JSON.parse(o[0].castToText(!0)),r=te(n,"layerdefinition");if(null!==r){l.layerDefinition.geometryType=te(r,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=te(r,"globalidfield",""),l.layerDefinition.objectIdField=te(r,"objectidfield",""),l.layerDefinition.typeIdField=te(r,"typeidfield",""),l.layerDefinition.hasZ=!0===te(r,"hasz",!1),l.layerDefinition.hasM=!0===te(r,"hasm",!1);const e=te(r,"spatialreference");e&&(l.layerDefinition.spatialReference=ae(e));const t=[];for(const n of te(r,"fields",[])){const e={name:te(n,"name",""),alias:te(n,"alias",""),type:te(n,"type",""),nullable:te(n,"nullable",!0),editable:te(n,"editable",!0),length:te(n,"length",null),domain:ne(te(n,"domain"))};t.push(e)}l.layerDefinition.fields=t;const a=te(n,"featureset");if(a){const e={};for(const n of t)e[n.name.toLowerCase()]=n.name;for(const t of te(a,"features",[])){const n={},a=te(t,"attributes",{});for(const t in a)n[e[t.toLowerCase()]]=a[t];l.featureSet.features.push({attributes:n,geometry:ie(te(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===te(n,"hasz",!1),l.layerDefinition.hasM=!0===te(n,"hasm",!1),l.layerDefinition.geometryType=te(n,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=te(n,"objectidfieldname",""),l.layerDefinition.typeIdField=te(n,"typeidfieldname","");const r=te(n,"spatialreference");r&&(l.layerDefinition.spatialReference=ae(r));const s=[],o=te(n,"fields",null);if(!A(o))throw new a(e,i.InvalidParameter,t);for(const e of o){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};s.push(t)}l.layerDefinition.fields=s;const f={};for(const e of s)f[e.name.toLowerCase()]=e.name;let u=te(n,"features",null);if(A(u))for(const e of u){const t={},n=te(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ie(te(e,"geometry",null))})}else u=null,l.featureSet.features=u}}}if(!1===se(l))throw new a(e,i.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),W.create(l,e.spatialReference)}))},q.signatures.push({name:"featureset",min:1,max:1}),q.functions.filter=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),A(s[0])||x(s[0])){const n=[];let r,o=s[0];if(o instanceof m&&(o=o.toArray()),!S(s[1]))throw new a(e,i.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);B(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(h(s[0])){const t=await s[0].load(),n=V.create(s[1],t.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC),a=n.getVariables();if(a.length>0){const t=[];for(let n=0;n<a.length;n++){const i={name:a[n]};t.push(await q.evaluateIdentifier(e,i))}const i={};for(let e=0;e<a.length;e++)i[a[e]]=t[e];return n.parameters=i,new k({parentfeatureset:s[0],whereclause:n})}return new k({parentfeatureset:s[0],whereclause:n})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filter",min:2,max:2}),q.functions.orderby=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"orderby",min:2,max:2}),q.functions.top=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0]))return new z({parentfeatureset:s[0],topnum:s[1]});if(A(s[0]))return L(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,L(s[1]));if(x(s[0]))return L(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,L(s[1]));throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"top",min:2,max:2}),q.functions.first=function(e,t){return q.standardFunctionAsync(e,t,(async(n,a,i)=>{if(p(i,1,1,e,t),h(i[0])){const t=await i[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,i[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return A(i[0])?0===i[0].length?null:i[0][0]:x(i[0])?0===i[0].length()?null:i[0].get(0):null}))},q.signatures.push({name:"first",min:1,max:1}),q.functions.attachments=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{p(o,1,2,e,t);const l={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(l.minsize=L(o[1].field("minsize"))),o[1].hasField("metadata")&&(l.returnMetadata=E(o[1].field("metadata"))),o[1].hasField("maxsize")&&(l.maxsize=L(o[1].field("maxsize"))),o[1].hasField("types")){const e=C(o[1].field("types"),!1);e.length>0&&(l.types=e)}}else if(null!==o[1])throw new a(e,i.InvalidParameter,t);if(N(o[0])){let t=o[0]._layer;return t instanceof Q&&(t=f(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===h(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),l.minsize,l.maxsize,l.types,l.returnMetadata))}if(null===o[0])return[];throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"attachments",min:1,max:2}),q.functions.featuresetbyrelationshipname=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,4,e,t);const o=s[0],l=F(s[1]);let d=b(s[2],null);const m=E(b(s[3],!0));if(null===d&&(d=["*"]),!1===A(d))throw new a(e,i.InvalidParameter,t);if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let y=o._layer;if(y instanceof Q&&(y=f(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===h(y))return null;y=await y.load();const w=y.relationshipMetaData().filter((e=>e.name===l));if(0===w.length)return null;if(void 0!==w[0].relationshipTableId&&null!==w[0].relationshipTableId&&w[0].relationshipTableId>-1)return u(y,w[0],o.field(y.objectIdField),y.spatialReference,d,m,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+w[0].relatedTableId.toString():g+"/"+w[0].relatedTableId.toString();const I=await c(g,y.spatialReference,d,m,e.lrucache,e.interceptor);await I.load();let D=I.relationshipMetaData();if(D=D.filter((e=>e.id===w[0].id)),!1===o.hasField(w[0].keyField)||null===o.field(w[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[w[0].keyField]);if(e){const t=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return t.parameters={id:e.attributes[w[0].keyField]},I.filter(t)}return new H({parentfeatureset:I})}const T=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return T.parameters={id:o.field(w[0].keyField)},I.filter(T)}))},q.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),q.functions.featuresetbyassociation=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{p(s,2,3,e,t);const o=s[0],l=F(b(s[1],"")).toLowerCase(),u=g(s[2])?F(s[2]):null;if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let c=o._layer;if(c instanceof Q&&(c=f(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===h(c))return null;await c.load();const m=c.serviceUrl(),y=await d(m,e.spatialReference);let w=null,I=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of y.terminals)e.terminalName===u&&(I=e.terminalId);null===I&&(D=!0)}const T=y.associations.getFieldsIndex(),E=T.get("TOGLOBALID").name,A=T.get("FROMGLOBALID").name,x=T.get("TOTERMINALID").name,S=T.get("FROMTERMINALID").name,L=T.get("FROMNETWORKSOURCEID").name,C=T.get("TONETWORKSOURCEID").name,v=T.get("ASSOCIATIONTYPE").name,P=T.get("ISCONTENTVISIBLE").name,k=T.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){w=o.field(e.name);break}let O=null,z=new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create("''",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));const W="globalid",G="globalId",K={};for(const e in y.lkp)K[e]=y.lkp[e].sourceId;const q=new U(new J({name:"classname",alias:"classname",type:"string"}),null,K);let B="";switch(l){case"midspan":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (5))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),z=y.unVersion>=4?new R(M.findField(y.associations.fields,T.get("PERCENTALONG").name)):new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"junctionedge":{B=`((${E}='${w}') OR ( ${A}='${w}')) AND (${v} IN (4,6))`,q.codefield=V.create(`CASE WHEN (${E}='${w}') THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${w}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create(`CASE WHEN (${v}=4) THEN 'from' ELSE 'to' END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==I&&(e+=` AND ${x}=@A`,t+=` AND ${S}=@A`),B="(("+e+") OR ("+t+"))",B=$(B,"@T",w??""),e=$(e,"@T",w??""),null!==I&&(e=$(e,"@A",I.toString()),B=$(B,"@A",I.toString())),q.codefield=V.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const n=_(M.findField(y.associations.fields,A));n.name=W,n.alias=W,O=new j(n,V.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"container":B=`${E}='${w}' AND ${v} = 2`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,W);break;case"content":B=`(${A}='${w}' AND ${v} = 2)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,W);break;case"structure":B=`(${E}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=L,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,G);break;case"attached":B=`(${A}='${w}' AND ${v} = 3)`,null!==I&&(B+=` AND ${S} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,G);break;default:throw new a(e,i.InvalidParameter,t)}D&&(B="1 <> 1");return new M({parentfeatureset:y.associations,adaptedFields:[new R(M.findField(y.associations.fields,k)),new R(M.findField(y.associations.fields,P)),O,H,q,z],extraFilter:B?V.create(B,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC):null})}))},q.signatures.push({name:"featuresetbyassociation",min:2,max:6}),q.functions.groupby=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(p(o,3,3,e,t),!h(o[0]))throw new a(e,i.InvalidParameter,t);const l=await o[0].load(),f=[],u=[];let c=!1,d=[];if(g(o[1]))d.push(o[1]);else if(o[1]instanceof n)d.push(o[1]);else if(A(o[1]))d=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);d=o[1].toArray()}for(const m of d)if(g(m)){const e=V.create(F(m),l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(c=!0)}else{if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(c=!0),!n)throw new a(e,i.InvalidParameter,t);f.push({name:n,expression:V.create(r||n,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(d=[],g(o[2]))d.push(o[2]);else if(A(o[2]))d=o[2];else if(x(o[2]))d=o[2].toArray();else{if(!(o[2]instanceof n))throw new a(e,i.InvalidParameter,t);d.push(o[2])}for(const m of d){if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new a(e,i.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:V.create(s,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(c){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of u)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)await ee(t.expression,q,e);for(const t of u)await ee(t.expression,q,e);return o[0].groupby(f,u)}))},q.signatures.push({name:"groupby",min:3,max:3}),q.functions.distinct=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(h(o[0])){p(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(g(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(A(o[1]))l=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(g(o)){const e=V.create(F(o),r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?F(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new a(e,i.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new a(e,i.InvalidParameter,t);s.push({name:n,expression:V.create(l||n,r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC)})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await ee(t.expression,q,e);return o[0].groupby(s,[])}return X(o)}))},q.functions.getfeaturesetinfo=function(e,t){return q.standardFunctionAsync(e,t,(async(a,i,r)=>{if(p(r,1,1,e,t),!h(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},D(e),!1,!1):null}))},q.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),q.functions.filterbysubtypecode=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(p(s,2,2,e,t),h(s[0])){const n=await s[0].load(),r=s[1];if(!v(r))throw new a(e,i.InvalidParameter,t);if(n.subtypeField){const e=V.create(`${n.subtypeField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new a(e,i.FeatureSetDoesNotHaveSubtypes,t);const o=V.create(`${n.typeIdField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:o})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le as registerFunctions};
|
|
5
|
+
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as i}from"../executionError.js";import r from"../Feature.js";import{convertToFeatureSet as s,constructFeatureSetFromPortalItem as o,constructFeatureSet as l,constructFeatureSetFromRelationship as f,constructFeatureSetFromUrl as u,constructAssociationMetaDataFeatureSetFromUrl as d}from"../featureSetUtils.js";import c from"../ImmutableArray.js";import{H as m,n as p,m as y,u as w,c as h,j as g,l as F,N as I,k as D,s as T,K as b,h as E,o as A,r as N,q as x,i as L,g as S,a1 as C,T as $,O as v}from"../../chunks/languageUtils.js";import{getPortal as P}from"../portalUtils.js";import{SqlExpressionAdapted as j,StringToCodeAdapted as U,FieldRename as Z,AdaptedFeatureSet as M,OriginalField as R}from"../featureset/actions/Adapted.js";import k from"../featureset/actions/AttributeFilter.js";import O from"../featureset/actions/OrderBy.js";import z from"../featureset/actions/Top.js";import H from"../featureset/sources/Empty.js";import W from"../featureset/sources/FeatureLayerMemory.js";import G from"../featureset/support/OrderbyClause.js";import{cloneField as _}from"../featureset/support/shared.js";import{isSingleField as K}from"../featureset/support/sqlUtils.js";import{calculateStat as q}from"./fieldStats.js";import{isPromiseLike as B}from"../../core/promiseUtils.js";import{WhereClause as V}from"../../core/sql/WhereClause.js";import Q from"../../layers/FeatureLayer.js";import J from"../../layers/support/Field.js";import Y from"../../portal/Portal.js";function X(e){if(1===e.length){if(A(e[0]))return q("distinct",e[0],-1);if(x(e[0]))return q("distinct",e[0].toArray(),-1)}return q("distinct",e,-1)}async function ee(e,t,n){const a=e.getVariables();if(a.length>0){const i=[];for(let e=0;e<a.length;e++){const r={name:a[e]};i.push(await t.evaluateIdentifier(n,r))}const r={};for(let e=0;e<a.length;e++)r[a[e]]=i[e];return e.parameters=r,e}return e}function te(e,t,n=null){for(const a in e)if(a.toLowerCase()===t.toLowerCase())return e[a];return n}function ne(e){if(null===e)return null;const t={type:te(e,"type",""),name:te(e,"name","")};if("range"===t.type)t.range=te(e,"range",[]);else{t.codedValues=[];for(const n of te(e,"codedValues",[]))t.codedValues.push({name:te(n,"name",""),code:te(n,"code",null)})}return t}function ae(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const a=te(e,"wkid");return null!==a&&(t.wkid=a),t}function ie(e){if(null===e)return null;const t={hasZ:te(e,"hasz",!1),hasM:te(e,"hasm",!1)},n=te(e,"spatialreference");null!=n&&(t.spatialReference=ae(n));const a=te(e,"x",null);if(null!==a)return t.x=a,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const i=te(e,"rings",null);if(null!==i)return t.rings=i,t;const r=te(e,"paths",null);if(null!==r)return t.paths=r,t;const s=te(e,"points",null);if(null!==s)return t.points=s,t;for(const o of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=te(e,o,null);null!==n&&(t[o]=n)}return t}function re(e,t){for(const n of t)if(n===e)return!0;return!1}function se(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==re(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==A(e.layerDefinition.fields)&&!1!==A(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(q){"async"===q.mode&&(q.functions.timezone=function(t,r){return q.standardFunctionAsync(t,r,(async(s,o,l)=>{if(m(l,1,2,t,r),p(l[0]))return"Unknown";if(y(l[0]))return"Unknown";if(w(l[0])){if(await l[0].load(),1===l.length||null===l[1])return l[0].datesInUnknownTimezone?oe("unknown"):oe(l[0].dateFieldsTimeZone);if(!(l[1]instanceof n)||!1===l[1].hasField("type"))throw new a(t,i.InvalidParameter,r);const e=l[1].field("type");if(!1===h(e))throw new a(t,i.InvalidParameter,r);switch(g(e).toLowerCase()){case"preferredtimezone":return oe(l[0].preferredTimeZone);case"editfieldsinfo":return oe(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return oe(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&h(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(g(l[1].field("fieldname"))))}throw new a(t,i.InvalidParameter,r)}const f=F(l[0],I(t));if(null===f)return null;const u=f.timeZone;return"system"===u?e.systemTimeZoneCanonicalName:"utc"===u.toLowerCase()?"UTC":"unknown"===u.toLowerCase()?"Unknown":u}))},q.functions.sqltimestamp=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,1,3,e,t);const o=s[0];if(D(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(g(s[1])).toSQLWithKeyword();throw new a(e,i.InvalidParameter,t)}if(y(o))return o.toSQLWithKeyword();if(w(o)){if(3!==s.length)throw new a(e,i.InvalidParameter,t);await o.load();const n=g(s[1]);if(y(s[2]))return s[2].toSQLWithKeyword();if(!1===D(s[2]))throw new a(e,i.InvalidParameter,t);const r=o.fieldTimeZone(n);return null===r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"sqltimestamp",min:2,max:4}),q.functions.featuresetbyid=function(e,t){return q.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),T(s[0])){const n=g(s[1]);let r=b(s[2],null);const o=E(b(s[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return s[0].featureSetById(n,o,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyid",min:2,max:4}),q.functions.getfeatureset=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,o)=>{if(m(o,1,2,e,t),N(o[0])){let t=b(o[1],"datasource");return null===t&&(t="datasource"),t=g(t).toLowerCase(),s(o[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference??null)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"getfeatureset",min:1,max:2}),q.functions.featuresetbyportalitem=function(e,n){return q.standardFunctionAsync(e,n,((r,s,l)=>{if(m(l,2,5,e,n),null===l[0])throw new a(e,i.PortalRequired,n);if(l[0]instanceof t){const t=g(l[1]),r=g(l[2]);let s=b(l[3],null);const f=E(b(l[4],!0));if(null===s&&(s=["*"]),!1===A(s))throw new a(e,i.InvalidParameter,n);let u;return u=e.services?.portal?e.services.portal:Y.getDefault(),u=P(l[0],u),o(t,r,e.spatialReference??null,s,f,u,e.lrucache,e.interceptor)}if(!1===h(l[0]))throw new a(e,i.PortalRequired,n);const f=g(l[0]),u=g(l[1]);let d=b(l[2],null);const c=E(b(l[3],!0));if(null===d&&(d=["*"]),!1===A(d))throw new a(e,i.InvalidParameter,n);return o(f,u,e.spatialReference??null,d,c,e.services?.portal??Y.getDefault(),e.lrucache,e.interceptor)}))},q.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),q.functions.featuresetbyname=function(e,t){return q.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),T(s[0])){const n=g(s[1]);let r=b(s[2],null);const o=E(b(s[3],!0));if(null===r&&(r=["*"]),!1===A(r))throw new a(e,i.InvalidParameter,t);return s[0].featureSetByName(n,o,r)}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"featuresetbyname",min:2,max:4}),q.functions.featureset=function(e,t){return q.standardFunction(e,t,((r,s,o)=>{m(o,1,1,e,t);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(h(o[0])){const e=JSON.parse(o[0]);void 0!==e.layerDefinition?(l.layerDefinition=e.layerDefinition,l.featureSet=e.featureSet,e.layerDefinition.spatialReference&&(l.layerDefinition.spatialReference=e.layerDefinition.spatialReference)):(l.featureSet.features=e.features,l.featureSet.geometryType=e.geometryType,l.layerDefinition.geometryType=l.featureSet.geometryType,l.layerDefinition.objectIdField=e.objectIdFieldName??"",l.layerDefinition.typeIdField=e.typeIdFieldName,l.layerDefinition.globalIdField=e.globalIdFieldName,l.layerDefinition.fields=e.fields,e.spatialReference&&(l.layerDefinition.spatialReference=e.spatialReference))}else{if(!(o[0]instanceof n))throw new a(e,i.InvalidParameter,t);{const n=JSON.parse(o[0].castToText(!0)),r=te(n,"layerdefinition");if(null!==r){l.layerDefinition.geometryType=te(r,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=te(r,"globalidfield",""),l.layerDefinition.objectIdField=te(r,"objectidfield",""),l.layerDefinition.typeIdField=te(r,"typeidfield",""),l.layerDefinition.hasZ=!0===te(r,"hasz",!1),l.layerDefinition.hasM=!0===te(r,"hasm",!1);const e=te(r,"spatialreference");e&&(l.layerDefinition.spatialReference=ae(e));const t=[];for(const n of te(r,"fields",[])){const e={name:te(n,"name",""),alias:te(n,"alias",""),type:te(n,"type",""),nullable:te(n,"nullable",!0),editable:te(n,"editable",!0),length:te(n,"length",null),domain:ne(te(n,"domain"))};t.push(e)}l.layerDefinition.fields=t;const a=te(n,"featureset");if(a){const e={};for(const n of t)e[n.name.toLowerCase()]=n.name;for(const t of te(a,"features",[])){const n={},a=te(t,"attributes",{});for(const t in a)n[e[t.toLowerCase()]]=a[t];l.featureSet.features.push({attributes:n,geometry:ie(te(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===te(n,"hasz",!1),l.layerDefinition.hasM=!0===te(n,"hasm",!1),l.layerDefinition.geometryType=te(n,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=te(n,"objectidfieldname",""),l.layerDefinition.typeIdField=te(n,"typeidfieldname","");const r=te(n,"spatialreference");r&&(l.layerDefinition.spatialReference=ae(r));const s=[],o=te(n,"fields",null);if(!A(o))throw new a(e,i.InvalidParameter,t);for(const e of o){const t={name:te(e,"name",""),alias:te(e,"alias",""),type:te(e,"type",""),nullable:te(e,"nullable",!0),editable:te(e,"editable",!0),length:te(e,"length",null),domain:ne(te(e,"domain"))};s.push(t)}l.layerDefinition.fields=s;const f={};for(const e of s)f[e.name.toLowerCase()]=e.name;let u=te(n,"features",null);if(A(u))for(const e of u){const t={},n=te(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ie(te(e,"geometry",null))})}else u=null,l.featureSet.features=u}}}if(!1===se(l))throw new a(e,i.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),W.create(l,e.spatialReference)}))},q.signatures.push({name:"featureset",min:1,max:1}),q.functions.filter=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),A(s[0])||x(s[0])){const n=[];let r,o=s[0];if(o instanceof c&&(o=o.toArray()),!L(s[1]))throw new a(e,i.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);B(t)?!0===await t&&n.push(e):!0===t&&n.push(e)}return n}if(w(s[0])){const t=await s[0].load(),n=V.create(s[1],t.getFieldsIndex(),t.dateFieldsTimeZoneDefaultUTC),a=n.getVariables();if(a.length>0){const t=[];for(let n=0;n<a.length;n++){const i={name:a[n]};t.push(await q.evaluateIdentifier(e,i))}const i={};for(let e=0;e<a.length;e++)i[a[e]]=t[e];return n.parameters=i,new k({parentfeatureset:s[0],whereclause:n})}return new k({parentfeatureset:s[0],whereclause:n})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filter",min:2,max:2}),q.functions.orderby=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const e=new G(s[1]);return new O({parentfeatureset:s[0],orderbyclause:e})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"orderby",min:2,max:2}),q.functions.top=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0]))return new z({parentfeatureset:s[0],topnum:s[1]});if(A(s[0]))return S(s[1])>=s[0].length?s[0].slice(0):s[0].slice(0,S(s[1]));if(x(s[0]))return S(s[1])>=s[0].length()?s[0].slice(0):s[0].slice(0,S(s[1]));throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"top",min:2,max:2}),q.functions.first=function(e,t){return q.standardFunctionAsync(e,t,(async(n,a,i)=>{if(m(i,1,1,e,t),w(i[0])){const t=await i[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,i[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return A(i[0])?0===i[0].length?null:i[0][0]:x(i[0])?0===i[0].length()?null:i[0].get(0):null}))},q.signatures.push({name:"first",min:1,max:1}),q.functions.attachments=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{m(o,1,2,e,t);const f={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(o.length>1)if(o[1]instanceof n){if(o[1].hasField("minsize")&&(f.minsize=S(o[1].field("minsize"))),o[1].hasField("metadata")&&(f.returnMetadata=E(o[1].field("metadata"))),o[1].hasField("maxsize")&&(f.maxsize=S(o[1].field("maxsize"))),o[1].hasField("types")){const e=C(o[1].field("types"),!1);e.length>0&&(f.types=e)}}else if(null!==o[1])throw new a(e,i.InvalidParameter,t);if(N(o[0])){let t=o[0]._layer;return t instanceof Q&&(t=l(t,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===t?[]:!1===w(t)?[]:(await t.load(),t.queryAttachments(o[0].field(t.objectIdField),f.minsize,f.maxsize,f.types,f.returnMetadata))}if(null===o[0])return[];throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"attachments",min:1,max:2}),q.functions.featuresetbyrelationshipname=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,4,e,t);const o=s[0],d=g(s[1]);let c=b(s[2],null);const p=E(b(s[3],!0));if(null===c&&(c=["*"]),!1===A(c))throw new a(e,i.InvalidParameter,t);if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let y=o._layer;if(y instanceof Q&&(y=l(y,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===y)return null;if(!1===w(y))return null;y=await y.load();const h=y.relationshipMetaData().filter((e=>e.name===d));if(0===h.length)return null;if(void 0!==h[0].relationshipTableId&&null!==h[0].relationshipTableId&&h[0].relationshipTableId>-1)return f(y,h[0],o.field(y.objectIdField),y.spatialReference,c,p,e.lrucache,e.interceptor);let F=y.serviceUrl();if(!F)return null;F="/"===F.charAt(F.length-1)?F+h[0].relatedTableId.toString():F+"/"+h[0].relatedTableId.toString();const I=await u(F,y.spatialReference,c,p,e.lrucache,e.interceptor);await I.load();let D=I.relationshipMetaData();if(D=D.filter((e=>e.id===h[0].id)),!1===o.hasField(h[0].keyField)||null===o.field(h[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[h[0].keyField]);if(e){const t=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return t.parameters={id:e.attributes[h[0].keyField]},I.filter(t)}return new H({parentfeatureset:I})}const T=V.create(D[0].keyField+"= @id",I.getFieldsIndex(),I.dateFieldsTimeZoneDefaultUTC);return T.parameters={id:o.field(h[0].keyField)},I.filter(T)}))},q.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),q.functions.featuresetbyassociation=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,3,e,t);const o=s[0],f=g(b(s[1],"")).toLowerCase(),u=h(s[2])?g(s[2]):null;if(null===s[0])return null;if(!N(s[0]))throw new a(e,i.InvalidParameter,t);let c=o._layer;if(c instanceof Q&&(c=l(c,e.spatialReference,["*"],!0,e.lrucache,e.interceptor)),null===c)return null;if(!1===w(c))return null;await c.load();const p=c.serviceUrl(),y=await d(p,e.spatialReference);let F=null,I=null,D=!1;if(null!==u&&""!==u&&void 0!==u){for(const e of y.terminals)e.terminalName===u&&(I=e.terminalId);null===I&&(D=!0)}const T=y.associations.getFieldsIndex(),E=T.get("TOGLOBALID").name,A=T.get("FROMGLOBALID").name,x=T.get("TOTERMINALID").name,L=T.get("FROMTERMINALID").name,S=T.get("FROMNETWORKSOURCEID").name,C=T.get("TONETWORKSOURCEID").name,v=T.get("ASSOCIATIONTYPE").name,P=T.get("ISCONTENTVISIBLE").name,k=T.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){F=o.field(e.name);break}let O=null,z=new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create("''",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));const W="globalid",G="globalId",K={};for(const e in y.lkp)K[e]=y.lkp[e].sourceId;const q=new U(new J({name:"classname",alias:"classname",type:"string"}),null,K);let B="";switch(f){case"midspan":{B=`((${E}='${F}') OR ( ${A}='${F}')) AND (${v} IN (5))`,q.codefield=V.create(`CASE WHEN (${E}='${F}') THEN ${S} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${F}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),z=y.unVersion>=4?new R(M.findField(y.associations.fields,T.get("PERCENTALONG").name)):new j(new J({name:"percentalong",alias:"percentalong",type:"double"}),V.create("0",y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"junctionedge":{B=`((${E}='${F}') OR ( ${A}='${F}')) AND (${v} IN (4,6))`,q.codefield=V.create(`CASE WHEN (${E}='${F}') THEN ${S} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const e=_(M.findField(y.associations.fields,A));e.name=W,e.alias=W,O=new j(e,V.create(`CASE WHEN (${A}='${F}') THEN ${E} ELSE ${A} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC)),H=new j(new J({name:"side",alias:"side",type:"string"}),V.create(`CASE WHEN (${v}=4) THEN 'from' ELSE 'to' END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"connected":{let e=`${E}='@T'`,t=`${A}='@T'`;null!==I&&(e+=` AND ${x}=@A`,t+=` AND ${L}=@A`),B="(("+e+") OR ("+t+"))",B=$(B,"@T",F??""),e=$(e,"@T",F??""),null!==I&&(e=$(e,"@A",I.toString()),B=$(B,"@A",I.toString())),q.codefield=V.create("CASE WHEN "+e+` THEN ${S} ELSE ${C} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC);const n=_(M.findField(y.associations.fields,A));n.name=W,n.alias=W,O=new j(n,V.create("CASE WHEN "+e+` THEN ${A} ELSE ${E} END`,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC));break}case"container":B=`${E}='${F}' AND ${v} = 2`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=S,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,W);break;case"content":B=`(${A}='${F}' AND ${v} = 2)`,null!==I&&(B+=` AND ${L} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,W);break;case"structure":B=`(${E}='${F}' AND ${v} = 3)`,null!==I&&(B+=` AND ${x} = `+I.toString()),q.codefield=S,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,A),W,G);break;case"attached":B=`(${A}='${F}' AND ${v} = 3)`,null!==I&&(B+=` AND ${L} = `+I.toString()),q.codefield=C,B="( "+B+" )",O=new Z(M.findField(y.associations.fields,E),W,G);break;default:throw new a(e,i.InvalidParameter,t)}D&&(B="1 <> 1");return new M({parentfeatureset:y.associations,adaptedFields:[new R(M.findField(y.associations.fields,k)),new R(M.findField(y.associations.fields,P)),O,H,q,z],extraFilter:B?V.create(B,y.associations.getFieldsIndex(),y.associations.dateFieldsTimeZoneDefaultUTC):null})}))},q.signatures.push({name:"featuresetbyassociation",min:2,max:6}),q.functions.groupby=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(m(o,3,3,e,t),!w(o[0]))throw new a(e,i.InvalidParameter,t);const l=await o[0].load(),f=[],u=[];let d=!1,c=[];if(h(o[1]))c.push(o[1]);else if(o[1]instanceof n)c.push(o[1]);else if(A(o[1]))c=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);c=o[1].toArray()}for(const m of c)if(h(m)){const e=V.create(g(m),l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?g(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(d=!0)}else{if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(d=!0),!n)throw new a(e,i.InvalidParameter,t);f.push({name:n,expression:V.create(r||n,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(c=[],h(o[2]))c.push(o[2]);else if(A(o[2]))c=o[2];else if(x(o[2]))c=o[2].toArray();else{if(!(o[2]instanceof n))throw new a(e,i.InvalidParameter,t);c.push(o[2])}for(const m of c){if(!(m instanceof n))throw new a(e,i.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new a(e,i.InvalidParameter,t);u.push({name:n,statistic:r.toLowerCase(),expression:V.create(s,l.getFieldsIndex(),l.dateFieldsTimeZoneDefaultUTC)})}}if(d){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of u)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)await ee(t.expression,q,e);for(const t of u)await ee(t.expression,q,e);return o[0].groupby(f,u)}))},q.signatures.push({name:"groupby",min:3,max:3}),q.functions.distinct=function(e,t){return q.standardFunctionAsync(e,t,(async(r,s,o)=>{if(w(o[0])){m(o,2,2,e,t);const r=await o[0].load(),s=[];let l=[];if(h(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(A(o[1]))l=o[1];else{if(!x(o[1]))throw new a(e,i.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(h(o)){const e=V.create(g(o),r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC),t=!0===K(e)?g(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new a(e,i.InvalidParameter,t);{const n=o.hasField("name")?o.field("name"):"%%%%FIELDNAME",l=o.hasField("expression")?o.field("expression"):"";if("%%%%FIELDNAME"===n&&(f=!0),!n)throw new a(e,i.InvalidParameter,t);s.push({name:n,expression:V.create(l||n,r.getFieldsIndex(),r.dateFieldsTimeZoneDefaultUTC)})}}if(f){const e={};for(const n of r.fields)e[n.name.toLowerCase()]=1;for(const n of s)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of s)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of s)await ee(t.expression,q,e);return o[0].groupby(s,[])}return X(o)}))},q.functions.getfeaturesetinfo=function(e,t){return q.standardFunctionAsync(e,t,(async(a,i,r)=>{if(m(r,1,1,e,t),!w(r[0]))return null;const s=await r[0].getFeatureSetInfo();return s?n.convertObjectToArcadeDictionary({layerId:s.layerId,layerName:s.layerName,itemId:s.itemId,serviceLayerUrl:s.serviceLayerUrl,webMapLayerId:s.webMapLayerId??null,webMapLayerTitle:s.webMapLayerTitle??null,className:null,objectClassId:null},I(e),!1,!1):null}))},q.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),q.functions.filterbysubtypecode=function(e,t){return q.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const n=await s[0].load(),r=s[1];if(!v(r))throw new a(e,i.InvalidParameter,t);if(n.subtypeField){const e=V.create(`${n.subtypeField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new a(e,i.FeatureSetDoesNotHaveSubtypes,t);const o=V.create(`${n.typeIdField}= ${s[1]}`,n.getFieldsIndex(),n.dateFieldsTimeZoneDefaultUTC);return new k({parentfeatureset:s[0],whereclause:o})}throw new a(e,i.InvalidParameter,t)}))},q.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le as registerFunctions};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.30/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as e}from"../executionError.js";import{H as t,r,W as o,j as i,u as c,
|
|
5
|
+
import n from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as e}from"../executionError.js";import{H as t,r,W as o,j as i,u as c,a2 as s,V as d,N as u,X as m,a3 as f,Y as l,a4 as y,K as v,t as w,U as p}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as h}from"../featureset/support/shared.js";function T(a,e){return a&&a.domain?"coded-value"===a.domain.type||"codedValue"===a.domain.type?n.convertObjectToArcadeDictionary({type:"codedValue",name:a.domain.name,dataType:h[a.field.type],codedValues:a.domain.codedValues.map((n=>({name:n.name,code:n.code})))},u(e)):n.convertObjectToArcadeDictionary({type:"range",name:a.domain.name,dataType:h[a.field.type],min:a.domain.minValue,max:a.domain.maxValue},u(e)):null}function b(h){"async"===h.mode&&(h.functions.domain=function(n,d){return h.standardFunctionAsync(n,d,(async(u,m,f)=>{if(t(f,2,3,n,d),r(f[0])){return T(o(f[0],i(f[1]),void 0===f[2]?void 0:f[2]),n)}if(c(f[0])){await f[0]._ensureLoaded();return T(s(i(f[1]),f[0],null,void 0===f[2]?void 0:f[2]),n)}throw new a(n,e.InvalidParameter,d)}))},h.functions.subtypes=function(o,i){return h.standardFunctionAsync(o,i,(async(s,m,f)=>{if(t(f,1,1,o,i),r(f[0])){const a=d(f[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}if(c(f[0])){await f[0]._ensureLoaded();const a=f[0].subtypeMetaData();return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))},h.functions.domainname=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,l)=>{if(t(l,2,4,n,o),r(l[0]))return m(l[0],i(l[1]),l[2],void 0===l[3]?void 0:l[3]);if(c(l[0])){await l[0]._ensureLoaded();const n=s(i(l[1]),l[0],null,void 0===l[3]?void 0:l[3]);return f(n,l[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domainname",min:2,max:4}),h.functions.domaincode=function(n,o){return h.standardFunctionAsync(n,o,(async(d,u,m)=>{if(t(m,2,4,n,o),r(m[0]))return l(m[0],i(m[1]),m[2],void 0===m[3]?void 0:m[3]);if(c(m[0])){await m[0]._ensureLoaded();const n=s(i(m[1]),m[0],null,void 0===m[3]?void 0:m[3]);return y(n,m[2])}throw new a(n,e.InvalidParameter,o)}))},h.signatures.push({name:"domaincode",min:2,max:4}),h.functions.text=function(n,r){return h.standardFunctionAsync(n,r,(async(o,i,s)=>{if(t(s,1,2,n,r),c(s[0])){const t=v(s[1],"");if(""===t)return s[0].castToText();if("schema"===t.toLowerCase())return s[0].convertToText("schema",o.abortSignal);if("featureset"===t.toLowerCase())return s[0].convertToText("featureset",o.abortSignal);throw new a(n,e.InvalidParameter,r)}return w(s[0],s[1])}))},h.functions.gdbversion=function(n,o){return h.standardFunctionAsync(n,o,(async(i,s,d)=>{if(t(d,1,1,n,o),r(d[0]))return d[0].gdbVersion();if(c(d[0])){return(await d[0].load()).gdbVersion}throw new a(n,e.InvalidParameter,o)}))},h.functions.schema=function(o,i){return h.standardFunctionAsync(o,i,(async(s,d,m)=>{if(t(m,1,1,o,i),c(m[0]))return await m[0].load(),n.convertObjectToArcadeDictionary(m[0].schema(),u(o));if(r(m[0])){const a=p(m[0]);return a?n.convertObjectToArcadeDictionary(a,u(o)):null}throw new a(o,e.InvalidParameter,i)}))})}export{b as registerFunctions};
|