@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.8 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import e from"../../config.js";import r from"../ArcadePortal.js";import t from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as o}from"../executionError.js";import{B as a,w as i,o as s,J as p,K as l,e as c,f,g as u,n as m,h as d}from"../../chunks/languageUtils.js";import{getPortal as h}from"../portalUtils.js";import g from"../../geometry/Geometry.js";import{load as w,project as y,isLoaded as j}from"../../geometry/projectionUtils.js";import S from"../../geometry/SpatialReference.js";import{webMercatorToGeographic as v,geographicToWebMercator as R}from"../../geometry/support/webMercatorUtils.js";import G from"../../portal/Portal.js";import x from"../../portal/PortalItem.js";import{project as k}from"../../rest/geometryService/project.js";import P from"../../rest/knowledgeGraph/Entity.js";import b from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import I from"../../rest/knowledgeGraph/ObjectValue.js";import W from"../../rest/knowledgeGraph/Path.js";import D from"../../rest/knowledgeGraph/Relationship.js";import T from"../../rest/support/ProjectParameters.js";import{isString as U,isArray as q,isNumber as A,isDate as J}from"../../support/guards.js";let N=null;async function F(r){const t=e.geometryServiceUrl??"";if(!t){j()||await w();for(const e of r)e.container[e.indexer]=y(e.container[e.indexer],S.WGS84);return}const n=r.map((e=>e.container[e.indexer])),o=new T({geometries:n,outSpatialReference:S.WGS84}),a=await k(t,o);for(let e=0;e<a.length;e++){const t=r[e];t.container[t.indexer]=a[e]}}async function M(e,r){const t=new x({portal:e,id:r});return await t.load(),null===N&&(N=await import("../../rest/knowledgeGraphService.js")),await N.fetchKnowledgeGraph(t.url)}function Q(e,r,t,n,o){if(null===e)return null;if(U(e)||A(e))return e;if(c(e))return e.toJSDate();if(c(e))return e.toJSDate();if(f(e))return e.toStorageFormat();if(u(e))return e.toStorageString();if(m(e)){const a={};for(const i of e.keys())a[i]=Q(e.field(i),r,t,n,o),a[i]instanceof g&&o.push({container:a,indexer:i});return a}if(q(e)){const a=e.map((e=>Q(e,r,t,n,o)));for(let e=0;e<a.length;e++)a[e]instanceof g&&o.push({container:a,indexer:e});return a}return d(e)?e.spatialReference.isWGS84?e:e.spatialReference.isWebMercator&&r?v(e):e:void 0}function B(e,r){if(!e)return e;if(e.spatialReference.isWGS84&&r.spatialReference.isWebMercator)return R(e);if(e.spatialReference.equals(r.spatialReference))return e;throw new n(r,o.WrongSpatialReference,null)}function E(e,r){if(!e)return null;const t={};for(const n in e)t[n]=K(e[n],r);return t}function K(e,r){return null===e?null:q(e)?e.map((e=>K(e,r))):e instanceof P?{graphTypeName:e.typeName,id:e.id,graphType:"entity",properties:E(e.properties,r)}:e instanceof I?{graphType:"object",properties:E(e.properties,r)}:e instanceof D?{graphTypeName:e.typeName,id:e.id,graphType:"relationship",originId:e.originId??null,destinationId:e.destinationId??null,properties:E(e.properties,r)}:e instanceof W?{graphType:"path",path:e.path?e.path.map((e=>K(e,r))):null}:d(e)?B(e,r):U(e)||A(e)||J(e)?e:null}function V(e){"async"===e.mode&&(e.functions.knowledgegraphbyportalitem=function(t,s){return e.standardFunctionAsync(t,s,((e,p,l)=>{if(a(l,2,2,t,s),null===l[0])throw new n(t,o.PortalRequired,s);if(l[0]instanceof r){const e=i(l[1]);let r;r=t.services?.portal?t.services.portal:G.getDefault();return M(h(l[0],r),e)}if(!1===U(l[0]))throw new n(t,o.InvalidParameter,s);const c=i(l[0]);return M(t.services?.portal??G.getDefault(),c)}))},e.signatures.push({name:"knowledgegraphbyportalitem",min:2,max:2}),e.functions.querygraph=function(r,i){return e.standardFunctionAsync(r,i,(async(e,c,f)=>{a(f,2,4,r,i);const u=f[0];if(!s(u))throw new n(r,o.InvalidParameter,i);const m=f[1];if(!U(m))throw new n(r,o.InvalidParameter,i);null===N&&(N=await import("../../rest/knowledgeGraphService.js"));let d=null;const h=p(f[2],null);if(!(h instanceof t||null===h))throw new n(r,o.InvalidParameter,i);if(h){let e=[];d=Q(h,!0,!1,r,e),e=e.filter((e=>!e.container[e.indexer].spatialReference.isWGS84)),e.length>0&&await F(e)}const g=p(f[3],!1),w=new b({openCypherQuery:m,bindParameters:d,provenanceBehavior:g?"include":"exclude"});(u?.serviceDefinition?.currentVersion??11.3)>11.2&&(w.outputSpatialReference=r.spatialReference);const y=(await N.executeQueryStreaming(u,w)).resultRowsStream.getReader(),j=[];try{for(;;){const{done:e,value:t}=await y.read();if(e)break;if(q(t))for(const n of t)j.push(K(n,r));else{const e=[];for(const n of t)e.push(K(t[n],r));j.push(e)}}}catch(S){throw S}return t.convertJsonToArcade(j,l(r),!1,!0)}))},e.signatures.push({name:"querygraph",min:2,max:4}))}export{V as registerFunctions};