@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 28.1 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../Graphic.js";import r from"../../../core/Accessor.js";import{equals as i,isSome as s}from"../../../core/arrayUtils.js";import n from"../../../core/Collection.js";import a from"../../../core/Error.js";import{clone as o}from"../../../core/lang.js";import u from"../../../core/Logger.js";import{getOrCreateMapValue as l}from"../../../core/MapUtils.js";import d from"../../../core/ReactiveMap.js";import{watch as p,when as h}from"../../../core/reactiveUtils.js";import{property as c,subclass as y}from"../../../core/accessorSupport/decorators.js";import{geometryTypes as g}from"../../../geometry/support/typeUtils.js";import{isFeatureLayer as _,isSubtypeGroupLayer as f,isSubtypeSublayer as m}from"../../../layers/support/layerUtils.js";import b from"../../../rest/support/AttachmentQuery.js";import E from"../../../rest/support/RelationshipQuery.js";import v from"../../../time/TimeExtent.js";import{isIFeatureTableSupportedLayerWithAttachments as C,isIFeatureTableSupportedLayerWithAttachmentsEditing as I,isIFeatureTableSupportedLayerWithEditing as O,isIFeatureTableSupportedLayerWithRelationships as F,findRelatedLayer as A}from"./tableUtils.js";import w from"../../support/ContingentValuesManager.js";let j=class extends r{constructor(e){super(e),this._attachmentsOperationQueue=new n,this._contingentValuesManager=new w,this._defaultOutFields=["*"],this._editOperationQueue=new n,this.featureTitleMap=new d,this._loaded=!1,this._loadError=!1,this._loading=!1,this._objectIdCache=new n,this._pendingEditsCache=new d,this._queryOperationQueue=new n,this.attachmentsEnabled=!1,this.autoSaveEnabled=!0,this.count=0,this.editingEnabled=!1,this.failures=new n,this.filterGeometry=null,this.initialSize=null,this.layer=null,this.objectIds=null,this.outFields=null,this.pageCache=new d,this.pageSize=50,this.relationshipConfig=null,this.relatedRecordsEnabled=!1,this.returnGeometry=!1,this.returnZ=!1,this.returnM=!1,this.sortOrders=[],this.timeExtent=null,this.timeZone=null,this.view=null,this.where=null}initialize(){this.addHandles([p(()=>[this.filterGeometry,this.layer,this.objectIds,this.outFields,this.pageSize,this.relationshipConfig,this.returnGeometry,this.returnM,this.returnZ,this.timeExtent,this.where],()=>this._reset()),p(()=>this.orderByFields,()=>this._clearCaches(),{equals:i}),h(()=>this.attachmentsEnabled,()=>this._reset()),h(()=>this.relatedRecordsEnabled,()=>this._reset()),p(()=>this._layerWithContingentValues,e=>{const t=this._contingentValuesManager;e&&!t.layers.includes(e)&&t.layers.add(e)})])}destroy(){this.layer=null,this.itemCache?.destroy(),this.failures?.destroy()}get _capabilities(){const{layer:e}=this;return e?.effectiveCapabilities??e?.capabilities}get _canSavePendingEdits(){return this.supportsEditing&&this.hasPendingEdits&&!this.hasInvalidPendingEdits}get _effectiveReturnZ(){return this.returnZ&&this.supportsZ}get _effectiveReturnM(){return this.returnM&&this.supportsM}get _layerWithAttachments(){const{layer:e}=this;return e&&this._capabilities&&this.attachmentsEnabled&&this.supportsAttachments&&C(e)?e:null}get _layerWithAttachmentsEditing(){const{_layerWithAttachments:e}=this;return e&&I(e)&&this.supportsEditing?e:null}get _layerWithContingentValues(){const{layer:e}=this;return _(e)||f(e)?e:null}get _layerWithEditing(){const e=this.layer;return O(e)&&this.supportsEditing?e:null}get _layerWithRelationships(){const e=this.layer;return F(e)&&this.supportsQueryRelated?e:null}get _pendingEditsAreInvalid(){const e=this._pendingEditsCache,t=this._layerWithContingentValues;if(!t)return!1;for(const r of e.keys()){const i=e.get(r),s=this._getFeatureWithPendingEdits(r,i);for(const e of i.changes.keys()){if(this._contingentValuesManager.getViolationForField(t,s,e))return!0}}return!1}get _relatedLayer(){return this.relationshipConfig?.relatedLayer}get _relatedLayerCapabilities(){const{_relatedLayer:e}=this;return e?.effectiveCapabilities??e?.capabilities}get _relatedLayerSupportsCacheHint(){return!!this._relatedLayerCapabilities?.queryRelated?.supportsCacheHint}get _relatedLayerSupportsQuery(){return!!this._relatedLayerCapabilities?.operations.supportsQuery}get _relatedLayerSupportsQueryRelated(){const{_relatedLayerCapabilities:e}=this;return!!e?.queryRelated?.supportsCount&&!!e?.queryRelated?.supportsPagination}get _sortedFieldNames(){return this.sortOrders.map(({fieldName:e})=>e)}get _subtypeCode(){return this.layer?.subtypeCode??null}get _subtypeField(){const{layer:e}=this;return f(e?.parent)?e.subtypeField:null}get _canUseRelatedLayer(){return!(!this._relatedLayerSupportsQuery||!this._relatedLayerSupportsQueryRelated)}get canAddRelatedFeature(){const{state:e,relationship:t,supportsAdd:r,supportsEditing:i}=this;if("loaded"!==e||!t||!r||!i)return!1;const{count:s}=this,{cardinality:n,role:a}=t,o=s>0;return("one-to-one"!==n||!o)&&("one-to-many"!==n||"origin"!==a||!o)}get effectiveOutFields(){const{layer:e,outFields:t}=this;if(!e||!t?.length)return this._defaultOutFields;const r=[];t.forEach(t=>{const i=e.fieldsIndex.normalizeFieldName(t);i&&r.push(i)});const{objectIdField:i}=e,s=e.fieldsIndex.normalizeFieldName(i)??i;return s&&!r.includes(s)&&r.unshift(s),r}get effectiveTimeExtent(){const{layer:e,timeExtent:t}=this;return t||e&&"timeExtent"in e&&e.timeExtent||null}get effectiveWhere(){const{layer:e,where:t}=this;return null!=t&&""!==t?t:m(e)&&e.parent?.definitionExpression?e.parent.definitionExpression:e?.definitionExpression||"1=1"}get fieldsWithContingentValues(){const e=this._layerWithContingentValues;return e?this._contingentValuesManager.fieldsWithContingentValues.get(e):void 0}get hasContingentValues(){const e=this.fieldsWithContingentValues;return!!(e&&e.size>0)}get hasInvalidPendingEdits(){return this.hasPendingEdits&&this._pendingEditsAreInvalid}get hasPendingEdits(){return this.pendingEditsCount>0}get isQuerying(){return this._queryOperationQueue.length>0}get isSyncing(){return this.isSyncingFeatureEdits||this.isSyncingAttachmentEdits}get isSyncingAttachmentEdits(){return this._attachmentsOperationQueue.length>0}get isSyncingFeatureEdits(){return this._editOperationQueue.length>0}get itemCache(){return new n({items:[...this.pageCache.values()].flat()})}get layerView(){const{layer:e,view:t}=this;if(!e||!t)return null;const r="sublayer"===e.type||m(e)?e.parent:e;return t.allLayerViews.find(e=>e.layer===r)}get orderByFields(){const{_sortedFieldNames:e,layer:t,sortOrders:r}=this,i=r.filter(({fieldName:t,direction:r},i)=>e.indexOf(t)===i&&null!=r).map(({fieldName:e,direction:t})=>`${e} ${t?.toUpperCase()}`);if(t&&!i.length&&!t.objectIdField&&t.fields?.length){const e=t.fields.find(e=>e.name);if(e){const r=t.fieldsIndex.normalizeFieldName(e.name);r&&i.push(`${r} ASC`)}}return i}get pendingEditsCount(){let e=0;return this._pendingEditsCache.forEach(t=>e+=t.changes.size),e}get relationship(){const{relationshipConfig:e}=this;return null==e?.relationshipId?null:this.relationships?.find(t=>t.id===e.relationshipId)}get relationshipIds(){return this.relationships?.map(e=>e.id)??[]}get relationshipInfos(){const{_layerWithRelationships:e,relatedRecordsEnabled:t,relationships:r,view:i}=this,s=[];return t&&e?.loaded&&i?.map&&r?.length?(r.forEach(t=>{const r=A(e,i,t);r&&(r.load(),s.push({layer:e,relatedLayer:r,relationshipId:t.id}))}),s):s}get relationships(){return this._layerWithRelationships?.relationships}get state(){const{layer:e,_loaded:t,_loadError:r,_loading:i}=this;return!e||e.destroyed?"disabled":r||e.loadError?"error":"loaded"===e.loadStatus&&t?"loaded":i?"loading":"ready"}get supportsAdd(){return!!this._capabilities?.operations.supportsAdd}get supportsAddAttachments(){return!(!this._layerWithAttachmentsEditing||!this.supportsAdd&&!this.supportsUpdate)}get supportsAttachments(){const{_capabilities:e}=this;return!(!e?.data?.supportsAttachment||!e?.operations.supportsQueryAttachments)}get supportsCacheHint(){return!!this._capabilities?.query?.supportsCacheHint}get supportsCacheHintQueryRelated(){return!!this._capabilities?.queryRelated?.supportsCacheHint}get supportsDelete(){return!!this._capabilities?.operations.supportsDelete}get supportsEditing(){return!!this._capabilities?.operations.supportsEditing}get supportsM(){return!!this.layer?.hasM&&!!this._capabilities?.data?.supportsM}get supportsOrderBy(){return!!this._capabilities?.query?.supportsOrderBy}get supportsPagination(){return!!this._capabilities?.query?.supportsPagination}get supportsQuery(){return!!this._capabilities?.operations.supportsQuery}get supportsQueryRelated(){const{_capabilities:e}=this;return!!e?.queryRelated?.supportsCount&&!!e?.queryRelated?.supportsPagination}get supportsResizeAttachments(){const{_capabilities:e}=this;return!(!this.supportsAttachments||!e?.attachment?.supportsResize)}get supportsUpdate(){return!!this._capabilities?.operations.supportsUpdate}get supportsUpdateAttachments(){return!(!this._layerWithAttachmentsEditing||!this.supportsAdd&&!this.supportsUpdate)}get supportsZ(){return!!this.layer?.hasZ&&!!this._capabilities?.data?.supportsZ}async addAttachment(e,t){const{_layerWithAttachmentsEditing:r}=this;if(!r||!this.supportsAddAttachments)return{};const i=await this._queueAttachmentsOperation(e,()=>r.addAttachment(this._createBaseGraphic(r,e),t));return this._ensureArrayContent(i)}addPendingEdits(e){const t=this._ensureLayerAndUpdateSupport();this.autoSaveEnabled&&this._logWarning("store:pending-edit","Edit will be cached, but 'autoSaveEnabled' is true.",!0),this._stashPendingEdits(t,e)}async deleteAttachments(e,t){const{_layerWithAttachmentsEditing:r}=this;if(!r||!this.supportsUpdateAttachments||!t.length)return[];const i=await this._queueAttachmentsOperation(e,()=>r.deleteAttachments(this._createBaseGraphic(r,e),t));return this._ensureArray(i)}async deleteRowsByObjectId(e){const{_layerWithEditing:t}=this;if(!this.supportsDelete||!t)throw new a("store:delete-error","Delete is not supported.");const r=e.map(e=>this.getItemByObjectId(e)?.feature).filter(s),i=this._queueEditOperation(()=>t.applyEdits({deleteFeatures:r}));return e.forEach(e=>this.featureTitleMap.delete(e)),i}discardPendingEdits(e){if(e?.length)e.forEach(e=>this._discardPendingEdit(e));else{for(const[e,t]of this._pendingEditsCache){const r=this.getItemByObjectId(e);r&&(r.feature=t.originalFeature)}this._pendingEditsCache.clear(),this._clearOptionsAndViolations()}}itemHasInvalidPendingEdits(e,t){if(!this.hasInvalidPendingEdits)return!1;const r=this._layerWithContingentValues,i=this._pendingEditsCache.get(e);if(!r||!i)return!1;const s=this._getFeatureWithPendingEdits(e,i),n=this._contingentValuesManager;return t?!!n.getViolationForField(r,s,t):!!n.getAllViolations(r,s)}itemHasPendingEdits(e,t){const r=this._pendingEditsCache.get(e);return!!r&&(!t||r.changes.has(t))}async fetchItems(e){const{page:t}=e,{pageSize:r}=this,i=t*r,s=i+r,{layer:n,state:a}=this;return n&&"loaded"===a?this._query({layer:n,start:i,num:s,page:t,pageSize:r}):[]}async getAttachmentsByObjectId(e,t){const r=this.getItemByObjectId(e)?.attachments??[];if(!r.length&&t){return(await this._queryAttachments([e]))[e]??[]}return r}getFieldValueOptions(e){return this._contingentValuesManager.getFieldValueOptions(e)}async getFeatureTitle(e,r=!1){const{layer:i}=this,s=this.featureTitleMap.get(e),n=`${e}`;if(!i)return s||n;if(s&&!r)return s;if(!("getFeatureTitle"in i)||!i.getFeatureTitle)return n;const a=this.getItemByObjectId(e);let o=a?.feature;o||(o=new t({attributes:{[i.objectIdField]:e},origin:i.graphicOrigin}));const u=await i.getFeatureTitle(o,{fetchMissingFields:!0,removeHTML:!0});return u?(this.featureTitleMap.set(e,u),u):n}getItemByObjectId(e){for(const t of this.pageCache.values())for(const r of t)if(r.objectId===e)return r}getItemIndexByObjectId(e){const{pageCache:t,pageSize:r}=this,i=t.entries();let s=-1;for(const[n,a]of i)if(a.some((t,i)=>{const a=t.objectId===e;return a&&(s=n*r+i),a}),s>-1)break;return s}async load(){const{layer:e}=this;if(!this._loading&&!this._loaded&&e){this._reset(),this._loading=!0;try{await e.load(),e.parent&&f(e.parent)&&await e.parent.loadAll(),await e.when();const t=this.initialSize;this.initialSize=null,await this.refresh(t),this._loaded=!0,this._loading=!1}catch(t){throw this._reset(),this._loadError=!0,this._logError("store:load-error","An error occurred."),t}}}async query(e){const{state:t}=this;return this.supportsQuery&&"loaded"===t?this._query(e):[]}async refresh(e){this._clearCaches(),await this._syncCount(e),await this._syncObjectIdCache(),this._syncPendingEdits()}reset(){this._reset()}async savePendingEdits(){if(!this.hasPendingEdits)return;if(!this._canSavePendingEdits)return void this._logError("store:update-error","An error occurred. Unable to save pending edits.");const e=[];for(const[t]of this._pendingEditsCache){const r=this.getItemByObjectId(t);r?.feature&&e.push(r.feature)}await this._savePendingEdits(e),this._clearOptionsAndViolations()}async updateAttachment(e,t,r){const{_layerWithAttachmentsEditing:i}=this;if(!i||!this.supportsUpdateAttachments)return{};const s=await this._queueAttachmentsOperation(e,()=>i.updateAttachment(this._createBaseGraphic(i,e),t,r));return this._ensureArrayContent(s)}async updateItem(e){const t=this._ensureLayerAndUpdateSupport();if(this.hasContingentValues){const t=e.updates.some(e=>this.fieldsWithContingentValues?.has(e.fieldName)),r=this.itemHasPendingEdits(e.objectId);if(r||t){const t=this._layerWithContingentValues,i=this.getItemByObjectId(e.objectId)?.feature?.clone();if(i){const s=this._contingentValuesManager.getAllViolations(t,i);e.updates.forEach(({fieldName:e,value:r})=>{const s=t.getField(e);s&&(i.attributes[s.name]=r)});if(this._contingentValuesManager.validateContingencyConstraints(t,i).length||s.length||r)return this._stashPendingEdits(t,[e]),void this._contingentValuesManager.resetOptionsForLayer(t)}}}if(!this.autoSaveEnabled)return void this._stashPendingEdits(t,[e]);const{_sortedFieldNames:r}=this,i=e.updates.map(({fieldName:e})=>e);!(await this._update(t,e)).updateFeatureResults.find(e=>e.error)&&i.some(e=>r.includes(e))&&this._clearCaches()}async verifyFeaturesByObjectId(e){const{layer:t,state:r}=this;if(!t||"loaded"!==r)return[];const{objectIdField:i}=t,s=await this._queryFeaturesByObjectId(e);return e.map(e=>s.some(t=>{const r=t.getObjectId()??t.attributes[i];return e===r}))}_clearCaches(){this.pageCache.clear(),this._objectIdCache.removeAll()}_createBaseGraphic(e,r){const i=new t({attributes:{[e.objectIdField]:r}});return this._subtypeField&&null!=this._subtypeCode&&(i.attributes[this._subtypeField]=this._subtypeCode),i}_ensureArray(e){return Array.isArray(e)?e:[e]}_ensureArrayContent(e){return Array.isArray(e)?e[0]:e}_getObjectIdsForPage(e,t){const r=this._objectIdCache.toArray();return r.length>=e+t?r.slice(e,e+t):r.slice(e)}_logError(e,t){u.getLogger(this).error(e,t)}_logWarning(e,t,r=!1){r?u.getLogger(this).warnOnce(e,t):u.getLogger(this).warn(e,t)}_reset(){this._clearCaches(),this._pendingEditsCache.clear(),this.failures.removeAll(),this._attachmentsOperationQueue.removeAll(),this._editOperationQueue.removeAll(),this._queryOperationQueue.removeAll(),this.featureTitleMap.clear(),this._loading=!1,this._loaded=!1,this._loadError=!1,this._set("count",0)}async _syncCount(e){null==e?await this._queryCount().then(e=>this._set("count",e)):this._set("count",e)}async _syncObjectIdCache(){if(this.supportsPagination)return;const e=await this._queryObjectIds();this._objectIdCache.removeAll(),this._objectIdCache.addMany(e)}async _queryFeaturesByObjectId(e){const{layer:t}=this;if(!t||!this.supportsQuery)throw new a("store:query-error","Layer does not support query operation.");const{effectiveTimeExtent:r,effectiveWhere:i,orderByFields:s,supportsCacheHint:n,supportsOrderBy:o}=this,u=t.createQuery();u.where=i,u.timeExtent=r,u.returnGeometry=!1,u.objectIds=e.length?e:void 0,u.outFields=[t.objectIdField],o&&(u.orderByFields=s),n&&(u.cacheHint=!0);return(await t.queryFeatures(u)).features}_ensureLayerAndUpdateSupport(){const e=this._layerWithEditing;if(!this.supportsUpdate||!e)throw new a("store:update-error","Update is not supported.");return e}_stashPendingEdits(e,t){t.forEach(({objectId:t,updates:r})=>{const i=this.getItemByObjectId(t)?.feature;if(!i)throw new a("store:update-error","Feature with provided 'objectId' not found.");const s=i.clone(),n=l(this._pendingEditsCache,t,()=>({originalFeature:s,changes:new d}));r.forEach(({fieldName:t,value:r})=>{const s=e.getField(t);s?(n.changes.set(s.name,r),i.attributes[s.name]=r):this._logWarning("store:pending-edit-unknown-field","The provided field does not belong to this layer.")}),n.changes.size>0&&this._pendingEditsCache.set(t,n)})}_syncPendingEdits(){for(const[e,t]of this._pendingEditsCache){const r=this.getItemByObjectId(e)?.feature;if(r){const e=r.clone();for(const[i,s]of t.changes)r.attributes[i]=s;t.originalFeature=e}}}_getFeatureWithPendingEdits(e,t){let r=this.getItemByObjectId(e)?.feature;if(!r){r=t.originalFeature.clone();for(const[e,i]of t.changes)r.attributes[e]=i}return r}_discardPendingEdit({objectId:e,fieldName:t}){const r=this._pendingEditsCache.get(e);if(!r)return void this._logWarning("store:pending-edit-not-found","Could not find a pending edit with the given information");const i=this.getItemByObjectId(e);t?(i&&(i.feature.attributes[t]=r.originalFeature.attributes[t]),r.changes.delete(t),0===r.changes.size&&this._pendingEditsCache.delete(e)):(i&&(i.feature=r.originalFeature),this._pendingEditsCache.delete(e))}_clearOptionsAndViolations(){const{_layerWithContingentValues:e,_contingentValuesManager:t}=this;e&&(t.resetOptionsForLayer(e),t.resetViolationsForLayer(e))}async _update(e,r){const{objectId:i,updates:s}=r,n=this.getItemByObjectId(i)?.feature;if(!n)throw new a("store:update-error","Feature with provided 'objectId' not found.");const u=o(n.attributes);s.forEach(({fieldName:e,value:t})=>u[e]=t);const l=new t({attributes:u,sourceLayer:n.sourceLayer}),d=e.applyEdits({updateFeatures:[l]}).then(e=>{const{updateFeatureResults:t}=e,r=t.find(e=>!!e.error);if(r)throw r.error;return t.length&&(n.attributes=u,this.featureTitleMap.has(i)&&this.getFeatureTitle(i,!0)),e});return this._queueEditOperation(()=>d)}async _savePendingEdits(e){const{_layerWithEditing:t}=this;if(!this.supportsUpdate||!t)throw new a("store:update-error","Update is not supported.");const r=t.applyEdits({updateFeatures:e}).then(e=>{const{updateFeatureResults:t}=e,r=t.filter(e=>!!e.error);if(r.length)throw this.discardPendingEdits(),r[0].error;return e});return this._queueEditOperation(()=>r,!0)}_createFeatureStoreItems(e){const{attachments:t,features:r,layer:i,relatedRecords:s}=e,n=i.objectIdField;return r.map(e=>{const r=e.getObjectId()??e.attributes[n],a=[];e.layer||e.sourceLayer||(e.layer=i,e.sourceLayer=i);const o=this._pendingEditsCache.get(r);if(o){const t=e.clone(),r=o.changes;for(const[i,s]of r)e.attributes[i]=s;o.originalFeature=t}return s.forEach((e,t)=>{a.push({relationshipId:t,count:e[r]??0})}),{objectId:r,feature:e,attachments:t[r]??null,relatedRecords:a}})}async _query(e){const{page:t,refresh:r}=e;!0===r&&await this.refresh();const i=this.pageCache.get(t);if(i)return i;const s=await this._queryPage(e);return this.pageCache.set(t,s),s}_queryAttachments(e){const{_layerWithAttachments:t,effectiveWhere:r}=this;return t?e.some(e=>"number"!=typeof e)?Promise.reject(new a("invalid-object-id","Only numeric object ids are valid to query attachments")):t.queryAttachments(new b({objectIds:e,where:r,returnMetadata:!0})):Promise.resolve({})}async _queryCount(){const{_relatedLayerSupportsCacheHint:e,layer:t,relationshipConfig:r,supportsCacheHint:i}=this;if(!t)return 0;if(r&&this._canUseRelatedLayer){const{objectId:t,relatedLayer:i,relationshipId:s}=r;return(await i.queryRelatedFeaturesCount(new E({cacheHint:e,relationshipId:s,objectIds:[t]})))[t]??0}const{effectiveTimeExtent:s,effectiveWhere:n,filterGeometry:a,objectIds:o}=this,u=t.createQuery();return u.geometry=a,u.returnGeometry=!1,u.where=n,u.timeExtent=s,u.objectIds=o?.length?o:void 0,i&&(u.cacheHint=!0),t.queryFeatureCount(u)}async _queryFeatures(e){const{relationshipConfig:t}=this;if(t&&this._canUseRelatedLayer)return this._queryRelatedFeatures(e,t);const{_effectiveReturnM:r,_effectiveReturnZ:i,effectiveOutFields:s,effectiveTimeExtent:n,effectiveWhere:a,filterGeometry:o,objectIds:u,orderByFields:l,pageSize:d,returnGeometry:p,supportsCacheHint:h,supportsOrderBy:c,supportsPagination:y}=this,{layer:g,start:_}=e,f=u?.length,m=g.createQuery();m.returnGeometry=p,m.outFields=s,m.returnM=r,m.returnZ=i,y?(m.start=_,m.num=d,m.where=a,m.timeExtent=n,m.objectIds=f?u:void 0):m.objectIds=f?u:this._getObjectIdsForPage(_,d??0),c&&(m.orderByFields=l),o&&(m.geometry=o),h&&(m.cacheHint=!0);return(await g.queryFeatures(m)).features}_queryObjectIds(){const{effectiveTimeExtent:e,effectiveWhere:t,filterGeometry:r,layer:i,objectIds:s,orderByFields:n,supportsCacheHint:a,supportsOrderBy:o}=this;if(!i)return Promise.resolve([]);const u=i.createQuery();return u.geometry=r,u.outFields=[i.objectIdField],u.returnGeometry=!1,u.where=t,u.timeExtent=e,u.objectIds=s?.length?s:void 0,o&&(u.orderByFields=n),a&&(u.cacheHint=!0),i.queryObjectIds(u)}async _queryPage(e){const{layer:t}=e;return this._queueQueryOperation(async()=>{const r=await this._queryFeatures(e),i=r.map(e=>e.getObjectId()??e.attributes[t.objectIdField]),s=await this._queryAttachments(i),n=await this._queryRelatedCounts(i);return this._createFeatureStoreItems({layer:t,features:r,attachments:s,relatedRecords:n})||[]})}async _queryRelatedCounts(e){const{_layerWithRelationships:t,relationshipIds:r,supportsCacheHintQueryRelated:i}=this,s=new Map;return t&&e?.length&&r.length?(await Promise.allSettled(r.map(async r=>{const n=await t.queryRelatedFeaturesCount(new E({cacheHint:i,relationshipId:r,objectIds:e}));s.set(r,n)})),s):s}async _queryRelatedFeatures(e,t){const{_defaultOutFields:r,_effectiveReturnM:i,_effectiveReturnZ:s,orderByFields:n,pageSize:a,returnGeometry:o,supportsCacheHint:u}=this,{layer:l,start:d}=e,{objectId:p,relatedLayer:h,relationshipId:c}=t,y=l.createQuery(),g=new E({cacheHint:u,num:a,objectIds:[p],orderByFields:n,outFields:r,relationshipId:c,returnGeometry:o,returnM:i,returnZ:s,start:d,where:y.where??void 0}),_=await h.queryRelatedFeatures(g);return _[p]?.features||[]}_queueAttachmentsOperation(e,t){return this._attachmentsOperationQueue.push(t),t().then(async r=>{this._attachmentsOperationQueue.remove(t);const i=this._ensureArray(r),s=i.some(e=>e.error),n=this.getItemByObjectId(e);if(n&&(!s||i.length>1)){const t=await this._queryAttachments([e]);n.attachments=t[e]}return r}).catch(async r=>{this._logError("store:attachment-error","An error occurred.");const i={error:r,retry:()=>{this.failures.remove(i),this._queueAttachmentsOperation(e,t)},cancel:()=>this.failures.remove(i)};throw this.failures.add(i),this._attachmentsOperationQueue.remove(t),r})}_queueEditOperation(e,t=!1){return this._editOperationQueue.push(e),e().then(r=>(this._editOperationQueue.remove(e),t&&this._pendingEditsCache.clear(),r)).catch(t=>{this._logError("store:edit-error","An error occurred.");const r={error:t,retry:()=>{this.failures.remove(r),this._queueEditOperation(e)},cancel:()=>this.failures.remove(r)};throw this.failures.add(r),this._editOperationQueue.remove(e),t})}_queueQueryOperation(e){return this._queryOperationQueue.push(e),e().then(t=>this._queryOperationQueue.includes(e)?t:[]).catch(t=>{this._logError("store:query-error","An error occurred.");const r={error:t,retry:()=>{this.failures.remove(r),this._queueQueryOperation(e)},cancel:()=>this.failures.remove(r)};return this.failures.add(r),[]}).then(t=>(this._queryOperationQueue.remove(e),t))}};e([c()],j.prototype,"_attachmentsOperationQueue",void 0),e([c({readOnly:!0})],j.prototype,"_capabilities",null),e([c()],j.prototype,"_canSavePendingEdits",null),e([c()],j.prototype,"_contingentValuesManager",void 0),e([c()],j.prototype,"_defaultOutFields",void 0),e([c()],j.prototype,"_editOperationQueue",void 0),e([c()],j.prototype,"_effectiveReturnZ",null),e([c()],j.prototype,"_effectiveReturnM",null),e([c()],j.prototype,"featureTitleMap",void 0),e([c({readOnly:!0})],j.prototype,"_layerWithAttachments",null),e([c({readOnly:!0})],j.prototype,"_layerWithAttachmentsEditing",null),e([c()],j.prototype,"_layerWithContingentValues",null),e([c({readOnly:!0})],j.prototype,"_layerWithEditing",null),e([c({readOnly:!0})],j.prototype,"_layerWithRelationships",null),e([c()],j.prototype,"_loaded",void 0),e([c()],j.prototype,"_loadError",void 0),e([c()],j.prototype,"_loading",void 0),e([c()],j.prototype,"_objectIdCache",void 0),e([c()],j.prototype,"_pendingEditsCache",void 0),e([c()],j.prototype,"_pendingEditsAreInvalid",null),e([c()],j.prototype,"_queryOperationQueue",void 0),e([c({readOnly:!0})],j.prototype,"_relatedLayer",null),e([c({readOnly:!0})],j.prototype,"_relatedLayerCapabilities",null),e([c({readOnly:!0})],j.prototype,"_relatedLayerSupportsCacheHint",null),e([c()],j.prototype,"_relatedLayerSupportsQuery",null),e([c()],j.prototype,"_relatedLayerSupportsQueryRelated",null),e([c()],j.prototype,"_sortedFieldNames",null),e([c()],j.prototype,"_subtypeCode",null),e([c()],j.prototype,"_subtypeField",null),e([c()],j.prototype,"_canUseRelatedLayer",null),e([c()],j.prototype,"attachmentsEnabled",void 0),e([c()],j.prototype,"autoSaveEnabled",void 0),e([c()],j.prototype,"canAddRelatedFeature",null),e([c({readOnly:!0})],j.prototype,"count",void 0),e([c()],j.prototype,"editingEnabled",void 0),e([c()],j.prototype,"effectiveOutFields",null),e([c()],j.prototype,"effectiveTimeExtent",null),e([c()],j.prototype,"effectiveWhere",null),e([c({readOnly:!0})],j.prototype,"failures",void 0),e([c()],j.prototype,"fieldsWithContingentValues",null),e([c({types:g})],j.prototype,"filterGeometry",void 0),e([c()],j.prototype,"hasContingentValues",null),e([c()],j.prototype,"hasInvalidPendingEdits",null),e([c()],j.prototype,"hasPendingEdits",null),e([c()],j.prototype,"initialSize",void 0),e([c({readOnly:!0})],j.prototype,"isQuerying",null),e([c({readOnly:!0})],j.prototype,"isSyncing",null),e([c({readOnly:!0})],j.prototype,"isSyncingAttachmentEdits",null),e([c({readOnly:!0})],j.prototype,"isSyncingFeatureEdits",null),e([c({readOnly:!0})],j.prototype,"itemCache",null),e([c()],j.prototype,"layer",void 0),e([c()],j.prototype,"layerView",null),e([c()],j.prototype,"objectIds",void 0),e([c()],j.prototype,"orderByFields",null),e([c()],j.prototype,"outFields",void 0),e([c({readOnly:!0})],j.prototype,"pageCache",void 0),e([c()],j.prototype,"pageSize",void 0),e([c()],j.prototype,"pendingEditsCount",null),e([c()],j.prototype,"relationship",null),e([c()],j.prototype,"relationshipConfig",void 0),e([c()],j.prototype,"relationshipIds",null),e([c()],j.prototype,"relationshipInfos",null),e([c()],j.prototype,"relationships",null),e([c()],j.prototype,"relatedRecordsEnabled",void 0),e([c()],j.prototype,"returnGeometry",void 0),e([c()],j.prototype,"returnZ",void 0),e([c()],j.prototype,"returnM",void 0),e([c()],j.prototype,"sortOrders",void 0),e([c({readOnly:!0})],j.prototype,"state",null),e([c()],j.prototype,"supportsAdd",null),e([c()],j.prototype,"supportsAddAttachments",null),e([c()],j.prototype,"supportsAttachments",null),e([c()],j.prototype,"supportsCacheHint",null),e([c()],j.prototype,"supportsCacheHintQueryRelated",null),e([c()],j.prototype,"supportsDelete",null),e([c()],j.prototype,"supportsEditing",null),e([c()],j.prototype,"supportsM",null),e([c()],j.prototype,"supportsOrderBy",null),e([c()],j.prototype,"supportsPagination",null),e([c()],j.prototype,"supportsQuery",null),e([c()],j.prototype,"supportsQueryRelated",null),e([c()],j.prototype,"supportsResizeAttachments",null),e([c()],j.prototype,"supportsUpdate",null),e([c()],j.prototype,"supportsUpdateAttachments",null),e([c()],j.prototype,"supportsZ",null),e([c({type:v})],j.prototype,"timeExtent",void 0),e([c()],j.prototype,"timeZone",void 0),e([c()],j.prototype,"view",void 0),e([c()],j.prototype,"where",void 0),j=e([y("esri.widgets.FeatureTable.support.FeatureStore")],j);const q=j;export{q as default};