@arcgis/core 4.33.0-next.20250220 → 4.33.0-next.20250221
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/functions/featuresetbase.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/4f764b952c6463fc7c88.js +1 -0
- package/assets/esri/core/workers/chunks/63d8d507f073a8ed42d2.js +1 -0
- package/assets/esri/core/workers/chunks/70574e0e3de729187d98.js +1 -0
- package/assets/esri/core/workers/chunks/78c066e8fe167d4ab817.js +1 -0
- package/assets/esri/core/workers/chunks/875a200f215e472d147e.js +1 -0
- package/assets/esri/core/workers/chunks/{f976233ad5e5b718ba83.js → 8d1f49927738ad3601d2.js} +1 -1
- package/assets/esri/core/workers/chunks/9050dad7e4f093568026.js +1 -0
- package/assets/esri/core/workers/chunks/930544d3b2c1d9c035c7.js +1 -0
- package/assets/esri/core/workers/chunks/{962cad03be1b7aa52ebe.js → 95835a62712fe4f24205.js} +1 -1
- package/assets/esri/core/workers/chunks/{030384851fa745908a6e.js → 9dbdb88cdac993104740.js} +2 -2
- package/assets/esri/core/workers/chunks/{ac11b2168feee63d2f09.js → b7c6d0ff4c085c8d0596.js} +1 -1
- package/assets/esri/core/workers/chunks/e0cd4815149d1ff4d31e.js +1 -0
- package/assets/esri/core/workers/chunks/{0a82c13828ffd4780419.js → f51fc2370fb486233499.js} +1 -1
- package/assets/esri/core/workers/chunks/fcbe65256a71b34ac9cf.js +1 -0
- package/assets/esri/themes/base/widgets/_Editor.scss +4 -0
- package/assets/esri/themes/dark/main.css +1 -1
- package/assets/esri/themes/light/main.css +1 -1
- package/assets/esri/themes/light/view.css +1 -1
- package/chunks/ColorMaterial.glsl.js +1 -1
- package/chunks/DefaultMaterial.glsl.js +1 -1
- package/chunks/ImageMaterial.glsl.js +3 -3
- package/chunks/LineMarker.glsl.js +11 -11
- package/chunks/NativeLine.glsl.js +1 -1
- package/chunks/Path.glsl.js +11 -11
- package/chunks/Pattern.glsl.js +2 -2
- package/chunks/RealisticTree.glsl.js +1 -1
- package/chunks/RibbonLine.glsl.js +1 -1
- package/chunks/Terrain.glsl.js +1 -1
- package/chunks/WaterSurface.glsl.js +9 -9
- package/editing/sharedTemplates/SharedTemplate.js +1 -1
- package/editing/sharedTemplates/SharedTemplateMetadata.js +1 -1
- package/editing/sharedTemplates/SharedTemplateProvider.js +1 -1
- package/editing/sharedTemplates/executor/support/createServiceEdit.js +1 -1
- package/editing/sharedTemplates/support/sharedTemplateErrors.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/FeatureTemplateDefinition.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/GroupTemplateDefinition.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/PresetTemplateDefinition.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/TemplateDefinitionBase.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/parts/FeatureTemplateRelationshipPart.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/parts/GroupTemplatePart.js +1 -1
- package/editing/sharedTemplates/templateDefinitions/parts/TemplatePartBase.js +1 -1
- package/interfaces.d.ts +112 -22
- package/layers/ImageryLayer.js +1 -1
- package/layers/ImageryTileLayer.js +1 -1
- package/layers/WCSLayer.js +1 -1
- package/layers/mixins/ArcGISImageService.js +1 -1
- package/layers/mixins/ImageryTileMixin.js +1 -1
- package/layers/mixins/RasterJobHandlerMixin.js +5 -0
- package/layers/orientedImagery/transformations/utils.js +1 -1
- package/layers/orientedImagery/transformations/worldToImage.js +1 -1
- package/layers/support/Relationship.js +1 -1
- package/package.json +1 -1
- package/support/revision.js +1 -1
- package/undoredo/support/Services.js +1 -1
- package/views/2d/AnimationManager.js +1 -1
- package/views/2d/layers/imagery/VectorFieldTileView2D.js +1 -1
- package/views/2d/layers/imagery/VectorFieldView2D.js +1 -1
- package/views/View.js +1 -1
- package/views/animation/easing.js +1 -1
- package/views/webgl/ShaderBuilder.js +1 -1
- package/widgets/Editor/CreateFeaturesWorkflow.js +1 -1
- package/widgets/Editor/components/Prompt.js +1 -1
- package/widgets/Editor/workflowUtils.js +1 -1
- package/widgets/Editor.js +1 -1
- package/widgets/OrientedImageryViewer/OrientedImageryViewerViewModel.js +1 -1
- package/widgets/OrientedImageryViewer/symbols.js +1 -1
- package/widgets/OrientedImageryViewer.js +1 -1
- package/widgets/support/FilterCondition.js +1 -1
- package/widgets/support/GoTo.js +1 -1
- package/widgets/support/goToUtils.js +1 -1
- package/assets/esri/core/workers/chunks/0c85731e9bf3eaeb96a2.js +0 -1
- package/assets/esri/core/workers/chunks/1b36d4400ab841c978c8.js +0 -1
- package/assets/esri/core/workers/chunks/3c44b4bf7fe407ec1d70.js +0 -1
- package/assets/esri/core/workers/chunks/4e3e141b3fd8bb652798.js +0 -1
- package/assets/esri/core/workers/chunks/717d7e9912d948e44d8d.js +0 -1
- package/assets/esri/core/workers/chunks/7bf9ebff90bb02bec8e7.js +0 -1
- package/assets/esri/core/workers/chunks/905cf2bb280479cd4f80.js +0 -1
- package/assets/esri/core/workers/chunks/b8fae500c69ca2cff62a.js +0 -1
- package/assets/esri/core/workers/chunks/b90b7ffc1e9363ed18e0.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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../request.js";import t from"./featureSetCollection.js";import{p as a,_ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import l from"./featureset/actions/OrderBy.js";import s 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 w}from"./featureset/support/shared.js";import _ from"../core/Loadable.js";import L from"../core/sql/WhereClause.js";import I from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import g from"../portal/PortalItem.js";function C(){null===f.applicationCache&&(f.applicationCache=new f)}async function F(e,t,a){if(f.applicationCache){const a=f.applicationCache.getLayerInfo(e);if(a){const r=await a;return new I({url:e,outFields:t,sourceJSON:r})}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(r){throw f.applicationCache.clearLayerInfo(e),r}}return await i,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new I({url:e,outFields:t,sourceJSON:a})}const i=new I({url:e,outFields:t}),l=(async()=>(await i.load(),i.sourceJSON))();a.setCachedLayerMetadata(e,l);try{return await l,i}catch(n){throw a.removeCachedLayerMetadata(e,l),n}}return new I({url:e,outFields:t})}async function N(e,t,a,r,n,i=null){return T(await F(e,["*"],n),t,a,r,n,i)}function T(e,t=null,a=null,r=!0,n=null,i=null){switch(e.type){case"catalog-footprint":return T(e.parent,t,a,r,n,i);case"subtype-sublayer":{const l=T(e.parent,t,a,r,n,i);return l.filter(L.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:l.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"knowledge-graph-sublayer":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const l={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!e.url&&e.source?new c(l):new u(l)}default: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,a){if(null!==f.applicationCache){const e=f.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==f.applicationCache){f.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw f.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(i){throw a.removeCachedServiceMetadata(t,r),i}}return r}async function O(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await k(e,null);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 N(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(L.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:i.getFieldsIndex(),timeZone: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,l=null,s=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 N(o,r,n,i,l,s);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:l,interceptor:s})}n.registerAction(),i.registerAction(),l.registerAction(),s.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let 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=>w(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(_.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let 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=>w(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._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=T(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await k(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])l.name===e&&(i=l);if(!i)for(const l of n.tables??[])l.name===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(!i)for(const l of n.tables??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function v(e,t,a=null,r=null){return new j(e,t,a,r)}function R(e,t,a=null,r=null){return new D(e,t,a,r)}function M(e,t,n,i,l){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,l,"outFields"in a?a.outFields:null,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(a,l,"outFields"in a?a.outFields:null,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return T(e.parent,l,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return T(e,l,e.parent.outFields,!0,n,i)}return null}return null}async function q(e,t,a,r,n,i,l,s=null){if(f.applicationCache){const o=f.applicationCache.getLayerInfo(e+":"+i.url);if(o)return G(await o,t,a,r,n,l,s)}if(null!=l){const o=l.getCachedPortalItem(i.url,e);if(null!=o)return await G(await o,t,a,r,n,l,s)}const o=new g({id:e,portal:i}).load();f.applicationCache?f.applicationCache.setLayerInfo(e+":"+i.url,o):null!=l&&l.setCachedPortalItem(i.url,e,o);try{return await G(await o,t,a,r,n,l,s)}catch(u){throw f.applicationCache&&f.applicationCache.clearLayerInfo(e+":"+i.url),null!=l&&l.removeCachedPortalItem(i.url,e,o),u}}async function G(e,t,a,r,n,i,l){let s;if("Feature Service"===e.type||"Map Service"===e.type)s=await F(h(e.url??"")+"/"+t,["*"],i);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=i){const t=i.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)s=await t;else{const t=S.fromPortalItem(e);i.setCachedPortalItemLayer(e.portal.url,e.id,t);try{s=await t}catch(o){throw i.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else s=await S.fromPortalItem(e)}return T(s,a,r,n,i,l)}export{O as constructAssociationMetaDataFeatureSetFromUrl,T as constructFeatureSet,q as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,N as constructFeatureSetFromUrl,M as convertToFeatureSet,v as createFeatureSetCollectionFromMap,R as createFeatureSetCollectionFromService,C as initialiseMetaDataCache};
|
|
5
|
+
import e from"../request.js";import t from"./featureSetCollection.js";import{p as a,_ as r}from"../chunks/languageUtils.js";import n from"./featureset/actions/AttributeFilter.js";import i from"./featureset/actions/GroupBy.js";import l from"./featureset/actions/OrderBy.js";import s from"./featureset/actions/SpatialFilter.js";import o from"./featureset/actions/Top.js";import u from"./featureset/sources/FeatureLayerDynamic.js";import c from"./featureset/sources/FeatureLayerMemory.js";import d from"./featureset/sources/FeatureLayerRelated.js";import p from"./featureset/support/cache.js";import{FeatureSetError as f,FeatureSetErrorCodes as y}from"./featureset/support/errorsupport.js";import{isSupportedSourceLayer as m,extractServiceUrl as h,isSupportedLayer as w}from"./featureset/support/shared.js";import I from"../core/Loadable.js";import L from"../core/sql/WhereClause.js";import _ from"../layers/FeatureLayer.js";import S from"../layers/Layer.js";import C from"../portal/PortalItem.js";function g(){null===p.applicationCache&&(p.applicationCache=new p)}async function F(e,t,a){if(p.applicationCache){const a=p.applicationCache.getLayerInfo(e);if(a){const r=await a;return new _({url:e,outFields:t,sourceJSON:r})}const n=new _({url:e,outFields:t}),i=(async()=>(await n.load(),n.sourceJSON))();if(p.applicationCache){p.applicationCache.setLayerInfo(e,i);try{return await i,n}catch(r){throw p.applicationCache.clearLayerInfo(e),r}}return await i,n}if(null!=a){const r=a.getCachedLayerMetadata(e);if(r){const a=await r;return new _({url:e,outFields:t,sourceJSON:a})}const i=new _({url:e,outFields:t}),l=(async()=>(await i.load(),i.sourceJSON))();a.setCachedLayerMetadata(e,l);try{return await l,i}catch(n){throw a.removeCachedLayerMetadata(e,l),n}}return new _({url:e,outFields:t})}async function k(e,t,a,r,n,i=null){return N(await F(e,["*"],n),t,a,r,n,i)}function N(e,t=null,a=null,r=!0,n=null,i=null){switch(e.type){case"catalog-footprint":return N(e.parent,t,a,r,n,i);case"subtype-sublayer":{const l=N(e.parent,t,a,r,n,i);return l.filter(L.create(e.parent.subtypeField+"="+e.subtypeCode.toString(),{fieldsIndex:e.parent.fieldsIndex,timeZone:l.dateFieldsTimeZoneDefaultUTC}))}case"csv":case"geojson":case"knowledge-graph-sublayer":case"wfs":return new c({layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i});case"catalog":case"feature":case"oriented-imagery":case"subtype-group":{const l={layer:e,spatialReference:t,outFields:a,includeGeometry:r,lrucache:n,interceptor:i};return!e.url&&e.source?new c(l):new u(l)}default:throw new Error(`Unsupported layer type: ${e.type}`)}}async function T(t){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}const a=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});return a.data?a.data:null})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,a);try{return await a}catch(r){throw p.applicationCache.clearLayerInfo(t),r}}return a}async function A(t,a){const r="QUERYDATAELEMTS:"+a.toString()+":"+t;if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(r);if(null!==e)return e}const n=(async()=>{const r=await e(t+"/queryDataElements",{method:"post",responseType:"json",query:{layers:JSON.stringify([a.toString()]),f:"json"}});if(r.data){const e=r.data;if(e.layerDataElements?.[0])return e.layerDataElements[0]}throw new f(y.DataElementsNotFound)})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(r,n);try{return await n}catch(i){throw p.applicationCache.clearLayerInfo(r),i}}return n}async function b(t,a){if(null!==p.applicationCache){const e=p.applicationCache.getLayerInfo(t);if(null!==e)return e}if(null!=a){const e=a.getCachedServiceMetadata(t);if(null!=e)return e}const r=(async()=>{const a=await e(t,{responseType:"json",query:{f:"json"}});if(a.data){const e=a.data;return e.layers||(e.layers=[]),e.tables||(e.tables=[]),e}return{layers:[],tables:[]}})();if(null!==p.applicationCache){p.applicationCache.setLayerInfo(t,r);try{return await r}catch(n){throw p.applicationCache.clearLayerInfo(t),n}}if(null!=a){a.setCachedServiceMetadata(t,r);try{return await r}catch(i){throw a.removeCachedServiceMetadata(t,r),i}}return r}async function O(e,t,a){const r={metadata:null,networkId:-1,unVersion:3,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map,queryelem:null,layerNameLkp:{},lkp:null},n=await b(e,null);if(r.metadata=n,void 0!==n.controllerDatasetLayers?.utilityNetworkLayerId&&null!==n.controllerDatasetLayers.utilityNetworkLayerId){if(n.layers)for(const e of n.layers)r.layerNameLkp[e.id]=e.name;if(n.tables)for(const e of n.tables)r.layerNameLkp[e.id]=e.name;const i=n.controllerDatasetLayers.utilityNetworkLayerId;r.networkId=i;const l=await A(e,i);if(l){r.queryelem=l,r.queryelem?.dataElement&&void 0!==r.queryelem.dataElement.schemaGeneration&&(r.unVersion=r.queryelem.dataElement.schemaGeneration),r.lkp={},r.queryelem.dataElement.domainNetworks||(r.queryelem.dataElement.domainNetworks=[]);for(const e of r.queryelem.dataElement.domainNetworks){for(const t of e.edgeSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}for(const t of e.junctionSources??[]){const e={layerId:t.layerId,sourceId:t.sourceId,className:r.layerNameLkp[t.layerId]??null};r.layerIdLookup.set(e.layerId,e),r.sourceIdLookup.set(e.sourceId,e),e.className&&(r.lkp[e.className]=e)}}if(r.queryelem.dataElement.terminalConfigurations)for(const e of r.queryelem.dataElement.terminalConfigurations)for(const t of e.terminals)r.terminals.push({terminalId:t.terminalId,terminalName:t.terminalName});const n=await T(e+"/"+i);if(void 0!==n.systemLayers?.associationsTableId&&null!==n.systemLayers.associationsTableId){let i=null;if(a&&r.unVersion<8){const a=[];r.unVersion>=4&&(a.push("STATUS"),a.push("PERCENTALONG")),i=await k(e+"/"+n.systemLayers.associationsTableId,t,["OBJECTID","FROMNETWORKSOURCEID","TONETWORKSOURCEID","FROMGLOBALID","TOGLOBALID","TOTERMINALID","FROMTERMINALID","ASSOCIATIONTYPE","ISCONTENTVISIBLE","GLOBALID",...a],!1,null,null),await i.load(),r.unVersion>=4&&(i=i.filter(L.create("STATUS NOT IN (1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63)",{fieldsIndex:i.getFieldsIndex(),timeZone:i.dateFieldsTimeZoneDefaultUTC})),await i.load())}return{lkp:r.lkp,associations:i,unVersion:r.unVersion,terminals:r.terminals,layerIdLookup:r.layerIdLookup,sourceIdLookup:r.sourceIdLookup}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}return{associations:null,unVersion:r.unVersion,lkp:null,terminals:[],layerIdLookup:new Map,sourceIdLookup:new Map}}async function E(e,t,a,r=null,n=null,i=!0,l=null,s=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 k(o,r,n,i,l,s);return new d({layer:e,relatedLayer:u,relationship:t,objectId:a,spatialReference:r,outFields:n,includeGeometry:i,lrucache:l,interceptor:s})}n.registerAction(),i.registerAction(),l.registerAction(),s.registerAction(),o.registerAction();class j extends t{constructor(e,t=null,a=null,r=null){super(),this._map=e,this._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this._instantLayers=[]}_makeAndAddFeatureSet(e,t=!0,a=null){const r=N(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache,this._interceptor);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async featureSetByName(e,t=!0,a=null){if(I.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetByName(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let 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=>w(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 _)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e=r.outFields?r:{...r,outFields:["*"]};r._materializedTable=new _(e)}return await r._materializedTable.load(),this._makeAndAddFeatureSet(r._materializedTable,t,a)}}return null}async featureSetById(e,t=!0,a=["*"]){if(I.isLoadable(this._map)&&!this._map.loaded)return await this._map.load(),this.featureSetById(e,t,a);null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let 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=>w(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 _)return this._makeAndAddFeatureSet(r,t,a);if(null==r._materializedTable){const e={...r,outFields:["*"]};r._materializedTable=new _(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._overrideSpatialReference=t,this._lrucache=a,this._interceptor=r,this.metadata=null,this._instantLayers=[]}get url(){return this._url}_makeAndAddFeatureSet(e,t=!0,a=null){const r=N(e,this._overrideSpatialReference,null===a?["*"]:a,t,this._lrucache);return this._instantLayers.push({featureset:r,opitem:e,includeGeometry:t,outFields:JSON.stringify(a)}),r}async _loadMetaData(){const e=await b(this._url,this._lrucache);return this.metadata=e,e}load(){return this._loadMetaData()}clone(){return new D(this._url,this._overrideSpatialReference,this._lrucache,this._interceptor)}async featureSetByName(e,t=!0,a=null){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.title===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])l.name===e&&(i=l);if(!i)for(const l of n.tables??[])l.name===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}async featureSetById(e,t=!0,a=["*"]){null===a&&(a=["*"]),a=(a=a.slice()).sort();const r=JSON.stringify(a);e=null!=e?e.toString():"";for(let l=0;l<this._instantLayers.length;l++){const a=this._instantLayers[l];if(a.opitem.id===e&&a.includeGeometry===t&&a.outFields===r)return this._instantLayers[l].featureset}const n=await this._loadMetaData();let i=null;for(const l of n.layers??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(!i)for(const l of n.tables??[])null!==l.id&&void 0!==l.id&&l.id.toString()===e&&(i=l);if(i){const e=await F(this._url+"/"+i.id,["*"],this._lrucache);return this._makeAndAddFeatureSet(e,t,a)}return null}}function M(e,t,a=null,r=null){return new j(e,t,a,r)}function v(e,t,a=null,r=null){return new D(e,t,a,r)}function R(e,t,n,i,l){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&&m(e)){const a=e;switch(t){case"datasource":return N(a,l,"outFields"in a?a.outFields:null,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return N(a,l,"outFields"in a?a.outFields:null,!0,n,i)}return null}if(r(e)){switch(t){case"datasource":return N(e.parent,l,e.parent.outFields,!0,n,i).getDataSourceFeatureSet();case"parent":case"root":return N(e,l,e.parent.outFields,!0,n,i)}return null}return null}async function q(e,t,a,r,n,i,l,s=null){if(p.applicationCache){const o=p.applicationCache.getLayerInfo(e+":"+i.url);if(o)return G(await o,t,a,r,n,l,s)}if(null!=l){const o=l.getCachedPortalItem(i.url,e);if(null!=o)return await G(await o,t,a,r,n,l,s)}const o=new C({id:e,portal:i}).load();p.applicationCache?p.applicationCache.setLayerInfo(e+":"+i.url,o):null!=l&&l.setCachedPortalItem(i.url,e,o);try{return await G(await o,t,a,r,n,l,s)}catch(u){throw p.applicationCache&&p.applicationCache.clearLayerInfo(e+":"+i.url),null!=l&&l.removeCachedPortalItem(i.url,e,o),u}}async function G(e,t,a,r,n,i,l){let s;if("Feature Service"===e.type||"Map Service"===e.type)s=await F(h(e.url??"")+"/"+t,["*"],i);else{if(t)throw new Error(`layerId=${t} provided for ${e.type} item`);if(null!=i){const t=i.getCachedPortalItemLayer(e.portal.url,e.id);if(null!=t)s=await t;else{const t=S.fromPortalItem(e);i.setCachedPortalItemLayer(e.portal.url,e.id,t);try{s=await t}catch(o){throw i.removeCachedPortalItemLayer(e.portal.url,e.id,t),o}}}else s=await S.fromPortalItem(e)}return N(s,a,r,n,i,l)}export{O as constructAssociationMetaDataFeatureSetFromUrl,N as constructFeatureSet,q as constructFeatureSetFromPortalItem,E as constructFeatureSetFromRelationship,k as constructFeatureSetFromUrl,R as convertToFeatureSet,M as createFeatureSetCollectionFromMap,v 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.33/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"../ArcadeDate.js";import t from"../ArcadePortal.js";import n from"../Dictionary.js";import{ArcadeExecutionError as i,ExecutionErrorCodes as a}from"../executionError.js";import r from"../Feature.js";import{convertToFeatureSet as s,constructFeatureSetFromPortalItem as o,constructFeatureSet as l,constructFeatureSetFromRelationship as f,constructFeatureSetFromUrl as d,constructAssociationMetaDataFeatureSetFromUrl as u}from"../featureSetUtils.js";import c from"../ImmutableArray.js";import{D as m,k as p,j as y,p as w,f as h,h as I,L as g,g as F,o as D,K as T,e as x,n as b,m as E,i as A,t as N,a0 as L,X as S}from"../../chunks/languageUtils.js";import{getPortal as C}from"../portalUtils.js";import{SqlExpressionAdapted as Z,StringToCodeAdapted as $,FieldRename as v,AdaptedFeatureSet as P,OriginalField as j}from"../featureset/actions/Adapted.js";import U from"../featureset/actions/AttributeFilter.js";import M from"../featureset/actions/OrderBy.js";import R from"../featureset/actions/Top.js";import k from"../featureset/sources/Empty.js";import O from"../featureset/sources/FeatureLayerMemory.js";import z from"../featureset/support/OrderbyClause.js";import{cloneField as W}from"../featureset/support/shared.js";import{isSingleField as H}from"../featureset/support/sqlUtils.js";import{calculateStat as G}from"./fieldStats.js";import{isPromiseLike as _}from"../../core/promiseUtils.js";import K from"../../core/sql/WhereClause.js";import B from"../../layers/FeatureLayer.js";import q from"../../layers/support/Field.js";import V from"../../portal/Portal.js";import{isString as Q,isArray as J,isInteger as X}from"../../support/guards.js";function Y(e){if(1===e.length){if(J(e[0]))return G("distinct",e[0],-1);if(E(e[0]))return G("distinct",e[0].toArray(),-1)}return G("distinct",e,-1)}function ee(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function te(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];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 ie(e){if(null===e)return null;const t={},n=te(e,"wkt");null!==n&&(t.wkt=n);const i=te(e,"wkid");return null!==i&&(t.wkid=i),t}function ae(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=ie(n));const i=te(e,"x",null);if(null!==i)return t.x=i,t.y=te(e,"y",null),t.hasZ&&(t.z=te(e,"z",null)),t.hasM&&(t.m=te(e,"m",null)),t;const a=te(e,"rings",null);if(null!==a)return t.rings=a,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!==J(e.layerDefinition.fields)&&!1!==J(e.featureSet.features))))}function oe(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}function le(G){"async"===G.mode&&(G.functions.timezone=function(t,r){return G.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 i(t,a.InvalidParameter,r);const e=l[1].field("type");if(!1===Q(e))throw new i(t,a.InvalidParameter,r);switch(h(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")&&Q(l[1].field("fieldname")))return oe(l[0].fieldTimeZone(h(l[1].field("fieldname"))))}throw new i(t,a.InvalidParameter,r)}const f=I(l[0],g(t));if(null===f)return null;const d=f.timeZone;return"system"===d?e.systemTimeZoneCanonicalName:"utc"===d.toLowerCase()?"UTC":"unknown"===d.toLowerCase()?"Unknown":d}))},G.functions.sqltimestamp=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,1,3,e,t);const o=s[0];if(F(o)){if(1===s.length)return o.toSQLWithKeyword();if(2===s.length)return o.changeTimeZone(h(s[1])).toSQLWithKeyword();throw new i(e,a.InvalidParameter,t)}if(y(o))return o.toSQLWithKeyword();if(w(o)){if(3!==s.length)throw new i(e,a.InvalidParameter,t);await o.load();const n=h(s[1]);if(y(s[2]))return s[2].toSQLWithKeyword();if(!1===F(s[2]))throw new i(e,a.InvalidParameter,t);const r=o.fieldTimeZone(n);return null==r?s[2].toSQLWithKeyword():s[2].changeTimeZone(r).toSQLWithKeyword()}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"sqltimestamp",min:2,max:4}),G.functions.featuresetbyid=function(e,t){return G.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),D(s[0])){const n=h(s[1]);let r=T(s[2],null);const o=x(T(s[3],!0));if(null===r&&(r=["*"]),!1===J(r))throw new i(e,a.InvalidParameter,t);return s[0].featureSetById(n,o,r)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"featuresetbyid",min:2,max:4}),G.functions.getfeatureset=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,o)=>{if(m(o,1,2,e,t),b(o[0])){let t=T(o[1],"datasource");return null===t&&(t="datasource"),t=h(t).toLowerCase(),s(o[0].fullSchema(),t,e.lrucache,e.interceptor,e.spatialReference)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"getfeatureset",min:1,max:2}),G.functions.featuresetbyportalitem=function(e,n){return G.standardFunctionAsync(e,n,((r,s,l)=>{if(m(l,2,5,e,n),null===l[0])throw new i(e,a.PortalRequired,n);if(l[0]instanceof t){const t=h(l[1]),r=h(l[2]);let s=T(l[3],null);const f=x(T(l[4],!0));if(null===s&&(s=["*"]),!1===J(s))throw new i(e,a.InvalidParameter,n);let d;return d=e.services?.portal?e.services.portal:V.getDefault(),d=C(l[0],d),o(t,r,e.spatialReference,s,f,d,e.lrucache,e.interceptor)}if(!1===Q(l[0]))throw new i(e,a.PortalRequired,n);const f=h(l[0]),d=h(l[1]);let u=T(l[2],null);const c=x(T(l[3],!0));if(null===u&&(u=["*"]),!1===J(u))throw new i(e,a.InvalidParameter,n);return o(f,d,e.spatialReference,u,c,e.services?.portal??V.getDefault(),e.lrucache,e.interceptor)}))},G.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),G.functions.featuresetbyname=function(e,t){return G.standardFunctionAsync(e,t,((n,r,s)=>{if(m(s,2,4,e,t),D(s[0])){const n=h(s[1]);let r=T(s[2],null);const o=x(T(s[3],!0));if(null===r&&(r=["*"]),!1===J(r))throw new i(e,a.InvalidParameter,t);return s[0].featureSetByName(n,o,r)}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"featuresetbyname",min:2,max:4}),G.functions.featureset=function(e,t){return G.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(Q(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 i(e,a.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=ie(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 i=te(n,"featureset");if(i){const e={};for(const n of t)e[n.name.toLowerCase()]=n.name;for(const t of te(i,"features",[])){const n={},i=te(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];l.featureSet.features.push({attributes:n,geometry:ae(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=ie(r));const s=[],o=te(n,"fields",null);if(!J(o))throw new i(e,a.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 d=te(n,"features",null);if(J(d))for(const e of d){const t={},n=te(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:ae(te(e,"geometry",null))})}else d=null,l.featureSet.features=d}}}if(!1===se(l))throw new i(e,a.InvalidParameter,t);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),O.create(l,e.spatialReference)}))},G.signatures.push({name:"featureset",min:1,max:1}),G.functions.filter=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),J(s[0])||E(s[0])){const n=[];let r,o=s[0];if(o instanceof c&&(o=o.toArray()),!A(s[1]))throw new i(e,a.InvalidParameter,t);r=s[1].createFunction(e);for(const e of o){const t=r(e);_(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=K.create(s[1],{fieldsIndex:t.getFieldsIndex(),timeZone:t.dateFieldsTimeZoneDefaultUTC}),i=n.getVariables();if(i.length>0){const t={};for(const n of i)t[n]=G.evaluateIdentifier(e,{name:n});n.parameters=t}return new U({parentfeatureset:s[0],whereclause:n})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"filter",min:2,max:2}),G.functions.orderby=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0])){const e=new z(s[1]);return new M({parentfeatureset:s[0],orderbyclause:e})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"orderby",min:2,max:2}),G.functions.top=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{if(m(s,2,2,e,t),w(s[0]))return new R({parentfeatureset:s[0],topnum:s[1]});if(J(s[0]))return N(s[1])>=s[0].length?s[0].slice():s[0].slice(0,N(s[1]));if(E(s[0]))return N(s[1])>=s[0].length()?s[0].slice():s[0].slice(0,N(s[1]));throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"top",min:2,max:2}),G.functions.first=function(e,t){return G.standardFunctionAsync(e,t,(async(n,i,a)=>{if(m(a,1,1,e,t),w(a[0])){const t=await a[0].first(n.abortSignal);if(null!==t){const n=r.createFromGraphicLikeObject(t.geometry,t.attributes,a[0],e.timeZone);return n._underlyingGraphic=t,n}return t}return J(a[0])?0===a[0].length?null:a[0][0]:E(a[0])?0===a[0].length()?null:a[0].get(0):null}))},G.signatures.push({name:"first",min:1,max:1}),G.functions.attachments=function(e,t){return G.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=N(o[1].field("minsize"))),o[1].hasField("metadata")&&(f.returnMetadata=x(o[1].field("metadata"))),o[1].hasField("maxsize")&&(f.maxsize=N(o[1].field("maxsize"))),o[1].hasField("types")){const e=L(o[1].field("types"),!1);e.length>0&&(f.types=e)}}else if(null!==o[1])throw new i(e,a.InvalidParameter,t);if(b(o[0])){let t=o[0]._layer;return t instanceof B&&(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 i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"attachments",min:1,max:2}),G.functions.featuresetbyrelationshipname=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,4,e,t);const o=s[0],u=h(s[1]);let c=T(s[2],null);const p=x(T(s[3],!0));if(null===c&&(c=["*"]),!1===J(c))throw new i(e,a.InvalidParameter,t);if(null===s[0])return null;if(!b(s[0]))throw new i(e,a.InvalidParameter,t);let y=o._layer;if(y instanceof B&&(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 I=y.relationshipMetaData().filter((e=>e.name===u));if(0===I.length)return null;if(void 0!==I[0].relationshipTableId&&null!==I[0].relationshipTableId&&I[0].relationshipTableId>-1)return f(y,I[0],o.field(y.objectIdField),y.spatialReference,c,p,e.lrucache,e.interceptor);let g=y.serviceUrl();if(!g)return null;g="/"===g.charAt(g.length-1)?g+I[0].relatedTableId.toString():g+"/"+I[0].relatedTableId.toString();const F=await d(g,y.spatialReference,c,p,e.lrucache,e.interceptor);await F.load();let D=F.relationshipMetaData();if(D=D.filter((e=>e.id===I[0].id)),!1===o.hasField(I[0].keyField)||null===o.field(I[0].keyField)){const e=await y.getFeatureByObjectId(o.field(y.objectIdField),[I[0].keyField]);if(e){const t=K.create(D[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[I[0].keyField]},F.filter(t)}return new k({parentfeatureset:F})}const E=K.create(D[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return E.parameters={id:o.field(I[0].keyField)},F.filter(E)}))},G.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),G.functions.featuresetbyassociation=function(e,t){return G.standardFunctionAsync(e,t,(async(n,r,s)=>{m(s,2,3,e,t);const o=s[0],f=h(T(s[1],"")).toLowerCase(),d=Q(s[2])?h(s[2]):null;if(null===s[0])return null;if(!b(s[0]))throw new i(e,a.InvalidParameter,t);let c=o._layer;if(c instanceof B&&(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 u(p,e.spatialReference);let I=null,g=null,F=!1;if(null!==d&&""!==d&&void 0!==d){for(const e of y.terminals)e.terminalName===d&&(g=e.terminalId);null===g&&(F=!0)}const D=y.associations.getFieldsIndex(),x=D.get("TOGLOBALID").name,E=D.get("FROMGLOBALID").name,A=D.get("TOTERMINALID").name,N=D.get("FROMTERMINALID").name,L=D.get("FROMNETWORKSOURCEID").name,C=D.get("TONETWORKSOURCEID").name,U=D.get("ASSOCIATIONTYPE").name,M=D.get("ISCONTENTVISIBLE").name,R=D.get("OBJECTID").name;for(const e of c.fields)if("global-id"===e.type){I=o.field(e.name);break}let k=null,O=new Z(new q({name:"percentalong",alias:"percentalong",type:"double"}),K.create("0",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),z=new Z(new q({name:"side",alias:"side",type:"string"}),K.create("''",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));const H="globalid",G="globalId",_={};for(const e in y.lkp)_[e]=y.lkp[e].sourceId;const V=new $(new q({name:"classname",alias:"classname",type:"string"}),null,_);let J="";switch(f){case"midspan":{J=`((${x}='${I}') OR ( ${E}='${I}')) AND (${U} IN (5))`,V.codefield=K.create(`CASE WHEN (${x}='${I}') THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const e=W(P.findField(y.associations.fields,E));e.name=H,e.alias=H,k=new Z(e,K.create(`CASE WHEN (${E}='${I}') THEN ${x} ELSE ${E} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),O=y.unVersion>=4?new j(P.findField(y.associations.fields,D.get("PERCENTALONG").name)):new Z(new q({name:"percentalong",alias:"percentalong",type:"double"}),K.create("0",{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{J=`((${x}='${I}') OR ( ${E}='${I}')) AND (${U} IN (4,6))`,V.codefield=K.create(`CASE WHEN (${x}='${I}') THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const e=W(P.findField(y.associations.fields,E));e.name=H,e.alias=H,k=new Z(e,K.create(`CASE WHEN (${E}='${I}') THEN ${x} ELSE ${E} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC})),z=new Z(new q({name:"side",alias:"side",type:"string"}),K.create(`CASE WHEN (${U}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${x}='@T'`,t=`${E}='@T'`;null!==g&&(e+=` AND ${A}=@A`,t+=` AND ${N}=@A`),J="(("+e+") OR ("+t+"))",J=S(J,"@T",I??""),e=S(e,"@T",I??""),null!==g&&(e=S(e,"@A",g.toString()),J=S(J,"@A",g.toString())),V.codefield=K.create("CASE WHEN "+e+` THEN ${L} ELSE ${C} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC});const n=W(P.findField(y.associations.fields,E));n.name=H,n.alias=H,k=new Z(n,K.create("CASE WHEN "+e+` THEN ${E} ELSE ${x} END`,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}));break}case"container":J=`${x}='${I}' AND ${U} = 2`,null!==g&&(J+=` AND ${A} = `+g.toString()),V.codefield=L,J="( "+J+" )",k=new v(P.findField(y.associations.fields,E),H,H);break;case"content":J=`(${E}='${I}' AND ${U} = 2)`,null!==g&&(J+=` AND ${N} = `+g.toString()),V.codefield=C,J="( "+J+" )",k=new v(P.findField(y.associations.fields,x),H,H);break;case"structure":J=`(${x}='${I}' AND ${U} = 3)`,null!==g&&(J+=` AND ${A} = `+g.toString()),V.codefield=L,J="( "+J+" )",k=new v(P.findField(y.associations.fields,E),H,G);break;case"attached":J=`(${E}='${I}' AND ${U} = 3)`,null!==g&&(J+=` AND ${N} = `+g.toString()),V.codefield=C,J="( "+J+" )",k=new v(P.findField(y.associations.fields,x),H,G);break;default:throw new i(e,a.InvalidParameter,t)}F&&(J="1 <> 1");return new P({parentfeatureset:y.associations,adaptedFields:[new j(P.findField(y.associations.fields,R)),new j(P.findField(y.associations.fields,M)),k,z,V,O],extraFilter:J?K.create(J,{fieldsIndex:y.associations.getFieldsIndex(),timeZone:y.associations.dateFieldsTimeZoneDefaultUTC}):null})}))},G.signatures.push({name:"featuresetbyassociation",min:2,max:6}),G.functions.groupby=function(e,t){return G.standardFunctionAsync(e,t,(async(r,s,o)=>{if(m(o,3,3,e,t),!w(o[0]))throw new i(e,a.InvalidParameter,t);const l=await o[0].load(),f=[],d=[];let u=!1,c=[];if(Q(o[1]))c.push(o[1]);else if(o[1]instanceof n)c.push(o[1]);else if(J(o[1]))c=o[1];else{if(!E(o[1]))throw new i(e,a.InvalidParameter,t);c=o[1].toArray()}for(const m of c)if(Q(m)){const e=K.create(h(m),{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC}),t=!0===H(e)?h(m):"%%%%FIELDNAME";f.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(u=!0)}else{if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"%%%%FIELDNAME",r=m.hasField("expression")?m.field("expression"):"";if("%%%%FIELDNAME"===n&&(u=!0),!n)throw new i(e,a.InvalidParameter,t);f.push({name:n,expression:K.create(r||n,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(c=[],Q(o[2]))c.push(o[2]);else if(J(o[2]))c=o[2];else if(E(o[2]))c=o[2].toArray();else{if(!(o[2]instanceof n))throw new i(e,a.InvalidParameter,t);c.push(o[2])}for(const m of c){if(!(m instanceof n))throw new i(e,a.InvalidParameter,t);{const n=m.hasField("name")?m.field("name"):"",r=m.hasField("statistic")?m.field("statistic"):"",s=m.hasField("expression")?m.field("expression"):"";if(!n||!r||!s)throw new i(e,a.InvalidParameter,t);d.push({name:n,statistic:r.toLowerCase(),expression:K.create(s,{fieldsIndex:l.getFieldsIndex(),timeZone:l.dateFieldsTimeZoneDefaultUTC})})}}if(u){const e={};for(const n of l.fields)e[n.name.toLowerCase()]=1;for(const n of f)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);for(const n of d)"%%%%FIELDNAME"!==n.name&&(e[n.name.toLowerCase()]=1);let t=0;for(const n of f)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const t of f)ee(t.expression,G,e);for(const t of d)ee(t.expression,G,e);return o[0].groupby(f,d)}))},G.signatures.push({name:"groupby",min:3,max:3}),G.functions.distinct=function(e,t){return G.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(Q(o[1]))l.push(o[1]);else if(o[1]instanceof n)l.push(o[1]);else if(J(o[1]))l=o[1];else{if(!E(o[1]))throw new i(e,a.InvalidParameter,t);l=o[1].toArray()}let f=!1;for(const o of l)if(Q(o)){const e=K.create(h(o),{fieldsIndex:r.getFieldsIndex(),timeZone:r.dateFieldsTimeZoneDefaultUTC}),t=!0===H(e)?h(o):"%%%%FIELDNAME";s.push({name:t,expression:e}),"%%%%FIELDNAME"===t&&(f=!0)}else{if(!(o instanceof n))throw new i(e,a.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 i(e,a.InvalidParameter,t);s.push({name:n,expression:K.create(l||n,{fieldsIndex:r.getFieldsIndex(),timeZone: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)ee(t.expression,G,e);return o[0].groupby(s,[])}return Y(o)}))},G.functions.getfeaturesetinfo=function(e,t){return G.standardFunctionAsync(e,t,(async(i,a,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},g(e),!1,!1):null}))},G.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),G.functions.filterbysubtypecode=function(e,t){return G.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(!X(r))throw new i(e,a.InvalidParameter,t);if(n.subtypeField){const e=K.create(`${n.subtypeField}= ${s[1]}`,{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:s[0],whereclause:e})}if(null===n.typeIdField||""===n.typeIdField)throw new i(e,a.FeatureSetDoesNotHaveSubtypes,t);const o=K.create(`${n.typeIdField}= ${s[1]}`,{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:s[0],whereclause:o})}throw new i(e,a.InvalidParameter,t)}))},G.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{le as registerFunctions};
|
|
5
|
+
import e from"../../Graphic.js";import{ArcadeDate as t}from"../ArcadeDate.js";import n from"../ArcadePortal.js";import i from"../Dictionary.js";import{ArcadeExecutionError as a,ExecutionErrorCodes as r}from"../executionError.js";import o from"../Feature.js";import{convertToFeatureSet as s,constructFeatureSetFromPortalItem as l,constructFeatureSet as f,constructFeatureSetFromRelationship as d,constructFeatureSetFromUrl as u,constructAssociationMetaDataFeatureSetFromUrl as c}from"../featureSetUtils.js";import m from"../ImmutableArray.js";import{D as p,k as y,j as w,p as h,f as I,h as g,L as F,g as b,o as T,K as D,e as x,n as E,m as N,i as A,t as v,a0 as S,X as L}from"../../chunks/languageUtils.js";import{getPortal as j}from"../portalUtils.js";import{SqlExpressionAdapted as C,StringToCodeAdapted as Z,FieldRename as k,AdaptedFeatureSet as $,OriginalField as P}from"../featureset/actions/Adapted.js";import U from"../featureset/actions/AttributeFilter.js";import M from"../featureset/actions/OrderBy.js";import R from"../featureset/actions/Top.js";import O from"../featureset/sources/Empty.js";import z from"../featureset/sources/FeatureLayerMemory.js";import W from"../featureset/support/OrderbyClause.js";import{cloneField as H}from"../featureset/support/shared.js";import{isSingleField as G}from"../featureset/support/sqlUtils.js";import{calculateStat as V}from"./fieldStats.js";import{isPromiseLike as _}from"../../core/promiseUtils.js";import K from"../../core/sql/WhereClause.js";import q from"../../layers/FeatureLayer.js";import B from"../../layers/support/Field.js";import Q from"../../portal/Portal.js";import{queryAssociations as J}from"../../rest/networks/queryAssociations.js";import X from"../../rest/networks/support/NetworkElement.js";import Y from"../../rest/networks/support/QueryAssociationsParameters.js";import{isString as ee,isArray as te,isInteger as ne}from"../../support/guards.js";function ie(e){if(1===e.length){if(te(e[0]))return V("distinct",e[0],-1);if(N(e[0]))return V("distinct",e[0].toArray(),-1)}return V("distinct",e,-1)}function ae(e,t,n){const i=e.getVariables();if(i.length>0){const a={};for(const e of i)a[e]=t.evaluateIdentifier(n,{name:e});e.parameters=a}return e}function re(e,t,n=null){for(const i in e)if(i.toLowerCase()===t.toLowerCase())return e[i];return n}function oe(e){if(null===e)return null;const t={type:re(e,"type",""),name:re(e,"name","")};if("range"===t.type)t.range=re(e,"range",[]);else{t.codedValues=[];for(const n of re(e,"codedValues",[]))t.codedValues.push({name:re(n,"name",""),code:re(n,"code",null)})}return t}function se(e){if(null===e)return null;const t={},n=re(e,"wkt");null!==n&&(t.wkt=n);const i=re(e,"wkid");return null!==i&&(t.wkid=i),t}function le(e){if(null===e)return null;const t={hasZ:re(e,"hasz",!1),hasM:re(e,"hasm",!1)},n=re(e,"spatialreference");null!=n&&(t.spatialReference=se(n));const i=re(e,"x",null);if(null!==i)return t.x=i,t.y=re(e,"y",null),t.hasZ&&(t.z=re(e,"z",null)),t.hasM&&(t.m=re(e,"m",null)),t;const a=re(e,"rings",null);if(null!==a)return t.rings=a,t;const r=re(e,"paths",null);if(null!==r)return t.paths=r,t;const o=re(e,"points",null);if(null!==o)return t.points=o,t;for(const s of["xmin","xmax","ymin","ymax","zmin","zmax","mmin","mmax"]){const n=re(e,s,null);null!==n&&(t[s]=n)}return t}function fe(e,t){for(const n of t)if(n===e)return!0;return!1}function de(e){return!!e.layerDefinition&&(!!e.featureSet&&(!1!==fe(e.layerDefinition.geometryType,["",null,"esriGeometryNull","esriGeometryPoint","esriGeometryPolyline","esriGeometryPolygon","esriGeometryMultipoint","esriGeometryEnvelope"])&&(!1!==te(e.layerDefinition.fields)&&!1!==te(e.featureSet.features))))}function ue(e){return"utc"===e?.toLowerCase()?"UTC":"unknown"===e?.toLowerCase()?"Unknown":e}async function ce(t,n,i,o,s,l,d){const u=await t.getFeatureSetInfo();if(null===(u?.layerId??null))return null;if(!s.layerIdLookup.get(u.layerId))return null;const c=t.serviceUrl().replace(/\/FeatureServer/i,"/UtilityNetworkServer"),m=[];switch(i){case"connected":m.push("connectivity"),m.push("junction-edge-from-connectivity"),m.push("junction-edge-to-connectivity"),m.push("junction-edge-midspan-connectivity"),m.push("junction-junction-connectivity");break;case"container":case"content":m.push("containment");break;case"structure":case"attached":m.push("attachment");break;case"junctionedge":m.push("junction-edge-from-connectivity"),m.push("junction-edge-to-connectivity");break;case"midspan":m.push("junction-edge-midspan-connectivity");break;default:throw new a(l,r.InvalidParameter,d)}let p=null,y=!1;if(null!==o&&""!==o&&void 0!==o){for(const e of s.terminals)e.terminalName===o&&(p=e.terminalId);null===p&&(y=!0)}const w=[];if(!y){const a=new X({globalId:n.field(t.globalIdField),networkSourceId:s.layerIdLookup.get(u.layerId).sourceId,...p?{terminalId:p}:""}),r=await J(c,new Y({types:m,elements:[a]}));let o=0;for(const t of r.associations){let n=null,r="",l="";if(t.fromNetworkElement?.globalId===a.globalId?(n=t.toNetworkElement,l="to"):t.toNetworkElement?.globalId===a.globalId&&(n=t.fromNetworkElement,l="from"),!n)continue;switch(i){case"attached":if("attachment"!==t.associationType)continue;if("to"!==l)continue;break;case"structure":if("attachment"!==t.associationType)continue;if("from"!==l)continue;break;case"container":if("containment"!==t.associationType)continue;if("from"!==l)continue;break;case"content":if("containment"!==t.associationType)continue;if("to"!==l)continue;break;case"connected":break;case"junctionedge":"junction-edge-to-connectivity"===t.associationType?r="to":"junction-edge-from-connectivity"===t.associationType&&(r="from");break;case"midspan":if("junction-edge-midspan-connectivity"!==t.associationType)continue}const f=s.sourceIdLookup.get(n.networkSourceId)?.className??"";w.push(new e({geometry:null,attributes:{objectId:o++,globalId:n.globalId,percentAlong:t.percentAlong??0,isContentVisible:t.isContentVisible?0:1,className:f,side:r}}))}}const h=new q({source:w,geometryType:null,objectIdField:"objectId",globalIdField:"globalId",fields:[new B({name:"objectId",alias:"objectId",type:"oid"}),new B({name:"globalId",alias:"globalId",type:"global-id"}),new B({name:"percentAlong",alias:"percentAlong",type:"double"}),new B({name:"side",alias:"side",type:"string"}),new B({name:"isContentVisible",alias:"isContentVisible",type:"integer"}),new B({name:"className",alias:"className",type:"string"})]});return f(h)}function me(e){"async"===e.mode&&(e.functions.timezone=function(n,o){return e.standardFunctionAsync(n,o,(async(e,s,l)=>{if(p(l,1,2,n,o),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?ue("unknown"):ue(l[0].dateFieldsTimeZone);if(!(l[1]instanceof i)||!1===l[1].hasField("type"))throw new a(n,r.InvalidParameter,o);const e=l[1].field("type");if(!1===ee(e))throw new a(n,r.InvalidParameter,o);switch(I(e).toLowerCase()){case"preferredtimezone":return ue(l[0].preferredTimeZone);case"editfieldsinfo":return ue(l[0].editFieldsInfo?.timeZone??null);case"timeinfo":return ue(l[0].timeInfo?.timeZone??null);case"field":if(l[1].hasField("fieldname")&&ee(l[1].field("fieldname")))return ue(l[0].fieldTimeZone(I(l[1].field("fieldname"))))}throw new a(n,r.InvalidParameter,o)}const f=g(l[0],F(n));if(null===f)return null;const d=f.timeZone;return"system"===d?t.systemTimeZoneCanonicalName:"utc"===d.toLowerCase()?"UTC":"unknown"===d.toLowerCase()?"Unknown":d}))},e.functions.sqltimestamp=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{p(o,1,3,t,n);const s=o[0];if(b(s)){if(1===o.length)return s.toSQLWithKeyword();if(2===o.length)return s.changeTimeZone(I(o[1])).toSQLWithKeyword();throw new a(t,r.InvalidParameter,n)}if(w(s))return s.toSQLWithKeyword();if(h(s)){if(3!==o.length)throw new a(t,r.InvalidParameter,n);await s.load();const e=I(o[1]);if(w(o[2]))return o[2].toSQLWithKeyword();if(!1===b(o[2]))throw new a(t,r.InvalidParameter,n);const i=s.fieldTimeZone(e);return null==i?o[2].toSQLWithKeyword():o[2].changeTimeZone(i).toSQLWithKeyword()}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"sqltimestamp",min:2,max:4}),e.functions.featuresetbyid=function(t,n){return e.standardFunctionAsync(t,n,((e,i,o)=>{if(p(o,2,4,t,n),T(o[0])){const e=I(o[1]);let i=D(o[2],null);const s=x(D(o[3],!0));if(null===i&&(i=["*"]),!1===te(i))throw new a(t,r.InvalidParameter,n);return o[0].featureSetById(e,s,i)}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"featuresetbyid",min:2,max:4}),e.functions.getfeatureset=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{if(p(o,1,2,t,n),E(o[0])){let e=D(o[1],"datasource");return null===e&&(e="datasource"),e=I(e).toLowerCase(),s(o[0].fullSchema(),e,t.lrucache,t.interceptor,t.spatialReference)}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"getfeatureset",min:1,max:2}),e.functions.featuresetbyportalitem=function(t,i){return e.standardFunctionAsync(t,i,((e,o,s)=>{if(p(s,2,5,t,i),null===s[0])throw new a(t,r.PortalRequired,i);if(s[0]instanceof n){const e=I(s[1]),n=I(s[2]);let o=D(s[3],null);const f=x(D(s[4],!0));if(null===o&&(o=["*"]),!1===te(o))throw new a(t,r.InvalidParameter,i);let d;return d=t.services?.portal?t.services.portal:Q.getDefault(),d=j(s[0],d),l(e,n,t.spatialReference,o,f,d,t.lrucache,t.interceptor)}if(!1===ee(s[0]))throw new a(t,r.PortalRequired,i);const f=I(s[0]),d=I(s[1]);let u=D(s[2],null);const c=x(D(s[3],!0));if(null===u&&(u=["*"]),!1===te(u))throw new a(t,r.InvalidParameter,i);return l(f,d,t.spatialReference,u,c,t.services?.portal??Q.getDefault(),t.lrucache,t.interceptor)}))},e.signatures.push({name:"featuresetbyportalitem",min:2,max:5}),e.functions.featuresetbyname=function(t,n){return e.standardFunctionAsync(t,n,((e,i,o)=>{if(p(o,2,4,t,n),T(o[0])){const e=I(o[1]);let i=D(o[2],null);const s=x(D(o[3],!0));if(null===i&&(i=["*"]),!1===te(i))throw new a(t,r.InvalidParameter,n);return o[0].featureSetByName(e,s,i)}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"featuresetbyname",min:2,max:4}),e.functions.featureset=function(t,n){return e.standardFunction(t,n,((e,o,s)=>{p(s,1,1,t,n);const l={layerDefinition:{geometryType:"",objectIdField:"",globalIdField:"",typeIdField:"",hasM:!1,hasZ:!1,fields:[]},featureSet:{geometryType:"",features:[]}};if(ee(s[0])){const e=JSON.parse(s[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(!(s[0]instanceof i))throw new a(t,r.InvalidParameter,n);{const e=JSON.parse(s[0].castToText(!0)),i=re(e,"layerdefinition");if(null!==i){l.layerDefinition.geometryType=re(i,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.globalIdField=re(i,"globalidfield",""),l.layerDefinition.objectIdField=re(i,"objectidfield",""),l.layerDefinition.typeIdField=re(i,"typeidfield",""),l.layerDefinition.hasZ=!0===re(i,"hasz",!1),l.layerDefinition.hasM=!0===re(i,"hasm",!1);const t=re(i,"spatialreference");t&&(l.layerDefinition.spatialReference=se(t));const n=[];for(const e of re(i,"fields",[])){const t={name:re(e,"name",""),alias:re(e,"alias",""),type:re(e,"type",""),nullable:re(e,"nullable",!0),editable:re(e,"editable",!0),length:re(e,"length",null),domain:oe(re(e,"domain"))};n.push(t)}l.layerDefinition.fields=n;const a=re(e,"featureset");if(a){const e={};for(const t of n)e[t.name.toLowerCase()]=t.name;for(const t of re(a,"features",[])){const n={},i=re(t,"attributes",{});for(const t in i)n[e[t.toLowerCase()]]=i[t];l.featureSet.features.push({attributes:n,geometry:le(re(t,"geometry"))})}}}else{l.layerDefinition.hasZ=!0===re(e,"hasz",!1),l.layerDefinition.hasM=!0===re(e,"hasm",!1),l.layerDefinition.geometryType=re(e,"geometrytype",""),l.featureSet.geometryType=l.layerDefinition.geometryType,l.layerDefinition.objectIdField=re(e,"objectidfieldname",""),l.layerDefinition.typeIdField=re(e,"typeidfieldname","");const i=re(e,"spatialreference");i&&(l.layerDefinition.spatialReference=se(i));const o=[],s=re(e,"fields",null);if(!te(s))throw new a(t,r.InvalidParameter,n);for(const e of s){const t={name:re(e,"name",""),alias:re(e,"alias",""),type:re(e,"type",""),nullable:re(e,"nullable",!0),editable:re(e,"editable",!0),length:re(e,"length",null),domain:oe(re(e,"domain"))};o.push(t)}l.layerDefinition.fields=o;const f={};for(const e of o)f[e.name.toLowerCase()]=e.name;let d=re(e,"features",null);if(te(d))for(const e of d){const t={},n=re(e,"attributes",{});for(const e in n)t[f[e.toLowerCase()]]=n[e];l.featureSet.features.push({attributes:t,geometry:le(re(e,"geometry",null))})}else d=null,l.featureSet.features=d}}}if(!1===de(l))throw new a(t,r.InvalidParameter,n);return l.layerDefinition.geometryType||(l.layerDefinition.geometryType="esriGeometryNull"),z.create(l,t.spatialReference)}))},e.signatures.push({name:"featureset",min:1,max:1}),e.functions.filter=function(t,n){return e.standardFunctionAsync(t,n,(async(i,o,s)=>{if(p(s,2,2,t,n),te(s[0])||N(s[0])){const e=[];let i,o=s[0];if(o instanceof m&&(o=o.toArray()),!A(s[1]))throw new a(t,r.InvalidParameter,n);i=s[1].createFunction(t);for(const t of o){const n=i(t);_(n)?!0===await n&&e.push(t):!0===n&&e.push(t)}return e}if(h(s[0])){const n=await s[0].load(),i=K.create(s[1],{fieldsIndex:n.getFieldsIndex(),timeZone:n.dateFieldsTimeZoneDefaultUTC}),a=i.getVariables();if(a.length>0){const n={};for(const i of a)n[i]=e.evaluateIdentifier(t,{name:i});i.parameters=n}return new U({parentfeatureset:s[0],whereclause:i})}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"filter",min:2,max:2}),e.functions.orderby=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{if(p(o,2,2,t,n),h(o[0])){const e=new W(o[1]);return new M({parentfeatureset:o[0],orderbyclause:e})}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"orderby",min:2,max:2}),e.functions.top=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{if(p(o,2,2,t,n),h(o[0]))return new R({parentfeatureset:o[0],topnum:o[1]});if(te(o[0]))return v(o[1])>=o[0].length?o[0].slice():o[0].slice(0,v(o[1]));if(N(o[0]))return v(o[1])>=o[0].length()?o[0].slice():o[0].slice(0,v(o[1]));throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"top",min:2,max:2}),e.functions.first=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,a)=>{if(p(a,1,1,t,n),h(a[0])){const n=await a[0].first(e.abortSignal);if(null!==n){const e=o.createFromGraphicLikeObject(n.geometry,n.attributes,a[0],t.timeZone);return e._underlyingGraphic=n,e}return n}return te(a[0])?0===a[0].length?null:a[0][0]:N(a[0])?0===a[0].length()?null:a[0].get(0):null}))},e.signatures.push({name:"first",min:1,max:1}),e.functions.attachments=function(t,n){return e.standardFunctionAsync(t,n,(async(e,o,s)=>{p(s,1,2,t,n);const l={minsize:-1,maxsize:-1,types:null,returnMetadata:!1};if(s.length>1)if(s[1]instanceof i){if(s[1].hasField("minsize")&&(l.minsize=v(s[1].field("minsize"))),s[1].hasField("metadata")&&(l.returnMetadata=x(s[1].field("metadata"))),s[1].hasField("maxsize")&&(l.maxsize=v(s[1].field("maxsize"))),s[1].hasField("types")){const e=S(s[1].field("types"),!1);e.length>0&&(l.types=e)}}else if(null!==s[1])throw new a(t,r.InvalidParameter,n);if(E(s[0])){let e=s[0]._layer;return e instanceof q&&(e=f(e,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)),null===e?[]:!1===h(e)?[]:(await e.load(),e.queryAttachments(s[0].field(e.objectIdField),l.minsize,l.maxsize,l.types,l.returnMetadata))}if(null===s[0])return[];throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"attachments",min:1,max:2}),e.functions.featuresetbyrelationshipname=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{p(o,2,4,t,n);const s=o[0],l=I(o[1]);let c=D(o[2],null);const m=x(D(o[3],!0));if(null===c&&(c=["*"]),!1===te(c))throw new a(t,r.InvalidParameter,n);if(null===o[0])return null;if(!E(o[0]))throw new a(t,r.InvalidParameter,n);let y=s._layer;if(y instanceof q&&(y=f(y,t.spatialReference,["*"],!0,t.lrucache,t.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 d(y,w[0],s.field(y.objectIdField),y.spatialReference,c,m,t.lrucache,t.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 F=await u(g,y.spatialReference,c,m,t.lrucache,t.interceptor);await F.load();let b=F.relationshipMetaData();if(b=b.filter((e=>e.id===w[0].id)),!1===s.hasField(w[0].keyField)||null===s.field(w[0].keyField)){const e=await y.getFeatureByObjectId(s.field(y.objectIdField),[w[0].keyField]);if(e){const t=K.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return t.parameters={id:e.attributes[w[0].keyField]},F.filter(t)}return new O({parentfeatureset:F})}const T=K.create(b[0].keyField+"= @id",{fieldsIndex:F.getFieldsIndex(),timeZone:F.dateFieldsTimeZoneDefaultUTC});return T.parameters={id:s.field(w[0].keyField)},F.filter(T)}))},e.signatures.push({name:"featuresetbyrelationshipname",min:2,max:4}),e.functions.featuresetbyassociation=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{p(o,2,3,t,n);const s=o[0],l=I(D(o[1],"")).toLowerCase(),d=ee(o[2])?I(o[2]):null;if(null===o[0])return null;if(!E(o[0]))throw new a(t,r.InvalidParameter,n);let u=s._layer;if(u instanceof q&&(u=f(u,t.spatialReference,["*"],!0,t.lrucache,t.interceptor)),null===u)return null;if(!1===h(u))return null;await u.load();const m=u.serviceUrl(),y=await c(m,t.spatialReference,!0);if(y.unVersion>=8)return await ce(u,s,l,d,y,t,n);const w=y.associations;let g=null,F=null,b=!1;if(null!==d&&""!==d&&void 0!==d){for(const e of y.terminals)e.terminalName===d&&(F=e.terminalId);null===F&&(b=!0)}const T=w.getFieldsIndex(),x=T.get("TOGLOBALID").name,N=T.get("FROMGLOBALID").name,A=T.get("TOTERMINALID").name,v=T.get("FROMTERMINALID").name,S=T.get("FROMNETWORKSOURCEID").name,j=T.get("TONETWORKSOURCEID").name,U=T.get("ASSOCIATIONTYPE").name,M=T.get("ISCONTENTVISIBLE").name,R=T.get("OBJECTID").name;for(const t of u.fields)if("global-id"===t.type){g=s.field(t.name);break}let O=null,z=new C(new B({name:"percentalong",alias:"percentalong",type:"double"}),K.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new C(new B({name:"side",alias:"side",type:"string"}),K.create("''",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));const G="globalid",V="globalId",_={};for(const t in y.lkp)_[t]=y.lkp[t].sourceId;const Q=new Z(new B({name:"classname",alias:"classname",type:"string"}),null,_);let J="";switch(l){case"midspan":{J=`((${x}='${g}') OR ( ${N}='${g}')) AND (${U} IN (5))`,Q.codefield=K.create(`CASE WHEN (${x}='${g}') THEN ${S} ELSE ${j} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=H($.findField(w.fields,N));e.name=G,e.alias=G,O=new C(e,K.create(`CASE WHEN (${N}='${g}') THEN ${x} ELSE ${N} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),z=y.unVersion>=4?new P($.findField(w.fields,T.get("PERCENTALONG").name)):new C(new B({name:"percentalong",alias:"percentalong",type:"double"}),K.create("0",{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"junctionedge":{J=`((${x}='${g}') OR ( ${N}='${g}')) AND (${U} IN (4,6))`,Q.codefield=K.create(`CASE WHEN (${x}='${g}') THEN ${S} ELSE ${j} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const e=H($.findField(w.fields,N));e.name=G,e.alias=G,O=new C(e,K.create(`CASE WHEN (${N}='${g}') THEN ${x} ELSE ${N} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC})),W=new C(new B({name:"side",alias:"side",type:"string"}),K.create(`CASE WHEN (${U}=4) THEN 'from' ELSE 'to' END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"connected":{let e=`${x}='@T'`,t=`${N}='@T'`;null!==F&&(e+=` AND ${A}=@A`,t+=` AND ${v}=@A`),J="(("+e+") OR ("+t+"))",J=L(J,"@T",g??""),e=L(e,"@T",g??""),null!==F&&(e=L(e,"@A",F.toString()),J=L(J,"@A",F.toString())),Q.codefield=K.create("CASE WHEN "+e+` THEN ${S} ELSE ${j} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC});const n=H($.findField(w.fields,N));n.name=G,n.alias=G,O=new C(n,K.create("CASE WHEN "+e+` THEN ${N} ELSE ${x} END`,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}));break}case"container":J=`${x}='${g}' AND ${U} = 2`,null!==F&&(J+=` AND ${A} = `+F.toString()),Q.codefield=S,J="( "+J+" )",O=new k($.findField(w.fields,N),G,G);break;case"content":J=`(${N}='${g}' AND ${U} = 2)`,null!==F&&(J+=` AND ${v} = `+F.toString()),Q.codefield=j,J="( "+J+" )",O=new k($.findField(w.fields,x),G,G);break;case"structure":J=`(${x}='${g}' AND ${U} = 3)`,null!==F&&(J+=` AND ${A} = `+F.toString()),Q.codefield=S,J="( "+J+" )",O=new k($.findField(w.fields,N),G,V);break;case"attached":J=`(${N}='${g}' AND ${U} = 3)`,null!==F&&(J+=` AND ${v} = `+F.toString()),Q.codefield=j,J="( "+J+" )",O=new k($.findField(w.fields,x),G,V);break;default:throw new a(t,r.InvalidParameter,n)}b&&(J="1 <> 1");return new $({parentfeatureset:w,adaptedFields:[new P($.findField(w.fields,R)),new P($.findField(w.fields,M)),O,W,Q,z],extraFilter:J?K.create(J,{fieldsIndex:w.getFieldsIndex(),timeZone:w.dateFieldsTimeZoneDefaultUTC}):null})}))},e.signatures.push({name:"featuresetbyassociation",min:2,max:6}),e.functions.groupby=function(t,n){return e.standardFunctionAsync(t,n,(async(o,s,l)=>{if(p(l,3,3,t,n),!h(l[0]))throw new a(t,r.InvalidParameter,n);const f=await l[0].load(),d=[],u=[];let c=!1,m=[];if(ee(l[1]))m.push(l[1]);else if(l[1]instanceof i)m.push(l[1]);else if(te(l[1]))m=l[1];else{if(!N(l[1]))throw new a(t,r.InvalidParameter,n);m=l[1].toArray()}for(const e of m)if(ee(e)){const t=K.create(I(e),{fieldsIndex:f.getFieldsIndex(),timeZone:f.dateFieldsTimeZoneDefaultUTC}),n=!0===G(t)?I(e):"%%%%FIELDNAME";d.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(c=!0)}else{if(!(e instanceof i))throw new a(t,r.InvalidParameter,n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",o=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(c=!0),!i)throw new a(t,r.InvalidParameter,n);d.push({name:i,expression:K.create(o||i,{fieldsIndex:f.getFieldsIndex(),timeZone:f.dateFieldsTimeZoneDefaultUTC})})}}if(m=[],ee(l[2]))m.push(l[2]);else if(te(l[2]))m=l[2];else if(N(l[2]))m=l[2].toArray();else{if(!(l[2]instanceof i))throw new a(t,r.InvalidParameter,n);m.push(l[2])}for(const e of m){if(!(e instanceof i))throw new a(t,r.InvalidParameter,n);{const i=e.hasField("name")?e.field("name"):"",o=e.hasField("statistic")?e.field("statistic"):"",s=e.hasField("expression")?e.field("expression"):"";if(!i||!o||!s)throw new a(t,r.InvalidParameter,n);u.push({name:i,statistic:o.toLowerCase(),expression:K.create(s,{fieldsIndex:f.getFieldsIndex(),timeZone:f.dateFieldsTimeZoneDefaultUTC})})}}if(c){const e={};for(const n of f.fields)e[n.name.toLowerCase()]=1;for(const n of d)"%%%%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 d)if("%%%%FIELDNAME"===n.name){for(;1===e["field_"+t.toString()];)t++;e["field_"+t.toString()]=1,n.name="FIELD_"+t.toString()}}for(const n of d)ae(n.expression,e,t);for(const n of u)ae(n.expression,e,t);return l[0].groupby(d,u)}))},e.signatures.push({name:"groupby",min:3,max:3}),e.functions.distinct=function(t,n){return e.standardFunctionAsync(t,n,(async(o,s,l)=>{if(h(l[0])){p(l,2,2,t,n);const o=await l[0].load(),s=[];let f=[];if(ee(l[1]))f.push(l[1]);else if(l[1]instanceof i)f.push(l[1]);else if(te(l[1]))f=l[1];else{if(!N(l[1]))throw new a(t,r.InvalidParameter,n);f=l[1].toArray()}let d=!1;for(const e of f)if(ee(e)){const t=K.create(I(e),{fieldsIndex:o.getFieldsIndex(),timeZone:o.dateFieldsTimeZoneDefaultUTC}),n=!0===G(t)?I(e):"%%%%FIELDNAME";s.push({name:n,expression:t}),"%%%%FIELDNAME"===n&&(d=!0)}else{if(!(e instanceof i))throw new a(t,r.InvalidParameter,n);{const i=e.hasField("name")?e.field("name"):"%%%%FIELDNAME",l=e.hasField("expression")?e.field("expression"):"";if("%%%%FIELDNAME"===i&&(d=!0),!i)throw new a(t,r.InvalidParameter,n);s.push({name:i,expression:K.create(l||i,{fieldsIndex:o.getFieldsIndex(),timeZone:o.dateFieldsTimeZoneDefaultUTC})})}}if(d){const e={};for(const n of o.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 n of s)ae(n.expression,e,t);return l[0].groupby(s,[])}return ie(l)}))},e.functions.getfeaturesetinfo=function(t,n){return e.standardFunctionAsync(t,n,(async(e,a,r)=>{if(p(r,1,1,t,n),!h(r[0]))return null;const o=await r[0].getFeatureSetInfo();return o?i.convertObjectToArcadeDictionary({layerId:o.layerId,layerName:o.layerName,itemId:o.itemId,serviceLayerUrl:o.serviceLayerUrl,webMapLayerId:o.webMapLayerId??null,webMapLayerTitle:o.webMapLayerTitle??null,className:null,objectClassId:null},F(t),!1,!1):null}))},e.signatures.push({name:"getfeaturesetinfo",min:1,max:1}),e.functions.filterbysubtypecode=function(t,n){return e.standardFunctionAsync(t,n,(async(e,i,o)=>{if(p(o,2,2,t,n),h(o[0])){const e=await o[0].load(),i=o[1];if(!ne(i))throw new a(t,r.InvalidParameter,n);if(e.subtypeField){const t=K.create(`${e.subtypeField}= ${o[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:o[0],whereclause:t})}if(null===e.typeIdField||""===e.typeIdField)throw new a(t,r.FeatureSetDoesNotHaveSubtypes,n);const s=K.create(`${e.typeIdField}= ${o[1]}`,{fieldsIndex:e.getFieldsIndex(),timeZone:e.dateFieldsTimeZoneDefaultUTC});return new U({parentfeatureset:o[0],whereclause:s})}throw new a(t,r.InvalidParameter,n)}))},e.signatures.push({name:"filterbysubtypecode",min:2,max:2}))}export{me as registerFunctions};
|