UNPKG

@doegis/core

Version:

DOE GIS API

3 lines (1 loc) 13.3 kB
import t from"../ArcadePortal.js";import e from"../Attachment.js";import r from"../Dictionary.js";import{ArcadeExecutionError as n,ExecutionErrorCodes as a}from"../executionError.js";import{y as o,j as i,B as u,g as s,M as l,v as d,A as c,h as p,t as f,m as h,x as y,L as m,w as g,N as A,C as w,O as I,P as v,Q as U,S as b,c as x,k as j,a as N,b as P,i as F,T as C,U as O}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as T}from"../featureset/support/shared.js";import{convertDirection as L}from"./convertdirection.js";import{XXH as k}from"./hash.js";import S from"../../geometry/Extent.js";import z from"../../geometry/Multipoint.js";import R from"../../geometry/Point.js";import D from"../../geometry/Polygon.js";import M from"../../geometry/Polyline.js";import H from"../../geometry/SpatialReference.js";import{hasSamePortal as J}from"../../core/urlUtils.js";function W(t){if("loaded"===t.loadStatus&&t.user&&t.user.sourceJSON){return t.user.sourceJSON}return null}function B(t,e){return!!t&&J(t,e?.restUrl||"")}function V(t,e){if(!t||!e)return t===e;if(t.x===e.x&&t.y===e.y){if(t.hasZ){if(t.z!==e.z)return!1}else if(e.hasZ)return!1;if(t.hasM){if(t.m!==e.m)return!1}else if(e.hasM)return!1;return!0}return!1}function E(o,i,u){if(null!==o)if(h(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o)E(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else if(y(o)){if(i.updateUint8Array([61]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.toArray())E(t,i,u);u.map.delete(o),u.currentLength--}i.updateUint8Array([199])}else{if(j(o))return i.updateIntArray([o.toNumber()]),void i.updateUint8Array([241]);if(x(o))return i.updateIntArray([o.length]),i.updateWithString(o),void i.updateUint8Array([41]);if(N(o))i.updateUint8Array([!0===o?1:0,113]);else{if(P(o))return i.updateFloatArray([o]),void i.updateUint8Array([173]);if(o instanceof e)throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof t)throw new n(u.context,a.UnsupportedHashType,u.node);if(!(o instanceof r)){if(g(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o instanceof R)return i.updateIntArray([3833836621]),i.updateIntArray([0]),i.updateFloatArray([o.x]),i.updateIntArray([1]),i.updateFloatArray([o.y]),o.hasZ&&(i.updateIntArray([2]),i.updateFloatArray([o.z])),o.hasM&&(i.updateIntArray([3]),i.updateFloatArray([o.m])),i.updateIntArray([3765347959]),void E(o.spatialReference.wkid,i,u);if(o instanceof D){i.updateIntArray([1266616829]);for(let t=0;t<o.rings.length;t++){const e=o.rings[t],r=[];let n=null,a=null;for(let i=0;i<e.length;i++){const u=o.getPoint(t,i);if(0===i)n=u;else if(V(a,u))continue;a=u,i===e.length-1&&V(n,u)||r.push(u)}i.updateIntArray([1397116793,r.length]);for(let t=0;t<r.length;t++){const e=r[t];i.updateIntArray([3962308117,t]),E(e,i,u),i.updateIntArray([2716288009])}i.updateIntArray([2278822459])}return i.updateIntArray([3878477243]),void E(o.spatialReference.wkid,i,u)}if(o instanceof M){i.updateIntArray([4106883559]);for(let t=0;t<o.paths.length;t++){const e=o.paths[t];i.updateIntArray([1397116793,e.length]);for(let r=0;r<e.length;r++)i.updateIntArray([3962308117,r]),E(o.getPoint(t,r),i,u),i.updateIntArray([2716288009]);i.updateIntArray([2278822459])}return i.updateIntArray([2568784753]),void E(o.spatialReference.wkid,i,u)}if(o instanceof z){i.updateIntArray([588535921,o.points.length]);for(let t=0;t<o.points.length;t++){const e=o.getPoint(t);i.updateIntArray([t]),E(e,i,u)}return i.updateIntArray([1700171621]),void E(o.spatialReference.wkid,i,u)}if(o instanceof S)return i.updateIntArray([3483648373]),i.updateIntArray([0]),i.updateFloatArray([o.xmax]),i.updateIntArray([1]),i.updateFloatArray([o.xmin]),i.updateIntArray([2]),i.updateFloatArray([o.ymax]),i.updateIntArray([3]),i.updateFloatArray([o.ymin]),o.hasZ&&(i.updateIntArray([4]),i.updateFloatArray([o.zmax]),i.updateIntArray([5]),i.updateFloatArray([o.zmin])),o.hasM&&(i.updateIntArray([6]),i.updateFloatArray([o.mmax]),i.updateIntArray([7]),i.updateFloatArray([o.mmin])),i.updateIntArray([3622027469]),void E(o.spatialReference.wkid,i,u);if(o instanceof H)return i.updateIntArray([14]),void 0!==o.wkid&&null!==o.wkid&&i.updateIntArray([o.wkid]),void(o.wkt&&i.updateWithString(o.wkt));if(F(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(C(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(O(o))throw new n(u.context,a.UnsupportedHashType,u.node);if(o===d)throw new n(u.context,a.UnsupportedHashType,u.node);throw new n(u.context,a.UnsupportedHashType,u.node)}if(i.updateUint8Array([223]),u.map.has(o)){const t=u.map.get(o);i.updateIntArray([61237541^t])}else{u.map.set(o,u.currentLength++);for(const t of o.keys()){i.updateIntArray([t.length]),i.updateWithString(t),i.updateUint8Array([251]);E(o.field(t),i,u),i.updateUint8Array([239])}u.map.delete(o),u.currentLength--}i.updateUint8Array([73])}}else i.updateUint8Array([0,139])}function Z(e,j){e.portal=function(e,r){return j(e,r,((n,a,u)=>(o(u,1,1,e,r),new t(i(u[0])))))},e.typeof=function(t,e){return j(t,e,((r,i,s)=>{o(s,1,1,t,e);const l=u(s[0]);if("Unrecognised Type"===l)throw new n(t,a.UnrecognisedType,e);return l}))},e.trim=function(t,e){return j(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).trim())))},e.tohex=function(t,e){return j(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=s(a[0]);return isNaN(i)?i:i.toString(16)}))},e.upper=function(t,e){return j(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toUpperCase())))},e.proper=function(t,e){return j(t,e,((r,n,a)=>{o(a,1,2,t,e);let u=1;2===a.length&&"firstword"===i(a[1]).toLowerCase()&&(u=2);const s=/\s/,l=i(a[0]);let d="",c=!0;for(let t=0;t<l.length;t++){let e=l[t];if(s.test(e))1===u&&(c=!0);else{e.toUpperCase()!==e.toLowerCase()&&(c?(e=e.toUpperCase(),c=!1):e=e.toLowerCase())}d+=e}return d}))},e.lower=function(t,e){return j(t,e,((r,n,a)=>(o(a,1,1,t,e),i(a[0]).toLowerCase())))},e.guid=function(t,e){return j(t,e,((r,n,a)=>{if(o(a,0,1,t,e),a.length>0)switch(i(a[0]).toLowerCase()){case"digits":return l().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return l();case"digits-hyphen-braces":return"{"+l()+"}";case"digits-hyphen-parentheses":return"("+l()+")"}return"{"+l()+"}"}))},e.standardizeguid=function(t,e){return j(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=i(a[0]);if(""===u||null===u)return"";const s=/^(\{|\()?(?<partA>[0-9a-z]{8})(\-?)(?<partB>[0-9a-z]{4})(\-?)(?<partC>[0-9a-z]{4})(\-?)(?<partD>[0-9a-z]{4})(\-?)(?<partE>[0-9a-z]{12})(\}|\))?$/gim.exec(u);if(!s)return"";const l=s.groups;switch(u=l.partA+"-"+l.partB+"-"+l.partC+"-"+l.partD+"-"+l.partE,i(a[1]).toLowerCase()){case"digits":return u.replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return u;case"digits-hyphen-braces":return"{"+u+"}";case"digits-hyphen-parentheses":return"("+u+")"}return"{"+u+"}"}))},e.console=function(t,e){return j(t,e,((e,r,n)=>(0===n.length||(1===n.length?t.console(i(n[0])):t.console(i(n))),d)))},e.mid=function(t,e){return j(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=s(a[1]);if(isNaN(u))return"";if(u<0&&(u=0),2===a.length)return i(a[0]).substr(u);let l=s(a[2]);return isNaN(l)?"":(l<0&&(l=0),i(a[0]).substr(u,l))}))},e.find=function(t,e){return j(t,e,((r,n,a)=>{o(a,2,3,t,e);let u=0;if(a.length>2){if(u=s(c(a[2],0)),isNaN(u))return-1;u<0&&(u=0)}return i(a[1]).indexOf(i(a[0]),u)}))},e.left=function(t,e){return j(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(0,u))}))},e.right=function(t,e){return j(t,e,((r,n,a)=>{o(a,2,2,t,e);let u=s(a[1]);return isNaN(u)?"":(u<0&&(u=0),i(a[0]).substr(-1*u,u))}))},e.split=function(t,e){return j(t,e,((r,n,a)=>{let u;o(a,2,4,t,e);let l=s(c(a[2],-1));const d=p(c(a[3],!1));if(-1===l||null===l||!0===d?u=i(a[0]).split(i(a[1])):(isNaN(l)&&(l=-1),l<-1&&(l=-1),u=i(a[0]).split(i(a[1]),l)),!1===d)return u;const f=[];for(let t=0;t<u.length&&!(-1!==l&&f.length>=l);t++)""!==u[t]&&void 0!==u[t]&&f.push(u[t]);return f}))},e.text=function(t,e){return j(t,e,((r,n,a)=>(o(a,1,2,t,e),f(a[0],a[1]))))},e.concatenate=function(t,e){return j(t,e,((t,e,r)=>{const n=[];if(r.length<1)return"";if(h(r[0])){const t=c(r[2],"");for(let e=0;e<r[0].length;e++)n[e]=f(r[0][e],t);return r.length>1?n.join(r[1]):n.join("")}if(y(r[0])){const t=c(r[2],"");for(let e=0;e<r[0].length();e++)n[e]=f(r[0].get(e),t);return r.length>1?n.join(r[1]):n.join("")}for(let a=0;a<r.length;a++)n[a]=f(r[a]);return n.join("")}))},e.reverse=function(t,e){return j(t,e,((r,i,u)=>{if(o(u,1,1,t,e),h(u[0])){const t=u[0].slice(0);return t.reverse(),t}if(y(u[0])){const t=u[0].toArray().slice(0);return t.reverse(),t}throw new n(t,a.InvalidParameter,e)}))},e.replace=function(t,e){return j(t,e,((r,n,a)=>{o(a,3,4,t,e);const u=i(a[0]),s=i(a[1]),l=i(a[2]);return 4!==a.length||p(a[3])?m(u,s,l):u.replace(s,l)}))},e.schema=function(t,e){return j(t,e,((o,i,u)=>{if(g(u[0])){const e=A(u[0]);return e?r.convertObjectToArcadeDictionary(e,w(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypes=function(t,e){return j(t,e,((i,u,s)=>{if(o(s,1,1,t,e),g(s[0])){const e=I(s[0]);return e?r.convertObjectToArcadeDictionary(e,w(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.subtypecode=function(t,e){return j(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0])){const t=I(u[0]);if(!t)return null;if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.code;return null}return null}throw new n(t,a.InvalidParameter,e)}))},e.subtypename=function(t,e){return j(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0])){const t=I(u[0]);if(!t)return"";if(t.subtypeField&&u[0].hasField(t.subtypeField)){const e=u[0].field(t.subtypeField);for(const r of t.subtypes)if(r.code===e)return r.name;return""}return""}throw new n(t,a.InvalidParameter,e)}))},e.gdbversion=function(t,e){return j(t,e,((r,i,u)=>{if(o(u,1,1,t,e),g(u[0]))return u[0].gdbVersion();throw new n(t,a.InvalidParameter,e)}))},e.domain=function(t,e){return j(t,e,((u,l,d)=>{if(o(d,2,3,t,e),g(d[0])){const e=v(d[0],i(d[1]),void 0===d[2]?void 0:s(d[2]));return e&&e.domain?"coded-value"===e.domain.type||"codedValue"===e.domain.type?r.convertObjectToArcadeDictionary({type:"codedValue",name:e.domain.name,dataType:T[e.field.type],codedValues:e.domain.codedValues.map((t=>({name:t.name,code:t.code})))},w(t)):r.convertObjectToArcadeDictionary({type:"range",name:e.domain.name,dataType:T[e.field.type],min:e.domain.min,max:e.domain.max},w(t)):null}throw new n(t,a.InvalidParameter,e)}))},e.domainname=function(t,e){return j(t,e,((r,u,l)=>{if(o(l,2,4,t,e),g(l[0]))return U(l[0],i(l[1]),l[2],void 0===l[3]?void 0:s(l[3]));throw new n(t,a.InvalidParameter,e)}))},e.domaincode=function(t,e){return j(t,e,((r,u,l)=>{if(o(l,2,4,t,e),g(l[0]))return b(l[0],i(l[1]),l[2],void 0===l[3]?void 0:s(l[3]));throw new n(t,a.InvalidParameter,e)}))},e.urlencode=function(t,e){return j(t,e,((n,a,u)=>{if(o(u,1,1,t,e),null===u[0])return"";if(u[0]instanceof r){let t="";for(const e of u[0].keys()){const r=u[0].field(e);""!==t&&(t+="&"),t+=null===r?encodeURIComponent(e)+"=":encodeURIComponent(e)+"="+encodeURIComponent(r)}return t}return encodeURIComponent(i(u[0]))}))},e.hash=function(t,e){return j(t,e,((r,n,a)=>{o(a,1,1,t,e);const i=new k(0);return E(a[0],i,{context:t,node:e,map:new Map,currentLength:0}),i.digest()}))},e.convertdirection=function(t,e){return j(t,e,((r,n,a)=>(o(a,3,3,t,e),L(a[0],a[1],a[2]))))},e.fromjson=function(t,e){return j(t,e,((u,s,l)=>{if(o(l,1,1,t,e),!1===x(l[0]))throw new n(t,a.InvalidParameter,e);return r.convertJsonToArcade(JSON.parse(i(l[0])),w(t))}))},e.expects=function(t,e){return j(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);return d}))},e.tocharcode=function(t,e){return j(t,e,((r,u,l)=>{o(l,1,2,t,e);const d=s(c(l[1],0)),p=i(l[0]);if(0===p.length&&1===l.length)return null;if(p.length<=d||d<0)throw new n(t,a.OutOfBounds,e);return p.charCodeAt(d)}))},e.tocodepoint=function(t,e){return j(t,e,((r,u,l)=>{o(l,1,2,t,e);const d=s(c(l[1],0)),p=i(l[0]);if(0===p.length&&1===l.length)return null;if(p.length<=d||d<0)throw new n(t,a.OutOfBounds,e);return p.codePointAt(d)}))},e.fromcharcode=function(t,e){return j(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);const u=i.map((t=>Math.trunc(s(t)))).filter((t=>t>=0&&t<=65535));return 0===u.length?null:String.fromCharCode.apply(null,u)}))},e.fromcodepoint=function(t,e){return j(t,e,((r,o,i)=>{if(i.length<1)throw new n(t,a.WrongNumberOfParameters,e);let u;try{u=i.map((t=>Math.trunc(s(t)))).filter((t=>t<=1114111&&t>>>0===t))}catch(l){return null}return 0===u.length?null:String.fromCodePoint.apply(null,u)}))},e.getuser=function(e,u){return j(e,u,((s,l,d)=>{o(d,0,2,e,u);let p=c(d[1],"");if(p=!0===p||!1===p?"":i(p),null!==p&&""!==p)return null;if(0===d.length||d[0]instanceof t){let t=null;if(e.services&&e.services.portal&&(t=e.services.portal),d.length>0){if(!B(d[0].field("url"),t))return null}if(!t)return null;if(""===p){const n=W(t);if(n){const t=JSON.parse(JSON.stringify(n));for(const e of["lastLogin","created","modified"])void 0!==t[e]&&null!==t[e]&&(t[e]=new Date(t[e]));return r.convertObjectToArcadeDictionary(t,w(e))}}return null}throw new n(e,a.InvalidParameter,u)}))}}export{Z as registerFunctions};