@dashspec/renderer 0.1.41 → 0.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +1 -1
- package/dist/FlowMapView-BSTKU7D4.js +458 -0
- package/dist/FlowMapView-BSTKU7D4.js.map +1 -0
- package/dist/chunk-5LRFKK4I.js +118 -0
- package/dist/chunk-5LRFKK4I.js.map +1 -0
- package/dist/{chunk-NLKXHTLO.js → chunk-D4GFCPCL.js} +6 -33
- package/dist/chunk-D4GFCPCL.js.map +1 -0
- package/dist/chunk-E4CT25TF.js +440 -0
- package/dist/chunk-E4CT25TF.js.map +1 -0
- package/dist/chunk-HUBYJ34E.js +38 -0
- package/dist/chunk-HUBYJ34E.js.map +1 -0
- package/dist/{chunk-YOCDUP7X.js → chunk-IBSZQEYY.js} +207 -527
- package/dist/chunk-IBSZQEYY.js.map +1 -0
- package/dist/{chunk-M4WXE3FW.js → chunk-JCPQBIAL.js} +5 -3
- package/dist/{chunk-M4WXE3FW.js.map → chunk-JCPQBIAL.js.map} +1 -1
- package/dist/{core-DE2SVeij.d.ts → core-DJ1ABh7P.d.ts} +34 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +18 -16
- package/dist/index.d.ts +33 -4
- package/dist/index.js +354 -290
- package/dist/index.js.map +1 -1
- package/dist/sandbox-RCDZ7SDZ.js +11 -0
- package/dist/sandbox.js +3 -2
- package/dist/schema.json +15 -0
- package/docs/README.md +1 -1
- package/docs/api.md +1 -1
- package/docs/data.md +8 -0
- package/docs/design-systems.md +21 -0
- package/docs/getting-started.md +1 -1
- package/docs/json-format.md +3 -1
- package/docs/widgets.md +2 -1
- package/package.json +1 -1
- package/dist/chunk-NLKXHTLO.js.map +0 -1
- package/dist/chunk-YOCDUP7X.js.map +0 -1
- package/dist/sandbox-WEMG76LE.js +0 -10
- /package/dist/{sandbox-WEMG76LE.js.map → sandbox-RCDZ7SDZ.js.map} +0 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ScriptError
|
|
3
|
+
} from "./chunk-D4GFCPCL.js";
|
|
1
4
|
import {
|
|
2
5
|
BLOCKED,
|
|
3
|
-
ScriptError,
|
|
4
6
|
getPath
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-HUBYJ34E.js";
|
|
6
8
|
|
|
7
9
|
// src/runtime/scripts/sandbox.ts
|
|
8
10
|
import releaseSync from "@jitl/quickjs-wasmfile-release-sync";
|
|
@@ -251,4 +253,4 @@ export {
|
|
|
251
253
|
loadQuickJS,
|
|
252
254
|
createSandboxRunner
|
|
253
255
|
};
|
|
254
|
-
//# sourceMappingURL=chunk-
|
|
256
|
+
//# sourceMappingURL=chunk-JCPQBIAL.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/runtime/scripts/sandbox.ts"],"sourcesContent":["/**\n * `sandbox` (default): callbacks, fn transforms and fn props run in QuickJS compiled to WebAssembly.\n * The code sees only `event`, `state`, `api` (or `rows` / the fn params): no `window`, DOM, storage, cookies or tokens.\n * Each run is limited in time and the VM in memory. Values cross the boundary as JSON.\n */\nimport releaseSync from \"@jitl/quickjs-wasmfile-release-sync\";\nimport {\n type QuickJSContext,\n type QuickJSHandle,\n type QuickJSWASMModule,\n newQuickJSWASMModuleFromVariant,\n shouldInterruptAfterDeadline,\n} from \"quickjs-emscripten-core\";\nimport { BLOCKED, getPath } from \"../store/paths\";\nimport { type CallbackApi, ScriptError, type ScriptRunner } from \"./index\";\n\nexport interface SandboxOptions {\n /** Synchronous budget for one transform or the synchronous part of a callback. Default 1000 ms. */\n syncTimeoutMs?: number;\n /** Budget for one function-prop call (formatters run often). Default 50 ms. */\n fnPropTimeoutMs?: number;\n /** A callback including its awaits. Default 30 s. */\n asyncTimeoutMs?: number;\n /** VM heap. Default 32 MB. */\n memoryBytes?: number;\n}\n\n/**\n * Runs first in every callback VM. The host bridge (`__get`, `__set`, `__keys`, `__do`, `__call`) is captured in a\n * closure and removed from the global object, so the document's code only gets `state` and `api`.\n */\nconst PRELUDE = `\n(() => {\n const g = globalThis;\n const get = g.__get, set = g.__set, keys = g.__keys, run = g.__do, call = g.__call;\n for (const k of [\"__get\", \"__set\", \"__keys\", \"__do\", \"__call\"]) delete g[k];\n const wrap = (path) => new Proxy({}, {\n get(_, k) {\n if (typeof k !== \"string\") return undefined;\n if (k === \"toJSON\") return () => JSON.parse(get(JSON.stringify(path)));\n const p = [...path, k];\n const v = JSON.parse(get(JSON.stringify(p)));\n return v !== null && typeof v === \"object\" ? wrap(p) : v;\n },\n set(_, k, v) { set(JSON.stringify([...path, k]), JSON.stringify(v === undefined ? null : v)); return true; },\n deleteProperty(_, k) { set(JSON.stringify([...path, k]), \"null\"); return true; },\n has(_, k) { return JSON.parse(keys(JSON.stringify(path))).includes(k); },\n ownKeys() { return JSON.parse(keys(JSON.stringify(path))); },\n getOwnPropertyDescriptor(_, k) {\n const v = JSON.parse(get(JSON.stringify([...path, k])));\n return v === undefined ? undefined : { enumerable: true, configurable: true, writable: true, value: v };\n },\n });\n const json = (s) => JSON.parse(s);\n g.__state = wrap([]);\n g.__api = Object.freeze({\n fetch: (source, params) => call(\"fetch\", JSON.stringify([source, params])).then(json),\n http: (connection, request) => call(\"http\", JSON.stringify([connection, request])).then(json),\n call: (fn, args) => call(\"call\", JSON.stringify([fn, args])).then(json),\n refresh: (source) => { run(\"refresh\", JSON.stringify([source])); },\n navigate: (to) => { run(\"navigate\", JSON.stringify([to])); },\n toast: (message, tone) => { run(\"toast\", JSON.stringify([message, tone])); },\n emit: (event, payload) => { run(\"emit\", JSON.stringify([event, payload])); },\n });\n})();\n`;\n\n/** Freezes the shared VM's built-ins so one transform or fn prop can't change what the next one sees. */\nconst HARDEN = `\n(() => {\n \"use strict\";\n const g = globalThis;\n for (const name of Object.getOwnPropertyNames(g)) {\n const v = g[name];\n if ((typeof v === \"function\" || (v && typeof v === \"object\")) && v !== g) {\n Object.freeze(v);\n if (typeof v === \"function\" && v.prototype) Object.freeze(v.prototype);\n }\n }\n Object.freeze(Object.getPrototypeOf(function* () {}));\n Object.freeze(Object.getPrototypeOf(async function () {}));\n Object.freeze(g);\n})();\n`;\n\nlet modulePromise: Promise<QuickJSWASMModule> | undefined;\n/** Loads the WebAssembly module once (about 500 KB); the React layer calls this only when a dashboard has scripts. */\nexport const loadQuickJS = () => {\n modulePromise ??= newQuickJSWASMModuleFromVariant(releaseSync);\n return modulePromise;\n};\n\n/** Plain JSON for the VM. Shared objects are kept (only real cycles are cut); functions are dropped. */\nconst toJson = (v: unknown): string => {\n const x = v === undefined ? null : v;\n try {\n return JSON.stringify(x);\n } catch {\n const path: object[] = [];\n return JSON.stringify(x, function (this: unknown, _k, val) {\n if (val && typeof val === \"object\") {\n while (path.length && path[path.length - 1] !== this) path.pop();\n if (path.includes(val)) return undefined;\n path.push(val);\n }\n return val;\n });\n }\n};\n\n/** A state path from the VM: a non-empty list of names and indexes, never reaching a prototype. */\nconst statePath = (p: string): (string | number)[] => {\n const path = JSON.parse(p) as unknown;\n if (\n !Array.isArray(path) ||\n path.length === 0 ||\n !path.every((k) => (typeof k === \"string\" && !BLOCKED.has(k)) || (typeof k === \"number\" && Number.isInteger(k)))\n )\n throw new ScriptError(\"Invalid state path\");\n return path as (string | number)[];\n};\n\nexport async function createSandboxRunner(opts: SandboxOptions = {}): Promise<ScriptRunner> {\n const QuickJS = await loadQuickJS();\n const syncMs = opts.syncTimeoutMs ?? 1000;\n const fnMs = opts.fnPropTimeoutMs ?? 50;\n const asyncMs = opts.asyncTimeoutMs ?? 30_000;\n const memory = opts.memoryBytes ?? 32 * 1024 * 1024;\n\n const newVm = () => {\n const vm = QuickJS.newContext();\n vm.runtime.setMemoryLimit(memory);\n vm.runtime.setMaxStackSize(1024 * 1024);\n return vm;\n };\n const arm = (vm: QuickJSContext, ms = syncMs) =>\n vm.runtime.setInterruptHandler(shouldInterruptAfterDeadline(Date.now() + ms));\n const unwrap = (vm: QuickJSContext, r: ReturnType<QuickJSContext[\"evalCode\"]>): QuickJSHandle => {\n if (r.error) {\n const e = vm.dump(r.error);\n r.error.dispose();\n throw new ScriptError(\n typeof e === \"object\" && e && \"message\" in e ? String((e as { message: unknown }).message) : String(e),\n );\n }\n return r.value;\n };\n const fn = (vm: QuickJSContext, name: string, impl: (...args: string[]) => string | undefined) => {\n const h = vm.newFunction(name, (...args) => {\n const out = impl(...args.map((a) => vm.getString(a)));\n return out === undefined ? vm.undefined : vm.newString(out);\n });\n vm.setProp(vm.global, name, h);\n h.dispose();\n };\n\n // One VM for synchronous work (transforms, fn props), reused across calls for speed. Its built-ins are frozen, so\n // one script can't change what the next sees, and it is rebuilt after any error (timeout, out of memory, a bad\n // script), so a failure never leaves it half-changed or full.\n const hardenedVm = () => {\n const vm = newVm();\n arm(vm);\n unwrap(vm, vm.evalCode(HARDEN)).dispose();\n return vm;\n };\n let syncVm = hardenedVm();\n const runSync = (src: string, ms: number): unknown => {\n arm(syncVm, ms);\n try {\n const h = unwrap(syncVm, syncVm.evalCode(src));\n const s = syncVm.getString(h);\n h.dispose();\n return JSON.parse(s);\n } catch (e) {\n syncVm.dispose();\n syncVm = hardenedVm();\n throw e;\n }\n };\n\n return {\n async callback(code, event, state, api: CallbackApi) {\n const vm = newVm();\n const pending = new Set<Promise<unknown>>();\n try {\n const live = state as Record<string, unknown>;\n // Read the plain tree once per call and serialise only the part asked for.\n const root = () => (live as unknown as { toJSON(): unknown }).toJSON();\n fn(vm, \"__get\", (p) => toJson(getPath(root(), JSON.parse(p))));\n fn(vm, \"__keys\", (p) => {\n const v = getPath(root(), JSON.parse(p));\n return JSON.stringify(v && typeof v === \"object\" ? Object.keys(v) : []);\n });\n fn(vm, \"__set\", (p, v) => {\n const path = statePath(p);\n // Through the live proxy (own properties only), so writes dispatch and read-only roots stay read-only.\n let target: unknown = live;\n for (const k of path.slice(0, -1)) {\n target = (target as Record<string | number, unknown>)[k];\n if (!target || typeof target !== \"object\") throw new ScriptError(`Can't write state.${path.join(\".\")}`);\n }\n (target as Record<string | number, unknown>)[path[path.length - 1] as string | number] = JSON.parse(\n v as string,\n );\n return undefined;\n });\n fn(vm, \"__do\", (name, args) => {\n const a = JSON.parse(args as string) as unknown[];\n (api[name as keyof CallbackApi] as (...x: unknown[]) => unknown)(...a);\n return undefined;\n });\n const call = vm.newFunction(\"__call\", (nameH, argsH) => {\n const name = vm.getString(nameH) as \"fetch\" | \"http\" | \"call\";\n const args = JSON.parse(vm.getString(argsH)) as [string, never];\n const promise = vm.newPromise();\n const p = (api[name] as (a: string, b: never) => Promise<unknown>)(args[0], args[1])\n .then(\n (v) => {\n if (!vm.alive) return;\n const h = vm.newString(toJson(v));\n promise.resolve(h);\n h.dispose();\n },\n (e) => {\n if (!vm.alive) return;\n const h = vm.newError((e as Error).message ?? String(e));\n promise.reject(h);\n h.dispose();\n },\n )\n .finally(() => {\n pending.delete(p);\n if (vm.alive) {\n arm(vm);\n vm.runtime.executePendingJobs();\n }\n });\n pending.add(p);\n promise.settled.then(() => vm.alive && vm.runtime.executePendingJobs());\n return promise.handle;\n });\n vm.setProp(vm.global, \"__call\", call);\n call.dispose();\n\n arm(vm);\n unwrap(vm, vm.evalCode(PRELUDE)).dispose();\n const fnH = unwrap(vm, vm.evalCode(`(${code})`));\n const evH = unwrap(vm, vm.evalCode(`(${toJson(event)})`));\n const stateH = vm.getProp(vm.global, \"__state\");\n const apiH = vm.getProp(vm.global, \"__api\");\n const result = vm.callFunction(fnH, vm.undefined, evH, stateH, apiH);\n for (const h of [fnH, evH, stateH, apiH]) h.dispose();\n const resH = unwrap(vm, result);\n const settled = vm.resolvePromise(resH);\n resH.dispose();\n vm.runtime.executePendingJobs();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const out = await Promise.race([\n settled,\n new Promise<never>((_, rej) => {\n timer = setTimeout(() => rej(new ScriptError(`Callback took longer than ${asyncMs / 1000} s`)), asyncMs);\n }),\n ]);\n clearTimeout(timer);\n if (out.error) {\n const e = vm.dump(out.error);\n out.error.dispose();\n throw new ScriptError(\n typeof e === \"object\" && e && \"message\" in e ? String((e as { message: unknown }).message) : String(e),\n );\n }\n const v = vm.dump(out.value);\n out.value.dispose();\n return v;\n } finally {\n await Promise.allSettled([...pending]);\n vm.dispose();\n }\n },\n\n transform(code, rows) {\n return runSync(`JSON.stringify((function(rows){ \"use strict\"; ${code} })(${toJson(rows)}) ?? null)`, syncMs);\n },\n\n fnProp(code, params) {\n return (...args: unknown[]) => {\n return runSync(\n `JSON.stringify((function(${params.join(\",\")}){ \"use strict\"; ${code} })(...${toJson(args)}) ?? null)`,\n fnMs,\n );\n };\n },\n };\n}\n"],"mappings":";;;;;;;AAKA,OAAO,iBAAiB;AACxB;AAAA,EAIE;AAAA,EACA;AAAA,OACK;AAmBP,IAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqChB,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBf,IAAI;AAEG,IAAM,cAAc,MAAM;AAC/B,oBAAkB,gCAAgC,WAAW;AAC7D,SAAO;AACT;AAGA,IAAM,SAAS,CAAC,MAAuB;AACrC,QAAM,IAAI,MAAM,SAAY,OAAO;AACnC,MAAI;AACF,WAAO,KAAK,UAAU,CAAC;AAAA,EACzB,QAAQ;AACN,UAAM,OAAiB,CAAC;AACxB,WAAO,KAAK,UAAU,GAAG,SAAyB,IAAI,KAAK;AACzD,UAAI,OAAO,OAAO,QAAQ,UAAU;AAClC,eAAO,KAAK,UAAU,KAAK,KAAK,SAAS,CAAC,MAAM,KAAM,MAAK,IAAI;AAC/D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KAAK,aAAa,IAAI,OAAQ,EAA2B,OAAO,IAAI,OAAO,CAAC;AAAA,UACvG;AAAA,QACF;AACA,cAAM,IAAI,GAAG,KAAK,IAAI,KAAK;AAC3B,YAAI,MAAM,QAAQ;AAClB,eAAO;AAAA,MACT,UAAE;AACA,cAAM,QAAQ,WAAW,CAAC,GAAG,OAAO,CAAC;AACrC,WAAG,QAAQ;AAAA,MACb;AAAA,IACF;AAAA,IAEA,UAAU,MAAM,MAAM;AACpB,aAAO,QAAQ,iDAAiD,IAAI,OAAO,OAAO,IAAI,CAAC,cAAc,MAAM;AAAA,IAC7G;AAAA,IAEA,OAAO,MAAM,QAAQ;AACnB,aAAO,IAAI,SAAoB;AAC7B,eAAO;AAAA,UACL,4BAA4B,OAAO,KAAK,GAAG,CAAC,oBAAoB,IAAI,UAAU,OAAO,IAAI,CAAC;AAAA,UAC1F;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["v"]}
|
|
1
|
+
{"version":3,"sources":["../src/runtime/scripts/sandbox.ts"],"sourcesContent":["/**\n * `sandbox` (default): callbacks, fn transforms and fn props run in QuickJS compiled to WebAssembly.\n * The code sees only `event`, `state`, `api` (or `rows` / the fn params): no `window`, DOM, storage, cookies or tokens.\n * Each run is limited in time and the VM in memory. Values cross the boundary as JSON.\n */\nimport releaseSync from \"@jitl/quickjs-wasmfile-release-sync\";\nimport {\n type QuickJSContext,\n type QuickJSHandle,\n type QuickJSWASMModule,\n newQuickJSWASMModuleFromVariant,\n shouldInterruptAfterDeadline,\n} from \"quickjs-emscripten-core\";\nimport { BLOCKED, getPath } from \"../store/paths\";\nimport { type CallbackApi, ScriptError, type ScriptRunner } from \"./index\";\n\nexport interface SandboxOptions {\n /** Synchronous budget for one transform or the synchronous part of a callback. Default 1000 ms. */\n syncTimeoutMs?: number;\n /** Budget for one function-prop call (formatters run often). Default 50 ms. */\n fnPropTimeoutMs?: number;\n /** A callback including its awaits. Default 30 s. */\n asyncTimeoutMs?: number;\n /** VM heap. Default 32 MB. */\n memoryBytes?: number;\n}\n\n/**\n * Runs first in every callback VM. The host bridge (`__get`, `__set`, `__keys`, `__do`, `__call`) is captured in a\n * closure and removed from the global object, so the document's code only gets `state` and `api`.\n */\nconst PRELUDE = `\n(() => {\n const g = globalThis;\n const get = g.__get, set = g.__set, keys = g.__keys, run = g.__do, call = g.__call;\n for (const k of [\"__get\", \"__set\", \"__keys\", \"__do\", \"__call\"]) delete g[k];\n const wrap = (path) => new Proxy({}, {\n get(_, k) {\n if (typeof k !== \"string\") return undefined;\n if (k === \"toJSON\") return () => JSON.parse(get(JSON.stringify(path)));\n const p = [...path, k];\n const v = JSON.parse(get(JSON.stringify(p)));\n return v !== null && typeof v === \"object\" ? wrap(p) : v;\n },\n set(_, k, v) { set(JSON.stringify([...path, k]), JSON.stringify(v === undefined ? null : v)); return true; },\n deleteProperty(_, k) { set(JSON.stringify([...path, k]), \"null\"); return true; },\n has(_, k) { return JSON.parse(keys(JSON.stringify(path))).includes(k); },\n ownKeys() { return JSON.parse(keys(JSON.stringify(path))); },\n getOwnPropertyDescriptor(_, k) {\n const v = JSON.parse(get(JSON.stringify([...path, k])));\n return v === undefined ? undefined : { enumerable: true, configurable: true, writable: true, value: v };\n },\n });\n const json = (s) => JSON.parse(s);\n g.__state = wrap([]);\n g.__api = Object.freeze({\n fetch: (source, params) => call(\"fetch\", JSON.stringify([source, params])).then(json),\n http: (connection, request) => call(\"http\", JSON.stringify([connection, request])).then(json),\n call: (fn, args) => call(\"call\", JSON.stringify([fn, args])).then(json),\n refresh: (source) => { run(\"refresh\", JSON.stringify([source])); },\n navigate: (to) => { run(\"navigate\", JSON.stringify([to])); },\n toast: (message, tone) => { run(\"toast\", JSON.stringify([message, tone])); },\n emit: (event, payload) => { run(\"emit\", JSON.stringify([event, payload])); },\n });\n})();\n`;\n\n/** Freezes the shared VM's built-ins so one transform or fn prop can't change what the next one sees. */\nconst HARDEN = `\n(() => {\n \"use strict\";\n const g = globalThis;\n for (const name of Object.getOwnPropertyNames(g)) {\n const v = g[name];\n if ((typeof v === \"function\" || (v && typeof v === \"object\")) && v !== g) {\n Object.freeze(v);\n if (typeof v === \"function\" && v.prototype) Object.freeze(v.prototype);\n }\n }\n Object.freeze(Object.getPrototypeOf(function* () {}));\n Object.freeze(Object.getPrototypeOf(async function () {}));\n Object.freeze(g);\n})();\n`;\n\nlet modulePromise: Promise<QuickJSWASMModule> | undefined;\n/** Loads the WebAssembly module once (about 500 KB); the React layer calls this only when a dashboard has scripts. */\nexport const loadQuickJS = () => {\n modulePromise ??= newQuickJSWASMModuleFromVariant(releaseSync);\n return modulePromise;\n};\n\n/** Plain JSON for the VM. Shared objects are kept (only real cycles are cut); functions are dropped. */\nconst toJson = (v: unknown): string => {\n const x = v === undefined ? null : v;\n try {\n return JSON.stringify(x);\n } catch {\n const path: object[] = [];\n return JSON.stringify(x, function (this: unknown, _k, val) {\n if (val && typeof val === \"object\") {\n while (path.length && path[path.length - 1] !== this) path.pop();\n if (path.includes(val)) return undefined;\n path.push(val);\n }\n return val;\n });\n }\n};\n\n/** A state path from the VM: a non-empty list of names and indexes, never reaching a prototype. */\nconst statePath = (p: string): (string | number)[] => {\n const path = JSON.parse(p) as unknown;\n if (\n !Array.isArray(path) ||\n path.length === 0 ||\n !path.every((k) => (typeof k === \"string\" && !BLOCKED.has(k)) || (typeof k === \"number\" && Number.isInteger(k)))\n )\n throw new ScriptError(\"Invalid state path\");\n return path as (string | number)[];\n};\n\nexport async function createSandboxRunner(opts: SandboxOptions = {}): Promise<ScriptRunner> {\n const QuickJS = await loadQuickJS();\n const syncMs = opts.syncTimeoutMs ?? 1000;\n const fnMs = opts.fnPropTimeoutMs ?? 50;\n const asyncMs = opts.asyncTimeoutMs ?? 30_000;\n const memory = opts.memoryBytes ?? 32 * 1024 * 1024;\n\n const newVm = () => {\n const vm = QuickJS.newContext();\n vm.runtime.setMemoryLimit(memory);\n vm.runtime.setMaxStackSize(1024 * 1024);\n return vm;\n };\n const arm = (vm: QuickJSContext, ms = syncMs) =>\n vm.runtime.setInterruptHandler(shouldInterruptAfterDeadline(Date.now() + ms));\n const unwrap = (vm: QuickJSContext, r: ReturnType<QuickJSContext[\"evalCode\"]>): QuickJSHandle => {\n if (r.error) {\n const e = vm.dump(r.error);\n r.error.dispose();\n throw new ScriptError(\n typeof e === \"object\" && e && \"message\" in e ? String((e as { message: unknown }).message) : String(e),\n );\n }\n return r.value;\n };\n const fn = (vm: QuickJSContext, name: string, impl: (...args: string[]) => string | undefined) => {\n const h = vm.newFunction(name, (...args) => {\n const out = impl(...args.map((a) => vm.getString(a)));\n return out === undefined ? vm.undefined : vm.newString(out);\n });\n vm.setProp(vm.global, name, h);\n h.dispose();\n };\n\n // One VM for synchronous work (transforms, fn props), reused across calls for speed. Its built-ins are frozen, so\n // one script can't change what the next sees, and it is rebuilt after any error (timeout, out of memory, a bad\n // script), so a failure never leaves it half-changed or full.\n const hardenedVm = () => {\n const vm = newVm();\n arm(vm);\n unwrap(vm, vm.evalCode(HARDEN)).dispose();\n return vm;\n };\n let syncVm = hardenedVm();\n const runSync = (src: string, ms: number): unknown => {\n arm(syncVm, ms);\n try {\n const h = unwrap(syncVm, syncVm.evalCode(src));\n const s = syncVm.getString(h);\n h.dispose();\n return JSON.parse(s);\n } catch (e) {\n syncVm.dispose();\n syncVm = hardenedVm();\n throw e;\n }\n };\n\n return {\n async callback(code, event, state, api: CallbackApi) {\n const vm = newVm();\n const pending = new Set<Promise<unknown>>();\n try {\n const live = state as Record<string, unknown>;\n // Read the plain tree once per call and serialise only the part asked for.\n const root = () => (live as unknown as { toJSON(): unknown }).toJSON();\n fn(vm, \"__get\", (p) => toJson(getPath(root(), JSON.parse(p))));\n fn(vm, \"__keys\", (p) => {\n const v = getPath(root(), JSON.parse(p));\n return JSON.stringify(v && typeof v === \"object\" ? Object.keys(v) : []);\n });\n fn(vm, \"__set\", (p, v) => {\n const path = statePath(p);\n // Through the live proxy (own properties only), so writes dispatch and read-only roots stay read-only.\n let target: unknown = live;\n for (const k of path.slice(0, -1)) {\n target = (target as Record<string | number, unknown>)[k];\n if (!target || typeof target !== \"object\") throw new ScriptError(`Can't write state.${path.join(\".\")}`);\n }\n (target as Record<string | number, unknown>)[path[path.length - 1] as string | number] = JSON.parse(\n v as string,\n );\n return undefined;\n });\n fn(vm, \"__do\", (name, args) => {\n const a = JSON.parse(args as string) as unknown[];\n (api[name as keyof CallbackApi] as (...x: unknown[]) => unknown)(...a);\n return undefined;\n });\n const call = vm.newFunction(\"__call\", (nameH, argsH) => {\n const name = vm.getString(nameH) as \"fetch\" | \"http\" | \"call\";\n const args = JSON.parse(vm.getString(argsH)) as [string, never];\n const promise = vm.newPromise();\n const p = (api[name] as (a: string, b: never) => Promise<unknown>)(args[0], args[1])\n .then(\n (v) => {\n if (!vm.alive) return;\n const h = vm.newString(toJson(v));\n promise.resolve(h);\n h.dispose();\n },\n (e) => {\n if (!vm.alive) return;\n const h = vm.newError((e as Error).message ?? String(e));\n promise.reject(h);\n h.dispose();\n },\n )\n .finally(() => {\n pending.delete(p);\n if (vm.alive) {\n arm(vm);\n vm.runtime.executePendingJobs();\n }\n });\n pending.add(p);\n promise.settled.then(() => vm.alive && vm.runtime.executePendingJobs());\n return promise.handle;\n });\n vm.setProp(vm.global, \"__call\", call);\n call.dispose();\n\n arm(vm);\n unwrap(vm, vm.evalCode(PRELUDE)).dispose();\n const fnH = unwrap(vm, vm.evalCode(`(${code})`));\n const evH = unwrap(vm, vm.evalCode(`(${toJson(event)})`));\n const stateH = vm.getProp(vm.global, \"__state\");\n const apiH = vm.getProp(vm.global, \"__api\");\n const result = vm.callFunction(fnH, vm.undefined, evH, stateH, apiH);\n for (const h of [fnH, evH, stateH, apiH]) h.dispose();\n const resH = unwrap(vm, result);\n const settled = vm.resolvePromise(resH);\n resH.dispose();\n vm.runtime.executePendingJobs();\n let timer: ReturnType<typeof setTimeout> | undefined;\n const out = await Promise.race([\n settled,\n new Promise<never>((_, rej) => {\n timer = setTimeout(() => rej(new ScriptError(`Callback took longer than ${asyncMs / 1000} s`)), asyncMs);\n }),\n ]);\n clearTimeout(timer);\n if (out.error) {\n const e = vm.dump(out.error);\n out.error.dispose();\n throw new ScriptError(\n typeof e === \"object\" && e && \"message\" in e ? String((e as { message: unknown }).message) : String(e),\n );\n }\n const v = vm.dump(out.value);\n out.value.dispose();\n return v;\n } finally {\n await Promise.allSettled([...pending]);\n vm.dispose();\n }\n },\n\n transform(code, rows) {\n return runSync(`JSON.stringify((function(rows){ \"use strict\"; ${code} })(${toJson(rows)}) ?? null)`, syncMs);\n },\n\n fnProp(code, params) {\n return (...args: unknown[]) => {\n return runSync(\n `JSON.stringify((function(${params.join(\",\")}){ \"use strict\"; ${code} })(...${toJson(args)}) ?? null)`,\n fnMs,\n );\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;AAKA,OAAO,iBAAiB;AACxB;AAAA,EAIE;AAAA,EACA;AAAA,OACK;AAmBP,IAAM,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqChB,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBf,IAAI;AAEG,IAAM,cAAc,MAAM;AAC/B,oBAAkB,gCAAgC,WAAW;AAC7D,SAAO;AACT;AAGA,IAAM,SAAS,CAAC,MAAuB;AACrC,QAAM,IAAI,MAAM,SAAY,OAAO;AACnC,MAAI;AACF,WAAO,KAAK,UAAU,CAAC;AAAA,EACzB,QAAQ;AACN,UAAM,OAAiB,CAAC;AACxB,WAAO,KAAK,UAAU,GAAG,SAAyB,IAAI,KAAK;AACzD,UAAI,OAAO,OAAO,QA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K,IAAI,KAAK;AAC3B,cAAI,MAAM,QAAQ;AAClB,gBAAM,IAAI;AAAA,YACR,OAAO,MAAM,YAAY,KAAK,aAAa,IAAI,OAAQ,EAA2B,OAAO,IAAI,OAAO,CAAC;AAAA,UACvG;AAAA,QACF;AACA,cAAM,IAAI,GAAG,KAAK,IAAI,KAAK;AAC3B,YAAI,MAAM,QAAQ;AAClB,eAAO;AAAA,MACT,UAAE;AACA,cAAM,QAAQ,WAAW,CAAC,GAAG,OAAO,CAAC;AACrC,WAAG,QAAQ;AAAA,MACb;AAAA,IACF;AAAA,IAEA,UAAU,MAAM,MAAM;AACpB,aAAO,QAAQ,iDAAiD,IAAI,OAAO,OAAO,IAAI,CAAC,cAAc,MAAM;AAAA,IAC7G;AAAA,IAEA,OAAO,MAAM,QAAQ;AACnB,aAAO,IAAI,SAAoB;AAC7B,eAAO;AAAA,UACL,4BAA4B,OAAO,KAAK,GAAG,CAAC,oBAAoB,IAAI,UAAU,OAAO,IAAI,CAAC;AAAA,UAC1F;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["v"]}
|
|
@@ -2047,6 +2047,8 @@ declare const Spec: z.ZodObject<{
|
|
|
2047
2047
|
size: z.ZodDefault<z.ZodEnum<["sm", "md", "lg", "xl", "full"]>>;
|
|
2048
2048
|
presentation: z.ZodDefault<z.ZodEnum<["modal", "drawer"]>>;
|
|
2049
2049
|
open: z.ZodOptional<z.ZodString>;
|
|
2050
|
+
defaultArgs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>>>;
|
|
2051
|
+
availableWhen: z.ZodOptional<z.ZodString>;
|
|
2050
2052
|
datasources: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>>>;
|
|
2051
2053
|
panels: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
2052
2054
|
kind: z.ZodString;
|
|
@@ -2474,6 +2476,8 @@ declare const Spec: z.ZodObject<{
|
|
|
2474
2476
|
}>> | undefined;
|
|
2475
2477
|
title?: string | undefined;
|
|
2476
2478
|
open?: string | undefined;
|
|
2479
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
2480
|
+
availableWhen?: string | undefined;
|
|
2477
2481
|
}, {
|
|
2478
2482
|
panels: Record<string, {
|
|
2479
2483
|
kind: string;
|
|
@@ -2554,6 +2558,8 @@ declare const Spec: z.ZodObject<{
|
|
|
2554
2558
|
title?: string | undefined;
|
|
2555
2559
|
presentation?: "modal" | "drawer" | undefined;
|
|
2556
2560
|
open?: string | undefined;
|
|
2561
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
2562
|
+
availableWhen?: string | undefined;
|
|
2557
2563
|
}>>>;
|
|
2558
2564
|
layouts: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
2559
2565
|
view: z.ZodOptional<z.ZodString>;
|
|
@@ -2971,6 +2977,8 @@ declare const Spec: z.ZodObject<{
|
|
|
2971
2977
|
}>> | undefined;
|
|
2972
2978
|
title?: string | undefined;
|
|
2973
2979
|
open?: string | undefined;
|
|
2980
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
2981
|
+
availableWhen?: string | undefined;
|
|
2974
2982
|
}> | undefined;
|
|
2975
2983
|
tour?: {
|
|
2976
2984
|
text: string;
|
|
@@ -3281,6 +3289,8 @@ declare const Spec: z.ZodObject<{
|
|
|
3281
3289
|
title?: string | undefined;
|
|
3282
3290
|
presentation?: "modal" | "drawer" | undefined;
|
|
3283
3291
|
open?: string | undefined;
|
|
3292
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
3293
|
+
availableWhen?: string | undefined;
|
|
3284
3294
|
}> | undefined;
|
|
3285
3295
|
tour?: {
|
|
3286
3296
|
text: string;
|
|
@@ -4456,6 +4466,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
4456
4466
|
size: z.ZodDefault<z.ZodEnum<["sm", "md", "lg", "xl", "full"]>>;
|
|
4457
4467
|
presentation: z.ZodDefault<z.ZodEnum<["modal", "drawer"]>>;
|
|
4458
4468
|
open: z.ZodOptional<z.ZodString>;
|
|
4469
|
+
defaultArgs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>>>;
|
|
4470
|
+
availableWhen: z.ZodOptional<z.ZodString>;
|
|
4459
4471
|
datasources: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>>>;
|
|
4460
4472
|
panels: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
4461
4473
|
kind: z.ZodString;
|
|
@@ -4883,6 +4895,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
4883
4895
|
}>> | undefined;
|
|
4884
4896
|
title?: string | undefined;
|
|
4885
4897
|
open?: string | undefined;
|
|
4898
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
4899
|
+
availableWhen?: string | undefined;
|
|
4886
4900
|
}, {
|
|
4887
4901
|
panels: Record<string, {
|
|
4888
4902
|
kind: string;
|
|
@@ -4963,6 +4977,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
4963
4977
|
title?: string | undefined;
|
|
4964
4978
|
presentation?: "modal" | "drawer" | undefined;
|
|
4965
4979
|
open?: string | undefined;
|
|
4980
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
4981
|
+
availableWhen?: string | undefined;
|
|
4966
4982
|
}>>>;
|
|
4967
4983
|
layouts: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
4968
4984
|
view: z.ZodOptional<z.ZodString>;
|
|
@@ -5380,6 +5396,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
5380
5396
|
}>> | undefined;
|
|
5381
5397
|
title?: string | undefined;
|
|
5382
5398
|
open?: string | undefined;
|
|
5399
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
5400
|
+
availableWhen?: string | undefined;
|
|
5383
5401
|
}> | undefined;
|
|
5384
5402
|
tour?: {
|
|
5385
5403
|
text: string;
|
|
@@ -5690,6 +5708,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
5690
5708
|
title?: string | undefined;
|
|
5691
5709
|
presentation?: "modal" | "drawer" | undefined;
|
|
5692
5710
|
open?: string | undefined;
|
|
5711
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
5712
|
+
availableWhen?: string | undefined;
|
|
5693
5713
|
}> | undefined;
|
|
5694
5714
|
tour?: {
|
|
5695
5715
|
text: string;
|
|
@@ -6003,6 +6023,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
6003
6023
|
}>> | undefined;
|
|
6004
6024
|
title?: string | undefined;
|
|
6005
6025
|
open?: string | undefined;
|
|
6026
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
6027
|
+
availableWhen?: string | undefined;
|
|
6006
6028
|
}> | undefined;
|
|
6007
6029
|
tour?: {
|
|
6008
6030
|
text: string;
|
|
@@ -6329,6 +6351,8 @@ declare const Dashboard: z.ZodObject<{
|
|
|
6329
6351
|
title?: string | undefined;
|
|
6330
6352
|
presentation?: "modal" | "drawer" | undefined;
|
|
6331
6353
|
open?: string | undefined;
|
|
6354
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
6355
|
+
availableWhen?: string | undefined;
|
|
6332
6356
|
}> | undefined;
|
|
6333
6357
|
tour?: {
|
|
6334
6358
|
text: string;
|
|
@@ -6671,6 +6695,11 @@ declare const Modal: z.ZodObject<{
|
|
|
6671
6695
|
presentation: z.ZodDefault<z.ZodEnum<["modal", "drawer"]>>;
|
|
6672
6696
|
/** Bind open state instead of using openModal, e.g. "${state.heatModal.open}". */
|
|
6673
6697
|
open: z.ZodOptional<z.ZodString>;
|
|
6698
|
+
/** Arguments to reopen with when it has not been opened yet (a host drawer's rail or handle). */
|
|
6699
|
+
defaultArgs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>>>;
|
|
6700
|
+
/** An expression: while false the modal can't be open, and a host drawer (`ui.Drawer`) isn't drawn (e.g. its rail
|
|
6701
|
+
* only on one view: "view == 'flow'"). Default always. */
|
|
6702
|
+
availableWhen: z.ZodOptional<z.ZodString>;
|
|
6674
6703
|
datasources: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodUnknown>, Record<string, unknown>, Record<string, unknown>>>>;
|
|
6675
6704
|
panels: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
6676
6705
|
kind: z.ZodString;
|
|
@@ -7098,6 +7127,8 @@ declare const Modal: z.ZodObject<{
|
|
|
7098
7127
|
}>> | undefined;
|
|
7099
7128
|
title?: string | undefined;
|
|
7100
7129
|
open?: string | undefined;
|
|
7130
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
7131
|
+
availableWhen?: string | undefined;
|
|
7101
7132
|
}, {
|
|
7102
7133
|
panels: Record<string, {
|
|
7103
7134
|
kind: string;
|
|
@@ -7178,6 +7209,8 @@ declare const Modal: z.ZodObject<{
|
|
|
7178
7209
|
title?: string | undefined;
|
|
7179
7210
|
presentation?: "modal" | "drawer" | undefined;
|
|
7180
7211
|
open?: string | undefined;
|
|
7212
|
+
defaultArgs?: Record<string, JsonValue> | undefined;
|
|
7213
|
+
availableWhen?: string | undefined;
|
|
7181
7214
|
}>;
|
|
7182
7215
|
|
|
7183
7216
|
declare const Drill: z.ZodObject<{
|
|
@@ -7588,7 +7621,7 @@ declare class TransformError extends Error {
|
|
|
7588
7621
|
declare function applyTransform(data: unknown, steps: readonly Step[], root: Scope, opts?: TransformOptions): unknown;
|
|
7589
7622
|
|
|
7590
7623
|
/** This package's version. A test keeps it equal to package.json's; bump both together. */
|
|
7591
|
-
declare const RENDERER_VERSION = "0.1.
|
|
7624
|
+
declare const RENDERER_VERSION = "0.1.43";
|
|
7592
7625
|
/**
|
|
7593
7626
|
* Whether `version` satisfies `range`. Supports what documents need: "1.2.3" (that or newer within the major, like
|
|
7594
7627
|
* "^"), ">=1.2", ">1.2.3", "<2", "<=2.1", "^1.2", "~1.2.3", and several of them separated by spaces (all must hold).
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { f as ACTION_KINDS, g as ACTION_SCHEMAS, h as API_VERSION, i as Action, j as ActionRef, k as Auth, B as BREAKPOINTS, l as BUILT_IN_DATASOURCE_TYPES, C as Callback, m as Connection, n as ConnectionSpec, o as DATE_PRESETS, D as Dashboard, p as DashboardInput, q as DataBinding, r as DataError, s as DataErrorCode, t as Datasource, u as DateRange, v as Display, w as Drill, x as Duration, y as EventHandler, z as EventMap, F as Expression, G as ExpressionError, I as FnProp, a$ as Grid, K as Handler, L as HelperSettings, M as Helpers, H as HttpClient, O as HttpClientInternals, P as Id, J as JsonValue, Q as Layout, U as LayoutItem, V as LoadOptions, X as LoadResult, Y as Metadata, Z as MigrateResult, _ as MigrationError, $ as Modal, a0 as NamedAction, N as NetworkOptions, a1 as Node, a2 as Panel, a3 as PanelControl, a4 as PanelMigration, a6 as Problem, a7 as RENDERER_VERSION, a8 as RESERVED_STATE_KEYS, a9 as RefRoot, aa as Reference, ab as Requires, R as ResolvedRequest, ac as SCHEMA_URL, S as Scope, ad as Severity, ae as Spec, b0 as StatusTone, af as Template, a as TimeSettings, ag as TokenSource, ah as TransformError, ai as TransformOptions, aj as TransformStep, ak as Translations, al as VARIABLE_KINDS, am as ValidateOptions, an as ValidationResult, ao as Variable, ap as WidgetCheck, aq as WidgetMigrations, as as applyTransform, at as buildRequestUrl, au as buildUrl, av as builtInWidgetChecks, aw as collectReferences, ax as compile, ay as createHelpers, az as createHttpClient, aA as dashboardJsonSchema, aB as evaluate, aC as evaluateSafe, aD as expressionReferences, aE as graphqlData, aF as interpolate, aG as interpolateUrl, aH as isCallbackSource, aI as isSafeUrl, aJ as loadDocument, aK as mergeConnections, aL as migrateDocument, aM as parse, aN as parseDuration, aO as placeholders, aP as plantDate, aQ as plantDayStart, aR as resolve, aS as resolveBaseUrl, aT as resolveRequest, aU as safeLink, aV as satisfies, aW as scope, aX as stripStrings, aY as templateReferences, aZ as translator, a_ as validateDocument } from './core-
|
|
1
|
+
export { f as ACTION_KINDS, g as ACTION_SCHEMAS, h as API_VERSION, i as Action, j as ActionRef, k as Auth, B as BREAKPOINTS, l as BUILT_IN_DATASOURCE_TYPES, C as Callback, m as Connection, n as ConnectionSpec, o as DATE_PRESETS, D as Dashboard, p as DashboardInput, q as DataBinding, r as DataError, s as DataErrorCode, t as Datasource, u as DateRange, v as Display, w as Drill, x as Duration, y as EventHandler, z as EventMap, F as Expression, G as ExpressionError, I as FnProp, a$ as Grid, K as Handler, L as HelperSettings, M as Helpers, H as HttpClient, O as HttpClientInternals, P as Id, J as JsonValue, Q as Layout, U as LayoutItem, V as LoadOptions, X as LoadResult, Y as Metadata, Z as MigrateResult, _ as MigrationError, $ as Modal, a0 as NamedAction, N as NetworkOptions, a1 as Node, a2 as Panel, a3 as PanelControl, a4 as PanelMigration, a6 as Problem, a7 as RENDERER_VERSION, a8 as RESERVED_STATE_KEYS, a9 as RefRoot, aa as Reference, ab as Requires, R as ResolvedRequest, ac as SCHEMA_URL, S as Scope, ad as Severity, ae as Spec, b0 as StatusTone, af as Template, a as TimeSettings, ag as TokenSource, ah as TransformError, ai as TransformOptions, aj as TransformStep, ak as Translations, al as VARIABLE_KINDS, am as ValidateOptions, an as ValidationResult, ao as Variable, ap as WidgetCheck, aq as WidgetMigrations, as as applyTransform, at as buildRequestUrl, au as buildUrl, av as builtInWidgetChecks, aw as collectReferences, ax as compile, ay as createHelpers, az as createHttpClient, aA as dashboardJsonSchema, aB as evaluate, aC as evaluateSafe, aD as expressionReferences, aE as graphqlData, aF as interpolate, aG as interpolateUrl, aH as isCallbackSource, aI as isSafeUrl, aJ as loadDocument, aK as mergeConnections, aL as migrateDocument, aM as parse, aN as parseDuration, aO as placeholders, aP as plantDate, aQ as plantDayStart, aR as resolve, aS as resolveBaseUrl, aT as resolveRequest, aU as safeLink, aV as satisfies, aW as scope, aX as stripStrings, aY as templateReferences, aZ as translator, a_ as validateDocument } from './core-DJ1ABh7P.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import 'react';
|
package/dist/core.js
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
EventHandler,
|
|
21
21
|
EventMap,
|
|
22
22
|
Expression,
|
|
23
|
-
ExpressionError,
|
|
24
23
|
FnProp,
|
|
25
24
|
Grid,
|
|
26
25
|
Handler,
|
|
@@ -50,38 +49,41 @@ import {
|
|
|
50
49
|
buildRequestUrl,
|
|
51
50
|
buildUrl,
|
|
52
51
|
builtInWidgetChecks,
|
|
53
|
-
collectReferences,
|
|
54
|
-
compile,
|
|
55
52
|
createHelpers,
|
|
56
53
|
createHttpClient,
|
|
57
54
|
dashboardJsonSchema,
|
|
58
|
-
evaluate,
|
|
59
|
-
evaluateSafe,
|
|
60
|
-
expressionReferences,
|
|
61
55
|
graphqlData,
|
|
62
|
-
interpolate,
|
|
63
|
-
interpolateUrl,
|
|
64
56
|
isCallbackSource,
|
|
65
57
|
isSafeUrl,
|
|
66
58
|
loadDocument,
|
|
67
59
|
mergeConnections,
|
|
68
60
|
migrateDocument,
|
|
69
|
-
parse,
|
|
70
61
|
parseDuration,
|
|
71
|
-
placeholders,
|
|
72
62
|
plantDate,
|
|
73
63
|
plantDayStart,
|
|
74
|
-
resolve,
|
|
75
64
|
resolveBaseUrl,
|
|
76
|
-
resolveRequest,
|
|
77
65
|
safeLink,
|
|
78
66
|
satisfies,
|
|
79
|
-
scope,
|
|
80
|
-
stripStrings,
|
|
81
|
-
templateReferences,
|
|
82
67
|
translator,
|
|
83
68
|
validateDocument
|
|
84
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-IBSZQEYY.js";
|
|
70
|
+
import {
|
|
71
|
+
ExpressionError,
|
|
72
|
+
collectReferences,
|
|
73
|
+
compile,
|
|
74
|
+
evaluate,
|
|
75
|
+
evaluateSafe,
|
|
76
|
+
expressionReferences,
|
|
77
|
+
interpolate,
|
|
78
|
+
interpolateUrl,
|
|
79
|
+
parse,
|
|
80
|
+
placeholders,
|
|
81
|
+
resolve,
|
|
82
|
+
resolveRequest,
|
|
83
|
+
scope,
|
|
84
|
+
stripStrings,
|
|
85
|
+
templateReferences
|
|
86
|
+
} from "./chunk-E4CT25TF.js";
|
|
85
87
|
export {
|
|
86
88
|
ACTION_KINDS,
|
|
87
89
|
ACTION_SCHEMAS,
|