@arcgis/core 4.28.0-next.20230911 → 4.28.0-next.20230912
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/Feature.js +1 -1
- package/arcade/arcadeTimeUtils.js +1 -1
- package/arcade/executionError.js +1 -1
- package/arcade/featureSetUtils.js +1 -1
- package/arcade/featureset/actions/Adapted.js +1 -1
- package/arcade/featureset/actions/GroupBy.js +1 -1
- package/arcade/featureset/support/FeatureSet.js +1 -1
- package/arcade/featureset/support/errorsupport.js +1 -1
- package/arcade/functions/featuresetbase.js +1 -1
- package/arcade/functions/featuresetstats.js +1 -1
- package/arcade/functions/string.js +1 -1
- package/assets/esri/core/workers/RemoteClient.js +1 -1
- package/assets/esri/core/workers/chunks/0920312e3c7b63c2e253.js +1 -0
- package/assets/esri/core/workers/chunks/0cb007ab5db0a2a598ec.js +1 -0
- package/assets/esri/core/workers/chunks/0cc61f1b2c0473ded5c2.js +1 -0
- package/assets/esri/core/workers/chunks/0f804e3f888cb4998f46.js +1 -0
- package/assets/esri/core/workers/chunks/189dd81cf95bd8417ee3.js +1 -0
- package/assets/esri/core/workers/chunks/1a723bb4a341f645e5fe.js +1 -0
- package/assets/esri/core/workers/chunks/24c717492ea1b35310d8.js +1 -0
- package/assets/esri/core/workers/chunks/{3ce73dd4113dbc7d11de.js → 2eb58dc339b2bb03d9e3.js} +1 -1
- package/assets/esri/core/workers/chunks/{38c07a8574352a7f2f6d.js → 2ff0dbd5eb7ca57bb7fc.js} +1 -1
- package/assets/esri/core/workers/chunks/{768f3db2705fa9e57641.js → 49dfdc0463450491df9d.js} +1 -1
- package/assets/esri/core/workers/chunks/650a317b6dc245a7060f.js +1 -0
- package/assets/esri/core/workers/chunks/{56ed099745360888604e.js → 67f01c71280fa0759742.js} +1 -1
- package/assets/esri/core/workers/chunks/{f62842807744bdfaced7.js → 67fab13f56b340076763.js} +1 -1
- package/assets/esri/core/workers/chunks/718607d7a3b33fc33b0a.js +1 -0
- package/assets/esri/core/workers/chunks/{4c63d6b9460aa6ae9843.js → 860417f4138f53d315ba.js} +2 -2
- package/assets/esri/core/workers/chunks/9fa485b04b997b0a5509.js +1 -0
- package/assets/esri/core/workers/chunks/a753d9874801cd448946.js +1 -0
- package/assets/esri/core/workers/chunks/aa78ca83a4b582b6c2b6.js +1 -0
- package/assets/esri/core/workers/chunks/aedb1f944b332b098933.js +1 -0
- package/assets/esri/core/workers/chunks/c61f20d91a5c432b07dc.js +1 -0
- package/assets/esri/core/workers/chunks/d3d11242e5af57ba77f4.js +1 -0
- package/assets/esri/core/workers/chunks/e8a8791d765ab6c450dd.js +1 -0
- package/assets/esri/core/workers/chunks/{5fe7b5665710ec6d3046.js → eb0d1c5c96f735c162d3.js} +1 -1
- package/chunks/HUDMaterial.glsl.js +38 -45
- package/chunks/languageUtils.js +1 -1
- package/core/sql/AggregateFunctions.js +1 -1
- package/core/sql/SqlTimestampOffset.js +1 -1
- package/core/sql/WhereClause.js +1 -1
- package/core/sql/WhereGrammar.js +1 -1
- package/core/sql/sqlCompareUtils.js +1 -1
- package/geometry/GeometryCursor.js +1 -1
- package/geometry/Mesh.js +1 -1
- package/geometry/support/labelPoint.js +1 -1
- package/geometry/support/meshUtils/bounds.js +1 -1
- package/geometry/support/meshUtils/georeference.js +1 -1
- package/layers/ImageryLayer.js +1 -1
- package/layers/graphics/controllers/I3SOnDemandController.js +1 -1
- package/layers/graphics/sources/csv/csv.js +1 -1
- package/layers/support/fieldUtils.js +1 -1
- package/layers/support/wmsUtils.js +1 -1
- package/package.json +3 -3
- package/smartMapping/heuristics/sizeRange.js +1 -1
- package/smartMapping/labels/bins.js +1 -1
- package/smartMapping/labels/clusters.js +1 -1
- package/smartMapping/labels/support/utils.js +1 -1
- package/smartMapping/popup/support/clusterUtils.js +1 -1
- package/smartMapping/support/clusterUtils.js +1 -1
- package/support/revision.js +1 -1
- package/views/3d/analysis/AreaMeasurement/support/AreaMeasurementVisualization.js +1 -1
- package/views/3d/analysis/AreaMeasurement/support/MeasurementData.js +1 -1
- package/views/3d/interactive/Manipulator3D.js +1 -1
- package/views/3d/interactive/editingTools/reshapeGraphic/ReshapeOperation.js +1 -1
- package/views/3d/interactive/measurementTools/areaMeasurement3D/AreaMeasurement3DTool.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/I3SMeshWorkerHandle.js +1 -1
- package/views/3d/layers/ImageryTileLayerView3D.js +1 -1
- package/views/3d/layers/SceneLayerWorker.js +1 -1
- package/views/3d/layers/i3s/I3SClientNodeLoader.js +1 -1
- package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
- package/views/3d/webgl-engine/shaders/HUDMaterialTechniqueConfiguration.js +1 -1
- package/views/ToolViewManager.js +1 -1
- package/views/View.js +1 -1
- package/views/webgl/FramebufferObject.js +1 -1
- package/views/webgl/RenderingContext.js +1 -1
- package/views/webgl/enums.js +1 -1
- package/views/webgl/renderState.js +1 -1
- package/widgets/FeatureForm.js +1 -1
- package/widgets/Search/SearchViewModel.js +1 -1
- package/assets/esri/core/workers/chunks/055575ed2ab78be0bdb2.js +0 -1
- package/assets/esri/core/workers/chunks/0ee90a0b4d09a56c0d48.js +0 -1
- package/assets/esri/core/workers/chunks/344e40934c98d6fe66ae.js +0 -1
- package/assets/esri/core/workers/chunks/558049fcac3a82a093fc.js +0 -1
- package/assets/esri/core/workers/chunks/5c41eb67d19b8710118a.js +0 -1
- package/assets/esri/core/workers/chunks/5d183ac1a8b68ba9c656.js +0 -1
- package/assets/esri/core/workers/chunks/610d4a5d2511fa81460e.js +0 -1
- package/assets/esri/core/workers/chunks/6755bb1f2a6575a8e082.js +0 -1
- package/assets/esri/core/workers/chunks/84173936b309712ba9b3.js +0 -1
- package/assets/esri/core/workers/chunks/a07dc782e69111e2eeaf.js +0 -1
- package/assets/esri/core/workers/chunks/b825019841247d173072.js +0 -1
- package/assets/esri/core/workers/chunks/bed1bc13b168fae46404.js +0 -1
- package/assets/esri/core/workers/chunks/ccc3564e76c0ec5c0228.js +0 -1
- package/assets/esri/core/workers/chunks/d0a81c7ec8a84eeadd31.js +0 -1
- package/assets/esri/core/workers/chunks/e7a852b319c1d89eddc5.js +0 -1
- package/assets/esri/core/workers/chunks/ebde11fdccb437954ce7.js +0 -1
package/arcade/Feature.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{ArcadeDate as e}from"./ArcadeDate.js";import{DateTimeReferenceFieldIndex as t}from"./arcadeTimeUtils.js";import{configureDeepClone as i}from"./deepClone.js";import s from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as n}from"./executionError.js";import a from"./ImmutableArray.js";import{a as o,b as l,c as f,t as u,n as d,m as c,k as m,f as y,d as h}from"../chunks/languageUtils.js";import{DateOnly as p}from"../core/sql/DateOnly.js";import{TimeOnly as _}from"../core/sql/TimeOnly.js";import T from"../geometry/Geometry.js";import b from"../geometry/Point.js";import{fromJSON as g}from"../geometry/support/jsonUtils.js";import{convertToGeometry as F}from"../layers/graphics/featureConversionUtils.js";class x{constructor(){this.arcadeDeclaredClass="esri.arcade.Feature",this._optimizedGeomDefinition=null,this._geometry=null,this.attributes=null,this._layer=null,this._fieldTypesFixed=!0,this.dateTimeReferenceFieldIndex=null,this.contextTimeReference=null,this.immutable=!0,this._fieldsToFixDataTypes=null,this.immutable=!0}static createFromGraphic(e,i){const s=new x;return s.contextTimeReference=i??null,s._geometry=null!=e.geometry?e.geometry:null,void 0===e.attributes||null===e.attributes?s.attributes={}:s.attributes=e.attributes,e._sourceLayer?(s._layer=e._sourceLayer,s._fieldTypesFixed=!1):e._layer?(s._layer=e._layer,s._fieldTypesFixed=!1):e.layer&&"fields"in e.layer?(s._layer=e.layer,s._fieldTypesFixed=!1):e.sourceLayer&&"fields"in e.sourceLayer&&(s._layer=e.sourceLayer,s._fieldTypesFixed=!1),s._layer&&!s._fieldTypesFixed&&(void 0!==s._layer.dateTimeReferenceFieldIndex?s.dateTimeReferenceFieldIndex=s._layer.dateTimeReferenceFieldIndex:s.dateTimeReferenceFieldIndex=t.createFromLayer(s._layer)),s}static createFromArcadeFeature(e){if(e instanceof x){const t=new x;return t._fieldTypesFixed=e._fieldTypesFixed,t.attributes=e.attributes,t._geometry=e._geometry,t._optimizedGeomDefinition=e._optimizedGeomDefinition,e._layer&&(t._layer=e._layer),t.dateTimeReferenceFieldIndex=e.dateTimeReferenceFieldIndex,t.contextTimeReference=e.contextTimeReference,t}const t={};for(const i of e.keys())t[i]=e.field(i);return x.createFromGraphicLikeObject(e.geometry(),t,e.fullSchema(),e.contextTimeReference)}static createFromOptimisedFeature(e,t,i){const s=new x;return s._geometry=e.geometry?{geometry:e.geometry}:null,s._optimizedGeomDefinition=i,s.attributes=e.attributes||{},s._layer=t,s._fieldTypesFixed=!1,s}static createFromArcadeDictionary(e){const t=new x;return t.attributes=e.field("attributes"),null!==t.attributes&&t.attributes instanceof s?(t.attributes=t.attributes.attributes,null===t.attributes&&(t.attributes={})):t.attributes={},t._geometry=e.field("geometry"),null!==t._geometry&&(t._geometry instanceof s?t._geometry=x.parseGeometryFromDictionary(t._geometry):t._geometry instanceof T||(t._geometry=null)),t}static createFromGraphicLikeObject(e,i,s=null,r){const n=new x;return n.contextTimeReference=r??null,null===i&&(i={}),n.attributes=i,n._geometry=null!=e?e:null,n._layer=s,n._layer&&(n._fieldTypesFixed=!1,void 0!==n._layer.dateTimeReferenceFieldIndex?n.dateTimeReferenceFieldIndex=n._layer.dateTimeReferenceFieldIndex:n.dateTimeReferenceFieldIndex=t.createFromLayer(n._layer)),n}repurposeFromGraphicLikeObject(e,t,i=null){null===t&&(t={}),this.attributes=t,this._geometry=e??null,this._layer=i,this._layer?this._fieldTypesFixed=!1:this._fieldTypesFixed=!0}get layerPreferredTimeZone(){return this.dateTimeReferenceFieldIndex?.layerPreferredTimeZone??""}fieldSourceTimeZone(e){return this.dateTimeReferenceFieldIndex?.fieldTimeZone(e)??""}castToText(t=!1){let i="";!1===this._fieldTypesFixed&&this._fixFieldTypes();for(const s in this.attributes){""!==i&&(i+=",");const r=this.attributes[s];null==r?i+=JSON.stringify(s)+":null":o(r)||l(r)||f(r)?i+=JSON.stringify(s)+":"+JSON.stringify(r):r instanceof T?i+=JSON.stringify(s)+":"+u(r):r instanceof _||r instanceof p?i+=`${JSON.stringify(s)}:${JSON.stringify(r.toString())}`:r instanceof a||r instanceof Array?i+=JSON.stringify(s)+":"+u(r,null,t):r instanceof e?i+=t?JSON.stringify(s)+":"+JSON.stringify(r.getTime()):JSON.stringify(s)+":"+r.stringify():null!==r&&"object"==typeof r&&void 0!==r.castToText&&(i+=JSON.stringify(s)+":"+r.castToText(t))}return'{"geometry":'+(null===this.geometry()?"null":u(this.geometry()))+',"attributes":{'+i+"}}"}_fixFieldTypes(){if(this._fieldsToFixDataTypes&&this._fieldsToFixDataTypes?.length>0)return this._fixAllFields(this._fieldsToFixDataTypes),void(this._fieldTypesFixed=!0);const e=[],t=this._layer.fields;for(let i=0;i<t.length;i++){const s=t[i],{name:r,type:n}=s;switch(n){case"date":case"esriFieldTypeDate":e.push({field:r,dataType:"date"});break;case"date-only":case"esriFieldTypeDateOnly":e.push({field:r,dataType:"date-only"});break;case"time-only":case"esriFieldTypeTimeOnly":e.push({field:r,dataType:"time-only"});break;case"timestamp-offset":case"esriFieldTypeTimestampOffset":e.push({field:r,dataType:"timestamp-offset"})}}this._fieldsToFixDataTypes=e,e.length>0&&this._fixAllFields(e),this._fieldTypesFixed=!0}isUnknownDateTimeField(e){return"unknown"===this.dateTimeReferenceFieldIndex?.fieldTimeZone(e)}_fixAllFields(t){this.attributes={...this.attributes};const i=this.contextTimeReference?.timeZone??"system";for(let s=0;s<t.length;s++){const r=t[s].field,n=t[s].dataType;let a=this.attributes[r];if(void 0===a){for(const t in this.attributes)if(t.toLowerCase()===r.toLowerCase()){if(a=this.attributes[t],null!==a){if("time-only"===n){d(a)||(this.attributes[t]=_.fromReader(a.toString()));break}if("date-only"===n){c(a)||(this.attributes[t]=p.fromReader(a.toString()));break}if("timestamp-offset"===n){m(a)||(this.attributes[t]=e.fromReaderAsTimeStampOffset(a.toString()));break}const s=this.isUnknownDateTimeField(t);a instanceof Date?this.attributes[t]=s?e.unknownDateJSToArcadeDate(a):e.dateJSAndZoneToArcadeDate(a,i):m(a)||(this.attributes[t]=s?e.unknownEpochToArcadeDate(a):e.epochToArcadeDate(a,i))}break}}else if(null!==a){if("time-only"===n){d(a)?this.attributes[r]=a:this.attributes[r]=_.fromReader(a.toString());continue}if("date-only"===n){c(a)?this.attributes[r]=a:this.attributes[r]=p.fromReader(a.toString());break}if("timestamp-offset"===n){m(a)?this.attributes[r]=a:this.attributes[r]=e.fromReaderAsTimeStampOffset(a.toString());break}const t=this.isUnknownDateTimeField(r);m(a)?this.attributes[r]=a:a instanceof Date?this.attributes[r]=t?e.unknownDateJSToArcadeDate(a):e.dateJSAndZoneToArcadeDate(a,i):this.attributes[r]=t?e.unknownEpochToArcadeDate(a):e.epochToArcadeDate(a,i)}}}geometry(){return null===this._geometry||this._geometry instanceof T||(this._optimizedGeomDefinition?(this._geometry=g(F(this._geometry,this._optimizedGeomDefinition.geometryType,this._optimizedGeomDefinition.hasZ,this._optimizedGeomDefinition.hasM)),this._geometry.spatialReference=this._optimizedGeomDefinition.spatialReference):this._geometry=g(this._geometry)),this._geometry}field(e){this._fieldTypesFixed||this._fixFieldTypes();const t=this.attributes[e];if(void 0!==t)return t;const i=e.toLowerCase();for(const s in this.attributes)if(s.toLowerCase()===i)return this.attributes[s];if(this._hasFieldDefinition(i))return null;throw new r(null,n.FieldNotFound,null,{key:e})}_hasFieldDefinition(e){if(null===this._layer)return!1;for(let t=0;t<this._layer.fields.length;t++){if(this._layer.fields[t].name.toLowerCase()===e)return!0}return!1}setField(t,i){if(this.immutable)throw new r(null,n.Immutable,null);if(i instanceof Date&&(i=this.isUnknownDateTimeField(t)?e.unknownDateJSToArcadeDate(i):e.dateJSToArcadeDate(i)),!1===y(i))throw new r(null,n.TypeNotAllowedInFeature,null);const s=t.toLowerCase();if(void 0===this.attributes[t]){for(const e in this.attributes)if(e.toLowerCase()===s)return void(this.attributes[e]=i);this.attributes[t]=i}else this.attributes[t]=i}hasField(e){const t=e.toLowerCase();if(void 0!==this.attributes[e])return!0;for(const i in this.attributes)if(i.toLowerCase()===t)return!0;return!!this._hasFieldDefinition(t)}keys(){let e=[];const t={};for(const i in this.attributes)e.push(i),t[i.toLowerCase()]=1;if(null!==this._layer)for(let i=0;i<this._layer.fields.length;i++){const s=this._layer.fields[i];1!==t[s.name.toLowerCase()]&&e.push(s.name)}return e=e.sort(),e}static parseGeometryFromDictionary(e){const t=x._convertDictionaryToJson(e,!0);return void 0!==t.hasm&&(t.hasM=t.hasm,delete t.hasm),void 0!==t.hasz&&(t.hasZ=t.hasz,delete t.hasz),void 0!==t.spatialreference&&(t.spatialReference=t.spatialreference,delete t.spatialreference),void 0!==t.rings&&(t.rings=this._fixPathArrays(t.rings,!0===t.hasZ,!0===t.hasZ)),void 0!==t.paths&&(t.paths=this._fixPathArrays(t.paths,!0===t.hasZ,!0===t.hasM)),void 0!==t.points&&(t.points=this._fixPointArrays(t.points,!0===t.hasZ,!0===t.hasM)),g(t)}static _fixPathArrays(e,t,i){const s=[];if(e instanceof Array)for(let r=0;r<e.length;r++)s.push(this._fixPointArrays(e[r],t,i));else if(e instanceof a)for(let r=0;r<e.length();r++)s.push(this._fixPointArrays(e.get(r),t,i));return s}static _fixPointArrays(e,t,i){const s=[];if(e instanceof Array)for(let r=0;r<e.length;r++){const n=e[r];n instanceof b?t&&i?s.push([n.x,n.y,n.z,n.m]):t?s.push([n.x,n.y,n.z]):i?s.push([n.x,n.y,n.m]):s.push([n.x,n.y]):n instanceof a?s.push(n.toArray()):s.push(n)}else if(e instanceof a)for(let r=0;r<e.length();r++){const n=e.get(r);n instanceof b?t&&i?s.push([n.x,n.y,n.z,n.m]):t?s.push([n.x,n.y,n.z]):i?s.push([n.x,n.y,n.m]):s.push([n.x,n.y]):n instanceof a?s.push(n.toArray()):s.push(n)}return s}static _convertDictionaryToJson(e,t=!1){const i={};for(const r in e.attributes){let n=e.attributes[r];n instanceof s&&(n=x._convertDictionaryToJson(n)),t?i[r.toLowerCase()]=n:i[r]=n}return i}static parseAttributesFromDictionary(e){const t={};for(const i in e.attributes){const s=e.attributes[i];if(!y(s))throw new r(null,n.InvalidParameter,null);t[i]=s}return t}static fromJson(e,t){let i=null;null!==e.geometry&&void 0!==e.geometry&&(i=g(e.geometry));const s={};if(null!==e.attributes&&void 0!==e.attributes)for(const a in e.attributes){const t=e.attributes[a];if(null===t)s[a]=t;else{if(!(f(t)||l(t)||o(t)||m(t)||d(t)||c(t)))throw new r(null,n.InvalidParameter,null);s[a]=t}}return x.createFromGraphicLikeObject(i,s,null,t??null)}fullSchema(){return this._layer}gdbVersion(){if(null===this._layer)return"";const e=this._layer.gdbVersion;return void 0===e?"":""===e&&this._layer.capabilities&&this._layer.capabilities.isVersioned?"SDE.DEFAULT":e}castAsJson(e){const t={attributes:{},geometry:!0===e?.keepGeometryType?this.geometry():this.geometry()?.toJSON()??null};for(const i in this.attributes){const s=this.attributes[i];void 0!==s&&(t.attributes[i]=h(s,e))}return t}async castAsJsonAsync(e=null,t){return this.castAsJson(t)}}i(x);export{x as default};
|
|
5
|
+
import{ArcadeDate as e}from"./ArcadeDate.js";import{DateTimeReferenceFieldIndex as t}from"./arcadeTimeUtils.js";import{configureDeepClone as i}from"./deepClone.js";import s from"./Dictionary.js";import{ArcadeExecutionError as r,ExecutionErrorCodes as n}from"./executionError.js";import a from"./ImmutableArray.js";import{a as o,b as l,c as f,t as u,n as d,m as c,k as m,f as y,d as h}from"../chunks/languageUtils.js";import{DateOnly as p}from"../core/sql/DateOnly.js";import{TimeOnly as _}from"../core/sql/TimeOnly.js";import T from"../geometry/Geometry.js";import b from"../geometry/Point.js";import{fromJSON as g}from"../geometry/support/jsonUtils.js";import{convertToGeometry as F}from"../layers/graphics/featureConversionUtils.js";class x{constructor(){this.arcadeDeclaredClass="esri.arcade.Feature",this._optimizedGeomDefinition=null,this._geometry=null,this.attributes=null,this._layer=null,this._fieldTypesFixed=!0,this.dateTimeReferenceFieldIndex=null,this.contextTimeReference=null,this.immutable=!0,this._fieldsToFixDataTypes=null,this.immutable=!0}static createFromGraphic(e,i){const s=new x;return s.contextTimeReference=i??null,s._geometry=null!=e.geometry?e.geometry:null,void 0===e.attributes||null===e.attributes?s.attributes={}:s.attributes=e.attributes,e._sourceLayer?(s._layer=e._sourceLayer,s._fieldTypesFixed=!1):e._layer?(s._layer=e._layer,s._fieldTypesFixed=!1):e.layer&&"fields"in e.layer?(s._layer=e.layer,s._fieldTypesFixed=!1):e.sourceLayer&&"fields"in e.sourceLayer&&(s._layer=e.sourceLayer,s._fieldTypesFixed=!1),s._layer&&!s._fieldTypesFixed&&(void 0!==s._layer.dateTimeReferenceFieldIndex?s.dateTimeReferenceFieldIndex=s._layer.dateTimeReferenceFieldIndex:s.dateTimeReferenceFieldIndex=t.createFromLayer(s._layer)),s}static createFromArcadeFeature(e){if(e instanceof x){const t=new x;return t._fieldTypesFixed=e._fieldTypesFixed,t.attributes=e.attributes,t._geometry=e._geometry,t._optimizedGeomDefinition=e._optimizedGeomDefinition,e._layer&&(t._layer=e._layer),t.dateTimeReferenceFieldIndex=e.dateTimeReferenceFieldIndex,t.contextTimeReference=e.contextTimeReference,t}const t={};for(const i of e.keys())t[i]=e.field(i);return x.createFromGraphicLikeObject(e.geometry(),t,e.fullSchema(),e.contextTimeReference)}static createFromOptimisedFeature(e,t,i){const s=new x;return s._geometry=e.geometry?{geometry:e.geometry}:null,s._optimizedGeomDefinition=i,s.attributes=e.attributes||{},s._layer=t,s._fieldTypesFixed=!1,s}static createFromArcadeDictionary(e){const t=new x;return t.attributes=e.field("attributes"),null!==t.attributes&&t.attributes instanceof s?(t.attributes=t.attributes.attributes,null===t.attributes&&(t.attributes={})):t.attributes={},t._geometry=e.field("geometry"),null!==t._geometry&&(t._geometry instanceof s?t._geometry=x.parseGeometryFromDictionary(t._geometry):t._geometry instanceof T||(t._geometry=null)),t}static createFromGraphicLikeObject(e,i,s=null,r){const n=new x;return n.contextTimeReference=r??null,null===i&&(i={}),n.attributes=i,n._geometry=null!=e?e:null,n._layer=s,n._layer&&(n._fieldTypesFixed=!1,void 0!==n._layer.dateTimeReferenceFieldIndex?n.dateTimeReferenceFieldIndex=n._layer.dateTimeReferenceFieldIndex:n.dateTimeReferenceFieldIndex=t.createFromLayer(n._layer)),n}repurposeFromGraphicLikeObject(e,t,i=null){null===t&&(t={}),this.attributes=t,this._geometry=e??null,this._layer=i,this._layer?this._fieldTypesFixed=!1:this._fieldTypesFixed=!0}get layerPreferredTimeZone(){return this.dateTimeReferenceFieldIndex?.layerPreferredTimeZone??""}fieldSourceTimeZone(e){return this.dateTimeReferenceFieldIndex?.fieldTimeZone(e)??""}castToText(t=!1){let i="";!1===this._fieldTypesFixed&&this._fixFieldTypes();for(const s in this.attributes){""!==i&&(i+=",");const r=this.attributes[s];null==r?i+=JSON.stringify(s)+":null":o(r)||l(r)||f(r)?i+=JSON.stringify(s)+":"+JSON.stringify(r):r instanceof T?i+=JSON.stringify(s)+":"+u(r):r instanceof _||r instanceof p?i+=`${JSON.stringify(s)}:${JSON.stringify(r.toString())}`:r instanceof a||r instanceof Array?i+=JSON.stringify(s)+":"+u(r,null,t):r instanceof e?i+=t?JSON.stringify(s)+":"+JSON.stringify(r.getTime()):JSON.stringify(s)+":"+r.stringify():null!==r&&"object"==typeof r&&void 0!==r.castToText&&(i+=JSON.stringify(s)+":"+r.castToText(t))}return'{"geometry":'+(null===this.geometry()?"null":u(this.geometry()))+',"attributes":{'+i+"}}"}_fixFieldTypes(){if(this._fieldsToFixDataTypes&&this._fieldsToFixDataTypes?.length>0)return this._fixAllFields(this._fieldsToFixDataTypes),void(this._fieldTypesFixed=!0);const e=[],t=this._layer.fields;for(let i=0;i<t.length;i++){const s=t[i],{name:r,type:n}=s;switch(n){case"date":case"esriFieldTypeDate":e.push({field:r,dataType:"date"});break;case"date-only":case"esriFieldTypeDateOnly":e.push({field:r,dataType:"date-only"});break;case"time-only":case"esriFieldTypeTimeOnly":e.push({field:r,dataType:"time-only"});break;case"timestamp-offset":case"esriFieldTypeTimestampOffset":e.push({field:r,dataType:"timestamp-offset"})}}this._fieldsToFixDataTypes=e,e.length>0&&this._fixAllFields(e),this._fieldTypesFixed=!0}isUnknownDateTimeField(e){return"unknown"===this.dateTimeReferenceFieldIndex?.fieldTimeZone(e)}_fixAllFields(t){this.attributes={...this.attributes};const i=this.contextTimeReference?.timeZone??"system";for(let s=0;s<t.length;s++){const r=t[s].field,n=t[s].dataType;let a=this.attributes[r];if(void 0===a){for(const t in this.attributes)if(t.toLowerCase()===r.toLowerCase()){if(a=this.attributes[t],null!==a){if("time-only"===n){d(a)||(this.attributes[t]=_.fromReader(a.toString()));break}if("date-only"===n){c(a)||(this.attributes[t]=p.fromReader(a.toString()));break}if("timestamp-offset"===n){m(a)||(this.attributes[t]=e.fromReaderAsTimeStampOffset(a.toString()));break}const s=this.isUnknownDateTimeField(t);a instanceof Date?this.attributes[t]=s?e.unknownDateJSToArcadeDate(a):e.dateJSAndZoneToArcadeDate(a,i):m(a)||(this.attributes[t]=s?e.unknownEpochToArcadeDate(a):e.epochToArcadeDate(a,i))}break}}else if(null!==a){if("time-only"===n){d(a)?this.attributes[r]=a:this.attributes[r]=_.fromReader(a.toString());continue}if("date-only"===n){c(a)?this.attributes[r]=a:this.attributes[r]=p.fromReader(a.toString());continue}if("timestamp-offset"===n){m(a)?this.attributes[r]=a:this.attributes[r]=e.fromReaderAsTimeStampOffset(a.toString());continue}const t=this.isUnknownDateTimeField(r);m(a)?this.attributes[r]=a:a instanceof Date?this.attributes[r]=t?e.unknownDateJSToArcadeDate(a):e.dateJSAndZoneToArcadeDate(a,i):this.attributes[r]=t?e.unknownEpochToArcadeDate(a):e.epochToArcadeDate(a,i)}}}geometry(){return null===this._geometry||this._geometry instanceof T||(this._optimizedGeomDefinition?(this._geometry=g(F(this._geometry,this._optimizedGeomDefinition.geometryType,this._optimizedGeomDefinition.hasZ,this._optimizedGeomDefinition.hasM)),this._geometry.spatialReference=this._optimizedGeomDefinition.spatialReference):this._geometry=g(this._geometry)),this._geometry}field(e){this._fieldTypesFixed||this._fixFieldTypes();const t=this.attributes[e];if(void 0!==t)return t;const i=e.toLowerCase();for(const s in this.attributes)if(s.toLowerCase()===i)return this.attributes[s];if(this._hasFieldDefinition(i))return null;throw new r(null,n.FieldNotFound,null,{key:e})}_hasFieldDefinition(e){if(null===this._layer)return!1;for(let t=0;t<this._layer.fields.length;t++){if(this._layer.fields[t].name.toLowerCase()===e)return!0}return!1}setField(t,i){if(this.immutable)throw new r(null,n.Immutable,null);if(i instanceof Date&&(i=this.isUnknownDateTimeField(t)?e.unknownDateJSToArcadeDate(i):e.dateJSToArcadeDate(i)),!1===y(i))throw new r(null,n.TypeNotAllowedInFeature,null);const s=t.toLowerCase();if(void 0===this.attributes[t]){for(const e in this.attributes)if(e.toLowerCase()===s)return void(this.attributes[e]=i);this.attributes[t]=i}else this.attributes[t]=i}hasField(e){const t=e.toLowerCase();if(void 0!==this.attributes[e])return!0;for(const i in this.attributes)if(i.toLowerCase()===t)return!0;return!!this._hasFieldDefinition(t)}keys(){let e=[];const t={};for(const i in this.attributes)e.push(i),t[i.toLowerCase()]=1;if(null!==this._layer)for(let i=0;i<this._layer.fields.length;i++){const s=this._layer.fields[i];1!==t[s.name.toLowerCase()]&&e.push(s.name)}return e=e.sort(),e}static parseGeometryFromDictionary(e){const t=x._convertDictionaryToJson(e,!0);return void 0!==t.hasm&&(t.hasM=t.hasm,delete t.hasm),void 0!==t.hasz&&(t.hasZ=t.hasz,delete t.hasz),void 0!==t.spatialreference&&(t.spatialReference=t.spatialreference,delete t.spatialreference),void 0!==t.rings&&(t.rings=this._fixPathArrays(t.rings,!0===t.hasZ,!0===t.hasZ)),void 0!==t.paths&&(t.paths=this._fixPathArrays(t.paths,!0===t.hasZ,!0===t.hasM)),void 0!==t.points&&(t.points=this._fixPointArrays(t.points,!0===t.hasZ,!0===t.hasM)),g(t)}static _fixPathArrays(e,t,i){const s=[];if(e instanceof Array)for(let r=0;r<e.length;r++)s.push(this._fixPointArrays(e[r],t,i));else if(e instanceof a)for(let r=0;r<e.length();r++)s.push(this._fixPointArrays(e.get(r),t,i));return s}static _fixPointArrays(e,t,i){const s=[];if(e instanceof Array)for(let r=0;r<e.length;r++){const n=e[r];n instanceof b?t&&i?s.push([n.x,n.y,n.z,n.m]):t?s.push([n.x,n.y,n.z]):i?s.push([n.x,n.y,n.m]):s.push([n.x,n.y]):n instanceof a?s.push(n.toArray()):s.push(n)}else if(e instanceof a)for(let r=0;r<e.length();r++){const n=e.get(r);n instanceof b?t&&i?s.push([n.x,n.y,n.z,n.m]):t?s.push([n.x,n.y,n.z]):i?s.push([n.x,n.y,n.m]):s.push([n.x,n.y]):n instanceof a?s.push(n.toArray()):s.push(n)}return s}static _convertDictionaryToJson(e,t=!1){const i={};for(const r in e.attributes){let n=e.attributes[r];n instanceof s&&(n=x._convertDictionaryToJson(n)),t?i[r.toLowerCase()]=n:i[r]=n}return i}static parseAttributesFromDictionary(e){const t={};for(const i in e.attributes){const s=e.attributes[i];if(!y(s))throw new r(null,n.InvalidParameter,null);t[i]=s}return t}static fromJson(e,t){let i=null;null!==e.geometry&&void 0!==e.geometry&&(i=g(e.geometry));const s={};if(null!==e.attributes&&void 0!==e.attributes)for(const a in e.attributes){const t=e.attributes[a];if(null===t)s[a]=t;else{if(!(f(t)||l(t)||o(t)||m(t)||d(t)||c(t)))throw new r(null,n.InvalidParameter,null);s[a]=t}}return x.createFromGraphicLikeObject(i,s,null,t??null)}fullSchema(){return this._layer}gdbVersion(){if(null===this._layer)return"";const e=this._layer.gdbVersion;return void 0===e?"":""===e&&this._layer.capabilities&&this._layer.capabilities.isVersioned?"SDE.DEFAULT":e}castAsJson(e){const t={attributes:{},geometry:!0===e?.keepGeometryType?this.geometry():this.geometry()?.toJSON()??null};for(const i in this.attributes){const s=this.attributes[i];void 0!==s&&(t.attributes[i]=h(s,e))}return t}async castAsJsonAsync(e=null,t){return this.castAsJson(t)}}i(x);export{x 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.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{UnknownTimeZone as e,ArcadeDateError as t,ArcadeDateErrorCodes as i}from"./ArcadeDate.js";import n from"../layers/support/FieldsIndex.js";import a from"../time/TimeReference.js";import{convertLegacyTimeZone as r}from"../time/timeReferenceUtils.js";import{Zone as s,SystemZone as d,FixedOffsetZone as o,IANAZone as f}from"luxon";function l(e){return e instanceof a}function m(n){if(!n)return null;if(l(n)&&(n=c(n.toJSON())),n instanceof s)return n;if("unknown"===n.toLowerCase())return e.instance;if("system"===n.toLowerCase())return d.instance;if("utc"===n.toLowerCase())return o.utcInstance;if(/^[\+\-]?[0-9]{1,2}([:][0-9]{2})?$/.test(n)){const e=o.parseSpecifier("UTC"+(n.startsWith("+")||n.startsWith("-")?"":"+")+n);if(e)return e}const a=f.create(n);if(!a.isValid)throw new t(i.TimeZoneNotRecognized);return a}function c(e){return e?.timeZoneIANA?e?.timeZoneIANA:e?.timeZone?r(e,""):""}class T{constructor(){this.dateTimeReferenceMetaData=null,this._fieldTimeZoneIndex={},this._fieldIndex=null,this._ianaPreferred=null,this._ianaTimeInfo=null,this._ianaEditFields=null,this._ianaLayerDateFields=null}static create(e,t){const i=new T;return i.dateTimeReferenceMetaData=t,i._fieldIndex=e instanceof n?e:new n(e),i}static createFromLayer(e){if(!e)return null;if(!e.fieldsIndex)return!e.declaredClass&&e.fields?T.create(e.fields,e):null;const t=new T;return t._fieldIndex=e.fieldsIndex,t.dateTimeReferenceMetaData={timeInfo:e?.timeInfo?.toJSON()??null,editFieldsInfo:e?.editFieldsInfo?.toJSON()??null,dateFieldsTimeReference:e?.dateFieldsTimeReference?.toJSON()??null,preferredTimeReference:e?.preferredTimeReference?.toJSON()??null,datesInUnknownTimezone:!0===e?.datesInUnknownTimezone},t}fieldTimeZone(e){const t=this._fieldIndex?.get(e);if(!t)return null;if("esriFieldTypeTimestampOffset"===t.type||"esriFieldTypeDateOnly"===t.type||"esriFieldTypeTimeOnly"===t.type||"timestamp-offset"===t.type||"date-only"===t.type||"time-only"===t.type)return"unknown";if("date"!==t.type&&"esriFieldTypeDate"!==t.type)return null;const i=this._fieldTimeZoneIndex[t.name];if(void 0!==i)return i;const n=[{field:this.dateTimeReferenceMetaData?.editFieldsInfo?.creationDateField,timeReference:this.dateTimeReferenceMetaData?.editFieldsInfo?.dateFieldsTimeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone},{field:this.dateTimeReferenceMetaData?.editFieldsInfo?.editDateField,timeReference:this.dateTimeReferenceMetaData?.editFieldsInfo?.dateFieldsTimeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone},{field:this.dateTimeReferenceMetaData?.timeInfo?.startTimeField,timeReference:this.dateTimeReferenceMetaData?.timeInfo?.timeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone},{field:this.dateTimeReferenceMetaData?.timeInfo?.endTimeField,timeReference:this.dateTimeReferenceMetaData?.timeInfo?.timeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone}];for(const r of n)if(r.field===t.name){const e=this.convertToIANA(r.timeReference,r.isunknown);return this._fieldTimeZoneIndex[t.name]=e,e}const a=this.convertToIANA(this.dateTimeReferenceMetaData?.dateFieldsTimeReference,this.dateTimeReferenceMetaData?.datesInUnknownTimezone);return this._fieldTimeZoneIndex[t.name]=a,a}convertToIANA(e,t){return t?"unknown":c(e)}get layerPreferredTimeZone(){if(null!==this._ianaPreferred)return this._ianaPreferred;this._ianaPreferred="";const e=this.dateTimeReferenceMetaData?.preferredTimeReference;return this._ianaPreferred=this.convertToIANA(e,!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone),this._ianaPreferred}get layerTimeInfoTimeZone(){if(null!==this._ianaTimeInfo)return this._ianaTimeInfo;this._ianaTimeInfo="";const e=this.dateTimeReferenceMetaData?.timeInfo?.timeReference;return this._ianaTimeInfo=this.convertToIANA(e,!1),this._ianaTimeInfo}get
|
|
5
|
+
import{UnknownTimeZone as e,ArcadeDateError as t,ArcadeDateErrorCodes as i}from"./ArcadeDate.js";import n from"../layers/support/FieldsIndex.js";import a from"../time/TimeReference.js";import{convertLegacyTimeZone as r}from"../time/timeReferenceUtils.js";import{Zone as s,SystemZone as d,FixedOffsetZone as o,IANAZone as f}from"luxon";function l(e){return e instanceof a}function m(n){if(!n)return null;if(l(n)&&(n=c(n.toJSON())),n instanceof s)return n;if("unknown"===n.toLowerCase())return e.instance;if("system"===n.toLowerCase())return d.instance;if("utc"===n.toLowerCase())return o.utcInstance;if(/^[\+\-]?[0-9]{1,2}([:][0-9]{2})?$/.test(n)){const e=o.parseSpecifier("UTC"+(n.startsWith("+")||n.startsWith("-")?"":"+")+n);if(e)return e}const a=f.create(n);if(!a.isValid)throw new t(i.TimeZoneNotRecognized);return a}function c(e){return e?.timeZoneIANA?e?.timeZoneIANA:e?.timeZone?r(e,""):""}class T{constructor(){this.dateTimeReferenceMetaData=null,this._fieldTimeZoneIndex={},this._fieldIndex=null,this._ianaPreferred=null,this._ianaTimeInfo=null,this._ianaEditFields=null,this._ianaLayerDateFields=null}static create(e,t){const i=new T;return i.dateTimeReferenceMetaData=t,i._fieldIndex=e instanceof n?e:new n(e),i}static createFromLayer(e){if(!e)return null;if(!e.fieldsIndex)return!e.declaredClass&&e.fields?T.create(e.fields,e):null;const t=new T;return t._fieldIndex=e.fieldsIndex,t.dateTimeReferenceMetaData={timeInfo:e?.timeInfo?.toJSON()??null,editFieldsInfo:e?.editFieldsInfo?.toJSON()??null,dateFieldsTimeReference:e?.dateFieldsTimeReference?.toJSON()??null,preferredTimeReference:e?.preferredTimeReference?.toJSON()??null,datesInUnknownTimezone:!0===e?.datesInUnknownTimezone},t}fieldTimeZone(e){const t=this._fieldIndex?.get(e);if(!t)return null;if("esriFieldTypeTimestampOffset"===t.type||"esriFieldTypeDateOnly"===t.type||"esriFieldTypeTimeOnly"===t.type||"timestamp-offset"===t.type||"date-only"===t.type||"time-only"===t.type)return"unknown";if("date"!==t.type&&"esriFieldTypeDate"!==t.type)return null;const i=this._fieldTimeZoneIndex[t.name];if(void 0!==i)return i;const n=[{field:this.dateTimeReferenceMetaData?.editFieldsInfo?.creationDateField,timeReference:this.dateTimeReferenceMetaData?.editFieldsInfo?.dateFieldsTimeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone},{field:this.dateTimeReferenceMetaData?.editFieldsInfo?.editDateField,timeReference:this.dateTimeReferenceMetaData?.editFieldsInfo?.dateFieldsTimeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone},{field:this.dateTimeReferenceMetaData?.timeInfo?.startTimeField,timeReference:this.dateTimeReferenceMetaData?.timeInfo?.timeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone},{field:this.dateTimeReferenceMetaData?.timeInfo?.endTimeField,timeReference:this.dateTimeReferenceMetaData?.timeInfo?.timeReference,isunknown:!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone}];for(const r of n)if(r.field===t.name){const e=this.convertToIANA(r.timeReference,r.isunknown);return this._fieldTimeZoneIndex[t.name]=e,e}const a=this.convertToIANA(this.dateTimeReferenceMetaData?.dateFieldsTimeReference,this.dateTimeReferenceMetaData?.datesInUnknownTimezone);return this._fieldTimeZoneIndex[t.name]=a,a}convertToIANA(e,t){return t?"unknown":c(e)}get layerPreferredTimeZone(){if(null!==this._ianaPreferred)return this._ianaPreferred;this._ianaPreferred="";const e=this.dateTimeReferenceMetaData?.preferredTimeReference;return this._ianaPreferred=this.convertToIANA(e,!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone),this._ianaPreferred}get layerTimeInfoTimeZone(){if(null!==this._ianaTimeInfo)return this._ianaTimeInfo;this._ianaTimeInfo="";const e=this.dateTimeReferenceMetaData?.timeInfo?.timeReference;return this._ianaTimeInfo=this.convertToIANA(e,!1),this._ianaTimeInfo}get layerDateFieldsTimeZoneDefaultUTC(){const e=this.layerDateFieldsTimeZone;return""===e?"UTC":e}get layerEditFieldsTimeZone(){if(null!==this._ianaEditFields)return this._ianaEditFields;this._ianaEditFields="";const e=this.dateTimeReferenceMetaData?.editFieldsInfo?.dateFieldsTimeReference;return this._ianaEditFields=this.convertToIANA(e,this.dateTimeReferenceMetaData?.datesInUnknownTimezone),this._ianaEditFields}get layerDateFieldsTimeZone(){if(null!==this._ianaLayerDateFields)return this._ianaLayerDateFields;this._ianaLayerDateFields="";const e=this.dateTimeReferenceMetaData?.dateFieldsTimeReference;return this._ianaLayerDateFields=this.convertToIANA(e,!0===this.dateTimeReferenceMetaData?.datesInUnknownTimezone),this._ianaLayerDateFields}}export{T as DateTimeReferenceFieldIndex,m as convertTimeReference,c as convertToIANA};
|
package/arcade/executionError.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
var e;!function(e){e.AsyncNotEnabled="AsyncNotEnabled",e.ModulesNotSupported="ModulesNotSupported",e.CircularModules="CircularModules",e.NeverReach="NeverReach",e.UnsupportedHashType="UnsupportedHashType",e.InvalidParameter="InvalidParameter",e.UnexpectedToken="UnexpectedToken",e.Unrecognized="Unrecognized",e.UnrecognizedType="UnrecognizedType",e.MaximumCallDepth="MaximumCallDepth",e.BooleanConditionRequired="BooleanConditionRequired",e.TypeNotAllowedInFeature="TypeNotAllowedInFeature",e.KeyMustBeString="KeyMustBeString",e.WrongNumberOfParameters="WrongNumberOfParameters",e.CallNonFunction="CallNonFunction",e.NoFunctionInTemplateLiteral="NoFunctionInTemplateLiteral",e.NoFunctionInDictionary="NoFunctionInDictionary",e.NoFunctionInArray="NoFunctionInArray",e.AssignModuleFunction="AssignModuleFunction",e.LogicExpressionOrAnd="LogicExpressionOrAnd",e.LogicalExpressionOnlyBoolean="LogicalExpressionOnlyBoolean",e.FunctionNotFound="FunctionNotFound",e.InvalidMemberAccessKey="InvalidMemberAccessKey",e.UnsupportedUnaryOperator="UnsupportUnaryOperator",e.InvalidIdentifier="InvalidIdentifier",e.MemberOfNull="MemberOfNull",e.UnsupportedOperator="UnsupportedOperator",e.Cancelled="Cancelled",e.ModuleAccessorMustBeString="ModuleAccessorMustBeString",e.ModuleExportNotFound="ModuleExportNotFound",e.Immutable="Immutable",e.OutOfBounds="OutOfBounds",e.IllegalResult="IllegalResult",e.FieldNotFound="FieldNotFound",e.PortalRequired="PortalRequired",e.LogicError="LogicError",e.ArrayAccessorMustBeNumber="ArrayAccessMustBeNumber",e.KeyAccessorMustBeString="KeyAccessorMustBeString",e.WrongSpatialReference="WrongSpatialReference",e.CannotChangeTimeZoneTime="CannotChangeTimeZoneTime",e.CannotChangeTimeZoneDateOnly="CannotChangeTimeZoneDateOnly"}(e||(e={}));const r={[e.TypeNotAllowedInFeature]:"Feature attributes only support dates, numbers, strings, guids.",[e.LogicError]:"Logic error - {reason}",[e.NeverReach]:"Encountered unreachable logic",[e.AsyncNotEnabled]:"Async Arcade must be enabled for this script",[e.ModuleAccessorMustBeString]:"Module accessor must be a string",[e.ModuleExportNotFound]:"Module has no export with provided identifier",[e.ModulesNotSupported]:"Current profile does not support modules",[e.ArrayAccessorMustBeNumber]:"Array accessor must be a number",[e.FunctionNotFound]:"Function not found",[e.FieldNotFound]:"Key not found - {key}",[e.CircularModules]:"Circular module dependencies are not allowed",[e.Cancelled]:"Execution cancelled",[e.UnsupportedHashType]:"Type not supported in hash function",[e.IllegalResult]:"Value is not a supported return type",[e.PortalRequired]:"Portal is required",[e.InvalidParameter]:"Invalid parameter",[e.WrongNumberOfParameters]:"Call with wrong number of parameters",[e.Unrecognized]:"Unrecognized code structure",[e.UnrecognizedType]:"Unrecognized type",[e.WrongSpatialReference]:"Cannot work with geometry in this spatial reference. It is different to the execution spatial reference",[e.BooleanConditionRequired]:"Conditions must use booleans",[e.NoFunctionInDictionary]:"Dictionaries cannot contain functions.",[e.NoFunctionInArray]:"Arrays cannot contain functions.",[e.NoFunctionInTemplateLiteral]:"Template Literals do not expect functions by value.",[e.KeyAccessorMustBeString]:"Accessor must be a string",[e.KeyMustBeString]:"Object keys must be a string",[e.Immutable]:"Object is immutable",[e.UnexpectedToken]:"Unexpected token",[e.MemberOfNull]:"Cannot access property of null object",[e.MaximumCallDepth]:"Exceeded maximum function depth",[e.OutOfBounds]:"Out of bounds",[e.InvalidIdentifier]:"Identifier not recognized",[e.CallNonFunction]:"Expression is not a function",[e.InvalidMemberAccessKey]:"Cannot access value using a key of this type",[e.AssignModuleFunction]:"Cannot assign function to module variable",[e.UnsupportedUnaryOperator]:"Unsupported unary operator",[e.UnsupportedOperator]:"Unsupported operator",[e.LogicalExpressionOnlyBoolean]:"Logical expressions must be boolean",[e.LogicExpressionOrAnd]:"Logical expression can only be combined with || or &&",[e.CannotChangeTimeZoneTime]:"Cannot change the timezone of a Time",[e.CannotChangeTimeZoneDateOnly]:"Cannot change the timezone of a DateOnly"};class o extends Error{constructor(...e){super(...e)}}class n extends o{constructor(e,r){super(a(r)+e.message,{cause:e}),this.loc=null,Error.captureStackTrace&&Error.captureStackTrace(this,n),r&&r.loc&&(this.loc=r.loc)}}class t extends Error{constructor(e,o,n,c){super("Execution error - "+a(n)+i(r[o],c)),this.loc=null,this.declaredRootClass="esri.arcade.arcadeexecutionerror",Error.captureStackTrace&&Error.captureStackTrace(this,t),n&&n.loc&&(this.loc=n.loc)}}function a(e){return e&&e.loc?`Line : ${e.loc.start?.line}, ${e.loc.start?.column}: `:""}class c extends Error{constructor(e,o,n,t){super("Compilation error - "+a(n)+i(r[o],t)),this.loc=null,this.declaredRootClass="esri.arcade.arcadecompilationerror",Error.captureStackTrace&&Error.captureStackTrace(this,c),n&&n.loc&&(this.loc=n.loc)}}class s extends Error{constructor(){super("Uncompilable code structures"),this.declaredRootClass="esri.arcade.arcadeuncompilableerror",Error.captureStackTrace&&Error.captureStackTrace(this,s)}}function i(e,r){try{if(!r)return e;for(const o in r){let n=r[o];n||(n=""),e=e.replace("{"+o+"}",r[o])}}catch(o){}return e}function u(e,r,o){return"esri.arcade.arcadeexecutionerror"===o.declaredRootClass||"esri.arcade.arcadecompilationerror"===o.declaredRootClass?null===o.loc&&r&&r.loc?new n(o,{cause:o}):o:("esri.arcade.featureset.support.featureseterror"===o.declaredRootClass||"esri.arcade.featureset.support.sqlerror"===o.declaredRootClass||o.declaredRootClass,r&&r.loc?new n(o,{cause:o}):o)}var l;!function(e){e.UnrecognizedUri="UnrecognizedUri",e.UnsupportedUriProtocol="UnsupportedUriProtocol"}(l||(l={}));const d={[l.UnrecognizedUri]:"Unrecognized uri - {uri}",[l.UnsupportedUriProtocol]:"Unrecognized uri protocol"};class p extends Error{constructor(e,r){super(i(d[e],r)),this.declaredRootClass="esri.arcade.arcademoduleerror",Error.captureStackTrace&&Error.captureStackTrace(this,p)}}function m(e,o,n){return"Parsing error - "+a(e)+i(r[o],n)}export{c as ArcadeCompilationError,t as ArcadeExecutionError,s as ArcadeUncompilableError,o as ErrorWithCause,e as ExecutionErrorCodes,r as ExecutionErrorMessages,n as LocatableArcadeExecutionError,p as ModuleError,l as ModuleErrorCodes,d as ModuleErrorMessages,i as doSubstitutions,u as ensureArcadeExecutionError,m as parsingValidationMessage};
|
|
5
|
+
var e;!function(e){e.AsyncNotEnabled="AsyncNotEnabled",e.ModulesNotSupported="ModulesNotSupported",e.CircularModules="CircularModules",e.CannotCompareDateAndTime="CannotCompareDateAndTime",e.NeverReach="NeverReach",e.UnsupportedHashType="UnsupportedHashType",e.InvalidParameter="InvalidParameter",e.UnexpectedToken="UnexpectedToken",e.Unrecognized="Unrecognized",e.UnrecognizedType="UnrecognizedType",e.MaximumCallDepth="MaximumCallDepth",e.BooleanConditionRequired="BooleanConditionRequired",e.TypeNotAllowedInFeature="TypeNotAllowedInFeature",e.KeyMustBeString="KeyMustBeString",e.WrongNumberOfParameters="WrongNumberOfParameters",e.CallNonFunction="CallNonFunction",e.NoFunctionInTemplateLiteral="NoFunctionInTemplateLiteral",e.NoFunctionInDictionary="NoFunctionInDictionary",e.NoFunctionInArray="NoFunctionInArray",e.AssignModuleFunction="AssignModuleFunction",e.LogicExpressionOrAnd="LogicExpressionOrAnd",e.LogicalExpressionOnlyBoolean="LogicalExpressionOnlyBoolean",e.FunctionNotFound="FunctionNotFound",e.InvalidMemberAccessKey="InvalidMemberAccessKey",e.UnsupportedUnaryOperator="UnsupportUnaryOperator",e.InvalidIdentifier="InvalidIdentifier",e.MemberOfNull="MemberOfNull",e.UnsupportedOperator="UnsupportedOperator",e.Cancelled="Cancelled",e.ModuleAccessorMustBeString="ModuleAccessorMustBeString",e.ModuleExportNotFound="ModuleExportNotFound",e.Immutable="Immutable",e.OutOfBounds="OutOfBounds",e.IllegalResult="IllegalResult",e.FieldNotFound="FieldNotFound",e.PortalRequired="PortalRequired",e.LogicError="LogicError",e.ArrayAccessorMustBeNumber="ArrayAccessMustBeNumber",e.KeyAccessorMustBeString="KeyAccessorMustBeString",e.WrongSpatialReference="WrongSpatialReference",e.CannotChangeTimeZoneTime="CannotChangeTimeZoneTime",e.CannotChangeTimeZoneDateOnly="CannotChangeTimeZoneDateOnly"}(e||(e={}));const r={[e.TypeNotAllowedInFeature]:"Feature attributes only support dates, numbers, strings, guids.",[e.LogicError]:"Logic error - {reason}",[e.CannotCompareDateAndTime]:"Cannot compare date or dateonly with timeonly types",[e.NeverReach]:"Encountered unreachable logic",[e.AsyncNotEnabled]:"Async Arcade must be enabled for this script",[e.ModuleAccessorMustBeString]:"Module accessor must be a string",[e.ModuleExportNotFound]:"Module has no export with provided identifier",[e.ModulesNotSupported]:"Current profile does not support modules",[e.ArrayAccessorMustBeNumber]:"Array accessor must be a number",[e.FunctionNotFound]:"Function not found",[e.FieldNotFound]:"Key not found - {key}",[e.CircularModules]:"Circular module dependencies are not allowed",[e.Cancelled]:"Execution cancelled",[e.UnsupportedHashType]:"Type not supported in hash function",[e.IllegalResult]:"Value is not a supported return type",[e.PortalRequired]:"Portal is required",[e.InvalidParameter]:"Invalid parameter",[e.WrongNumberOfParameters]:"Call with wrong number of parameters",[e.Unrecognized]:"Unrecognized code structure",[e.UnrecognizedType]:"Unrecognized type",[e.WrongSpatialReference]:"Cannot work with geometry in this spatial reference. It is different to the execution spatial reference",[e.BooleanConditionRequired]:"Conditions must use booleans",[e.NoFunctionInDictionary]:"Dictionaries cannot contain functions.",[e.NoFunctionInArray]:"Arrays cannot contain functions.",[e.NoFunctionInTemplateLiteral]:"Template Literals do not expect functions by value.",[e.KeyAccessorMustBeString]:"Accessor must be a string",[e.KeyMustBeString]:"Object keys must be a string",[e.Immutable]:"Object is immutable",[e.UnexpectedToken]:"Unexpected token",[e.MemberOfNull]:"Cannot access property of null object",[e.MaximumCallDepth]:"Exceeded maximum function depth",[e.OutOfBounds]:"Out of bounds",[e.InvalidIdentifier]:"Identifier not recognized",[e.CallNonFunction]:"Expression is not a function",[e.InvalidMemberAccessKey]:"Cannot access value using a key of this type",[e.AssignModuleFunction]:"Cannot assign function to module variable",[e.UnsupportedUnaryOperator]:"Unsupported unary operator",[e.UnsupportedOperator]:"Unsupported operator",[e.LogicalExpressionOnlyBoolean]:"Logical expressions must be boolean",[e.LogicExpressionOrAnd]:"Logical expression can only be combined with || or &&",[e.CannotChangeTimeZoneTime]:"Cannot change the timezone of a Time",[e.CannotChangeTimeZoneDateOnly]:"Cannot change the timezone of a DateOnly"};class o extends Error{constructor(...e){super(...e)}}class n extends o{constructor(e,r){super(a(r)+e.message,{cause:e}),this.loc=null,Error.captureStackTrace&&Error.captureStackTrace(this,n),r&&r.loc&&(this.loc=r.loc)}}class t extends Error{constructor(e,o,n,c){super("Execution error - "+a(n)+i(r[o],c)),this.loc=null,this.declaredRootClass="esri.arcade.arcadeexecutionerror",Error.captureStackTrace&&Error.captureStackTrace(this,t),n&&n.loc&&(this.loc=n.loc)}}function a(e){return e&&e.loc?`Line : ${e.loc.start?.line}, ${e.loc.start?.column}: `:""}class c extends Error{constructor(e,o,n,t){super("Compilation error - "+a(n)+i(r[o],t)),this.loc=null,this.declaredRootClass="esri.arcade.arcadecompilationerror",Error.captureStackTrace&&Error.captureStackTrace(this,c),n&&n.loc&&(this.loc=n.loc)}}class s extends Error{constructor(){super("Uncompilable code structures"),this.declaredRootClass="esri.arcade.arcadeuncompilableerror",Error.captureStackTrace&&Error.captureStackTrace(this,s)}}function i(e,r){try{if(!r)return e;for(const o in r){let n=r[o];n||(n=""),e=e.replace("{"+o+"}",r[o])}}catch(o){}return e}function u(e,r,o){return"esri.arcade.arcadeexecutionerror"===o.declaredRootClass||"esri.arcade.arcadecompilationerror"===o.declaredRootClass?null===o.loc&&r&&r.loc?new n(o,{cause:o}):o:("esri.arcade.featureset.support.featureseterror"===o.declaredRootClass||"esri.arcade.featureset.support.sqlerror"===o.declaredRootClass||o.declaredRootClass,r&&r.loc?new n(o,{cause:o}):o)}var l;!function(e){e.UnrecognizedUri="UnrecognizedUri",e.UnsupportedUriProtocol="UnsupportedUriProtocol"}(l||(l={}));const d={[l.UnrecognizedUri]:"Unrecognized uri - {uri}",[l.UnsupportedUriProtocol]:"Unrecognized uri protocol"};class p extends Error{constructor(e,r){super(i(d[e],r)),this.declaredRootClass="esri.arcade.arcademoduleerror",Error.captureStackTrace&&Error.captureStackTrace(this,p)}}function m(e,o,n){return"Parsing error - "+a(e)+i(r[o],n)}export{c as ArcadeCompilationError,t as ArcadeExecutionError,s as ArcadeUncompilableError,o as ErrorWithCause,e as ExecutionErrorCodes,r as ExecutionErrorMessages,n as LocatableArcadeExecutionError,p as ModuleError,l as ModuleErrorCodes,d as ModuleErrorMessages,i as doSubstitutions,u as ensureArcadeExecutionError,m as parsingValidationMessage};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/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 m,FeatureSetErrorCodes as p}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 S(){null===f.applicationCache&&(f.applicationCache=new f)}async function I(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 I(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,{timeZone:l.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC}))}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"}});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 A(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&&e.layerDataElements[0])return e.layerDataElements[0]}throw new m(p.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 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"}});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 C(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await N(e);if(a.metadata=r,r.controllerDatasetLayers&&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 A(e,n);if(i){a.queryelem=i,a.queryelem&&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 T(e+"/"+n);if(r.systemLayers&&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(),{timeZone:i.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC})),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 b 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=[],s=this._map.allLayers.find((t=>{if(t instanceof w){if(t.title===e)return!0}else if(a(t)){if(t.title===e)return!0;i.push(t)}return!1}));if(s)return this._makeAndAddFeatureSet(s,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)}}for(const a of i){if("not-loaded"===a.loadStatus||"loading"===a.loadStatus)try{await a.load()}catch(l){}const n=a.sublayers.find((t=>t.title===e));if(n)return this._makeAndAddFeatureSet(n,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=[],s=this._map.allLayers.find((t=>{if(t instanceof w){if(t.id===e)return!0}else if(a(t)){if(t.id===e)return!0;i.push(t)}return!1}));if(s)return this._makeAndAddFeatureSet(s,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)}}for(const a of i){if("not-loaded"===a.loadStatus||"loading"===a.loadStatus)try{await a.load()}catch(l){}const n=a.sublayers.find((t=>t.id===e));if(n)return this._makeAndAddFeatureSet(n,t,r)}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=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 N(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 I(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 I(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function O(e,t,a=null,r=null){return new b(e,t,a,r)}function E(e,t,a=null,r=null){return new D(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{C as constructAssociationMetaDataFeatureSetFromUrl,g as constructFeatureSet,q as constructFeatureSetFromPortalItem,k as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,j as convertToFeatureSet,O as createFeatureSetCollectionFromMap,E as createFeatureSetCollectionFromService,S as initialiseMetaDataCache};
|
|
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 S(){null===f.applicationCache&&(f.applicationCache=new f)}async function I(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 I(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,{timeZone:l.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC}))}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 N(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&&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 C(e,t){const a={metadata:null,networkId:-1,unVersion:3,terminals:[],queryelem:null,layerNameLkp:{},lkp:null},r=await T(e);if(a.metadata=r,r.controllerDatasetLayers&&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 N(e,n);if(i){a.queryelem=i,a.queryelem&&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(r.systemLayers&&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(),{timeZone:i.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC})),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 D 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=[],s=this._map.allLayers.find((t=>{if(t instanceof w){if(t.title===e)return!0}else if(a(t)){if(t.title===e)return!0;i.push(t)}return!1}));if(s)return this._makeAndAddFeatureSet(s,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)}}for(const a of i){if("not-loaded"===a.loadStatus||"loading"===a.loadStatus)try{await a.load()}catch(l){}const n=a.sublayers.find((t=>t.title===e));if(n)return this._makeAndAddFeatureSet(n,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=[],s=this._map.allLayers.find((t=>{if(t instanceof w){if(t.id===e)return!0}else if(a(t)){if(t.id===e)return!0;i.push(t)}return!1}));if(s)return this._makeAndAddFeatureSet(s,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)}}for(const a of i){if("not-loaded"===a.loadStatus||"loading"===a.loadStatus)try{await a.load()}catch(l){}const n=a.sublayers.find((t=>t.id===e));if(n)return this._makeAndAddFeatureSet(n,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 I(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 I(this._url+"/"+i.id,["*"]);return this._makeAndAddFeatureSet(e,t,a)}return null}}function O(e,t,a=null,r=null){return new D(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{C as constructAssociationMetaDataFeatureSetFromUrl,g as constructFeatureSet,q as constructFeatureSetFromPortalItem,k as constructFeatureSetFromRelationship,F as constructFeatureSetFromUrl,j as convertToFeatureSet,O as createFeatureSetCollectionFromMap,E as createFeatureSetCollectionFromService,S 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.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import e from"../../../Graphic.js";import{ArcadeDate as t}from"../../ArcadeDate.js";import{cloneGeometry as r}from"../../kernel.js";import{SqlError as s,SqlErrorCodes as a,FeatureSetError as i,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import o from"../support/IdSet.js";import{cloneField as h,FeatureServiceDatabaseType as u,layerGeometryEsriConstants as c}from"../support/shared.js";import{reformulateWithoutField as d,toWhereClause as p,translateFunctionToDatabaseSpecific as f,makeToday as g,makeDateString as N,arcadeDateToSqlString as _,convertIntervalToSql as S,combine as m,scanForField as w}from"../support/sqlUtils.js";import{assertIsSome as v}from"../../../core/maybe.js";import{WhereClause as C}from"../../../core/sql/WhereClause.js";import T from"../../../geometry/SpatialReference.js";class F{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class W extends F{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class A extends F{constructor(e,t,r){super(h(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:d(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class E extends F{constructor(e,t,r){super(e),this.codefield=t,this.lkp=r,this.reverseLkp={};for(const s in r)this.reverseLkp[r[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const r=this.evaluateNodeToWhereClause(e.parseTree,u.Standardised,this.field.name,this.codefield instanceof C?p(this.codefield,u.Standardised):this.codefield,e.parameters);return r.includes(E.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:C.create(r,t._parent.getFieldsIndex(),{timeZone:t.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC})}}evaluateNodeToWhereClause(e,r,i=null,l=null,n){let o,h,u,c;switch(e.type){case"interval":return S(this.evaluateNodeToWhereClause(e.value,r,i,l,n),e.qualifier,e.op);case"case-expression":{let t=" CASE ";"simple"===e.format&&(t+=this.evaluateNodeToWhereClause(e.operand,r,i,E.BADNESS,n));for(let s=0;s<e.clauses.length;s++)t+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[s].operand,r,i,E.BADNESS,n)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[s].value,r,i,E.BADNESS,n);return null!==e.else&&(t+=" ELSE "+this.evaluateNodeToWhereClause(e.else,r,i,E.BADNESS,n)),t+=" END ",t}case"parameter":{const s=n[e.value.toLowerCase()];if("string"==typeof s)return"'"+s.toString().replaceAll("'","''")+"'";if(s instanceof Date)return N(s,r,null);if(s instanceof t)return _(s,r,null);if(s instanceof Array){const e=[];for(let a=0;a<s.length;a++)"string"==typeof s[a]?e.push("'"+s[a].toString().replaceAll("'","''")+"'"):s[a]instanceof Date?e.push(N(s[a],r,null)):s[a]instanceof t?e.push(_(s[a],r,null)):e.push(s[a].toString());return e}return s.toString()}case"expression-list":h=[];for(const t of e.value)h.push(this.evaluateNodeToWhereClause(t,r,i,l,n));return h;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,r,i,E.BADNESS,n)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" AND "+this.evaluateNodeToWhereClause(e.right,r,i,l,n)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" OR "+this.evaluateNodeToWhereClause(e.right,r,i,l,n)+") ";case"IS":if("null"!==e.right.type)throw new s(a.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new s(a.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IS NOT NULL )";case"IN":if(o=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const t=[];let s=!0;for(const r of e.right.value){if("string"!==r.type){s=!1;break}if(void 0===this.lkp[r.value]){s=!1;break}t.push(this.lkp[r.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+t.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,r,i,l,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+o.join(",")+")) "}return c=this.evaluateNodeToWhereClause(e.right,r,i,l,n),c instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+c.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+c+")) ";case"NOT IN":if(o=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const t=[];let s=!0;for(const r of e.right.value){if("string"!==r.type){s=!1;break}if(void 0===this.lkp[r.value]){s=!1;break}t.push(this.lkp[r.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+t.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,r,i,l,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+o.join(",")+")) "}return c=this.evaluateNodeToWhereClause(e.right,r,i,l,n),c instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+c.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+c+")) ";case"BETWEEN":return u=this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" BETWEEN "+u[0]+" AND "+u[1]+" ) ";case"NOTBETWEEN":return u=this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" NOT BETWEEN "+u[0]+" AND "+u[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") ";case"<>":case"=":if("column-reference"===e.left.type&&"string"===e.right.type){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&void 0!==this.lkp[e.right.value.toString()])return" ("+l+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if("column-reference"===e.right.type&&"string"===e.left.type&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+l+") ";return" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") "}case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":case"date":return N(e.value,r,null);case"number":return e.value.toString();case"current-time":return g("date"===e.mode,r);case"column-reference":return i&&i.toLowerCase()===e.column.toLowerCase()?"("+l+")":e.column;case"data-type":return e.value;case"function":{const t=this.evaluateNodeToWhereClause(e.args,r,i,E.BADNESS,n);return f(e.name,t,r)}}throw new s(a.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof C?this.reverseLkp[C.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}}E.BADNESS="_!!!_BAD_LKP_!!!!";class x extends F{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:d(e,this.field.name,p(this._sql,u.Standardised),t.getFieldsIndex())}}extractValue(e){return C.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}class y extends n{static findField(e,t){for(const r of e)if(r.name.toLowerCase()===t.toString().toLowerCase())return r;return null}constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=[],this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}_initialiseFeatureSet(){null!==this._parent?(this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.spatialReference=new T({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=c.point,this.typeIdField="",this.types=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();let t=null;return t=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await(this._parent?._getSet(e)),this._checkCancelled(e),v(t),this._wset=new o(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(t,s,a,i){const l=[];-1!==s&&void 0===this._featureCache[s]&&l.push(s);const n=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(t,n))return await this._expandPagedSet(t,n,0,0,i),this._getFeatures(t,s,a,i);let h=0;for(let e=t._lastFetchedIndex;e<t._known.length&&(h++,h<=a&&(t._lastFetchedIndex+=1),!(void 0===this._featureCache[t._known[e]]&&(t._known[e]!==s&&l.push(t._known[e]),l.length>=n)));e++);if(0===l.length)return"success";t=new o([],l,t._ordered,null);const u=Math.min(l.length,a);await(this._parent?._getFeatures(t,-1,u,i)),this._checkCancelled(i);const c=[];for(let e=0;e<u;e++){const t=this._parent?._featureFromCache(l[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:l[e]})}for(const o of c){const t=[];for(const e of this.adaptedFields)t[e.field.name]=e.extractValue(o);this._featureCache[o.id]=new e({attributes:t,geometry:r(o.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new i(l.NeverReach)}async _getFilteredSet(e,t,r,s,a){let i=!1;const l=this._reformulateWithoutAdaptions(r);i=l.cannot,r=l.where;let n=!1;if(null!==s){n=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof W)&&!0===s.scanForField(t.field.name)){if(!(t instanceof A)){s=null,n=!1;break}e.push({field:t.field.name,newfield:t.originalField.name})}s&&e.length>0&&(s=s.replaceFields(e))}null!==r?null!==this._extraFilter&&(r=m(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const h=await this._parent._getFilteredSet(e,t,r,s,a);let u;return this._checkCancelled(a),u=!0===i?new o(h._candidates.slice(0).concat(h._known.slice(0)),[],!0===n&&h._ordered,this._clonePageDefinition(h.pagesDefinition)):new o(h._candidates.slice(0),h._known.slice(0),!0===n&&h._ordered,this._clonePageDefinition(h.pagesDefinition)),u}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!==e)for(const r of this.adaptedFields)if(!0===w(e,r.field.name)){const s=r.rewriteSql(e,this);if(!0!==s.rewritten){t.cannot=!0,t.where=null;break}t.where=s.where}return t}async _stat(e,t,r,s,a,i,l){let n=!1,o=this._reformulateWithoutAdaptions(t);if(n=o.cannot,t=o.where,o=this._reformulateWithoutAdaptions(a),n=n||o.cannot,null!==(a=o.where)?null!==this._extraFilter&&(a=m(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const h=await this._parent._stat(e,t,r,s,a,i,l);return!1===h.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:h}async _canDoAggregates(e,t,r,s,a){if(null===this._parent)return!1;for(let n=0;n<e.length;n++)for(const t of this.adaptedFields)if(e[n].toLowerCase()===t.field.name.toLowerCase()&&!(t instanceof W))return!1;const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)return!1;const r=e.clone();r.workingexpr=t.where,i.push(r)}else i.push(e)}const l=this._reformulateWithoutAdaptions(a);return!l.cannot&&(null!==(a=l.where)?null!==this._extraFilter&&(a=m(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,r,s,a,n,o){if(null===this._parent)throw new i(l.NeverReach);const h=[];for(let c=0;c<t.length;c++){const e=t[c];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)throw new i(l.NeverReach);const r=e.clone();r.workingexpr=t.where,h.push(r)}else h.push(e)}const u=this._reformulateWithoutAdaptions(a);if(u.cannot)throw new i(l.NeverReach);return null!==(a=u.where)?null!==this._extraFilter&&(a=m(this._extraFilter,a)):a=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,h,r,s,a,n,o)}}export{y as AdaptedFeatureSet,F as AdaptedField,A as FieldRename,W as OriginalField,x as SqlExpressionAdapted,E as StringToCodeAdapted};
|
|
5
|
+
import e from"../../../Graphic.js";import{ArcadeDate as t}from"../../ArcadeDate.js";import{cloneGeometry as r}from"../../kernel.js";import{SqlError as s,SqlErrorCodes as a,FeatureSetError as i,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import n from"../support/FeatureSet.js";import o from"../support/IdSet.js";import{cloneField as h,FeatureServiceDatabaseType as u,layerGeometryEsriConstants as c}from"../support/shared.js";import{reformulateWithoutField as d,toWhereClause as p,translateFunctionToDatabaseSpecific as f,makeToday as g,makeDateString as N,arcadeDateToSqlString as _,convertIntervalToSql as S,combine as m,scanForField as w}from"../support/sqlUtils.js";import{assertIsSome as v}from"../../../core/maybe.js";import{WhereClause as C}from"../../../core/sql/WhereClause.js";import T from"../../../geometry/SpatialReference.js";class F{constructor(e){this.field=e,this.sqlRewritable=!1}postInitialization(e,t){}}class W extends F{constructor(e){super(e),this.sqlRewritable=!0}extractValue(e){return e.attributes[this.field.name]}rewriteSql(e){return{rewritten:this.sqlRewritable,where:e}}}class A extends F{constructor(e,t,r){super(h(e)),this.originalField=e,this.sqlRewritable=!0,this.field.name=t,this.field.alias=r}rewriteSql(e,t){return{rewritten:this.sqlRewritable,where:d(e,this.field.name,this.originalField.name,t.getFieldsIndex())}}extractValue(e){return e.attributes[this.originalField.name]}}class E extends F{constructor(e,t,r){super(e),this.codefield=t,this.lkp=r,this.reverseLkp={};for(const s in r)this.reverseLkp[r[s]]=s;this.sqlRewritable=!0}rewriteSql(e,t){const r=this.evaluateNodeToWhereClause(e.parseTree,u.Standardised,this.field.name,this.codefield instanceof C?p(this.codefield,u.Standardised):this.codefield,e.parameters);return r.includes(E.BADNESS)?{rewritten:!1,where:e}:{rewritten:this.sqlRewritable,where:C.create(r,t._parent.getFieldsIndex(),{timeZone:t.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC})}}evaluateNodeToWhereClause(e,r,i=null,l=null,n){let o,h,u,c;switch(e.type){case"interval":return S(this.evaluateNodeToWhereClause(e.value,r,i,l,n),e.qualifier,e.op);case"case-expression":{let t=" CASE ";"simple"===e.format&&(t+=this.evaluateNodeToWhereClause(e.operand,r,i,E.BADNESS,n));for(let s=0;s<e.clauses.length;s++)t+=" WHEN "+this.evaluateNodeToWhereClause(e.clauses[s].operand,r,i,E.BADNESS,n)+" THEN "+this.evaluateNodeToWhereClause(e.clauses[s].value,r,i,E.BADNESS,n);return null!==e.else&&(t+=" ELSE "+this.evaluateNodeToWhereClause(e.else,r,i,E.BADNESS,n)),t+=" END ",t}case"parameter":{const s=n[e.value.toLowerCase()];if("string"==typeof s)return"'"+s.toString().replaceAll("'","''")+"'";if(s instanceof Date)return N(s,r,null);if(s instanceof t)return _(s,r,null);if(s instanceof Array){const e=[];for(let a=0;a<s.length;a++)"string"==typeof s[a]?e.push("'"+s[a].toString().replaceAll("'","''")+"'"):s[a]instanceof Date?e.push(N(s[a],r,null)):s[a]instanceof t?e.push(_(s[a],r,null)):e.push(s[a].toString());return e}return s.toString()}case"expression-list":h=[];for(const t of e.value)h.push(this.evaluateNodeToWhereClause(t,r,i,l,n));return h;case"unary-expression":return" ( NOT "+this.evaluateNodeToWhereClause(e.expr,r,i,E.BADNESS,n)+" ) ";case"binary-expression":switch(e.operator){case"AND":return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" AND "+this.evaluateNodeToWhereClause(e.right,r,i,l,n)+") ";case"OR":return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" OR "+this.evaluateNodeToWhereClause(e.right,r,i,l,n)+") ";case"IS":if("null"!==e.right.type)throw new s(a.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IS NULL )";case"ISNOT":if("null"!==e.right.type)throw new s(a.UnsupportedIsRhs);return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IS NOT NULL )";case"IN":if(o=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const t=[];let s=!0;for(const r of e.right.value){if("string"!==r.type){s=!1;break}if(void 0===this.lkp[r.value]){s=!1;break}t.push(this.lkp[r.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+t.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,r,i,l,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+o.join(",")+")) "}return c=this.evaluateNodeToWhereClause(e.right,r,i,l,n),c instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+c.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" IN ("+c+")) ";case"NOT IN":if(o=[],"expression-list"===e.right.type){if("column-reference"===e.left.type&&e.left.column.toUpperCase()===this.field.name.toUpperCase()){const t=[];let s=!0;for(const r of e.right.value){if("string"!==r.type){s=!1;break}if(void 0===this.lkp[r.value]){s=!1;break}t.push(this.lkp[r.value].toString())}if(s)return" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+t.join(",")+")) "}return o=this.evaluateNodeToWhereClause(e.right,r,i,l,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+o.join(",")+")) "}return c=this.evaluateNodeToWhereClause(e.right,r,i,l,n),c instanceof Array?" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+c.join(",")+")) ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,l,n)+" NOT IN ("+c+")) ";case"BETWEEN":return u=this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" BETWEEN "+u[0]+" AND "+u[1]+" ) ";case"NOTBETWEEN":return u=this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)," ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" NOT BETWEEN "+u[0]+" AND "+u[1]+" ) ";case"LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") ";case"NOT LIKE":return""!==e.escape?" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+" ESCAPE '"+e.escape+"') ":" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" NOT LIKE "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") ";case"<>":case"=":if("column-reference"===e.left.type&&"string"===e.right.type){if(e.left.column.toUpperCase()===this.field.name.toUpperCase()&&void 0!==this.lkp[e.right.value.toString()])return" ("+l+" "+e.operator+" "+this.lkp[e.right.value.toString()].toString()+") "}else if("column-reference"===e.right.type&&"string"===e.left.type&&e.right.column.toUpperCase()===this.field.name.toUpperCase())return" ("+this.lkp[e.right.value.toString()].toString()+" "+e.operator+" "+l+") ";return" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") ";case"<":case">":case">=":case"<=":case"*":case"-":case"+":case"/":case"||":return" ("+this.evaluateNodeToWhereClause(e.left,r,i,E.BADNESS,n)+" "+e.operator+" "+this.evaluateNodeToWhereClause(e.right,r,i,E.BADNESS,n)+") "}case"null":return"null";case"boolean":return!0===e.value?"1":"0";case"string":return"'"+e.value.toString().replaceAll("'","''")+"'";case"timestamp":case"date":return N(e.value,r,null);case"number":return e.value.toString();case"current-time":return g("date"===e.mode,r);case"column-reference":return i&&i.toLowerCase()===e.column.toLowerCase()?"("+l+")":e.column;case"data-type":return e.value;case"function":{const t=this.evaluateNodeToWhereClause(e.args,r,i,E.BADNESS,n);return f(e.name,t,r)}}throw new s(a.UnsupportedSyntax,{node:e.type})}extractValue(e){return this.codefield instanceof C?this.reverseLkp[C.convertValueToStorageFormat(this.codefield.calculateValueCompiled(e))]:this.reverseLkp[e.attributes[this.codefield]]}}E.BADNESS="_!!!_BAD_LKP_!!!!";class x extends F{constructor(e,t){super(e),this._sql=t}rewriteSql(e,t){return{rewritten:!0,where:d(e,this.field.name,p(this._sql,u.Standardised),t.getFieldsIndex())}}extractValue(e){return C.convertValueToStorageFormat(this._sql.calculateValueCompiled(e),this.field.type)}}class y extends n{static findField(e,t){for(const r of e)if(r.name.toLowerCase()===t.toString().toLowerCase())return r;return null}constructor(e){super(e),this._calcFunc=null,this.declaredClass="esri.arcade.featureset.actions.Adapted",this.adaptedFields=[],this._extraFilter=null,this._extraFilter=e.extraFilter,this._parent=e.parentfeatureset,this._maxProcessing=30,this.adaptedFields=e.adaptedFields}_initialiseFeatureSet(){null!==this._parent?(this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.spatialReference=new T({wkid:4326}),this.objectIdField="",this.globalIdField="",this.geometryType=c.point,this.typeIdField="",this.types=null),this.fields=[];for(const e of this.adaptedFields)e.postInitialization(this,this._parent),this.fields.push(e.field)}async _getSet(e){if(null===this._wset){await this._ensureLoaded();let t=null;return t=this._extraFilter?await this._getFilteredSet("",null,null,null,e):await(this._parent?._getSet(e)),this._checkCancelled(e),v(t),this._wset=new o(t._candidates.slice(0),t._known.slice(0),t._ordered,this._clonePageDefinition(t.pagesDefinition)),this._wset}return this._wset}_isInFeatureSet(e){return this._parent._isInFeatureSet(e)}async _getFeatures(t,s,a,i){const l=[];-1!==s&&void 0===this._featureCache[s]&&l.push(s);const n=this._maxQueryRate();if(!0===this._checkIfNeedToExpandKnownPage(t,n))return await this._expandPagedSet(t,n,0,0,i),this._getFeatures(t,s,a,i);let h=0;for(let e=t._lastFetchedIndex;e<t._known.length&&(h++,h<=a&&(t._lastFetchedIndex+=1),!(void 0===this._featureCache[t._known[e]]&&(t._known[e]!==s&&l.push(t._known[e]),l.length>=n)));e++);if(0===l.length)return"success";t=new o([],l,t._ordered,null);const u=Math.min(l.length,a);await(this._parent?._getFeatures(t,-1,u,i)),this._checkCancelled(i);const c=[];for(let e=0;e<u;e++){const t=this._parent?._featureFromCache(l[e]);void 0!==t&&c.push({geometry:t.geometry,attributes:t.attributes,id:l[e]})}for(const o of c){const t=[];for(const e of this.adaptedFields)t[e.field.name]=e.extractValue(o);this._featureCache[o.id]=new e({attributes:t,geometry:r(o.geometry)})}return"success"}async _fetchAndRefineFeatures(){throw new i(l.NeverReach)}async _getFilteredSet(e,t,r,s,a){let i=!1;const l=this._reformulateWithoutAdaptions(r);i=l.cannot,r=l.where;let n=!1;if(null!==s){n=!0;const e=[];for(const t of this.adaptedFields)if(!(t instanceof W)&&!0===s.scanForField(t.field.name)){if(!(t instanceof A)){s=null,n=!1;break}e.push({field:t.field.name,newfield:t.originalField.name})}s&&e.length>0&&(s=s.replaceFields(e))}null!==r?null!==this._extraFilter&&(r=m(this._extraFilter,r)):r=this._extraFilter,await this._ensureLoaded();const h=await this._parent._getFilteredSet(e,t,r,s,a);let u;return this._checkCancelled(a),u=!0===i?new o(h._candidates.slice(0).concat(h._known.slice(0)),[],!0===n&&h._ordered,this._clonePageDefinition(h.pagesDefinition)):new o(h._candidates.slice(0),h._known.slice(0),!0===n&&h._ordered,this._clonePageDefinition(h.pagesDefinition)),u}_reformulateWithoutAdaptions(e){const t={cannot:!1,where:e};if(null!==e)for(const r of this.adaptedFields)if(!0===w(e,r.field.name)){const s=r.rewriteSql(e,this);if(!0!==s.rewritten){t.cannot=!0,t.where=null;break}t.where=s.where}return t}async _stat(e,t,r,s,a,i,l){let n=!1,o=this._reformulateWithoutAdaptions(t);if(n=o.cannot,t=o.where,o=this._reformulateWithoutAdaptions(a),n=n||o.cannot,null!==(a=o.where)?null!==this._extraFilter&&(a=m(this._extraFilter,a)):a=this._extraFilter,!0===n)return null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1};const h=await this._parent._stat(e,t,r,s,a,i,l);return!1===h.calculated?null===a&&""===r&&null===s?this._manualStat(e,t,i,l):{calculated:!1}:h}async _canDoAggregates(e,t,r,s,a){if(null===this._parent)return!1;for(let n=0;n<e.length;n++)for(const t of this.adaptedFields)if(e[n].toLowerCase()===t.field.name.toLowerCase()&&!(t instanceof W))return!1;const i=[];for(let n=0;n<t.length;n++){const e=t[n];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)return!1;const r=e.clone();r.workingexpr=t.where,i.push(r)}else i.push(e)}const l=this._reformulateWithoutAdaptions(a);return!l.cannot&&(null!==(a=l.where)?null!==this._extraFilter&&(a=m(this._extraFilter,a)):a=this._extraFilter,this._parent._canDoAggregates(e,i,r,s,a))}async _getAggregatePagesDataSourceDefinition(e,t,r,s,a,n,o){if(null===this._parent)throw new i(l.NeverReach);const h=[];for(let c=0;c<t.length;c++){const e=t[c];if(null!==e.workingexpr){const t=this._reformulateWithoutAdaptions(e.workingexpr);if(t.cannot)throw new i(l.NeverReach);const r=e.clone();r.workingexpr=t.where,h.push(r)}else h.push(e)}const u=this._reformulateWithoutAdaptions(a);if(u.cannot)throw new i(l.NeverReach);return null!==(a=u.where)?null!==this._extraFilter&&(a=m(this._extraFilter,a)):a=this._extraFilter,this._parent._getAggregatePagesDataSourceDefinition(e,h,r,s,a,n,o)}}export{y as AdaptedFeatureSet,F as AdaptedField,A as FieldRename,W as OriginalField,x as SqlExpressionAdapted,E as StringToCodeAdapted};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.arcgis.com/4.28/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 o,FeatureSetErrorCodes as l}from"../support/errorsupport.js";import d from"../support/FeatureSet.js";import u from"../support/IdSet.js";import f from"../support/OrderbyClause.js";import{IdState as c,layerGeometryEsriConstants as p,FeatureServiceDatabaseType as h}from"../support/shared.js";import{isSingleField as g,toWhereClause as m,predictType as _,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 T from"../../../geometry/SpatialReference.js";import A from"../../../layers/support/Field.js";import C 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 C([]);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,{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC}),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,{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC}),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}else this.geometryType=p.point,this.typeIdField="",this.types=null,this.spatialReference=new T({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(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC}),a.typeofstat="MIN",this._decodedStatsfield.push(a);for(const s of this._decodedGroupbyfield){const t=new A;if(s.name=this._nextUniqueName(e),t.name=s.tofieldname,t.alias=t.name,g(s.expression)){const e=this._parent.getField(m(s.expression,h.Standardised));if(!e)throw new o(l.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(_(s.expression,this._parent.fields));const e=new A;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 A;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)?m(n.workingexpr,h.Standardised):"";switch(this._decodedStatsfield[i].typeofstat){case"SUM":if(""!==r){if(s=this._parent.getField(r),!s)throw new o(l.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 o(l.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 o(l.AggregationFieldNotFound);t.type="double"}this.fields.push(t)}}async _canDoAggregates(){return!1}async _getFeatures(e,t,i,s){-1!==t&&this._featureCache[t];const n=this._maxQuery;return!0===this._checkIfNeedToExpandKnownPage(e,n)?(await this._expandPagedSet(e,n,0,0,s),this._getFeatures(e,t,i,s)):"success"}async _getFilteredSet(e,t,i,s,o){if(""!==e)return new u([],[],!0,null);let l=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(o),l=!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)),l}let c=this._parent;if(this._adaptedFields.length>0&&(c=new n({parentfeatureset:this._parent,adaptedFields:this._adaptedFields,extraFilter:null})),!0===d.nowhereclause)l=new u(["GETPAGES"],[],!1,{aggregatefeaturesetpagedefinition:!0,resultOffset:0,resultRecordCount:this._maxQuery,internal:{fullyResolved:!1,workingItem:null,type:"manual",iterator:null,set:[],subfeatureset:new 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})}l=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 l}_reformulateWhereClauseWithoutStatsFields(e){for(const t of this._decodedStatsfield)e=b(e,t.tofieldname,m(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,m(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 o=this._generateAggregateHash(t);if(null===e.pagesDefinition.internal.workingItem)e.pagesDefinition.internal.workingItem={features:[t],id:o};else{if(o!==e.pagesDefinition.internal.workingItem.id){const s=this._calculateAndAppendAggregateItem(e.pagesDefinition.internal.workingItem);return n.push(s),e.pagesDefinition.internal.workingItem=null,e.pagesDefinition.internal.set.push(s.attributes[this.objectIdField]),i-=1,e.pagesDefinition.internal.workingItem={features:[t],id:o},void r(s)}e.pagesDefinition.internal.workingItem.features.push(t)}this._nextAggregateItem(e,i,s,n,r,a)}}),a)}catch(o){a(o)}}_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{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 m,predictType as _,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,{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC}),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,{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC}),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}else this.geometryType=p.point,this.typeIdField="",this.types=null,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(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC}),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(m(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(_(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)?m(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,m(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,m(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.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{DateTimeReferenceFieldIndex as e}from"../../arcadeTimeUtils.js";import t from"./cache.js";import{FeatureSetError as n,FeatureSetErrorCodes as i}from"./errorsupport.js";import s from"./FeatureSetIterator.js";import r from"./IdSet.js";import{FeatureServiceDatabaseType as a,layerGeometryEsriConstants as l,IdState as u,convertSquareUnitsToCode as h,convertLinearUnitsToCode as o,esriFieldToJson as c,layerGeometryEsriRestConstants as d}from"./shared.js";import{max as _,min as f,sum as p,variance as m,stdev as g,mean as y,distinct as T,count as F}from"./stats.js";import{isPromiseLike as I}from"../../../core/promiseUtils.js";import{WhereClause as b}from"../../../core/sql/WhereClause.js";import{union as w,geodesicArea as S,planarArea as x,geodesicLength as D,planarLength as P}from"../../../geometry/geometryEngineAsync.js";import k from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/FieldsIndex.js";class R{constructor(e){this.recentlyUsedQueries=null,this.featureSetQueryInterceptor=null,this._idstates=[],this._parent=null,this._wset=null,this._mainSetInUse=null,this._maxProcessing=200,this._maxQuery=500,this._totalCount=-1,this._databaseType=a.NotEvaluated,this._databaseTypeProbed=null,this.declaredRootClass="esri.arcade.featureset.support.FeatureSet",this._featureCache=[],this.typeIdField=null,this.types=null,this.fields=null,this.geometryType="",this.objectIdField="",this.globalIdField="",this.spatialReference=null,this.hasM=!1,this.hasZ=!1,this._transparent=!1,this.loaded=!1,this._loadPromise=null,this._fieldsIndex=null,this._dateFieldIndex=null,e&&e.lrucache&&(this.recentlyUsedQueries=e.lrucache),e&&e.interceptor&&(this.featureSetQueryInterceptor=e.interceptor)}optimisePagingFeatureQueries(e){this._parent&&this._parent.optimisePagingFeatureQueries(e)}_hasMemorySource(){return!0}prop(e,t){return void 0===t?this[e]:(void 0!==this[e]&&(this[e]=t),this)}end(){return null!==this._parent&&!0===this._parent._transparent?this._parent.end():this._parent}_ensureLoaded(){return this.load()}load(){return null===this._loadPromise&&(this._loadPromise=this.loadImpl()),this._loadPromise}async loadImpl(){return!0===this._parent?.loaded?(this._initialiseFeatureSet(),this):(await(this._parent?.load()),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.fields=[],this.typeIdField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new k({wkid:4326}),this.geometryType=l.point)}getField(e,t){let n;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(n=t),!!n)))),n}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=new C(this.fields)),this._fieldsIndex}_maxProcessingRate(){return null!==this._parent?Math.min(this._maxProcessing,this._parent._maxProcessingRate()):Math.min(this._maxProcessing,this._maxQueryRate())}_maxQueryRate(){return null!==this._parent?Math.max(this._maxQuery,this._parent._maxQueryRate()):this._maxQuery}_checkCancelled(e){if(null!=e&&e.aborted)throw new n(i.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,n,i,s){return null!==this._parent&&this._parent._canDoAggregates(e,t,n,i,s)}async _getAggregatePagesDataSourceDefinition(e,t,s,r,a,l,u){if(null===this._parent)throw new n(i.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,t,s,r,a,l,u)}async _getAgregagtePhysicalPage(e,t,s){if(null===this._parent)throw new n(i.NeverReach);return this._parent._getAgregagtePhysicalPage(e,t,s)}async databaseType(){if(this._databaseType===a.NotEvaluated){if(null!==t.applicationCache){const e=t.applicationCache.getDatabaseType(this._cacheableFeatureSetSourceKey());if(null!==e)return e}if(null!==this._databaseTypeProbed)return this._databaseTypeProbed;try{this._databaseTypeProbed=this._getDatabaseTypeImpl(),null!==t.applicationCache&&t.applicationCache.setDatabaseType(this._cacheableFeatureSetSourceKey(),this._databaseTypeProbed)}catch(e){throw null!==t.applicationCache&&t.applicationCache.clearDatabaseType(this._cacheableFeatureSetSourceKey()),e}return this._databaseTypeProbed}return this._databaseType}async _getDatabaseTypeImpl(){const e=[{thetype:a.SqlServer,testwhere:"(CAST( '2015-01-01' as DATETIME) = CAST( '2015-01-01' as DATETIME)) AND OBJECTID<0"},{thetype:a.Oracle,testwhere:"(TO_DATE('2003-11-18','YYYY-MM-DD') = TO_DATE('2003-11-18','YYYY-MM-DD')) AND OBJECTID<0"},{thetype:a.StandardisedNoInterval,testwhere:"(date '2015-01-01 10:10:10' = date '2015-01-01 10:10:10') AND OBJECTID<0"}];for(const t of e){if(!0===await this._runDatabaseProbe(t.testwhere))return t.thetype}return a.StandardisedNoInterval}_cacheableFeatureSetSourceKey(){return"MUSTBESET"}async _runDatabaseProbe(e){if(null!==this._parent)return this._parent._runDatabaseProbe(e);throw new n(i.NotImplemented)}isTable(){return this._parent?.isTable()??!1}_featureFromCache(e){if(void 0!==this._featureCache[e])return this._featureCache[e]}_isInFeatureSet(e){return u.Unknown}_getSet(e){throw new n(i.NotImplemented)}async _getFeature(e,t,s){if(this._checkCancelled(s),void 0!==this._featureFromCache(t))return this._featureFromCache(t);if(await this._getFeatures(e,t,this._maxProcessingRate(),s),this._checkCancelled(s),void 0!==this._featureFromCache(t))return this._featureFromCache(t);throw new n(i.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const n=new r([],e,!1,null),i=[];await this._getFeatures(n,-1,e.length,t),this._checkCancelled(t);for(const s of e)void 0!==this._featureFromCache(s)&&i.push(this._featureFromCache(s));return i}async _getFeatures(e,t,n,i){return"success"}_getFilteredSet(e,t,s,r,a){throw new n(i.NotImplemented)}async _refineSetBlock(e,t,n){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,n),this._refineSetBlock(e,t,n);this._checkCancelled(n);const i=e._candidates.length;this._refineKnowns(e,t);let s=i-e._candidates.length;if(0===e._candidates.length)return e;if(s>=t)return e;if(await this._refineIfParentKnown(e,t-s,n),this._checkCancelled(n),this._refineKnowns(e,t-s),s=i-e._candidates.length,s<t&&e._candidates.length>0){const i=t-s,r=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(r,r.length>i?i:e._candidates.length,n),this._checkCancelled(n),this._refineKnowns(e,t-s),e}return e}_fetchAndRefineFeatures(e,t,n){return null}_prepareFetchAndRefineSet(e){const t=[];for(let n=0;n<e.length;n++)this._isPhysicalFeature(e[n])&&t.push(e[n]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let n=0,i=null;const s=[];t=this._maxQueryRate();for(let r=0;r<e._candidates.length&&"GETPAGES"!==e._candidates[r];r++){let a=!1;const l=this._candidateIdTransform(e._candidates[r]);l!==e._candidates[r]&&(a=!0);const h=this._isInFeatureSet(l);if(h===u.InFeatureSet)!0===a?e._known.includes(l)||(e._known.push(l),n+=1):(e._known.push(e._candidates[r]),n+=1),null===i?i={start:r,end:r}:i.end===r-1?i.end=r:(s.push(i),i={start:r,end:r});else if(h===u.NotInFeatureSet)null===i?i={start:r,end:r}:i.end===r-1?i.end=r:(s.push(i),i={start:r,end:r}),n+=1;else if(h===u.Unknown&&(n+=1,!0===e._ordered))break;if(n>=t)break}null!==i&&s.push(i);for(let r=s.length-1;r>=0;r--)e._candidates.splice(s[r].start,s[r].end-s[r].start+1)}_refineIfParentKnown(e,t,n){const i=new r([],[],e._ordered,null);return i._candidates=e._candidates.slice(0),this._parent._refineSetBlock(i,t,n)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let n=0;for(let i=e._lastFetchedIndex;i<e._known.length;i++){if("GETPAGES"===e._known[i])return!0;if(void 0===this._featureCache[e._known[i]]&&(n+=1,n>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let n=0;for(let i=0;i<e._candidates.length;i++){if("GETPAGES"===e._candidates[i])return!0;if(n+=1,n>=t)break}return!1}async _expandPagedSet(e,t,s,r,a){if(null===this._parent)throw new n(i.NotImplemented);return this._parent._expandPagedSet(e,t,s,r,a)}async _expandPagedSetFeatureSet(e,t,n,i,s){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(i=1),0===i&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(i=2),0===i)return"finished";const r=await this._getPage(e,i,s);return n+r<t?this._expandPagedSet(e,t,n+r,0,s):"success"}async _getPage(e,t,n){const i=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){i.length=i.length-1;let t=0;for(let s=0;s<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+s>=e.pagesDefinition.internal.set.length);s++)i[i.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+s],t++;e.pagesDefinition.resultOffset+=t;let n=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(n=!0),!1===n&&i.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,n),this._getPage(e,t,n)}_getPhysicalPage(e,t,n){return null}_clonePageDefinition(e){return null===this._parent?null:this._parent._clonePageDefinition(e)}_first(e){return this.iterator(e).next()}first(e){return this._first(e)}async calculateStatistic(e,t,n,i){await this._ensureLoaded();let s=await this._stat(e,t,"",null,null,n,i);return!1===s.calculated&&(s=await this._manualStat(e,t,n,i)),s.result}async _manualStat(e,t,n,i){let s=null;switch(e.toLowerCase()){case"count":return s=await F(this,i),{calculated:!0,result:s};case"distinct":return s=await T(this,t,n,i),{calculated:!0,result:s};case"avg":case"mean":return s=await y(this,t,i),{calculated:!0,result:s};case"stdev":return s=await g(this,t,i),{calculated:!0,result:s};case"variance":return s=await m(this,t,i),{calculated:!0,result:s};case"sum":return s=await p(this,t,i),{calculated:!0,result:s};case"min":return s=await f(this,t,i),{calculated:!0,result:s};case"max":return s=await _(this,t,i),{calculated:!0,result:s};default:return{calculated:!0,result:0}}}async _stat(e,t,n,i,s,r,a){const l=await this._parent._stat(e,t,n,i,s,r,a);return!1===l.calculated?null===s&&""===n&&null===i?this._manualStat(e,t,r,a):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),n=[];return new Promise(((e,i)=>{this._unionShapeInBatches(n,t,e,i)}))}_unionAllGeom(e){return new Promise(((t,n)=>{const i=this.iterator(this._defaultTracker(e)),s=[];this._unionShapeInBatches(s,i,t,n)}))}_unionShapeInBatches(e,t,n,i){t.next().then((s=>{try{null!==s&&null!==s.geometry&&e.push(s.geometry),e.length>30||null===s&&e.length>1?w(e).then((r=>{try{null===s?n(r):(e=[r],this._unionShapeInBatches(e,t,n,i))}catch(a){i(a)}}),i):null===s?1===e.length?n(e[0]):n(null):this._unionShapeInBatches(e,t,n,i)}catch(r){i(r)}}),i)}iterator(e){return new s(this,e)}intersection(e,t=!1){return R._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,n=!0){return R._featuresetFunctions.difference.bind(this)(e,t,n)}symmetricDifference(e,t=!1,n=!0){return R._featuresetFunctions.symmetricDifference.bind(this)(e,t,n)}morphShape(e,t,n="unknown",i=null){return R._featuresetFunctions.morphShape.bind(this)(e,t,n,i)}morphShapeAndAttributes(e,t,n="unknown"){return R._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,n)}union(e,t=!1){return R._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return R._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return R._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return R._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return R._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return R._featuresetFunctions.relate.bind(this)(e,t)}within(e){return R._featuresetFunctions.within.bind(this)(e)}touches(e){return R._featuresetFunctions.touches.bind(this)(e)}top(e){return R._featuresetFunctions.top.bind(this)(e)}crosses(e){return R._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,n,i=!0){return R._featuresetFunctions.buffer.bind(this)(e,t,n,i)}filter(e,t=null){return R._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return R._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return R._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return R._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,n){return new Promise(((i,s)=>{this._reduceImpl(this.iterator(this._defaultTracker(n)),e,t,0,i,s,0)}))}_reduceImpl(e,t,n,i,s,r,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._reduceImpl(e,t,n,i,s,r,a)}));e.next().then((l=>{try{if(null===l)s(n);else{const u=t(n,l,i,this);I(u)?u.then((n=>{this._reduceImpl(e,t,n,i+1,s,r,a)}),r):this._reduceImpl(e,t,u,i+1,s,r,a)}}catch(u){r(u)}}),r)}catch(l){r(l)}}removeField(e){return R._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,n=null){return R._featuresetFunctions.addField.bind(this)(e,t,n)}sumArea(e,t=!1,n){const i=h(e);return this.reduce(((e,n)=>null===n.geometry?0:t?S(n.geometry,i).then((t=>e+t)):x(n.geometry,i).then((t=>e+t))),0,n)}sumLength(e,t=!1,n){const i=o(e);return this.reduce(((e,n)=>null===n.geometry?0:t?D(n.geometry,i).then((t=>e+t)):P(n.geometry,i).then((t=>e+t))),0,n)}_substituteVars(e,t){if(null!==t){const n={};for(const e in t)n[e.toLowerCase()]=t[e];e.parameters=n}}async distinct(e,t=1e3,n=null,i){await this.load();const s=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(s,n),this.calculateStatistic("distinct",s,t,this._defaultTracker(i))}async min(e,t=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(i,t),this.calculateStatistic("min",i,-1,this._defaultTracker(n))}async max(e,t=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(i,t),this.calculateStatistic("max",i,-1,this._defaultTracker(n))}async avg(e,t=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(i,t),this.calculateStatistic("avg",i,-1,this._defaultTracker(n))}async sum(e,t=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(i,t),this.calculateStatistic("sum",i,-1,this._defaultTracker(n))}async stdev(e,t=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(i,t),this.calculateStatistic("stdev",i,-1,this._defaultTracker(n))}async variance(e,t=null,n){await this.load();const i=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC});return this._substituteVars(i,t),this.calculateStatistic("variance",i,-1,this._defaultTracker(n))}async count(e){return await this.load(),this.calculateStatistic("count",b.create("1",this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerTimeInfoTimeZoneDefaultUTC}),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((n,i)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,n,i,0)}))}_forEachImpl(e,t,n,i,s,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._forEachImpl(e,t,n,i,s,r)}),0);e.next().then((a=>{try{if(null===a)i(n);else{const l=t(a);null==l?this._forEachImpl(e,t,n,i,s,r):I(l)?l.then((()=>{try{this._forEachImpl(e,t,n,i,s,r)}catch(a){s(a)}}),s):this._forEachImpl(e,t,n,i,s,r)}}catch(l){s(l)}}),s)}catch(a){s(a)}}convertToJSON(e){const t={layerDefinition:{geometryType:this.geometryType,fields:[]},featureSet:{features:[],geometryType:this.geometryType}};for(let n=0;n<this.fields.length;n++)t.layerDefinition.fields.push(c(this.fields[n]));return this.reduce(((e,n)=>{const i={geometry:n.geometry&&n.geometry.toJSON(),attributes:{}};for(const t in n.attributes)i.attributes[t]=n.attributes[t];return t.featureSet.features.push(i),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,n,i,s){return this._parent.queryAttachments(e,t,n,i,s)}serviceUrl(){return this._parent.serviceUrl()}subtypes(){return this.typeIdField?{subtypeField:this.typeIdField,subtypes:this.types?this.types.map((e=>({name:e.name,code:e.id}))):[]}:null}relationshipMetaData(){return this._parent.relationshipMetaData()}get gdbVersion(){return this._parent?this._parent.gdbVersion:""}schema(){const e=[];for(const t of this.fields)e.push(c(t));return{objectIdField:this.objectIdField,globalIdField:this.globalIdField,geometryType:void 0===d[this.geometryType]?"esriGeometryNull":d[this.geometryType],fields:e}}async convertToText(e,t){if("schema"===e)return await this._ensureLoaded(),JSON.stringify(this.schema());if("featureset"===e){await this._ensureLoaded();const e=[];await this.reduce(((t,n)=>{const i={geometry:n.geometry?n.geometry.toJSON():null,attributes:n.attributes};return null!==i.geometry&&i.geometry.spatialReference&&delete i.geometry.spatialReference,e.push(i),1}),0,t);const n=this.schema();return n.features=e,n.spatialReference=this.spatialReference.toJSON(),JSON.stringify(n)}return this.castToText()}getFeatureByObjectId(e,t){return this._parent.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._parent.getOwningSystemUrl()}getIdentityUser(){return this._parent.getIdentityUser()}getRootFeatureSet(){return null!==this._parent?this._parent.getRootFeatureSet():this}getDataSourceFeatureSet(){return null!==this._parent?this._parent.getDataSourceFeatureSet():this}castAsJson(e=null){return"keeptype"===e?.featureset?this:"none"===e?.featureset?null:{type:"FeatureSet"}}async castAsJsonAsync(e=null,t=null){if("keeptype"===t?.featureset)return this;if("schema"===t?.featureset)return await this._ensureLoaded(),JSON.parse(JSON.stringify(this.schema()));if("none"===t?.featureset)return null;await this._ensureLoaded();const n=[];await this.reduce(((e,i)=>{const s={geometry:i.geometry?!0===t?.keepGeometryType?i.geometry:i.geometry.toJSON():null,attributes:i.attributes};return null!==s.geometry&&s.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete s.geometry.spatialReference,n.push(s),1}),0,e);const i=this.schema();return i.features=n,i.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),i}get dateTimeReferenceFieldIndex(){return null===this._dateFieldIndex&&(this._dateFieldIndex=e.create(this.getFieldsIndex(),this)),this._dateFieldIndex}fieldTimeZone(e){return this.dateTimeReferenceFieldIndex.fieldTimeZone(e)}get preferredTimeReference(){return this._parent?.preferredTimeReference??null}get dateFieldsTimeReference(){return this._parent?.dateFieldsTimeReference??null}get datesInUnknownTimezone(){return this._parent.datesInUnknownTimezone}get editFieldsInfo(){return this._parent?.editFieldsInfo??null}get timeInfo(){return this._parent?.timeInfo??null}}R._featuresetFunctions={};export{R as default};
|
|
5
|
+
import{DateTimeReferenceFieldIndex as e}from"../../arcadeTimeUtils.js";import t from"./cache.js";import{FeatureSetError as i,FeatureSetErrorCodes as n}from"./errorsupport.js";import s from"./FeatureSetIterator.js";import a from"./IdSet.js";import{FeatureServiceDatabaseType as r,layerGeometryEsriConstants as l,IdState as u,convertSquareUnitsToCode as h,convertLinearUnitsToCode as o,esriFieldToJson as c,layerGeometryEsriRestConstants as d}from"./shared.js";import{max as _,min as f,sum as p,variance as m,stdev as g,mean as y,distinct as F,count as T}from"./stats.js";import{isPromiseLike as I}from"../../../core/promiseUtils.js";import{WhereClause as b}from"../../../core/sql/WhereClause.js";import{union as w,geodesicArea as S,planarArea as D,geodesicLength as x,planarLength as P}from"../../../geometry/geometryEngineAsync.js";import k from"../../../geometry/SpatialReference.js";import C from"../../../layers/support/FieldsIndex.js";class R{constructor(e){this.recentlyUsedQueries=null,this.featureSetQueryInterceptor=null,this._idstates=[],this._parent=null,this._wset=null,this._mainSetInUse=null,this._maxProcessing=200,this._maxQuery=500,this._totalCount=-1,this._databaseType=r.NotEvaluated,this._databaseTypeProbed=null,this.declaredRootClass="esri.arcade.featureset.support.FeatureSet",this._featureCache=[],this.typeIdField=null,this.types=null,this.fields=null,this.geometryType="",this.objectIdField="",this.globalIdField="",this.spatialReference=null,this.hasM=!1,this.hasZ=!1,this._transparent=!1,this.loaded=!1,this._loadPromise=null,this._fieldsIndex=null,this._dateFieldIndex=null,e&&e.lrucache&&(this.recentlyUsedQueries=e.lrucache),e&&e.interceptor&&(this.featureSetQueryInterceptor=e.interceptor)}optimisePagingFeatureQueries(e){this._parent&&this._parent.optimisePagingFeatureQueries(e)}_hasMemorySource(){return!0}prop(e,t){return void 0===t?this[e]:(void 0!==this[e]&&(this[e]=t),this)}end(){return null!==this._parent&&!0===this._parent._transparent?this._parent.end():this._parent}_ensureLoaded(){return this.load()}load(){return null===this._loadPromise&&(this._loadPromise=this.loadImpl()),this._loadPromise}async loadImpl(){return!0===this._parent?.loaded?(this._initialiseFeatureSet(),this):(await(this._parent?.load()),this._initialiseFeatureSet(),this)}_initialiseFeatureSet(){null!==this._parent?(this.fields=this._parent.fields.slice(0),this.geometryType=this._parent.geometryType,this.objectIdField=this._parent.objectIdField,this.globalIdField=this._parent.globalIdField,this.spatialReference=this._parent.spatialReference,this.hasM=this._parent.hasM,this.hasZ=this._parent.hasZ,this.typeIdField=this._parent.typeIdField,this.types=this._parent.types):(this.fields=[],this.typeIdField="",this.objectIdField="",this.globalIdField="",this.spatialReference=new k({wkid:4326}),this.geometryType=l.point)}getField(e,t){let i;return(t=t||this.fields)&&(e=e.toLowerCase(),t.some((t=>(t&&t.name.toLowerCase()===e&&(i=t),!!i)))),i}getFieldsIndex(){return null===this._fieldsIndex&&(this._fieldsIndex=new C(this.fields)),this._fieldsIndex}_maxProcessingRate(){return null!==this._parent?Math.min(this._maxProcessing,this._parent._maxProcessingRate()):Math.min(this._maxProcessing,this._maxQueryRate())}_maxQueryRate(){return null!==this._parent?Math.max(this._maxQuery,this._parent._maxQueryRate()):this._maxQuery}_checkCancelled(e){if(null!=e&&e.aborted)throw new i(n.Cancelled)}nativeCapabilities(){return this._parent.nativeCapabilities()}async _canDoAggregates(e,t,i,n,s){return null!==this._parent&&this._parent._canDoAggregates(e,t,i,n,s)}async _getAggregatePagesDataSourceDefinition(e,t,s,a,r,l,u){if(null===this._parent)throw new i(n.NeverReach);return this._parent._getAggregatePagesDataSourceDefinition(e,t,s,a,r,l,u)}async _getAgregagtePhysicalPage(e,t,s){if(null===this._parent)throw new i(n.NeverReach);return this._parent._getAgregagtePhysicalPage(e,t,s)}async databaseType(){if(this._databaseType===r.NotEvaluated){if(null!==t.applicationCache){const e=t.applicationCache.getDatabaseType(this._cacheableFeatureSetSourceKey());if(null!==e)return e}if(null!==this._databaseTypeProbed)return this._databaseTypeProbed;try{this._databaseTypeProbed=this._getDatabaseTypeImpl(),null!==t.applicationCache&&t.applicationCache.setDatabaseType(this._cacheableFeatureSetSourceKey(),this._databaseTypeProbed)}catch(e){throw null!==t.applicationCache&&t.applicationCache.clearDatabaseType(this._cacheableFeatureSetSourceKey()),e}return this._databaseTypeProbed}return this._databaseType}async _getDatabaseTypeImpl(){const e=[{thetype:r.SqlServer,testwhere:"(CAST( '2015-01-01' as DATETIME) = CAST( '2015-01-01' as DATETIME)) AND OBJECTID<0"},{thetype:r.Oracle,testwhere:"(TO_DATE('2003-11-18','YYYY-MM-DD') = TO_DATE('2003-11-18','YYYY-MM-DD')) AND OBJECTID<0"},{thetype:r.StandardisedNoInterval,testwhere:"(date '2015-01-01 10:10:10' = date '2015-01-01 10:10:10') AND OBJECTID<0"}];for(const t of e){if(!0===await this._runDatabaseProbe(t.testwhere))return t.thetype}return r.StandardisedNoInterval}_cacheableFeatureSetSourceKey(){return"MUSTBESET"}async _runDatabaseProbe(e){if(null!==this._parent)return this._parent._runDatabaseProbe(e);throw new i(n.NotImplemented)}isTable(){return this._parent?.isTable()??!1}_featureFromCache(e){if(void 0!==this._featureCache[e])return this._featureCache[e]}_isInFeatureSet(e){return u.Unknown}_getSet(e){throw new i(n.NotImplemented)}async _getFeature(e,t,s){if(this._checkCancelled(s),void 0!==this._featureFromCache(t))return this._featureFromCache(t);if(await this._getFeatures(e,t,this._maxProcessingRate(),s),this._checkCancelled(s),void 0!==this._featureFromCache(t))return this._featureFromCache(t);throw new i(n.MissingFeatures)}async _getFeatureBatch(e,t){this._checkCancelled(t);const i=new a([],e,!1,null),n=[];await this._getFeatures(i,-1,e.length,t),this._checkCancelled(t);for(const s of e)void 0!==this._featureFromCache(s)&&n.push(this._featureFromCache(s));return n}async _getFeatures(e,t,i,n){return"success"}_getFilteredSet(e,t,s,a,r){throw new i(n.NotImplemented)}async _refineSetBlock(e,t,i){if(!0===this._checkIfNeedToExpandCandidatePage(e,this._maxQueryRate()))return await this._expandPagedSet(e,this._maxQueryRate(),0,0,i),this._refineSetBlock(e,t,i);this._checkCancelled(i);const n=e._candidates.length;this._refineKnowns(e,t);let s=n-e._candidates.length;if(0===e._candidates.length)return e;if(s>=t)return e;if(await this._refineIfParentKnown(e,t-s,i),this._checkCancelled(i),this._refineKnowns(e,t-s),s=n-e._candidates.length,s<t&&e._candidates.length>0){const n=t-s,a=this._prepareFetchAndRefineSet(e._candidates);return await this._fetchAndRefineFeatures(a,a.length>n?n:e._candidates.length,i),this._checkCancelled(i),this._refineKnowns(e,t-s),e}return e}_fetchAndRefineFeatures(e,t,i){return null}_prepareFetchAndRefineSet(e){const t=[];for(let i=0;i<e.length;i++)this._isPhysicalFeature(e[i])&&t.push(e[i]);return t}_isPhysicalFeature(e){return null===this._parent||this._parent._isPhysicalFeature(e)}_refineKnowns(e,t){let i=0,n=null;const s=[];t=this._maxQueryRate();for(let a=0;a<e._candidates.length&&"GETPAGES"!==e._candidates[a];a++){let r=!1;const l=this._candidateIdTransform(e._candidates[a]);l!==e._candidates[a]&&(r=!0);const h=this._isInFeatureSet(l);if(h===u.InFeatureSet)!0===r?e._known.includes(l)||(e._known.push(l),i+=1):(e._known.push(e._candidates[a]),i+=1),null===n?n={start:a,end:a}:n.end===a-1?n.end=a:(s.push(n),n={start:a,end:a});else if(h===u.NotInFeatureSet)null===n?n={start:a,end:a}:n.end===a-1?n.end=a:(s.push(n),n={start:a,end:a}),i+=1;else if(h===u.Unknown&&(i+=1,!0===e._ordered))break;if(i>=t)break}null!==n&&s.push(n);for(let a=s.length-1;a>=0;a--)e._candidates.splice(s[a].start,s[a].end-s[a].start+1)}_refineIfParentKnown(e,t,i){const n=new a([],[],e._ordered,null);return n._candidates=e._candidates.slice(0),this._parent._refineSetBlock(n,t,i)}_candidateIdTransform(e){return this._parent._candidateIdTransform(e)}_checkIfNeedToExpandKnownPage(e,t){if(null===e.pagesDefinition)return!1;let i=0;for(let n=e._lastFetchedIndex;n<e._known.length;n++){if("GETPAGES"===e._known[n])return!0;if(void 0===this._featureCache[e._known[n]]&&(i+=1,i>=t))break}return!1}_checkIfNeedToExpandCandidatePage(e,t){if(null===e.pagesDefinition)return!1;let i=0;for(let n=0;n<e._candidates.length;n++){if("GETPAGES"===e._candidates[n])return!0;if(i+=1,i>=t)break}return!1}async _expandPagedSet(e,t,s,a,r){if(null===this._parent)throw new i(n.NotImplemented);return this._parent._expandPagedSet(e,t,s,a,r)}async _expandPagedSetFeatureSet(e,t,i,n,s){if(e._known.length>0&&"GETPAGES"===e._known[e._known.length-1]&&(n=1),0===n&&e._candidates.length>0&&"GETPAGES"===e._candidates[e._candidates.length-1]&&(n=2),0===n)return"finished";const a=await this._getPage(e,n,s);return i+a<t?this._expandPagedSet(e,t,i+a,0,s):"success"}async _getPage(e,t,i){const n=1===t?e._known:e._candidates;if(e.pagesDefinition.internal.set.length>e.pagesDefinition.resultOffset||!0===e.pagesDefinition.internal.fullyResolved){n.length=n.length-1;let t=0;for(let s=0;s<e.pagesDefinition.resultRecordCount&&!(e.pagesDefinition.resultOffset+s>=e.pagesDefinition.internal.set.length);s++)n[n.length]=e.pagesDefinition.internal.set[e.pagesDefinition.resultOffset+s],t++;e.pagesDefinition.resultOffset+=t;let i=!1;return!0===e.pagesDefinition.internal.fullyResolved&&e.pagesDefinition.internal.set.length<=e.pagesDefinition.resultOffset&&(i=!0),!1===i&&n.push("GETPAGES"),t}return await this._getPhysicalPage(e,t,i),this._getPage(e,t,i)}_getPhysicalPage(e,t,i){return null}_clonePageDefinition(e){return null===this._parent?null:this._parent._clonePageDefinition(e)}_first(e){return this.iterator(e).next()}first(e){return this._first(e)}async calculateStatistic(e,t,i,n){await this._ensureLoaded();let s=await this._stat(e,t,"",null,null,i,n);return!1===s.calculated&&(s=await this._manualStat(e,t,i,n)),s.result}async _manualStat(e,t,i,n){let s=null;switch(e.toLowerCase()){case"count":return s=await T(this,n),{calculated:!0,result:s};case"distinct":return s=await F(this,t,i,n),{calculated:!0,result:s};case"avg":case"mean":return s=await y(this,t,n),{calculated:!0,result:s};case"stdev":return s=await g(this,t,n),{calculated:!0,result:s};case"variance":return s=await m(this,t,n),{calculated:!0,result:s};case"sum":return s=await p(this,t,n),{calculated:!0,result:s};case"min":return s=await f(this,t,n),{calculated:!0,result:s};case"max":return s=await _(this,t,n),{calculated:!0,result:s};default:return{calculated:!0,result:0}}}async _stat(e,t,i,n,s,a,r){const l=await this._parent._stat(e,t,i,n,s,a,r);return!1===l.calculated?null===s&&""===i&&null===n?this._manualStat(e,t,a,r):{calculated:!1}:l}_unionAllGeomSelf(e){const t=this.iterator(this._defaultTracker(e)),i=[];return new Promise(((e,n)=>{this._unionShapeInBatches(i,t,e,n)}))}_unionAllGeom(e){return new Promise(((t,i)=>{const n=this.iterator(this._defaultTracker(e)),s=[];this._unionShapeInBatches(s,n,t,i)}))}_unionShapeInBatches(e,t,i,n){t.next().then((s=>{try{null!==s&&null!==s.geometry&&e.push(s.geometry),e.length>30||null===s&&e.length>1?w(e).then((a=>{try{null===s?i(a):(e=[a],this._unionShapeInBatches(e,t,i,n))}catch(r){n(r)}}),n):null===s?1===e.length?i(e[0]):i(null):this._unionShapeInBatches(e,t,i,n)}catch(a){n(a)}}),n)}iterator(e){return new s(this,e)}intersection(e,t=!1){return R._featuresetFunctions.intersection.bind(this)(e,t)}difference(e,t=!1,i=!0){return R._featuresetFunctions.difference.bind(this)(e,t,i)}symmetricDifference(e,t=!1,i=!0){return R._featuresetFunctions.symmetricDifference.bind(this)(e,t,i)}morphShape(e,t,i="unknown",n=null){return R._featuresetFunctions.morphShape.bind(this)(e,t,i,n)}morphShapeAndAttributes(e,t,i="unknown"){return R._featuresetFunctions.morphShapeAndAttributes.bind(this)(e,t,i)}union(e,t=!1){return R._featuresetFunctions.union.bind(this)(e,t)}intersects(e){return R._featuresetFunctions.intersects.bind(this)(e)}envelopeIntersects(e){return R._featuresetFunctions.envelopeIntersects.bind(this)(e)}contains(e){return R._featuresetFunctions.contains.bind(this)(e)}overlaps(e){return R._featuresetFunctions.overlaps.bind(this)(e)}relate(e,t){return R._featuresetFunctions.relate.bind(this)(e,t)}within(e){return R._featuresetFunctions.within.bind(this)(e)}touches(e){return R._featuresetFunctions.touches.bind(this)(e)}top(e){return R._featuresetFunctions.top.bind(this)(e)}crosses(e){return R._featuresetFunctions.crosses.bind(this)(e)}buffer(e,t,i,n=!0){return R._featuresetFunctions.buffer.bind(this)(e,t,i,n)}filter(e,t=null){return R._featuresetFunctions.filter.bind(this)(e,t)}orderBy(e){return R._featuresetFunctions.orderBy.bind(this)(e)}dissolve(e,t){return R._featuresetFunctions.dissolve.bind(this)(e,t)}groupby(e,t){return R._featuresetFunctions.groupby.bind(this)(e,t)}reduce(e,t=null,i){return new Promise(((n,s)=>{this._reduceImpl(this.iterator(this._defaultTracker(i)),e,t,0,n,s,0)}))}_reduceImpl(e,t,i,n,s,a,r){try{if(++r>1e3)return void setTimeout((()=>{r=0,this._reduceImpl(e,t,i,n,s,a,r)}));e.next().then((l=>{try{if(null===l)s(i);else{const u=t(i,l,n,this);I(u)?u.then((i=>{this._reduceImpl(e,t,i,n+1,s,a,r)}),a):this._reduceImpl(e,t,u,n+1,s,a,r)}}catch(u){a(u)}}),a)}catch(l){a(l)}}removeField(e){return R._featuresetFunctions.removeField.bind(this)(e)}addField(e,t,i=null){return R._featuresetFunctions.addField.bind(this)(e,t,i)}sumArea(e,t=!1,i){const n=h(e);return this.reduce(((e,i)=>null===i.geometry?0:t?S(i.geometry,n).then((t=>e+t)):D(i.geometry,n).then((t=>e+t))),0,i)}sumLength(e,t=!1,i){const n=o(e);return this.reduce(((e,i)=>null===i.geometry?0:t?x(i.geometry,n).then((t=>e+t)):P(i.geometry,n).then((t=>e+t))),0,i)}_substituteVars(e,t){if(null!==t){const i={};for(const e in t)i[e.toLowerCase()]=t[e];e.parameters=i}}async distinct(e,t=1e3,i=null,n){await this.load();const s=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(s,i),this.calculateStatistic("distinct",s,t,this._defaultTracker(n))}async min(e,t=null,i){await this.load();const n=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(n,t),this.calculateStatistic("min",n,-1,this._defaultTracker(i))}async max(e,t=null,i){await this.load();const n=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(n,t),this.calculateStatistic("max",n,-1,this._defaultTracker(i))}async avg(e,t=null,i){await this.load();const n=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(n,t),this.calculateStatistic("avg",n,-1,this._defaultTracker(i))}async sum(e,t=null,i){await this.load();const n=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(n,t),this.calculateStatistic("sum",n,-1,this._defaultTracker(i))}async stdev(e,t=null,i){await this.load();const n=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(n,t),this.calculateStatistic("stdev",n,-1,this._defaultTracker(i))}async variance(e,t=null,i){await this.load();const n=b.create(e,this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC});return this._substituteVars(n,t),this.calculateStatistic("variance",n,-1,this._defaultTracker(i))}async count(e){return await this.load(),this.calculateStatistic("count",b.create("1",this.getFieldsIndex(),{timeZone:this.dateTimeReferenceFieldIndex.layerDateFieldsTimeZoneDefaultUTC}),-1,this._defaultTracker(e))}_defaultTracker(e){return e??{aborted:!1}}forEach(e,t){return new Promise(((i,n)=>{this._forEachImpl(this.iterator(this._defaultTracker(t)),e,this,i,n,0)}))}_forEachImpl(e,t,i,n,s,a){try{if(++a>1e3)return void setTimeout((()=>{a=0,this._forEachImpl(e,t,i,n,s,a)}),0);e.next().then((r=>{try{if(null===r)n(i);else{const l=t(r);null==l?this._forEachImpl(e,t,i,n,s,a):I(l)?l.then((()=>{try{this._forEachImpl(e,t,i,n,s,a)}catch(r){s(r)}}),s):this._forEachImpl(e,t,i,n,s,a)}}catch(l){s(l)}}),s)}catch(r){s(r)}}convertToJSON(e){const t={layerDefinition:{geometryType:this.geometryType,fields:[]},featureSet:{features:[],geometryType:this.geometryType}};for(let i=0;i<this.fields.length;i++)t.layerDefinition.fields.push(c(this.fields[i]));return this.reduce(((e,i)=>{const n={geometry:i.geometry&&i.geometry.toJSON(),attributes:{}};for(const t in i.attributes)n.attributes[t]=i.attributes[t];return t.featureSet.features.push(n),1}),0,e).then((()=>t))}castToText(e=!1){return"object, FeatureSet"}queryAttachments(e,t,i,n,s){return this._parent.queryAttachments(e,t,i,n,s)}serviceUrl(){return this._parent.serviceUrl()}subtypes(){return this.typeIdField?{subtypeField:this.typeIdField,subtypes:this.types?this.types.map((e=>({name:e.name,code:e.id}))):[]}:null}relationshipMetaData(){return this._parent.relationshipMetaData()}get gdbVersion(){return this._parent?this._parent.gdbVersion:""}schema(){const e=[];for(const t of this.fields)e.push(c(t));return{objectIdField:this.objectIdField,globalIdField:this.globalIdField,geometryType:void 0===d[this.geometryType]?"esriGeometryNull":d[this.geometryType],fields:e}}async convertToText(e,t){if("schema"===e)return await this._ensureLoaded(),JSON.stringify(this.schema());if("featureset"===e){await this._ensureLoaded();const e=[];await this.reduce(((t,i)=>{const n={geometry:i.geometry?i.geometry.toJSON():null,attributes:i.attributes};return null!==n.geometry&&n.geometry.spatialReference&&delete n.geometry.spatialReference,e.push(n),1}),0,t);const i=this.schema();return i.features=e,i.spatialReference=this.spatialReference.toJSON(),JSON.stringify(i)}return this.castToText()}getFeatureByObjectId(e,t){return this._parent.getFeatureByObjectId(e,t)}getOwningSystemUrl(){return this._parent.getOwningSystemUrl()}getIdentityUser(){return this._parent.getIdentityUser()}getRootFeatureSet(){return null!==this._parent?this._parent.getRootFeatureSet():this}getDataSourceFeatureSet(){return null!==this._parent?this._parent.getDataSourceFeatureSet():this}castAsJson(e=null){return"keeptype"===e?.featureset?this:"none"===e?.featureset?null:{type:"FeatureSet"}}async castAsJsonAsync(e=null,t=null){if("keeptype"===t?.featureset)return this;if("schema"===t?.featureset)return await this._ensureLoaded(),JSON.parse(JSON.stringify(this.schema()));if("none"===t?.featureset)return null;await this._ensureLoaded();const i=[];await this.reduce(((e,n)=>{const s={geometry:n.geometry?!0===t?.keepGeometryType?n.geometry:n.geometry.toJSON():null,attributes:n.attributes};return null!==s.geometry&&s.geometry.spatialReference&&!0!==t?.keepGeometryType&&delete s.geometry.spatialReference,i.push(s),1}),0,e);const n=this.schema();return n.features=i,n.spatialReference=!0===t?.keepGeometryType?this.spatialReference:this.spatialReference?.toJSON(),n}get dateTimeReferenceFieldIndex(){return null===this._dateFieldIndex&&(this._dateFieldIndex=e.create(this.getFieldsIndex(),this)),this._dateFieldIndex}fieldTimeZone(e){return this.dateTimeReferenceFieldIndex.fieldTimeZone(e)}get preferredTimeReference(){return this._parent?.preferredTimeReference??null}get dateFieldsTimeReference(){return this._parent?.dateFieldsTimeReference??null}get datesInUnknownTimezone(){return this._parent.datesInUnknownTimezone}get editFieldsInfo(){return this._parent?.editFieldsInfo??null}get timeInfo(){return this._parent?.timeInfo??null}}R._featuresetFunctions={};export{R 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.28/esri/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{doSubstitutions as e}from"../../executionError.js";var t;!function(e){e.InvalidFunctionParameters="InvalidFunctionParameters",e.UnsupportedSqlFunction="UnsupportedSqlFunction",e.UnsupportedOperator="UnsupportedOperator",e.UnsupportedSyntax="UnsupportedSyntax",e.UnsupportedIsRhs="UnsupportedIsRhs",e.UnsupportedIsLhs="UnsupportedIsLhs",e.InvalidDataType="InvalidDataType",e.CannotCastValue="CannotCastValue",e.FunctionNotRecognized="FunctionNotRecognized",e.InvalidTime="InvalidTime",e.InvalidParameterCount="InvalidParameterCount",e.InvalidTimeStamp="InvalidTimeStamp",e.InvalidDate="InvalidDate",e.InvalidOperator="InvalidOperator",e.IllegalInterval="IllegalInterval",e.YearMonthIntervals="YearMonthIntervals",e.PrimarySecondaryQualifiers="rimarySecondaryQualifiers",e.MissingStatisticParameters="MissingStatisticParameters"}(t||(t={}));const a={[t.MissingStatisticParameters]:"Statistic does not have 1 or 0 Parameters",[t.InvalidFunctionParameters]:"Invalid parameters for call to {function}",[t.UnsupportedIsLhs]:"Unsupported left hand expression in is statement",[t.UnsupportedIsRhs]:"Unsupported right hand expression in is statement",[t.UnsupportedOperator]:"Unsupported operator - {operator}",[t.UnsupportedSyntax]:"Unsupported syntax - {node}",[t.UnsupportedSqlFunction]:"Sql function not found = {function}",[t.InvalidDataType]:"Invalid sql data type",[t.InvalidDate]:"Invalid date encountered",[t.InvalidOperator]:"Invalid operator encountered",[t.InvalidTime]:"Invalid time encountered",[t.IllegalInterval]:"Illegal interval",[t.FunctionNotRecognized]:"Function not recognized",[t.InvalidTimeStamp]:"Invalid timestamp encountered",[t.InvalidParameterCount]:"Invalid parameter count for call to {name}",[t.PrimarySecondaryQualifiers]:"Primary and Secondary SqlInterval qualifiers not supported",[t.YearMonthIntervals]:"Year-Month Intervals not supported",[t.CannotCastValue]:"Cannot cast value to the required data type"};class n extends Error{constructor(t,r){super(e(a[t],r)),this.declaredRootClass="esri.arcade.featureset.support.sqlerror",Error.captureStackTrace&&Error.captureStackTrace(this,n)}}var r;!function(e){e.NeverReach="NeverReach",e.NotImplemented="NotImplemented",e.Cancelled="Cancelled",e.InvalidStatResponse="InvalidStatResponse",e.InvalidRequest="InvalidRequest",e.RequestFailed="RequestFailed",e.MissingFeatures="MissingFeatures",e.AggregationFieldNotFound="AggregationFieldNotFound",e.DataElementsNotFound="DataElementsNotFound"}(r||(r={}));const o={[r.Cancelled]:"Cancelled",[r.InvalidStatResponse]:"Invalid statistics response from service",[r.InvalidRequest]:"Invalid request",[r.RequestFailed]:"Request failed - {reason}",[r.MissingFeatures]:"Missing features",[r.AggregationFieldNotFound]:"Aggregation field not found",[r.DataElementsNotFound]:"Data elements not found on service",[r.NeverReach]:"Encountered unreachable logic",[r.NotImplemented]:"Not implemented"};class s extends Error{constructor(t,a){super(e(o[t],a)),this.declaredRootClass="esri.arcade.featureset.support.featureseterror",Error.captureStackTrace&&Error.captureStackTrace(this,s)}}export{s as FeatureSetError,r as FeatureSetErrorCodes,o as FeatureSetErrorMessages,n as SqlError,t as SqlErrorCodes,a as SqlErrorMessages};
|
|
5
|
+
import{doSubstitutions as e}from"../../executionError.js";var t;!function(e){e.InvalidFunctionParameters="InvalidFunctionParameters",e.InvalidValueForAggregateFunction="InvalidValueForAggregateFunction",e.UnsupportedSqlFunction="UnsupportedSqlFunction",e.UnsupportedOperator="UnsupportedOperator",e.UnsupportedSyntax="UnsupportedSyntax",e.UnsupportedIsRhs="UnsupportedIsRhs",e.UnsupportedIsLhs="UnsupportedIsLhs",e.InvalidDataType="InvalidDataType",e.CannotCastValue="CannotCastValue",e.FunctionNotRecognized="FunctionNotRecognized",e.InvalidTime="InvalidTime",e.InvalidParameterCount="InvalidParameterCount",e.InvalidTimeStamp="InvalidTimeStamp",e.InvalidDate="InvalidDate",e.InvalidOperator="InvalidOperator",e.IllegalInterval="IllegalInterval",e.YearMonthIntervals="YearMonthIntervals",e.PrimarySecondaryQualifiers="rimarySecondaryQualifiers",e.MissingStatisticParameters="MissingStatisticParameters"}(t||(t={}));const a={[t.InvalidValueForAggregateFunction]:"Invalid value used in aggregate function",[t.MissingStatisticParameters]:"Statistic does not have 1 or 0 Parameters",[t.InvalidFunctionParameters]:"Invalid parameters for call to {function}",[t.UnsupportedIsLhs]:"Unsupported left hand expression in is statement",[t.UnsupportedIsRhs]:"Unsupported right hand expression in is statement",[t.UnsupportedOperator]:"Unsupported operator - {operator}",[t.UnsupportedSyntax]:"Unsupported syntax - {node}",[t.UnsupportedSqlFunction]:"Sql function not found = {function}",[t.InvalidDataType]:"Invalid sql data type",[t.InvalidDate]:"Invalid date encountered",[t.InvalidOperator]:"Invalid operator encountered",[t.InvalidTime]:"Invalid time encountered",[t.IllegalInterval]:"Illegal interval",[t.FunctionNotRecognized]:"Function not recognized",[t.InvalidTimeStamp]:"Invalid timestamp encountered",[t.InvalidParameterCount]:"Invalid parameter count for call to {name}",[t.PrimarySecondaryQualifiers]:"Primary and Secondary SqlInterval qualifiers not supported",[t.YearMonthIntervals]:"Year-Month Intervals not supported",[t.CannotCastValue]:"Cannot cast value to the required data type"};class n extends Error{constructor(t,r){super(e(a[t],r)),this.declaredRootClass="esri.arcade.featureset.support.sqlerror",Error.captureStackTrace&&Error.captureStackTrace(this,n)}}var r;!function(e){e.NeverReach="NeverReach",e.NotImplemented="NotImplemented",e.Cancelled="Cancelled",e.InvalidStatResponse="InvalidStatResponse",e.InvalidRequest="InvalidRequest",e.RequestFailed="RequestFailed",e.MissingFeatures="MissingFeatures",e.AggregationFieldNotFound="AggregationFieldNotFound",e.DataElementsNotFound="DataElementsNotFound"}(r||(r={}));const o={[r.Cancelled]:"Cancelled",[r.InvalidStatResponse]:"Invalid statistics response from service",[r.InvalidRequest]:"Invalid request",[r.RequestFailed]:"Request failed - {reason}",[r.MissingFeatures]:"Missing features",[r.AggregationFieldNotFound]:"Aggregation field not found",[r.DataElementsNotFound]:"Data elements not found on service",[r.NeverReach]:"Encountered unreachable logic",[r.NotImplemented]:"Not implemented"};class s extends Error{constructor(t,a){super(e(o[t],a)),this.declaredRootClass="esri.arcade.featureset.support.featureseterror",Error.captureStackTrace&&Error.captureStackTrace(this,s)}}export{s as FeatureSetError,r as FeatureSetErrorCodes,o as FeatureSetErrorMessages,n as SqlError,t as SqlErrorCodes,a as SqlErrorMessages};
|