@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 34 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{id as e}from"../kernel.js";import t from"../request.js";import a from"../core/Error.js";import r from"../core/Logger.js";import{isAbortError as n}from"../core/promiseUtils.js";import o from"../geometry/Geometry.js";import d from"../geometry/SpatialReference.js";import{submitJob as i}from"./geoprocessor/submitJob.js";import s from"./knowledgeGraph/GraphQueryResult.js";import c from"./knowledgeGraph/GraphQueryResultHeader.js";import p from"./knowledgeGraph/GraphQueryStreamingResult.js";import l from"./knowledgeGraph/KnowledgeGraph.js";import u from"./knowledgeGraph/ServiceDefinition.js";import{encodeClientDataAtKeysRequest as h}from"./knowledgeGraph/wasmInterface/clientDataToWasmEncodedFactories.js";import{getWasmInterface as w}from"./knowledgeGraph/wasmInterface/knowledgeWasmAccess.js";import{bindParamArrayToWasm as g,setInputQuantizationParametersOnEncoder as y,setOutputQuantizationParametersOnEncoder as f,setProvenanceBehaviorOnEncoder as m,geometryToWasm as _,bindParamObjectToWasm as k}from"./knowledgeGraph/wasmInterface/queryToWasmEncodedFactories.js";import{domainToWasm as G,updateSearchPropertiesToWasm as b,fieldIndexToWasm as x,updateGraphPropertyToWasm as T,graphPropertyToWasm as v,updateEntityTypeToWasm as D,updateRelationshipTypeToWasm as P,entityTypeToWasm as A,relationshipTypeToWasm as S,inputQuantizationParametersToWasmFormat as R,namedObjectToWasm as E}from"./knowledgeGraph/wasmInterface/updateToWasmEncodedFactories.js";import{wasmClientDataAllKeysResponseToClientDataKeys as M,wasmClientDataFetchResponseToClientData as C}from"./knowledgeGraph/wasmInterface/wasmToClientDataFactories.js";import{decoderToAddNamedTypesResult as q,decoderToDeleteNamedTypeResult as F,decoderToUpdateNamedTypesResult as I,decoderToAddGraphPropertiesResult as j,decoderToDeleteGraphPropertiesResult as U,decoderToUpdateGraphPropertiesResult as $,decoderToGraphAddIndexResult as K,decoderToGraphDeleteIndexResult as N,decoderToGraphUpdateSearchIndexResult as Q,decoderToGraphDataModelSingletonOperationResult as L}from"./knowledgeGraph/wasmInterface/wasmToDataModelChangeResponseFactories.js";import{wasmToDataModel as O}from"./knowledgeGraph/wasmInterface/wasmToDataModelFactories.js";import{wasmToGraphQueryResponseHeader as W,decodedWasmObjToQueryResponseObj as H}from"./knowledgeGraph/wasmInterface/wasmToQueryResponseObjFactories.js";import{decoderToApplyEditsResponse as z}from"./knowledgeGraph/wasmInterface/wasmToUpdateResponseFactories.js";import{checkWasmError as B}from"./knowledgeGraph/wasmInterface/wasmUtils.js";const V=new Map,J=()=>new Map(V.entries()),Y={fetchKnowledgeGraph:async e=>{const t=new l({url:e}),a=[];return a.push(ge(t)),a.push(ye(t)),await Promise.all(a),t},refreshDataModel:async e=>{e.dataModel=await it(e)},refreshServiceDefinition:async e=>{const a=(await t(e.url,{query:{f:"json"}})).data;return a.capabilities=a?.capabilities?.split(","),a.supportedQueryFormats=a?.supportedQueryFormats?.split(","),e.serviceDefinition=new u(a),e.serviceDefinition},executeFindPathsAsynchronous:async(e,t)=>{const r=e.inKnowledgeGraphUrl.split("/rest/services");if(r.length<2)throw new a("knowledge-graph:invalid-tool-url","The URL for the KG Service was not correctly formatted. It should contain /rest/services/");const n=r[0],o=(await De(`${n}/rest/info`,{query:{f:"json"}})).data.currentVersion,d=`/rest/services/${o&&o<12?"System":"Utilities"}/KnowledgeGraphServerToolsAsync/GPServer/ServerFilteredFindPaths`;return await ve(`${n}${d}`,{in_knowledge_graph_url:e.inKnowledgeGraphUrl,config_type:"STRING",config_string:e.config.toJSON(),result_type:"STRING"},{},t)},executeFindPaths:async(e,t)=>{const r=e.inKnowledgeGraphUrl.split("/rest/services");if(r.length<2)throw new a("knowledge-graph:invalid-tool-url","The URL for the KG Service was not correctly formatted. It should contain /rest/services/");const n=r[0],o=(await De(`${n}/rest/info`,{query:{f:"json"}})).data.currentVersion,d=`/rest/services/${o&&o<12?"System":"Utilities"}/KnowledgeGraphServerTools/GPServer/ServerFilteredFindPaths/execute`,i=await De(`${n}${d}`,{method:"post",query:{f:"pjson",in_knowledge_graph_url:e.inKnowledgeGraphUrl,config_type:"STRING",config_string:JSON.stringify(e.config),result_type:"STRING"},...t});if(i.data.results.length<1)throw new a("knowledge-graph:no-results","No results were returned from the FindPaths tool - no results returned",i);let s;for(const a of i.data.results)if("out_results_string"===a.paramName){s=a.value;break}if(!s)throw new a("knowledge-graph:no-results","No results were returned from the FindPaths tool - no results were returned on the expected paramater out_results_string",i);return s},fetchAsynchronousFindPathsResultData:async(e,t)=>(await e.fetchResultData("out_results_string",null,t)).value,executeQueryStreaming:async(e,t,r)=>{const n="include",o=`${e.url}/graph/query`;await Pe(e);const d=await Qe(o,r);if(!e.serviceDefinition?.supportsProvenance&&t.provenanceBehavior===n)throw new a("knowledge-graph:provenance-not-supported","The Knowledge Graph Service definition indicated that provenance is not supported");d.data.body=await Ke(t,e);const i=await Te(d.data.url,d.data);if(e.dataModel){const t=await dt(i,e.dataModel);return new p({resultRowsStream:t.readableStream,resultHeader:t.resultHeader})}throw new a("knowledge-graph:undefined-data-model","The KnowledgeGraph supplied did not have a data model")},executeApplyEdits:async(e,t,r)=>{if(e.serviceDefinition?.dataEditingNotSupported||null!=e.dataModel.arcgisManaged&&!e.dataModel.arcgisManaged)throw new a("knowledge-graph:data-editing-not-supported","The Knowledge Graph Service definition indicated that data editing is not supported");const n=`${e.url}/graph/applyEdits`;await Pe(e);const o=await Qe(n,r);o.data.body=await Se(t,e);return Oe(await Te(o.data.url,o.data))},executeAddNamedTypes:async(e,t,r)=>{if(!t.newEntityTypes?.length&&!t.newRelationshipTypes?.length)throw new a("knowledge-graph:no-arguments","The operation to add types to the data model contained no values");const n=`${e.url}/dataModel/edit/namedTypes/add`;await Pe(e);const o=await Qe(n,r);o.data.body=await Re(t);const d=await Te(o.data.url,o.data),i=await We(d);return i.updatedKnowledgeGraph=await we(e.url),i},executeDeleteNamedType:async(e,t,r)=>{if(!t)throw new a("knowledge-graph:no-arguments","The operation to delete a named type from the data model contained no value");const n=`${e.url}/dataModel/edit/namedTypes/${t}/delete`;await Pe(e);const o=await Qe(n,r);o.data.body="";const d=await Te(o.data.url,o.data),i=await He(d);return i.updatedKnowledgeGraph=await we(e.url),i},executeUpdateNamedType:async(e,t,r,n)=>{if(!t&&!Object.keys(r).length)throw new a("knowledge-graph:no-arguments","The operation to update types in the data model contained missing or empty values");const o=`${e.url}/dataModel/edit/namedTypes/${t}/update`;await Pe(e);const d=await Qe(o,n);d.data.body=await Ee(r,t,e.dataModel);const i=await Te(d.data.url,d.data),s=await ze(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeAddGraphProperties:async(e,t,r,n)=>{if(!t&&!r.length)throw new a("knowledge-graph:no-arguments","The operation to add properties to the data model contained missing or empty values");const o=`${e.url}/dataModel/edit/namedTypes/${t}/fields/add`;await Pe(e);const d=await Qe(o,n);d.data.body=await Me(r);const i=await Te(d.data.url,d.data),s=await Be(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeDeleteGraphProperty:async(e,t,r,n)=>{if(!t&&!r)throw new a("knowledge-graph:no-arguments","The operation to delete property contained missing or empty values");const o=`${e.url}/dataModel/edit/namedTypes/${t}/fields/delete`;await Pe(e);const d=await Qe(o,n);d.data.body=await Ce(r);const i=await Te(d.data.url,d.data),s=await Ve(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeUpdateGraphProperty:async(e,t,r,n,o)=>{if(!t&&!r&&!Object.keys(n).length)throw new a("knowledge-graph:no-arguments","The operation to update properties in the data model contained missing or empty values");const d=`${e.url}/dataModel/edit/namedTypes/${t}/fields/update`;await Pe(e);const i=await Qe(d,o);i.data.body=await qe(r,n);const s=await Te(i.data.url,i.data),c=await Je(s);return c.updatedKnowledgeGraph=await we(e.url),c},executeAddGraphFieldIndex:async(e,t,r,n)=>{if(!t)throw new a("knowledge-graph:no-arguments","The operation to update search index in the data model contained missing named type");if(!r?.length)throw new a("knowledge-graph:no-arguments","The operation to update search index in the data model contained missing or empty field index values");const o=`${e.url}/dataModel/edit/namedTypes/${t}/indexes/add`;await Pe(e);const d=await Qe(o,n);d.data.body=await Fe(r);const i=await Te(d.data.url,d.data),s=await Ye(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeDeleteGraphFieldIndex:async(e,t,r,n)=>{if(!t)throw new a("knowledge-graph:no-arguments","The operation to update search index in the data model contained missing named type");if(!r?.length)throw new a("knowledge-graph:no-arguments","The operation to update search index in the data model contained missing or empty field index values");const o=`${e.url}/dataModel/edit/namedTypes/${t}/indexes/delete`;await Pe(e);const d=await Qe(o,n);d.data.body=await Ue(r);const i=await Te(d.data.url,d.data),s=await Xe(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeUpdateSearchIndex:async(e,t,r,n)=>{if(!t)throw new a("knowledge-graph:no-arguments","The operation to update search index in the data model contained missing named type");if(!Object.keys(r.addSearchProperties??{}).length&&!Object.keys(r.removeSearchProperties??{}).length)throw new a("knowledge-graph:no-arguments","The operation to update search index in the data model contained missing or empty properties values");const o=`${e.url}/dataModel/searchIndex/update`;await Pe(e);const d=await Qe(o,n);d.data.body=await $e(t,r);const i=await Te(d.data.url,d.data),s=await Ze(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeAddDomain:async(e,t,a,{mergePolicy:r="esriMergePolicyTypeDefaultValue",splitPolicy:n="esriSplitPolicyTypeDefaultValue"},o)=>{const d=`${e.url}/dataModel/domains/add`;await Pe(e);const i=await Qe(d,o);i.data.body=await Ie(t,a,{mergePolicy:r,splitPolicy:n});const s=await Te(i.data.url,i.data),c=await et(s);return c.updatedKnowledgeGraph=await we(e.url),c},executeUpdateDomain:async(e,t,a,r,n)=>{const o=`${e.url}/dataModel/domains/${t.name}/update`;await Pe(e);const d=await Qe(o,n);d.data.body=await je(t,a,r);const i=await Te(d.data.url,d.data),s=await tt(i);return s.updatedKnowledgeGraph=await we(e.url),s},executeDeleteDomain:async(e,t,r)=>{const n=`${e.url}/dataModel/domains/${t}/delete`;if(!t)throw new a("knowledge-graph:no-arguments","The operation to delete a domain from the data model contained missing or empty domain name");await Pe(e);const o=await Qe(n,r);o.data.body="";const d=await Te(o.data.url,o.data),i=await at(d);return i.updatedKnowledgeGraph=await we(e.url),i},executeQuery:async(e,r,n)=>{const o=`${e.url}/graph/query`,d=await t(o,{responseType:"array-buffer",query:{f:"pbf",openCypherQuery:r.openCypherQuery,...n?.query},signal:n?.signal,timeout:n?.timeout}),i=d.getHeader?.("content-type"),c=d.data;if(i?.includes("application/x-protobuf")){const t=new((await w()).GraphQueryDecoder);if(t.deleteLater(),e.dataModel){const a=ot({wasmQueryDecoder:t,newArrayBufferToParse:c,dataModel:e.dataModel});return new s({resultRows:a.resultRows,resultHeader:a.resultHeader})}throw new a("knowledge-graph:undefined-data-model","The KnowledgeGraph supplied did not have a data model")}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response",{responseType:i,data:d.data})},executeSearch:async(e,r,n)=>{const o="provenance"===r.typeCategoryFilter?"metaEntityProvenance":r.typeCategoryFilter,d=`${e.url}/graph/search`,i=await t(d,{responseType:"array-buffer",query:{f:"pbf",searchQuery:`"${r.searchQuery}"`,typeCategoryFilter:o,...n?.query},signal:n?.signal,timeout:n?.timeout}),c=i.getHeader?.("content-type"),p=i.data;if(c?.includes("application/x-protobuf")){const t=new((await w()).GraphQueryDecoder);if(t.deleteLater(),e.dataModel){const a=ot({wasmQueryDecoder:t,newArrayBufferToParse:p,dataModel:e.dataModel});return new s({resultRows:a.resultRows,resultHeader:a.resultHeader})}throw new a("knowledge-graph:undefined-data-model","The KnowledgeGraph supplied did not have a data model")}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response",{responseType:c,data:i.data})},executeSearchStreaming:async(e,t,r)=>{const n=`${e.url}/graph/search`;await Pe(e);const o=await Qe(n,r);o.data.body=await Ne(t);const d=await Te(o.data.url,o.data);if(e.dataModel){const t=await dt(d,e.dataModel);return new p({resultRowsStream:t.readableStream,resultHeader:t.resultHeader})}throw new a("knowledge-graph:undefined-data-model","The KnowledgeGraph supplied did not have a data model")},fetchClientDataAtKeys:async(e,t,r={ignoreCache:!1})=>{if(!t.length)return new Map;let n=V.get(e.url||"");n||(n=new Map,V.set(e.url||"",n));const o=new Map(n.entries()),d=`${e.url}/clientData/fetch`;t=Array.from(new Set(t));const i=await w(),s=h(t,n,i,r.ignoreCache),c=await Qe(d,r.requestOptions);c.data.body=s;const p=await Te(c.data.url,c.data),l=p.headers.get("content-type");if(l?.includes("application/x-protobuf")){const e=new i.ClientDataFetchResponseDecoder;e.deleteLater();const t=await p.arrayBuffer();return e.decode(new Uint8Array(t)),e.has_error()&&B(e.error,"knowledge-graph:fetchClientDataAtKeys-decoding-error","An error occurred while decoding the client data keys response"),C(e,n,o,r.ignoreCache)}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response when fetching client data",{responseType:l,data:p})},fetchAllClientDataKeys:async(e,r)=>{const n=`${e.url}/clientData`,o=await t(n,{responseType:"array-buffer",query:{f:"pbf"},signal:r?.signal,timeout:r?.timeout}),d=o.getHeader?.("content-type"),i=o.data;if(d?.includes("application/x-protobuf")){const e=new((await w()).ClientDataKeysResponseDecoder);return e.deleteLater(),e.decode(new Uint8Array(i)),e.has_error()&&B(e.error,"knowledge-graph:fetchAllClientDataKeys-decoding-error","An error occurred while decoding the client data keys response"),M(e)}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response",{responseType:d,data:o.data})},clearClientDataCache:()=>V.clear(),_fetchWrapper:async(e,t)=>fetch(e,t),_submitJobWrapper:async(e,t,a,r)=>i(e,t,a,r),_esriRequestWrapper:async(e,a)=>t(e,a)};async function X(e,t,a){return Y.executeApplyEdits(e,t,a)}async function Z(e,t,a){return Y.executeAddNamedTypes(e,t,a)}async function ee(e,t,a){return Y.executeDeleteNamedType(e,t,a)}async function te(e,t,a,r){return Y.executeUpdateNamedType(e,t,a,r)}async function ae(e,t,a,r){return Y.executeAddGraphProperties(e,t,a,r)}async function re(e,t,a,r){return Y.executeDeleteGraphProperty(e,t,a,r)}async function ne(e,t,a,r,n){return Y.executeUpdateGraphProperty(e,t,a,r,n)}async function oe(e,t,a,r){return Y.executeAddGraphFieldIndex(e,t,a,r)}async function de(e,t,a,r){return Y.executeDeleteGraphFieldIndex(e,t,a,r)}async function ie(e,t,a,r){return Y.executeUpdateSearchIndex(e,t,a,r)}async function se(e,t,a){return Y.executeQuery(e,t,a)}async function ce(e,t,a){return Y.executeQueryStreaming(e,t,a)}async function pe(e,t,a){return Y.executeSearch(e,t,a)}async function le(e,t,a){return Y.executeSearchStreaming(e,t,a)}function ue(e,t){return Y.fetchAllClientDataKeys(e,t)}function he(e,t,a){return Y.fetchClientDataAtKeys(e,t,a)}async function we(e){return Y.fetchKnowledgeGraph(e)}async function ge(e){return Y.refreshDataModel(e)}async function ye(e){return Y.refreshServiceDefinition(e)}async function fe(e,t){return Y.executeFindPathsAsynchronous(e,t)}async function me(e,t){return Y.executeFindPaths(e,t)}async function _e(e,t){return Y.fetchAsynchronousFindPathsResultData(e,t)}async function ke(e,t,a,r={mergePolicy:"esriMergePolicyTypeDefaultValue",splitPolicy:"esriSplitPolicyTypeDefaultValue"},n){return Y.executeAddDomain(e,t,a,r,n)}async function Ge(e,t,a,r,n){return Y.executeUpdateDomain(e,t,a,r,n)}async function be(e,t,a){return Y.executeDeleteDomain(e,t,a)}function xe(){return Y.clearClientDataCache()}async function Te(e,t){return Y._fetchWrapper(e,t)}async function ve(e,t,a,r){return Y._submitJobWrapper(e,t,a,r)}async function De(e,t){return Y._esriRequestWrapper(e,t)}async function Pe(t){const a=e?.findCredential(t.url);a||(t.dataModel?await it(t):await ge(t))}function Ae(e,t,a,r){null==t?a.set_param_key_value(e,""):"object"!=typeof t||t instanceof Date?a.set_param_key_value(e,t):t instanceof o?a.set_param_key_value(e,_(t,r)):Array.isArray(t)?a.set_param_key_value(e,g(t,r)):a.set_param_key_value(e,k(t,r))}async function Se(e,t){if(t.dataModel||await ge(t),!t.dataModel)throw new a("knowledge-graph:data-model-undefined","Encoding could not proceed because a data model was not provided and it could not be determined from the service");const r=await w(),n=!!e.options?.cascadeDelete,o=!!e.options?.cascadeProvenanceDelete,d=new r.GraphApplyEditsEncoder(r.SpatialReferenceUtil.WGS84(),e.options?.inputQuantizationParameters?R(e.options?.inputQuantizationParameters):r.InputQuantizationUtil.WGS84_lossless());d.deleteLater(),d.cascade_delete=n,d.cascade_delete_provenance=o;try{let t;e.entityAdds?.forEach(e=>{t=d.add_entity(E(e,r)),B(t,"knowledge-graph:applyEdits-encoding-failed","Attempting to encode the applyEdits - an entity failed to be added to the encoder")}),e.relationshipAdds?.forEach(e=>{if(!e.originId||!e.destinationId)throw new a("knowledge-graph:relationship-origin-destination-missing","When adding a new relationship, you must provide both an origin and destination id on the appropriate class property");t=d.add_relationship(E(e,r)),B(t,"knowledge-graph:applyEdits-encoding-failed","Attempting to encode the applyEdits - a relationship failed to be added to the encoder")}),e.entityUpdates?.forEach(e=>{if(!e.id)throw new a("knowledge-graph:entity-id-missing","When updating an entity or relationship, you must specify the id on the class level property");t=d.update_entity(E(e,r)),B(t,"knowledge-graph:applyEdits-encoding-failed","Attempting to encode the applyEdits - an entity failed to be added to the encoder")}),e.relationshipUpdates?.forEach(e=>{if(!e.id)throw new a("knowledge-graph:relationship-id-missing","When updating an entity or relationship, you must specify the id on the class level property");t=d.update_relationship(E(e,r)),B(t,"knowledge-graph:applyEdits-encoding-failed","Attempting to encode the applyEdits - a relationship failed to be added to the encoder")}),e.entityDeletes?.forEach(e=>{if(!e.typeName)throw new a("knowledge-graph:no-type-name","You must indicate the entity/relationship named object type to apply edits - delete");const t=d.make_delete_helper(e.typeName,!0);t.deleteLater(),e.ids?.forEach(e=>{t.delete_by_id(e)})}),e.relationshipDeletes?.forEach(e=>{if(!e.typeName)throw new a("knowledge-graph:no-type-name","You must indicate the entity/relationship named object type to apply edits - delete");const t=d.make_delete_helper(e.typeName,!1);e.ids?.forEach(e=>{t.delete_by_id(e)})}),d.encode()}catch(s){throw new a("knowledge-graph:applyEdits-encoding-failed","Attempting to encode the applyEdits failed",{error:s})}const i=d.get_encoding_result();return B(i.error,"knowledge-graph:applyEdits-encoding-failed","Attempting to encode the applyEdits failed"),structuredClone(i.get_byte_buffer())}async function Re(e){const t=await w(),r=new t.GraphNamedObjectTypeAddsRequestEncoder;r.deleteLater(),e.newEntityTypes?.forEach(e=>{r.add_entity_type(A(e,t))}),e.newRelationshipTypes?.forEach(e=>{r.add_relationship_type(S(e,t))});try{r.encode()}catch(o){throw new a("knowledge-graph:addNamedTypes-encoding-failed","Attempting to encode the addNamedTypes failed",{error:o})}const n=r.get_encoding_result();return B(n.error,"knowledge-graph:addNamedTypes-encoding-failed","Attempting to encode the addNamedTypes failed"),structuredClone(n.get_byte_buffer())}async function Ee(e,t,r){const n=await w(),o=new n.GraphNamedObjectTypeUpdateRequestEncoder;o.deleteLater();if(r.entityTypes.some(e=>e.name===t))o.update_entity_type(D(e,n));else{if(!r.relationshipTypes.some(e=>e.name===t))throw new a("knowledge-graph:updateNamedType-encoding-failed","The named type you are trying to update does not exist in the data model");o.update_relationship_type(P(e,n))}o.update_alias=e.hasOwnProperty("alias");try{o.encode()}catch(i){throw new a("knowledge-graph:updateNamedType-encoding-failed","Attempting to encode the updateNamedType failed",{error:i})}const d=o.get_encoding_result();return B(d.error,"knowledge-graph:updateNamedType-encoding-failed","Attempting to encode the updateNamedType failed"),structuredClone(d.get_byte_buffer())}async function Me(e){const t=await w(),r=new t.GraphPropertyAddsRequestEncoder;r.deleteLater(),e.forEach(e=>{r.add_graph_property(v(e,t))});try{r.encode()}catch(o){throw new a("knowledge-graph:addGraphProperties-encoding-failed","Attempting to encode the addGraphProperties failed",{error:o})}const n=r.get_encoding_result();return B(n.error,"knowledge-graph:addGraphProperties-encoding-failed","Attempting to encode the addGraphProperties failed"),structuredClone(n.get_byte_buffer())}async function Ce(e){const t=new((await w()).GraphPropertyDeleteRequestEncoder);t.deleteLater(),t.field_name=e;try{t.encode()}catch(n){throw new a("knowledge-graph:deleteGraphProperty-encoding-failed","Attempting to encode the deleteGraphProperty failed",{error:n})}const r=t.get_encoding_result();return B(r.error,"knowledge-graph:deleteGraphProperty-encoding-failed","Attempting to encode the deleteGraphProperty failed"),structuredClone(r.get_byte_buffer())}async function qe(e,t){const r=await w(),n=new r.GraphPropertyUpdateRequestEncoder;n.deleteLater(),n.update_graph_property(T(t,r)),n.set_property_name(e),n.update_alias=t.hasOwnProperty("alias"),n.update_editable=t.hasOwnProperty("editable"),n.update_required=t.hasOwnProperty("required"),n.update_visible=t.hasOwnProperty("defaultVisibility"),n.update_default_value=t.hasOwnProperty("defaultValue"),n.update_domain=t.hasOwnProperty("domain");try{n.encode()}catch(d){throw new a("knowledge-graph:updateGraphProperty-encoding-failed","Attempting to encode the updateGraphProperty failed",{error:d})}const o=n.get_encoding_result();return B(o.error,"knowledge-graph:updateGraphProperty-encoding-failed","Attempting to encode the updateGraphProperty failed"),structuredClone(o.get_byte_buffer())}async function Fe(e){const t=await w(),r=new t.GraphIndexAddsRequestEncoder;r.deleteLater(),e.forEach(e=>{r.add_field_index(x(e,t))});try{r.encode()}catch(o){throw new a("knowledge-graph:addGraphFieldIndex-encoding-failed","Attempting to encode the addGraphFieldIndex failed",{error:o})}const n=r.get_encoding_result();return B(n.error,"knowledge-graph:addGraphFieldIndex-encoding-failed","Attempting to encode the addGraphFieldIndex failed"),structuredClone(n.get_byte_buffer())}async function Ie(e,t,r){const n=await w(),o=new n.GraphDomainAddRequestEncoder;o.deleteLater(),o.set_domain(G(e,n,t,r));try{o.encode()}catch(i){throw new a("knowledge-graph:addDomain-encoding-failed","Attempting to encode the domain failed",{error:i})}const d=o.get_encoding_result();return B(d.error,"knowledge-graph:addDomain-encoding-failed","Attempting to encode the domain failed"),structuredClone(d.get_byte_buffer())}async function je(e,t,r){const n=await w(),o=new n.GraphDomainUpdateRequestEncoder;o.deleteLater(),o.set_domain(G(e,n,t,r)),o.update_domain=!0,r?.mergePolicy&&(o.update_merge_policy=!0),r?.splitPolicy&&(o.update_split_policy=!0);try{o.encode()}catch(i){throw new a("knowledge-graph:updateDomain-encoding-failed","Attempting to encode the domain failed",{error:i})}const d=o.get_encoding_result();return B(d.error,"knowledge-graph:updateDomain-encoding-failed","Attempting to encode the domain failed"),structuredClone(d.get_byte_buffer())}async function Ue(e){const t=new((await w()).GraphIndexDeleteRequestEncoder);t.deleteLater(),e.forEach(e=>{t.add_index_name(e)});try{t.encode()}catch(n){throw new a("knowledge-graph:deleteGraphFieldIndex-encoding-failed","Attempting to encode the deleteGraphFieldIndex failed",{error:n})}const r=t.get_encoding_result();return B(r.error,"knowledge-graph:deleteGraphFieldIndex-encoding-failed","Attempting to encode the deleteGraphFieldIndex failed"),structuredClone(r.get_byte_buffer())}async function $e(e,t){const r=await w(),n=new r.GraphUpdateSearchIndexRequestEncoder;n.deleteLater(),t.hasOwnProperty("addSearchProperties")&&n.insert_add_search_property(e,b(t.addSearchProperties,r)),t.hasOwnProperty("removeSearchProperties")&&n.insert_delete_search_property(e,b(t.removeSearchProperties,r));try{n.encode()}catch(d){throw new a("knowledge-graph:updateSearchIndex-encoding-failed","Attempting to encode the updateSearchIndex failed",{error:d})}const o=n.get_encoding_result();return B(o.error,"knowledge-graph:updateSearchIndex-encoding-failed","Attempting to encode the updateSearchIndex failed"),structuredClone(o.get_byte_buffer())}async function Ke(e,t){const r=await w(),n=new r.GraphQueryRequestEncoder;if(n.deleteLater(),e.outputSpatialReference?n.output_spatial_reference={wkid:e.outputSpatialReference.wkid,latestWkid:e.outputSpatialReference.latestWkid,vcsWkid:e.outputSpatialReference.vcsWkid,latestVcsWkid:e.outputSpatialReference.latestVcsWkid,wkt:e.outputSpatialReference.wkt??""}:n.output_spatial_reference=r.SpatialReferenceUtil.WGS84(),n.open_cypher_query=e.openCypherQuery,e.bindParameters)for(const[a,i]of Object.entries(e.bindParameters))Ae(a,i,n,r);if(e.bindGeometryQuantizationParameters)y(e.bindGeometryQuantizationParameters,n);else{if(t.dataModel||await ge(t),4326!==t.dataModel?.spatialReference?.wkid)throw new a("knowledge-graph:SR-quantization-mismatch","If the DataModel indicates a coordinate system other than WGS84, inputQuantizationParameters must be provided to the query encoder");n.input_quantization_parameters=r.InputQuantizationUtil.WGS84_lossless()}e.outputQuantizationParameters&&f(e.outputQuantizationParameters,n,r),e.provenanceBehavior&&m(e.provenanceBehavior,n);try{n.encode()}catch(d){throw new a("knowledge-graph:query-encoding-failed","Attempting to encode the query failed",{error:d})}const o=n.get_encoding_result();if(0!==o.error.error_code)throw new a("knowledge-graph:query-encoding-failed","Attempting to encode the query failed",{errorCode:o.error.error_code,errorMessage:o.error.error_message});return structuredClone(o.get_byte_buffer())}async function Ne(e){const t=await w(),r=new t.GraphSearchRequestEncoder;r.deleteLater(),r.search_query=e.searchQuery;const n="provenance"===e.typeCategoryFilter?"meta_entity_provenance":e.typeCategoryFilter;if(r.type_category_filter=t.esriNamedTypeCategory[n],!0===e.returnSearchContext&&(r.return_search_context=e.returnSearchContext),null!=e.start&&e.start>0&&(r.start_index=e.start),null!=e.num&&(r.max_num_results=e.num),null!=e.idsFilter&&Array.isArray(e.idsFilter)&&e.idsFilter.length>0)try{r.set_ids_filter(g(e.idsFilter,t))}catch(d){throw new a("knowledge-graph:ids-format-error","Attempting to set ids filter failed. This is usually caused by an incorrectly formatted UUID string",{error:d})}e.namedTypesFilter?.forEach(e=>{r.add_named_type_filter(e)});try{r.encode()}catch(d){throw new a("knowledge-graph:search-encoding-failed","Attempting to encode the search failed",{error:d})}const o=r.get_encoding_result();if(0!==o.error.error_code)throw new a("knowledge-graph:search-encoding-failed","Attempting to get encoding result from the query failed",{errorCode:o.error.error_code,errorMessage:o.error.error_message});return structuredClone(o.get_byte_buffer())}async function Qe(e,a){return t(e,{responseType:"native-request-init",method:"post",query:{f:"pbf",...a?.query},body:"x",headers:{"Content-Type":"application/octet-stream"},signal:a?.signal,timeout:a?.timeout})}async function Le(e,t,r){const n=e.headers.get("content-type");if(n?.includes("application/x-protobuf")){const a=await e.arrayBuffer(),n=new t;try{return n.decode(new Uint8Array(a)),r(n)}finally{n.deleteLater()}}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response",{responseType:n,data:await e.text()})}async function Oe(e){return Le(e,(await w()).GraphApplyEditsDecoder,z)}async function We(e){return Le(e,(await w()).GraphNamedObjectTypeAddsResponseDecoder,q)}async function He(e){return Le(e,(await w()).GraphNamedObjectTypeDeleteResponseDecoder,F)}async function ze(e){return Le(e,(await w()).GraphNamedObjectTypeUpdateResponseDecoder,I)}async function Be(e){return Le(e,(await w()).GraphPropertyAddsResponseDecoder,j)}async function Ve(e){return Le(e,(await w()).GraphPropertyDeleteResponseDecoder,U)}async function Je(e){return Le(e,(await w()).GraphPropertyUpdateResponseDecoder,$)}async function Ye(e){return Le(e,(await w()).GraphIndexAddsResponseDecoder,K)}async function Xe(e){return Le(e,(await w()).GraphIndexDeleteResponseDecoder,N)}async function Ze(e){return Le(e,(await w()).GraphUpdateSearchIndexResponseDecoder,Q)}async function et(e){return Le(e,(await w()).GraphDomainAddResponseDecoder,L)}async function tt(e){return Le(e,(await w()).GraphDomainUpdateResponseDecoder,L)}async function at(e){return Le(e,(await w()).GraphDomainDeleteResponseDecoder,L)}let rt=50;function nt(e){rt=e}function ot({wasmQueryDecoder:e,newArrayBufferToParse:t,dataModel:r,decodedHeader:n,limitMaxProcessingTime:o=!1}){t&&e.push_buffer(new Uint8Array(t));const i=[];let s,c,p=0;const l=Date.now();let u=!0;for(;e.next_row();){s&&c||(s=n??W(e),c=s.outSpatialReference??new d({wkid:4326})),p||(p=e.get_header_keys().size());const t=new Array(p);for(let a=0;a<p;a++){const n=e.get_value(a);t[a]=H(n,r,c)}if(i.push(t),o&&Date.now()-l>rt){u=!1;break}}if(e.has_error())throw new a("knowledge-graph:stream-decoding-error","One or more result rows were not successfully decoded - inner row decoding",{errorCode:e.error.error_code,errorMessage:e.error.error_message});return{resultHeader:s,resultRows:i,parsedAllResultsFromBuffer:u}}async function dt(e,t){const o=e.headers.get("content-type");if(e.headers.get("content-length")&&r.getLogger("esri.rest.knowledgeGraph.knowledgeGraphService").warnOnce("Found `Content-Length` header when expecting a streaming HTTP response! Please investigate whether all intermediate HTTP proxies and/or load balancers are configured such that they don't forcefully buffer the entire response before returning it to the client. A valid HTTP streaming response should use Chunked Transfer Encoding and not have a Content Length defined."),o?.includes("application/x-protobuf")){const o=e.body?.getReader(),d=new((await w()).GraphQueryDecoder);let i,s,p;d.deleteLater();const l=new Promise((e,t)=>{s=e,p=t});let u=!1,h=null;const g=new ReadableStream({pull:async function e(l){if(!o){const e=new a("knowledge-graph:stream-decoding-error","Error reading from stream - reader is undefined");throw p(e),e}const{done:w,value:g}=h?{done:!1,value:null}:await o.read().catch(e=>{throw p(e),o.releaseLock(),e});g&&(h=g);try{if(w){let e;if(d.has_error()?e=new a("knowledge-graph:stream-decoding-error","One or more result rows were not successfully decoded - query stream done",{errorCode:d.error.error_code,errorMessage:d.error.error_message}):u||s(new c),o.releaseLock(),e)throw l.error(e),p(e),e;return void l.close()}const{resultHeader:r,resultRows:n,parsedAllResultsFromBuffer:y}=ot({wasmQueryDecoder:d,newArrayBufferToParse:g,dataModel:t,decodedHeader:i,limitMaxProcessingTime:!0});return y&&(h=null),!i&&r&&(i=r,s(r),u=!0),n.length>0?void l.enqueue(n):await e(l)}catch(y){throw r.getLogger("esri.rest.knowledgeGraph.knowledgeGraphService").error(y),p(y),o.releaseLock(),n(y)?y:new a("knowledge-graph:unexpected-server-response","Error inside streaming data return parsing",{error:y})}}});return{readableStream:g,resultHeader:await l}}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response",{responseType:o,data:e.text()})}async function it(e){const r=`${e.url}/dataModel/queryDataModel`,n=await t(r,{responseType:"array-buffer",query:{f:"pbf"}}),o=n.getHeader?.("content-type"),d=n.data;if(o?.includes("application/x-protobuf")){const e=(await w()).decode_data_model_from_protocol_buffer(new Uint8Array(d));if(!e)throw new a("knowledge-graph:data-model-decode-failure","The server responded to the data model query, but the response failed to be decoded. This typically occurs when the Knowledge JS API (4.26 or later) is used with an unsupported backend (11.0 or earlier)");return O(e)}throw new a("knowledge-graph:unexpected-server-response","server returned an unexpected response",{responseType:o,data:n.data})}export{Pe as _checkAuthentication,De as _esriRequestWrapper,Te as _fetchWrapper,J as _getClientDataCacheCopy,nt as _setMaxQueryParsingDurationForTesting,ve as _submitJobWrapper,xe as clearClientDataCache,V as clientDataCache,ke as executeAddDomain,oe as executeAddGraphFieldIndex,ae as executeAddGraphProperties,Z as executeAddNamedTypes,X as executeApplyEdits,be as executeDeleteDomain,de as executeDeleteGraphFieldIndex,re as executeDeleteGraphProperty,ee as executeDeleteNamedType,me as executeFindPaths,fe as executeFindPathsAsynchronous,se as executeQuery,ce as executeQueryStreaming,pe as executeSearch,le as executeSearchStreaming,Ge as executeUpdateDomain,ne as executeUpdateGraphProperty,te as executeUpdateNamedType,ie as executeUpdateSearchIndex,ue as fetchAllClientDataKeys,_e as fetchAsynchronousFindPathsResultData,he as fetchClientDataAtKeys,we as fetchKnowledgeGraph,Y as kgRestServices,ge as refreshDataModel,ye as refreshServiceDefinition};