@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 17.2 kB
JavaScript
import{ArcadeFunction as e}from"../arcade/FunctionWrapper.js";import n from"../arcade/ImmutableArray.js";import t from"../arcade/ImmutablePathArray.js";import r from"../arcade/ImmutablePointArray.js";import{ArcadeDate as a,createDateTimeZone as i}from"../arcade/ArcadeDate.js";import o from"../geometry/Extent.js";import l from"../geometry/Geometry.js";import u from"../geometry/Multipoint.js";import s from"../geometry/Point.js";import f from"../geometry/Polygon.js";import c from"../geometry/Polyline.js";import{DateTime as m}from"luxon";import{isNone as d}from"../core/maybe.js";import{format as y,parse as p}from"../core/number.js";import{isClockwise as h}from"../geometry/support/coordsUtils.js";import{getLocale as g}from"../intl/locale.js";import{esriFieldToJson as b,layerGeometryEsriRestConstants as x}from"../arcade/featureset/support/shared.js";import{ArcadeModule as S}from"../arcade/ArcadeModule.js";import{ArcadeExecutionError as N,ExecutionErrorCodes as T}from"../arcade/executionError.js";class M{constructor(e){this.value=e}}class k{constructor(e){this.value=e}}const j=k,A=M,R={type:"VOID"},D={type:"BREAK"},F={type:"CONTINUE"};function I(e,n,t){return""===n||null==n||n===t||n===t?e:e=e.split(n).join(t)}function C(n){return n instanceof e}function w(e){return e instanceof S}function O(e){return!!v(e)||(!!Y(e)||(!!U(e)||(!!L(e)||(null===e||(e===R||"number"==typeof e)))))}function Z(e,n){return void 0===e?n:e}function _(e){return null==e?"":J(e)||V(e)?"Array":U(e)?"Date":v(e)?"String":L(e)?"Boolean":Y(e)?"Number":"esri.arcade.Attachment"===e?.declaredClass?"Attachment":"esri.arcade.Portal"===e?.declaredClass?"Portal":"esri.arcade.Dictionary"===e?.declaredClass?"Dictionary":e instanceof S?"Module":z(e)?"Feature":e instanceof s?"Point":e instanceof f?"Polygon":e instanceof c?"Polyline":e instanceof u?"Multipoint":e instanceof o?"Extent":C(e)?"Function":G(e)?"FeatureSet":E(e)?"FeatureSetCollection":e===R?"":"number"==typeof e&&isNaN(e)?"Number":"Unrecognised Type"}function v(e){return"string"==typeof e||e instanceof String}function L(e){return"boolean"==typeof e}function Y(e){return"number"==typeof e}function P(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}function J(e){return e instanceof Array}function z(e){return"esri.arcade.Feature"===e?.arcadeDeclaredClass}function G(e){return"esri.arcade.featureset.support.FeatureSet"===e?.declaredRootClass}function E(e){return"esri.arcade.featureSetCollection"===e?.declaredRootClass}function V(e){return e instanceof n}function U(e){return e instanceof a}function H(e){return null!=e&&"object"==typeof e}function q(e){return e instanceof Date}function B(e,n,t,r,a){if(e.length<n||e.length>t)throw new N(r,T.WrongNumberOfParameters,a)}function W(e){return e<0?-Math.round(-e):Math.round(e)}function $(){let e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(n=>{const t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===n?t:3&t|8).toString(16)}))}function Q(e,n){return isNaN(e)||null==n||""===n?e.toString():(n=I(n,"‰",""),n=I(n,"¤",""),y(e,{pattern:n}))}function X(e,n){return null==n||""===n?e.toISOString(!0):e.toFormat(K(n),{locale:g(),numberingSystem:"latn"})}function K(e){e=e.replace(/LTS|LT|LL?L?L?|l{1,4}/g,"[$&]");let n="";const t=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;for(const r of e.match(t)||[])switch(r){case"D":n+="d";break;case"DD":n+="dd";break;case"DDD":n+="o";break;case"d":n+="c";break;case"ddd":n+="ccc";break;case"dddd":n+="cccc";break;case"M":n+="L";break;case"MM":n+="LL";break;case"MMM":n+="LLL";break;case"MMMM":n+="LLLL";break;case"YY":n+="yy";break;case"Y":case"YYYY":n+="yyyy";break;case"Q":n+="q";break;case"Z":n+="ZZ";break;case"ZZ":n+="ZZZ";break;case"S":n+="'S'";break;case"SS":n+="'SS'";break;case"SSS":n+="u";break;case"A":case"a":n+="a";break;case"m":case"mm":case"h":case"hh":case"H":case"HH":case"s":case"ss":case"X":case"x":n+=r;break;default:r.length>=2&&"["===r.slice(0,1)&&"]"===r.slice(-1)?n+=`'${r.slice(1,-1)}'`:n+=`'${r}'`}return n}function ee(e,n,t){switch(t){case">":return e>n;case"<":return e<n;case">=":return e>=n;case"<=":return e<=n}return!1}function ne(e,n,t){if(null===e){if(null===n||n===R)return ee(null,null,t);if(Y(n))return ee(0,n,t);if(v(n))return ee(0,le(n),t);if(L(n))return ee(0,le(n),t);if(U(n))return ee(0,n.toNumber(),t)}if(e===R){if(null===n||n===R)return ee(null,null,t);if(Y(n))return ee(0,n,t);if(v(n))return ee(0,le(n),t);if(L(n))return ee(0,le(n),t);if(U(n))return ee(0,n.toNumber(),t)}else if(Y(e)){if(Y(n))return ee(e,n,t);if(L(n))return ee(e,le(n),t);if(null===n||n===R)return ee(e,0,t);if(v(n))return ee(e,le(n),t);if(U(n))return ee(e,n.toNumber(),t)}else if(v(e)){if(v(n))return ee(re(e),re(n),t);if(U(n))return ee(le(e),n.toNumber(),t);if(Y(n))return ee(le(e),n,t);if(null===n||n===R)return ee(le(e),0,t);if(L(n))return ee(le(e),le(n),t)}else if(U(e)){if(U(n))return ee(e.toNumber(),n.toNumber(),t);if(null===n||n===R)return ee(e.toNumber(),0,t);if(Y(n))return ee(e.toNumber(),n,t);if(L(n))return ee(e.toNumber(),le(n),t);if(v(n))return ee(e.toNumber(),le(n),t)}else if(L(e)){if(L(n))return ee(e,n,t);if(Y(n))return ee(le(e),le(n),t);if(U(n))return ee(le(e),n.toNumber(),t);if(null===n||n===R)return ee(le(e),0,t);if(v(n))return ee(le(e),le(n),t)}return!!te(e,n)&&("<="===t||">="===t)}function te(e,n){if(e===n)return!0;if(null===e&&n===R||null===n&&e===R)return!0;if(U(e)&&U(n))return e.equals(n);if(e instanceof t)return e.equalityTest(n);if(e instanceof r)return e.equalityTest(n);if(e instanceof s&&n instanceof s){const t=e.cache._arcadeCacheId,r=n.cache._arcadeCacheId;if(null!=t)return t===r}if(H(e)&&H(n)){if(e._arcadeCacheId===n._arcadeCacheId&&void 0!==e._arcadeCacheId&&null!==e._arcadeCacheId)return!0;if(e._underlyingGraphic===n._underlyingGraphic&&void 0!==e._underlyingGraphic&&null!==e._underlyingGraphic)return!0}return!1}function re(e,t){if(v(e))return e;if(null===e)return"";if(Y(e))return Q(e,t);if(L(e))return e.toString();if(U(e))return X(e,t);if(e instanceof l)return JSON.stringify(e.toJSON());if(J(e)){const n=[];for(let t=0;t<e.length;t++)n[t]=oe(e[t]);return"["+n.join(",")+"]"}if(e instanceof n){const n=[];for(let t=0;t<e.length();t++)n[t]=oe(e.get(t));return"["+n.join(",")+"]"}return null!==e&&"object"==typeof e&&void 0!==e.castToText?e.castToText():C(e)?"object, Function":e===R?"":w(e)?"object, Module":""}function ae(e){const t=[];if(!J(e))return null;if(e instanceof n){for(let n=0;n<e.length();n++)t[n]=le(e.get(n));return t}for(let n=0;n<e.length;n++)t[n]=le(e[n]);return t}function ie(e,t,r=!1){if(v(e))return e;if(null===e)return"";if(Y(e))return Q(e,t);if(L(e))return e.toString();if(U(e))return X(e,t);if(e instanceof l)return e instanceof o?'{"xmin":'+e.xmin.toString()+',"ymin":'+e.ymin.toString()+","+(e.hasZ?'"zmin":'+e.zmin.toString()+",":"")+(e.hasM?'"mmin":'+e.mmin.toString()+",":"")+'"xmax":'+e.xmax.toString()+',"ymax":'+e.ymax.toString()+","+(e.hasZ?'"zmax":'+e.zmax.toString()+",":"")+(e.hasM?'"mmax":'+e.mmax.toString()+",":"")+'"spatialReference":'+ge(e.spatialReference)+"}":ge(e.toJSON(),((e,n)=>e.key===n.key?0:"spatialReference"===e.key?1:"spatialReference"===n.key||e.key<n.key?-1:e.key>n.key?1:0));if(J(e)){const n=[];for(let t=0;t<e.length;t++)n[t]=oe(e[t],r);return"["+n.join(",")+"]"}if(e instanceof n){const n=[];for(let t=0;t<e.length();t++)n[t]=oe(e.get(t),r);return"["+n.join(",")+"]"}return null!==e&&"object"==typeof e&&void 0!==e.castToText?e.castToText(r):C(e)?"object, Function":e===R?"":w(e)?"object, Module":""}function oe(e,t=!1){if(null===e)return"null";if(L(e)||Y(e)||v(e))return JSON.stringify(e);if(e instanceof l)return ie(e,null,t);if(e instanceof n)return ie(e,null,t);if(e instanceof Array)return ie(e,null,t);if(U(e))return t?JSON.stringify(e.getTime()):JSON.stringify(X(e,""));if(null!==e&&"object"==typeof e){if(void 0!==e.castToText)return e.castToText(t)}else if(e===R)return"null";return"null"}function le(e,n){return Y(e)?e:null===e||""===e?0:U(e)?NaN:L(e)?e?1:0:J(e)||""===e||void 0===e?NaN:void 0!==n&&v(e)?(n=I(n,"‰",""),n=I(n,"¤",""),p(e,{pattern:n})):e===R?0:Number(e)}function ue(e,n){if(U(e))return e;if(v(e)){const t=se(e,n);if(t)return a.dateTimeToArcadeDate(t)}return null}function se(e,n){const t=/ (\d\d)/,r=i(n);let a=m.fromISO(e,{zone:r});return a.isValid||t.test(e)&&(e=e.replace(t,"T$1"),a=m.fromISO(e,{zone:n}),a.isValid)?a:null}function fe(e){return L(e)?e:v(e)?"true"===(e=e.toLowerCase()):!!Y(e)&&(0!==e&&!isNaN(e))}function ce(e,n){return d(e)?null:(null!==e.spatialReference&&void 0!==e.spatialReference||(e.spatialReference=n),e)}function me(e){if(null===e)return null;if(e instanceof s)return"NaN"===e.x||null===e.x||isNaN(e.x)?null:e;if(e instanceof f){if(0===e.rings.length)return null;for(const n of e.rings)if(n.length>0)return e;return null}if(e instanceof c){if(0===e.paths.length)return null;for(const n of e.paths)if(n.length>0)return e;return null}return e instanceof u?0===e.points.length?null:e:e instanceof o?"NaN"===e.xmin||null===e.xmin||isNaN(e.xmin)?null:e:null}function de(e,n){if(!e)return n;if(!e.domain)return n;let t=null;if("string"===e.field.type||"esriFieldTypeString"===e.field.type)n=re(n);else{if(null==n)return null;if(""===n)return n;n=le(n)}for(let r=0;r<e.domain.codedValues.length;r++){const a=e.domain.codedValues[r];a.code===n&&(t=a)}return null===t?n:t.name}function ye(e,n){if(!e)return n;if(!e.domain)return n;let t=null;n=re(n);for(let r=0;r<e.domain.codedValues.length;r++){const a=e.domain.codedValues[r];a.name===n&&(t=a)}return null===t?n:t.code}function pe(e,n,t=null,r=null){if(!n)return null;if(!n.fields)return null;let a,i,o=null;for(let l=0;l<n.fields.length;l++){const t=n.fields[l];t.name.toLowerCase()===e.toString().toLowerCase()&&(o=t)}if(null===o)throw new N(null,T.FieldNotFound,null,{key:e});return null===r&&t&&n.typeIdField&&(r=t.hasField(n.typeIdField)?t.field(n.typeIdField):null),null!=r&&n.types.some((e=>e.id===r&&(a=e.domains&&e.domains[o.name],a&&"inherited"===a.type&&(a=he(o.name,n),i=!0),!0))),i||a||(a=he(e,n)),{field:o,domain:a}}function he(e,n){let t;return n.fields.some((n=>(n.name.toLowerCase()===e.toLowerCase()&&(t=n.domain),!!t))),t}function ge(e,n){n||(n={}),"function"==typeof n&&(n={cmp:n});const t="boolean"==typeof n.cycles&&n.cycles,r=n.cmp&&(a=n.cmp,function(e){return function(n,t){const r={key:n,value:e[n]},i={key:t,value:e[t]};return a(r,i)}});var a;const i=[];return function e(n){if(n&&n.toJSON&&"function"==typeof n.toJSON&&(n=n.toJSON()),void 0===n)return;if("number"==typeof n)return isFinite(n)?""+n:"null";if("object"!=typeof n)return JSON.stringify(n);let a,o;if(Array.isArray(n)){for(o="[",a=0;a<n.length;a++)a&&(o+=","),o+=e(n[a])||"null";return o+"]"}if(null===n)return"null";if(i.includes(n)){if(t)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}const l=i.push(n)-1,u=Object.keys(n).sort(r&&r(n));for(o="",a=0;a<u.length;a++){const t=u[a],r=e(n[t]);r&&(o&&(o+=","),o+=JSON.stringify(t)+":"+r)}return i.splice(l,1),"{"+o+"}"}(e)}function be(e){if(null===e)return null;const n=[];for(const t of e)t&&t.arcadeDeclaredClass&&"esri.arcade.Feature"===t.arcadeDeclaredClass?n.push(t.geometry()):n.push(t);return n}function xe(e,n){if(!(n instanceof s))throw new N(null,T.InvalidParameter,null);e.push(n.hasZ?n.hasM?[n.x,n.y,n.z,n.m]:[n.x,n.y,n.z]:[n.x,n.y])}function Se(e,n){if(J(e)||V(e)){let t=!1,a=!1,i=[],o=n;if(J(e)){for(const n of e)xe(i,n);i.length>0&&(o=e[0].spatialReference,t=e[0].hasZ,a=e[0].hasM)}else if(e instanceof r)i=e._elements,i.length>0&&(t=e._hasZ,a=e._hasM,o=e.get(0).spatialReference);else{if(!V(e))throw new N(null,T.InvalidParameter,null);for(const n of e.toArray())xe(i,n);i.length>0&&(o=e.get(0).spatialReference,t=!0===e.get(0).hasZ,a=!0===e.get(0).hasM)}if(0===i.length)return null;return h(i,a,t)||(i=i.slice(0).reverse()),new f({rings:[i],spatialReference:o,hasZ:t,hasM:a})}return e}function Ne(e,n){if(J(e)||V(e)){let t=!1,a=!1,i=[],o=n;if(J(e)){for(const n of e)xe(i,n);i.length>0&&(o=e[0].spatialReference,t=!0===e[0].hasZ,a=!0===e[0].hasM)}else if(e instanceof r)i=e._elements,i.length>0&&(t=e._hasZ,a=e._hasM,o=e.get(0).spatialReference);else if(V(e)){for(const n of e.toArray())xe(i,n);i.length>0&&(o=e.get(0).spatialReference,t=!0===e.get(0).hasZ,a=!0===e.get(0).hasM)}return 0===i.length?null:new c({paths:[i],spatialReference:o,hasZ:t,hasM:a})}return e}function Te(e,n){if(J(e)||V(e)){let t=!1,a=!1,i=[],o=n;if(J(e)){for(const n of e)xe(i,n);i.length>0&&(o=e[0].spatialReference,t=!0===e[0].hasZ,a=!0===e[0].hasM)}else if(e instanceof r)i=e._elements,i.length>0&&(t=e._hasZ,a=e._hasM,o=e.get(0).spatialReference);else if(V(e)){for(const n of e.toArray())xe(i,n);i.length>0&&(o=e.get(0).spatialReference,t=!0===e.get(0).hasZ,a=!0===e.get(0).hasM)}return 0===i.length?null:new u({points:i,spatialReference:o,hasZ:t,hasM:a})}return e}function Me(e,t=!1){const r=[];if(null===e)return r;if(!0===J(e)){for(let n=0;n<e.length;n++){const a=re(e[n]);""===a&&!0!==t||r.push(a)}return r}if(e instanceof n){for(let n=0;n<e.length();n++){const a=re(e.get(n));""===a&&!0!==t||r.push(a)}return r}if(O(e)){const n=re(e);return""===n&&!0!==t||r.push(n),r}return[]}let ke=0;function je(e){return ke++,ke%100==0?(ke=0,new Promise((n=>{setTimeout((()=>{n(e)}),0)}))):e}function Ae(e,n,t){switch(t){case"&":return e&n;case"|":return e|n;case"^":return e^n;case"<<":return e<<n;case">>":return e>>n;case">>>":return e>>>n}}function Re(e,t=null){return null==e?null:L(e)||Y(e)||v(e)?e:e instanceof l?!0===t?.keepGeometryType?e:e.toJSON():e instanceof n?e.toArray().map((e=>Re(e,t))):e instanceof Array?e.map((e=>Re(e,t))):q(e)?e:U(e)?e.toJSDate():null!==e&&"object"==typeof e&&void 0!==e.castAsJson?e.castAsJson(t):null}async function De(e,n,t,r,a){const i=await Fe(e,n,t);a[r]=i}async function Fe(e,t=null,r=null){if(e instanceof n&&(e=e.toArray()),null==e)return null;if(O(e)||e instanceof l||q(e)||U(e))return Re(e,r);if(e instanceof Array){const n=[],a=[];for(const i of e)null===i||O(i)||i instanceof l||q(i)||U(i)?a.push(Re(i,r)):(a.push(null),n.push(De(i,t,r,a.length-1,a)));return n.length>0&&await Promise.all(n),a}return null!==e&&"object"==typeof e&&void 0!==e.castAsJsonAsync?e.castAsJsonAsync(t,r):null}function Ie(e,n,t){const r=e.fullSchema();if(null===r)return null;if(!r.fields)return null;return pe(n,r,e,t)}function Ce(e){const n=e.fullSchema();return null===n?null:n.fields&&n.typeIdField?{subtypeField:n.typeIdField,subtypes:n.types?n.types.map((e=>({name:e.name,code:e.id}))):[]}:null}function we(e,n,t,r){const a=e.fullSchema();if(null===a)return null;if(!a.fields)return null;const i=pe(n,a,e,r);if(void 0===t)try{t=e.field(n)}catch(o){return null}return de(i,t)}function Oe(e,n,t,r){const a=e.fullSchema();if(null===a)return null;if(!a.fields)return null;if(void 0===t){try{t=e.field(n)}catch(i){return null}return t}return ye(pe(n,a,e,r),t)}function Ze(e){return e?.timeReference?.timeZone?e?.timeReference?.timeZone:"system"}function _e(e){const n=e.fullSchema();if(null===n)return null;if(!n.fields)return null;const t=[];for(const r of n.fields)t.push(b(r));return{objectIdField:n.objectIdField,globalIdField:n.globalIdField,geometryType:void 0===x[n.geometryType]?"":x[n.geometryType],fields:t,datesInUnknownTimezone:!0===n.datesInUnknownTimezone,preferredTimeReference:n.preferredTimeReference||null,editFieldsInfo:n.editFieldsInfo||null,timeInfo:n.timeInfo||null,dateFieldsTimeReference:n.dateFieldsTimeReference||null}}const ve=Object.freeze(Object.defineProperty({__proto__:null,ImplicitResult:j,ImplicitResultE:k,ReturnResult:A,ReturnResultE:M,absRound:W,autoCastArrayOfPointsToMultiPoint:Te,autoCastArrayOfPointsToPolygon:Se,autoCastArrayOfPointsToPolyline:Ne,autoCastFeatureToGeometry:be,binaryOperator:Ae,breakResult:D,castAsJson:Re,castAsJsonAsync:Fe,continueResult:F,defaultTimeZone:Ze,defaultUndefined:Z,equalityTest:te,featureDomainCodeLookup:Oe,featureDomainValueLookup:we,featureFullDomain:Ie,featureSchema:_e,featureSubtypes:Ce,fixNullGeometry:me,fixSpatialReference:ce,formatDate:X,formatNumber:Q,generateUUID:$,getDomain:pe,getDomainCode:ye,getDomainValue:de,getType:_,greaterThanLessThan:ne,isArray:J,isBoolean:L,isDate:U,isFeature:z,isFeatureSet:G,isFeatureSetCollection:E,isFunctionParameter:C,isImmutableArray:V,isInteger:P,isJsDate:q,isModule:w,isNumber:Y,isObject:H,isSimpleType:O,isString:v,multiReplace:I,pcCheck:B,stableStringify:ge,standardiseDateFormat:K,tick:je,toBoolean:fe,toDate:ue,toNumber:le,toNumberArray:ae,toString:re,toStringArray:Me,toStringExplicit:ie,voidOperation:R},Symbol.toStringTag,{value:"Module"}));export{M as $,Z as A,_ as B,Ze as C,K as D,W as E,me as F,be as G,Ne as H,j as I,Se as J,Te as K,I as L,$ as M,_e as N,Ce as O,Ie as P,we as Q,A as R,Oe as S,G as T,E as U,ae as V,je as W,Me as X,pe as Y,de as Z,ye as _,L as a,k as a0,w as a1,H as a2,q as a3,Q as a4,X as a5,ge as a6,Y as b,v as c,Re as d,Fe as e,O as f,le as g,fe as h,C as i,re as j,U as k,ue as l,J as m,ve as n,D as o,F as p,ce as q,ne as r,te as s,ie as t,Ae as u,R as v,z as w,V as x,B as y,P as z};