// All material copyright Esri, All Rights Reserved, unless otherwise specified. // See https://js.arcgis.com/4.30/esri/copyright.txt for details. //>>built define("../../../Graphic ../support/errorsupport ../support/FeatureSet ../support/IdSet ../support/shared ../../../rest/support/RelationshipQuery".split(" "),function(q,m,r,l,n,p){class t extends r{constructor(a){super(a);this.declaredClass="esri.arcade.featureset.sources.FeatureLayerRelated";this._findObjectId=-1;this._removeGeometry=this._requestStandardised=!1;this.featureObjectId=this._overrideFields=null;a.spatialReference&&(this.spatialReference=a.spatialReference);this._transparent=!0;this._maxProcessing= 1E3;this._layer=a.layer;this._wset=null;this.featureObjectId=this._findObjectId=a.objectId;this.relationship=a.relationship;this._relatedLayer=a.relatedLayer;void 0!==a.outFields&&(this._overrideFields=a.outFields);void 0!==a.includeGeometry&&(this._removeGeometry=!1===a.includeGeometry)}_maxQueryRate(){return n.defaultMaxRecords}end(){return this._layer}optimisePagingFeatureQueries(){}async loadImpl(){await Promise.all([this._layer.load(),this._relatedLayer?.load()]);this._initialiseFeatureSet(); return this}nativeCapabilities(){return this._relatedLayer.nativeCapabilities()}_initialiseFeatureSet(){null==this.spatialReference&&(this.spatialReference=this._layer.spatialReference);this.geometryType=this._relatedLayer.geometryType;this.fields=this._relatedLayer.fields.slice(0);this.hasZ=this._relatedLayer.hasZ;this.hasM=this._relatedLayer.hasM;if(null!==this._overrideFields)if(1===this._overrideFields.length&&"*"===this._overrideFields[0])this._overrideFields=null;else{var a=[];const d=[];for(const c of this.fields)if("oid"=== c.type)a.push(c),d.push(c.name);else for(const b of this._overrideFields)if(b.toLowerCase()===c.name.toLowerCase()){a.push(c);d.push(c.name);break}this.fields=a;this._overrideFields=d}if(a=this._layer.nativeCapabilities())this._databaseType=a.databaseType,this._requestStandardised=a.requestStandardised;this.objectIdField=this._relatedLayer.objectIdField;this.globalIdField=this._relatedLayer.globalIdField;this.hasM=this._relatedLayer.supportsM;this.hasZ=this._relatedLayer.supportsZ;this.typeIdField= this._relatedLayer.typeIdField;this.types=this._relatedLayer.types;this.subtypeField=this._relatedLayer.subtypeField;this.subtypes=this._relatedLayer.subtypes}async databaseType(){await this._relatedLayer.databaseType();return this._databaseType=this._relatedLayer._databaseType}isTable(){return this._relatedLayer.isTable()}_isInFeatureSet(){return n.IdState.InFeatureSet}_candidateIdTransform(a){return a}async _getSet(a){return null===this._wset?(await this._ensureLoaded(),this._wset=a=await this._getFilteredSet("", null,null,null,a)):this._wset}_changeFeature(a){const d={};for(const c of this.fields)d[c.name]=a.attributes[c.name];return new q({geometry:!0===this._removeGeometry?null:a.geometry,attributes:d})}async _getFilteredSet(a,d,c,b,f){await this.databaseType();if(this.isTable()&&d&&null!==a&&""!==a)return new l([],[],!0,null);var e=this._layer.nativeCapabilities();if(!1===e.canQueryRelated)return new l([],[],!0,null);if(e.capabilities?.queryRelated.supportsPagination)return this._getFilteredSetUsingPaging(a, d,c,b,f);var g="";let h=!1;null!==b&&!0===e.capabilities?.queryRelated.supportsOrderBy&&(g=b.constructClause(),h=!0);b=new p;b.objectIds=[this._findObjectId];var k=null!==this._overrideFields?this._overrideFields:this._fieldsIncludingObjectId(this._relatedLayer.fields?this._relatedLayer.fields.map(u=>u.name):["*"]);b.outFields=k;b.relationshipId=this.relationship.id;b.where="1\x3d1";k=!0;!0===this._removeGeometry&&(k=!1);b.returnGeometry=k;this._requestStandardised&&(b.sqlFormat="standard");b.outSpatialReference= this.spatialReference;b.orderByFields=""!==g?g.split(","):null;e=await e.source.queryRelatedFeatures(b);this._checkCancelled(f);e=e[this._findObjectId]?e[this._findObjectId].features:[];f=[];for(g=0;gk.name):["*"]);d=new l(a||c?["GETPAGES"]:[],a||c?[]:["GETPAGES"],g,{outFields:h.join(","),resultRecordCount:b,resultOffset:0,objectIds:[this._findObjectId],where:"1\x3d1",orderByFields:e,returnGeometry:d,returnIdsOnly:"false",internal:{set:[],lastRetrieved:0,lastPage:0,fullyResolved:!1}});await this._expandPagedSet(d, b,0,0,f);return d}_expandPagedSet(a,d,c,b,f){return this._expandPagedSetFeatureSet(a,d,c,b,f)}_clonePageDefinition(a){return null===a?null:!0!==a.groupbypage?{groupbypage:!1,outFields:a.outFields,resultRecordCount:a.resultRecordCount,resultOffset:a.resultOffset,where:a.where,objectIds:a.objectIds,orderByFields:a.orderByFields,returnGeometry:a.returnGeometry,returnIdsOnly:a.returnIdsOnly,internal:a.internal}:{groupbypage:!0,outFields:a.outFields,resultRecordCount:a.resultRecordCount,useOIDpagination:a.useOIDpagination, generatedOid:a.generatedOid,groupByFieldsForStatistics:a.groupByFieldsForStatistics,resultOffset:a.resultOffset,outStatistics:a.outStatistics,geometry:a.geometry,where:a.where,objectIds:a.objectIds,orderByFields:a.orderByFields,returnGeometry:a.returnGeometry,returnIdsOnly:a.returnIdsOnly,internal:a.internal}}async _getPhysicalPage(a,d,c){d=a.pagesDefinition.internal.lastRetrieved;var b=a.pagesDefinition.internal.lastPage,f=this._layer.nativeCapabilities();const e=new p;!0===this._requestStandardised&& (e.sqlFormat="standard");e.relationshipId=this.relationship.id;e.objectIds=a.pagesDefinition.objectIds;e.resultOffset=a.pagesDefinition.internal.lastPage;e.resultRecordCount=a.pagesDefinition.resultRecordCount;e.outFields=a.pagesDefinition.outFields.split(",");e.where=a.pagesDefinition.where;e.orderByFields=""!==a.pagesDefinition.orderByFields?a.pagesDefinition.orderByFields.split(","):null;e.returnGeometry=a.pagesDefinition.returnGeometry;e.outSpatialReference=this.spatialReference;f=await f.source.queryRelatedFeatures(e); this._checkCancelled(c);if(a.pagesDefinition.internal.lastPage!==b)return 0;c=f[this._findObjectId]?f[this._findObjectId].features:[];for(b=0;bc))break;if(b>=c&&0===f.length)break}if(0===f.length)return"success";throw new m.FeatureSetError(m.FeatureSetErrorCodes.MissingFeatures);}async _refineSetBlock(a,d,c){return a}async _stat(a,d,c,b,f,e,g){return{calculated:!1}}get gdbVersion(){return this._relatedLayer.gdbVersion}async _canDoAggregates(a,d,c,b,f){return!1}relationshipMetaData(){return this._relatedLayer.relationshipMetaData()}serviceUrl(){return this._relatedLayer.serviceUrl()}queryAttachments(a, d,c,b,f){return this._relatedLayer.queryAttachments(a,d,c,b,f)}getFeatureByObjectId(a,d){return this._relatedLayer.getFeatureByObjectId(a,d)}getOwningSystemUrl(){return this._relatedLayer.getOwningSystemUrl()}getIdentityUser(){return this._relatedLayer.getIdentityUser()}getDataSourceFeatureSet(){return this._relatedLayer}get preferredTimeZone(){return this._relatedLayer?.preferredTimeZone??null}get dateFieldsTimeZone(){return this._relatedLayer?.dateFieldsTimeZone??null}get datesInUnknownTimezone(){return this._relatedLayer?.datesInUnknownTimezone}get editFieldsInfo(){return this._relatedLayer?.editFieldsInfo?? null}get timeInfo(){return this._relatedLayer?.timeInfo??null}async getFeatureSetInfo(){return this.fsetInfo??this._layer.featureSetInfo}}return t});