@vertigis/arcgis-extensions 35.8.2 → 35.9.0
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/AppConfig.schema.json +6 -9
- package/data/Feature.d.ts +14 -3
- package/data/Feature.js +1 -1
- package/data/FeatureSourceBase.d.ts +2 -2
- package/data/FeatureSourceBase.js +1 -1
- package/data/RelationshipBase.d.ts +9 -6
- package/data/RelationshipBase.js +1 -1
- package/data/_Relationship.d.ts +3 -3
- package/data/_TableExtension.d.ts +5 -0
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/data_ArcGISServiceTableExtension.ArcGISServiceTableExtension.html +13 -13
- package/docs/html/classes/data_Feature.Feature.html +35 -33
- package/docs/html/classes/data_FeatureSourceBase.FeatureSourceBase.html +19 -19
- package/docs/html/classes/data_FeatureSourceBase.RelationshipCollection.html +4 -4
- package/docs/html/classes/data_FeatureStream.FeatureStream.html +1 -1
- package/docs/html/classes/data_RelationshipBase.RelationshipBase.html +11 -11
- package/docs/html/classes/data__TableExtension.TableExtension.html +27 -27
- package/docs/html/classes/data__TableExtension.TableFeatureSettings.html +3 -3
- package/docs/html/classes/data__TableExtension.TableSchema.html +10 -10
- package/docs/html/classes/mapping_ArcGISSublayerExtension.ArcGISSublayerExtension.html +45 -45
- package/docs/html/classes/mapping_ArcGISSublayerExtension.ArcGISSublayerRelationshipCollection.html +3 -3
- package/docs/html/classes/mapping_ArcGISSublayerExtension.ArcGISSublayerSchema.html +1 -1
- package/docs/html/classes/mapping_BuildingComponentSublayerExtension.BuildingComponentSublayerExtension.html +48 -48
- package/docs/html/classes/mapping_BuildingComponentSublayerExtension.BuildingComponentSublayerSchema.html +1 -1
- package/docs/html/classes/mapping_BuildingGroupSublayerExtension.BuildingGroupSublayerExtension.html +52 -52
- package/docs/html/classes/mapping_BuildingGroupSublayerExtension.BuildingGroupSublayerSchema.html +2 -2
- package/docs/html/classes/mapping_BuildingSceneLayerExtension.BuildingSceneLayerExtension.html +63 -63
- package/docs/html/classes/mapping_BuildingSceneLayerExtension.BuildingSceneLayerReadOnlySchema.html +3 -3
- package/docs/html/classes/mapping_BuildingSublayerExtension.BuildingSublayerExtension.html +58 -58
- package/docs/html/classes/mapping_BuildingSublayerExtension.BuildingSublayerSchema.html +2 -2
- package/docs/html/classes/mapping_CSVLayerExtension.CSVLayerExtension.html +66 -66
- package/docs/html/classes/mapping_ElevationLayerExtension.ElevationLayerExtension.html +67 -67
- package/docs/html/classes/mapping_FeatureCollectionLayerExtension.FeatureCollectionLayerExtension.html +61 -61
- package/docs/html/classes/mapping_FeatureLayerExtension.FeatureLayerExtension.html +54 -54
- package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerExtensionBase.html +64 -64
- package/docs/html/classes/mapping_FeatureLayerExtensionBase.FeatureLayerSchema.html +4 -4
- package/docs/html/classes/mapping_GeoRSSLayerExtension.GeoRSSLayerExtension.html +67 -67
- package/docs/html/classes/mapping_GraphicsLayerExtension.GraphicsLayerExtension.html +63 -63
- package/docs/html/classes/mapping_GroupLayerExtension.GroupLayerExtension.html +60 -60
- package/docs/html/classes/mapping_ImageryLayerExtension.ImageryLayerExtension.html +65 -65
- package/docs/html/classes/mapping_ImageryTileLayerExtension.ImageryTileLayerExtension.html +65 -65
- package/docs/html/classes/mapping_IntegratedMeshLayerExtension.IntegratedMeshLayerExtension.html +68 -68
- package/docs/html/classes/mapping_KMLLayerExtension.KMLLayerExtension.html +63 -63
- package/docs/html/classes/mapping_KMLSublayerExtension.KMLSublayerExtension.html +53 -53
- package/docs/html/classes/mapping_MapImageLayerExtension.MapImageLayerExtension.html +64 -64
- package/docs/html/classes/mapping_MapImageSublayerExtension.MapImageSublayerExtension.html +40 -40
- package/docs/html/classes/mapping_OpenStreetMapLayerExtension.OpenStreetMapLayerExtension.html +70 -70
- package/docs/html/classes/mapping_PointCloudLayerExtension.PointCloudLayerExtension.html +65 -65
- package/docs/html/classes/mapping_SceneLayerExtension.SceneLayerExtension.html +64 -64
- package/docs/html/classes/mapping_StreamLayerExtension.StreamLayerExtension.html +65 -65
- package/docs/html/classes/mapping_StreamLayerExtension.StreamLayerSchema.html +4 -4
- package/docs/html/classes/mapping_TileLayerExtension.TileLayerExtension.html +63 -63
- package/docs/html/classes/mapping_TileSublayerExtension.TileSublayerExtension.html +41 -41
- package/docs/html/classes/mapping_UnsupportedLayerExtension.UnsupportedLayerExtension.html +71 -71
- package/docs/html/classes/mapping_VectorTileLayerExtension.VectorTileLayerExtension.html +67 -67
- package/docs/html/classes/mapping_WMSLayerExtension.WMSLayerExtension.html +65 -65
- package/docs/html/classes/mapping_WMSSublayerExtension.WMSSublayerExtension.html +52 -52
- package/docs/html/classes/mapping_WMTSLayerExtension.WMTSLayerExtension.html +64 -64
- package/docs/html/classes/mapping_WMTSSublayerExtension.WMTSSublayerExtension.html +54 -54
- package/docs/html/classes/mapping_WebTileLayerExtension.WebTileLayerExtension.html +70 -70
- package/docs/html/classes/mapping__LayerExtension.ArrayWrappedCollection.html +2 -2
- package/docs/html/classes/mapping__LayerExtension.LayerExtension.html +73 -73
- package/docs/html/classes/mapping__LayerExtension.LayerExtensionSchema.html +5 -5
- package/docs/html/classes/mapping__SublayerExtension.SubSublayerExtensionCollection.html +6 -6
- package/docs/html/classes/mapping__SublayerExtension.SublayerExtension.html +64 -64
- package/docs/html/classes/mapping__SublayerExtension.SublayerSchema.html +2 -2
- package/docs/html/classes/tasks_geocoding_ArcGISGeocoder.ArcGISGeocoder.html +16 -16
- package/docs/html/classes/tasks_geocoding_Geocoder.Geocoder.html +18 -18
- package/docs/html/classes/tasks_query_ArcGISRelationship.ArcGISRelationship.html +15 -15
- package/docs/html/classes/tasks_query_QueryBasedRelationship.QueryBasedRelationship.html +11 -11
- package/docs/html/classes/utilities_asyncIterable.AsyncQueue.html +1 -1
- package/docs/html/interfaces/data_ArcGISServiceTableExtension.ArcGISServiceTableExtensionProperties.html +2 -2
- package/docs/html/interfaces/data_Feature.FeatureProperties.html +5 -5
- package/docs/html/interfaces/data_Feature.FetchRelatedFeaturesOptions.html +3 -0
- package/docs/html/interfaces/data_Feature.FormatOptions.html +1 -1
- package/docs/html/interfaces/data_Feature.PresentableAttributes.html +2 -2
- package/docs/html/interfaces/data__Relationship.Relationship-1.html +4 -4
- package/docs/html/interfaces/data__Relationship.RelationshipProperties.html +1 -1
- package/docs/html/interfaces/data__TableExtension.TableExtensionProperties.html +5 -5
- package/docs/html/interfaces/data__TableExtension.TableProperties.html +1 -1
- package/docs/html/interfaces/data__TableExtension.TableReference.html +2 -2
- package/docs/html/interfaces/mapping_ArcGISSublayerExtension.ArcGISSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_ArcGISSublayerExtension.ArcGISSublayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_BuildingComponentSublayerExtension.BuildingComponentSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_BuildingGroupSublayerExtension.BuildingGroupSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_BuildingSceneLayerExtension.BuildingSceneLayerExtensionProperties.html +7 -7
- package/docs/html/interfaces/mapping_BuildingSceneLayerExtension.BuildingSceneLayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_BuildingSublayerExtension.BuildingSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_BuildingSublayerExtension.BuildingSublayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_CSVLayerExtension.CSVLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_ElevationLayerExtension.ElevationLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_FeatureLayerExtension.FeatureLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_FeatureLayerExtension.FeatureLayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_FeatureLayerExtensionBase.FeatureLayerBaseProperties.html +2 -2
- package/docs/html/interfaces/mapping_FeatureLayerExtensionBase.FeatureLayerExtensionBaseProperties.html +8 -8
- package/docs/html/interfaces/mapping_GeoRSSLayerExtension.GeoRSSLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_GraphicsLayerExtension.GraphicsLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_GroupLayerExtension.GroupLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_ImageryLayerExtension.ImageryLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_ImageryTileLayerExtension.ImageryTileLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_ImageryTileLayerExtension.ImageryTileLayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_IntegratedMeshLayerExtension.IntegratedMeshLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_KMLLayerExtension.KMLLayerExtensionProperties.html +7 -7
- package/docs/html/interfaces/mapping_KMLSublayerExtension.KMLSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_MapImageLayerExtension.MapImageLayerExtensionProperties.html +7 -7
- package/docs/html/interfaces/mapping_MapImageSublayerExtension.MapImageSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_MapImageSublayerExtension.MapImageSublayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_OpenStreetMapLayerExtension.OpenStreetMapLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_PointCloudLayerExtension.PointCloudLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_SceneLayerExtension.SceneLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_StreamLayerExtension.StreamLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_TileLayerExtension.TileLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_TileLayerExtension.TileLayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_TileSublayerExtension.TileSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_TileSublayerExtension.TileSublayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_VectorTileLayerExtension.VectorTileLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping_WMSLayerExtension.WMSLayerExtensionProperties.html +7 -7
- package/docs/html/interfaces/mapping_WMSSublayerExtension.WMSSublayerExtensionProperties.html +5 -5
- package/docs/html/interfaces/mapping_WMSSublayerExtension.WMSSublayerProperties.html +2 -2
- package/docs/html/interfaces/mapping_WMTSLayerExtension.WMTSLayerExtensionProperties.html +7 -7
- package/docs/html/interfaces/mapping_WMTSSublayerExtension.WMTSSublayerExtensionProperties.html +6 -6
- package/docs/html/interfaces/mapping_WebTileLayerExtension.WebTileLayerExtensionProperties.html +8 -8
- package/docs/html/interfaces/mapping__LayerExtension.LayerExtensionProperties.html +11 -11
- package/docs/html/interfaces/mapping__LayerExtension.LayerProperties.html +2 -2
- package/docs/html/interfaces/mapping__LayerExtension.LayerReference.html +4 -4
- package/docs/html/interfaces/mapping__SublayerExtension.SublayerExtensionProperties.html +9 -9
- package/docs/html/interfaces/mapping__SublayerExtension.SublayerProperties.html +2 -2
- package/docs/html/interfaces/mapping__SublayerExtension.SublayerReference.html +2 -2
- package/docs/html/interfaces/portal_PopupInfo.OrderByFields.html +2 -2
- package/docs/html/interfaces/portal_PopupInfo.PopupElement.html +5 -5
- package/docs/html/interfaces/portal_PopupInfo.PopupInfo-1.html +8 -8
- package/docs/html/interfaces/portal_PopupInfo.RelatedRecordsInfo.html +2 -2
- package/docs/html/interfaces/tasks_query_ArcGISRelationship.ArcGISRelationshipProperties.html +4 -4
- package/docs/html/interfaces/tasks_query_QueryBasedRelationship.QueryBasedRelationshipProperties.html +1 -1
- package/docs/html/modules/data_Feature.html +5 -5
- package/docs/html/modules/data__Relationship.Relationship.html +2 -2
- package/docs/html/modules/data__Relationship.html +5 -5
- package/docs/html/modules/mapping__LayerExtension.html +1 -1
- package/docs/html/modules/mapping__SublayerExtension.html +2 -2
- package/docs/html/modules/portal_PopupInfo.html +1 -1
- package/docs/html/modules/utilities_promise.html +9 -2
- package/docs/html/modules/version.html +1 -1
- package/mapping/_LayerExtension.d.ts +5 -0
- package/mapping/_SublayerExtension.d.ts +5 -0
- package/package.json +1 -1
- package/tasks/query/ArcGISRelationship.d.ts +3 -3
- package/tasks/query/ArcGISRelationship.js +1 -1
- package/tasks/query/QueryBasedRelationship.d.ts +3 -3
- package/tasks/query/QueryBasedRelationship.js +1 -1
- package/utilities/promise.d.ts +8 -0
- package/utilities/promise.js +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/AppConfig.schema.json
CHANGED
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"description": "See{@linkFeatureSource.onEditFeature}."
|
|
106
106
|
},
|
|
107
107
|
"relationships": {
|
|
108
|
-
"description": "See{@
|
|
108
|
+
"description": "See{@linkTableExtension.relationships}.",
|
|
109
109
|
"items": {
|
|
110
110
|
"anyOf": [
|
|
111
111
|
{
|
|
@@ -1294,7 +1294,7 @@
|
|
|
1294
1294
|
"description": "See{@linkFeatureSource.onEditFeature}."
|
|
1295
1295
|
},
|
|
1296
1296
|
"relationships": {
|
|
1297
|
-
"description": "See{@
|
|
1297
|
+
"description": "See{@linkLayerExtension.relationships}.",
|
|
1298
1298
|
"items": {
|
|
1299
1299
|
"anyOf": [
|
|
1300
1300
|
{
|
|
@@ -2327,8 +2327,8 @@
|
|
|
2327
2327
|
"description": "Properties that can be used to initialize a{@linkRelationship}.",
|
|
2328
2328
|
"properties": {
|
|
2329
2329
|
"$relationshipType": {
|
|
2330
|
-
"
|
|
2331
|
-
"
|
|
2330
|
+
"description": "The Relationship's type.",
|
|
2331
|
+
"type": "string"
|
|
2332
2332
|
},
|
|
2333
2333
|
"failureMode": {
|
|
2334
2334
|
"$ref": "#/definitions/FailureMode",
|
|
@@ -2366,9 +2366,6 @@
|
|
|
2366
2366
|
}
|
|
2367
2367
|
]
|
|
2368
2368
|
},
|
|
2369
|
-
"RelationshipType": {
|
|
2370
|
-
"description": "The type of the Relationship."
|
|
2371
|
-
},
|
|
2372
2369
|
"Schema": {
|
|
2373
2370
|
"description": "Metadata about features, such as fields, domains, geometry type, etc."
|
|
2374
2371
|
},
|
|
@@ -2556,7 +2553,7 @@
|
|
|
2556
2553
|
"description": "See{@linkFeatureSource.onEditFeature}."
|
|
2557
2554
|
},
|
|
2558
2555
|
"relationships": {
|
|
2559
|
-
"description": "See{@
|
|
2556
|
+
"description": "See{@linkSublayerExtension.relationships}.",
|
|
2560
2557
|
"items": {
|
|
2561
2558
|
"anyOf": [
|
|
2562
2559
|
{
|
|
@@ -2763,7 +2760,7 @@
|
|
|
2763
2760
|
"description": "See{@linkFeatureSource.onEditFeature}."
|
|
2764
2761
|
},
|
|
2765
2762
|
"relationships": {
|
|
2766
|
-
"description": "See{@
|
|
2763
|
+
"description": "See{@linkTableExtension.relationships}.",
|
|
2767
2764
|
"items": {
|
|
2768
2765
|
"anyOf": [
|
|
2769
2766
|
{
|
package/data/Feature.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type FeatureType from "@arcgis/core/layers/support/FeatureType";
|
|
|
4
4
|
import { EntityBase, EntityBaseProperties } from "../Entity.js";
|
|
5
5
|
import { Hyperlink } from "../Hyperlink.js";
|
|
6
6
|
import { Geometry as PortalGeometry } from "../portal/Geometry.js";
|
|
7
|
+
import type { CancelToken } from "../support/Cancellable.js";
|
|
7
8
|
import { PropertyDefs } from "../support/Serializable.js";
|
|
8
9
|
import type { WatchCallback } from "../support/esri.js";
|
|
9
10
|
import { ObservableMap } from "../utilities/ObservableMap.js";
|
|
@@ -73,6 +74,15 @@ export interface FormatOptions extends FormatOptionsBase {
|
|
|
73
74
|
*/
|
|
74
75
|
defaultExpressionValue?: string;
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Options that can be used as arguments for the fetchRelatedFeatures() function.
|
|
79
|
+
*/
|
|
80
|
+
export interface FetchRelatedFeaturesOptions {
|
|
81
|
+
/**
|
|
82
|
+
* @inheritdoc
|
|
83
|
+
*/
|
|
84
|
+
cancelToken?: CancelToken;
|
|
85
|
+
}
|
|
76
86
|
/**
|
|
77
87
|
* Represents a record in a {@link FeatureSource}. Both spatial and non-spatial
|
|
78
88
|
* features have attributes, while only spatial features have geometry.
|
|
@@ -193,10 +203,11 @@ export declare class Feature extends EntityBase<FeatureProperties> {
|
|
|
193
203
|
* Fetches features that are related to this feature. Features are available
|
|
194
204
|
* through {@link Feature.relatedFeatures}.
|
|
195
205
|
*
|
|
196
|
-
* @param
|
|
197
|
-
* features for. If omitted, all related features will be fetched.
|
|
206
|
+
* @param relationships The relationships or relationship IDs to fetch
|
|
207
|
+
* related features for. If omitted, all related features will be fetched.
|
|
208
|
+
* @param options Additional options that affect fetching related features.
|
|
198
209
|
*/
|
|
199
|
-
fetchRelatedFeatures(
|
|
210
|
+
fetchRelatedFeatures(relationships?: Relationship | string | (Relationship | string)[], options?: FetchRelatedFeaturesOptions): Promise<void>;
|
|
200
211
|
/**
|
|
201
212
|
* Retrieves attachments that are associated with this feature.
|
|
202
213
|
*/
|
package/data/Feature.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__decorate}from"tslib";import Graphic from"@arcgis/core/Graphic";import*as Arcade from"@arcgis/core/arcade/arcade";import{EntityBase}from"../Entity.js";import{Hyperlink}from"../Hyperlink.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{ItemType}from"../ItemType.js";import{toEsriApiGeometry,toPortalGeometry}from"../portal/Geometry.js";import{serializable}from"../support/Serializable.js";import{MapTransformCollection}from"../utilities/MapTransformCollection.js";import{ObservableMap}from"../utilities/ObservableMap.js";import{ReadOnlyMap}from"../utilities/ReadOnlyMap.js";import{arcadeScriptUsesGeometry,isArcadeScriptAsync,runArcadeExpression,runAsyncArcadeExpression}from"../utilities/arcade.js";import{flatten,groupBy}from"../utilities/array.js";import{checkArg}from"../utilities/checkArg.js";import{Collection,compare}from"../utilities/collection.js";import{parse as parseDate,esriFormatToGeocortexFormat}from"../utilities/date.js";import{isCodedValueDomain}from"../utilities/esri.js";import{some,map as mapIterable,concat,forEach,find}from"../utilities/iterable.js";import{getLogger}from"../utilities/log.js";import{parse as parseNumber,NumberFormat}from"../utilities/number.js";import{map as promiseMap}from"../utilities/promise.js";import{format as formatString}from"../utilities/string.js";import{FeatureSettings}from"./FeatureSettings.js";import{_fieldWithArcadeXRegex,_fieldWithRelationshipRegex,Schema}from"./Schema.js";const log=getLogger("geocortex.api.data.Feature");export const SCORE_FIELD="_score";export const SCORE_FIELD_ORIGINAL="_score_original";let Feature=class extends EntityBase{constructor(e){super(e),this._itemType=ItemType.FEATURE,this._expressionFieldValues=new ObservableMap,this._expressionValuesUpdatePending=!1,this.settings=new FeatureSettings,this.settings._setFeature(this),this.schema=new Schema,this.schema._featureSettings=this.settings,this.attachments=new Collection,this.attributes=new ObservableMap,this._relatedFeatures=new ObservableMap,this.expressionFieldValues=new ExpressionFieldsValuesImpl(this._expressionFieldValues,this)}get geometry(){return this._geometry}set geometry(e){this._notifyChange("geometryType"),this._geometry=toEsriApiGeometry(e),this.schema.spatialReference=this._geometry?.spatialReference}get geometryType(){return this.geometry?this.geometry.type:void 0}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.settings.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0)}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get presentableAttributes(){return this._presentableAttributes=this._presentableAttributes||new PresentableAttributesImpl(this),this._presentableAttributes}get title(){return this.format(this._title||"")}get description(){return this.format(this._description)}get hyperlinks(){return this._hyperlinks||(this._hyperlinks=new HyperlinksCollection(this))}get relatedFeatures(){return this._relatedFeatures}get type(){if(this.schema.typeIdField&&this.attributes.has(this.schema.typeIdField)){const e=this.attributes.get(this.schema.typeIdField);return this.schema.types.find((t=>t.id===e))}}get _hydrationStatus(){return this._featureHydrationStatus?this._featureHydrationStatus:this.source?.capabilities?.supportsQuery&&1===this.attributes.size&&void 0!==this.primaryKey?"dehydrated":"hydrated"}set _hydrationStatus(e){this._featureHydrationStatus=e}get _title(){let e;return this.settings.popupTemplate&&(e="function"==typeof this.settings.popupTemplate.title?this.settings.popupTemplate.title():this.settings.popupTemplate.title),e||this.schema.displayField&&this.presentableAttributes.get(this.schema.displayField)||""}get _description(){if(this.settings.popupTemplate?.content){if("string"==typeof this.settings.popupTemplate.content)return this.settings.popupTemplate.content;if(Array.isArray(this.settings.popupTemplate.content)){const e=this.settings.popupTemplate.content.find((e=>"text"===e.type));if(e)return e.text}}return""}format(e,...t){let s="string"==typeof e?{format:e}:e;checkArg("options",s).isNotMissing();const{format:r}=s;checkArg("format",r).isNotMissing();let i=s.format.replace(escapedBraceRegex,escapedBracePlaceholder);return i=i.replace(fieldTokenRegex,((e,t,r,i,a)=>formatAttribute(this,t||r,i,{...s,format:a?`{0:${a}}`:"{0}"}))),i=i.replace(escapedBracePlaceholderRegex,"{{"),s={...s},s.format=i,formatString(s,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(t)return await Promise.all(t.map((async e=>{try{const t=this.source?.layer??this.source?.sublayer;let s=this.source?.mapExtension;if(!s){const e=this.source?.layerExtension;s=e?.mapExtension}this._expressionFieldValues.set(e.name,await runAsyncArcadeExpression(e.expression,{layer:t,map:s?.map,feature:this,spatialReference:this.schema.spatialReference}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e.name,t.message),this._expressionFieldValues.set(e.name,invalidRelationshipOrExpression)}}))),e?this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))})):void 0}async fetchRelatedFeatures(e){if(!this.source)return;let t;if(e){const s="string"==typeof e?this.source.relationships.find((t=>t.id===e)):e;if(!s||!this.source.relationships.includes(s))throw new InvalidOperationError("Relationship not found in feature source.");t=[s]}else t=this.source.relationships.toArray();const s=await promiseMap(t,(async e=>[e,await e.getRelatedFeatures(this)]));for(const e of s)this._relatedFeatures.set(e[0],e[1])}async fetchAttachments(){if(this.source){const e=await this.source.getAttachments(this);compare(this.attachments,e,{equals:(e,t)=>e.id===t.id,onMissing:(e,t)=>this.attachments.remove(e),onNew:(e,t)=>this.attachments.add(e),onMatch:(e,t,s,r)=>{this.attachments.splice(s,1,t)}})}}async addAttachment(e){return this.source?.addAttachment(this,e)}async deleteAttachments(e){return this.source?.deleteAttachments(this,e)}_getSerializableProperties(){return{...super._getSerializableProperties(),attributes:{serializeModes:["project"],serialize:e=>{const t={};if("project"===e&&this.primaryKey&&this.source?.capabilities.supportsQuery)t[this.schema.primaryKeyField]=this.primaryKey;else for(const[e,s]of this.attributes.entries())t[e]=s;return t},deserialize:e=>{if(this.attributes.clear(),e instanceof Map)e.forEach(((e,t)=>{this.attributes.set(t,e)}));else for(const[t,s]of Object.entries(e))this.attributes.set(t,s)}},geometry:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("geometry"):toPortalGeometry(this.geometry),deserialize:e=>this.geometry=toEsriApiGeometry(e)},settings:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("settings"):this.settings.toJSON(e)},schema:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("schema"):this.schema.toJSON(e)},source:["project"]}}_watchProperty(e,t,s,r){if("title"===e||"description"===e){const i=super._watchProperty(e,t,s,r),a="title"===e?"settings.popupTemplate.title":"settings.popupTemplate.content",o=this.watch(a,(()=>{this._notifyChange(e)})),n=this.presentableAttributes.on("change",(()=>{this._notifyChange(e)}));return{remove(){i.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,s,r)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],s=[];for(const r of e)t.includes(r)?s.push(this.fetchRelatedFeatures(r)):log.error("Could not find relationship '{0}' referenced in feature title or description.",r);await Promise.all(s)}_findRelationshipIds(...e){const t=[];for(const s of e){let e;const r=s.replace(escapedBraceRegex,escapedBracePlaceholder);for(;e=relationshipIdRegex.exec(r),null!==e;){const s=e[0];t.includes(s)||t.push(e[1])}}return t}};Feature=__decorate([serializable],Feature);export{Feature};export function toFeature(e,t){const s=new Feature(t);if(e.attributes)for(const t of Object.keys(e.attributes))s.attributes.set(t,e.attributes[t]);return s.geometry=e.geometry,e.popupTemplate&&(s.settings.popupTemplate=e.popupTemplate),s}export function toGraphic(e){const t=new Graphic;t.attributes={};for(const s of e.attributes.keys())t.attributes[s]=e.attributes.get(s);return e.source?.layer&&(t.layer=e.source?.layer),t.geometry=e.geometry,e.settings.popupTemplate&&(t.popupTemplate=e.settings.popupTemplate),t}const ERR_PRESENTABLE_ATTRIBUTES_READONLY="Presentable attributes are read-only.",ERR_HYPERLINK_READONLY="Feature hyperlinks are read-only. Modify the feature's hyperlink templates instead.";class ExpressionFieldsValuesImpl extends ReadOnlyMap{constructor(e,t){super(e),this._feature=t}get(e){if(!super.has(e)){const{spatialReference:t}=this._feature.schema,s=this._feature.settings.popupTemplate?.expressionInfos?.find((t=>t.name===e));if(!s)return;(async()=>{try{if(isArcadeScriptAsync(s.expression,t)){const r=this._feature.source?.layer??this._feature.source?.sublayer;let i=this._feature.source?.mapExtension;if(!i){const e=this._feature.source?.layerExtension;i=e?.mapExtension}this._originalMap.set(e,await runAsyncArcadeExpression(s.expression,{feature:this._feature,layer:r,map:i?.map,spatialReference:t}))}else arcadeScriptUsesGeometry(s.expression,t)&&await Arcade.enableGeometrySupport(),this._originalMap.set(e,runArcadeExpression(s.expression,{feature:this._feature,spatialReference:t}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e,t.message),this._originalMap.set(e,invalidRelationshipOrExpression)}})()}return super.get(e)}}class PresentableAttributesImpl extends ReadOnlyMap{constructor(e){super(new ObservableMap),this._feature=e}get size(){return this._feature.attributes.size+this._feature.schema.fields._expressionFieldsLength}clear(){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}delete(e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}forEach(e,t){checkArg("callback",e).isNotMissing();for(const s of this.keys())e.call(t,this.get(s),s,this)}get(e){const t=this._getFieldExtensionFormat(e);return this._formatAttribute(e,t)}has(e){return some(this.keys(),(t=>t===e))}set(...e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}*entries(){yield*mapIterable(this.keys(),(e=>[e,this.get(e)]))}*keys(){const e=this._feature.schema.fields.expressionFields.map((e=>e.name)),t=[];this._feature.source?.relationships&&this._feature.source.relationships.filter((e=>"one-to-one"===e.cardinality||"many-to-one"===e.cardinality)).forEach((e=>t.push(...e.relatedSource.schema.fields.map((t=>`relationships/${e.id}/${t.name}`)).toArray()))),yield*concat(this._feature.attributes.keys(),e.toArray(),t)}*values(){yield*mapIterable(this.keys(),(e=>this.get(e)))}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}toJSON(){return Array.from(this.entries())}on(e,t){if(checkArg("callback",t).isNotMissing(),!this._numObservers){const e=new Map,t=new Set,s=()=>{t.forEach((e=>e.remove())),t.clear()},r=()=>{const t={added:Array.from(this.entries()).filter((t=>t[1]!==e.get(t[0]))),removed:Array.from(e.entries()).filter((e=>!this.has(e[0])||e[1]!==this.get(e[0]))),target:this};(t.added.length||t.removed.length)&&(this.emit("change",t),i())},i=()=>{e.clear(),s(),forEach(this.keys(),(s=>{const i=this._getFieldExtension(s);let a="{0}";if(i){const e=i.watch("format",(()=>{r()}));t.add(e),i.format&&(a=i.format)}e.set(s,this._formatAttribute(s,a))}))};i();const a=this._feature.attributes.on("change",(()=>{r()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{r()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{r()})),l=this._feature.expressionFieldValues.on("change",(()=>{r()})),p=this._feature.schema.fields.on("change",(e=>{(e.added?.some((e=>null!==e.name.match(_fieldWithArcadeXRegex)))||e.removed?.some((e=>null!==e.name.match(_fieldWithArcadeXRegex))))&&r()})),h=this._feature.settings.watch("popupTemplate",(()=>{r()}));this._onAllObserversRemoved=()=>{l.remove(),a.remove(),o.remove(),p.remove(),n.remove(),h.remove(),e.clear(),s()}}const s=super.on("change",t);return this._numObservers++,{remove:()=>{s.remove(),this._numObservers--,this._numObservers||this._onAllObserversRemoved()}}}watch(e,t){if("size"===e){const e=this._feature.attributes.watch("size",((e,s)=>{t(e+this._feature.schema.fields._expressionFieldsLength,s+this._feature.schema.fields._expressionFieldsLength,"size",this)})),s=this._feature.schema.fields.watch("_expressionFieldsLength",((e,s)=>{t(e+this._feature.attributes.size,s+this._feature.attributes.size,"size",this)}));return{remove:()=>{e.remove(),s.remove()}}}return super.watch(e,t)}_getFieldExtension(e){const t=this._feature.schema.findFieldByName(e);if(t)return this._feature.schema.fieldExtensions.forField(t)}_getFieldExtensionFormat(e){const t=this._getFieldExtension(e);return t?t.format:"{0}"}_formatAttribute(e,t){const s=e.match(_fieldWithArcadeXRegex),r=e.match(_fieldWithRelationshipRegex);if(s)return formatAttribute(this._feature,"expression",s[1],{format:t});if(r){const[,e,s]=r;return formatAttribute(this._feature,e,s,{format:t})}return formatAttribute(this._feature,void 0,e,{format:t})}}const fieldTokenRegex=/\{(?:relationships[\\/](\w\w*)[\\/])?(?:(expression)[\\/])?([a-zA-Z][.\w]*)(?::([^}]*))?\}/g,relationshipIdRegex=/\{relationships\/(\w\w*)[\\/]([^}]*)\}/g,escapedBraceRegex=/{{/g,escapedBracePlaceholder="\0MAGIC\0",escapedBracePlaceholderRegex=new RegExp(escapedBracePlaceholder,"g"),invalidRelationshipOrExpression="#INVALID";class HyperlinksCollection extends MapTransformCollection{constructor(e){super(e.settings.hyperlinkTemplates,(e=>this._getHyperlink(e))),this._feature=e}_getHyperlink(e){return this._hyperlinks=this._hyperlinks||new WeakMap,this._hyperlinks.has(e)||this._hyperlinks.set(e,new FeatureHyperlink(this._feature,e)),this._hyperlinks.get(e)}}let FeatureHyperlink=class extends Hyperlink{constructor(e,t){super(t.toJSON()),this._feature=e,this._template=t}get url(){return this._template.url?this._feature.format(this._template.url):this._template.url}set url(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get text(){return this._template.text?this._feature.format(this._template.text):this._template.text}set text(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get iconUrl(){return this._template.iconUrl?this._feature.format(this._template.iconUrl):this._template.iconUrl}set iconUrl(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get target(){return this._template.target?this._feature.format(this._template.target):this._template.target}set target(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get tooltip(){return this._template.tooltip?this._feature.format(this._template.tooltip):this._template.tooltip}set tooltip(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}_watchProperty(e,t,s,r){const i=super._watchProperty(e,t,s,r),a=this._template.watch(e,(()=>{this._notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this._notifyChange(e)}));return{remove:()=>{i.remove(),a.remove(),o.remove()}}}_getSerializableProperties(){return{}}};function formatAttribute(e,t,s,r={format:"{0}"}){if("expression"!==t){if(t){const i=find(e.relatedFeatures.keys(),(e=>e.id===t));if(!i)return log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression;const a=Array.from(e.relatedFeatures.get(i));return"many-to-one"===i.cardinality||"one-to-one"===i.cardinality?a.length<1?(log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression):formatAttributeValue(a[0],s,r):a.map((e=>formatAttributeValue(e,s,r))).filter((e=>""!==e)).join(",")}return formatAttributeValue(e,s,r)}if(!e.settings.popupTemplate?.expressionInfos?.find((e=>e.name===s)))return log.debug("Could not find expression '{0}'.",s),invalidRelationshipOrExpression;try{const t=e.expressionFieldValues.get(s)??r.defaultExpressionValue??"",i=e.schema.findFieldByName(`expression/${s}`);let a=r;if(i){const t=e.schema.fieldExtensions.forField(i);a=formatOptionsForField(e,s,formatOptionsFromSettings(t.formatSettings),a)}return formatValue(e,t,a)}catch(e){if(e instanceof Error)return log.error({message:"Error evaluating expression '{0}': {1}.",error:e},s,e.message),invalidRelationshipOrExpression;throw e}}function formatAttributeValue(e,t,s){let r=e.attributes.get(t);if(null==r)return"";const i=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[t];if(t===e.schema.typeIdField)r=e.type?e.type.name:r;else if(isCodedValueDomain(o)){const e=o.codedValues.find((e=>`${e.code}`==`${r.toString()}`));r=e?e.name:r}else if(i)if(isCodedValueDomain(i.domain)){const e=i.domain.codedValues.find((e=>`${e.code}`==`${r.toString()}`));e&&(r=e.name)}else{switch(i.type){case"integer":case"small-integer":case"single":case"double":r=parseNumber(r);break;case"date":r=parseDate({timeZone:e.schema.timeZone},r);break;default:r=`${r.toString()}`}a=formatOptionsFromSettings(e.schema.fieldExtensions.forField(i).formatSettings)}return formatValue(e,r,formatOptionsForField(e,t,a,s))}function formatValue(e,t,s){let r=s;if("number"==typeof t||t instanceof Date){r={...formatOptionsFromSettings(e.settings.formatSettings),...s}}return"{0}"===r.format&&"string"==typeof t?t:formatString(r,t)}function formatOptionsFromSettings(e){return{format:"{0}",dateFormat:e.dateFormat,numberFormat:e.numberFormat,currency:e.currency,fractionalDigits:e.fractionalDigits,locale:e.locale,timeZone:e.timeZone}}function formatOptionsForField(e,t,s,r){const{popupTemplate:i}=e.settings,a=i?.fieldInfos?i.fieldInfos.find((e=>e.fieldName===t)):void 0,o=a?a.format:void 0;let n;return o&&(n={format:"{0}",numberFormat:o.digitSeparator?NumberFormat.NUMBER:NumberFormat.FIXED_POINT,dateFormat:esriFormatToGeocortexFormat(o.dateFormat),fractionalDigits:o.places}),{...n,...s,...r}}FeatureHyperlink=__decorate([serializable],FeatureHyperlink);export async function resolveRelatedFeatures(e){const t=groupBy(e,(e=>e.source));await Promise.all(flatten([...t.keys()].map((e=>e.relationships.toArray()))).map((e=>(async e=>{[...(await e.getAllRelatedFeatures(t.get(e.source))).entries()].forEach((([t,s])=>{t.relatedFeatures.set(e,s)}))})(e))))}
|
|
1
|
+
import{__decorate}from"tslib";import Graphic from"@arcgis/core/Graphic";import*as Arcade from"@arcgis/core/arcade/arcade";import{EntityBase}from"../Entity.js";import{Hyperlink}from"../Hyperlink.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{ItemType}from"../ItemType.js";import{toEsriApiGeometry,toPortalGeometry}from"../portal/Geometry.js";import{serializable}from"../support/Serializable.js";import{MapTransformCollection}from"../utilities/MapTransformCollection.js";import{ObservableMap}from"../utilities/ObservableMap.js";import{ReadOnlyMap}from"../utilities/ReadOnlyMap.js";import{arcadeScriptUsesGeometry,isArcadeScriptAsync,runArcadeExpression,runAsyncArcadeExpression}from"../utilities/arcade.js";import{flatten,groupBy}from"../utilities/array.js";import{checkArg}from"../utilities/checkArg.js";import{Collection,compare}from"../utilities/collection.js";import{parse as parseDate,esriFormatToGeocortexFormat}from"../utilities/date.js";import{isCodedValueDomain}from"../utilities/esri.js";import{some,map as mapIterable,concat,forEach,find}from"../utilities/iterable.js";import{getLogger}from"../utilities/log.js";import{parse as parseNumber,NumberFormat}from"../utilities/number.js";import{map as promiseMap}from"../utilities/promise.js";import{format as formatString}from"../utilities/string.js";import{FeatureSettings}from"./FeatureSettings.js";import{_fieldWithArcadeXRegex,_fieldWithRelationshipRegex,Schema}from"./Schema.js";const log=getLogger("geocortex.api.data.Feature");export const SCORE_FIELD="_score";export const SCORE_FIELD_ORIGINAL="_score_original";let Feature=class extends EntityBase{constructor(e){super(e),this._itemType=ItemType.FEATURE,this._expressionFieldValues=new ObservableMap,this._expressionValuesUpdatePending=!1,this.settings=new FeatureSettings,this.settings._setFeature(this),this.schema=new Schema,this.schema._featureSettings=this.settings,this.attachments=new Collection,this.attributes=new ObservableMap,this._relatedFeatures=new ObservableMap,this.expressionFieldValues=new ExpressionFieldsValuesImpl(this._expressionFieldValues,this)}get geometry(){return this._geometry}set geometry(e){this._notifyChange("geometryType"),this._geometry=toEsriApiGeometry(e),this.schema.spatialReference=this._geometry?.spatialReference}get geometryType(){return this.geometry?this.geometry.type:void 0}get source(){return this._source}set source(e){this._source&&this.settings.parent===this._source.featureSettings&&(this.settings.parent=void 0),this._source&&this.schema.parent===this._source.schema&&(this.schema.parent=void 0),this._source=e,this.settings.parent||(this.settings.parent=e?e.featureSettings:void 0),this.schema.parent||(this.schema.parent=e?e.schema:void 0)}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get presentableAttributes(){return this._presentableAttributes=this._presentableAttributes||new PresentableAttributesImpl(this),this._presentableAttributes}get title(){return this.format(this._title||"")}get description(){return this.format(this._description)}get hyperlinks(){return this._hyperlinks||(this._hyperlinks=new HyperlinksCollection(this))}get relatedFeatures(){return this._relatedFeatures}get type(){if(this.schema.typeIdField&&this.attributes.has(this.schema.typeIdField)){const e=this.attributes.get(this.schema.typeIdField);return this.schema.types.find((t=>t.id===e))}}get _hydrationStatus(){return this._featureHydrationStatus?this._featureHydrationStatus:this.source?.capabilities?.supportsQuery&&1===this.attributes.size&&void 0!==this.primaryKey?"dehydrated":"hydrated"}set _hydrationStatus(e){this._featureHydrationStatus=e}get _title(){let e;return this.settings.popupTemplate&&(e="function"==typeof this.settings.popupTemplate.title?this.settings.popupTemplate.title():this.settings.popupTemplate.title),e||this.schema.displayField&&this.presentableAttributes.get(this.schema.displayField)||""}get _description(){if(this.settings.popupTemplate?.content){if("string"==typeof this.settings.popupTemplate.content)return this.settings.popupTemplate.content;if(Array.isArray(this.settings.popupTemplate.content)){const e=this.settings.popupTemplate.content.find((e=>"text"===e.type));if(e)return e.text}}return""}format(e,...t){let r="string"==typeof e?{format:e}:e;checkArg("options",r).isNotMissing();const{format:s}=r;checkArg("format",s).isNotMissing();let i=r.format.replace(escapedBraceRegex,escapedBracePlaceholder);return i=i.replace(fieldTokenRegex,((e,t,s,i,a)=>formatAttribute(this,t||s,i,{...r,format:a?`{0:${a}}`:"{0}"}))),i=i.replace(escapedBracePlaceholderRegex,"{{"),r={...r},r.format=i,formatString(r,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(t)return await Promise.all(t.map((async e=>{try{const t=this.source?.layer??this.source?.sublayer;let r=this.source?.mapExtension;if(!r){const e=this.source?.layerExtension;r=e?.mapExtension}this._expressionFieldValues.set(e.name,await runAsyncArcadeExpression(e.expression,{layer:t,map:r?.map,feature:this,spatialReference:this.schema.spatialReference}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e.name,t.message),this._expressionFieldValues.set(e.name,invalidRelationshipOrExpression)}}))),e?this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))})):void 0}async fetchRelatedFeatures(e,t){if(!this.source)return;let r=[];if(e){const t=new Set(Array.isArray(e)?e:[e]);for(const e of t){const t="string"==typeof e?this.source.relationships.find((t=>t.id===e)):e;if(!t||!this.source.relationships.includes(t))throw new InvalidOperationError("Relationship not found in feature source.");r.push(t)}}else r=this.source.relationships.toArray();const s=await promiseMap(r,(async e=>[e,await e.getRelatedFeatures(this,t)]));for(const e of s)this._relatedFeatures.set(e[0],e[1])}async fetchAttachments(){if(this.source){const e=await this.source.getAttachments(this);compare(this.attachments,e,{equals:(e,t)=>e.id===t.id,onMissing:(e,t)=>this.attachments.remove(e),onNew:(e,t)=>this.attachments.add(e),onMatch:(e,t,r,s)=>{this.attachments.splice(r,1,t)}})}}async addAttachment(e){return this.source?.addAttachment(this,e)}async deleteAttachments(e){return this.source?.deleteAttachments(this,e)}_getSerializableProperties(){return{...super._getSerializableProperties(),attributes:{serializeModes:["project"],serialize:e=>{const t={};if("project"===e&&this.primaryKey&&this.source?.capabilities.supportsQuery)t[this.schema.primaryKeyField]=this.primaryKey;else for(const[e,r]of this.attributes.entries())t[e]=r;return t},deserialize:e=>{if(this.attributes.clear(),e instanceof Map)e.forEach(((e,t)=>{this.attributes.set(t,e)}));else for(const[t,r]of Object.entries(e))this.attributes.set(t,r)}},geometry:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("geometry"):toPortalGeometry(this.geometry),deserialize:e=>this.geometry=toEsriApiGeometry(e)},settings:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("settings"):this.settings.toJSON(e)},schema:{serializeModes:["project"],serialize:e=>"project"===e&&this.source?.capabilities.supportsQuery?this.getDefault("schema"):this.schema.toJSON(e)},source:["project"]}}_watchProperty(e,t,r,s){if("title"===e||"description"===e){const i=super._watchProperty(e,t,r,s),a="title"===e?"settings.popupTemplate.title":"settings.popupTemplate.content",o=this.watch(a,(()=>{this._notifyChange(e)})),n=this.presentableAttributes.on("change",(()=>{this._notifyChange(e)}));return{remove(){i.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,r,s)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],r=[];for(const s of e)t.includes(s)?r.push(this.fetchRelatedFeatures(s)):log.error("Could not find relationship '{0}' referenced in feature title or description.",s);await Promise.all(r)}_findRelationshipIds(...e){const t=[];for(const r of e){let e;const s=r.replace(escapedBraceRegex,escapedBracePlaceholder);for(;e=relationshipIdRegex.exec(s),null!==e;){const r=e[0];t.includes(r)||t.push(e[1])}}return t}};Feature=__decorate([serializable],Feature);export{Feature};export function toFeature(e,t){const r=new Feature(t);if(e.attributes)for(const t of Object.keys(e.attributes))r.attributes.set(t,e.attributes[t]);return r.geometry=e.geometry,e.popupTemplate&&(r.settings.popupTemplate=e.popupTemplate),r}export function toGraphic(e){const t=new Graphic;t.attributes={};for(const r of e.attributes.keys())t.attributes[r]=e.attributes.get(r);return e.source?.layer&&(t.layer=e.source?.layer),t.geometry=e.geometry,e.settings.popupTemplate&&(t.popupTemplate=e.settings.popupTemplate),t}const ERR_PRESENTABLE_ATTRIBUTES_READONLY="Presentable attributes are read-only.",ERR_HYPERLINK_READONLY="Feature hyperlinks are read-only. Modify the feature's hyperlink templates instead.";class ExpressionFieldsValuesImpl extends ReadOnlyMap{constructor(e,t){super(e),this._feature=t}get(e){if(!super.has(e)){const{spatialReference:t}=this._feature.schema,r=this._feature.settings.popupTemplate?.expressionInfos?.find((t=>t.name===e));if(!r)return;(async()=>{try{if(isArcadeScriptAsync(r.expression,t)){const s=this._feature.source?.layer??this._feature.source?.sublayer;let i=this._feature.source?.mapExtension;if(!i){const e=this._feature.source?.layerExtension;i=e?.mapExtension}this._originalMap.set(e,await runAsyncArcadeExpression(r.expression,{feature:this._feature,layer:s,map:i?.map,spatialReference:t}))}else arcadeScriptUsesGeometry(r.expression,t)&&await Arcade.enableGeometrySupport(),this._originalMap.set(e,runArcadeExpression(r.expression,{feature:this._feature,spatialReference:t}))}catch(t){t instanceof Error&&log.error({message:"Error evaluating expression '{0}': {1}.",error:t},e,t.message),this._originalMap.set(e,invalidRelationshipOrExpression)}})()}return super.get(e)}}class PresentableAttributesImpl extends ReadOnlyMap{constructor(e){super(new ObservableMap),this._feature=e}get size(){return this._feature.attributes.size+this._feature.schema.fields._expressionFieldsLength}clear(){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}delete(e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}forEach(e,t){checkArg("callback",e).isNotMissing();for(const r of this.keys())e.call(t,this.get(r),r,this)}get(e){const t=this._getFieldExtensionFormat(e);return this._formatAttribute(e,t)}has(e){return some(this.keys(),(t=>t===e))}set(...e){throw new InvalidOperationError(ERR_PRESENTABLE_ATTRIBUTES_READONLY)}*entries(){yield*mapIterable(this.keys(),(e=>[e,this.get(e)]))}*keys(){const e=this._feature.schema.fields.expressionFields.map((e=>e.name)),t=[];this._feature.source?.relationships&&this._feature.source.relationships.filter((e=>"one-to-one"===e.cardinality||"many-to-one"===e.cardinality)).forEach((e=>t.push(...e.relatedSource.schema.fields.map((t=>`relationships/${e.id}/${t.name}`)).toArray()))),yield*concat(this._feature.attributes.keys(),e.toArray(),t)}*values(){yield*mapIterable(this.keys(),(e=>this.get(e)))}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}toJSON(){return Array.from(this.entries())}on(e,t){if(checkArg("callback",t).isNotMissing(),!this._numObservers){const e=new Map,t=new Set,r=()=>{t.forEach((e=>e.remove())),t.clear()},s=()=>{const t={added:Array.from(this.entries()).filter((t=>t[1]!==e.get(t[0]))),removed:Array.from(e.entries()).filter((e=>!this.has(e[0])||e[1]!==this.get(e[0]))),target:this};(t.added.length||t.removed.length)&&(this.emit("change",t),i())},i=()=>{e.clear(),r(),forEach(this.keys(),(r=>{const i=this._getFieldExtension(r);let a="{0}";if(i){const e=i.watch("format",(()=>{s()}));t.add(e),i.format&&(a=i.format)}e.set(r,this._formatAttribute(r,a))}))};i();const a=this._feature.attributes.on("change",(()=>{s()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{s()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{s()})),l=this._feature.expressionFieldValues.on("change",(()=>{s()})),p=this._feature.schema.fields.on("change",(e=>{(e.added?.some((e=>null!==e.name.match(_fieldWithArcadeXRegex)))||e.removed?.some((e=>null!==e.name.match(_fieldWithArcadeXRegex))))&&s()})),h=this._feature.settings.watch("popupTemplate",(()=>{s()}));this._onAllObserversRemoved=()=>{l.remove(),a.remove(),o.remove(),p.remove(),n.remove(),h.remove(),e.clear(),r()}}const r=super.on("change",t);return this._numObservers++,{remove:()=>{r.remove(),this._numObservers--,this._numObservers||this._onAllObserversRemoved()}}}watch(e,t){if("size"===e){const e=this._feature.attributes.watch("size",((e,r)=>{t(e+this._feature.schema.fields._expressionFieldsLength,r+this._feature.schema.fields._expressionFieldsLength,"size",this)})),r=this._feature.schema.fields.watch("_expressionFieldsLength",((e,r)=>{t(e+this._feature.attributes.size,r+this._feature.attributes.size,"size",this)}));return{remove:()=>{e.remove(),r.remove()}}}return super.watch(e,t)}_getFieldExtension(e){const t=this._feature.schema.findFieldByName(e);if(t)return this._feature.schema.fieldExtensions.forField(t)}_getFieldExtensionFormat(e){const t=this._getFieldExtension(e);return t?t.format:"{0}"}_formatAttribute(e,t){const r=e.match(_fieldWithArcadeXRegex),s=e.match(_fieldWithRelationshipRegex);if(r)return formatAttribute(this._feature,"expression",r[1],{format:t});if(s){const[,e,r]=s;return formatAttribute(this._feature,e,r,{format:t})}return formatAttribute(this._feature,void 0,e,{format:t})}}const fieldTokenRegex=/\{(?:relationships[\\/](\w\w*)[\\/])?(?:(expression)[\\/])?([a-zA-Z][.\w]*)(?::([^}]*))?\}/g,relationshipIdRegex=/\{relationships\/(\w\w*)[\\/]([^}]*)\}/g,escapedBraceRegex=/{{/g,escapedBracePlaceholder="\0MAGIC\0",escapedBracePlaceholderRegex=new RegExp(escapedBracePlaceholder,"g"),invalidRelationshipOrExpression="#INVALID";class HyperlinksCollection extends MapTransformCollection{constructor(e){super(e.settings.hyperlinkTemplates,(e=>this._getHyperlink(e))),this._feature=e}_getHyperlink(e){return this._hyperlinks=this._hyperlinks||new WeakMap,this._hyperlinks.has(e)||this._hyperlinks.set(e,new FeatureHyperlink(this._feature,e)),this._hyperlinks.get(e)}}let FeatureHyperlink=class extends Hyperlink{constructor(e,t){super(t.toJSON()),this._feature=e,this._template=t}get url(){return this._template.url?this._feature.format(this._template.url):this._template.url}set url(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get text(){return this._template.text?this._feature.format(this._template.text):this._template.text}set text(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get iconUrl(){return this._template.iconUrl?this._feature.format(this._template.iconUrl):this._template.iconUrl}set iconUrl(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get target(){return this._template.target?this._feature.format(this._template.target):this._template.target}set target(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}get tooltip(){return this._template.tooltip?this._feature.format(this._template.tooltip):this._template.tooltip}set tooltip(e){throw new InvalidOperationError(ERR_HYPERLINK_READONLY)}_watchProperty(e,t,r,s){const i=super._watchProperty(e,t,r,s),a=this._template.watch(e,(()=>{this._notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this._notifyChange(e)}));return{remove:()=>{i.remove(),a.remove(),o.remove()}}}_getSerializableProperties(){return{}}};function formatAttribute(e,t,r,s={format:"{0}"}){if("expression"!==t){if(t){const i=find(e.relatedFeatures.keys(),(e=>e.id===t));if(!i)return log.debug("Could not resolve related field '{0}/{1}",t,r),invalidRelationshipOrExpression;const a=Array.from(e.relatedFeatures.get(i));return"many-to-one"===i.cardinality||"one-to-one"===i.cardinality?a.length<1?(log.debug("Could not resolve related field '{0}/{1}",t,r),invalidRelationshipOrExpression):formatAttributeValue(a[0],r,s):a.map((e=>formatAttributeValue(e,r,s))).filter((e=>""!==e)).join(",")}return formatAttributeValue(e,r,s)}if(!e.settings.popupTemplate?.expressionInfos?.find((e=>e.name===r)))return log.debug("Could not find expression '{0}'.",r),invalidRelationshipOrExpression;try{const t=e.expressionFieldValues.get(r)??s.defaultExpressionValue??"",i=e.schema.findFieldByName(`expression/${r}`);let a=s;if(i){const t=e.schema.fieldExtensions.forField(i);a=formatOptionsForField(e,r,formatOptionsFromSettings(t.formatSettings),a)}return formatValue(e,t,a)}catch(e){if(e instanceof Error)return log.error({message:"Error evaluating expression '{0}': {1}.",error:e},r,e.message),invalidRelationshipOrExpression;throw e}}function formatAttributeValue(e,t,r){let s=e.attributes.get(t);if(null==s)return"";const i=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[t];if(t===e.schema.typeIdField)s=e.type?e.type.name:s;else if(isCodedValueDomain(o)){const e=o.codedValues.find((e=>`${e.code}`==`${s.toString()}`));s=e?e.name:s}else if(i)if(isCodedValueDomain(i.domain)){const e=i.domain.codedValues.find((e=>`${e.code}`==`${s.toString()}`));e&&(s=e.name)}else{switch(i.type){case"integer":case"small-integer":case"single":case"double":s=parseNumber(s);break;case"date":s=parseDate({timeZone:e.schema.timeZone},s);break;default:s=`${s.toString()}`}a=formatOptionsFromSettings(e.schema.fieldExtensions.forField(i).formatSettings)}return formatValue(e,s,formatOptionsForField(e,t,a,r))}function formatValue(e,t,r){let s=r;if("number"==typeof t||t instanceof Date){s={...formatOptionsFromSettings(e.settings.formatSettings),...r}}return"{0}"===s.format&&"string"==typeof t?t:formatString(s,t)}function formatOptionsFromSettings(e){return{format:"{0}",dateFormat:e.dateFormat,numberFormat:e.numberFormat,currency:e.currency,fractionalDigits:e.fractionalDigits,locale:e.locale,timeZone:e.timeZone}}function formatOptionsForField(e,t,r,s){const{popupTemplate:i}=e.settings,a=i?.fieldInfos?i.fieldInfos.find((e=>e.fieldName===t)):void 0,o=a?a.format:void 0;let n;return o&&(n={format:"{0}",numberFormat:o.digitSeparator?NumberFormat.NUMBER:NumberFormat.FIXED_POINT,dateFormat:esriFormatToGeocortexFormat(o.dateFormat),fractionalDigits:o.places}),{...n,...r,...s}}FeatureHyperlink=__decorate([serializable],FeatureHyperlink);export async function resolveRelatedFeatures(e){const t=groupBy(e,(e=>e.source));await Promise.all(flatten([...t.keys()].map((e=>e.relationships.toArray()))).map((e=>(async e=>{[...(await e.getAllRelatedFeatures(t.get(e.source))).entries()].forEach((([t,r])=>{t.relatedFeatures.set(e,r)}))})(e))))}
|
|
@@ -15,7 +15,7 @@ import type { Feature } from "./Feature.js";
|
|
|
15
15
|
import { FeatureSettings } from "./FeatureSettings.js";
|
|
16
16
|
import { Schema } from "./Schema.js";
|
|
17
17
|
import { TaskSettings } from "./TaskSettings.js";
|
|
18
|
-
import { Relationship } from "./_Relationship.js";
|
|
18
|
+
import { Relationship, RelationshipProperties } from "./_Relationship.js";
|
|
19
19
|
/**
|
|
20
20
|
* Properties that can be passed into the constructor for {@link FeatureSourceBase}.
|
|
21
21
|
*/
|
|
@@ -232,9 +232,9 @@ export declare abstract class FeatureSourceBase<TProperties extends FeatureSourc
|
|
|
232
232
|
* The capabilities of the feature source.
|
|
233
233
|
*/
|
|
234
234
|
protected _capabilities(): Capabilities;
|
|
235
|
+
protected _isRelationship(relationship: Relationship | RelationshipProperties): boolean;
|
|
235
236
|
private _createAndSetupSchema;
|
|
236
237
|
private _createAndSetupFeatureSettings;
|
|
237
|
-
private _isRelationship;
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
240
|
* Backing implementation for FeatureSourceBase.relationships.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ArgumentError}from"../ArgumentError.js";import{EntityBase}from"../Entity.js";import{Hyperlink}from"../Hyperlink.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isMenu,isRelationship}from"../ItemType.js";import{NotFoundError}from"../NotFoundError.js";import{FeatureReadOptions}from"../data/FeatureSource.js";import{Menu}from"../menus/Menu.js";import{CollectionProxy}from"../utilities/CollectionProxy.js";import{first}from"../utilities/asyncIterable.js";import{checkArg}from"../utilities/checkArg.js";import{Collection,compare}from"../utilities/collection.js";import{getLogger}from"../utilities/log.js";import{FeatureSettings}from"./FeatureSettings.js";import{Schema}from"./Schema.js";import{TaskSettings}from"./TaskSettings.js";import{Relationship}from"./_Relationship.js";const ERR_GET_FEATURES_NOT_SUPPORTED="Querying features is not supported.",ERR_ADD_FEATURES_NOT_SUPPORTED="Adding features is not supported.",ERR_ADD_ATTACHMENTS_NOT_SUPPORTED="Adding attachments is not supported.",ERR_DELETE_ATTACHMENTS_NOT_SUPPORTED="Deleting attachments is not supported.",ERR_UPDATE_FEATURES_NOT_SUPPORTED="Updating features is not supported.",ERR_DELETE_FEATURES_NOT_SUPPORTED="Deleting features is not supported.",DEFAULT_CAPABILITIES=Object.freeze({supportsAdd:!1,supportsUpdate:!1,supportsDelete:!1,supportsEditing:!1,supportsAttachmentEditing:!1}),log=getLogger("FeatureSourceBase");export class FeatureSourceBase extends EntityBase{constructor(e){super(e),this.featureSettings=this._createAndSetupFeatureSettings(),this.taskSettings=this._createTaskSettings(),this.schema=this._createAndSetupSchema(),this.relationships=this._createRelationships(),this.hyperlinks=this._createHyperlinks()}get featureActions(){return this._featureActions}set featureActions(e){this._featureActions=e,e&&this.isInitialized&&!e.isInitialized&&(async()=>{try{await e.initialize()}catch(e){e instanceof Error&&log.error({message:"An error occurred while initializing feature action menu.",error:e})}})()}get capabilities(){return this._capabilities()}getFullExtent(){}async getAttachments(e){return checkArg("feature",e).isNotMissing(),await this.initialize(),this._getAttachments(e)}async addAttachment(e,t){if(checkArg("feature",e).isNotMissing(),checkArg("attachment",t).isNotMissing(),e.source&&e.source!==this)throw new ArgumentError("feature",`Cannot add an attachment to a feature not of this source (${this.title??this.id})`);return await this.initialize(),this._addAttachment(e,t)}async deleteAttachments(e,t){if(checkArg("feature",e).isNotMissing(),checkArg("attachmentIds",t).isNotMissing(),e.source&&e.source!==this)throw new ArgumentError("feature",`Cannot delete attachments from a feature not of this source (${this.title??this.id})`);await this.initialize(),await this._deleteAttachments(e,t)}async getFeature(e,t){checkArg("id",e).isNotMissing();const i=this.getFeatures([e],t),s=await first(i);if(!s)throw new NotFoundError("No feature exists with ID '{0}'.",e);return s}getFeatures(e,t){checkArg("ids",e).isNotMissing();const i=this;return async function*(){await i.initialize(),yield*i._getFeatures(e,{...FeatureReadOptions.DEFAULTS,...FeatureReadOptions.fromFeatureSource(i),...t})}()}async addFeature(e,t){checkArg("feature",e).isNotMissing(),await this.addFeatures([e])}async addFeatures(e,t){if(checkArg("features",e).isNotMissing(),await this.initialize(),!this.capabilities.supportsAdd)throw new InvalidOperationError(ERR_ADD_FEATURES_NOT_SUPPORTED);await this._addFeatures(e,t)}async updateFeature(e,t){checkArg("feature",e).isNotMissing(),await this.updateFeatures([e])}async updateFeatures(e,t){if(checkArg("features",e).isNotMissing(),await this.initialize(),!this.capabilities.supportsUpdate)throw new InvalidOperationError(ERR_UPDATE_FEATURES_NOT_SUPPORTED);await this._updateFeatures(e,t)}async deleteFeature(e,t){checkArg("feature",e).isNotMissing(),await this.deleteFeatures([e])}async deleteFeatures(e,t){if(checkArg("features",e).isNotMissing(),await this.initialize(),!this.capabilities.supportsDelete)throw new InvalidOperationError(ERR_DELETE_FEATURES_NOT_SUPPORTED);const i=[];for(const t of e)i.push("string"==typeof t?t:t.primaryKey);await this._deleteFeatures(i,t)}_getSerializableProperties(){return{...super._getSerializableProperties(),featureSettings:{serializeModes:["initial"],isDefault:e=>{if(!e)return!0;if(e.constructor===Object){if(!Object.keys(e).length)return!0}return!1}},taskSettings:"initial",onAddFeature:"initial",onEditFeature:"initial",schema:"initial",relationships:{serialize
|
|
1
|
+
import{ArgumentError}from"../ArgumentError.js";import{EntityBase}from"../Entity.js";import{Hyperlink}from"../Hyperlink.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isMenu,isRelationship}from"../ItemType.js";import{NotFoundError}from"../NotFoundError.js";import{FeatureReadOptions}from"../data/FeatureSource.js";import{Menu}from"../menus/Menu.js";import{CollectionProxy}from"../utilities/CollectionProxy.js";import{first}from"../utilities/asyncIterable.js";import{checkArg}from"../utilities/checkArg.js";import{Collection,compare}from"../utilities/collection.js";import{getLogger}from"../utilities/log.js";import{FeatureSettings}from"./FeatureSettings.js";import{Schema}from"./Schema.js";import{TaskSettings}from"./TaskSettings.js";import{Relationship}from"./_Relationship.js";const ERR_GET_FEATURES_NOT_SUPPORTED="Querying features is not supported.",ERR_ADD_FEATURES_NOT_SUPPORTED="Adding features is not supported.",ERR_ADD_ATTACHMENTS_NOT_SUPPORTED="Adding attachments is not supported.",ERR_DELETE_ATTACHMENTS_NOT_SUPPORTED="Deleting attachments is not supported.",ERR_UPDATE_FEATURES_NOT_SUPPORTED="Updating features is not supported.",ERR_DELETE_FEATURES_NOT_SUPPORTED="Deleting features is not supported.",DEFAULT_CAPABILITIES=Object.freeze({supportsAdd:!1,supportsUpdate:!1,supportsDelete:!1,supportsEditing:!1,supportsAttachmentEditing:!1}),log=getLogger("FeatureSourceBase");export class FeatureSourceBase extends EntityBase{constructor(e){super(e),this.featureSettings=this._createAndSetupFeatureSettings(),this.taskSettings=this._createTaskSettings(),this.schema=this._createAndSetupSchema(),this.relationships=this._createRelationships(),this.hyperlinks=this._createHyperlinks()}get featureActions(){return this._featureActions}set featureActions(e){this._featureActions=e,e&&this.isInitialized&&!e.isInitialized&&(async()=>{try{await e.initialize()}catch(e){e instanceof Error&&log.error({message:"An error occurred while initializing feature action menu.",error:e})}})()}get capabilities(){return this._capabilities()}getFullExtent(){}async getAttachments(e){return checkArg("feature",e).isNotMissing(),await this.initialize(),this._getAttachments(e)}async addAttachment(e,t){if(checkArg("feature",e).isNotMissing(),checkArg("attachment",t).isNotMissing(),e.source&&e.source!==this)throw new ArgumentError("feature",`Cannot add an attachment to a feature not of this source (${this.title??this.id})`);return await this.initialize(),this._addAttachment(e,t)}async deleteAttachments(e,t){if(checkArg("feature",e).isNotMissing(),checkArg("attachmentIds",t).isNotMissing(),e.source&&e.source!==this)throw new ArgumentError("feature",`Cannot delete attachments from a feature not of this source (${this.title??this.id})`);await this.initialize(),await this._deleteAttachments(e,t)}async getFeature(e,t){checkArg("id",e).isNotMissing();const i=this.getFeatures([e],t),s=await first(i);if(!s)throw new NotFoundError("No feature exists with ID '{0}'.",e);return s}getFeatures(e,t){checkArg("ids",e).isNotMissing();const i=this;return async function*(){await i.initialize(),yield*i._getFeatures(e,{...FeatureReadOptions.DEFAULTS,...FeatureReadOptions.fromFeatureSource(i),...t})}()}async addFeature(e,t){checkArg("feature",e).isNotMissing(),await this.addFeatures([e])}async addFeatures(e,t){if(checkArg("features",e).isNotMissing(),await this.initialize(),!this.capabilities.supportsAdd)throw new InvalidOperationError(ERR_ADD_FEATURES_NOT_SUPPORTED);await this._addFeatures(e,t)}async updateFeature(e,t){checkArg("feature",e).isNotMissing(),await this.updateFeatures([e])}async updateFeatures(e,t){if(checkArg("features",e).isNotMissing(),await this.initialize(),!this.capabilities.supportsUpdate)throw new InvalidOperationError(ERR_UPDATE_FEATURES_NOT_SUPPORTED);await this._updateFeatures(e,t)}async deleteFeature(e,t){checkArg("feature",e).isNotMissing(),await this.deleteFeatures([e])}async deleteFeatures(e,t){if(checkArg("features",e).isNotMissing(),await this.initialize(),!this.capabilities.supportsDelete)throw new InvalidOperationError(ERR_DELETE_FEATURES_NOT_SUPPORTED);const i=[];for(const t of e)i.push("string"==typeof t?t:t.primaryKey);await this._deleteFeatures(i,t)}_getSerializableProperties(){return{...super._getSerializableProperties(),featureSettings:{serializeModes:["initial"],isDefault:e=>{if(!e)return!0;if(e.constructor===Object){if(!Object.keys(e).length)return!0}return!1}},taskSettings:"initial",onAddFeature:"initial",onEditFeature:"initial",schema:"initial",relationships:{serializeModes:["initial"],serialize:e=>this.relationships?this.relationships.filter((e=>"ArcGISRelationship"!==e.relationshipType)).map((t=>t.toJSON(e))).toArray():[],deserialize:e=>{compare(this.relationships,e,{onNew:e=>{isRelationship(e)?this.relationships.add(e):this.relationships.add(Relationship.create(e))},onMatch:(e,t)=>{isRelationship(e)&&e.assignProperties({title:t.title})},onMissing:e=>{"ArcGISRelationship"!==e.relationshipType&&this.relationships.remove(e)},equals:(e,t)=>e.id===t.id})},default:[]},hyperlinks:{serialize:!1,deserialize:e=>{this.hyperlinks.removeAll(),this.hyperlinks.addMany(e.map((e=>e instanceof Hyperlink?e:new Hyperlink(e))))}},featureActions:{serializeModes:["initial"],deserialize:e=>{e?isMenu(e)?this.featureActions=e:this.featureActions?this.featureActions.assignProperties(e):this.featureActions=Menu.create(e):this.featureActions=void 0}}}}*_initializableChildCollections(){yield*super._initializableChildCollections(),yield this.schema.fieldExtensions}async _onInitialize(){await super._onInitialize(),this.featureActions&&await this.featureActions.initialize()}async _postInitialize(){await super._postInitialize(),this.featureSettings.popupTemplate||(this.featureSettings.popupTemplate=this.schema.createPopupTemplate());const{popupTemplate:e}=this.featureSettings;"function"==typeof e.content&&(e.content=e.content()),e.content=await e.content;const{content:t}=e;Array.isArray(t)&&t.some((e=>"fields"===e.type&&!e.fieldInfos?.length))&&!e.fieldInfos?.length&&(e.fieldInfos=this.schema.createAllFieldInfos()),!e.title&&this.schema.displayField&&(e.title=`{${this.schema.displayField}}`)}_createSchema(){return new Schema}_createFeatureSettings(){return new FeatureSettings}_createTaskSettings(){return new TaskSettings}_createRelationships(){return new RelationshipCollection(this)}_createHyperlinks(){return new Collection}async _getAttachments(e){return[]}async _addAttachment(e,t){throw new InvalidOperationError(ERR_ADD_ATTACHMENTS_NOT_SUPPORTED)}async _deleteAttachments(e,t){throw new InvalidOperationError(ERR_DELETE_ATTACHMENTS_NOT_SUPPORTED)}_getFeatures(e,t){const{primaryKeyField:i}=this.schema;if(this.queryService&&i){const s=e.map((e=>`${i} = ${e}`)).join(" OR ");return this.queryService.query(this,s,t)}throw new InvalidOperationError(ERR_GET_FEATURES_NOT_SUPPORTED)}_addFeatures(e,t){throw new InvalidOperationError(ERR_ADD_FEATURES_NOT_SUPPORTED)}_updateFeatures(e,t){throw new InvalidOperationError(ERR_UPDATE_FEATURES_NOT_SUPPORTED)}_deleteFeatures(e,t){throw new InvalidOperationError(ERR_DELETE_FEATURES_NOT_SUPPORTED)}_capabilities(){return DEFAULT_CAPABILITIES}_isRelationship(e){return"function"==typeof e.getRelatedFeatures}_createAndSetupSchema(){const e=this._createSchema();return e._featureSettings=this.featureSettings,e}_createAndSetupFeatureSettings(){const e=this._createFeatureSettings();return e._setFeatureSource(this),e}}export class RelationshipCollection extends CollectionProxy{constructor(e){super(new Collection),this._source=e}add(e,t){checkArg("relationship",e).isNotMissing(),e.source&&e.source.relationships.remove(e),isRelationship(e)&&e._setSource(this._source),super.add(e,t)}removeAt(e){const t=super.removeAt(e);return isRelationship(t)&&t._setSource(void 0),t}}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EntityBase } from "../Entity.js";
|
|
2
|
-
import type { Feature } from "../data/Feature.js";
|
|
2
|
+
import type { Feature, FetchRelatedFeaturesOptions } from "../data/Feature.js";
|
|
3
3
|
import type { FeatureSet } from "../data/FeatureSet.js";
|
|
4
4
|
import type { FeatureSource } from "../data/FeatureSource.js";
|
|
5
5
|
import type { PropertyDefs } from "../support/Serializable.js";
|
|
@@ -33,15 +33,18 @@ export declare abstract class RelationshipBase<TProperties extends RelationshipP
|
|
|
33
33
|
* @inheritdoc
|
|
34
34
|
*/
|
|
35
35
|
protected readonly _itemType: string;
|
|
36
|
-
private _source;
|
|
37
36
|
/**
|
|
38
37
|
* @inheritdoc
|
|
39
38
|
*/
|
|
40
|
-
|
|
39
|
+
protected _source: FeatureSource;
|
|
41
40
|
/**
|
|
42
41
|
* @inheritdoc
|
|
43
42
|
*/
|
|
44
|
-
|
|
43
|
+
getRelatedFeatures(feature: Feature, options?: FetchRelatedFeaturesOptions): Promise<FeatureSet>;
|
|
44
|
+
/**
|
|
45
|
+
* @inheritdoc
|
|
46
|
+
*/
|
|
47
|
+
getAllRelatedFeatures(features: Feature[] | FeatureSet | FeatureStream, options?: FetchRelatedFeaturesOptions): Promise<Map<Feature, FeatureSet>>;
|
|
45
48
|
/**
|
|
46
49
|
* @inheritdoc
|
|
47
50
|
*/
|
|
@@ -49,9 +52,9 @@ export declare abstract class RelationshipBase<TProperties extends RelationshipP
|
|
|
49
52
|
/**
|
|
50
53
|
* Called to get related features. Subclasses must override this.
|
|
51
54
|
*/
|
|
52
|
-
protected abstract _getRelatedFeatures(feature: Feature): Promise<FeatureSet>;
|
|
55
|
+
protected abstract _getRelatedFeatures(feature: Feature, options?: FetchRelatedFeaturesOptions): Promise<FeatureSet>;
|
|
53
56
|
/**
|
|
54
57
|
* Called to get related features. Subclasses must override this.
|
|
55
58
|
*/
|
|
56
|
-
protected abstract _getAllRelatedFeatures(features: Feature[]): Promise<Map<Feature, FeatureSet>>;
|
|
59
|
+
protected abstract _getAllRelatedFeatures(features: Feature[], options?: FetchRelatedFeaturesOptions): Promise<Map<Feature, FeatureSet>>;
|
|
57
60
|
}
|
package/data/RelationshipBase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isFeatureSet,ItemType}from"../ItemType.js";import{checkArg}from"../utilities/checkArg.js";const ERR_NO_FEATURE_SOURCE="Cannot get related features without feature source.";export class RelationshipBase extends EntityBase{constructor(){super(...arguments),this._itemType=ItemType.RELATIONSHIP}get source(){return this._source}async getRelatedFeatures(e){if(checkArg("feature",e).isNotMissing(),!this.source)throw new InvalidOperationError(ERR_NO_FEATURE_SOURCE);return this._getRelatedFeatures(e)}async getAllRelatedFeatures(e){if(checkArg("feature",e).isNotMissing(),!this.source)throw new InvalidOperationError(ERR_NO_FEATURE_SOURCE);let
|
|
1
|
+
import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isFeatureSet,ItemType}from"../ItemType.js";import{checkArg}from"../utilities/checkArg.js";const ERR_NO_FEATURE_SOURCE="Cannot get related features without feature source.";export class RelationshipBase extends EntityBase{constructor(){super(...arguments),this._itemType=ItemType.RELATIONSHIP}get source(){return this._source}async getRelatedFeatures(e,t){if(checkArg("feature",e).isNotMissing(),!this.source)throw new InvalidOperationError(ERR_NO_FEATURE_SOURCE);return this._getRelatedFeatures(e,t)}async getAllRelatedFeatures(e,t){if(checkArg("feature",e).isNotMissing(),!this.source)throw new InvalidOperationError(ERR_NO_FEATURE_SOURCE);let r;return r=Array.isArray(e)?e:isFeatureSet(e)?[...e]:await e.toArray(),this._getAllRelatedFeatures(r,t)}_setSource(e){this._source=e}_getSerializableProperties(){return{...super._getSerializableProperties(),title:"initial"}}}
|
package/data/_Relationship.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Entity, EntityBaseProperties } from "../Entity.js";
|
|
2
2
|
import type { Observable } from "../support/Observable.js";
|
|
3
3
|
import type { Serializable } from "../support/Serializable.js";
|
|
4
|
-
import type { Feature } from "./Feature.js";
|
|
4
|
+
import type { Feature, FetchRelatedFeaturesOptions } from "./Feature.js";
|
|
5
5
|
import type { FeatureSet } from "./FeatureSet.js";
|
|
6
6
|
import type { FeatureSource } from "./FeatureSource.js";
|
|
7
7
|
import type { FeatureStream } from "./FeatureStream.js";
|
|
@@ -46,7 +46,7 @@ export interface Relationship extends Observable, Entity, Serializable<Relations
|
|
|
46
46
|
/**
|
|
47
47
|
* Gets features that are related to the given feature.
|
|
48
48
|
*/
|
|
49
|
-
getRelatedFeatures(feature: Feature): Promise<FeatureSet>;
|
|
49
|
+
getRelatedFeatures(feature: Feature, options?: FetchRelatedFeaturesOptions): Promise<FeatureSet>;
|
|
50
50
|
/**
|
|
51
51
|
* Gets features that are related to the each of the given features.
|
|
52
52
|
*/
|
|
@@ -89,4 +89,4 @@ export declare type GeodatabaseCardinality = "esriRelCardinalityOneToOne" | "esr
|
|
|
89
89
|
/**
|
|
90
90
|
* The type of the Relationship.
|
|
91
91
|
*/
|
|
92
|
-
export declare type RelationshipType = "QueryBasedRelationship" | "ArcGISRelationship";
|
|
92
|
+
export declare type RelationshipType = "QueryBasedRelationship" | "ArcGISRelationship" | string;
|
|
@@ -8,6 +8,7 @@ import { PropertyDefs } from "../support/Serializable.js";
|
|
|
8
8
|
import { FeatureSettings } from "./FeatureSettings.js";
|
|
9
9
|
import { FeatureSourceBase, FeatureSourceBaseProperties } from "./FeatureSourceBase.js";
|
|
10
10
|
import type { QuerySourceCapabilities } from "./QuerySourceCapabilities.js";
|
|
11
|
+
import type { Relationship, RelationshipProperties } from "./Relationship.js";
|
|
11
12
|
import { Schema } from "./Schema.js";
|
|
12
13
|
import type { TableExtensionFactory } from "./support/TableExtensionFactory.js";
|
|
13
14
|
/**
|
|
@@ -18,6 +19,10 @@ export interface TableExtensionProperties extends FeatureSourceBaseProperties {
|
|
|
18
19
|
* See {@link TableExtension.table}.
|
|
19
20
|
*/
|
|
20
21
|
table?: Layer | TableProperties;
|
|
22
|
+
/**
|
|
23
|
+
* See {@link TableExtension.relationships}.
|
|
24
|
+
*/
|
|
25
|
+
relationships?: (Relationship | RelationshipProperties)[];
|
|
21
26
|
}
|
|
22
27
|
/**
|
|
23
28
|
* Properties that can be specified for the
|