@arcgis/coding-components
Version:
ArcGIS Coding Components
106 lines (105 loc) • 5.26 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import { createArcadeDebugExecutor as A, createArcadeExecutor as b } from "@arcgis/core/arcade.js";
import w from "@arcgis/core/geometry/SpatialReference.js";
const K = "https://developers.arcgis.com/arcade/", M = 100, D = 100;
function R(e) {
return !!e && typeof e == "object" && "declaredRootClass" in e && typeof e.declaredRootClass == "string" && e.declaredRootClass === "esri.arcade.featureset.support.FeatureSet";
}
function x(e) {
return !!e && typeof e == "object" && "arcadeDeclaredClass" in e && typeof e.arcadeDeclaredClass == "string" && e.arcadeDeclaredClass === "esri.arcade.Feature";
}
function S(e) {
return !!e && typeof e == "object" && "declaredClass" in e && typeof e.declaredClass == "string" && e.declaredClass === "esri.arcade.Dictionary";
}
function h(e) {
return !!e && typeof e == "object" && "declaredClass" in e && typeof e.declaredClass == "string" && e.declaredClass.startsWith("esri.geometry.");
}
function T(e) {
return !!e && typeof e == "object" && "declaredClass" in e && typeof e.declaredClass == "string" && e.declaredClass.startsWith("esri.rest.knowledgeGraph.KnowledgeGraph");
}
function F(e) {
return !!e && typeof e == "object" && "declaredClass" in e && typeof e.declaredClass == "string" && e.declaredClass === "esri.arcade.Portal";
}
function j(e) {
return !!e && typeof e == "object" && "declaredClass" in e && typeof e.declaredClass == "string" && e.declaredClass === "esri.arcade.Attachment";
}
function k(e) {
return !!e && typeof e == "object" && "declaredRootClass" in e && typeof e.declaredRootClass == "string" && e.declaredRootClass === "esri.arcade.arcadedate";
}
function P(e) {
return !!e && typeof e == "object" && "declaredRootClass" in e && typeof e.declaredRootClass == "string" && e.declaredRootClass === "esri.core.sql.dateonly";
}
function Z(e) {
return !!e && typeof e == "object" && "declaredRootClass" in e && typeof e.declaredRootClass == "string" && e.declaredRootClass === "esri.core.sql.timeonly";
}
function G(e) {
return !!e && typeof e == "object" && "arcadeDeclaredClass" in e && typeof e.arcadeDeclaredClass == "string" && e.arcadeDeclaredClass === "esri.arcade.Pixel";
}
function O(e) {
return !!e && typeof e == "object" && "length" in e && typeof e.length == "function" && "get" in e && typeof e.get == "function" && "toArray" in e && typeof e.toArray == "function" && "_elements" in e && Array.isArray(e._elements);
}
function E(e) {
return e == null ? { type: "null" } : Array.isArray(e) ? { type: "array", value: e } : O(e) ? { type: "array", value: e.toArray() } : e instanceof Date ? { type: "date", value: e } : typeof e == "string" ? { type: "text", value: e } : typeof e == "number" ? { type: "number", value: e } : typeof e == "boolean" ? { type: "boolean", value: e } : typeof e != "object" ? { type: "unknown" } : k(e) ? { type: "date", value: e } : P(e) ? { type: "dateOnly", value: e } : Z(e) ? { type: "time", value: e } : j(e) ? { type: "attachment", value: e } : F(e) ? { type: "portal", value: e } : R(e) ? { type: "featureSet", value: e, features: [], iterator: null } : x(e) ? { type: "feature", value: e } : G(e) ? { type: "pixel", value: e } : S(e) ? { type: "dictionary", value: e } : h(e) ? { type: "geometry", value: e } : T(e) ? { type: "knowledgeGraph", value: e } : { type: "unknown" };
}
function U(e, r = "en") {
return e.value instanceof Date ? new Intl.DateTimeFormat(r, { dateStyle: "medium", timeStyle: "long" }).format(e.value) : e.value.toDateTime().setLocale(r).toFormat(e.value.isUnknownTimeZone ? "FF" : "FF ZZZZZ");
}
function _(e) {
return e.value.toString();
}
function z(e) {
return e.value.toString();
}
async function I(e, r = "system") {
const t = E(e);
return t.type !== "featureSet" || (await t.value.load(), t.iterator = t.value.iterator({ aborted: !1 }), t.features = await t.iterator.nextBatchAsArcadeFeatures(D, r) ?? []), t;
}
function L(e) {
return "compilationTime" in e || "executionTime" in e || "timeStamp" in e;
}
async function V(e, r, t, n = {}) {
const a = /* @__PURE__ */ new Date(), c = n.mode ?? "run";
n.console ??= () => {
};
try {
const o = performance.now(), s = r ?? "", d = {
variables: e?.variables ?? []
}, m = c === "debug" ? await A(s, d, {
services: {
debugger: n.onDebugPause ? { pause: n.onDebugPause } : void 0
},
breakpoints: n.breakpoints
}) : await b(s, d), f = performance.now(), { profileVariableInstances: l, spatialReference: u, timeZone: p, services: g } = t, C = {
spatialReference: new w({ wkid: u?.wkid ?? 3857 }),
timeZone: p,
console: n.console,
services: g,
rawOutput: !0
}, y = await m.executeAsync(l, C);
if (c === "debug")
return y;
const i = await I(y, p);
return i.timeStamp = a, i.compilationTime = f - o, i.executionTime = performance.now() - f, i;
} catch (o) {
let s = "Unknown Error";
return o instanceof Error && (s = o.message), {
type: "error",
value: s,
error: o,
timeStamp: a,
compilationTime: 0,
executionTime: 0
};
}
}
export {
D as B,
K as D,
M,
_ as a,
U as b,
V as e,
z as f,
L as i,
E as v
};