@arcgis/core 4.33.0-next.20250509 → 4.33.0-next.20250511

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.
Files changed (67) hide show
  1. package/applications/SceneViewer/sceneViewerUtils.js +1 -1
  2. package/assets/esri/core/workers/RemoteClient.js +1 -1
  3. package/assets/esri/core/workers/chunks/06eb4832b6c86744e52e.js +1 -0
  4. package/assets/esri/core/workers/chunks/170c346cf5a18adb25b0.js +1 -0
  5. package/assets/esri/core/workers/chunks/253bcc3cc7bc4c2dc6ea.js +1 -0
  6. package/assets/esri/core/workers/chunks/{d874d24568b1acedebc4.js → 297d2c0a9d3f1e978318.js} +1 -1
  7. package/assets/esri/core/workers/chunks/4bd5cbf6e0be2fc7e84d.js +1 -0
  8. package/assets/esri/core/workers/chunks/{b1035bf4a016b1199236.js → 83d6a1b3db7d364d156b.js} +1 -1
  9. package/assets/esri/core/workers/chunks/{7ed9a9c33a08ebba5570.js → 92cbe9af8a6c061bfb57.js} +1 -1
  10. package/assets/esri/core/workers/chunks/a1d697e2be1e892a666a.js +1 -0
  11. package/assets/esri/core/workers/chunks/{61c74a733718d667b071.js → d551f70560a2b1ef5696.js} +1 -1
  12. package/assets/esri/core/workers/chunks/f6a1fec33b0d81acce61.js +1 -0
  13. package/core/has.js +1 -1
  14. package/core/sql/StandardizedFunctions.js +1 -1
  15. package/core/sql/WhereGrammar.js +1 -1
  16. package/geometry/support/meshUtils/External.js +1 -1
  17. package/geometry/support/meshUtils/loadExternal.js +1 -1
  18. package/interfaces.d.ts +340 -14
  19. package/layers/SceneLayer.js +1 -1
  20. package/layers/VideoLayer.js +1 -1
  21. package/layers/graphics/sources/FeatureLayerSource.js +1 -1
  22. package/layers/graphics/sources/support/uploadAssets.js +1 -1
  23. package/layers/video/VideoController.js +1 -1
  24. package/package.json +1 -1
  25. package/rest/knowledgeGraph/wasmInterface/wasmToUpdateResponseFactories.js +1 -1
  26. package/rest/support/meshFeatureSet.js +1 -1
  27. package/smartMapping/renderers/size.js +1 -1
  28. package/smartMapping/renderers/support/spikeUtils.js +1 -1
  29. package/support/revision.js +1 -1
  30. package/views/2d/layers/features/layerAdapters/FeatureLayerAdapter.js +1 -1
  31. package/views/2d/layers/features/layerAdapters/OrientedImageryLayerAdapter.js +1 -1
  32. package/views/2d/layers/features/layerAdapters/SubtypeGroupLayerAdapter.js +1 -1
  33. package/views/2d/layers/features/layerAdapters/featureServiceUtils.js +1 -1
  34. package/views/2d/layers/features/sources/FeatureSource.js +1 -1
  35. package/views/3d/layers/DynamicLayerView3D.js +1 -1
  36. package/views/3d/layers/I3SMeshView3D.js +1 -1
  37. package/views/3d/layers/SceneLayerGraphicsView3D.js +1 -1
  38. package/views/3d/layers/SceneLayerView3D.js +1 -1
  39. package/views/3d/layers/graphics/Deconflictor.js +1 -1
  40. package/views/3d/layers/graphics/GraphicsDeconflictor.js +1 -1
  41. package/views/3d/layers/graphics/LabelDeconflictor.js +1 -1
  42. package/views/3d/layers/i3s/I3SQueryEngine.js +1 -1
  43. package/views/3d/layers/i3s/I3SQueryFeatureAdapter.js +1 -1
  44. package/views/3d/layers/i3s/I3SQueryResultGeometry.js +5 -0
  45. package/views/3d/webgl/ManagedFBOResource.js +1 -1
  46. package/views/3d/webgl-engine/lib/GPUPointOcclusionQuery.js +1 -1
  47. package/views/3d/webgl-engine/materials/HUDMaterial.js +1 -1
  48. package/views/interactive/keybindings.js +1 -1
  49. package/webdoc/IPSInfo.js +1 -1
  50. package/webdoc/ips/AppleIPSProperties.d.ts +4 -0
  51. package/webdoc/ips/AppleIPSProperties.js +5 -0
  52. package/webdoc/ips/Configuration.d.ts +4 -0
  53. package/webdoc/ips/Configuration.js +5 -0
  54. package/webdoc/ips/GNSSProperties.d.ts +4 -0
  55. package/webdoc/ips/GNSSProperties.js +5 -0
  56. package/webdoc/ips/PathSnappingProperties.d.ts +4 -0
  57. package/webdoc/ips/PathSnappingProperties.js +5 -0
  58. package/webdoc/ips/SmoothingProperties.d.ts +4 -0
  59. package/webdoc/ips/SmoothingProperties.js +5 -0
  60. package/widgets/Legend/support/sizeRampUtils.js +1 -1
  61. package/widgets/support/Selector2D/SelectionOperation.js +1 -1
  62. package/assets/esri/core/workers/chunks/46104db7f77952bb6c12.js +0 -1
  63. package/assets/esri/core/workers/chunks/47bbfc10c2a3b9e4bdd6.js +0 -1
  64. package/assets/esri/core/workers/chunks/49f0e53b3c9ba8451442.js +0 -1
  65. package/assets/esri/core/workers/chunks/5371df31553626528c69.js +0 -1
  66. package/assets/esri/core/workers/chunks/ad9bcd9dae45cdf90cbb.js +0 -1
  67. package/assets/esri/core/workers/chunks/c28d4717ed588c0d8bf1.js +0 -1
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../config.js";import r from"../../../request.js";import{isSome as s,remove as a}from"../../../core/arrayUtils.js";import i from"../../../core/Error.js";import has from"../../../core/has.js";import{JSONMap as n}from"../../../core/jsonMap.js";import o from"../../../core/Loadable.js";import u from"../../../core/Logger.js";import{setDeepValue as l}from"../../../core/object.js";import{debounce as c,after as d,throwIfAbortError as p}from"../../../core/promiseUtils.js";import{watch as y}from"../../../core/reactiveUtils.js";import{join as h}from"../../../core/urlUtils.js";import{generateBracedUUID as m}from"../../../core/uuid.js";import{property as f}from"../../../core/accessorSupport/decorators/property.js";import{subclass as g}from"../../../core/accessorSupport/decorators/subclass.js";import w from"../../../geometry/Extent.js";import q from"../../../geometry/SpatialReference.js";import S from"../../../geometry/support/MeshGeoreferencedVertexSpace.js";import{isRelativeVertexSpace as E}from"../../../geometry/support/meshVertexSpaceUtils.js";import{isOriginalExternal as O}from"../../../geometry/support/meshUtils/External.js";import{createFeatureEditResult as _,getFeatureJSON as b,getFeatureIds as R,getAttachmentEditsJSON as A,isProtectedOrPrivateVersionError as F,unpackEditResultData as I,createEditedFeatures as x}from"../applyEditsUtils.js";import{createDrawingInfo as j}from"./support/clientSideDefaults.js";import v from"./support/QueryTask.js";import{isHostedAgolService as T}from"../../support/arcgisLayerUrl.js";import{ensureLayerCredential as M}from"../../support/featureLayerUtils.js";import{getAssetMapTable as N}from"../../support/infoFor3D.js";import{executeQueryJSON as U}from"../../../rest/query/executeQueryJSON.js";import{unapplyEditsZUnitScaling as J}from"../../../rest/query/operations/editsZScale.js";import D from"../../../rest/support/Query.js";import{T as k}from"../../../chunks/TimeExtent.js";import{isSafeToEditVersion as C,isVersionInEditSession as L,isHistoricVersion as Q,currentSessionId as P}from"../../../versionManagement/support/versionManagementUtils.js";const V=new n({originalAndCurrentFeatures:"original-and-current-features",none:"none"}),$=new n({Started:"published",Publishing:"publishing",Stopped:"unavailable"});let G=class extends o{constructor(e){super(e),this.type="feature-layer",this.supportedSourceTypes=new Set(["Feature Layer","Oriented Imagery Layer","Table","Catalog Layer"]),this.refresh=c((async()=>{await this.load();const e=this.sourceJSON.editingInfo?.lastEditDate;if(null==e)return{dataChanged:!0,updates:{}};try{await this._fetchService(null)}catch{return{dataChanged:!0,updates:{}}}const t=e!==this.sourceJSON.editingInfo?.lastEditDate;return{dataChanged:t,updates:t?{editingInfo:this.sourceJSON.editingInfo,extent:this.sourceJSON.extent}:null}})),this._ongoingAssetUploads=new Map}load(e){const t=this.layer.sourceJSON,r=this._fetchService(t,{...e}).then((()=>this.layer.setUserPrivileges(this.sourceJSON.serviceItemId,e))).then((()=>this._ensureLatestMetadata(e)));return this.addResolvingPromise(r),Promise.resolve(this)}initialize(){this.addHandles([y((()=>{const e=this.layer;return e&&"lastEditsEventDate"in e?e.lastEditsEventDate:null}),(e=>this._handleLastEditsEventChange(e)))])}destroy(){this._removeEditInterceptor()}get queryTask(){const{capabilities:e,parsedUrl:t,gdbVersion:r,spatialReference:s,fieldsIndex:a,uniqueIdFields:i}=this.layer,n="infoFor3D"in this.layer?this.layer.infoFor3D:null,o="dynamicDataSource"in this.layer?this.layer.dynamicDataSource:null,u=has("featurelayer-pbf")&&e?.query.supportsFormatPBF&&null==n;return new v({dynamicDataSource:o,fieldsIndex:a,gdbVersion:r,infoFor3D:n,pbfSupported:u,queryAttachmentsSupported:e?.operations?.supportsQueryAttachments??!1,sourceSpatialReference:s,uniqueIdFields:i,url:t.path})}async addAttachment(e,t){await this.load();const{layer:s}=this;await M(s,"editing");const a=e.attributes[s.objectIdField],i=s.parsedUrl.path+"/"+a+"/addAttachment",n=this._getLayerRequestOptions(),o=this._getFormDataForAttachment(t,n.query);try{const e=await r(i,{body:o});return _(e.data.addAttachmentResult)}catch(u){throw this._createAttachmentErrorResult(a,u)}}async updateAttachment(e,t,s){await this.load();const{layer:a}=this;await M(a,"editing");const i=e.attributes[a.objectIdField],n=a.parsedUrl.path+"/"+i+"/updateAttachment",o=this._getLayerRequestOptions({query:{attachmentId:t}}),u=this._getFormDataForAttachment(s,o.query);try{const e=await r(n,{body:u});return _(e.data.updateAttachmentResult)}catch(l){throw this._createAttachmentErrorResult(i,l)}}async applyEdits(e,t){await this.load();const{layer:a}=this;await M(a,"editing");const n="infoFor3D"in a?a.infoFor3D:null,o=null!=n,u=o||(t?.globalIdUsed??!1),l=o?await this._uploadMeshesAndGetAssetMapEditsJSON(e):null,c=e.addFeatures?.map((e=>b(this.layer,e,n)))??[],d=(await Promise.all(c)).filter(s),p=e.updateFeatures?.map((e=>b(this.layer,e,n)))??[],y=(await Promise.all(p)).filter(s),h=R(this.layer,e.deleteFeatures,u);J(d,y,a.spatialReference);const m=await A(this.layer,e),f=a.capabilities.editing.supportsAsyncApplyEdits&&o,g=t?.gdbVersion||a.gdbVersion,w={gdbVersion:g,rollbackOnFailure:t?.rollbackOnFailureEnabled,useGlobalIds:u,returnEditMoment:t?.returnEditMoment,usePreviousEditMoment:t?.usePreviousEditMoment,async:f};await C(this.layer.url,g,!0);const q=L(this.layer.url,g||null);if(await Q(a.url,g,a.historicMoment))throw new i("feature-layer-source:historic-version","Editing a historic version is not allowed");t?.returnServiceEditsOption?(w.edits=JSON.stringify([{id:a.layerId,adds:d.length?d:null,updates:y.length?y:null,deletes:h.length?h:null,attachments:m,assetMaps:l}]),w.returnServiceEditsOption=V.toJSON(t?.returnServiceEditsOption),w.returnServiceEditsInSourceSR=t?.returnServiceEditsInSourceSR):(w.adds=d.length?JSON.stringify(d):null,w.updates=y.length?JSON.stringify(y):null,w.deletes=h.length?u?JSON.stringify(h):h.join(","):null,w.attachments=m&&JSON.stringify(m),w.assetMaps=null!=l?JSON.stringify(l):void 0);const S=this._getLayerRequestOptions({method:"post",query:w});q&&(S.authMode="immediate",S.query.returnEditMoment=!0,S.query.sessionId=P);const E=t?.returnServiceEditsOption?a.url:a.parsedUrl.path;let O;try{O=f?await this._asyncApplyEdits(E+"/applyEdits",S):await r(E+"/applyEdits",S)}catch(_){if(!F(_))throw _;S.authMode="immediate",O=f?await this._asyncApplyEdits(E+"/applyEdits",S):await r(E+"/applyEdits",S)}return this._createEditsResult(O)}async deleteAttachments(e,t){await this.load();const{layer:s}=this;await M(s,"editing");const a=e.attributes[s.objectIdField],i=s.parsedUrl.path+"/"+a+"/deleteAttachments";try{return(await r(i,this._getLayerRequestOptions({query:{attachmentIds:t.join(",")},method:"post"}))).data.deleteAttachmentResults.map(_)}catch(n){throw this._createAttachmentErrorResult(a,n)}}fetchRecomputedExtents(e={}){const t=e.signal;return this.load({signal:t}).then((async()=>{const t=this._getLayerRequestOptions({...e,query:{returnUpdates:!0}}),{layerId:s,url:a}=this.layer,{data:i}=await r(`${a}/${s}`,t),{id:n,extent:o,fullExtent:u,timeExtent:l}=i,c=o||u;return{id:n,fullExtent:c&&w.fromJSON(c),timeExtent:l&&k.fromJSON({start:l[0],end:l[1]})}}))}async queryAttachments(e,t={}){await this.load();const r=this._getLayerRequestOptions(t);return this.queryTask.executeAttachmentQuery(e,r)}async queryFeatures(e,t){await this.load();const r=await this.queryTask.execute(e,{...t,query:this._createRequestQueryOptions(t)});if(e.outStatistics?.length&&r.features.length){const t=new Map;if(r.features.forEach((r=>{const s=r.attributes;e.outStatistics?.forEach((({outStatisticFieldName:e})=>{if(e){const r=e.toLowerCase();r&&r in s&&e!==r&&(s[e]=s[r],delete s[r],t.set(r,e))}}))})),null!=r.fields)for(const e of r.fields){const r=t.get(e.name.toLowerCase());null!=r&&(e.name=r)}}return r}async queryFeaturesJSON(e,t){return await this.load(),this.queryTask.executeJSON(e,{...t,query:this._createRequestQueryOptions(t)})}async queryObjectIds(e,t){return await this.load(),this.queryTask.executeForIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryFeatureCount(e,t){return await this.load(),this.queryTask.executeForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryExtent(e,t){return await this.load(),this.queryTask.executeForExtent(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeatures(e,t){return await this.load(),this.queryTask.executeRelationshipQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeaturesCount(e,t){return await this.load(),this.queryTask.executeRelationshipQueryForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopFeatures(e,t){return await this.load(),this.queryTask.executeTopFeaturesQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryAttributeBins(e,t){return await this.load(),this.queryTask.executeAttributeBinsQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopObjectIds(e,t){return await this.load(),this.queryTask.executeForTopIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopExtents(e,t){return await this.load(),this.queryTask.executeForTopExtents(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopCount(e,t){return await this.load(),this.queryTask.executeForTopCount(e,{...t,query:this._createRequestQueryOptions(t)})}async fetchPublishingStatus(){if(!T(this.layer.url))return"unavailable";const e=h(this.layer.url,"status"),t=await r(e,{query:{f:"json"}});return $.fromJSON(t.data.status)}async uploadAssets(e,t){const{uploadAssets:r}=await import("./support/uploadAssets.js");return r(e,{layer:this.layer,ongoingUploads:this._ongoingAssetUploads},t)}_handleLastEditsEventChange(e){const t=this.layer;if(null==e||!("capabilities"in t)||!("effectiveCapabilities"in t))return;if(!(!t.capabilities?.operations?.supportsEditing&&t.effectiveCapabilities?.operations?.supportsEditing))return;const r=t.url;if(null==r)return;"layerId"in t&&h(r,t.layerId.toString());this._getOrCreateEditInterceptor(r).before=t=>{const r=t.requestOptions.method??"auto";if("auto"===r||"head"===r){const r=t.requestOptions.query??{};r._ts=e.getTime(),t.requestOptions.query=r}}}_getOrCreateEditInterceptor(e){return null==this._editInterceptor&&(this._editInterceptor={urls:e},t.request.internalInterceptors.push(this._editInterceptor)),this._editInterceptor}_removeEditInterceptor(){null!=this._editInterceptor&&(a(t.request.internalInterceptors,this._editInterceptor),this._editInterceptor=null)}async _asyncApplyEdits(e,t){const s=(await r(e,t)).data.statusUrl;for(;;){const e=(await r(s,{query:{f:"json"},responseType:"json"})).data;switch(e.status){case"Completed":return r(e.resultUrl,{query:{f:"json"},responseType:"json"});case"CompletedWithErrors":throw new i("async-applyEdits-failed","asynchronous applyEdits call failed.");case"Failed ImportChanges":case"InProgress":case"Pending":case"ExportAttachments":case"ExportChanges":case"ExportingData":case"ExportingSnapshot":case"ImportAttachments":case"ProvisioningReplica":case"UnRegisteringReplica":break;default:throw new i("async-applyEdits-failed","asynchronous applyEdits call failed (undefined response status)")}await d(H)}}_createRequestQueryOptions(e){const t={...this.layer.customParameters,token:this.layer.apiKey,...e?.query};return this.layer.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),t}async _fetchService(e,t){if(!e){const s={};has("featurelayer-advanced-symbols")&&(s.returnAdvancedSymbols=!0),t?.cacheBust&&(s._ts=Date.now());const{data:a}=await r(this.layer.parsedUrl.path,this._getLayerRequestOptions({query:s,signal:t?.signal}));e=a}this.sourceJSON=await this._patchServiceJSON(e,t?.signal);const s=e.type;if(!this.supportedSourceTypes.has(s))throw new i("feature-layer-source:unsupported-type",`Source type "${s}" is not supported`)}async _patchServiceJSON(e,t){if("Table"!==e.type&&e.geometryType&&!e?.drawingInfo?.renderer&&!e.defaultSymbol){const t=j(e.geometryType).renderer;l("drawingInfo.renderer",t,e)}if("esriGeometryMultiPatch"===e.geometryType&&e.infoFor3D&&(e.geometryType="mesh"),null==e.extent)try{const{data:s}=await r(this.layer.url,this._getLayerRequestOptions({signal:t}));s.spatialReference&&(e.extent={xmin:0,ymin:0,xmax:0,ymax:0,spatialReference:s.spatialReference})}catch(s){p(s)}return e}async _ensureLatestMetadata(e){if(this.layer.userHasUpdateItemPrivileges&&this.sourceJSON.cacheMaxAge>0)return this._fetchService(null,{...e,cacheBust:!0})}async _uploadMeshesAndGetAssetMapEditsJSON(e){const{addAssetFeatures:t}=e;if(!t?.length)return null;if(await this._areAllAssetsAlreadyMapped(t))return null;const r=e.addFeatures.filter((e=>e.geometry));if(t.length!==r.length+e.updateFeatures.length)throw new i("feature-layer-source:unsupported-mesh-edits","Mixing attribute only edits with mesh geometry edits is not currently supported");const s=new Array,a=new Map;for(const i of t){const{geometry:e}=i,{vertexSpace:t}=e;if(E(t))s.push(e);else{const t=e.origin,{convertMeshVertexSpace:r}=await import("../../../geometry/support/meshUtils/convertMeshVertexSpace.js"),n=await r(e,new S({origin:[t.x,t.y,t.z??0]}));a.set(n,e),i.geometry=n,s.push(n)}}await this.uploadAssets(s);for(const[i,n]of a)n.addExternalSources(i.metadata.externalSources.items);return{adds:this._getAssetMapEditsJSON(t),updates:[],deletes:[]}}_getAssetMapEditsJSON(e){const t=new Array,r=this.layer.globalIdField,s=this.layer.parsedUrl;for(const a of e){const e=a.geometry,{metadata:i}=e,n=i.getExternalSourcesOnService(s),o=a.getAttribute(r);if(0===n.length){u.getLogger(this).error(`Skipping feature ${o}. The mesh it is associated with has not been uploaded to the service and cannot be mapped to it.`);continue}const{source:l}=n.find(O)??n[0];for(const r of l)1===r.parts.length?t.push({globalId:m(),parentGlobalId:o,assetName:r.assetName,assetHash:r.parts[0].partHash,flags:[]}):u.getLogger(this).error(`Skipping asset ${r.assetName}. It does not have exactly one part, so we cannot map it to a feature.`)}return t}_createEditsResult(e){const t=e.data,{layerId:r}=this.layer,s=[];let a=null;if(Array.isArray(t))for(const n of t)s.push({id:n.id,editedFeatures:n.editedFeatures}),n.id===r&&(a={addResults:n.addResults??[],updateResults:n.updateResults??[],deleteResults:n.deleteResults??[],attachments:n.attachments,editMoment:n.editMoment});else a=t;const i=I(a);if(s.length>0){i.editedFeatureResults=[];for(const e of s){const{editedFeatures:t}=e,r=t?.spatialReference?new q(t.spatialReference):null;i.editedFeatureResults.push({layerId:e.id,editedFeatures:x(t,r)})}}return i}_createAttachmentErrorResult(e,t){const r=t.details.messages?.[0]||t.message,s=t.details.httpStatus||t.details.messageCode;return{objectId:e,globalId:null,error:new i("feature-layer-source:attachment-failure",r,{code:s})}}_getFormDataForAttachment(e,t){const r=e instanceof FormData?e:e&&e.elements?new FormData(e):null;if(r)for(const s in t){const e=t[s];null!=e&&(r.set?r.set(s,e):r.append(s,e))}return r}_getLayerRequestOptions(e={}){const{layer:t,layer:{parsedUrl:r,gdbVersion:s}}=this;return{...e,query:{gdbVersion:s,layer:"dynamicDataSource"in t&&t.dynamicDataSource?JSON.stringify({source:t.dynamicDataSource}):void 0,...r.query,f:"json",...this._createRequestQueryOptions(e)},responseType:"json"}}async _areAllAssetsAlreadyMapped(e){const{layer:t}=this,{globalIdField:r,parsedUrl:a}=t,i="infoFor3D"in t?t.infoFor3D:null;if(null==i||null==r)return!1;const n=N(i);if(null==n)return!1;const o=h(a.path,`../${n.id}`),u=new Array;for(const s of e){if(!(s.geometry.metadata.getExternalSourcesOnService(a).length>0))return!1;u.push(s)}const l=u.map((e=>e.getAttribute(r))).filter(s);if(0===l.length)return!1;const{assetMapFieldRoles:{parentGlobalId:c,assetHash:d}}=i,p=new D({where:`${c} IN (${l.map((e=>`'${e}'`))})`,outFields:[d,c],returnGeometry:!1}),y=await U(o,p),{features:m}=y;return 0!==m.length&&!u.some((e=>{const t=e.getAttribute(r);if(!t)return!0;const{metadata:s}=e.geometry,i=m.filter((e=>e.getAttribute(c)===t));if(0===i.length)return!0;const n=i.map((e=>e.getAttribute(d)));return s.getExternalSourcesOnService(a).flatMap((({source:e})=>e.flatMap((e=>e.parts.map((e=>e.partHash)))))).some((e=>n.every((t=>e!==t))))}))}};e([f()],G.prototype,"type",void 0),e([f({constructOnly:!0})],G.prototype,"layer",void 0),e([f({constructOnly:!0})],G.prototype,"supportedSourceTypes",void 0),e([f({readOnly:!0})],G.prototype,"queryTask",null),G=e([g("esri.layers.graphics.sources.FeatureLayerSource")],G);const H=1e3;export{G as default};
5
+ import{_ as e}from"../../../chunks/tslib.es6.js";import t from"../../../config.js";import s from"../../../request.js";import{isSome as r,remove as a}from"../../../core/arrayUtils.js";import i from"../../../core/Error.js";import has from"../../../core/has.js";import{JSONMap as n}from"../../../core/jsonMap.js";import o from"../../../core/Loadable.js";import u from"../../../core/Logger.js";import{setDeepValue as l}from"../../../core/object.js";import{debounce as c,after as d,throwIfAbortError as p}from"../../../core/promiseUtils.js";import{watch as y}from"../../../core/reactiveUtils.js";import{join as h}from"../../../core/urlUtils.js";import{generateBracedUUID as m}from"../../../core/uuid.js";import{property as f}from"../../../core/accessorSupport/decorators/property.js";import{subclass as g}from"../../../core/accessorSupport/decorators/subclass.js";import w from"../../../geometry/Extent.js";import q from"../../../geometry/SpatialReference.js";import S from"../../../geometry/support/MeshGeoreferencedVertexSpace.js";import{isRelativeVertexSpace as E}from"../../../geometry/support/meshVertexSpaceUtils.js";import{isOriginalExternal as O}from"../../../geometry/support/meshUtils/External.js";import{createFeatureEditResult as _,getFeatureJSON as b,getFeatureIds as R,getAttachmentEditsJSON as A,isProtectedOrPrivateVersionError as F,unpackEditResultData as I,createEditedFeatures as x}from"../applyEditsUtils.js";import{createDrawingInfo as j}from"./support/clientSideDefaults.js";import v from"./support/QueryTask.js";import{isHostedAgolService as T}from"../../support/arcgisLayerUrl.js";import{ensureLayerCredential as M}from"../../support/featureLayerUtils.js";import{getAssetMapTable as N}from"../../support/infoFor3D.js";import{executeQueryJSON as U}from"../../../rest/query/executeQueryJSON.js";import{unapplyEditsZUnitScaling as J}from"../../../rest/query/operations/editsZScale.js";import D from"../../../rest/support/Query.js";import{T as k}from"../../../chunks/TimeExtent.js";import{isSafeToEditVersion as C,isVersionInEditSession as L,isHistoricVersion as Q,currentSessionId as P}from"../../../versionManagement/support/versionManagementUtils.js";const V=new n({originalAndCurrentFeatures:"original-and-current-features",none:"none"}),$=new n({Started:"published",Publishing:"publishing",Stopped:"unavailable"});let G=class extends o{constructor(e){super(e),this.type="feature-layer",this.supportedSourceTypes=new Set(["Feature Layer","Oriented Imagery Layer","Table","Catalog Layer"]),this.refresh=c((async()=>{await this.load();const e=this.sourceJSON.editingInfo?.lastEditDate;if(null==e)return{dataChanged:!0,updates:{}};try{await this._fetchService(null)}catch{return{dataChanged:!0,updates:{}}}const t=e!==this.sourceJSON.editingInfo?.lastEditDate;return{dataChanged:t,updates:t?{editingInfo:this.sourceJSON.editingInfo,extent:this.sourceJSON.extent}:null}})),this._ongoingAssetUploads=new Map}load(e){const t=this.layer.sourceJSON,s=this._fetchService(t,{...e}).then((()=>this.layer.setUserPrivileges(this.sourceJSON.serviceItemId,e))).then((()=>this._ensureLatestMetadata(e)));return this.addResolvingPromise(s),Promise.resolve(this)}initialize(){this.addHandles([y((()=>{const e=this.layer;return e&&"lastEditsEventDate"in e?e.lastEditsEventDate:null}),(e=>this._handleLastEditsEventChange(e)))])}destroy(){this._removeEditInterceptor()}get queryTask(){const{capabilities:e,parsedUrl:t,gdbVersion:s,spatialReference:r,fieldsIndex:a,uniqueIdFields:i}=this.layer,n="infoFor3D"in this.layer?this.layer.infoFor3D:null,o="dynamicDataSource"in this.layer?this.layer.dynamicDataSource:null,u=has("featurelayer-pbf")&&e?.query.supportsFormatPBF&&null==n;return new v({dynamicDataSource:o,fieldsIndex:a,gdbVersion:s,infoFor3D:n,pbfSupported:u,queryAttachmentsSupported:e?.operations?.supportsQueryAttachments??!1,sourceSpatialReference:r,uniqueIdFields:i,url:t.path})}async addAttachment(e,t){await this.load();const{layer:r}=this;await M(r,"editing");const a=e.attributes[r.objectIdField],i=r.parsedUrl.path+"/"+a+"/addAttachment",n=this._getLayerRequestOptions(),o=this._getFormDataForAttachment(t,n.query);try{const e=await s(i,{body:o});return _(e.data.addAttachmentResult)}catch(u){throw this._createAttachmentErrorResult(a,u)}}async updateAttachment(e,t,r){await this.load();const{layer:a}=this;await M(a,"editing");const i=e.attributes[a.objectIdField],n=a.parsedUrl.path+"/"+i+"/updateAttachment",o=this._getLayerRequestOptions({query:{attachmentId:t}}),u=this._getFormDataForAttachment(r,o.query);try{const e=await s(n,{body:u});return _(e.data.updateAttachmentResult)}catch(l){throw this._createAttachmentErrorResult(i,l)}}async applyEdits(e,t){await this.load();const{layer:a}=this;await M(a,"editing");const n="infoFor3D"in a?a.infoFor3D:null,o=null!=n,u=o||(t?.globalIdUsed??!1),l=o?await this._uploadMeshesAndGetAssetMapEditsJSON(e):null,c=e.addFeatures?.map((e=>b(this.layer,e,n)))??[],d=(await Promise.all(c)).filter(r),p=e.updateFeatures?.map((e=>b(this.layer,e,n)))??[],y=(await Promise.all(p)).filter(r),h=R(this.layer,e.deleteFeatures,u);J(d,y,a.spatialReference);const m=await A(this.layer,e),f=a.capabilities.editing.supportsAsyncApplyEdits&&o,g=t?.gdbVersion||a.gdbVersion,w={gdbVersion:g,rollbackOnFailure:t?.rollbackOnFailureEnabled,useGlobalIds:u,returnEditMoment:t?.returnEditMoment,usePreviousEditMoment:t?.usePreviousEditMoment,async:f};await C(this.layer.url,g,!0);const q=L(this.layer.url,g||null);if(await Q(a.url,g,a.historicMoment))throw new i("feature-layer-source:historic-version","Editing a historic version is not allowed");t?.returnServiceEditsOption?(w.edits=JSON.stringify([{id:a.layerId,adds:d.length?d:null,updates:y.length?y:null,deletes:h.length?h:null,attachments:m,assetMaps:l}]),w.returnServiceEditsOption=V.toJSON(t?.returnServiceEditsOption),w.returnServiceEditsInSourceSR=t?.returnServiceEditsInSourceSR):(w.adds=d.length?JSON.stringify(d):null,w.updates=y.length?JSON.stringify(y):null,w.deletes=h.length?u?JSON.stringify(h):h.join(","):null,w.attachments=m&&JSON.stringify(m),w.assetMaps=null!=l?JSON.stringify(l):void 0);const S=this._getLayerRequestOptions({method:"post",query:w});q&&(S.authMode="immediate",S.query.returnEditMoment=!0,S.query.sessionId=P);const E=t?.returnServiceEditsOption?a.url:a.parsedUrl.path;let O;try{O=f?await this._asyncApplyEdits(E+"/applyEdits",S):await s(E+"/applyEdits",S)}catch(_){if(!F(_))throw _;S.authMode="immediate",O=f?await this._asyncApplyEdits(E+"/applyEdits",S):await s(E+"/applyEdits",S)}return this._createEditsResult(O)}async deleteAttachments(e,t){await this.load();const{layer:r}=this;await M(r,"editing");const a=e.attributes[r.objectIdField],i=r.parsedUrl.path+"/"+a+"/deleteAttachments";try{return(await s(i,this._getLayerRequestOptions({query:{attachmentIds:t.join(",")},method:"post"}))).data.deleteAttachmentResults.map(_)}catch(n){throw this._createAttachmentErrorResult(a,n)}}fetchRecomputedExtents(e={}){const t=e.signal;return this.load({signal:t}).then((async()=>{const t=this._getLayerRequestOptions({...e,query:{returnUpdates:!0}}),{layerId:r,url:a}=this.layer,{data:i}=await s(`${a}/${r}`,t),{id:n,extent:o,fullExtent:u,timeExtent:l}=i,c=o||u;return{id:n,fullExtent:c&&w.fromJSON(c),timeExtent:l&&k.fromJSON({start:l[0],end:l[1]})}}))}async queryAttachments(e,t={}){await this.load();const s=this._getLayerRequestOptions(t);return this.queryTask.executeAttachmentQuery(e,s)}async queryFeatures(e,t){await this.load();const s=await this.queryTask.execute(e,{...t,query:this._createRequestQueryOptions(t)});if(e.outStatistics?.length&&s.features.length){const t=new Map;if(s.features.forEach((s=>{const r=s.attributes;e.outStatistics?.forEach((({outStatisticFieldName:e})=>{if(e){const s=e.toLowerCase();s&&s in r&&e!==s&&(r[e]=r[s],delete r[s],t.set(s,e))}}))})),null!=s.fields)for(const e of s.fields){const s=t.get(e.name.toLowerCase());null!=s&&(e.name=s)}}return s}async queryFeaturesJSON(e,t){return await this.load(),this.queryTask.executeJSON(e,{...t,query:this._createRequestQueryOptions(t)})}async queryObjectIds(e,t){return await this.load(),this.queryTask.executeForIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryFeatureCount(e,t){return await this.load(),this.queryTask.executeForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryExtent(e,t){return await this.load(),this.queryTask.executeForExtent(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeatures(e,t){return await this.load(),this.queryTask.executeRelationshipQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryRelatedFeaturesCount(e,t){return await this.load(),this.queryTask.executeRelationshipQueryForCount(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopFeatures(e,t){return await this.load(),this.queryTask.executeTopFeaturesQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryAttributeBins(e,t){return await this.load(),this.queryTask.executeAttributeBinsQuery(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopObjectIds(e,t){return await this.load(),this.queryTask.executeForTopIds(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopExtents(e,t){return await this.load(),this.queryTask.executeForTopExtents(e,{...t,query:this._createRequestQueryOptions(t)})}async queryTopCount(e,t){return await this.load(),this.queryTask.executeForTopCount(e,{...t,query:this._createRequestQueryOptions(t)})}async fetchPublishingStatus(){if(!T(this.layer.url))return"unavailable";const e=h(this.layer.url,"status"),t=await s(e,{query:{f:"json"}});return $.fromJSON(t.data.status)}async uploadAssets(e,t){const{uploadAssets:s}=await import("./support/uploadAssets.js");return s(e,{layer:this.layer,ongoingUploads:this._ongoingAssetUploads},t)}_handleLastEditsEventChange(e){const t=this.layer;if(null==e||!("capabilities"in t)||!("effectiveCapabilities"in t))return;if(!(!t.capabilities?.operations?.supportsEditing&&t.effectiveCapabilities?.operations?.supportsEditing))return;const s=t.url;if(null==s)return;"layerId"in t&&h(s,t.layerId.toString());this._getOrCreateEditInterceptor(s).before=t=>{const s=t.requestOptions.method??"auto";if("auto"===s||"head"===s){const s=t.requestOptions.query??{};s._ts=e.getTime(),t.requestOptions.query=s}}}_getOrCreateEditInterceptor(e){return null==this._editInterceptor&&(this._editInterceptor={urls:e},t.request.internalInterceptors.push(this._editInterceptor)),this._editInterceptor}_removeEditInterceptor(){null!=this._editInterceptor&&(a(t.request.internalInterceptors,this._editInterceptor),this._editInterceptor=null)}async _asyncApplyEdits(e,t){const r=(await s(e,t)).data.statusUrl;for(;;){const e=(await s(r,{query:{f:"json"},responseType:"json"})).data;switch(e.status){case"Completed":return s(e.resultUrl,{query:{f:"json"},responseType:"json"});case"CompletedWithErrors":throw new i("async-applyEdits-failed","asynchronous applyEdits call failed.");case"Failed ImportChanges":case"InProgress":case"Pending":case"ExportAttachments":case"ExportChanges":case"ExportingData":case"ExportingSnapshot":case"ImportAttachments":case"ProvisioningReplica":case"UnRegisteringReplica":break;default:throw new i("async-applyEdits-failed","asynchronous applyEdits call failed (undefined response status)")}await d(H)}}_createRequestQueryOptions(e){const t={...this.layer.customParameters,token:this.layer.apiKey,...e?.query};return this.layer.datesInUnknownTimezone&&(t.timeReferenceUnknownClient=!0),t}async _fetchService(e,t){if(!e){const r={};has("featurelayer-advanced-symbols")&&(r.returnAdvancedSymbols=!0),t?.cacheBust&&(r._ts=Date.now());const{data:a}=await s(this.layer.parsedUrl.path,this._getLayerRequestOptions({query:r,signal:t?.signal}));e=a}this.sourceJSON=await this._patchServiceJSON(e,t?.signal);const r=e.type;if(!this.supportedSourceTypes.has(r))throw new i("feature-layer-source:unsupported-type",`Source type "${r}" is not supported`)}async _patchServiceJSON(e,t){if("Table"!==e.type&&e.geometryType&&!e?.drawingInfo?.renderer&&!e.defaultSymbol){const t=j(e.geometryType).renderer;l("drawingInfo.renderer",t,e)}if("esriGeometryMultiPatch"===e.geometryType&&e.infoFor3D&&(e.geometryType="mesh"),null==e.extent)try{const{data:r}=await s(this.layer.url,this._getLayerRequestOptions({signal:t}));r.spatialReference&&(e.extent={xmin:0,ymin:0,xmax:0,ymax:0,spatialReference:r.spatialReference})}catch(r){p(r)}return e}async _ensureLatestMetadata(e){if(this.layer.userHasUpdateItemPrivileges&&this.sourceJSON.cacheMaxAge>0)return this._fetchService(null,{...e,cacheBust:!0})}async _uploadMeshesAndGetAssetMapEditsJSON(e){const{addAssetFeatures:t}=e;if(!t?.length)return null;if(await this._areAllAssetsAlreadyMapped(t))return null;const s=e.addFeatures.filter((e=>e.geometry));if(t.length!==s.length+e.updateFeatures.length)throw new i("feature-layer-source:unsupported-mesh-edits","Mixing attribute only edits with mesh geometry edits is not currently supported");const r=new Array,a=new Map;for(const i of t){const{geometry:e}=i,{vertexSpace:t}=e;if(E(t))r.push(e);else{const t=e.origin,{convertMeshVertexSpace:s}=await import("../../../geometry/support/meshUtils/convertMeshVertexSpace.js"),n=await s(e,new S({origin:[t.x,t.y,t.z??0]}));a.set(n,e),i.geometry=n,r.push(n)}}await this.uploadAssets(r);for(const[i,n]of a)n.addExternalSources(i.metadata.externalSources.items);return{adds:this._getAssetMapEditsJSON(t),updates:[],deletes:[]}}_getAssetMapEditsJSON(e){const t=new Array,s=this.layer.globalIdField,r=this.layer.parsedUrl;for(const a of e){const e=a.geometry,{metadata:i}=e,n=i.getExternalSourcesOnService(r),o=a.getAttribute(s);if(0===n.length){u.getLogger(this).error(`Skipping feature ${o}. The mesh it is associated with has not been uploaded to the service and cannot be mapped to it.`);continue}const{source:l}=n.find(O)??n[0];for(const s of l.assets)1===s.parts.length?t.push({globalId:m(),parentGlobalId:o,assetName:s.assetName,assetHash:s.parts[0].partHash,flags:[]}):u.getLogger(this).error(`Skipping asset ${s.assetName}. It does not have exactly one part, so we cannot map it to a feature.`)}return t}_createEditsResult(e){const t=e.data,{layerId:s}=this.layer,r=[];let a=null;if(Array.isArray(t))for(const n of t)r.push({id:n.id,editedFeatures:n.editedFeatures}),n.id===s&&(a={addResults:n.addResults??[],updateResults:n.updateResults??[],deleteResults:n.deleteResults??[],attachments:n.attachments,editMoment:n.editMoment});else a=t;const i=I(a);if(r.length>0){i.editedFeatureResults=[];for(const e of r){const{editedFeatures:t}=e,s=t?.spatialReference?new q(t.spatialReference):null;i.editedFeatureResults.push({layerId:e.id,editedFeatures:x(t,s)})}}return i}_createAttachmentErrorResult(e,t){const s=t.details.messages?.[0]||t.message,r=t.details.httpStatus||t.details.messageCode;return{objectId:e,globalId:null,error:new i("feature-layer-source:attachment-failure",s,{code:r})}}_getFormDataForAttachment(e,t){const s=e instanceof FormData?e:e&&e.elements?new FormData(e):null;if(s)for(const r in t){const e=t[r];null!=e&&(s.set?s.set(r,e):s.append(r,e))}return s}_getLayerRequestOptions(e={}){const{layer:t,layer:{parsedUrl:s,gdbVersion:r}}=this;return{...e,query:{gdbVersion:r,layer:"dynamicDataSource"in t&&t.dynamicDataSource?JSON.stringify({source:t.dynamicDataSource}):void 0,...s.query,f:"json",...this._createRequestQueryOptions(e)},responseType:"json"}}async _areAllAssetsAlreadyMapped(e){const{layer:t}=this,{globalIdField:s,parsedUrl:a}=t,i="infoFor3D"in t?t.infoFor3D:null;if(null==i||null==s)return!1;const n=N(i);if(null==n)return!1;const o=h(a.path,`../${n.id}`),u=new Array;for(const r of e){if(!(r.geometry.metadata.getExternalSourcesOnService(a).length>0))return!1;u.push(r)}const l=u.map((e=>e.getAttribute(s))).filter(r);if(0===l.length)return!1;const{assetMapFieldRoles:{parentGlobalId:c,assetHash:d}}=i,p=new D({where:`${c} IN (${l.map((e=>`'${e}'`))})`,outFields:[d,c],returnGeometry:!1}),y=await U(o,p),{features:m}=y;return 0!==m.length&&!u.some((e=>{const t=e.getAttribute(s);if(!t)return!0;const{metadata:r}=e.geometry,i=m.filter((e=>e.getAttribute(c)===t));if(0===i.length)return!0;const n=i.map((e=>e.getAttribute(d)));return r.getExternalSourcesOnService(a).flatMap((({source:e})=>e.assets.flatMap((e=>e.parts.map((e=>e.partHash)))))).some((e=>n.every((t=>e!==t))))}))}};e([f()],G.prototype,"type",void 0),e([f({constructOnly:!0})],G.prototype,"layer",void 0),e([f({constructOnly:!0})],G.prototype,"supportedSourceTypes",void 0),e([f({readOnly:!0})],G.prototype,"queryTask",null),G=e([g("esri.layers.graphics.sources.FeatureLayerSource")],G);const H=1e3;export{G as default};
@@ -2,4 +2,4 @@
2
2
  All material copyright ESRI, All Rights Reserved, unless otherwise specified.
3
3
  See https://js.arcgis.com/4.33/esri/copyright.txt for details.
4
4
  */
5
- import e from"../../../../request.js";import has from"../../../../core/has.js";import s from"../../../../core/Logger.js";import{throwIfAborted as t,after as r,throwIfAbortError as o}from"../../../../core/promiseUtils.js";import{Milliseconds as n}from"../../../../core/time.js";import{join as a,parseData as i}from"../../../../core/urlUtils.js";import{generateBracedUUID as c}from"../../../../core/uuid.js";import u from"../../../../geometry/SpatialReference.js";import{externalIsOnService as l,externalSourceToMultiPart as p,assetFormatId as m,ServiceAsset as f,ServiceAssetPart as d}from"../../../../geometry/support/meshUtils/External.js";import{UnsupportedError as g,NoSupportedSourceError as y,NoGlbSupportError as w,Convert3DFailedError as h,UnsupportedFormatUploadedError as P,BadResponseError as b,UploadFailedError as j,NotBase64Error as T,UnableToPrepareOptionsError as A}from"./uploadAssetErrors.js";import{uploadProgressWeights as S}from"./uploadProgressWeights.js";import{uploadItem as F}from"./uploads.js";import{getPrjFormatId as v,getWorldFileFormatId as R,getGlbFormatId as U,getMimeTypeFormatId as x,getFormatIdMimeType as D}from"../../../support/infoFor3D.js";import{getMeshTransformForMetersToSpatialReference as N}from"../../../support/meshSpatialReferenceScaleUtils.js";import{extractMeshFeatureTransform as E,extractMeshFeatureOrigin as C}from"../../../../rest/support/meshFeatureAttributes.js";import{makeProgressManager as O,estimatedConversionTime as k,simulateProgress as I}from"../../../../support/progressUtils.js";async function B(e,s,t){const r=e.length;if(!r)return t?.onProgress?.(1),[];const o=O(r,t?.onProgress,"uploadAssets");return Promise.all(e.map(((e,r)=>q(e,s,{...t,onProgress:o.makeOnProgress(r)}))))}async function q(e,{layer:s,ongoingUploads:t},r){const o=t.get(e);if(o)return o;if(!ne(s))throw new g;if(L(e,s))return r?.onProgress?.(1),e;const n=H(e,s,r);t.set(e,n);try{await n}finally{t.delete(e)}return e}function L(e,s){const{parsedUrl:t}=s;return null!=t&&e.metadata.externalSources.some((e=>l(e,t)))}async function H(e,s,r){const{metadata:o}=e,{displaySource:n}=o,a=W(n?.source,s,{checkForConversionRequired:has("enable-feature:georeferenced-uploads")}),i=null!=a?$(a,s,r):o.externalSources.length>0?J(e,s,r):z(e,s,r),c=await i;return t(r),e.addExternalSources([c]),e}async function $(e,s,t){return{source:await Q(e,s,t),original:!0,unitConversionDisabled:!0}}async function J(e,s,t){const r=ae(s),{externalSources:o}=e.metadata,n=M(o,s);if(!n)throw new y;const a=O(S.uploadConvertibleSource,t?.onProgress,"uploadConvertibleSource"),i=await Q(n,s,{onProgress:a.makeOnProgress("uploadEditSource")});e.addExternalSources([{source:i,original:!0}]);const c=n.reduce(((e,{asset:s})=>s instanceof File?e+s.size:e),0),u=a.simulate("serviceAssetsToGlb",k(c));try{const{source:o,transform:n,origin:a}=await se(i,s,r);return e.transform=n,a&&(e.metadata.georeferenced=!0,t?.useAssetOrigin&&(e.vertexSpace.origin=[a.x,a.y,a.z??0],e.spatialReference=a.spatialReference)),{source:o,unitConversionDisabled:!0}}finally{u.remove()}}async function z(e,s,t){const r=O(S.uploadLocalMesh,t?.onProgress,"uploadLocalMesh"),o=G(e,s,{...t,onProgress:r.makeOnProgress("meshToAssetBlob")});return{source:await V([o],s,{...t,onProgress:r.makeOnProgress("uploadAssetBlobs")}),extent:e.extent.clone(),original:!0}}async function G(e,s,r){const o=ae(s),n=await e.load(r),a=await n.toBinaryGLTF({origin:n.origin,signal:r?.signal,ignoreLocalTransform:!0,unitConversionDisabled:!0});return t(r),{blob:new Blob([a],{type:"model/gltf-binary"}),assetName:`${c()}.glb`,assetType:o}}function M(e,s){for(const t of e){const e=W(t.source,s);if(e)return e}return null}function W(e,{infoFor3D:s},t={}){if(!e)return null;const{supportedFormats:r,editFormats:o}=s,n=p(e),a=new Array,i=v(s),c=R(s);let u=!1;for(const l of n){const e=K(l,r);if(!e)return null;const{assetType:s}=e;if(t.checkForConversionRequired&&(s===i||s===c))return null;o.includes(s)&&(u=!0),a.push(e)}return u?a:null}function K(e,s){const t=m(e,s);return t?{asset:e,assetType:t}:null}async function Q(e,s,t){return V(e.map((e=>X(e,t))),s,t)}async function V(e,s,r){const o=O(S.uploadAssetBlobs,r?.onProgress,"uploadAssetBlobs"),n=await Z(e,s,{...r,onProgress:o.makeOnProgress("prepareAssetItems")});t(r);const a=n.map((({item:e})=>e)),{uploadResults:i}=await _(a,s,{...r,onProgress:o.makeOnProgress("uploadAssetItems")});return t(r),e.map(((e,t)=>ee(n[t],i[t],s)))}async function X(e,s){const{asset:r,assetType:o}=e;if(r instanceof File)return{blob:r,assetName:r.name,assetType:o};const n=await r.toBlob(s);return t(s),{blob:n,assetName:r.assetName,assetType:o}}async function Y(e,s,r){const{blob:n,assetType:a,assetName:c}=e;let u=null;try{const e=await F({data:n,name:c},s.url,r);t(r),u={assetType:a,assetUploadId:e.itemID}}catch(l){o(l),ie().warnOnce(`Service ${s.url} does not support the REST Uploads API.`)}if(!u){const e=await i(n);if(t(r),!e.isBase64)throw new T;u={assetType:a,assetData:e.data}}if(!u)throw new A;return{item:u,assetName:c}}function Z(e,s,r){const o=O(e.length,r?.onProgress,"prepareAssetItems");return Promise.all(e.map((async(e,n)=>{const a=Y(await e,s,{...r,onProgress:o.makeOnProgress(n)});return t(r),a})))}async function _(s,r,o){const n=I(o?.onProgress);try{const n=await e(a(r.parsedUrl.path,"uploadAssets"),{timeout:0,query:{f:"json",assets:JSON.stringify(s)},method:"post",responseType:"json"});if(t(o),n.data.uploadResults.length!==s.length)throw new b(s.length,n.data.uploadResults.length);return n.data}finally{n.remove()}}function ee(e,s,t){const{success:r}=s;if(!r){const{error:t}=s;throw new j(e.assetName,t)}const{assetHash:o}=s,{assetName:n,item:{assetType:a}}=e,{infoFor3D:{supportedFormats:i}}=t,c=D(a,i);if(!c)throw new P(a);return new f(n,c,[new d(`${t.parsedUrl.path}/assets/${o}`,o)])}async function se(e,s,t){const r=e.map((({assetName:e,parts:s})=>({assetName:e,assetHash:s[0].partHash})));let o;try{const e=a(s.parsedUrl.path,"convert3D"),n=s.capabilities?.operations.supportsAsyncConvert3D;o=(await(n?oe:re)(e,{query:{f:"json",assets:JSON.stringify(r),transportType:"esriTransportTypeUrl",targetFormat:t,async:n},responseType:"json",timeout:0})).data}catch(n){throw new h}return te(s,o)}function te(e,s){const t={source:s.assets.map((s=>{const t=x(s.contentType,e.infoFor3D.supportedFormats);if(!t)throw new P(t);return new f(s.assetName,s.contentType,[new d(s.assetURL,s.assetHash)])})),origin:void 0,transform:void 0};if(has("enable-feature:georeferenced-uploads")&&s.transform){if(t.transform=E(s.transform),s.spatialReference){const e=u.fromJSON(s.spatialReference);t.origin=C(s.transform,e)}}else t.transform=N(e.spatialReference);return t}function re(s,t){return e(s,t)}async function oe(s,t){const o=(await e(s,t)).data.statusUrl;for(;;){const s=(await e(o,{query:{f:"json"},responseType:"json"})).data;switch(s.status){case"Completed":return e(s.resultUrl,{query:{f:"json"},responseType:"json"});case"CompletedWithErrors":throw new Error(s.status);case"Failed ImportChanges":case"InProgress":case"Pending":case"ExportAttachments":case"ExportChanges":case"ExportingData":case"ExportingSnapshot":case"ImportAttachments":case"ProvisioningReplica":case"UnRegisteringReplica":break;default:throw new Error}await r(ce)}}function ne(e){return!!e.infoFor3D&&!!e.url}function ae({infoFor3D:e}){const s=U(e);if(!s)throw new w;return s}function ie(){return s.getLogger("esri.layers.graphics.sources.support.uploadAssets")}const ce=n(1e3);export{B as uploadAssets};
5
+ import e from"../../../../request.js";import has from"../../../../core/has.js";import s from"../../../../core/Logger.js";import{throwIfAborted as t,after as r,throwIfAbortError as o}from"../../../../core/promiseUtils.js";import{Milliseconds as n}from"../../../../core/time.js";import{join as a,parseData as i}from"../../../../core/urlUtils.js";import{generateBracedUUID as c}from"../../../../core/uuid.js";import u from"../../../../geometry/SpatialReference.js";import{externalIsOnService as l,externalSourceToMultiPart as p,assetFormatId as m,ServiceAsset as f,ServiceAssetPart as d}from"../../../../geometry/support/meshUtils/External.js";import{UnsupportedError as g,NoSupportedSourceError as y,NoGlbSupportError as w,Convert3DFailedError as h,UnsupportedFormatUploadedError as P,BadResponseError as b,UploadFailedError as j,NotBase64Error as T,UnableToPrepareOptionsError as v}from"./uploadAssetErrors.js";import{uploadProgressWeights as A}from"./uploadProgressWeights.js";import{uploadItem as S}from"./uploads.js";import{getPrjFormatId as F,getWorldFileFormatId as R,getGlbFormatId as U,getMimeTypeFormatId as x,getFormatIdMimeType as D}from"../../../support/infoFor3D.js";import{getMeshTransformForMetersToSpatialReference as N}from"../../../support/meshSpatialReferenceScaleUtils.js";import{extractMeshFeatureTransform as E,extractMeshFeatureOrigin as C}from"../../../../rest/support/meshFeatureAttributes.js";import{makeProgressManager as O,estimatedConversionTime as k,simulateProgress as I}from"../../../../support/progressUtils.js";async function B(e,s,t){const r=e.length;if(!r)return t?.onProgress?.(1),[];const o=O(r,t?.onProgress,"uploadAssets");return Promise.all(e.map(((e,r)=>q(e,s,{...t,onProgress:o.makeOnProgress(r)}))))}async function q(e,{layer:s,ongoingUploads:t},r){const o=t.get(e);if(o)return o;if(!ne(s))throw new g;if(L(e,s))return r?.onProgress?.(1),e;const n=H(e,s,r);t.set(e,n);try{await n}finally{t.delete(e)}return e}function L(e,s){const{parsedUrl:t}=s;return null!=t&&e.metadata.externalSources.some((e=>l(e,t)))}async function H(e,s,r){const{metadata:o}=e,{displaySource:n}=o,a=W(n?.source,s,{checkForConversionRequired:has("enable-feature:georeferenced-uploads")}),i=null!=a?$(a,s,r):o.externalSources.length>0?J(e,s,r):z(e,s,r),c=await i;return t(r),e.addExternalSources([c]),e}async function $(e,s,t){return{source:{type:"service",assets:await Q(e,s,t)},original:!0,unitConversionDisabled:!0}}async function J(e,s,t){const r=ae(s),{externalSources:o}=e.metadata,n=M(o,s);if(!n)throw new y;const a=O(A.uploadConvertibleSource,t?.onProgress,"uploadConvertibleSource"),i={type:"service",assets:await Q(n,s,{onProgress:a.makeOnProgress("uploadEditSource")})};e.addExternalSources([{source:i,original:!0}]);const c=n.reduce(((e,{asset:s})=>s instanceof File?e+s.size:e),0),u=a.simulate("serviceAssetsToGlb",k(c));try{const{source:o,transform:n,origin:a}=await se(i,s,r);return e.transform=n,a&&(e.metadata.georeferenced=!0,t?.useAssetOrigin&&(e.vertexSpace.origin=[a.x,a.y,a.z??0],e.spatialReference=a.spatialReference)),{source:o,unitConversionDisabled:!0}}finally{u.remove()}}async function z(e,s,t){const r=O(A.uploadLocalMesh,t?.onProgress,"uploadLocalMesh"),o=G(e,s,{...t,onProgress:r.makeOnProgress("meshToAssetBlob")});return{source:{type:"service",assets:await V([o],s,{...t,onProgress:r.makeOnProgress("uploadAssetBlobs")})},extent:e.extent.clone(),original:!0}}async function G(e,s,r){const o=ae(s),n=await e.load(r),a=await n.toBinaryGLTF({origin:n.origin,signal:r?.signal,ignoreLocalTransform:!0,unitConversionDisabled:!0});return t(r),{blob:new Blob([a],{type:"model/gltf-binary"}),assetName:`${c()}.glb`,assetType:o}}function M(e,s){for(const t of e){const e=W(t.source,s);if(e)return e}return null}function W(e,{infoFor3D:s},t={}){if(!e)return null;const r=p(e);if(!r)return null;const{supportedFormats:o,editFormats:n}=s,a=new Array,i=F(s),c=R(s);let u=!1;for(const l of r){const e=K(l,o);if(!e)return null;const{assetType:s}=e;if(t.checkForConversionRequired&&(s===i||s===c))return null;n.includes(s)&&(u=!0),a.push(e)}return u?a:null}function K(e,s){const t=m(e,s);return t?{asset:e,assetType:t}:null}async function Q(e,s,t){return V(e.map((e=>X(e,t))),s,t)}async function V(e,s,r){const o=O(A.uploadAssetBlobs,r?.onProgress,"uploadAssetBlobs"),n=await Z(e,s,{...r,onProgress:o.makeOnProgress("prepareAssetItems")});t(r);const a=n.map((({item:e})=>e)),{uploadResults:i}=await _(a,s,{...r,onProgress:o.makeOnProgress("uploadAssetItems")});return t(r),e.map(((e,t)=>ee(n[t],i[t],s)))}async function X(e,s){const{asset:r,assetType:o}=e;if(r instanceof File)return{blob:r,assetName:r.name,assetType:o};const n=await r.toBlob(s);return t(s),{blob:n,assetName:r.assetName,assetType:o}}async function Y(e,s,r){const{blob:n,assetType:a,assetName:c}=e;let u=null;try{const e=await S({data:n,name:c},s.url,r);t(r),u={assetType:a,assetUploadId:e.itemID}}catch(l){o(l),ie().warnOnce(`Service ${s.url} does not support the REST Uploads API.`)}if(!u){const e=await i(n);if(t(r),!e.isBase64)throw new T;u={assetType:a,assetData:e.data}}if(!u)throw new v;return{item:u,assetName:c}}function Z(e,s,r){const o=O(e.length,r?.onProgress,"prepareAssetItems");return Promise.all(e.map((async(e,n)=>{const a=Y(await e,s,{...r,onProgress:o.makeOnProgress(n)});return t(r),a})))}async function _(s,r,o){const n=I(o?.onProgress);try{const n=await e(a(r.parsedUrl.path,"uploadAssets"),{timeout:0,query:{f:"json",assets:JSON.stringify(s)},method:"post",responseType:"json"});if(t(o),n.data.uploadResults.length!==s.length)throw new b(s.length,n.data.uploadResults.length);return n.data}finally{n.remove()}}function ee(e,s,t){const{success:r}=s;if(!r){const{error:t}=s;throw new j(e.assetName,t)}const{assetHash:o}=s,{assetName:n,item:{assetType:a}}=e,{infoFor3D:{supportedFormats:i}}=t,c=D(a,i);if(!c)throw new P(a);return new f(n,c,[new d(`${t.parsedUrl.path}/assets/${o}`,o)])}async function se({assets:e},s,t){const r=e.map((({assetName:e,parts:s})=>({assetName:e,assetHash:s[0].partHash})));let o;try{const e=a(s.parsedUrl.path,"convert3D"),n=s.capabilities?.operations.supportsAsyncConvert3D;o=(await(n?oe:re)(e,{query:{f:"json",assets:JSON.stringify(r),transportType:"esriTransportTypeUrl",targetFormat:t,async:n},responseType:"json",timeout:0})).data}catch(n){throw new h}return te(s,o)}function te(e,s){const t={source:{type:"service",assets:s.assets.map((s=>{const t=x(s.contentType,e.infoFor3D.supportedFormats);if(!t)throw new P(t);return new f(s.assetName,s.contentType,[new d(s.assetURL,s.assetHash)])}))},origin:void 0,transform:void 0};if(has("enable-feature:georeferenced-uploads")&&s.transform){if(t.transform=E(s.transform),s.spatialReference){const e=u.fromJSON(s.spatialReference);t.origin=C(s.transform,e)}}else t.transform=N(e.spatialReference);return t}function re(s,t){return e(s,t)}async function oe(s,t){const o=(await e(s,t)).data.statusUrl;for(;;){const s=(await e(o,{query:{f:"json"},responseType:"json"})).data;switch(s.status){case"Completed":return e(s.resultUrl,{query:{f:"json"},responseType:"json"});case"CompletedWithErrors":throw new Error(s.status);case"Failed ImportChanges":case"InProgress":case"Pending":case"ExportAttachments":case"ExportChanges":case"ExportingData":case"ExportingSnapshot":case"ImportAttachments":case"ProvisioningReplica":case"UnRegisteringReplica":break;default:throw new Error}await r(ce)}}function ne(e){return!!e.infoFor3D&&!!e.url}function ae({infoFor3D:e}){const s=U(e);if(!s)throw new w;return s}function ie(){return s.getLogger("esri.layers.graphics.sources.support.uploadAssets")}const ce=n(1e3);export{B as uploadAssets};