@vertigis/arcgis-extensions 37.3.1 → 37.4.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/data/Feature.d.ts +17 -0
- package/data/Feature.js +1 -1
- package/data/RelationshipBase.d.ts +1 -0
- package/data/RelationshipBase.js +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/data_Feature.Feature.html +33 -1
- package/docs/html/classes/data_FeatureSet.FeatureSet.html +2 -2
- package/docs/html/classes/data_FeatureStream.FeatureStream.html +1 -1
- package/docs/html/classes/utilities_ObservableMap.ObservableMap.html +2 -2
- package/docs/html/classes/utilities_ObservableSet.ObservableSet.html +2 -2
- package/docs/html/classes/utilities_ObservableWeakSet.ObservableWeakSet.html +1 -1
- package/docs/html/classes/utilities_asyncIterable.AsyncQueue.html +1 -1
- package/docs/html/variables/version.version.html +1 -1
- package/package.json +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/data/Feature.d.ts
CHANGED
|
@@ -176,6 +176,20 @@ export declare class Feature extends EntityBase<FeatureProperties> {
|
|
|
176
176
|
* The Esri API FeatureType object that is associated with this feature.
|
|
177
177
|
*/
|
|
178
178
|
get type(): FeatureType;
|
|
179
|
+
/**
|
|
180
|
+
* Indicates whether attachments have been fetched at least once.
|
|
181
|
+
*/
|
|
182
|
+
get attachmentsInitialized(): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Indicates whether related features have been fetched at least once, if
|
|
185
|
+
* this feature has relationships.
|
|
186
|
+
*/
|
|
187
|
+
get relatedFeaturesInitialized(): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Indicates whether async Arcade expressions have been evaluated at least
|
|
190
|
+
* once.
|
|
191
|
+
*/
|
|
192
|
+
get expressionsInitialized(): boolean;
|
|
179
193
|
private get _title();
|
|
180
194
|
private get _description();
|
|
181
195
|
private _geometry;
|
|
@@ -186,6 +200,9 @@ export declare class Feature extends EntityBase<FeatureProperties> {
|
|
|
186
200
|
private readonly _relatedFeatures;
|
|
187
201
|
private readonly _expressionFieldValues;
|
|
188
202
|
private _expressionValuesUpdatePending;
|
|
203
|
+
private _attachmentsInitialized;
|
|
204
|
+
private _expressionsInitialized;
|
|
205
|
+
private readonly _initializedRelationships;
|
|
189
206
|
constructor(properties?: FeatureProperties);
|
|
190
207
|
/**
|
|
191
208
|
* Same as {@link utilities/string!StringFormatter.format}, except that the
|
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.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 hasGlobalId(){return!!this.schema.fields.find((e=>"global-id"===e.type))}get globalId(){const e=this.schema.fields.find((e=>"global-id"===e.type));return e?this.attributes.get(e.name):void 0}set globalId(e){const t=this.schema.fields.find((e=>"global-id"===e.type));if(!t)throw new InvalidOperationError("Cannot set global ID on feature -- no global ID field.");this.attributes.set(t.name,e)}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 _key(){return`${this.source?.id}//${this.primaryKey??this.globalId??this.id}`}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,t){if(!this.source)return;let s=[];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.");s.push(t)}}else s=this.source.relationships.toArray();const r=await promiseMap(s,(async e=>[e,await e.getRelatedFeatures(this,t)]));for(const e of r)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{onCollectionPropertyChange}from"../utilities/watch.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._attachmentsInitialized=!1,this._expressionsInitialized=!1,this._initializedRelationships=new WeakSet,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),onCollectionPropertyChange(this,"source.relationships",(()=>{this.notifyChange("relatedFeaturesInitialized")}),!0),this.settings.watch("popupTemplate",((e,t)=>{e!==t&&(this._expressionsInitialized=!1,this.notifyChange("expressionsInitialized"))}),!0)}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),this.notifyChange("attachmentsInitialized"),this.notifyChange("relatedFeaturesInitialized")}get primaryKey(){const e=this.attributes.get(this.schema.primaryKeyField);return null!=e?`${e}`:void 0}get hasGlobalId(){return!!this.schema.fields.find((e=>"global-id"===e.type))}get globalId(){const e=this.schema.fields.find((e=>"global-id"===e.type));return e?this.attributes.get(e.name):void 0}set globalId(e){const t=this.schema.fields.find((e=>"global-id"===e.type));if(!t)throw new InvalidOperationError("Cannot set global ID on feature -- no global ID field.");this.attributes.set(t.name,e)}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 attachmentsInitialized(){return!this.source||this._attachmentsInitialized}get relatedFeaturesInitialized(){return!this.source||this.source.relationships.every((e=>this._initializedRelationships.has(e)))}get expressionsInitialized(){return!this.settings.popupTemplate||!this.settings.popupTemplate.expressionInfos?.length||this._expressionsInitialized}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 _key(){return`${this.source?.id}//${this.primaryKey??this.globalId??this.id}`}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:i}=s;checkArg("format",i).isNotMissing();let r=s.format.replace(escapedBraceRegex,escapedBracePlaceholder);return r=r.replace(fieldTokenRegex,((e,t,i,r,a)=>formatAttribute(this,t||i,r,{...s,format:a?`{0:${a}}`:"{0}"}))),r=r.replace(escapedBracePlaceholderRegex,"{{"),s={...s},s.format=r,formatString(s,...t)}clearExpressionInfos(){this._expressionFieldValues.clear()}async fetchExpressionInfos(e=!1){const{expressionInfos:t}=this.settings.popupTemplate??{};if(t){if(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)return this.attributes.on("change",(async e=>{this._expressionValuesUpdatePending||(this._expressionValuesUpdatePending=!0,setTimeout((async()=>{this._expressionValuesUpdatePending=!1,await this.fetchExpressionInfos()}),0))}));this._expressionsInitialized=!0,this.notifyChange("expressionsInitialized")}}async fetchRelatedFeatures(e,t){if(!this.source)return;let s=[];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.");s.push(t)}}else s=this.source.relationships.toArray();const i=await promiseMap(s,(async e=>[e,await(async()=>{const s=await e.getRelatedFeatures(this,t);return this._initializedRelationships.add(e),s})()]));for(const e of i)this._relatedFeatures.set(e[0],e[1]);this.notifyChange("relatedFeaturesInitialized")}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,i)=>{this.attachments.splice(s,1,t)}}),this._attachmentsInitialized=!0,this.notifyChange("attachmentsInitialized")}}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,i){if("title"===e||"description"===e){const r=super._watchProperty(e,t,s,i),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(){r.remove(),o.remove(),n.remove()}}}return super._watchProperty(e,t,s,i)}async _onInitialize(){const e=this._findRelationshipIds(this._title,this._description),t=this.source?this.source.relationships.map((e=>e.id)).toArray():[],s=[];for(const i of e)t.includes(i)?s.push(this.fetchRelatedFeatures(i)):log.error("Could not find relationship '{0}' referenced in feature title or description.",i);await Promise.all(s)}_findRelationshipIds(...e){const t=[];for(const s of e){let e;const i=s.replace(escapedBraceRegex,escapedBracePlaceholder);for(;e=relationshipIdRegex.exec(i),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 i=this._feature.source?.layer??this._feature.source?.sublayer;let r=this._feature.source?.mapExtension;if(!r){const e=this._feature.source?.layerExtension;r=e?.mapExtension}this._originalMap.set(e,await runAsyncArcadeExpression(s.expression,{feature:this._feature,layer:i,map:r?.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()},i=()=>{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),r())},r=()=>{e.clear(),s(),forEach(this.keys(),(s=>{const r=this._getFieldExtension(s);let a="{0}";if(r){const e=r.watch("format",(()=>{i()}));t.add(e),r.format&&(a=r.format)}e.set(s,this._formatAttribute(s,a))}))};r();const a=this._feature.attributes.on("change",(()=>{i()})),o=this._feature.schema.fieldExtensions.on("change",(()=>{i()})),n=this._feature.settings.formatSettings.watch(["numberFormat","dateFormat","locale"],(()=>{i()})),l=this._feature.expressionFieldValues.on("change",(()=>{i()})),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))))&&i()})),h=this._feature.settings.watch("popupTemplate",(()=>{i()}));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),i=e.match(fieldWithRelationshipRegex);if(s)return formatAttribute(this._feature,"expression",s[1],{format:t});if(i){const[,e,s]=i;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,i){const r=super._watchProperty(e,t,s,i),a=this._template.watch(e,(()=>{this.notifyChange(e)})),o=this._feature.presentableAttributes.on("change",(()=>{this.notifyChange(e)})),n=this._feature.relatedFeatures.on("change",(()=>{this._notifyChange(e)}));return{remove:()=>{r.remove(),a.remove(),o.remove(),n.remove()}}}_getSerializableProperties(){return{}}};function formatAttribute(e,t,s,i={format:"{0}"}){if("expression"!==t){if(t){const r=find(e.relatedFeatures.keys(),(e=>e.id===t));if(!r)return log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression;const a=Array.from(e.relatedFeatures.get(r));return"many-to-one"===r.cardinality||"one-to-one"===r.cardinality?a.length<1?(log.debug("Could not resolve related field '{0}/{1}",t,s),invalidRelationshipOrExpression):formatAttributeValue(a[0],s,i):a.map((e=>formatAttributeValue(e,s,i))).filter((e=>""!==e)).join(",")}return formatAttributeValue(e,s,i)}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)??i.defaultExpressionValue??"",r=e.schema.findFieldByName(`expression/${s}`);let a=i;if(r){const t=e.schema.fieldExtensions.forField(r);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 i=e.attributes.get(t);if(null==i)return"";const r=e.schema.findFieldByName(t);let a={format:"{0}"};const o=e.type?.domains?.[t];if(t===e.schema.typeIdField)i=e.type?e.type.name:i;else if(isCodedValueDomain(o)){const e=o.codedValues.find((e=>`${e.code}`==`${i.toString()}`));i=e?e.name:i}else if(r)if(isCodedValueDomain(r.domain)){const e=r.domain.codedValues.find((e=>`${e.code}`==`${i.toString()}`));e&&(i=e.name)}else{switch(r.type){case"integer":case"small-integer":case"single":case"double":i=parseNumber(i);break;case"date":i=parseDate({timeZone:e.schema.timeZone},i);break;default:i=`${i.toString()}`}a=formatOptionsFromSettings(e.schema.fieldExtensions.forField(r).formatSettings)}return formatValue(e,i,formatOptionsForField(e,t,a,s))}function formatValue(e,t,s){let i=s;if("number"==typeof t||t instanceof Date){i={...formatOptionsFromSettings(e.settings.formatSettings),...s}}return"{0}"===i.format&&"string"==typeof t?t:formatString(i,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,i){const{popupTemplate:r}=e.settings,a=r?.fieldInfos?r.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,...i}}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))))}
|
|
@@ -9,6 +9,7 @@ import type { Cardinality, Relationship, RelationshipProperties, RelationshipTyp
|
|
|
9
9
|
* A base class for implementations of {@link data/_Relationship!Relationship}.
|
|
10
10
|
*/
|
|
11
11
|
export declare abstract class RelationshipBase<TProperties extends RelationshipProperties = RelationshipProperties> extends EntityBase<TProperties> implements Relationship {
|
|
12
|
+
#private;
|
|
12
13
|
/**
|
|
13
14
|
* @inheritDoc
|
|
14
15
|
*/
|
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,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
|
|
1
|
+
var _RelationshipBase_getRelatedFeaturesPromises;import{__classPrivateFieldGet}from"tslib";import{EntityBase}from"../Entity.js";import{InvalidOperationError}from"../InvalidOperationError.js";import{isFeatureSet,ItemType}from"../ItemType.js";import{cancelify}from"../support/Cancellable.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),_RelationshipBase_getRelatedFeaturesPromises.set(this,new WeakMap),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);__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").has(e)||__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").set(e,(async()=>{try{return await this._getRelatedFeatures(e,t)}finally{__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").delete(e)}})());const s=__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").get(e);return cancelify(s,t?.cancelToken)}async getAllRelatedFeatures(e,t){if(checkArg("feature",e).isNotMissing(),!this.source)throw new InvalidOperationError(ERR_NO_FEATURE_SOURCE);let s;s=Array.isArray(e)?e:isFeatureSet(e)?[...e]:await e.toArray();const a=cancelify(this._getAllRelatedFeatures(s,t),t?.cancelToken);for(const e of s)__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").has(e)||__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").set(e,(async()=>{try{return(await a).get(e)}finally{__classPrivateFieldGet(this,_RelationshipBase_getRelatedFeaturesPromises,"f").delete(e)}})());return a}_setSource(e){this._source=e}_getSerializableProperties(){return{...super._getSerializableProperties(),title:"initial"}}}_RelationshipBase_getRelatedFeaturesPromises=new WeakMap;
|