@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 3.38 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"../../../core/Logger.js";import t from"../../../geometry/SpatialReference.js";import r from"../Entity.js";import n from"../GraphObject.js";import o from"../GraphQueryResultHeader.js";import s from"../ObjectValue.js";import a from"../Path.js";import u from"../Relationship.js";import{WasmGeometryTypeCodes as i}from"./KnowledgeWasmInterface.js";import{WasmGraphQueryResponseTypeCodes as c}from"./WasmQueryWrapperInterfaces.js";import{wasmToPolygonGeometry as l,wasmToPolylineGeometry as p,wasmToMultipointGeometry as _,wasmToPointGeometry as d}from"./wasmToGeometryFactories.js";const m=()=>e.getLogger("esri.rest.knowledgeGraph.WasmToQueryResponseObjConstructors"),f={decodedWasmObjToQueryResponseObj:(e,t,r)=>{if(null==e)return null;if("object"!=typeof e)return e;if("getDate"in e)return e;if("geometry_type"in e)switch(e.geometry_type.value){case null:return null;case i.ESRI_GEOMETRY_POINT:return d(e,r);case i.ESRI_GEOMETRY_MULTIPOINT:return _(e,r);case i.ESRI_GEOMETRY_POLYLINE:return p(e,r);case i.ESRI_GEOMETRY_POLYGON:return l(e,r);case i.ESRI_GEOMETRY_ENVELOPE:case i.ESRI_GEOMETRY_MULTI_PATCH:return m().warnOnce("Envelope and Multipatch are not supported on knowledge entities, but one of those geometry types was detected. Result interpreted as null"),null;case i.ESRI_GEOMETRY_NULL:case i.ESRI_GEOMETRY_ANY:default:return m().warnOnce("Unknown or blank geometry type returned - Result interpreted as null"),null}else{if(!("object_value_type"in e))return m().warnOnce("A decoded value came back of a type that is not supported. Result interpreted as null"),null;switch(e.object_value_type.value){case c.OBJECT:return j(e,t,r);case c.ENTITY:return g(e,t,r);case c.RELATIONSHIP:return h(e,t,r);case c.PATH:return T(e,t,r);case c.ARRAY:return y(e,t,r);default:return m().warnOnce("Unknown graph object type detected! Result interpreted as null"),null}}}};function y(e,t,r){const n=[],o=e.count();for(let s=0;s<o;s++){const o=e.get_value_at(s);n.push(E(o,t,r))}return n}function E(e,t,r){return f.decodedWasmObjToQueryResponseObj(e,t,r)}function g(e,t,n){const o=e.type_name,s=O(e,t,n),a=e.get_id();return new r(Object.assign({typeName:o,id:a},s))}function R(e,t,r){return new n(O(e,t,r))}function O(e,t,r){const n={},o=e.key_count();for(let s=0;s<o;s++)n[e.get_key_at(s)]=E(e.get_value_at(s),t,r);return{properties:n}}function j(e,t,r){return new s(O(e,t,r))}function T(e,t,r){const n=e.entity_count(),o=e.relationship_count(),s=[];for(let a=0;a<n;a++)s.push(g(e.get_entity_at(a),t,r)),a<o&&s.push(h(e.get_relationship_at(a),t,r));return new a({path:s})}function h(e,t,r){const n=e.type_name,o=O(e,t,r);return new u(Object.assign({typeName:n,id:e.get_id(),originId:e.get_origin_entity_id(),destinationId:e.get_destination_entity_id()},o))}function w(e){const r=[];for(let t=0;t<e.get_header_keys().size();t++)r.push(e.get_header_keys().get(t));const n=new t(e.get_out_sr());return new o({headerKeys:r,outSpatialReference:n,exceededTransferLimit:e.exceeded_transfer_limit()})}export{f as decodeWasmObjectTest,E as decodedWasmObjToQueryResponseObj,y as wasmArrayToArray,g as wasmToEntity,R as wasmToGraphObject,w as wasmToGraphQueryResponseHeader,j as wasmToObjectValue,T as wasmToPath,h as wasmToRelationship};