@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.66 kB
JavaScript
import e from"../../../core/Logger.js";import t from"../Entity.js";import n from"../GraphObject.js";import r from"../ObjectValue.js";import o from"../Path.js";import s from"../Relationship.js";import{WasmGeometryTypeCodes as u}from"./KnowledgeWasmInterface.js";import{WasmGraphQueryResponseTypeCodes as a}from"./WasmQueryWrapperInterfaces.js";import{wasmToPolygonGeometry as i,wasmToPolylineGeometry as c,wasmToMultipointGeometry as l,wasmToPointGeometry as p}from"./wasmToGeometryFactories.js";const _=e.getLogger("esri.rest.knowledgeGraph.WasmToQueryResponseObjConstructors");function E(e,t){const n=[],r=e.count();for(let o=0;o<r;o++){const t=e.get_value_at(o);n.push(f(t))}return n}function f(e,t){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 u.ESRI_GEOMETRY_POINT:return p(e);case u.ESRI_GEOMETRY_MULTIPOINT:return l(e);case u.ESRI_GEOMETRY_POLYLINE:return c(e);case u.ESRI_GEOMETRY_POLYGON:return i(e);case u.ESRI_GEOMETRY_ENVELOPE:case u.ESRI_GEOMETRY_MULTI_PATCH:return _.warnOnce("Envelope and Multipatch are not supported on knowledge entities, but one of those geometry types was detected. Result interpreted as null"),null;case u.ESRI_GEOMETRY_NULL:case u.ESRI_GEOMETRY_ANY:default:return _.warnOnce("Unknown or blank geometry type returned - Result interpreted as null"),null}else{if(!("object_value_type"in e))return _.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 a.OBJECT:return y(e);case a.ENTITY:return m(e);case a.RELATIONSHIP:return R(e);case a.PATH:return O(e);case a.ARRAY:return E(e);default:return _.warnOnce("Unknown graph object type detected! Result interpreted as null"),null}}}function m(e,n){const r=e.type_name,o=g(e),s=e.get_id();return new t(Object.assign({typeName:r,id:s},o))}function d(e,t){return new n(g(e))}function g(e,t){const n={},r=e.key_count();for(let o=0;o<r;o++)n[e.get_key_at(o)]=f(e.get_value_at(o));return{properties:n}}function y(e,t){return new r(g(e))}function O(e,t){const n=e.entity_count(),r=e.relationship_count(),s=[];for(let o=0;o<n;o++)s.push(m(e.get_entity_at(o))),o<r&&s.push(R(e.get_relationship_at(o)));return new o({path:s})}function R(e,t){const n=e.type_name,r=g(e);return new s(Object.assign({typeName:n,id:e.get_id(),originId:e.get_origin_entity_id(),destinationId:e.get_destination_entity_id()},r))}export{f as decodedWasmObjToQueryResponseObj,E as wasmArrayToArray,m as wasmToEntity,d as wasmToGraphObject,y as wasmToObjectValue,O as wasmToPath,R as wasmToRelationship};