@dashspec/renderer 0.0.0-stage → 0.1.1
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 +90 -0
- package/LICENSE +21 -0
- package/README.md +317 -2
- package/dist/chunk-M4WXE3FW.js +254 -0
- package/dist/chunk-M4WXE3FW.js.map +1 -0
- package/dist/chunk-NLKXHTLO.js +178 -0
- package/dist/chunk-NLKXHTLO.js.map +1 -0
- package/dist/chunk-ZUNMBDGH.js +3372 -0
- package/dist/chunk-ZUNMBDGH.js.map +1 -0
- package/dist/core-DXRBVGyG.d.ts +7611 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.js +167 -0
- package/dist/core.js.map +1 -0
- package/dist/index-CdW6ugMG.d.ts +27 -0
- package/dist/index.d.ts +1434 -0
- package/dist/index.js +7638 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox-WEMG76LE.js +10 -0
- package/dist/sandbox-WEMG76LE.js.map +1 -0
- package/dist/sandbox.d.ts +15 -0
- package/dist/sandbox.js +8 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/schema.json +3060 -0
- package/docs/README.md +25 -0
- package/docs/api.md +513 -0
- package/docs/data.md +582 -0
- package/docs/design-systems.md +227 -0
- package/docs/getting-started.md +242 -0
- package/docs/json-format.md +346 -0
- package/docs/security.md +141 -0
- package/docs/server-rendering.md +126 -0
- package/docs/state-and-events.md +551 -0
- package/docs/theming.md +244 -0
- package/docs/widgets.md +606 -0
- package/package.json +104 -3
|
@@ -0,0 +1,3372 @@
|
|
|
1
|
+
// src/core/expr/parse.ts
|
|
2
|
+
var ExpressionError = class extends Error {
|
|
3
|
+
name = "ExpressionError";
|
|
4
|
+
};
|
|
5
|
+
var OPS = [
|
|
6
|
+
"===",
|
|
7
|
+
"!==",
|
|
8
|
+
"??",
|
|
9
|
+
"?.",
|
|
10
|
+
"==",
|
|
11
|
+
"!=",
|
|
12
|
+
"<=",
|
|
13
|
+
">=",
|
|
14
|
+
"&&",
|
|
15
|
+
"||",
|
|
16
|
+
"+",
|
|
17
|
+
"-",
|
|
18
|
+
"*",
|
|
19
|
+
"/",
|
|
20
|
+
"%",
|
|
21
|
+
"<",
|
|
22
|
+
">",
|
|
23
|
+
"!",
|
|
24
|
+
"?",
|
|
25
|
+
":",
|
|
26
|
+
".",
|
|
27
|
+
",",
|
|
28
|
+
"(",
|
|
29
|
+
")",
|
|
30
|
+
"[",
|
|
31
|
+
"]",
|
|
32
|
+
"{",
|
|
33
|
+
"}"
|
|
34
|
+
];
|
|
35
|
+
function tokenize(src) {
|
|
36
|
+
const out = [];
|
|
37
|
+
let i = 0;
|
|
38
|
+
while (i < src.length) {
|
|
39
|
+
const c = src[i];
|
|
40
|
+
if (/\s/.test(c)) {
|
|
41
|
+
i++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (/[0-9]/.test(c) || c === "." && /[0-9]/.test(src[i + 1] ?? "")) {
|
|
45
|
+
const m = /^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(src.slice(i));
|
|
46
|
+
out.push({ k: "num", v: m?.[0] ?? c, at: i });
|
|
47
|
+
i += m?.[0].length ?? 1;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (c === "'" || c === '"') {
|
|
51
|
+
let j = i + 1;
|
|
52
|
+
let s = "";
|
|
53
|
+
while (j < src.length && src[j] !== c) {
|
|
54
|
+
if (src[j] === "\\") {
|
|
55
|
+
const n = src[j + 1];
|
|
56
|
+
s += n === "n" ? "\n" : n === "t" ? " " : n ?? "";
|
|
57
|
+
j += 2;
|
|
58
|
+
} else s += src[j++];
|
|
59
|
+
}
|
|
60
|
+
if (j >= src.length) throw new ExpressionError(`Unclosed string at ${i}`);
|
|
61
|
+
out.push({ k: "str", v: s, at: i });
|
|
62
|
+
i = j + 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (/[A-Za-z_$]/.test(c)) {
|
|
66
|
+
const m = /^[A-Za-z_$][\w$]*/.exec(src.slice(i));
|
|
67
|
+
out.push({ k: "name", v: m[0], at: i });
|
|
68
|
+
i += m[0].length;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const op = OPS.find((o) => src.startsWith(o, i) && !(o === "?." && /\d/.test(src[i + 2] ?? "")));
|
|
72
|
+
if (!op) throw new ExpressionError(`Unexpected "${c}" at ${i}`);
|
|
73
|
+
out.push({ k: "op", v: op, at: i });
|
|
74
|
+
i += op.length;
|
|
75
|
+
}
|
|
76
|
+
out.push({ k: "end", v: "", at: src.length });
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
var BINARY = {
|
|
80
|
+
"??": 1,
|
|
81
|
+
"||": 2,
|
|
82
|
+
"&&": 3,
|
|
83
|
+
"==": 4,
|
|
84
|
+
"!=": 4,
|
|
85
|
+
"===": 4,
|
|
86
|
+
"!==": 4,
|
|
87
|
+
"<": 5,
|
|
88
|
+
"<=": 5,
|
|
89
|
+
">": 5,
|
|
90
|
+
">=": 5,
|
|
91
|
+
"+": 6,
|
|
92
|
+
"-": 6,
|
|
93
|
+
"*": 7,
|
|
94
|
+
"/": 7,
|
|
95
|
+
"%": 7
|
|
96
|
+
};
|
|
97
|
+
function parse(src) {
|
|
98
|
+
const toks = tokenize(src);
|
|
99
|
+
let p = 0;
|
|
100
|
+
const peek = () => toks[p];
|
|
101
|
+
const next = () => toks[p++];
|
|
102
|
+
const isOp = (v) => peek().k === "op" && peek().v === v;
|
|
103
|
+
const expect = (v) => {
|
|
104
|
+
if (!isOp(v)) throw new ExpressionError(`Expected "${v}" at ${peek().at}`);
|
|
105
|
+
p++;
|
|
106
|
+
};
|
|
107
|
+
const expression = () => conditional();
|
|
108
|
+
const conditional = () => {
|
|
109
|
+
const test = binary(0);
|
|
110
|
+
if (!isOp("?")) return test;
|
|
111
|
+
p++;
|
|
112
|
+
const yes = expression();
|
|
113
|
+
expect(":");
|
|
114
|
+
return { t: "cond", test, yes, no: expression() };
|
|
115
|
+
};
|
|
116
|
+
const binary = (min) => {
|
|
117
|
+
let left = unary();
|
|
118
|
+
for (; ; ) {
|
|
119
|
+
const t = peek();
|
|
120
|
+
const prec = t.k === "op" ? BINARY[t.v] : void 0;
|
|
121
|
+
if (prec === void 0 || prec <= min) return left;
|
|
122
|
+
p++;
|
|
123
|
+
left = { t: "binary", op: t.v, left, right: binary(prec) };
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const unary = () => {
|
|
127
|
+
if (isOp("!") || isOp("-") || isOp("+")) return { t: "unary", op: next().v, arg: unary() };
|
|
128
|
+
return postfix(primary());
|
|
129
|
+
};
|
|
130
|
+
const postfix = (start) => {
|
|
131
|
+
let node2 = start;
|
|
132
|
+
let optionalCall = false;
|
|
133
|
+
for (; ; ) {
|
|
134
|
+
if (isOp(".") || isOp("?.")) {
|
|
135
|
+
const optional = next().v === "?.";
|
|
136
|
+
if (optional && isOp("[")) {
|
|
137
|
+
p++;
|
|
138
|
+
node2 = { t: "member", obj: node2, prop: expression(), optional };
|
|
139
|
+
expect("]");
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (optional && isOp("(")) {
|
|
143
|
+
optionalCall = true;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const name = next();
|
|
147
|
+
if (name.k !== "name") throw new ExpressionError(`Expected a property name at ${name.at}`);
|
|
148
|
+
node2 = { t: "member", obj: node2, prop: { t: "lit", v: name.v }, optional };
|
|
149
|
+
} else if (isOp("[")) {
|
|
150
|
+
p++;
|
|
151
|
+
node2 = { t: "member", obj: node2, prop: expression(), optional: false };
|
|
152
|
+
expect("]");
|
|
153
|
+
} else if (isOp("(")) {
|
|
154
|
+
p++;
|
|
155
|
+
const args = [];
|
|
156
|
+
while (!isOp(")")) {
|
|
157
|
+
args.push(expression());
|
|
158
|
+
if (!isOp(")")) expect(",");
|
|
159
|
+
}
|
|
160
|
+
p++;
|
|
161
|
+
node2 = { t: "call", callee: node2, args, ...optionalCall ? { optional: true } : {} };
|
|
162
|
+
optionalCall = false;
|
|
163
|
+
} else return node2;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const primary = () => {
|
|
167
|
+
const t = next();
|
|
168
|
+
if (t.k === "num") return { t: "lit", v: Number(t.v) };
|
|
169
|
+
if (t.k === "str") return { t: "lit", v: t.v };
|
|
170
|
+
if (t.k === "name") {
|
|
171
|
+
if (t.v === "true") return { t: "lit", v: true };
|
|
172
|
+
if (t.v === "false") return { t: "lit", v: false };
|
|
173
|
+
if (t.v === "null") return { t: "lit", v: null };
|
|
174
|
+
if (t.v === "undefined") return { t: "lit", v: void 0 };
|
|
175
|
+
return { t: "name", name: t.v };
|
|
176
|
+
}
|
|
177
|
+
if (t.k === "op" && t.v === "(") {
|
|
178
|
+
const e = expression();
|
|
179
|
+
expect(")");
|
|
180
|
+
return e;
|
|
181
|
+
}
|
|
182
|
+
if (t.k === "op" && t.v === "[") {
|
|
183
|
+
const items = [];
|
|
184
|
+
while (!isOp("]")) {
|
|
185
|
+
items.push(expression());
|
|
186
|
+
if (!isOp("]")) expect(",");
|
|
187
|
+
}
|
|
188
|
+
p++;
|
|
189
|
+
return { t: "array", items };
|
|
190
|
+
}
|
|
191
|
+
if (t.k === "op" && t.v === "{") {
|
|
192
|
+
const entries2 = [];
|
|
193
|
+
while (!isOp("}")) {
|
|
194
|
+
const key = next();
|
|
195
|
+
if (key.k !== "name" && key.k !== "str") throw new ExpressionError(`Expected a key at ${key.at}`);
|
|
196
|
+
expect(":");
|
|
197
|
+
entries2.push([key.v, expression()]);
|
|
198
|
+
if (!isOp("}")) expect(",");
|
|
199
|
+
}
|
|
200
|
+
p++;
|
|
201
|
+
return { t: "object", entries: entries2 };
|
|
202
|
+
}
|
|
203
|
+
throw new ExpressionError(t.k === "end" ? "Unexpected end of expression" : `Unexpected "${t.v}" at ${t.at}`);
|
|
204
|
+
};
|
|
205
|
+
const node = expression();
|
|
206
|
+
if (peek().k !== "end") throw new ExpressionError(`Unexpected "${peek().v}" at ${peek().at}`);
|
|
207
|
+
return node;
|
|
208
|
+
}
|
|
209
|
+
var cache = /* @__PURE__ */ new Map();
|
|
210
|
+
function compile(src) {
|
|
211
|
+
let n = cache.get(src);
|
|
212
|
+
if (!n) {
|
|
213
|
+
n = parse(src);
|
|
214
|
+
if (cache.size > 5e3) cache.clear();
|
|
215
|
+
cache.set(src, n);
|
|
216
|
+
}
|
|
217
|
+
return n;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/core/expr/evaluate.ts
|
|
221
|
+
var scope = (...layers) => ({
|
|
222
|
+
layers: layers.filter((l) => l !== void 0)
|
|
223
|
+
});
|
|
224
|
+
var BLOCKED = /* @__PURE__ */ new Set([
|
|
225
|
+
"__proto__",
|
|
226
|
+
"prototype",
|
|
227
|
+
"constructor",
|
|
228
|
+
"__defineGetter__",
|
|
229
|
+
"__defineSetter__",
|
|
230
|
+
"__lookupGetter__"
|
|
231
|
+
]);
|
|
232
|
+
function lookup(s, name) {
|
|
233
|
+
for (const l of s.layers) if (Object.hasOwn(l, name)) return l[name];
|
|
234
|
+
return void 0;
|
|
235
|
+
}
|
|
236
|
+
function member(obj, key) {
|
|
237
|
+
if (obj === null || obj === void 0) return void 0;
|
|
238
|
+
const k = typeof key === "number" ? key : String(key);
|
|
239
|
+
if (typeof k === "string" && BLOCKED.has(k)) throw new ExpressionError(`"${k}" is not allowed`);
|
|
240
|
+
if (typeof obj === "string") return k === "length" ? obj.length : typeof k === "number" ? obj[k] : void 0;
|
|
241
|
+
if (Array.isArray(obj)) return k === "length" ? obj.length : Object.hasOwn(obj, k) ? obj[k] : void 0;
|
|
242
|
+
if (typeof obj === "object") return Object.hasOwn(obj, k) ? obj[k] : void 0;
|
|
243
|
+
return void 0;
|
|
244
|
+
}
|
|
245
|
+
var looseEq = (a, b) => a === b || a == null && b == null;
|
|
246
|
+
function evalNode(n, s) {
|
|
247
|
+
switch (n.t) {
|
|
248
|
+
case "lit":
|
|
249
|
+
return n.v;
|
|
250
|
+
case "name":
|
|
251
|
+
return lookup(s, n.name);
|
|
252
|
+
case "member":
|
|
253
|
+
return member(evalNode(n.obj, s), evalNode(n.prop, s));
|
|
254
|
+
case "call": {
|
|
255
|
+
const fn = evalNode(n.callee, s);
|
|
256
|
+
if (n.optional && (fn === null || fn === void 0)) return void 0;
|
|
257
|
+
if (typeof fn !== "function") throw new ExpressionError("Only helper functions can be called");
|
|
258
|
+
return fn(...n.args.map((a) => evalNode(a, s)));
|
|
259
|
+
}
|
|
260
|
+
case "unary": {
|
|
261
|
+
const v = evalNode(n.arg, s);
|
|
262
|
+
return n.op === "!" ? !v : n.op === "-" ? -v : +v;
|
|
263
|
+
}
|
|
264
|
+
case "cond":
|
|
265
|
+
return evalNode(n.test, s) ? evalNode(n.yes, s) : evalNode(n.no, s);
|
|
266
|
+
case "array":
|
|
267
|
+
return n.items.map((i) => evalNode(i, s));
|
|
268
|
+
case "object":
|
|
269
|
+
return Object.fromEntries(n.entries.map(([k, v]) => [k, evalNode(v, s)]));
|
|
270
|
+
case "binary": {
|
|
271
|
+
if (n.op === "&&") return evalNode(n.left, s) && evalNode(n.right, s);
|
|
272
|
+
if (n.op === "||") return evalNode(n.left, s) || evalNode(n.right, s);
|
|
273
|
+
if (n.op === "??") return evalNode(n.left, s) ?? evalNode(n.right, s);
|
|
274
|
+
const a = evalNode(n.left, s);
|
|
275
|
+
const b = evalNode(n.right, s);
|
|
276
|
+
switch (n.op) {
|
|
277
|
+
case "==":
|
|
278
|
+
case "===":
|
|
279
|
+
return looseEq(a, b);
|
|
280
|
+
case "!=":
|
|
281
|
+
case "!==":
|
|
282
|
+
return !looseEq(a, b);
|
|
283
|
+
case "<":
|
|
284
|
+
return a < b;
|
|
285
|
+
case "<=":
|
|
286
|
+
return a <= b;
|
|
287
|
+
case ">":
|
|
288
|
+
return a > b;
|
|
289
|
+
case ">=":
|
|
290
|
+
return a >= b;
|
|
291
|
+
case "+":
|
|
292
|
+
return a + b;
|
|
293
|
+
case "-":
|
|
294
|
+
return a - b;
|
|
295
|
+
case "*":
|
|
296
|
+
return a * b;
|
|
297
|
+
case "/":
|
|
298
|
+
return a / b;
|
|
299
|
+
case "%":
|
|
300
|
+
return a % b;
|
|
301
|
+
}
|
|
302
|
+
throw new ExpressionError(`Unknown operator ${n.op}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function evaluate(expr, s) {
|
|
307
|
+
return evalNode(compile(expr), s);
|
|
308
|
+
}
|
|
309
|
+
function evaluateSafe(expr, s, fallback) {
|
|
310
|
+
try {
|
|
311
|
+
return evaluate(expr, s);
|
|
312
|
+
} catch {
|
|
313
|
+
return fallback;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/core/expr/translate.ts
|
|
318
|
+
function pick(translations, locale) {
|
|
319
|
+
const names = Object.keys(translations);
|
|
320
|
+
if (locale) {
|
|
321
|
+
const want = locale.toLowerCase();
|
|
322
|
+
const lang = want.split("-")[0];
|
|
323
|
+
const hit = names.find((n) => n.toLowerCase() === want) ?? names.find((n) => n.toLowerCase() === lang) ?? names.find((n) => n.toLowerCase().split("-")[0] === lang);
|
|
324
|
+
if (hit !== void 0) return translations[hit];
|
|
325
|
+
}
|
|
326
|
+
return names[0] === void 0 ? void 0 : translations[names[0]];
|
|
327
|
+
}
|
|
328
|
+
var own = (dict, key) => dict && typeof dict === "object" && Object.hasOwn(dict, key) && typeof dict[key] === "string" ? dict[key] : void 0;
|
|
329
|
+
function translator(translations, locale) {
|
|
330
|
+
const active = translations ? pick(translations, locale) : void 0;
|
|
331
|
+
const firstName = translations ? Object.keys(translations)[0] : void 0;
|
|
332
|
+
const first = translations && firstName !== void 0 ? translations[firstName] : void 0;
|
|
333
|
+
const text = (key) => own(active, key) ?? own(first, key) ?? key;
|
|
334
|
+
return new Proxy(/* @__PURE__ */ Object.create(null), {
|
|
335
|
+
get: (_, key) => typeof key === "string" ? text(key) : void 0,
|
|
336
|
+
getOwnPropertyDescriptor: (_, key) => typeof key === "string" ? { value: text(key), enumerable: true, configurable: true, writable: false } : void 0,
|
|
337
|
+
has: (_, key) => typeof key === "string",
|
|
338
|
+
// Listing every key: the active locale's and the first locale's.
|
|
339
|
+
ownKeys: () => [.../* @__PURE__ */ new Set([...Object.keys(first ?? {}), ...Object.keys(active ?? {})])],
|
|
340
|
+
set: () => false,
|
|
341
|
+
defineProperty: () => false,
|
|
342
|
+
deleteProperty: () => false
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/core/expr/helpers.ts
|
|
347
|
+
var MS = { ms: 1, s: 1e3, m: 6e4, h: 36e5, d: 864e5, w: 6048e5 };
|
|
348
|
+
function parseDuration(d) {
|
|
349
|
+
const m = /^(\d+(?:\.\d+)?)(ms|s|m|h|d|w)$/.exec(d.trim());
|
|
350
|
+
if (!m) throw new Error(`Not a duration: "${d}"`);
|
|
351
|
+
return Number(m[1]) * MS[m[2]];
|
|
352
|
+
}
|
|
353
|
+
function zoneOffset(at, timeZone) {
|
|
354
|
+
if (!timeZone) return -new Date(at).getTimezoneOffset() * 6e4;
|
|
355
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
356
|
+
timeZone,
|
|
357
|
+
hourCycle: "h23",
|
|
358
|
+
year: "numeric",
|
|
359
|
+
month: "2-digit",
|
|
360
|
+
day: "2-digit",
|
|
361
|
+
hour: "2-digit",
|
|
362
|
+
minute: "2-digit",
|
|
363
|
+
second: "2-digit"
|
|
364
|
+
}).formatToParts(new Date(at));
|
|
365
|
+
const get = (t) => Number(parts.find((p) => p.type === t)?.value);
|
|
366
|
+
const asUtc = Date.UTC(get("year"), get("month") - 1, get("day"), get("hour"), get("minute"), get("second"));
|
|
367
|
+
return asUtc - Math.floor(at / 1e3) * 1e3;
|
|
368
|
+
}
|
|
369
|
+
var dayStartMinutes = (s) => {
|
|
370
|
+
const [h, m] = (s ?? "00:00").split(":").map(Number);
|
|
371
|
+
return (h ?? 0) * 60 + (m ?? 0);
|
|
372
|
+
};
|
|
373
|
+
function plantDayStart(at, t) {
|
|
374
|
+
const shift = dayStartMinutes(t.dayStartsAt) * 6e4;
|
|
375
|
+
const offset = zoneOffset(at, t.timeZone);
|
|
376
|
+
const local = at + offset - shift;
|
|
377
|
+
const startLocal = Math.floor(local / MS.d) * MS.d + shift;
|
|
378
|
+
return startLocal - zoneOffset(startLocal - offset, t.timeZone);
|
|
379
|
+
}
|
|
380
|
+
function plantDate(at, t) {
|
|
381
|
+
const shift = dayStartMinutes(t.dayStartsAt) * 6e4;
|
|
382
|
+
return new Date(at + zoneOffset(at, t.timeZone) - shift).toISOString().slice(0, 10);
|
|
383
|
+
}
|
|
384
|
+
var daysBetween = (r) => Math.round((Date.parse(r.to) - Date.parse(r.from)) / MS.d) + 1;
|
|
385
|
+
function createHelpers(t = {}) {
|
|
386
|
+
const now = t.now ?? Date.now;
|
|
387
|
+
const locale = t.locale;
|
|
388
|
+
const num2 = (v) => typeof v === "number" ? v : Number(v);
|
|
389
|
+
const fmt = {
|
|
390
|
+
number: (v, decimals) => v === null || v === void 0 || Number.isNaN(num2(v)) ? "" : new Intl.NumberFormat(
|
|
391
|
+
locale,
|
|
392
|
+
decimals === void 0 ? {} : { minimumFractionDigits: decimals, maximumFractionDigits: decimals }
|
|
393
|
+
).format(num2(v)),
|
|
394
|
+
compact: (v) => v === null || v === void 0 ? "" : new Intl.NumberFormat(locale, { notation: "compact", maximumFractionDigits: 1 }).format(num2(v)),
|
|
395
|
+
/** `v` is already a percentage (42.5 → "42.5%"). */
|
|
396
|
+
percent: (v, decimals = 0) => v === null || v === void 0 ? "" : `${fmt.number(v, decimals)}%`,
|
|
397
|
+
/** Seconds → "1 hr 5 min", "1 min 13 sec". */
|
|
398
|
+
duration: (seconds) => {
|
|
399
|
+
let s = Math.round(num2(seconds));
|
|
400
|
+
if (!Number.isFinite(s)) return "";
|
|
401
|
+
const h = Math.floor(s / 3600);
|
|
402
|
+
s -= h * 3600;
|
|
403
|
+
const m = Math.floor(s / 60);
|
|
404
|
+
s -= m * 60;
|
|
405
|
+
if (h) return m ? `${h} hr ${m} min` : `${h} hr`;
|
|
406
|
+
if (m) return s ? `${m} min ${s} sec` : `${m} min`;
|
|
407
|
+
return `${s} sec`;
|
|
408
|
+
},
|
|
409
|
+
date: (v, style = "date") => {
|
|
410
|
+
if (v === null || v === void 0 || v === "") return "";
|
|
411
|
+
const d = new Date(typeof v === "number" ? v : String(v));
|
|
412
|
+
if (Number.isNaN(d.getTime())) return String(v);
|
|
413
|
+
const opts = style === "time" ? { timeStyle: "short" } : style === "datetime" ? { dateStyle: "medium", timeStyle: "short" } : { dateStyle: "medium" };
|
|
414
|
+
return new Intl.DateTimeFormat(locale, { ...opts, ...t.timeZone ? { timeZone: t.timeZone } : {} }).format(d);
|
|
415
|
+
},
|
|
416
|
+
/** "just now", "2 min ago", "3 hr ago", "4 days ago". */
|
|
417
|
+
ago: (v) => {
|
|
418
|
+
if (v === null || v === void 0 || v === "") return "";
|
|
419
|
+
const at = typeof v === "number" ? v : Date.parse(String(v));
|
|
420
|
+
if (Number.isNaN(at)) return "";
|
|
421
|
+
const s = Math.max(0, Math.round((now() - at) / 1e3));
|
|
422
|
+
if (s < 45) return "just now";
|
|
423
|
+
if (s < 3600) return `${Math.round(s / 60)} min ago`;
|
|
424
|
+
if (s < 86400) return `${Math.round(s / 3600)} hr ago`;
|
|
425
|
+
return `${Math.round(s / 86400)} days ago`;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
return {
|
|
429
|
+
has: (list2, v) => Array.isArray(list2) ? list2.includes(v) : typeof list2 === "string" ? list2.includes(String(v)) : false,
|
|
430
|
+
len: (v) => Array.isArray(v) || typeof v === "string" ? v.length : v && typeof v === "object" ? Object.keys(v).length : 0,
|
|
431
|
+
round: (v, decimals = 0) => {
|
|
432
|
+
const f = 10 ** decimals;
|
|
433
|
+
return Math.round(num2(v) * f) / f;
|
|
434
|
+
},
|
|
435
|
+
// Folds instead of spreading: a spread of a large array exceeds the engine's argument limit.
|
|
436
|
+
min: (...v) => v.flat().map(num2).reduce((a, b) => Math.min(a, b), Number.POSITIVE_INFINITY),
|
|
437
|
+
max: (...v) => v.flat().map(num2).reduce((a, b) => Math.max(a, b), Number.NEGATIVE_INFINITY),
|
|
438
|
+
sum: (list2, key) => Array.isArray(list2) ? list2.reduce((a, x) => a + num2(key ? x?.[key] : x) || a, 0) : 0,
|
|
439
|
+
/** First item of `list` whose `key` equals `value`. */
|
|
440
|
+
lookup: (list2, key, value) => Array.isArray(list2) ? list2.find((x) => x && typeof x === "object" && x[key] === value) : void 0,
|
|
441
|
+
join: (list2, sep = ",") => Array.isArray(list2) ? list2.join(sep) : list2 === null || list2 === void 0 ? "" : String(list2),
|
|
442
|
+
lower: (v) => String(v ?? "").toLowerCase(),
|
|
443
|
+
upper: (v) => String(v ?? "").toUpperCase(),
|
|
444
|
+
/** Epoch ms. */
|
|
445
|
+
now: () => now(),
|
|
446
|
+
/** Epoch ms `d` ago, e.g. ago('8h'). */
|
|
447
|
+
ago: (d) => now() - parseDuration(d),
|
|
448
|
+
/** Start of today's plant day (epoch ms). */
|
|
449
|
+
dayStart: () => plantDayStart(now(), t),
|
|
450
|
+
/** Today's plant date, "YYYY-MM-DD". */
|
|
451
|
+
today: () => plantDate(now(), t),
|
|
452
|
+
includesToday: (r) => {
|
|
453
|
+
if (!r || typeof r !== "object") return false;
|
|
454
|
+
const { from, to } = r;
|
|
455
|
+
const today = plantDate(now(), t);
|
|
456
|
+
return from <= today && today <= to;
|
|
457
|
+
},
|
|
458
|
+
/** heat ≤ 1 day, day ≤ 31, week ≤ 92, month ≤ 730, else year. */
|
|
459
|
+
granularityFor: (r) => {
|
|
460
|
+
if (!r || typeof r !== "object") return "day";
|
|
461
|
+
const days = daysBetween(r);
|
|
462
|
+
return days <= 1 ? "heat" : days <= 31 ? "day" : days <= 92 ? "week" : days <= 730 ? "month" : "year";
|
|
463
|
+
},
|
|
464
|
+
fmt,
|
|
465
|
+
/** `display.translations` for the active locale: `${t.revenue}`; falls back to the first locale, then the key. */
|
|
466
|
+
t: translator(t.translations, locale)
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/core/expr/references.ts
|
|
471
|
+
var ROOTS = ["datasources", "panels", "filters", "state", "modal", "context", "event", "drill", "panel"];
|
|
472
|
+
var REF = new RegExp(`(?<![\\w.$])(${ROOTS.join("|")})\\.([A-Za-z_][\\w-]*)`, "g");
|
|
473
|
+
function placeholders(template) {
|
|
474
|
+
const out = [];
|
|
475
|
+
let i = template.indexOf("${");
|
|
476
|
+
while (i !== -1) {
|
|
477
|
+
let depth = 1;
|
|
478
|
+
let j = i + 2;
|
|
479
|
+
let quote = null;
|
|
480
|
+
for (; j < template.length && depth > 0; j++) {
|
|
481
|
+
const c = template[j];
|
|
482
|
+
if (quote) {
|
|
483
|
+
if (c === "\\") j++;
|
|
484
|
+
else if (c === quote) quote = null;
|
|
485
|
+
} else if (c === "'" || c === '"' || c === "`") quote = c;
|
|
486
|
+
else if (c === "{") depth++;
|
|
487
|
+
else if (c === "}") depth--;
|
|
488
|
+
}
|
|
489
|
+
if (depth !== 0) break;
|
|
490
|
+
out.push(template.slice(i + 2, j - 1));
|
|
491
|
+
i = template.indexOf("${", j);
|
|
492
|
+
}
|
|
493
|
+
return out;
|
|
494
|
+
}
|
|
495
|
+
var stripStrings = (expr) => expr.replace(/'(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`/g, "''");
|
|
496
|
+
function expressionReferences(expr) {
|
|
497
|
+
const out = [];
|
|
498
|
+
for (const m of stripStrings(expr).matchAll(REF)) out.push({ root: m[1], name: m[2] });
|
|
499
|
+
return out;
|
|
500
|
+
}
|
|
501
|
+
function templateReferences(template) {
|
|
502
|
+
return placeholders(template).flatMap(expressionReferences);
|
|
503
|
+
}
|
|
504
|
+
function collectReferences(value, out = []) {
|
|
505
|
+
if (typeof value === "string") out.push(...templateReferences(value));
|
|
506
|
+
else if (Array.isArray(value)) for (const v of value) collectReferences(v, out);
|
|
507
|
+
else if (value && typeof value === "object") for (const v of Object.values(value)) collectReferences(v, out);
|
|
508
|
+
return out;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/core/expr/template.ts
|
|
512
|
+
var WHOLE = /^\$\{[\s\S]*\}$/;
|
|
513
|
+
function interpolate(template, s, encode) {
|
|
514
|
+
if (!template.includes("${")) return template;
|
|
515
|
+
const bodies = placeholders(template);
|
|
516
|
+
if (bodies.length === 1 && WHOLE.test(template.trim()) && template.trim() === `\${${bodies[0]}}`)
|
|
517
|
+
return evaluate(bodies[0], s);
|
|
518
|
+
let out = "";
|
|
519
|
+
let i = 0;
|
|
520
|
+
for (const body of bodies) {
|
|
521
|
+
const at = template.indexOf(`\${${body}}`, i);
|
|
522
|
+
out += template.slice(i, at);
|
|
523
|
+
const v = evaluate(body, s);
|
|
524
|
+
const text = v === null || v === void 0 ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
525
|
+
out += encode ? encode(text) : text;
|
|
526
|
+
i = at + body.length + 3;
|
|
527
|
+
}
|
|
528
|
+
return out + template.slice(i);
|
|
529
|
+
}
|
|
530
|
+
function resolve(value, s) {
|
|
531
|
+
if (typeof value === "string") return interpolate(value, s);
|
|
532
|
+
if (Array.isArray(value)) return value.map((v) => resolve(v, s));
|
|
533
|
+
if (value && typeof value === "object")
|
|
534
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, resolve(v, s)]));
|
|
535
|
+
return value;
|
|
536
|
+
}
|
|
537
|
+
function interpolateUrl(template, s) {
|
|
538
|
+
return interpolate(template, s, encodeURIComponent);
|
|
539
|
+
}
|
|
540
|
+
function resolveRequest(request, s) {
|
|
541
|
+
const out = {};
|
|
542
|
+
for (const [k, v] of Object.entries(request))
|
|
543
|
+
out[k] = (k === "url" || k === "path") && typeof v === "string" ? interpolateUrl(v, s) : resolve(v, s);
|
|
544
|
+
return out;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/core/http/index.ts
|
|
548
|
+
var DataError = class extends Error {
|
|
549
|
+
constructor(code, message, status, datasource) {
|
|
550
|
+
super(message);
|
|
551
|
+
this.code = code;
|
|
552
|
+
this.status = status;
|
|
553
|
+
this.datasource = datasource;
|
|
554
|
+
}
|
|
555
|
+
name = "DataError";
|
|
556
|
+
toJSON() {
|
|
557
|
+
return { code: this.code, status: this.status, message: this.message, datasource: this.datasource };
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
function mergeConnections(json = {}, host = {}, map = {}) {
|
|
561
|
+
const own2 = (c) => Object.assign(/* @__PURE__ */ Object.create(null), c);
|
|
562
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
563
|
+
for (const [name, c] of Object.entries(json)) {
|
|
564
|
+
const hostName = map[name] ?? name;
|
|
565
|
+
const h = Object.hasOwn(host, hostName) ? host[hostName] : void 0;
|
|
566
|
+
out[name] = own2(h ? { ...c, ...h, headers: { ...c.headers, ...h.headers } } : c);
|
|
567
|
+
}
|
|
568
|
+
for (const [name, c] of Object.entries(host)) if (!Object.hasOwn(out, name)) out[name] = own2(c);
|
|
569
|
+
return out;
|
|
570
|
+
}
|
|
571
|
+
function resolveBaseUrl(base2, pageHost) {
|
|
572
|
+
if (base2 === void 0 || typeof base2 === "string") return base2;
|
|
573
|
+
return Object.hasOwn(base2, pageHost) ? base2[pageHost] : Object.hasOwn(base2, "*") ? base2["*"] : void 0;
|
|
574
|
+
}
|
|
575
|
+
var joinUrl = (base2, path) => `${base2.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
576
|
+
var isEmpty = (v) => v === null || v === void 0 || v === "" || Array.isArray(v) && v.length === 0;
|
|
577
|
+
function buildUrl(url, query, omitEmpty) {
|
|
578
|
+
if (!query) return url;
|
|
579
|
+
const params = [];
|
|
580
|
+
for (const [k, v] of Object.entries(query)) {
|
|
581
|
+
if (v === void 0 || v === null || omitEmpty && isEmpty(v)) continue;
|
|
582
|
+
for (const item of Array.isArray(v) ? v : [v]) {
|
|
583
|
+
const s = typeof item === "object" ? JSON.stringify(item) : String(item);
|
|
584
|
+
params.push(`${encodeURIComponent(k)}=${encodeURIComponent(s)}`);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (params.length === 0) return url;
|
|
588
|
+
return `${url}${url.includes("?") ? "&" : "?"}${params.join("&")}`;
|
|
589
|
+
}
|
|
590
|
+
var originOf = (url, pageHost) => {
|
|
591
|
+
try {
|
|
592
|
+
return new URL(url, `https://${pageHost}`).origin;
|
|
593
|
+
} catch {
|
|
594
|
+
return void 0;
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
var readJsonPath = (obj, path) => path.replace(/^\$\.?/, "").split(".").filter(Boolean).reduce((o, k) => o && typeof o === "object" ? o[k] : void 0, obj);
|
|
598
|
+
function buildRequestUrl(request, c, pageHost) {
|
|
599
|
+
let url = request.url;
|
|
600
|
+
if (!url) {
|
|
601
|
+
const base2 = c ? resolveBaseUrl(c.baseUrl, pageHost) : void 0;
|
|
602
|
+
if (c?.baseUrl !== void 0 && base2 === void 0)
|
|
603
|
+
throw new DataError(
|
|
604
|
+
"config",
|
|
605
|
+
`Connection "${request.connection}" has no baseUrl for ${pageHost}; add it or a "*" fallback`,
|
|
606
|
+
void 0,
|
|
607
|
+
request.datasource
|
|
608
|
+
);
|
|
609
|
+
url = base2 ? joinUrl(base2, request.path ?? "") : request.path ?? "";
|
|
610
|
+
}
|
|
611
|
+
return buildUrl(url, request.query, request.omitEmpty ?? false);
|
|
612
|
+
}
|
|
613
|
+
var MAX_RETRY_AFTER_MS = 3e4;
|
|
614
|
+
function retryAfterMs(value, now) {
|
|
615
|
+
if (!value) return void 0;
|
|
616
|
+
const secs = Number(value);
|
|
617
|
+
const ms = Number.isFinite(secs) && value.trim() !== "" ? secs * 1e3 : Date.parse(value) - now;
|
|
618
|
+
return Number.isFinite(ms) ? Math.min(MAX_RETRY_AFTER_MS, Math.max(0, ms)) : void 0;
|
|
619
|
+
}
|
|
620
|
+
function whenAborted(signal, datasource) {
|
|
621
|
+
return new Promise((_, reject) => {
|
|
622
|
+
if (!signal) return;
|
|
623
|
+
const fail = () => reject(new DataError("aborted", "Request cancelled", void 0, datasource));
|
|
624
|
+
if (signal.aborted) fail();
|
|
625
|
+
else signal.addEventListener("abort", fail, { once: true });
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
function graphqlData(response, datasource) {
|
|
629
|
+
if (!response || typeof response !== "object") return response;
|
|
630
|
+
const r = response;
|
|
631
|
+
if (Array.isArray(r.errors) && r.errors.length > 0) {
|
|
632
|
+
const first = r.errors[0];
|
|
633
|
+
const msg = typeof first?.message === "string" && first.message ? first.message : "GraphQL request failed";
|
|
634
|
+
throw new DataError("http", msg, void 0, datasource);
|
|
635
|
+
}
|
|
636
|
+
return Object.hasOwn(r, "data") ? r.data : void 0;
|
|
637
|
+
}
|
|
638
|
+
function browserStorage(name) {
|
|
639
|
+
if (typeof window === "undefined") return void 0;
|
|
640
|
+
try {
|
|
641
|
+
return window[name];
|
|
642
|
+
} catch {
|
|
643
|
+
return void 0;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function createHttpClient(json, opts = {}, internals = {}) {
|
|
647
|
+
const connections = mergeConnections(json, opts.connections, opts.connectionMap);
|
|
648
|
+
const doFetch = opts.fetch ?? ((...a) => globalThis.fetch(...a));
|
|
649
|
+
const pageHost = opts.pageHost ?? (typeof window !== "undefined" ? window.location.host : "localhost");
|
|
650
|
+
const local = opts.storage?.local ?? browserStorage("localStorage");
|
|
651
|
+
const session = opts.storage?.session ?? browserStorage("sessionStorage");
|
|
652
|
+
const cookies = opts.storage?.cookie ?? (() => typeof document !== "undefined" ? document.cookie : "");
|
|
653
|
+
const maxBytes = opts.maxResponseBytes ?? 10 * 1024 * 1024;
|
|
654
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
655
|
+
const refreshing = /* @__PURE__ */ new Map();
|
|
656
|
+
const fillHeaders = (h, name) => {
|
|
657
|
+
if (!h) return {};
|
|
658
|
+
if (!internals.resolveTemplates) return { ...h };
|
|
659
|
+
let v;
|
|
660
|
+
try {
|
|
661
|
+
v = internals.resolveTemplates(h);
|
|
662
|
+
} catch (e) {
|
|
663
|
+
throw new DataError("config", `Connection "${name}": a header template failed: ${e.message}`);
|
|
664
|
+
}
|
|
665
|
+
const out = {};
|
|
666
|
+
for (const [k, x] of Object.entries(v ?? {})) {
|
|
667
|
+
if (x === void 0 || x === null || x === "") continue;
|
|
668
|
+
out[k] = typeof x === "object" ? JSON.stringify(x) : String(x);
|
|
669
|
+
}
|
|
670
|
+
return out;
|
|
671
|
+
};
|
|
672
|
+
const readStored = (from, key) => {
|
|
673
|
+
if (!key) return void 0;
|
|
674
|
+
if (from === "localStorage") return local?.getItem(key) ?? void 0;
|
|
675
|
+
if (from === "sessionStorage") return session?.getItem(key) ?? void 0;
|
|
676
|
+
if (from === "cookie") {
|
|
677
|
+
const name = `${encodeURIComponent(key)}=`;
|
|
678
|
+
const m = cookies().split(/;\s*/).find((c) => c.startsWith(name));
|
|
679
|
+
return m ? decodeURIComponent(m.slice(name.length)) : void 0;
|
|
680
|
+
}
|
|
681
|
+
return void 0;
|
|
682
|
+
};
|
|
683
|
+
const writeStored = (from, key, value) => {
|
|
684
|
+
if (from === "sessionStorage") session?.setItem(key, value);
|
|
685
|
+
else if (from === "localStorage") local?.setItem(key, value);
|
|
686
|
+
};
|
|
687
|
+
const hostNames = /* @__PURE__ */ new Set([...Object.keys(opts.connections ?? {}), ...Object.keys(opts.connectionMap ?? {})]);
|
|
688
|
+
const pageOrigin = originOf("/", pageHost);
|
|
689
|
+
const trusted = /* @__PURE__ */ new Set([pageOrigin, ...(opts.trustedOrigins ?? []).map((o) => originOf(o, pageHost))]);
|
|
690
|
+
const declaredOrigin = (c) => c.baseUrl !== void 0 ? originOf(resolveBaseUrl(c.baseUrl, pageHost) ?? "", pageHost) : pageOrigin;
|
|
691
|
+
const mayUseStored = (name, c) => hostNames.has(name) || trusted.has(declaredOrigin(c));
|
|
692
|
+
const untrusted = (name, c) => new DataError(
|
|
693
|
+
"config",
|
|
694
|
+
`Connection "${name}" would send stored credentials to ${declaredOrigin(c)}, which the host hasn't trusted. Add it to trustedOrigins, or give the token through getToken.`
|
|
695
|
+
);
|
|
696
|
+
async function token(name, c, src) {
|
|
697
|
+
if (src.from === "host") return await opts.getToken?.(name) ?? void 0;
|
|
698
|
+
if (!mayUseStored(name, c)) throw untrusted(name, c);
|
|
699
|
+
return readStored(src.from, src.key);
|
|
700
|
+
}
|
|
701
|
+
async function refresh(name, c, base2) {
|
|
702
|
+
const auth = c.auth;
|
|
703
|
+
if (!auth || auth.type !== "bearer" || !auth.refresh) return false;
|
|
704
|
+
let p = refreshing.get(name);
|
|
705
|
+
if (!p) {
|
|
706
|
+
p = (async () => {
|
|
707
|
+
const r = auth.refresh;
|
|
708
|
+
const from = auth.token.from;
|
|
709
|
+
if (r.from === "host") {
|
|
710
|
+
const t = await opts.refreshToken?.(name);
|
|
711
|
+
if (typeof t === "string" && auth.token.key) writeStored(from, auth.token.key, t);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (!mayUseStored(name, c)) throw untrusted(name, c);
|
|
715
|
+
const url = r.url ?? (base2 ? joinUrl(base2, r.path) : r.path);
|
|
716
|
+
if (originOf(url, pageHost) !== declaredOrigin(c))
|
|
717
|
+
throw new DataError("config", `Connection "${name}": the token refresh must go to ${declaredOrigin(c)}`);
|
|
718
|
+
const save = r.save ?? {};
|
|
719
|
+
const store = from === "host" ? "localStorage" : from;
|
|
720
|
+
const fill = (v) => typeof v === "string" ? v.replace(/\$\{storage\.([\w-]+)\}/g, (_, k) => readStored(store, k) ?? "") : Array.isArray(v) ? v.map(fill) : v && typeof v === "object" ? Object.fromEntries(Object.entries(v).map(([k, x]) => [k, fill(x)])) : v;
|
|
721
|
+
const res = await doFetch(url, {
|
|
722
|
+
method: r.method ?? "POST",
|
|
723
|
+
headers: { "Content-Type": "application/json", ...fillHeaders(r.headers, name) },
|
|
724
|
+
body: JSON.stringify(fill(r.body ?? {})),
|
|
725
|
+
signal: AbortSignal.timeout(parseDuration(c.timeout ?? "30s"))
|
|
726
|
+
});
|
|
727
|
+
if (!res.ok) throw new DataError("http", `Token refresh failed (${res.status})`, res.status);
|
|
728
|
+
const data = await res.json();
|
|
729
|
+
for (const [key, path] of Object.entries(save)) {
|
|
730
|
+
const v = readJsonPath(data, path);
|
|
731
|
+
if (typeof v === "string") writeStored(store, key, v);
|
|
732
|
+
}
|
|
733
|
+
})().finally(() => refreshing.delete(name));
|
|
734
|
+
refreshing.set(name, p);
|
|
735
|
+
}
|
|
736
|
+
await p;
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
async function once(req2, c, signal) {
|
|
740
|
+
const headers = {
|
|
741
|
+
Accept: "application/json",
|
|
742
|
+
...fillHeaders(c?.headers, req2.connection),
|
|
743
|
+
...req2.headers
|
|
744
|
+
};
|
|
745
|
+
let url = req2.url;
|
|
746
|
+
let credentials;
|
|
747
|
+
const name = req2.connection;
|
|
748
|
+
const sameOrigin = name !== void 0 && c !== void 0 && originOf(url, pageHost) === declaredOrigin(c);
|
|
749
|
+
const auth = c?.auth;
|
|
750
|
+
if (auth && c && name && sameOrigin) {
|
|
751
|
+
if (auth.type === "cookie") {
|
|
752
|
+
if (!mayUseStored(name, c)) throw untrusted(name, c);
|
|
753
|
+
credentials = "include";
|
|
754
|
+
}
|
|
755
|
+
if (auth.type === "bearer") {
|
|
756
|
+
const t = await token(name, c, auth.token);
|
|
757
|
+
if (t) headers[auth.header ?? "Authorization"] = `${auth.scheme ?? "Bearer"} ${t}`.trim();
|
|
758
|
+
}
|
|
759
|
+
if (auth.type === "apiKey") {
|
|
760
|
+
const t = await token(name, c, auth.from);
|
|
761
|
+
if (t && auth.in === "header") headers[auth.name] = t;
|
|
762
|
+
if (t && auth.in === "query") url = buildUrl(url, { [auth.name]: t }, false);
|
|
763
|
+
}
|
|
764
|
+
if (auth.type === "headers") Object.assign(headers, fillHeaders(auth.headers, name));
|
|
765
|
+
}
|
|
766
|
+
let body;
|
|
767
|
+
if (req2.body !== void 0 && req2.method !== "GET") {
|
|
768
|
+
body = typeof req2.body === "string" ? req2.body : JSON.stringify(req2.body);
|
|
769
|
+
headers["Content-Type"] ??= "application/json";
|
|
770
|
+
}
|
|
771
|
+
return doFetch(url, { method: req2.method, headers, body, signal, ...credentials ? { credentials } : {} });
|
|
772
|
+
}
|
|
773
|
+
async function send(request, outer) {
|
|
774
|
+
const name = request.connection;
|
|
775
|
+
const c = name ? connections[name] : void 0;
|
|
776
|
+
if (name && !c)
|
|
777
|
+
throw new DataError("config", `Connection "${name}" is not declared`, void 0, request.datasource);
|
|
778
|
+
const full = { ...request, url: buildRequestUrl(request, c, pageHost) };
|
|
779
|
+
opts.onRequest?.(full);
|
|
780
|
+
const timeoutMs = parseDuration(request.timeout ?? c?.timeout ?? "30s");
|
|
781
|
+
const retryCfg = request.retry ?? c?.retry;
|
|
782
|
+
const retryable = retryCfg !== false && (request.method === "GET" || retryCfg !== void 0);
|
|
783
|
+
const times = retryable ? retryCfg ? retryCfg.times ?? 2 : 2 : 0;
|
|
784
|
+
const RETRY_ON = [408, 429, 500, 502, 503, 504];
|
|
785
|
+
const retryOn = retryCfg === false || retryCfg === void 0 ? RETRY_ON : retryCfg.on ?? RETRY_ON;
|
|
786
|
+
const exponential = !retryCfg || retryCfg.backoff !== "fixed";
|
|
787
|
+
for (let attempt = 0; ; attempt++) {
|
|
788
|
+
const ctrl = new AbortController();
|
|
789
|
+
const onAbort = () => ctrl.abort();
|
|
790
|
+
outer?.addEventListener("abort", onAbort);
|
|
791
|
+
let timedOut = false;
|
|
792
|
+
const timer = setTimeout(() => {
|
|
793
|
+
timedOut = true;
|
|
794
|
+
ctrl.abort();
|
|
795
|
+
}, timeoutMs);
|
|
796
|
+
let retryAfter;
|
|
797
|
+
try {
|
|
798
|
+
if (outer?.aborted) throw new DataError("aborted", "Request cancelled", void 0, request.datasource);
|
|
799
|
+
if (opts.transport) {
|
|
800
|
+
const data2 = await opts.transport(full, ctrl.signal);
|
|
801
|
+
opts.onResponse?.({ status: 200, data: data2 }, full);
|
|
802
|
+
return data2;
|
|
803
|
+
}
|
|
804
|
+
let res = await once(full, c, ctrl.signal);
|
|
805
|
+
if (res.status === 401 && name && c) {
|
|
806
|
+
const refreshed = await Promise.race([
|
|
807
|
+
refresh(name, c, resolveBaseUrl(c.baseUrl, pageHost)).catch(() => false),
|
|
808
|
+
whenAborted(ctrl.signal, request.datasource)
|
|
809
|
+
]);
|
|
810
|
+
if (refreshed) res = await once(full, c, ctrl.signal);
|
|
811
|
+
}
|
|
812
|
+
const len = Number(res.headers.get("content-length") ?? 0);
|
|
813
|
+
if (len > maxBytes)
|
|
814
|
+
throw new DataError(
|
|
815
|
+
"too-large",
|
|
816
|
+
`Response is ${len} bytes; the limit is ${maxBytes}`,
|
|
817
|
+
res.status,
|
|
818
|
+
request.datasource
|
|
819
|
+
);
|
|
820
|
+
const text = await res.text();
|
|
821
|
+
if (text.length > maxBytes)
|
|
822
|
+
throw new DataError("too-large", `Response is over ${maxBytes} bytes`, res.status, request.datasource);
|
|
823
|
+
let data = text;
|
|
824
|
+
if (text && (res.headers.get("content-type") ?? "").includes("json")) {
|
|
825
|
+
try {
|
|
826
|
+
data = JSON.parse(text);
|
|
827
|
+
} catch {
|
|
828
|
+
throw new DataError("parse", "The response is not valid JSON", res.status, request.datasource);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
opts.onResponse?.({ status: res.status, data }, full);
|
|
832
|
+
if (!res.ok) {
|
|
833
|
+
retryAfter = retryAfterMs(res.headers.get("retry-after"), Date.now());
|
|
834
|
+
const msg = data && typeof data === "object" && "detail" in data ? String(data.detail) : res.statusText;
|
|
835
|
+
throw new DataError("http", `${res.status} ${msg || "Request failed"}`, res.status, request.datasource);
|
|
836
|
+
}
|
|
837
|
+
return data;
|
|
838
|
+
} catch (e) {
|
|
839
|
+
const err = e instanceof DataError && !(e.code === "aborted" && timedOut) ? e : timedOut ? new DataError("timeout", `No answer within ${timeoutMs / 1e3}s`, void 0, request.datasource) : outer?.aborted ? new DataError("aborted", "Request cancelled", void 0, request.datasource) : new DataError("network", e.message || "Network error", void 0, request.datasource);
|
|
840
|
+
const canRetry = attempt < times && (err.code === "network" || err.code === "timeout" || err.code === "http" && retryOn.includes(err.status ?? 0));
|
|
841
|
+
if (!canRetry) throw err;
|
|
842
|
+
await Promise.race([
|
|
843
|
+
sleep(retryAfter ?? (exponential ? 300 * 2 ** attempt : 500)),
|
|
844
|
+
whenAborted(outer, request.datasource)
|
|
845
|
+
]);
|
|
846
|
+
} finally {
|
|
847
|
+
clearTimeout(timer);
|
|
848
|
+
outer?.removeEventListener("abort", onAbort);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function streamTarget(request) {
|
|
853
|
+
const name = request.connection;
|
|
854
|
+
const c = name ? connections[name] : void 0;
|
|
855
|
+
if (name && !c)
|
|
856
|
+
throw new DataError("config", `Connection "${name}" is not declared`, void 0, request.datasource);
|
|
857
|
+
const url = buildRequestUrl(request, c, pageHost);
|
|
858
|
+
let withCredentials = false;
|
|
859
|
+
if (name && c?.auth?.type === "cookie" && originOf(url, pageHost) === declaredOrigin(c)) {
|
|
860
|
+
if (!mayUseStored(name, c)) throw untrusted(name, c);
|
|
861
|
+
withCredentials = true;
|
|
862
|
+
}
|
|
863
|
+
return { url, withCredentials };
|
|
864
|
+
}
|
|
865
|
+
return { send, streamTarget, connections };
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
// src/core/schema/dashboard.ts
|
|
869
|
+
import { z as z9 } from "zod";
|
|
870
|
+
|
|
871
|
+
// src/core/schema/actions.ts
|
|
872
|
+
import { z as z2 } from "zod";
|
|
873
|
+
|
|
874
|
+
// src/core/schema/primitives.ts
|
|
875
|
+
import { z } from "zod";
|
|
876
|
+
var Id = z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,63}$/, "Use a letter, then letters, digits, '_' or '-' (max 64)");
|
|
877
|
+
var ConnectionName = Id;
|
|
878
|
+
var Duration = z.string().regex(/^\d+(\.\d+)?(ms|s|m|h|d)$/, 'Use a duration such as "300ms", "30s", "5m", "1h" or "2d"');
|
|
879
|
+
var Template = z.string();
|
|
880
|
+
var Expression = z.string().min(1, "Expression is empty");
|
|
881
|
+
var Callback = z.string().refine((s) => isCallbackSource(s), 'A callback must be a function, e.g. "(event, state) => { \u2026 }"');
|
|
882
|
+
function isCallbackSource(s) {
|
|
883
|
+
const t = s.trim();
|
|
884
|
+
return /^(async\s+)?(function\b|\([^)]*\)\s*=>|[A-Za-z_$][\w$]*\s*=>)/.test(t);
|
|
885
|
+
}
|
|
886
|
+
var JsonValue = z.lazy(
|
|
887
|
+
() => z.union([z.string(), z.number(), z.boolean(), z.null(), z.array(JsonValue), z.record(JsonValue)])
|
|
888
|
+
);
|
|
889
|
+
var HttpMethod = z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
890
|
+
var StatusTone = z.enum(["good", "warn", "bad", "neutral", "info"]);
|
|
891
|
+
var FnProp = z.object({ fn: z.string().min(1) }).strict();
|
|
892
|
+
function browserUrlText(url) {
|
|
893
|
+
const s = url.replace(/[\t\n\r]/g, "");
|
|
894
|
+
let a = 0;
|
|
895
|
+
let b = s.length;
|
|
896
|
+
while (a < b && s.charCodeAt(a) <= 32) a++;
|
|
897
|
+
while (b > a && s.charCodeAt(b - 1) <= 32) b--;
|
|
898
|
+
return s.slice(a, b);
|
|
899
|
+
}
|
|
900
|
+
function isSafeUrl(url) {
|
|
901
|
+
const t = browserUrlText(url).toLowerCase();
|
|
902
|
+
if (t.startsWith("${")) return true;
|
|
903
|
+
if (/^[a-z][a-z0-9+.-]*:/.test(t)) return t.startsWith("https:") || t.startsWith("http:") || t.startsWith("mailto:");
|
|
904
|
+
return true;
|
|
905
|
+
}
|
|
906
|
+
var LINK_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "mailto:"]);
|
|
907
|
+
function safeLink(raw) {
|
|
908
|
+
if (typeof raw !== "string") return void 0;
|
|
909
|
+
const s = browserUrlText(raw);
|
|
910
|
+
if (!s || /^[/\\]{2}/.test(s)) return void 0;
|
|
911
|
+
try {
|
|
912
|
+
return LINK_PROTOCOLS.has(new URL(s, "https://relative.invalid/").protocol) ? s : void 0;
|
|
913
|
+
} catch {
|
|
914
|
+
return void 0;
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
var SafeUrl = Template.refine(isSafeUrl, "Only https:, http:, mailto: and relative URLs are allowed");
|
|
918
|
+
var onUnknownTag;
|
|
919
|
+
function readingUnknownTags(report, parse3) {
|
|
920
|
+
const prev = onUnknownTag;
|
|
921
|
+
onUnknownTag = report;
|
|
922
|
+
try {
|
|
923
|
+
return parse3();
|
|
924
|
+
} finally {
|
|
925
|
+
onUnknownTag = prev;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
function dispatch(key, schemas, pick2) {
|
|
929
|
+
const schema2 = z.record(z.unknown()).superRefine((v, ctx) => {
|
|
930
|
+
const tag = pick2 ? pick2(v) : typeof v[key] === "string" ? v[key] : void 0;
|
|
931
|
+
const member2 = tag !== void 0 ? schemas[tag] : void 0;
|
|
932
|
+
if (!member2 && tag !== void 0 && NAMESPACED.test(tag)) return;
|
|
933
|
+
if (!member2 && tag !== void 0 && onUnknownTag) {
|
|
934
|
+
onUnknownTag([...ctx.path, key], key, tag, Object.keys(schemas));
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
if (!member2) {
|
|
938
|
+
ctx.addIssue({
|
|
939
|
+
code: z.ZodIssueCode.custom,
|
|
940
|
+
path: [key],
|
|
941
|
+
message: tag === void 0 ? `Missing "${key}"; expected one of: ${Object.keys(schemas).join(", ")}` : `Unknown ${key} "${tag}"; expected one of: ${Object.keys(schemas).join(", ")}`
|
|
942
|
+
});
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
const r = member2.safeParse(v);
|
|
946
|
+
if (!r.success) for (const issue of r.error.issues) ctx.addIssue(issue);
|
|
947
|
+
});
|
|
948
|
+
schema2._def[DISPATCH] = { key, schemas };
|
|
949
|
+
return schema2;
|
|
950
|
+
}
|
|
951
|
+
var DISPATCH = "dashspecDispatch";
|
|
952
|
+
var NAMESPACED = /^[A-Za-z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]*$/;
|
|
953
|
+
|
|
954
|
+
// src/core/schema/actions.ts
|
|
955
|
+
var IdOrIds = z2.union([Id, z2.array(Id).min(1)]);
|
|
956
|
+
var common = { when: Expression.optional() };
|
|
957
|
+
var target = { url: Template.optional(), path: Template.optional() };
|
|
958
|
+
var req = (shape) => z2.object(shape).strict().refine((a) => Boolean(a.url) !== Boolean(a.path), {
|
|
959
|
+
message: 'Give exactly one of "url" or "path"',
|
|
960
|
+
path: ["path"]
|
|
961
|
+
});
|
|
962
|
+
var ActionRef;
|
|
963
|
+
var actions = {
|
|
964
|
+
// Navigation
|
|
965
|
+
navigate: z2.object({
|
|
966
|
+
do: z2.literal("navigate"),
|
|
967
|
+
...common,
|
|
968
|
+
to: SafeUrl,
|
|
969
|
+
query: z2.record(JsonValue).optional(),
|
|
970
|
+
newTab: z2.boolean().optional()
|
|
971
|
+
}).strict(),
|
|
972
|
+
openDashboard: z2.object({
|
|
973
|
+
do: z2.literal("openDashboard"),
|
|
974
|
+
...common,
|
|
975
|
+
dashboard: Template,
|
|
976
|
+
filters: z2.record(JsonValue).optional(),
|
|
977
|
+
newTab: z2.boolean().optional()
|
|
978
|
+
}).strict(),
|
|
979
|
+
emit: z2.object({ do: z2.literal("emit"), ...common, event: z2.string().min(1), payload: JsonValue.optional() }).strict(),
|
|
980
|
+
// Data
|
|
981
|
+
fetch: z2.object({ do: z2.literal("fetch"), ...common, source: Id, params: z2.record(JsonValue).optional() }).strict(),
|
|
982
|
+
refresh: z2.object({ do: z2.literal("refresh"), ...common, source: IdOrIds.optional() }).strict(),
|
|
983
|
+
http: req({
|
|
984
|
+
do: z2.literal("http"),
|
|
985
|
+
...common,
|
|
986
|
+
connection: ConnectionName.optional(),
|
|
987
|
+
...target,
|
|
988
|
+
method: HttpMethod.default("POST"),
|
|
989
|
+
query: z2.record(JsonValue).optional(),
|
|
990
|
+
body: JsonValue.optional(),
|
|
991
|
+
/** State path to store the response in, e.g. "result". */
|
|
992
|
+
saveTo: z2.string().optional()
|
|
993
|
+
}),
|
|
994
|
+
export: z2.object({
|
|
995
|
+
do: z2.literal("export"),
|
|
996
|
+
...common,
|
|
997
|
+
panel: Id,
|
|
998
|
+
format: z2.enum(["csv", "xlsx"]),
|
|
999
|
+
filename: Template.optional()
|
|
1000
|
+
}).strict(),
|
|
1001
|
+
download: req({
|
|
1002
|
+
do: z2.literal("download"),
|
|
1003
|
+
...common,
|
|
1004
|
+
connection: ConnectionName.optional(),
|
|
1005
|
+
...target,
|
|
1006
|
+
method: HttpMethod.default("GET"),
|
|
1007
|
+
query: z2.record(JsonValue).optional(),
|
|
1008
|
+
body: JsonValue.optional(),
|
|
1009
|
+
filename: Template.optional()
|
|
1010
|
+
}),
|
|
1011
|
+
// State
|
|
1012
|
+
setState: z2.object({
|
|
1013
|
+
do: z2.literal("setState"),
|
|
1014
|
+
...common,
|
|
1015
|
+
path: z2.string().min(1),
|
|
1016
|
+
value: JsonValue,
|
|
1017
|
+
merge: z2.boolean().optional()
|
|
1018
|
+
}).strict(),
|
|
1019
|
+
setVariable: z2.object({ do: z2.literal("setVariable"), ...common, name: Id, value: JsonValue }).strict(),
|
|
1020
|
+
setSelection: z2.object({ do: z2.literal("setSelection"), ...common, panel: Id.optional(), value: JsonValue.optional() }).strict(),
|
|
1021
|
+
clearSelection: z2.object({ do: z2.literal("clearSelection"), ...common, panel: Id.optional() }).strict(),
|
|
1022
|
+
// View
|
|
1023
|
+
show: z2.object({ do: z2.literal("show"), ...common, panel: IdOrIds }).strict(),
|
|
1024
|
+
hide: z2.object({ do: z2.literal("hide"), ...common, panel: IdOrIds }).strict(),
|
|
1025
|
+
toggle: z2.object({ do: z2.literal("toggle"), ...common, panel: IdOrIds }).strict(),
|
|
1026
|
+
setView: z2.object({ do: z2.literal("setView"), ...common, view: Id }).strict(),
|
|
1027
|
+
openModal: z2.object({ do: z2.literal("openModal"), ...common, modal: Id, args: z2.record(JsonValue).optional() }).strict(),
|
|
1028
|
+
closeModal: z2.object({ do: z2.literal("closeModal"), ...common }).strict(),
|
|
1029
|
+
highlight: z2.object({ do: z2.literal("highlight"), ...common, group: z2.string().min(1) }).strict(),
|
|
1030
|
+
toggleSeries: z2.object({ do: z2.literal("toggleSeries"), ...common, panel: Id.optional(), series: Template.optional() }).strict(),
|
|
1031
|
+
fullscreen: z2.object({ do: z2.literal("fullscreen"), ...common, panel: Id.optional() }).strict(),
|
|
1032
|
+
// Drill
|
|
1033
|
+
drillDown: z2.object({ do: z2.literal("drillDown"), ...common, panel: Id.optional() }).strict(),
|
|
1034
|
+
drillUp: z2.object({ do: z2.literal("drillUp"), ...common, panel: Id.optional() }).strict(),
|
|
1035
|
+
drillReset: z2.object({ do: z2.literal("drillReset"), ...common, panel: Id.optional() }).strict(),
|
|
1036
|
+
// Flow
|
|
1037
|
+
sequence: z2.object({ do: z2.literal("sequence"), ...common, steps: z2.lazy(() => z2.array(ActionRef).min(1)) }).strict(),
|
|
1038
|
+
toast: z2.object({ do: z2.literal("toast"), ...common, message: Template, tone: StatusTone.optional() }).strict(),
|
|
1039
|
+
call: z2.object({ do: z2.literal("call"), ...common, fn: z2.string().min(1), args: JsonValue.optional() }).strict(),
|
|
1040
|
+
script: z2.object({ do: z2.literal("script"), ...common, code: Callback }).strict()
|
|
1041
|
+
};
|
|
1042
|
+
var ACTION_KINDS = Object.keys(actions);
|
|
1043
|
+
var ACTION_SCHEMAS = actions;
|
|
1044
|
+
var Action = dispatch("do", actions);
|
|
1045
|
+
ActionRef = z2.union([Id, Action]);
|
|
1046
|
+
var RunMode = z2.enum(["latest", "parallel", "queue"]);
|
|
1047
|
+
var Handler = z2.union([z2.array(ActionRef).min(1), Callback]);
|
|
1048
|
+
var HandlerWithMode = z2.object({ run: Handler, mode: RunMode }).strict();
|
|
1049
|
+
var EventHandler = z2.union([
|
|
1050
|
+
Handler,
|
|
1051
|
+
HandlerWithMode,
|
|
1052
|
+
z2.record(z2.union([Handler, HandlerWithMode])).refine((o) => !("run" in o), "Use run + mode together")
|
|
1053
|
+
]);
|
|
1054
|
+
var EventMap = z2.record(EventHandler);
|
|
1055
|
+
var NamedAction = z2.union([
|
|
1056
|
+
z2.string().refine(isCallbackSource, "A named action string must be a callback"),
|
|
1057
|
+
Action
|
|
1058
|
+
]);
|
|
1059
|
+
|
|
1060
|
+
// src/core/schema/connections.ts
|
|
1061
|
+
import { z as z3 } from "zod";
|
|
1062
|
+
var TokenSource = z3.object({
|
|
1063
|
+
from: z3.enum(["host", "localStorage", "sessionStorage", "cookie"]),
|
|
1064
|
+
key: z3.string().min(1).optional()
|
|
1065
|
+
}).strict().refine((t) => t.from === "host" || t.key !== void 0, {
|
|
1066
|
+
message: '"key" is required unless "from" is "host"',
|
|
1067
|
+
path: ["key"]
|
|
1068
|
+
});
|
|
1069
|
+
var RefreshRequest = z3.object({
|
|
1070
|
+
method: HttpMethod.default("POST"),
|
|
1071
|
+
url: Template.optional(),
|
|
1072
|
+
path: Template.optional(),
|
|
1073
|
+
body: JsonValue.optional(),
|
|
1074
|
+
headers: z3.record(Template).optional(),
|
|
1075
|
+
/** storage key → JSON path in the response, e.g. `{ "auth_token": "$.access" }`. */
|
|
1076
|
+
save: z3.record(z3.string()).optional()
|
|
1077
|
+
}).strict().refine((r) => Boolean(r.url) !== Boolean(r.path), { message: 'Give exactly one of "url" or "path"' });
|
|
1078
|
+
var TokenRefresh = z3.union([z3.object({ from: z3.literal("host") }).strict(), RefreshRequest]);
|
|
1079
|
+
var Auth = z3.discriminatedUnion("type", [
|
|
1080
|
+
z3.object({ type: z3.literal("none") }).strict(),
|
|
1081
|
+
z3.object({ type: z3.literal("cookie") }).strict(),
|
|
1082
|
+
z3.object({
|
|
1083
|
+
type: z3.literal("bearer"),
|
|
1084
|
+
token: TokenSource,
|
|
1085
|
+
refresh: TokenRefresh.optional(),
|
|
1086
|
+
header: z3.string().default("Authorization"),
|
|
1087
|
+
scheme: z3.string().default("Bearer")
|
|
1088
|
+
}).strict(),
|
|
1089
|
+
z3.object({ type: z3.literal("apiKey"), in: z3.enum(["header", "query"]), name: z3.string().min(1), from: TokenSource }).strict(),
|
|
1090
|
+
z3.object({ type: z3.literal("headers"), headers: z3.record(Template) }).strict()
|
|
1091
|
+
]);
|
|
1092
|
+
var Retry = z3.union([
|
|
1093
|
+
z3.literal(false),
|
|
1094
|
+
z3.object({
|
|
1095
|
+
times: z3.number().int().min(0).max(10).default(2),
|
|
1096
|
+
backoff: z3.enum(["fixed", "exponential"]).default("exponential"),
|
|
1097
|
+
on: z3.array(z3.number().int().min(100).max(599)).optional()
|
|
1098
|
+
}).strict()
|
|
1099
|
+
]);
|
|
1100
|
+
var BaseUrl = z3.union([Template, z3.record(Template)]);
|
|
1101
|
+
var Connection = z3.object({
|
|
1102
|
+
description: z3.string().optional(),
|
|
1103
|
+
baseUrl: BaseUrl.optional(),
|
|
1104
|
+
auth: Auth.optional(),
|
|
1105
|
+
headers: z3.record(Template).optional(),
|
|
1106
|
+
timeout: Duration.optional(),
|
|
1107
|
+
retry: Retry.optional()
|
|
1108
|
+
}).strict();
|
|
1109
|
+
|
|
1110
|
+
// src/core/schema/datasources.ts
|
|
1111
|
+
import { z as z4 } from "zod";
|
|
1112
|
+
var OneOrMany = z4.union([z4.string().min(1), z4.array(z4.string().min(1)).min(1)]);
|
|
1113
|
+
var AGGREGATES = ["sum", "avg", "count", "min", "max", "first", "last"];
|
|
1114
|
+
var OPS2 = ["filter", "map", "groupBy", "pivot", "sort", "limit", "pick", "fn", ...AGGREGATES];
|
|
1115
|
+
var steps = {
|
|
1116
|
+
filter: z4.object({ filter: Expression }).strict(),
|
|
1117
|
+
map: z4.object({
|
|
1118
|
+
map: z4.object({
|
|
1119
|
+
field: z4.string().min(1),
|
|
1120
|
+
to: z4.string().min(1).optional(),
|
|
1121
|
+
values: z4.record(JsonValue),
|
|
1122
|
+
default: JsonValue.optional()
|
|
1123
|
+
}).strict()
|
|
1124
|
+
}).strict(),
|
|
1125
|
+
aggregate: z4.object({
|
|
1126
|
+
groupBy: OneOrMany.optional(),
|
|
1127
|
+
sum: OneOrMany.optional(),
|
|
1128
|
+
avg: OneOrMany.optional(),
|
|
1129
|
+
count: z4.union([z4.literal(true), z4.string().min(1)]).optional(),
|
|
1130
|
+
min: OneOrMany.optional(),
|
|
1131
|
+
max: OneOrMany.optional(),
|
|
1132
|
+
first: OneOrMany.optional(),
|
|
1133
|
+
last: OneOrMany.optional()
|
|
1134
|
+
}).strict(),
|
|
1135
|
+
pivot: z4.object({ pivot: z4.object({ rows: OneOrMany, cols: z4.string().min(1), value: z4.string().min(1) }).strict() }).strict(),
|
|
1136
|
+
sort: z4.object({ sort: OneOrMany, order: z4.enum(["asc", "desc"]).default("asc") }).strict(),
|
|
1137
|
+
limit: z4.object({ limit: z4.number().int().min(0) }).strict(),
|
|
1138
|
+
pick: z4.object({ pick: z4.array(z4.string().min(1)).min(1) }).strict(),
|
|
1139
|
+
fn: z4.object({ fn: z4.string().min(1) }).strict()
|
|
1140
|
+
};
|
|
1141
|
+
var TransformStep = dispatch("op", steps, (v) => {
|
|
1142
|
+
const keys = Object.keys(v);
|
|
1143
|
+
if (keys.some((k) => k === "groupBy" || AGGREGATES.includes(k))) return "aggregate";
|
|
1144
|
+
return keys.find((k) => OPS2.includes(k)) ?? keys.find((k) => !k.startsWith("x-") && k !== "description");
|
|
1145
|
+
});
|
|
1146
|
+
var Common = {
|
|
1147
|
+
description: z4.string().optional(),
|
|
1148
|
+
load: z4.enum(["onLoad", "lazy", "manual"]).optional(),
|
|
1149
|
+
refresh: z4.object({
|
|
1150
|
+
every: Duration.optional(),
|
|
1151
|
+
whenVisible: z4.boolean().optional(),
|
|
1152
|
+
when: Expression.optional(),
|
|
1153
|
+
onFocus: z4.boolean().optional()
|
|
1154
|
+
}).strict().optional(),
|
|
1155
|
+
transform: z4.array(TransformStep).optional(),
|
|
1156
|
+
forEach: z4.object({ source: Id, as: Id, concurrency: z4.number().int().min(1).max(32).optional() }).strict().optional(),
|
|
1157
|
+
timeout: Duration.optional(),
|
|
1158
|
+
retry: Retry.optional(),
|
|
1159
|
+
cache: z4.object({ staleTime: Duration }).strict().optional(),
|
|
1160
|
+
onError: z4.enum(["keepLast", "clear"]).optional(),
|
|
1161
|
+
/** Drop query parameters whose value is empty ("All" means "leave it out"). */
|
|
1162
|
+
omitEmpty: z4.boolean().optional()
|
|
1163
|
+
};
|
|
1164
|
+
var Request = {
|
|
1165
|
+
connection: ConnectionName.optional(),
|
|
1166
|
+
url: Template.optional(),
|
|
1167
|
+
path: Template.optional(),
|
|
1168
|
+
query: z4.record(JsonValue).optional(),
|
|
1169
|
+
headers: z4.record(Template).optional()
|
|
1170
|
+
};
|
|
1171
|
+
var oneTarget = (d) => Boolean(d.url) !== Boolean(d.path);
|
|
1172
|
+
var targetMsg = { message: 'Give exactly one of "url" or "path"', path: ["path"] };
|
|
1173
|
+
var types = {
|
|
1174
|
+
http: z4.object({
|
|
1175
|
+
type: z4.literal("http"),
|
|
1176
|
+
...Common,
|
|
1177
|
+
...Request,
|
|
1178
|
+
method: HttpMethod.default("GET"),
|
|
1179
|
+
body: JsonValue.optional(),
|
|
1180
|
+
/** Path into the response to use as data. */
|
|
1181
|
+
select: z4.string().optional(),
|
|
1182
|
+
paging: z4.object({
|
|
1183
|
+
mode: z4.enum(["server", "client"]),
|
|
1184
|
+
page: z4.string().optional(),
|
|
1185
|
+
size: z4.string().optional(),
|
|
1186
|
+
total: z4.string().optional(),
|
|
1187
|
+
sort: z4.string().optional(),
|
|
1188
|
+
pageSize: z4.number().int().min(1).optional()
|
|
1189
|
+
}).strict().optional()
|
|
1190
|
+
}).strict().refine(oneTarget, targetMsg),
|
|
1191
|
+
graphql: z4.object({
|
|
1192
|
+
type: z4.literal("graphql"),
|
|
1193
|
+
...Common,
|
|
1194
|
+
...Request,
|
|
1195
|
+
query: z4.string().min(1),
|
|
1196
|
+
variables: z4.record(JsonValue).optional(),
|
|
1197
|
+
select: z4.string().optional()
|
|
1198
|
+
}).strict().refine(oneTarget, targetMsg),
|
|
1199
|
+
sse: z4.object({
|
|
1200
|
+
type: z4.literal("sse"),
|
|
1201
|
+
...Common,
|
|
1202
|
+
...Request,
|
|
1203
|
+
event: z4.string().optional(),
|
|
1204
|
+
merge: z4.enum(["replace", "append"]).default("replace"),
|
|
1205
|
+
keep: z4.number().int().min(1).optional(),
|
|
1206
|
+
/**
|
|
1207
|
+
* Reconnect after the connection drops (default true): waits 1 s, 2 s, 4 s… up to `maxDelay` (default "30s"),
|
|
1208
|
+
* and starts over once data flows again. `false` stays closed until the next refresh.
|
|
1209
|
+
*/
|
|
1210
|
+
reconnect: z4.union([z4.boolean(), z4.object({ maxDelay: Duration.optional() }).strict()]).optional()
|
|
1211
|
+
}).strict().refine(oneTarget, targetMsg),
|
|
1212
|
+
websocket: z4.object({
|
|
1213
|
+
type: z4.literal("websocket"),
|
|
1214
|
+
...Common,
|
|
1215
|
+
...Request,
|
|
1216
|
+
send: JsonValue.optional(),
|
|
1217
|
+
merge: z4.enum(["replace", "append"]).default("replace"),
|
|
1218
|
+
keep: z4.number().int().min(1).optional(),
|
|
1219
|
+
/**
|
|
1220
|
+
* Reconnect after the connection drops (default true): waits 1 s, 2 s, 4 s… up to `maxDelay` (default "30s"),
|
|
1221
|
+
* and starts over once data flows again. `false` stays closed until the next refresh.
|
|
1222
|
+
*/
|
|
1223
|
+
reconnect: z4.union([z4.boolean(), z4.object({ maxDelay: Duration.optional() }).strict()]).optional()
|
|
1224
|
+
}).strict().refine(oneTarget, targetMsg),
|
|
1225
|
+
static: z4.object({ type: z4.literal("static"), ...Common, data: JsonValue }).strict(),
|
|
1226
|
+
host: z4.object({ type: z4.literal("host"), ...Common, key: z4.string().min(1) }).strict(),
|
|
1227
|
+
derived: z4.object({ ...Common, from: Id }).strict()
|
|
1228
|
+
};
|
|
1229
|
+
var BUILT_IN_DATASOURCE_TYPES = ["http", "graphql", "sse", "websocket", "static", "host"];
|
|
1230
|
+
var Datasource = dispatch("type", { ...types, custom: z4.record(z4.unknown()) }, (v) => {
|
|
1231
|
+
if (v.type === void 0 && "from" in v) return "derived";
|
|
1232
|
+
if (typeof v.type !== "string") return void 0;
|
|
1233
|
+
return v.type in types ? v.type : "custom";
|
|
1234
|
+
});
|
|
1235
|
+
|
|
1236
|
+
// src/core/schema/layout.ts
|
|
1237
|
+
import { z as z5 } from "zod";
|
|
1238
|
+
var LayoutItem = z5.object({
|
|
1239
|
+
panel: Id,
|
|
1240
|
+
x: z5.number().int().min(0),
|
|
1241
|
+
y: z5.number().int().min(0),
|
|
1242
|
+
w: z5.number().int().min(1),
|
|
1243
|
+
h: z5.number().int().min(1),
|
|
1244
|
+
minW: z5.number().int().min(1).optional(),
|
|
1245
|
+
minH: z5.number().int().min(1).optional()
|
|
1246
|
+
}).strict();
|
|
1247
|
+
var BREAKPOINTS = ["desktop", "tablet", "mobile", "tv"];
|
|
1248
|
+
var Layout = z5.object({
|
|
1249
|
+
view: Id.optional(),
|
|
1250
|
+
breakpoint: z5.enum(BREAKPOINTS).default("desktop"),
|
|
1251
|
+
label: z5.string().optional(),
|
|
1252
|
+
items: z5.array(LayoutItem).optional(),
|
|
1253
|
+
auto: z5.enum(["stack", "flow"]).optional()
|
|
1254
|
+
}).strict().refine((l) => Boolean(l.items) !== Boolean(l.auto), { message: 'Give either "items" or "auto"' });
|
|
1255
|
+
var Grid = z5.object({
|
|
1256
|
+
/** 12 or 24 columns; 60 splits evenly into 2, 3, 4, 5 or 6 (a row of 5 KPI cards). */
|
|
1257
|
+
columns: z5.union([z5.literal(12), z5.literal(24), z5.literal(60)]).default(12),
|
|
1258
|
+
rowHeight: z5.number().int().min(8).max(200).default(28),
|
|
1259
|
+
gap: z5.number().int().min(0).max(48).default(12)
|
|
1260
|
+
}).strict();
|
|
1261
|
+
|
|
1262
|
+
// src/core/schema/modals.ts
|
|
1263
|
+
import { z as z8 } from "zod";
|
|
1264
|
+
|
|
1265
|
+
// src/core/schema/panels.ts
|
|
1266
|
+
import { z as z7 } from "zod";
|
|
1267
|
+
|
|
1268
|
+
// src/core/schema/variables.ts
|
|
1269
|
+
import { z as z6 } from "zod";
|
|
1270
|
+
var DATE_PRESETS = [
|
|
1271
|
+
"today",
|
|
1272
|
+
"yesterday",
|
|
1273
|
+
"last7days",
|
|
1274
|
+
"last30days",
|
|
1275
|
+
"last90days",
|
|
1276
|
+
"thisWeek",
|
|
1277
|
+
"lastWeek",
|
|
1278
|
+
"thisMonth",
|
|
1279
|
+
"lastMonth",
|
|
1280
|
+
"thisQuarter",
|
|
1281
|
+
"thisYear",
|
|
1282
|
+
"lastYear",
|
|
1283
|
+
"custom"
|
|
1284
|
+
];
|
|
1285
|
+
var DatePreset = z6.enum(DATE_PRESETS);
|
|
1286
|
+
var Option = z6.union([
|
|
1287
|
+
z6.string(),
|
|
1288
|
+
z6.number(),
|
|
1289
|
+
z6.object({
|
|
1290
|
+
value: z6.union([z6.string(), z6.number(), z6.boolean()]),
|
|
1291
|
+
label: z6.string().optional(),
|
|
1292
|
+
count: z6.number().optional()
|
|
1293
|
+
}).strict()
|
|
1294
|
+
]);
|
|
1295
|
+
var Options = z6.union([
|
|
1296
|
+
z6.array(Option),
|
|
1297
|
+
z6.object({
|
|
1298
|
+
source: Id,
|
|
1299
|
+
path: z6.string().optional(),
|
|
1300
|
+
value: z6.string().optional(),
|
|
1301
|
+
label: z6.string().optional(),
|
|
1302
|
+
count: z6.string().optional()
|
|
1303
|
+
}).strict()
|
|
1304
|
+
]);
|
|
1305
|
+
var base = {
|
|
1306
|
+
name: Id,
|
|
1307
|
+
label: Template.optional(),
|
|
1308
|
+
description: z6.string().optional(),
|
|
1309
|
+
visibleWhen: Expression.optional(),
|
|
1310
|
+
persist: z6.enum(["url", "memory", "none"]).optional(),
|
|
1311
|
+
apply: z6.enum(["immediate", "button"]).optional(),
|
|
1312
|
+
hidden: z6.boolean().optional(),
|
|
1313
|
+
/** Filters this one depends on: when any of them changes, this one goes back to its default. */
|
|
1314
|
+
dependsOn: z6.array(Id).optional(),
|
|
1315
|
+
/** Keeps only matching options, e.g. "item.plant == filters.plant" (item = the option's row). */
|
|
1316
|
+
optionsFilter: Expression.optional()
|
|
1317
|
+
};
|
|
1318
|
+
var DateRangeValue = z6.union([DatePreset, z6.object({ from: Template, to: Template }).strict()]);
|
|
1319
|
+
var kinds = {
|
|
1320
|
+
DateRange: z6.object({
|
|
1321
|
+
...base,
|
|
1322
|
+
kind: z6.literal("DateRange"),
|
|
1323
|
+
presets: z6.array(DatePreset).optional(),
|
|
1324
|
+
default: DateRangeValue.optional(),
|
|
1325
|
+
min: Template.optional(),
|
|
1326
|
+
max: Template.optional(),
|
|
1327
|
+
maxDays: z6.number().int().min(1).optional()
|
|
1328
|
+
}).strict(),
|
|
1329
|
+
Date: z6.object({
|
|
1330
|
+
...base,
|
|
1331
|
+
kind: z6.literal("Date"),
|
|
1332
|
+
default: Template.optional(),
|
|
1333
|
+
min: Template.optional(),
|
|
1334
|
+
max: Template.optional(),
|
|
1335
|
+
stepper: z6.boolean().optional()
|
|
1336
|
+
}).strict(),
|
|
1337
|
+
Select: z6.object({
|
|
1338
|
+
...base,
|
|
1339
|
+
kind: z6.literal("Select"),
|
|
1340
|
+
options: Options,
|
|
1341
|
+
default: JsonValue.optional(),
|
|
1342
|
+
searchable: z6.boolean().optional(),
|
|
1343
|
+
stepper: z6.boolean().optional()
|
|
1344
|
+
}).strict(),
|
|
1345
|
+
MultiSelect: z6.object({
|
|
1346
|
+
...base,
|
|
1347
|
+
kind: z6.literal("MultiSelect"),
|
|
1348
|
+
options: Options,
|
|
1349
|
+
default: z6.array(JsonValue).optional(),
|
|
1350
|
+
searchable: z6.boolean().optional()
|
|
1351
|
+
}).strict(),
|
|
1352
|
+
Chips: z6.object({
|
|
1353
|
+
...base,
|
|
1354
|
+
kind: z6.literal("Chips"),
|
|
1355
|
+
options: Options,
|
|
1356
|
+
multiple: z6.boolean().optional(),
|
|
1357
|
+
default: JsonValue.optional()
|
|
1358
|
+
}).strict(),
|
|
1359
|
+
Search: z6.object({
|
|
1360
|
+
...base,
|
|
1361
|
+
kind: z6.literal("Search"),
|
|
1362
|
+
placeholder: Template.optional(),
|
|
1363
|
+
debounce: Duration.optional(),
|
|
1364
|
+
default: z6.string().optional()
|
|
1365
|
+
}).strict(),
|
|
1366
|
+
Toggle: z6.object({ ...base, kind: z6.literal("Toggle"), default: z6.boolean().optional() }).strict()
|
|
1367
|
+
};
|
|
1368
|
+
var VARIABLE_KINDS = Object.keys(kinds);
|
|
1369
|
+
var Variable = dispatch("kind", kinds);
|
|
1370
|
+
var PanelControl = Variable;
|
|
1371
|
+
|
|
1372
|
+
// src/core/schema/panels.ts
|
|
1373
|
+
var DrillLevel = z7.object({
|
|
1374
|
+
name: Id,
|
|
1375
|
+
label: Template.optional(),
|
|
1376
|
+
x: z7.string().optional(),
|
|
1377
|
+
query: z7.record(JsonValue).optional(),
|
|
1378
|
+
source: Id.optional(),
|
|
1379
|
+
do: z7.string().optional()
|
|
1380
|
+
}).passthrough();
|
|
1381
|
+
var Drill = z7.object({ levels: z7.array(DrillLevel).min(1) }).strict();
|
|
1382
|
+
var DataBinding = z7.union([
|
|
1383
|
+
z7.object({ source: Id, path: z7.string().optional() }).strict(),
|
|
1384
|
+
z7.object({ panel: Id, path: z7.string().optional() }).strict(),
|
|
1385
|
+
z7.object({ state: z7.string().min(1) }).strict(),
|
|
1386
|
+
z7.object({ value: JsonValue }).strict()
|
|
1387
|
+
]);
|
|
1388
|
+
var PanelStyle = z7.object({
|
|
1389
|
+
tone: z7.enum(["default", "subtle", "accent", "plain"]).optional(),
|
|
1390
|
+
padding: z7.union([z7.enum(["none", "compact", "normal", "roomy"]), z7.number().int().min(0).max(64)]).optional(),
|
|
1391
|
+
hideHeader: z7.boolean().optional(),
|
|
1392
|
+
minHeight: z7.number().int().min(0).optional(),
|
|
1393
|
+
/** Card look. Colours accept theme tokens such as "status-good-bg" or any CSS colour. */
|
|
1394
|
+
background: z7.string().optional(),
|
|
1395
|
+
borderColor: z7.string().optional(),
|
|
1396
|
+
borderWidth: z7.number().int().min(0).max(8).optional(),
|
|
1397
|
+
radius: z7.number().int().min(0).max(40).optional(),
|
|
1398
|
+
shadow: z7.enum(["none", "sm", "md", "lg"]).optional(),
|
|
1399
|
+
/** As a child of a Container: flex grow, basis and limits. */
|
|
1400
|
+
flex: z7.string().optional(),
|
|
1401
|
+
minWidth: z7.union([z7.number(), z7.string()]).optional(),
|
|
1402
|
+
maxWidth: z7.union([z7.number(), z7.string()]).optional(),
|
|
1403
|
+
align: z7.enum(["start", "center", "end", "stretch"]).optional()
|
|
1404
|
+
}).strict();
|
|
1405
|
+
var Panel = z7.object({
|
|
1406
|
+
kind: z7.string().regex(/^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)?$/, 'Use a widget kind such as "Kpi" or "acme.Furnace"'),
|
|
1407
|
+
version: z7.number().int().min(1).default(1),
|
|
1408
|
+
spec: z7.record(z7.unknown()).default({}),
|
|
1409
|
+
on: EventMap.optional(),
|
|
1410
|
+
drill: Drill.optional(),
|
|
1411
|
+
visibleWhen: Expression.optional(),
|
|
1412
|
+
style: PanelStyle.optional(),
|
|
1413
|
+
/**
|
|
1414
|
+
* React to the global state: when the value at `path` changes (a filter, another widget's selection, your own
|
|
1415
|
+
* state), run `do`. A runaway loop between watches is stopped and reported.
|
|
1416
|
+
*/
|
|
1417
|
+
watch: z7.array(z7.object({ path: z7.string().min(1), do: EventHandler }).strict()).optional(),
|
|
1418
|
+
/** Child nodes by slot name (header, footer, body, items, item, a tab key…), in order. Any depth. */
|
|
1419
|
+
slots: z7.record(z7.string().regex(/^[A-Za-z][\w-]*$/, "Slot names are letters, digits, '_' or '-'"), z7.array(Id)).optional(),
|
|
1420
|
+
controls: z7.array(PanelControl).optional(),
|
|
1421
|
+
messages: z7.object({ empty: Template.optional(), error: Template.optional(), loading: Template.optional() }).strict().optional(),
|
|
1422
|
+
description: z7.string().optional()
|
|
1423
|
+
}).strict();
|
|
1424
|
+
|
|
1425
|
+
// src/core/schema/modals.ts
|
|
1426
|
+
var Modal = z8.object({
|
|
1427
|
+
title: Template.optional(),
|
|
1428
|
+
size: z8.enum(["sm", "md", "lg", "xl", "full"]).default("md"),
|
|
1429
|
+
presentation: z8.enum(["modal", "drawer"]).default("modal"),
|
|
1430
|
+
/** Bind open state instead of using openModal, e.g. "${state.heatModal.open}". */
|
|
1431
|
+
open: Template.optional(),
|
|
1432
|
+
datasources: z8.record(Id, Datasource).optional(),
|
|
1433
|
+
panels: z8.record(Id, Panel),
|
|
1434
|
+
layout: z8.array(LayoutItem),
|
|
1435
|
+
on: EventMap.optional()
|
|
1436
|
+
}).strict();
|
|
1437
|
+
|
|
1438
|
+
// src/core/schema/dashboard.ts
|
|
1439
|
+
var API_VERSION = "dashspec.dev/v2";
|
|
1440
|
+
var SCHEMA_URL = "https://dashspec.dev/schema/v2.json";
|
|
1441
|
+
var RESERVED_STATE_KEYS = [
|
|
1442
|
+
"filters",
|
|
1443
|
+
"panels",
|
|
1444
|
+
"view",
|
|
1445
|
+
"modal",
|
|
1446
|
+
"highlight",
|
|
1447
|
+
"datasources",
|
|
1448
|
+
"context"
|
|
1449
|
+
];
|
|
1450
|
+
var Display = z9.object({
|
|
1451
|
+
title: Template.optional(),
|
|
1452
|
+
description: Template.optional(),
|
|
1453
|
+
theme: z9.string().optional(),
|
|
1454
|
+
locale: z9.string().optional(),
|
|
1455
|
+
translations: z9.record(z9.record(z9.string())).optional(),
|
|
1456
|
+
/** IANA zone used for "today", presets and date helpers, e.g. "Asia/Kolkata". */
|
|
1457
|
+
timeZone: z9.string().optional(),
|
|
1458
|
+
/** When the plant day starts, "HH:mm". */
|
|
1459
|
+
dayStartsAt: z9.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, 'Use "HH:mm"').optional(),
|
|
1460
|
+
filters: z9.enum(["toolbar", "drawer"]).optional(),
|
|
1461
|
+
/** How the filter bar applies changes: at once ("change") or with an Apply button; and a Reset button. */
|
|
1462
|
+
filterBar: z9.object({
|
|
1463
|
+
apply: z9.enum(["change", "button"]).default("change"),
|
|
1464
|
+
reset: z9.boolean().default(false),
|
|
1465
|
+
/** Hide the bar (filters can still be placed on the canvas as Filter widgets). */
|
|
1466
|
+
show: z9.boolean().default(true),
|
|
1467
|
+
/** The icon at the start of the bar. */
|
|
1468
|
+
icon: z9.enum(["sliders", "filter", "calendar", "search", "none"]).default("sliders"),
|
|
1469
|
+
/** "card" (default) or "plain" (no background). */
|
|
1470
|
+
look: z9.enum(["card", "plain"]).default("card")
|
|
1471
|
+
}).strict().optional(),
|
|
1472
|
+
syncedLabel: Template.optional(),
|
|
1473
|
+
tv: z9.object({ rotateViews: z9.array(Id).optional(), every: Duration.optional(), hideToolbar: z9.boolean().optional() }).strict().optional()
|
|
1474
|
+
}).strict();
|
|
1475
|
+
var TourStep = z9.object({ panel: Id.optional(), text: Template, title: Template.optional() }).strict();
|
|
1476
|
+
var Metadata = z9.object({
|
|
1477
|
+
key: Id,
|
|
1478
|
+
name: z9.string().min(1),
|
|
1479
|
+
group: z9.string().optional(),
|
|
1480
|
+
tags: z9.array(z9.string()).optional(),
|
|
1481
|
+
description: z9.string().optional(),
|
|
1482
|
+
/** The tool that wrote this document, e.g. { "name": "dashspec-builder", "version": "0.3.0" }. Informational. */
|
|
1483
|
+
generator: z9.object({ name: z9.string().min(1), version: z9.string().optional() }).strict().optional()
|
|
1484
|
+
}).strict();
|
|
1485
|
+
var Requires = z9.object({
|
|
1486
|
+
/** A version range of @dashspec/renderer, e.g. ">=0.2.0" or "^0.2". */
|
|
1487
|
+
renderer: z9.string().min(1).optional()
|
|
1488
|
+
}).strict();
|
|
1489
|
+
var Spec = z9.object({
|
|
1490
|
+
display: Display.default({}),
|
|
1491
|
+
grid: Grid.default({}),
|
|
1492
|
+
connections: z9.record(ConnectionName, Connection).optional(),
|
|
1493
|
+
variables: z9.array(Variable).optional(),
|
|
1494
|
+
state: z9.record(JsonValue).optional(),
|
|
1495
|
+
datasources: z9.record(Id, Datasource).optional(),
|
|
1496
|
+
on: EventMap.optional(),
|
|
1497
|
+
actions: z9.record(Id, NamedAction).optional(),
|
|
1498
|
+
panels: z9.record(Id, Panel),
|
|
1499
|
+
/** Reusable node subtrees (a saved card, a filter row…): `root` and its `nodes` by id. */
|
|
1500
|
+
templates: z9.record(Id, z9.object({ label: z9.string().optional(), root: Id, nodes: z9.record(Id, Panel) }).strict()).optional(),
|
|
1501
|
+
modals: z9.record(Id, Modal).optional(),
|
|
1502
|
+
layouts: z9.array(Layout).min(1),
|
|
1503
|
+
tour: z9.array(TourStep).optional(),
|
|
1504
|
+
requires: Requires.optional()
|
|
1505
|
+
}).strict();
|
|
1506
|
+
var Dashboard = z9.object({
|
|
1507
|
+
$schema: z9.string().optional(),
|
|
1508
|
+
apiVersion: z9.literal(API_VERSION),
|
|
1509
|
+
kind: z9.literal("Dashboard"),
|
|
1510
|
+
metadata: Metadata,
|
|
1511
|
+
spec: Spec
|
|
1512
|
+
}).strict();
|
|
1513
|
+
|
|
1514
|
+
// src/core/migrate/v1.ts
|
|
1515
|
+
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1516
|
+
var PRESETS = { last7d: "last7days", last30d: "last30days", last90d: "last90days" };
|
|
1517
|
+
var FILTER_KINDS = {
|
|
1518
|
+
dateRange: "DateRange",
|
|
1519
|
+
select: "Select",
|
|
1520
|
+
multiSelect: "MultiSelect",
|
|
1521
|
+
toggle: "Toggle",
|
|
1522
|
+
search: "Search"
|
|
1523
|
+
};
|
|
1524
|
+
var WIDGET_KINDS = {
|
|
1525
|
+
kpi: { kind: "Kpi" },
|
|
1526
|
+
"sparkline-kpi": { kind: "Kpi" },
|
|
1527
|
+
progress: { kind: "Kpi" },
|
|
1528
|
+
"stat-cards": { kind: "Tiles" },
|
|
1529
|
+
"stat-group": { kind: "Tiles" },
|
|
1530
|
+
bar: { kind: "BarChart" },
|
|
1531
|
+
combo: { kind: "BarChart" },
|
|
1532
|
+
pareto: { kind: "BarChart" },
|
|
1533
|
+
line: { kind: "LineChart" },
|
|
1534
|
+
area: { kind: "LineChart", spec: { area: true } },
|
|
1535
|
+
pie: { kind: "PieChart" },
|
|
1536
|
+
scatter: { kind: "Scatter" },
|
|
1537
|
+
gauge: { kind: "Gauge" },
|
|
1538
|
+
heatmap: { kind: "MatrixChart" },
|
|
1539
|
+
timeline: { kind: "StateTimeline" },
|
|
1540
|
+
"status-grid": { kind: "CardGrid" },
|
|
1541
|
+
table: { kind: "Table" },
|
|
1542
|
+
text: { kind: "Content" },
|
|
1543
|
+
image: { kind: "Image" },
|
|
1544
|
+
map: { kind: "ImageMap" }
|
|
1545
|
+
};
|
|
1546
|
+
var pathExpr = (root, path) => root + path.split(".").map((k) => /^[A-Za-z_$][\w$]*$/.test(k) ? `.${k}` : `[${JSON.stringify(k)}]`).join("");
|
|
1547
|
+
function convertRefs(v) {
|
|
1548
|
+
if (isObj(v)) {
|
|
1549
|
+
const keys = Object.keys(v);
|
|
1550
|
+
if (keys.length === 1) {
|
|
1551
|
+
if (typeof v.$filter === "string") return `\${${pathExpr("filters", v.$filter)}}`;
|
|
1552
|
+
if (typeof v.$var === "string") return `\${${pathExpr("context", v.$var)}}`;
|
|
1553
|
+
if (typeof v.$row === "string") return `\${${pathExpr("event.datum", v.$row)}}`;
|
|
1554
|
+
}
|
|
1555
|
+
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, convertRefs(x)]));
|
|
1556
|
+
}
|
|
1557
|
+
if (Array.isArray(v)) return v.map(convertRefs);
|
|
1558
|
+
return v;
|
|
1559
|
+
}
|
|
1560
|
+
var refExpr = (r) => {
|
|
1561
|
+
if (isObj(r) && typeof r.$filter === "string") return pathExpr("filters", r.$filter);
|
|
1562
|
+
if (isObj(r) && typeof r.$var === "string") return pathExpr("context", r.$var);
|
|
1563
|
+
return JSON.stringify(r);
|
|
1564
|
+
};
|
|
1565
|
+
var OPS3 = { eq: "==", neq: "!=", gt: ">", gte: ">=", lt: "<", lte: "<=" };
|
|
1566
|
+
function conditionToExpr(c) {
|
|
1567
|
+
if (!isObj(c)) return "true";
|
|
1568
|
+
const op = c.op;
|
|
1569
|
+
if (Object.hasOwn(OPS3, op)) return `${refExpr(c.left)} ${OPS3[op]} ${refExpr(c.right)}`;
|
|
1570
|
+
if (op === "in" || op === "nin") return `${op === "nin" ? "!" : ""}has(${refExpr(c.right)}, ${refExpr(c.left)})`;
|
|
1571
|
+
if (op === "empty") return `len(${refExpr(c.left)}) == 0`;
|
|
1572
|
+
if (op === "notEmpty") return `len(${refExpr(c.left)}) > 0`;
|
|
1573
|
+
if ((op === "and" || op === "or") && Array.isArray(c.conditions))
|
|
1574
|
+
return c.conditions.map((x) => `(${conditionToExpr(x)})`).join(op === "and" ? " && " : " || ");
|
|
1575
|
+
if (op === "not") return `!(${conditionToExpr(c.condition)})`;
|
|
1576
|
+
return "true";
|
|
1577
|
+
}
|
|
1578
|
+
var legacyKind = (type) => `v1.${type.replace(/(^|[-_\s]+)([a-z0-9])/gi, (_, __, c) => c.toUpperCase()).replace(/[^A-Za-z0-9]/g, "") || "Widget"}`;
|
|
1579
|
+
function migrateV1(v1) {
|
|
1580
|
+
const notes = [];
|
|
1581
|
+
const layout = isObj(v1.layout) ? v1.layout : {};
|
|
1582
|
+
const id = typeof v1.id === "string" ? v1.id : "dashboard";
|
|
1583
|
+
const variables = (Array.isArray(v1.filters) ? v1.filters : []).filter(isObj).map((f) => {
|
|
1584
|
+
const kind = FILTER_KINDS[f.type];
|
|
1585
|
+
if (!kind) notes.push(`Filter "${f.id}": type "${f.type}" has no v2 equivalent; set "kind" by hand`);
|
|
1586
|
+
const v = { name: f.id, kind: kind ?? String(f.type), label: f.label };
|
|
1587
|
+
if (f.hidden) v.hidden = true;
|
|
1588
|
+
if (kind === "DateRange") {
|
|
1589
|
+
if (Array.isArray(f.presets)) v.presets = f.presets.map((p) => PRESETS[p] ?? p);
|
|
1590
|
+
if (isObj(f.default))
|
|
1591
|
+
v.default = typeof f.default.preset === "string" ? PRESETS[f.default.preset] ?? f.default.preset : f.default;
|
|
1592
|
+
if (f.maxDays !== void 0) v.maxDays = f.maxDays;
|
|
1593
|
+
} else if (f.default !== void 0) v.default = f.default;
|
|
1594
|
+
const o = f.options;
|
|
1595
|
+
if (isObj(o)) {
|
|
1596
|
+
if (Array.isArray(o.static)) v.options = o.static;
|
|
1597
|
+
else if (typeof o.dataSource === "string")
|
|
1598
|
+
v.options = {
|
|
1599
|
+
source: o.dataSource,
|
|
1600
|
+
...o.valueKey ? { value: o.valueKey } : {},
|
|
1601
|
+
...o.labelKey ? { label: o.labelKey } : {}
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
return v;
|
|
1605
|
+
});
|
|
1606
|
+
const datasources = {};
|
|
1607
|
+
for (const ds of (Array.isArray(v1.dataSources) ? v1.dataSources : []).filter(isObj)) {
|
|
1608
|
+
const dsId = String(ds.id);
|
|
1609
|
+
let out;
|
|
1610
|
+
if (ds.kind === "http" && isObj(ds.request)) {
|
|
1611
|
+
const r = ds.request;
|
|
1612
|
+
out = { type: "http", url: r.url, method: r.method ?? "GET" };
|
|
1613
|
+
if (r.params) out.query = convertRefs(r.params);
|
|
1614
|
+
if (r.body !== void 0) out.body = convertRefs(r.body);
|
|
1615
|
+
if (typeof ds.refreshIntervalSec === "number" && ds.refreshIntervalSec > 0)
|
|
1616
|
+
out.refresh = { every: `${Math.max(1, Math.round(ds.refreshIntervalSec))}s` };
|
|
1617
|
+
} else {
|
|
1618
|
+
out = { type: "static", data: ds.static ?? null };
|
|
1619
|
+
}
|
|
1620
|
+
if (Array.isArray(ds.transform) && ds.transform.length > 0)
|
|
1621
|
+
notes.push(
|
|
1622
|
+
`Datasource "${dsId}": ${ds.transform.length} v1 transform step(s) were dropped; rewrite them as v2 steps`
|
|
1623
|
+
);
|
|
1624
|
+
datasources[dsId] = out;
|
|
1625
|
+
}
|
|
1626
|
+
const panels = {};
|
|
1627
|
+
const modals = {};
|
|
1628
|
+
const desktop = [];
|
|
1629
|
+
const tablet = [];
|
|
1630
|
+
const mobile = [];
|
|
1631
|
+
for (const w of (Array.isArray(v1.widgets) ? v1.widgets : []).filter(isObj)) {
|
|
1632
|
+
const pid = String(w.id);
|
|
1633
|
+
const map = WIDGET_KINDS[w.type];
|
|
1634
|
+
if (!map)
|
|
1635
|
+
notes.push(
|
|
1636
|
+
`Widget "${pid}": type "${w.type}" has no built-in v2 widget; kind "${legacyKind(String(w.type))}" shows as "Unknown widget" until one is registered`
|
|
1637
|
+
);
|
|
1638
|
+
const spec2 = { ...map?.spec ?? {} };
|
|
1639
|
+
if (w.title) spec2.title = w.title;
|
|
1640
|
+
if (w.subtitle) spec2.subtitle = w.subtitle;
|
|
1641
|
+
if (w.info) spec2.info = w.info;
|
|
1642
|
+
if (typeof w.dataSource === "string") spec2.data = { source: w.dataSource };
|
|
1643
|
+
if (isObj(w.mapping)) Object.assign(spec2, w.mapping);
|
|
1644
|
+
if (isObj(w.options)) {
|
|
1645
|
+
Object.assign(spec2, convertRefs(w.options));
|
|
1646
|
+
notes.push(
|
|
1647
|
+
`Panel "${pid}": v1 options were copied into spec; check them against the ${map?.kind ?? "widget"} props`
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
const panel = { kind: map?.kind ?? legacyKind(String(w.type)), version: 1, spec: spec2 };
|
|
1651
|
+
if (w.visibleWhen) panel.visibleWhen = conditionToExpr(w.visibleWhen);
|
|
1652
|
+
const on = {};
|
|
1653
|
+
for (const a of (Array.isArray(w.actions) ? w.actions : []).filter(isObj)) {
|
|
1654
|
+
const trigger = a.on === "rowClick" ? "rowClick" : "click";
|
|
1655
|
+
const p = isObj(a.params) ? a.params : {};
|
|
1656
|
+
let action;
|
|
1657
|
+
if (a.type === "navigate")
|
|
1658
|
+
action = { do: "navigate", to: p.to, ...p.query ? { query: convertRefs(p.query) } : {} };
|
|
1659
|
+
else if (a.type === "setFilter") action = { do: "setVariable", name: p.filter, value: convertRefs(p.value) };
|
|
1660
|
+
else if (a.type === "drilldown")
|
|
1661
|
+
action = {
|
|
1662
|
+
do: "openDashboard",
|
|
1663
|
+
dashboard: p.dashboardId,
|
|
1664
|
+
...p.variables ? { filters: convertRefs(p.variables) } : {}
|
|
1665
|
+
};
|
|
1666
|
+
else if (a.type === "openModal" && typeof p.widget === "string") {
|
|
1667
|
+
const mid = `${p.widget}Modal`;
|
|
1668
|
+
modals[mid] = { title: p.title ?? "", panels: {}, layout: [{ panel: p.widget, x: 0, y: 0, w: 12, h: 8 }] };
|
|
1669
|
+
notes.push(`Modal "${mid}" was created with a copy of panel "${p.widget}"`);
|
|
1670
|
+
action = { do: "openModal", modal: mid, ...p.variables ? { args: convertRefs(p.variables) } : {} };
|
|
1671
|
+
}
|
|
1672
|
+
if (action) {
|
|
1673
|
+
on[trigger] = [...on[trigger] ?? [], action];
|
|
1674
|
+
} else notes.push(`Panel "${pid}": v1 action "${a.type}" was dropped`);
|
|
1675
|
+
}
|
|
1676
|
+
if (Object.keys(on).length > 0) panel.on = on;
|
|
1677
|
+
panels[pid] = panel;
|
|
1678
|
+
const l = isObj(w.layout) ? w.layout : {};
|
|
1679
|
+
const pos = (g) => ({ panel: pid, x: g.x, y: g.y, w: g.w, h: g.h });
|
|
1680
|
+
desktop.push(pos(l));
|
|
1681
|
+
const resp = isObj(l.responsive) ? l.responsive : {};
|
|
1682
|
+
if (isObj(resp.md)) tablet.push(pos(resp.md));
|
|
1683
|
+
if (isObj(resp.sm) || isObj(resp.xs)) mobile.push(pos(isObj(resp.sm) ? resp.sm : resp.xs));
|
|
1684
|
+
}
|
|
1685
|
+
for (const m of Object.values(modals)) {
|
|
1686
|
+
const item = m.layout[0];
|
|
1687
|
+
const source = panels[item.panel];
|
|
1688
|
+
if (source) m.panels[item.panel] = JSON.parse(JSON.stringify(source));
|
|
1689
|
+
}
|
|
1690
|
+
const layouts = [{ breakpoint: "desktop", items: desktop }];
|
|
1691
|
+
if (tablet.length) layouts.push({ breakpoint: "tablet", items: tablet });
|
|
1692
|
+
layouts.push(mobile.length ? { breakpoint: "mobile", items: mobile } : { breakpoint: "mobile", auto: "stack" });
|
|
1693
|
+
const meta = isObj(v1.meta) ? v1.meta : {};
|
|
1694
|
+
const spec = {
|
|
1695
|
+
display: { title: v1.title, ...v1.description ? { description: v1.description } : {} },
|
|
1696
|
+
grid: { columns: 12, rowHeight: layout.rowHeight ?? 56, gap: layout.gapX ?? 16 },
|
|
1697
|
+
...variables.length ? { variables } : {},
|
|
1698
|
+
...Object.keys(datasources).length ? { datasources } : {},
|
|
1699
|
+
panels,
|
|
1700
|
+
...Object.keys(modals).length ? { modals } : {},
|
|
1701
|
+
layouts
|
|
1702
|
+
};
|
|
1703
|
+
if (Object.values(datasources).some((d) => isObj(d) && d.type === "http"))
|
|
1704
|
+
notes.push("HTTP datasources keep their full URLs; consider moving the base URL into spec.connections");
|
|
1705
|
+
return {
|
|
1706
|
+
document: {
|
|
1707
|
+
$schema: "https://dashspec.dev/schema/v2.json",
|
|
1708
|
+
apiVersion: "dashspec.dev/v2",
|
|
1709
|
+
kind: "Dashboard",
|
|
1710
|
+
metadata: { key: id, name: String(v1.title ?? id), ...Array.isArray(meta.tags) ? { tags: meta.tags } : {} },
|
|
1711
|
+
spec
|
|
1712
|
+
},
|
|
1713
|
+
notes
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
// src/core/migrate/index.ts
|
|
1718
|
+
var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1719
|
+
var MigrationError = class extends Error {
|
|
1720
|
+
name = "MigrationError";
|
|
1721
|
+
};
|
|
1722
|
+
var clone = (v) => typeof structuredClone === "function" ? structuredClone(v) : JSON.parse(JSON.stringify(v));
|
|
1723
|
+
function migratePanels(panels, widgets, notes, at) {
|
|
1724
|
+
let changed = false;
|
|
1725
|
+
if (!isObj2(panels)) return false;
|
|
1726
|
+
for (const [pid, p] of Object.entries(panels)) {
|
|
1727
|
+
if (!isObj2(p) || typeof p.kind !== "string") continue;
|
|
1728
|
+
const w = widgets.get(p.kind);
|
|
1729
|
+
if (!w) continue;
|
|
1730
|
+
let version = typeof p.version === "number" ? p.version : 1;
|
|
1731
|
+
if (version > w.version) continue;
|
|
1732
|
+
while (version < w.version) {
|
|
1733
|
+
const step = w.steps?.[version];
|
|
1734
|
+
if (!step) {
|
|
1735
|
+
notes.push(`${at}.${pid}: no migration for ${p.kind} v${version} \u2192 v${version + 1}`);
|
|
1736
|
+
break;
|
|
1737
|
+
}
|
|
1738
|
+
p.spec = step(isObj2(p.spec) ? p.spec : {});
|
|
1739
|
+
version += 1;
|
|
1740
|
+
changed = true;
|
|
1741
|
+
}
|
|
1742
|
+
p.version = version;
|
|
1743
|
+
}
|
|
1744
|
+
return changed;
|
|
1745
|
+
}
|
|
1746
|
+
function liftSlots(panels) {
|
|
1747
|
+
let changed = false;
|
|
1748
|
+
if (!isObj2(panels)) return false;
|
|
1749
|
+
for (const p of Object.values(panels)) {
|
|
1750
|
+
if (!isObj2(p)) continue;
|
|
1751
|
+
const slots = isObj2(p.slots) ? p.slots : {};
|
|
1752
|
+
if (isObj2(p.spec) && Array.isArray(p.spec.children)) {
|
|
1753
|
+
if (p.spec.children.length)
|
|
1754
|
+
slots.items = [...slots.items ?? [], ...p.spec.children];
|
|
1755
|
+
delete p.spec.children;
|
|
1756
|
+
changed = true;
|
|
1757
|
+
}
|
|
1758
|
+
if (Array.isArray(p.addons)) {
|
|
1759
|
+
if (p.addons.length)
|
|
1760
|
+
slots.header = [...slots.header ?? [], ...p.addons];
|
|
1761
|
+
delete p.addons;
|
|
1762
|
+
changed = true;
|
|
1763
|
+
}
|
|
1764
|
+
if (Object.keys(slots).length) p.slots = slots;
|
|
1765
|
+
}
|
|
1766
|
+
return changed;
|
|
1767
|
+
}
|
|
1768
|
+
function migrateDocument(input, widgets = []) {
|
|
1769
|
+
if (!isObj2(input)) throw new MigrationError("Dashboard JSON must be an object");
|
|
1770
|
+
let doc;
|
|
1771
|
+
let from;
|
|
1772
|
+
const notes = [];
|
|
1773
|
+
if (input.apiVersion === API_VERSION) {
|
|
1774
|
+
doc = clone(input);
|
|
1775
|
+
from = "v2";
|
|
1776
|
+
} else if (input.schemaVersion === 1) {
|
|
1777
|
+
const r = migrateV1(clone(input));
|
|
1778
|
+
doc = r.document;
|
|
1779
|
+
notes.push(...r.notes);
|
|
1780
|
+
from = "v1";
|
|
1781
|
+
} else if (typeof input.apiVersion === "string") {
|
|
1782
|
+
throw new MigrationError(`apiVersion "${input.apiVersion}" is not supported; this renderer reads "${API_VERSION}"`);
|
|
1783
|
+
} else {
|
|
1784
|
+
throw new MigrationError(`Not a dashboard: expected apiVersion "${API_VERSION}"`);
|
|
1785
|
+
}
|
|
1786
|
+
let changed = from !== "v2";
|
|
1787
|
+
if (isObj2(doc.spec)) {
|
|
1788
|
+
changed = liftSlots(doc.spec.panels) || changed;
|
|
1789
|
+
if (isObj2(doc.spec.modals)) {
|
|
1790
|
+
for (const m of Object.values(doc.spec.modals)) if (isObj2(m)) changed = liftSlots(m.panels) || changed;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
if (widgets.length > 0 && isObj2(doc.spec)) {
|
|
1794
|
+
const byKind = new Map(widgets.map((w) => [w.kind, w]));
|
|
1795
|
+
changed = migratePanels(doc.spec.panels, byKind, notes, "spec.panels") || changed;
|
|
1796
|
+
if (isObj2(doc.spec.modals)) {
|
|
1797
|
+
for (const [mid, m] of Object.entries(doc.spec.modals))
|
|
1798
|
+
if (isObj2(m)) changed = migratePanels(m.panels, byKind, notes, `spec.modals.${mid}.panels`) || changed;
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return { document: doc, from, notes, changed };
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// src/core/schema/validate.ts
|
|
1805
|
+
import { z as z10 } from "zod";
|
|
1806
|
+
|
|
1807
|
+
// src/version.ts
|
|
1808
|
+
var RENDERER_VERSION = "0.1.1";
|
|
1809
|
+
var parse2 = (v) => {
|
|
1810
|
+
const m = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/.exec(v.trim());
|
|
1811
|
+
return m ? [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)] : void 0;
|
|
1812
|
+
};
|
|
1813
|
+
var cmp = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
1814
|
+
function satisfies(version, range) {
|
|
1815
|
+
const v = parse2(version);
|
|
1816
|
+
if (!v) return void 0;
|
|
1817
|
+
const parts = range.trim().split(/\s+/).filter(Boolean);
|
|
1818
|
+
if (parts.length === 0) return void 0;
|
|
1819
|
+
for (const part of parts) {
|
|
1820
|
+
const m = /^(>=|<=|>|<|=|\^|~)?(.+)$/.exec(part);
|
|
1821
|
+
const want = m ? parse2(m[2]) : void 0;
|
|
1822
|
+
if (!m || !want) return void 0;
|
|
1823
|
+
const c = cmp(v, want);
|
|
1824
|
+
const op = m[1] ?? "^";
|
|
1825
|
+
const ok = op === ">=" ? c >= 0 : op === "<=" ? c <= 0 : op === ">" ? c > 0 : op === "<" ? c < 0 : op === "=" ? c === 0 : op === "~" ? c >= 0 && v[0] === want[0] && v[1] === want[1] : (
|
|
1826
|
+
// "^": same major (same minor while the major is 0), and not older
|
|
1827
|
+
c >= 0 && v[0] === want[0] && (want[0] !== 0 || v[1] === want[1])
|
|
1828
|
+
);
|
|
1829
|
+
if (!ok) return false;
|
|
1830
|
+
}
|
|
1831
|
+
return true;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
// src/core/schema/validate.ts
|
|
1835
|
+
function tolerantParse(schema2, input, warn) {
|
|
1836
|
+
let work = input;
|
|
1837
|
+
let copied = false;
|
|
1838
|
+
const own2 = () => {
|
|
1839
|
+
if (!copied) {
|
|
1840
|
+
work = typeof structuredClone === "function" ? structuredClone(input) : JSON.parse(JSON.stringify(input));
|
|
1841
|
+
copied = true;
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
const at = (path) => path.reduce(
|
|
1845
|
+
(o, k) => o && typeof o === "object" ? o[k] : void 0,
|
|
1846
|
+
work
|
|
1847
|
+
);
|
|
1848
|
+
for (let round = 0; round < 25; round++) {
|
|
1849
|
+
const r = schema2.safeParse(work);
|
|
1850
|
+
if (r.success) return r;
|
|
1851
|
+
let fixed = false;
|
|
1852
|
+
for (const i of r.error.issues) {
|
|
1853
|
+
if (i.code === z10.ZodIssueCode.unrecognized_keys) {
|
|
1854
|
+
own2();
|
|
1855
|
+
const parent = at(i.path);
|
|
1856
|
+
for (const k of i.keys) {
|
|
1857
|
+
if (parent && Object.hasOwn(parent, k)) delete parent[k];
|
|
1858
|
+
if (k.startsWith("x-")) continue;
|
|
1859
|
+
const near = closest(k, knownKeys(schema2, i.path));
|
|
1860
|
+
warn(
|
|
1861
|
+
[...i.path, k],
|
|
1862
|
+
"unknown-field",
|
|
1863
|
+
`"${k}" isn't a known field here; it is ignored${near ? ` (did you mean "${near}"?)` : ""}`
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
fixed = true;
|
|
1867
|
+
} else if (i.code === z10.ZodIssueCode.invalid_enum_value && i.path.length > 0) {
|
|
1868
|
+
own2();
|
|
1869
|
+
const parent = at(i.path.slice(0, -1));
|
|
1870
|
+
const key = i.path[i.path.length - 1];
|
|
1871
|
+
if (parent && Object.hasOwn(parent, key)) {
|
|
1872
|
+
delete parent[key];
|
|
1873
|
+
warn(i.path, "unknown-value", `"${String(i.received)}" isn't a known choice here; the default is used`);
|
|
1874
|
+
fixed = true;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
if (!fixed) return r;
|
|
1879
|
+
}
|
|
1880
|
+
return schema2.safeParse(work);
|
|
1881
|
+
}
|
|
1882
|
+
function knownKeys(schema2, path) {
|
|
1883
|
+
let t = schema2;
|
|
1884
|
+
const unwrap = (x) => {
|
|
1885
|
+
let cur = x;
|
|
1886
|
+
for (let n = 0; n < 8 && cur; n++) {
|
|
1887
|
+
const d2 = cur._def;
|
|
1888
|
+
if (d2.innerType) cur = d2.innerType;
|
|
1889
|
+
else if (d2.schema) cur = d2.schema;
|
|
1890
|
+
else break;
|
|
1891
|
+
}
|
|
1892
|
+
return cur;
|
|
1893
|
+
};
|
|
1894
|
+
for (const k of path) {
|
|
1895
|
+
t = unwrap(t);
|
|
1896
|
+
const d2 = t?._def;
|
|
1897
|
+
if (!d2) return [];
|
|
1898
|
+
if (typeof k === "number") t = d2.type;
|
|
1899
|
+
else t = d2.shape?.()[k] ?? d2.valueType;
|
|
1900
|
+
}
|
|
1901
|
+
const d = unwrap(t)?._def;
|
|
1902
|
+
return Object.keys(d?.shape?.() ?? {});
|
|
1903
|
+
}
|
|
1904
|
+
function closest(word, names) {
|
|
1905
|
+
const dist = (a, b) => {
|
|
1906
|
+
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
1907
|
+
for (let i = 1; i <= a.length; i++) {
|
|
1908
|
+
const row = [i];
|
|
1909
|
+
for (let j = 1; j <= b.length; j++)
|
|
1910
|
+
row[j] = Math.min(
|
|
1911
|
+
(prev[j] ?? 0) + 1,
|
|
1912
|
+
(row[j - 1] ?? 0) + 1,
|
|
1913
|
+
(prev[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1)
|
|
1914
|
+
);
|
|
1915
|
+
prev = row;
|
|
1916
|
+
}
|
|
1917
|
+
return prev[b.length] ?? 99;
|
|
1918
|
+
};
|
|
1919
|
+
let best;
|
|
1920
|
+
let bestD = 3;
|
|
1921
|
+
for (const n of new Set(names)) {
|
|
1922
|
+
const d = dist(word.toLowerCase(), n.toLowerCase());
|
|
1923
|
+
if (d < bestD) {
|
|
1924
|
+
best = n;
|
|
1925
|
+
bestD = d;
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
return best;
|
|
1929
|
+
}
|
|
1930
|
+
var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1931
|
+
var entries = (v) => isObj3(v) ? Object.entries(v).filter(([, x]) => isObj3(x)) : [];
|
|
1932
|
+
var join = (path) => path.map(String).join(".");
|
|
1933
|
+
var SECRET_KEY = /^(authorization|x-api-key|api[-_]?key|token|access[-_]?token|secret|password|client[-_]?secret)$/i;
|
|
1934
|
+
var SECRET_VALUE = /(^bearer\s+[A-Za-z0-9._~+/-]{8,}=*$)|(eyJ[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,}\.[A-Za-z0-9_-]{5,})/i;
|
|
1935
|
+
function validateDocument(input, options = {}) {
|
|
1936
|
+
const problems = [];
|
|
1937
|
+
const err = (path, code, message) => problems.push({ severity: "error", path: join(path), code, message });
|
|
1938
|
+
const warn = (path, code, message) => problems.push({ severity: "warning", path: join(path), code, message });
|
|
1939
|
+
const tags = /* @__PURE__ */ new Set();
|
|
1940
|
+
const parsed = readingUnknownTags(
|
|
1941
|
+
(path, key, tag, known) => {
|
|
1942
|
+
const at = join(path);
|
|
1943
|
+
if (tags.has(at)) return;
|
|
1944
|
+
tags.add(at);
|
|
1945
|
+
const near = closest(tag, known);
|
|
1946
|
+
warn(
|
|
1947
|
+
path,
|
|
1948
|
+
"unknown-value",
|
|
1949
|
+
`Unknown ${key} "${tag}"${near ? ` (did you mean "${near}"?)` : ""}; it is ignored by this version`
|
|
1950
|
+
);
|
|
1951
|
+
},
|
|
1952
|
+
() => tolerantParse(Dashboard, input, warn)
|
|
1953
|
+
);
|
|
1954
|
+
if (!parsed.success) {
|
|
1955
|
+
for (const i of parsed.error.issues) err(i.path, "schema", i.message);
|
|
1956
|
+
}
|
|
1957
|
+
if (!isObj3(input) || !isObj3(input.spec)) return { valid: false, problems };
|
|
1958
|
+
const spec = input.spec;
|
|
1959
|
+
const range = isObj3(spec.requires) ? spec.requires.renderer : void 0;
|
|
1960
|
+
if (typeof range === "string") {
|
|
1961
|
+
const version = options.rendererVersion ?? RENDERER_VERSION;
|
|
1962
|
+
const ok = satisfies(version, range);
|
|
1963
|
+
if (ok === void 0)
|
|
1964
|
+
warn(["spec", "requires", "renderer"], "requires-unreadable", `Can't read the version range "${range}"`);
|
|
1965
|
+
else if (!ok)
|
|
1966
|
+
warn(
|
|
1967
|
+
["spec", "requires", "renderer"],
|
|
1968
|
+
"requires-renderer",
|
|
1969
|
+
`Made for @dashspec/renderer ${range}; this is ${version}, so some parts may not show. Update the renderer.`
|
|
1970
|
+
);
|
|
1971
|
+
}
|
|
1972
|
+
const connections = /* @__PURE__ */ new Set([
|
|
1973
|
+
...Object.keys(isObj3(spec.connections) ? spec.connections : {}),
|
|
1974
|
+
...options.hostConnections ?? []
|
|
1975
|
+
]);
|
|
1976
|
+
const actions2 = isObj3(spec.actions) ? spec.actions : {};
|
|
1977
|
+
const panels = isObj3(spec.panels) ? spec.panels : {};
|
|
1978
|
+
const modals = isObj3(spec.modals) ? spec.modals : {};
|
|
1979
|
+
const variables = Array.isArray(spec.variables) ? spec.variables.filter(isObj3) : [];
|
|
1980
|
+
const layouts = Array.isArray(spec.layouts) ? spec.layouts.filter(isObj3) : [];
|
|
1981
|
+
const columns = isObj3(spec.grid) && typeof spec.grid.columns === "number" ? spec.grid.columns : 12;
|
|
1982
|
+
const views = new Set(layouts.map((l) => l.view).filter((v) => typeof v === "string"));
|
|
1983
|
+
const varNames = new Set(variables.map((v) => v.name).filter((n) => typeof n === "string"));
|
|
1984
|
+
const customTypes = new Map((options.datasourceTypes ?? []).map((d) => [d.type, d.schema]));
|
|
1985
|
+
const topSources = new Set(Object.keys(isObj3(spec.datasources) ? spec.datasources : {}));
|
|
1986
|
+
const sourceScopes = [
|
|
1987
|
+
{ base: ["spec", "datasources"], sources: isObj3(spec.datasources) ? spec.datasources : {}, visible: topSources }
|
|
1988
|
+
];
|
|
1989
|
+
for (const [mid, m] of entries(modals)) {
|
|
1990
|
+
const own2 = isObj3(m.datasources) ? m.datasources : {};
|
|
1991
|
+
sourceScopes.push({
|
|
1992
|
+
base: ["spec", "modals", mid, "datasources"],
|
|
1993
|
+
sources: own2,
|
|
1994
|
+
visible: /* @__PURE__ */ new Set([...topSources, ...Object.keys(own2)])
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
const seenVars = /* @__PURE__ */ new Set();
|
|
1998
|
+
variables.forEach((v, i) => {
|
|
1999
|
+
if (typeof v.name === "string") {
|
|
2000
|
+
if (seenVars.has(v.name))
|
|
2001
|
+
err(["spec", "variables", i, "name"], "duplicate", `Filter "${v.name}" is defined twice`);
|
|
2002
|
+
seenVars.add(v.name);
|
|
2003
|
+
}
|
|
2004
|
+
const opts = v.options;
|
|
2005
|
+
if (isObj3(opts) && typeof opts.source === "string" && !topSources.has(opts.source))
|
|
2006
|
+
err(["spec", "variables", i, "options", "source"], "unknown-datasource", `No datasource "${opts.source}"`);
|
|
2007
|
+
});
|
|
2008
|
+
const deps = /* @__PURE__ */ new Map();
|
|
2009
|
+
variables.forEach((v, i) => {
|
|
2010
|
+
if (!Array.isArray(v.dependsOn)) return;
|
|
2011
|
+
const list2 = v.dependsOn.filter((d) => typeof d === "string");
|
|
2012
|
+
deps.set(String(v.name), list2);
|
|
2013
|
+
list2.forEach((d, j) => {
|
|
2014
|
+
if (!varNames.has(d)) err(["spec", "variables", i, "dependsOn", j], "unknown-variable", `No filter "${d}"`);
|
|
2015
|
+
});
|
|
2016
|
+
});
|
|
2017
|
+
for (const cycle of findCycles(deps))
|
|
2018
|
+
err(["spec", "variables"], "cycle", `Filters depend on each other in a loop: ${cycle.join(" \u2192 ")}`);
|
|
2019
|
+
if (isObj3(spec.state)) {
|
|
2020
|
+
for (const k of Object.keys(spec.state))
|
|
2021
|
+
if (RESERVED_STATE_KEYS.includes(k))
|
|
2022
|
+
err(["spec", "state", k], "reserved", `"${k}" is reserved by the runtime; use another name`);
|
|
2023
|
+
}
|
|
2024
|
+
for (const scope2 of sourceScopes) {
|
|
2025
|
+
const graph = /* @__PURE__ */ new Map();
|
|
2026
|
+
for (const [id, ds] of entries(scope2.sources)) {
|
|
2027
|
+
const at = [...scope2.base, id];
|
|
2028
|
+
const deps2 = [];
|
|
2029
|
+
if (typeof ds.from === "string") deps2.push(ds.from);
|
|
2030
|
+
if (isObj3(ds.forEach) && typeof ds.forEach.source === "string") deps2.push(ds.forEach.source);
|
|
2031
|
+
for (const r of collectReferences({ ...ds, transform: void 0 }))
|
|
2032
|
+
if (r.root === "datasources") deps2.push(r.name);
|
|
2033
|
+
for (const d of deps2)
|
|
2034
|
+
if (!scope2.visible.has(d)) err(at, "unknown-datasource", `Uses datasource "${d}", which is not defined`);
|
|
2035
|
+
graph.set(
|
|
2036
|
+
id,
|
|
2037
|
+
deps2.filter((d) => Object.hasOwn(scope2.sources, d))
|
|
2038
|
+
);
|
|
2039
|
+
const type = typeof ds.type === "string" ? ds.type : void 0;
|
|
2040
|
+
if (type && !BUILT_IN_DATASOURCE_TYPES.includes(type)) {
|
|
2041
|
+
if (!customTypes.has(type)) {
|
|
2042
|
+
const msg = `Datasource type "${type}" is not built in; register it with the "datasourceTypes" prop`;
|
|
2043
|
+
if (options.datasourceTypes) err([...at, "type"], "unknown-datasource-type", msg);
|
|
2044
|
+
else warn([...at, "type"], "unknown-datasource-type", msg);
|
|
2045
|
+
}
|
|
2046
|
+
const schema2 = customTypes.get(type);
|
|
2047
|
+
if (schema2) {
|
|
2048
|
+
const r = schema2.safeParse(ds);
|
|
2049
|
+
if (!r.success) for (const i of r.error.issues) err([...at, ...i.path], "schema", i.message);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
if (typeof ds.connection === "string" && !connections.has(ds.connection))
|
|
2053
|
+
err(
|
|
2054
|
+
[...at, "connection"],
|
|
2055
|
+
"unknown-connection",
|
|
2056
|
+
`Connection "${ds.connection}" is not in spec.connections or the host's connections`
|
|
2057
|
+
);
|
|
2058
|
+
if (ds.connection === void 0 && typeof ds.path === "string" && connections.size !== 1)
|
|
2059
|
+
err(
|
|
2060
|
+
[...at, "connection"],
|
|
2061
|
+
"missing-connection",
|
|
2062
|
+
'A "path" needs a "connection" when the dashboard has more than one'
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
2065
|
+
for (const cycle of findCycles(graph))
|
|
2066
|
+
err(
|
|
2067
|
+
[...scope2.base, cycle[0]],
|
|
2068
|
+
"cycle",
|
|
2069
|
+
`Datasources depend on each other in a loop: ${cycle.join(" \u2192 ")}`
|
|
2070
|
+
);
|
|
2071
|
+
}
|
|
2072
|
+
const checkAction = (a, at, scopePanels) => {
|
|
2073
|
+
if (typeof a === "string") {
|
|
2074
|
+
if (!Object.hasOwn(actions2, a)) err(at, "unknown-action", `No action "${a}" in spec.actions`);
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
if (!isObj3(a) || typeof a.do !== "string" || !ACTION_KINDS.includes(a.do)) return;
|
|
2078
|
+
const panelIds = (p) => Array.isArray(p) ? p : p === void 0 ? [] : [p];
|
|
2079
|
+
switch (a.do) {
|
|
2080
|
+
case "openModal":
|
|
2081
|
+
if (typeof a.modal === "string" && !Object.hasOwn(modals, a.modal))
|
|
2082
|
+
err([...at, "modal"], "unknown-modal", `No modal "${a.modal}"`);
|
|
2083
|
+
break;
|
|
2084
|
+
case "setView":
|
|
2085
|
+
if (typeof a.view === "string" && !views.has(a.view))
|
|
2086
|
+
err([...at, "view"], "unknown-view", `No layout has view "${a.view}"`);
|
|
2087
|
+
break;
|
|
2088
|
+
case "setVariable":
|
|
2089
|
+
if (typeof a.name === "string" && !varNames.has(a.name))
|
|
2090
|
+
err([...at, "name"], "unknown-variable", `No filter "${a.name}" in spec.variables`);
|
|
2091
|
+
break;
|
|
2092
|
+
case "fetch":
|
|
2093
|
+
case "refresh":
|
|
2094
|
+
for (const s of panelIds(a.source))
|
|
2095
|
+
if (typeof s === "string" && !topSources.has(s))
|
|
2096
|
+
err([...at, "source"], "unknown-datasource", `No datasource "${s}"`);
|
|
2097
|
+
break;
|
|
2098
|
+
case "http":
|
|
2099
|
+
case "download":
|
|
2100
|
+
if (typeof a.connection === "string" && !connections.has(a.connection))
|
|
2101
|
+
err([...at, "connection"], "unknown-connection", `Connection "${a.connection}" is not declared`);
|
|
2102
|
+
break;
|
|
2103
|
+
case "sequence":
|
|
2104
|
+
if (Array.isArray(a.steps)) a.steps.forEach((s, i) => checkAction(s, [...at, "steps", i], scopePanels));
|
|
2105
|
+
break;
|
|
2106
|
+
}
|
|
2107
|
+
if ("panel" in a) {
|
|
2108
|
+
for (const p of panelIds(a.panel))
|
|
2109
|
+
if (typeof p === "string" && !Object.hasOwn(scopePanels, p))
|
|
2110
|
+
err([...at, "panel"], "unknown-panel", `No panel "${p}"`);
|
|
2111
|
+
}
|
|
2112
|
+
};
|
|
2113
|
+
const checkHandler = (h, at, scopePanels) => {
|
|
2114
|
+
if (typeof h === "string") return;
|
|
2115
|
+
if (Array.isArray(h)) h.forEach((a, i) => checkAction(a, [...at, i], scopePanels));
|
|
2116
|
+
else if (isObj3(h)) {
|
|
2117
|
+
if ("run" in h) checkHandler(h.run, [...at, "run"], scopePanels);
|
|
2118
|
+
else for (const [part, ph] of Object.entries(h)) checkHandler(ph, [...at, part], scopePanels);
|
|
2119
|
+
}
|
|
2120
|
+
};
|
|
2121
|
+
const checkEvents = (on, at, scopePanels) => {
|
|
2122
|
+
for (const [ev, h] of Object.entries(isObj3(on) ? on : {})) checkHandler(h, [...at, ev], scopePanels);
|
|
2123
|
+
};
|
|
2124
|
+
for (const [name, a] of Object.entries(actions2)) {
|
|
2125
|
+
if (typeof a === "string") continue;
|
|
2126
|
+
checkAction(a, ["spec", "actions", name], panels);
|
|
2127
|
+
}
|
|
2128
|
+
checkEvents(spec.on, ["spec", "on"], panels);
|
|
2129
|
+
const widgets = options.widgets ? new Map(options.widgets.map((w) => [w.kind, w])) : void 0;
|
|
2130
|
+
const checkPanels = (ps, base2, visibleSources) => {
|
|
2131
|
+
for (const [pid, p] of entries(ps)) {
|
|
2132
|
+
const at = [...base2, pid];
|
|
2133
|
+
checkEvents(p.on, [...at, "on"], ps);
|
|
2134
|
+
const data = isObj3(p.spec) ? p.spec.data : void 0;
|
|
2135
|
+
if (data !== void 0 && !(typeof data === "string" && data.includes("${")) && !DataBinding.safeParse(data).success)
|
|
2136
|
+
err(
|
|
2137
|
+
[...at, "spec", "data"],
|
|
2138
|
+
"data-binding",
|
|
2139
|
+
"Data must be { source, path? }, { panel, path? }, { state } or { value }"
|
|
2140
|
+
);
|
|
2141
|
+
if (isObj3(data)) {
|
|
2142
|
+
if (typeof data.source === "string" && !visibleSources.has(data.source))
|
|
2143
|
+
err([...at, "spec", "data", "source"], "unknown-datasource", `No datasource "${data.source}"`);
|
|
2144
|
+
if (typeof data.panel === "string" && !Object.hasOwn(ps, data.panel))
|
|
2145
|
+
err([...at, "spec", "data", "panel"], "unknown-panel", `No panel "${data.panel}"`);
|
|
2146
|
+
}
|
|
2147
|
+
for (const r of collectReferences(p.spec)) {
|
|
2148
|
+
if (r.root === "datasources" && !visibleSources.has(r.name))
|
|
2149
|
+
err([...at, "spec"], "unknown-datasource", `Refers to datasource "${r.name}", which is not defined`);
|
|
2150
|
+
if (r.root === "panels" && !Object.hasOwn(panels, r.name) && !Object.hasOwn(ps, r.name))
|
|
2151
|
+
err([...at, "spec"], "unknown-panel", `Refers to panel "${r.name}", which is not defined`);
|
|
2152
|
+
}
|
|
2153
|
+
if (typeof p.visibleWhen === "string") {
|
|
2154
|
+
for (const r of expressionReferences(p.visibleWhen))
|
|
2155
|
+
if (r.root === "datasources" && !visibleSources.has(r.name))
|
|
2156
|
+
err([...at, "visibleWhen"], "unknown-datasource", `Refers to datasource "${r.name}", which is not defined`);
|
|
2157
|
+
}
|
|
2158
|
+
if (widgets && typeof p.kind === "string") {
|
|
2159
|
+
const w = widgets.get(p.kind);
|
|
2160
|
+
if (!w)
|
|
2161
|
+
warn([...at, "kind"], "unknown-widget", `No widget "${p.kind}" is registered; it shows as "Unknown widget"`);
|
|
2162
|
+
else {
|
|
2163
|
+
const version = typeof p.version === "number" ? p.version : 1;
|
|
2164
|
+
if (w.version !== void 0 && version > w.version)
|
|
2165
|
+
warn(
|
|
2166
|
+
[...at, "version"],
|
|
2167
|
+
"widget-version",
|
|
2168
|
+
`${p.kind} version ${version} is newer than this renderer supports (${w.version}); update the renderer to show it fully`
|
|
2169
|
+
);
|
|
2170
|
+
if (w.schema) {
|
|
2171
|
+
const r = tolerantParse(
|
|
2172
|
+
w.schema,
|
|
2173
|
+
p.spec ?? {},
|
|
2174
|
+
(path, code, message) => warn([...at, "spec", ...path], code, message)
|
|
2175
|
+
);
|
|
2176
|
+
if (!r.success)
|
|
2177
|
+
for (const i of r.error.issues) {
|
|
2178
|
+
if (isDynamic(p.spec, i.path)) continue;
|
|
2179
|
+
err([...at, "spec", ...i.path], "widget-spec", i.message);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
checkPanels(panels, ["spec", "panels"], topSources);
|
|
2187
|
+
const seenLayouts = /* @__PURE__ */ new Set();
|
|
2188
|
+
const placed = /* @__PURE__ */ new Set();
|
|
2189
|
+
const checkItems = (items, at, ps) => {
|
|
2190
|
+
if (!Array.isArray(items)) return;
|
|
2191
|
+
const here = /* @__PURE__ */ new Set();
|
|
2192
|
+
items.forEach((it, i) => {
|
|
2193
|
+
if (!isObj3(it) || typeof it.panel !== "string") return;
|
|
2194
|
+
if (!Object.hasOwn(ps, it.panel)) err([...at, i, "panel"], "unknown-panel", `No panel "${it.panel}"`);
|
|
2195
|
+
if (here.has(it.panel))
|
|
2196
|
+
err([...at, i, "panel"], "duplicate", `Panel "${it.panel}" is placed twice in this layout`);
|
|
2197
|
+
here.add(it.panel);
|
|
2198
|
+
placed.add(it.panel);
|
|
2199
|
+
if (typeof it.x === "number" && typeof it.w === "number" && it.x + it.w > columns)
|
|
2200
|
+
err([...at, i], "out-of-grid", `x + w = ${it.x + it.w} is wider than the ${columns}-column grid`);
|
|
2201
|
+
});
|
|
2202
|
+
};
|
|
2203
|
+
layouts.forEach((l, i) => {
|
|
2204
|
+
const key = `${l.view ?? ""}|${l.breakpoint ?? "desktop"}`;
|
|
2205
|
+
if (seenLayouts.has(key))
|
|
2206
|
+
err(
|
|
2207
|
+
["spec", "layouts", i],
|
|
2208
|
+
"duplicate",
|
|
2209
|
+
`Two layouts for view "${l.view ?? "(default)"}" at "${l.breakpoint ?? "desktop"}"`
|
|
2210
|
+
);
|
|
2211
|
+
seenLayouts.add(key);
|
|
2212
|
+
checkItems(l.items, ["spec", "layouts", i, "items"], panels);
|
|
2213
|
+
});
|
|
2214
|
+
const allPanels = { ...panels };
|
|
2215
|
+
for (const m of Object.values(isObj3(modals) ? modals : {}))
|
|
2216
|
+
if (isObj3(m) && isObj3(m.panels)) Object.assign(allPanels, m.panels);
|
|
2217
|
+
const onGrid = new Set(placed);
|
|
2218
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
2219
|
+
const kids = /* @__PURE__ */ new Map();
|
|
2220
|
+
const byKind = new Map((options.widgets ?? []).map((w) => [w.kind, w]));
|
|
2221
|
+
for (const [pid, p] of entries(allPanels)) {
|
|
2222
|
+
if (!isObj3(p.slots)) continue;
|
|
2223
|
+
const def = byKind.get(String(p.kind));
|
|
2224
|
+
for (const [slot, list2] of Object.entries(p.slots)) {
|
|
2225
|
+
if (!Array.isArray(list2)) continue;
|
|
2226
|
+
const ids = list2.filter((c) => typeof c === "string");
|
|
2227
|
+
const rule = slot === "header" || slot === "footer" ? { accepts: "small" } : def?.slots?.[slot];
|
|
2228
|
+
if (def && !rule && !def.openSlots && slot !== "header" && slot !== "footer")
|
|
2229
|
+
warn(["spec", "panels", pid, "slots", slot], "unknown-slot", `${String(p.kind)} has no slot "${slot}"`);
|
|
2230
|
+
if (rule?.max !== void 0 && ids.length > rule.max)
|
|
2231
|
+
err(["spec", "panels", pid, "slots", slot], "slot-full", `Slot "${slot}" takes at most ${rule.max}`);
|
|
2232
|
+
ids.forEach((c, i) => {
|
|
2233
|
+
const at = ["spec", "panels", pid, "slots", slot, i];
|
|
2234
|
+
const child = allPanels[c];
|
|
2235
|
+
if (!isObj3(child)) return err(at, "unknown-panel", `No panel "${c}"`);
|
|
2236
|
+
if (onGrid.has(c)) err(at, "two-places", `"${c}" is both on the grid and inside "${pid}"`);
|
|
2237
|
+
else if (parentOf.has(c) && parentOf.get(c) !== pid)
|
|
2238
|
+
err(at, "two-places", `"${c}" is inside both "${parentOf.get(c)}" and "${pid}"`);
|
|
2239
|
+
parentOf.set(c, pid);
|
|
2240
|
+
placed.add(c);
|
|
2241
|
+
const ck = byKind.get(String(child.kind));
|
|
2242
|
+
const accepts = rule?.accepts ?? "any";
|
|
2243
|
+
if (ck && accepts === "small" && !ck.small && slot !== "footer")
|
|
2244
|
+
err(at, "slot-accepts", `${String(child.kind)} can't go in "${slot}" (it takes badges, atoms and filters)`);
|
|
2245
|
+
if (Array.isArray(accepts) && !accepts.includes(String(child.kind)))
|
|
2246
|
+
err(at, "slot-accepts", `Slot "${slot}" takes ${accepts.join(", ")}`);
|
|
2247
|
+
});
|
|
2248
|
+
kids.set(pid, [...kids.get(pid) ?? [], ...ids]);
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
for (const [pid, p] of entries(allPanels))
|
|
2252
|
+
if (p.kind === "Filter" && isObj3(p.spec) && typeof p.spec.variable === "string" && !varNames.has(p.spec.variable))
|
|
2253
|
+
err(["spec", "panels", pid, "spec", "variable"], "unknown-filter", `No filter "${p.spec.variable}"`);
|
|
2254
|
+
for (const cycle of findCycles(kids))
|
|
2255
|
+
err(["spec", "panels", cycle[0]], "cycle", `Nodes hold each other in a loop: ${cycle.join(" \u2192 ")}`);
|
|
2256
|
+
for (const pid of Object.keys(panels))
|
|
2257
|
+
if (!placed.has(pid)) warn(["spec", "panels", pid], "not-placed", `Panel "${pid}" is not in any layout`);
|
|
2258
|
+
for (const [mid, m] of entries(modals)) {
|
|
2259
|
+
const ps = isObj3(m.panels) ? m.panels : {};
|
|
2260
|
+
const scope2 = sourceScopes.find((s) => s.base[2] === mid);
|
|
2261
|
+
checkPanels(ps, ["spec", "modals", mid, "panels"], scope2?.visible ?? topSources);
|
|
2262
|
+
checkItems(m.layout, ["spec", "modals", mid, "layout"], ps);
|
|
2263
|
+
checkEvents(m.on, ["spec", "modals", mid, "on"], ps);
|
|
2264
|
+
}
|
|
2265
|
+
const display = isObj3(spec.display) ? spec.display : {};
|
|
2266
|
+
if (isObj3(display.tv) && Array.isArray(display.tv.rotateViews))
|
|
2267
|
+
display.tv.rotateViews.forEach((v, i) => {
|
|
2268
|
+
if (typeof v === "string" && !views.has(v))
|
|
2269
|
+
err(["spec", "display", "tv", "rotateViews", i], "unknown-view", `No layout has view "${v}"`);
|
|
2270
|
+
});
|
|
2271
|
+
if (Array.isArray(spec.tour))
|
|
2272
|
+
spec.tour.forEach((t, i) => {
|
|
2273
|
+
if (isObj3(t) && typeof t.panel === "string" && !Object.hasOwn(panels, t.panel))
|
|
2274
|
+
err(["spec", "tour", i, "panel"], "unknown-panel", `No panel "${t.panel}"`);
|
|
2275
|
+
});
|
|
2276
|
+
findSecrets(input, [], err);
|
|
2277
|
+
const valid = !problems.some((p) => p.severity === "error");
|
|
2278
|
+
return { valid, problems, ...valid && parsed.success ? { document: parsed.data } : {} };
|
|
2279
|
+
}
|
|
2280
|
+
function isDynamic(spec, path) {
|
|
2281
|
+
let cur = spec;
|
|
2282
|
+
for (let i = 0; i <= path.length; i++) {
|
|
2283
|
+
if (typeof cur === "string" && cur.includes("${")) return true;
|
|
2284
|
+
if (isObj3(cur) && typeof cur.fn === "string" && Object.keys(cur).length === 1) return true;
|
|
2285
|
+
if (i === path.length || cur === null || typeof cur !== "object") return false;
|
|
2286
|
+
cur = cur[path[i]];
|
|
2287
|
+
}
|
|
2288
|
+
return false;
|
|
2289
|
+
}
|
|
2290
|
+
function findSecrets(v, path, err) {
|
|
2291
|
+
if (typeof v === "string") {
|
|
2292
|
+
if (SECRET_VALUE.test(v))
|
|
2293
|
+
err(path, "secret", "Looks like a token; tokens never go in the JSON (use auth.token.from)");
|
|
2294
|
+
return;
|
|
2295
|
+
}
|
|
2296
|
+
if (Array.isArray(v)) v.forEach((x, i) => findSecrets(x, [...path, i], err));
|
|
2297
|
+
else if (isObj3(v))
|
|
2298
|
+
for (const [k, x] of Object.entries(v)) {
|
|
2299
|
+
const at = [...path, k];
|
|
2300
|
+
if (SECRET_KEY.test(k) && typeof x === "string" && x.length > 0 && !x.includes("${") && !x.startsWith("$"))
|
|
2301
|
+
err(at, "secret", `"${k}" holds a literal value; secrets never go in the JSON (use auth or the host)`);
|
|
2302
|
+
else findSecrets(x, at, err);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
function findCycles(graph) {
|
|
2306
|
+
const cycles = [];
|
|
2307
|
+
const state = /* @__PURE__ */ new Map();
|
|
2308
|
+
const stack = [];
|
|
2309
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2310
|
+
const visit = (n) => {
|
|
2311
|
+
state.set(n, 1);
|
|
2312
|
+
stack.push(n);
|
|
2313
|
+
for (const d of graph.get(n) ?? []) {
|
|
2314
|
+
if (state.get(d) === 1) {
|
|
2315
|
+
const cycle = [...stack.slice(stack.indexOf(d)), d];
|
|
2316
|
+
const key = [...cycle].slice(0, -1).sort().join(",");
|
|
2317
|
+
if (!seen.has(key)) {
|
|
2318
|
+
seen.add(key);
|
|
2319
|
+
cycles.push(cycle);
|
|
2320
|
+
}
|
|
2321
|
+
} else if (!state.has(d)) visit(d);
|
|
2322
|
+
}
|
|
2323
|
+
stack.pop();
|
|
2324
|
+
state.set(n, 2);
|
|
2325
|
+
};
|
|
2326
|
+
for (const n of graph.keys()) if (!state.has(n)) visit(n);
|
|
2327
|
+
return cycles;
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
// src/core/load.ts
|
|
2331
|
+
function loadDocument(input, options = {}) {
|
|
2332
|
+
let migrated;
|
|
2333
|
+
try {
|
|
2334
|
+
const migrations = (options.widgets ?? []).filter((w) => typeof w.version === "number").map((w) => ({ kind: w.kind, version: w.version, steps: w.steps }));
|
|
2335
|
+
migrated = migrateDocument(input, migrations);
|
|
2336
|
+
} catch (e) {
|
|
2337
|
+
if (!(e instanceof MigrationError)) throw e;
|
|
2338
|
+
return { status: "invalid", problems: [{ severity: "error", path: "", code: "migration", message: e.message }] };
|
|
2339
|
+
}
|
|
2340
|
+
const { document: document2, ...migration } = migrated;
|
|
2341
|
+
const result = validateDocument(document2, options);
|
|
2342
|
+
return result.valid && result.document ? { status: "valid", document: result.document, problems: result.problems, migration } : { status: "invalid", problems: result.problems, migration };
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// src/core/schema/jsonSchema.ts
|
|
2346
|
+
import { z as z11 } from "zod";
|
|
2347
|
+
import { ignoreOverride, parseDef, zodToJsonSchema } from "zod-to-json-schema";
|
|
2348
|
+
function dashboardJsonSchema(options = {}) {
|
|
2349
|
+
const widgetSchemas = (options.widgets ?? []).filter((w) => w.schema);
|
|
2350
|
+
const schema2 = zodToJsonSchema(Dashboard, {
|
|
2351
|
+
name: "Dashboard",
|
|
2352
|
+
target: "jsonSchema7",
|
|
2353
|
+
$refStrategy: "root",
|
|
2354
|
+
definitions: { JsonValue },
|
|
2355
|
+
override: (def, refs) => {
|
|
2356
|
+
const meta = def[DISPATCH];
|
|
2357
|
+
if (!meta) return ignoreOverride;
|
|
2358
|
+
const members = Object.values(meta.schemas);
|
|
2359
|
+
return parseDef(z11.union(members)._def, refs, true) ?? {};
|
|
2360
|
+
}
|
|
2361
|
+
});
|
|
2362
|
+
const root = schema2.definitions?.Dashboard ?? schema2;
|
|
2363
|
+
if (widgetSchemas.length > 0) attachWidgetProps(root, widgetSchemas);
|
|
2364
|
+
const { Dashboard: _, ...definitions } = schema2.definitions ?? {};
|
|
2365
|
+
const out = JSON.parse(JSON.stringify(root).replaceAll('"#/definitions/Dashboard', '"#'));
|
|
2366
|
+
return {
|
|
2367
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
2368
|
+
$id: SCHEMA_URL,
|
|
2369
|
+
title: "DashSpec dashboard",
|
|
2370
|
+
...out,
|
|
2371
|
+
definitions
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function attachWidgetProps(root, widgets) {
|
|
2375
|
+
const panelSchema = root.properties.spec.properties.panels;
|
|
2376
|
+
const panel = panelSchema.additionalProperties;
|
|
2377
|
+
panel.allOf = widgets.map((w) => ({
|
|
2378
|
+
if: { properties: { kind: { const: w.kind } }, required: ["kind"] },
|
|
2379
|
+
// biome-ignore lint/suspicious/noThenProperty: JSON Schema's if/then keyword
|
|
2380
|
+
then: {
|
|
2381
|
+
properties: { spec: zodToJsonSchema(w.schema, { $refStrategy: "none", target: "jsonSchema7" }) }
|
|
2382
|
+
}
|
|
2383
|
+
}));
|
|
2384
|
+
const kind = panel.properties.kind;
|
|
2385
|
+
kind.examples = widgets.map((w) => w.kind);
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
// src/core/transform/index.ts
|
|
2389
|
+
var TransformError = class extends Error {
|
|
2390
|
+
constructor(message, step) {
|
|
2391
|
+
super(message);
|
|
2392
|
+
this.step = step;
|
|
2393
|
+
}
|
|
2394
|
+
name = "TransformError";
|
|
2395
|
+
};
|
|
2396
|
+
var AGG = ["sum", "avg", "min", "max", "first", "last"];
|
|
2397
|
+
var list = (v) => v === void 0 ? [] : Array.isArray(v) ? v.map(String) : [String(v)];
|
|
2398
|
+
var asRows = (data) => Array.isArray(data) ? data : data === null || data === void 0 ? [] : [data];
|
|
2399
|
+
var num = (v) => typeof v === "number" ? v : v === null || v === void 0 || v === "" ? Number.NaN : Number(v);
|
|
2400
|
+
function compare(a, b) {
|
|
2401
|
+
if (a === b) return 0;
|
|
2402
|
+
if (a === null || a === void 0) return 1;
|
|
2403
|
+
if (b === null || b === void 0) return -1;
|
|
2404
|
+
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
2405
|
+
const na = num(a);
|
|
2406
|
+
const nb = num(b);
|
|
2407
|
+
if (!Number.isNaN(na) && !Number.isNaN(nb)) return na - nb;
|
|
2408
|
+
return String(a).localeCompare(String(b), void 0, { numeric: true });
|
|
2409
|
+
}
|
|
2410
|
+
function aggregate(rows, step, into) {
|
|
2411
|
+
for (const op of AGG) {
|
|
2412
|
+
for (const f of list(step[op])) {
|
|
2413
|
+
const vals = rows.map((r) => r[f]);
|
|
2414
|
+
const nums = vals.map(num).filter((n) => !Number.isNaN(n));
|
|
2415
|
+
into[f] = op === "sum" ? nums.reduce((a, b) => a + b, 0) : op === "avg" ? nums.length ? nums.reduce((a, b) => a + b, 0) / nums.length : null : op === "min" ? nums.length ? nums.reduce((a, b) => b < a ? b : a) : null : op === "max" ? nums.length ? nums.reduce((a, b) => b > a ? b : a) : null : op === "first" ? vals[0] ?? null : vals[vals.length - 1] ?? null;
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
if (step.count !== void 0) into[typeof step.count === "string" ? step.count : "count"] = rows.length;
|
|
2419
|
+
}
|
|
2420
|
+
function runStep(data, step, i, root, opts) {
|
|
2421
|
+
if ("fn" in step) {
|
|
2422
|
+
if (!opts.runFn) throw new TransformError("fn steps need the script runner", i);
|
|
2423
|
+
return opts.runFn(String(step.fn), data);
|
|
2424
|
+
}
|
|
2425
|
+
const rows = asRows(data);
|
|
2426
|
+
if ("filter" in step) {
|
|
2427
|
+
const expr = String(step.filter);
|
|
2428
|
+
const layer = (r) => r !== null && typeof r === "object" ? r : { value: r };
|
|
2429
|
+
return rows.filter((r) => Boolean(evaluate(expr, { layers: [layer(r), ...root.layers] })));
|
|
2430
|
+
}
|
|
2431
|
+
if ("map" in step) {
|
|
2432
|
+
const m = step.map;
|
|
2433
|
+
return rows.map((r) => {
|
|
2434
|
+
const key = String(r[m.field]);
|
|
2435
|
+
const v = Object.hasOwn(m.values, key) ? m.values[key] : m.default !== void 0 ? m.default : r[m.field];
|
|
2436
|
+
return { ...r, [m.to ?? m.field]: v };
|
|
2437
|
+
});
|
|
2438
|
+
}
|
|
2439
|
+
if ("groupBy" in step || AGG.some((a) => a in step) || "count" in step) {
|
|
2440
|
+
const keys = list(step.groupBy);
|
|
2441
|
+
if (keys.length === 0) {
|
|
2442
|
+
const out = {};
|
|
2443
|
+
aggregate(rows, step, out);
|
|
2444
|
+
return out;
|
|
2445
|
+
}
|
|
2446
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2447
|
+
for (const r of rows) {
|
|
2448
|
+
const k = JSON.stringify(keys.map((f) => r[f]));
|
|
2449
|
+
const g = groups.get(k);
|
|
2450
|
+
if (g) g.push(r);
|
|
2451
|
+
else groups.set(k, [r]);
|
|
2452
|
+
}
|
|
2453
|
+
return [...groups.values()].map((g) => {
|
|
2454
|
+
const out = Object.fromEntries(keys.map((f) => [f, g[0][f]]));
|
|
2455
|
+
aggregate(g, step, out);
|
|
2456
|
+
return out;
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
if ("pivot" in step) {
|
|
2460
|
+
const p = step.pivot;
|
|
2461
|
+
const keys = list(p.rows);
|
|
2462
|
+
const out = /* @__PURE__ */ new Map();
|
|
2463
|
+
for (const r of rows) {
|
|
2464
|
+
const k = JSON.stringify(keys.map((f) => r[f]));
|
|
2465
|
+
let o = out.get(k);
|
|
2466
|
+
if (!o) {
|
|
2467
|
+
o = Object.fromEntries(keys.map((f) => [f, r[f]]));
|
|
2468
|
+
out.set(k, o);
|
|
2469
|
+
}
|
|
2470
|
+
Object.defineProperty(o, String(r[p.cols]), {
|
|
2471
|
+
value: r[p.value],
|
|
2472
|
+
enumerable: true,
|
|
2473
|
+
writable: true,
|
|
2474
|
+
configurable: true
|
|
2475
|
+
});
|
|
2476
|
+
}
|
|
2477
|
+
return [...out.values()];
|
|
2478
|
+
}
|
|
2479
|
+
if ("sort" in step) {
|
|
2480
|
+
const keys = list(step.sort);
|
|
2481
|
+
const dir = step.order === "desc" ? -1 : 1;
|
|
2482
|
+
return [...rows].sort((a, b) => {
|
|
2483
|
+
for (const k of keys) {
|
|
2484
|
+
const c = compare(a[k], b[k]);
|
|
2485
|
+
if (c !== 0) return a[k] === null || a[k] === void 0 || b[k] === null || b[k] === void 0 ? c : c * dir;
|
|
2486
|
+
}
|
|
2487
|
+
return 0;
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
if ("limit" in step) return rows.slice(0, Number(step.limit));
|
|
2491
|
+
if ("pick" in step) {
|
|
2492
|
+
const fields = list(step.pick);
|
|
2493
|
+
return rows.map((r) => Object.fromEntries(fields.map((f) => [f, r[f]])));
|
|
2494
|
+
}
|
|
2495
|
+
throw new TransformError(`Unknown transform step: ${Object.keys(step).join(", ")}`, i);
|
|
2496
|
+
}
|
|
2497
|
+
function applyTransform(data, steps2, root, opts = {}) {
|
|
2498
|
+
const max = opts.maxRows ?? 1e5;
|
|
2499
|
+
const check = (rows, i) => {
|
|
2500
|
+
if (Array.isArray(rows) && rows.length > max)
|
|
2501
|
+
throw new TransformError(`${rows.length} rows is more than the ${max} a dashboard transforms in the browser`, i);
|
|
2502
|
+
};
|
|
2503
|
+
let out = data;
|
|
2504
|
+
steps2.forEach((step, i) => {
|
|
2505
|
+
check(out, i);
|
|
2506
|
+
try {
|
|
2507
|
+
out = runStep(out, step, i, root, opts);
|
|
2508
|
+
} catch (e) {
|
|
2509
|
+
if (e instanceof TransformError) throw e;
|
|
2510
|
+
throw new TransformError(`Step ${i + 1}: ${e.message}`, i);
|
|
2511
|
+
}
|
|
2512
|
+
});
|
|
2513
|
+
if (steps2.length) check(out, steps2.length - 1);
|
|
2514
|
+
return out;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
// src/widgets/registry.ts
|
|
2518
|
+
function createWidgetRegistry(builtIns, extra = [], aliases = {}) {
|
|
2519
|
+
for (const w of extra) {
|
|
2520
|
+
if (!w.kind.includes(".")) throw new Error(`Custom widget kind must be namespaced, e.g. "acme.${w.kind}"`);
|
|
2521
|
+
if (builtIns.some((b) => b.kind === w.kind))
|
|
2522
|
+
throw new Error(`Cannot replace the built-in widget ${w.kind}; use aliases`);
|
|
2523
|
+
if (extra.filter((x) => x.kind === w.kind).length > 1) throw new Error(`Widget ${w.kind} is registered twice`);
|
|
2524
|
+
}
|
|
2525
|
+
const all = [...builtIns, ...extra];
|
|
2526
|
+
const byKind = new Map(all.map((w) => [w.kind, w]));
|
|
2527
|
+
for (const [from, to] of Object.entries(aliases)) {
|
|
2528
|
+
const target2 = byKind.get(to);
|
|
2529
|
+
if (!target2) throw new Error(`Alias ${from} \u2192 ${to}: no widget ${to}`);
|
|
2530
|
+
const original = byKind.get(from);
|
|
2531
|
+
if (original?.implements && target2.implements && original.implements !== target2.implements)
|
|
2532
|
+
throw new Error(
|
|
2533
|
+
`Alias ${from} \u2192 ${to}: ${from} is a "${original.implements}", ${to} is a "${target2.implements}"`
|
|
2534
|
+
);
|
|
2535
|
+
byKind.set(from, target2);
|
|
2536
|
+
}
|
|
2537
|
+
return { byKind, all };
|
|
2538
|
+
}
|
|
2539
|
+
function checkWidget(w) {
|
|
2540
|
+
const out = [];
|
|
2541
|
+
if (!/^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)?$/.test(w.kind)) out.push(`invalid kind "${w.kind}"`);
|
|
2542
|
+
if (!w.meta?.label) out.push("meta.label is missing");
|
|
2543
|
+
if (typeof w.component !== "function" && typeof w.component !== "object") out.push("component is missing");
|
|
2544
|
+
const parsed = w.schema.safeParse(w.defaults ?? {});
|
|
2545
|
+
if (!parsed.success) out.push(`defaults don't match the schema: ${parsed.error.issues[0]?.message ?? ""}`);
|
|
2546
|
+
for (const name of Object.keys(w.slots ?? {}))
|
|
2547
|
+
if (!/^[A-Za-z][\w-]*$/.test(name)) out.push(`slot name "${name}" must be letters, digits, '_' or '-'`);
|
|
2548
|
+
for (const k of Object.keys(w.exposes ?? {}))
|
|
2549
|
+
if (!/^[A-Za-z][\w]*$/.test(k)) out.push(`exposes "${k}" must be a simple name`);
|
|
2550
|
+
return out;
|
|
2551
|
+
}
|
|
2552
|
+
var contractChecks = (widgets) => widgets.map((w) => ({
|
|
2553
|
+
kind: w.kind,
|
|
2554
|
+
version: w.version,
|
|
2555
|
+
schema: w.schema,
|
|
2556
|
+
...w.slots ? { slots: w.slots } : {},
|
|
2557
|
+
...w.small ? { small: true } : {},
|
|
2558
|
+
...w.openSlots ? { openSlots: true } : {},
|
|
2559
|
+
...w.migrations ? { steps: w.migrations } : {}
|
|
2560
|
+
}));
|
|
2561
|
+
var widgetChecks = (r) => contractChecks(r.all);
|
|
2562
|
+
|
|
2563
|
+
// src/widgets/schemas/Breakdown.ts
|
|
2564
|
+
import { z as z13 } from "zod";
|
|
2565
|
+
|
|
2566
|
+
// src/widgets/schemas/common.ts
|
|
2567
|
+
import { z as z12 } from "zod";
|
|
2568
|
+
var Format = z12.enum(["number", "compact", "percent", "duration", "date", "datetime", "time", "text"]);
|
|
2569
|
+
var Tone = z12.enum(["good", "warn", "bad", "neutral", "info"]);
|
|
2570
|
+
var ToneMap = z12.record(Tone);
|
|
2571
|
+
var Common2 = {
|
|
2572
|
+
title: z12.string().optional(),
|
|
2573
|
+
subtitle: z12.string().optional(),
|
|
2574
|
+
/** Plain-language help behind the ⓘ next to the title. */
|
|
2575
|
+
info: z12.string().optional(),
|
|
2576
|
+
/** Short text on the right of the card header, e.g. "Total: ${datasources.x.data.total} heats". */
|
|
2577
|
+
meta: z12.string().optional(),
|
|
2578
|
+
/** Shows "● Live, updated just now" from the datasource's last update (amber when a refresh failed). */
|
|
2579
|
+
live: z12.boolean().optional(),
|
|
2580
|
+
data: z12.unknown().optional(),
|
|
2581
|
+
/** Anything the underlying library supports, merged last. */
|
|
2582
|
+
options: z12.record(z12.unknown()).optional(),
|
|
2583
|
+
/** Hover group for cross-panel highlight. */
|
|
2584
|
+
highlight: z12.string().optional()
|
|
2585
|
+
};
|
|
2586
|
+
|
|
2587
|
+
// src/widgets/schemas/Breakdown.ts
|
|
2588
|
+
var BreakdownContract = {
|
|
2589
|
+
kind: "Breakdown",
|
|
2590
|
+
version: 1,
|
|
2591
|
+
schema: z13.object({
|
|
2592
|
+
...Common2,
|
|
2593
|
+
label: z13.string(),
|
|
2594
|
+
value: z13.string(),
|
|
2595
|
+
mode: z13.enum(["meters", "segmented", "donut"]).default("meters"),
|
|
2596
|
+
/** Adds a remainder item up to `total`, e.g. "Unaccounted". */
|
|
2597
|
+
remainder: z13.object({ label: z13.string(), total: z13.union([z13.number(), z13.string()]) }).strict().optional(),
|
|
2598
|
+
showPercent: z13.boolean().default(true),
|
|
2599
|
+
format: Format.optional(),
|
|
2600
|
+
decimals: z13.number().int().min(0).max(6).optional(),
|
|
2601
|
+
unit: z13.string().optional(),
|
|
2602
|
+
limit: z13.number().int().min(1).optional()
|
|
2603
|
+
}).strict()
|
|
2604
|
+
};
|
|
2605
|
+
|
|
2606
|
+
// src/widgets/schemas/CardGrid.ts
|
|
2607
|
+
import { z as z14 } from "zod";
|
|
2608
|
+
var FieldDef = z14.object({
|
|
2609
|
+
key: z14.string(),
|
|
2610
|
+
label: z14.string().optional(),
|
|
2611
|
+
format: Format.optional(),
|
|
2612
|
+
decimals: z14.number().int().optional(),
|
|
2613
|
+
unit: z14.string().optional()
|
|
2614
|
+
}).strict();
|
|
2615
|
+
var CardGridContract = {
|
|
2616
|
+
kind: "CardGrid",
|
|
2617
|
+
version: 1,
|
|
2618
|
+
schema: z14.object({
|
|
2619
|
+
...Common2,
|
|
2620
|
+
cardTitle: z14.string(),
|
|
2621
|
+
status: z14.string().optional(),
|
|
2622
|
+
statusMap: ToneMap.optional(),
|
|
2623
|
+
fields: z14.array(FieldDef).default([]),
|
|
2624
|
+
progress: z14.object({
|
|
2625
|
+
value: z14.string(),
|
|
2626
|
+
max: z14.union([z14.string(), z14.number()]).default(100),
|
|
2627
|
+
label: z14.string().optional()
|
|
2628
|
+
}).strict().optional(),
|
|
2629
|
+
badge: z14.string().optional(),
|
|
2630
|
+
minCardWidth: z14.number().int().min(120).default(220),
|
|
2631
|
+
selectable: z14.boolean().default(false),
|
|
2632
|
+
selected: z14.unknown().optional(),
|
|
2633
|
+
rowKey: z14.string().optional()
|
|
2634
|
+
}).strict()
|
|
2635
|
+
};
|
|
2636
|
+
|
|
2637
|
+
// src/widgets/schemas/Container.ts
|
|
2638
|
+
import { z as z15 } from "zod";
|
|
2639
|
+
var ContainerContract = {
|
|
2640
|
+
kind: "Container",
|
|
2641
|
+
version: 1,
|
|
2642
|
+
schema: z15.object({
|
|
2643
|
+
...Common2,
|
|
2644
|
+
direction: z15.enum(["row", "column"]).default("row"),
|
|
2645
|
+
wrap: z15.boolean().default(true),
|
|
2646
|
+
gap: z15.number().int().min(0).max(64).default(12),
|
|
2647
|
+
justify: z15.enum(["start", "center", "end", "between", "around", "evenly"]).default("start"),
|
|
2648
|
+
align: z15.enum(["start", "center", "end", "stretch"]).default("stretch"),
|
|
2649
|
+
/** Children share the width equally (row) unless they set their own `style.flex`. */
|
|
2650
|
+
equal: z15.boolean().default(true),
|
|
2651
|
+
/** Smallest width of a child before the row wraps, in px. */
|
|
2652
|
+
childMinWidth: z15.number().int().min(0).max(2e3).default(160),
|
|
2653
|
+
/** Scroll when the children don't fit. */
|
|
2654
|
+
scroll: z15.boolean().default(false)
|
|
2655
|
+
}).strict(),
|
|
2656
|
+
slots: { items: { label: "Items" } }
|
|
2657
|
+
};
|
|
2658
|
+
|
|
2659
|
+
// src/widgets/schemas/Content.ts
|
|
2660
|
+
import { z as z16 } from "zod";
|
|
2661
|
+
var ContentContract = {
|
|
2662
|
+
kind: "Content",
|
|
2663
|
+
version: 1,
|
|
2664
|
+
small: true,
|
|
2665
|
+
schema: z16.object({ ...Common2, markdown: z16.string().default(""), align: z16.enum(["left", "center", "right"]).optional() }).strict()
|
|
2666
|
+
};
|
|
2667
|
+
|
|
2668
|
+
// src/widgets/schemas/Filter.ts
|
|
2669
|
+
import { z as z17 } from "zod";
|
|
2670
|
+
var FilterContract = {
|
|
2671
|
+
kind: "Filter",
|
|
2672
|
+
version: 1,
|
|
2673
|
+
small: true,
|
|
2674
|
+
schema: z17.object({
|
|
2675
|
+
...Common2,
|
|
2676
|
+
/** The filter's name in `spec.variables`. */
|
|
2677
|
+
variable: z17.string().min(1),
|
|
2678
|
+
/** Stretch the control to the panel's width. */
|
|
2679
|
+
fill: z17.boolean().default(false)
|
|
2680
|
+
}).strict()
|
|
2681
|
+
};
|
|
2682
|
+
|
|
2683
|
+
// src/widgets/schemas/Image.ts
|
|
2684
|
+
import { z as z18 } from "zod";
|
|
2685
|
+
var ImageContract = {
|
|
2686
|
+
kind: "Image",
|
|
2687
|
+
version: 1,
|
|
2688
|
+
schema: z18.object({
|
|
2689
|
+
...Common2,
|
|
2690
|
+
src: z18.string().optional(),
|
|
2691
|
+
srcField: z18.string().optional(),
|
|
2692
|
+
alt: z18.string().default(""),
|
|
2693
|
+
fit: z18.enum(["contain", "cover", "fill"]).default("contain")
|
|
2694
|
+
}).strict()
|
|
2695
|
+
};
|
|
2696
|
+
|
|
2697
|
+
// src/widgets/schemas/ImageMap.ts
|
|
2698
|
+
import { z as z19 } from "zod";
|
|
2699
|
+
var Marker = z19.object({
|
|
2700
|
+
x: z19.number(),
|
|
2701
|
+
y: z19.number(),
|
|
2702
|
+
label: z19.string().optional(),
|
|
2703
|
+
value: z19.unknown().optional(),
|
|
2704
|
+
status: z19.string().optional()
|
|
2705
|
+
}).strict();
|
|
2706
|
+
var ImageMapContract = {
|
|
2707
|
+
kind: "ImageMap",
|
|
2708
|
+
version: 1,
|
|
2709
|
+
schema: z19.object({
|
|
2710
|
+
...Common2,
|
|
2711
|
+
src: z19.string(),
|
|
2712
|
+
alt: z19.string().default(""),
|
|
2713
|
+
/** Static markers (x and y in % of the image), or field names to read markers from the data rows. */
|
|
2714
|
+
markers: z19.union([
|
|
2715
|
+
z19.array(Marker),
|
|
2716
|
+
z19.object({
|
|
2717
|
+
x: z19.string(),
|
|
2718
|
+
y: z19.string(),
|
|
2719
|
+
label: z19.string().optional(),
|
|
2720
|
+
value: z19.string().optional(),
|
|
2721
|
+
status: z19.string().optional()
|
|
2722
|
+
}).strict()
|
|
2723
|
+
]).optional(),
|
|
2724
|
+
statusMap: ToneMap.optional(),
|
|
2725
|
+
format: Format.optional(),
|
|
2726
|
+
unit: z19.string().optional()
|
|
2727
|
+
}).strict()
|
|
2728
|
+
};
|
|
2729
|
+
|
|
2730
|
+
// src/widgets/schemas/Kpi.ts
|
|
2731
|
+
import { z as z20 } from "zod";
|
|
2732
|
+
var NumberOrPath = z20.union([z20.number(), z20.string()]);
|
|
2733
|
+
var KpiContract = {
|
|
2734
|
+
kind: "Kpi",
|
|
2735
|
+
version: 1,
|
|
2736
|
+
schema: z20.object({
|
|
2737
|
+
...Common2,
|
|
2738
|
+
unit: z20.string().optional(),
|
|
2739
|
+
format: Format.optional(),
|
|
2740
|
+
decimals: z20.number().int().min(0).max(6).optional(),
|
|
2741
|
+
/** Target or plan: a number, or a path in the datasource result. Shown in the footer and used for the status chip. */
|
|
2742
|
+
target: NumberOrPath.optional(),
|
|
2743
|
+
/** Footer text; default "Target: ≥ 95%" from goodWhen, target and unit. Use "Plan: ${…}" for plans. */
|
|
2744
|
+
targetLabel: z20.string().optional(),
|
|
2745
|
+
/** Which direction is good: "up" (≥ target), "down" (≤ target) or "none" (no status, no colour). */
|
|
2746
|
+
goodWhen: z20.enum(["up", "down", "none"]).default("up"),
|
|
2747
|
+
/** Show the status badge (On track / Action needed) next to the target; it needs a target. */
|
|
2748
|
+
badge: z20.boolean().default(true),
|
|
2749
|
+
/** Badge texts. */
|
|
2750
|
+
statusLabels: z20.object({ good: z20.string().default("On track"), bad: z20.string().default("Action needed") }).strict().optional(),
|
|
2751
|
+
/** Shown as a red tag when `target` is set but has no value (e.g. "Target un-defined"). */
|
|
2752
|
+
targetMissing: z20.string().default("Target un-defined"),
|
|
2753
|
+
/** Text instead of the value when there is none, e.g. "No heats tapped yet today". */
|
|
2754
|
+
emptyText: z20.string().optional(),
|
|
2755
|
+
/** A data-quality note under the value, e.g. "2 heats without kWh reading". */
|
|
2756
|
+
note: z20.string().optional(),
|
|
2757
|
+
/** Previous value: a number, a path, or { path, label } — shows ▲/▼ with the change. */
|
|
2758
|
+
compare: z20.union([
|
|
2759
|
+
z20.number(),
|
|
2760
|
+
z20.object({ path: z20.string().optional(), value: z20.unknown().optional(), label: z20.string().optional() }).strict()
|
|
2761
|
+
]).optional(),
|
|
2762
|
+
/** Expected range; outside it the value turns red. */
|
|
2763
|
+
band: z20.object({ low: NumberOrPath, high: NumberOrPath }).strict().optional(),
|
|
2764
|
+
/** Progress towards a target; `cap` limits the bar. */
|
|
2765
|
+
progress: z20.object({ target: NumberOrPath, cap: z20.number().optional() }).strict().optional(),
|
|
2766
|
+
sublabel: z20.string().optional(),
|
|
2767
|
+
size: z20.enum(["normal", "hero"]).default("normal"),
|
|
2768
|
+
tone: z20.enum(["good", "warn", "bad", "neutral", "info"]).optional()
|
|
2769
|
+
}).strict()
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
// src/widgets/schemas/Sparkline.ts
|
|
2773
|
+
import { z as z21 } from "zod";
|
|
2774
|
+
var SparklineContract = {
|
|
2775
|
+
kind: "Sparkline",
|
|
2776
|
+
version: 1,
|
|
2777
|
+
schema: z21.object({ ...Common2, x: z21.string().optional(), y: z21.string(), area: z21.boolean().default(true) }).strict()
|
|
2778
|
+
};
|
|
2779
|
+
|
|
2780
|
+
// src/widgets/schemas/StageTracker.ts
|
|
2781
|
+
import { z as z22 } from "zod";
|
|
2782
|
+
var StageTrackerContract = {
|
|
2783
|
+
kind: "StageTracker",
|
|
2784
|
+
version: 1,
|
|
2785
|
+
schema: z22.object({
|
|
2786
|
+
...Common2,
|
|
2787
|
+
stages: z22.array(z22.string()).min(1),
|
|
2788
|
+
/** Field with the current stage (name or index); default "stage". */
|
|
2789
|
+
current: z22.string().default("stage")
|
|
2790
|
+
}).strict()
|
|
2791
|
+
};
|
|
2792
|
+
|
|
2793
|
+
// src/widgets/schemas/StateTimeline.ts
|
|
2794
|
+
import { z as z23 } from "zod";
|
|
2795
|
+
var StateTimelineContract = {
|
|
2796
|
+
kind: "StateTimeline",
|
|
2797
|
+
version: 1,
|
|
2798
|
+
schema: z23.object({
|
|
2799
|
+
...Common2,
|
|
2800
|
+
time: z23.string().default("ts"),
|
|
2801
|
+
value: z23.string().default("value"),
|
|
2802
|
+
/** Raw value → state, e.g. { "RUN": "running" }. */
|
|
2803
|
+
stateMap: z23.record(z23.string()).optional(),
|
|
2804
|
+
/** State → tone. */
|
|
2805
|
+
tones: z23.record(z23.enum(["good", "warn", "bad", "neutral", "info"])).optional(),
|
|
2806
|
+
/** Window ending now, e.g. "8h". Without it the data's own span is used. */
|
|
2807
|
+
window: z23.string().optional(),
|
|
2808
|
+
/** One lane per value of this field. */
|
|
2809
|
+
rows: z23.string().optional(),
|
|
2810
|
+
endLabel: z23.string().optional()
|
|
2811
|
+
}).strict()
|
|
2812
|
+
};
|
|
2813
|
+
|
|
2814
|
+
// src/widgets/schemas/Status.ts
|
|
2815
|
+
import { z as z24 } from "zod";
|
|
2816
|
+
var StatusContract = {
|
|
2817
|
+
kind: "Status",
|
|
2818
|
+
version: 1,
|
|
2819
|
+
small: true,
|
|
2820
|
+
schema: z24.object({
|
|
2821
|
+
...Common2,
|
|
2822
|
+
/** Field shown under the state, e.g. the running program. */
|
|
2823
|
+
label: z24.string().optional(),
|
|
2824
|
+
/** Field holding the state. */
|
|
2825
|
+
state: z24.string().default("state"),
|
|
2826
|
+
stateMap: ToneMap.optional(),
|
|
2827
|
+
/** Text per state, e.g. { "running": "Running" }. */
|
|
2828
|
+
labels: z24.record(z24.string()).optional(),
|
|
2829
|
+
/** Fixed text instead of a state from the data, e.g. "Live" or "Beta". */
|
|
2830
|
+
text: z24.string().optional(),
|
|
2831
|
+
/** Colour of fixed text (and of states missing from stateMap). */
|
|
2832
|
+
tone: z24.enum(["good", "warn", "bad", "neutral", "info"]).optional()
|
|
2833
|
+
}).strict()
|
|
2834
|
+
};
|
|
2835
|
+
|
|
2836
|
+
// src/widgets/schemas/Table.ts
|
|
2837
|
+
import { z as z25 } from "zod";
|
|
2838
|
+
var Column = z25.object({
|
|
2839
|
+
key: z25.string(),
|
|
2840
|
+
label: z25.string().optional(),
|
|
2841
|
+
type: z25.enum(["text", "number", "badge", "link", "image", "progress", "sparkline", "list", "template"]).optional(),
|
|
2842
|
+
format: Format.optional(),
|
|
2843
|
+
decimals: z25.number().int().min(0).max(6).optional(),
|
|
2844
|
+
prefix: z25.string().optional(),
|
|
2845
|
+
suffix: z25.string().optional(),
|
|
2846
|
+
align: z25.enum(["left", "center", "right"]).optional(),
|
|
2847
|
+
/** Shown when the value is empty. */
|
|
2848
|
+
empty: z25.string().optional(),
|
|
2849
|
+
/** Text from the row, e.g. "${row.hour_start} – ${row.hour_end}". */
|
|
2850
|
+
template: z25.string().optional(),
|
|
2851
|
+
/** One line per item of an array value, e.g. "${item.part}". */
|
|
2852
|
+
list: z25.string().optional(),
|
|
2853
|
+
/** Badge: value → tone. */
|
|
2854
|
+
map: ToneMap.optional(),
|
|
2855
|
+
/** Badge tone as an expression over the row, e.g. "row.over_min > 0 ? 'bad' : 'good'". */
|
|
2856
|
+
tone: z25.string().optional(),
|
|
2857
|
+
/** Link: URL template using ${row.*}. */
|
|
2858
|
+
href: z25.string().optional(),
|
|
2859
|
+
/** Progress: the value that means 100%. */
|
|
2860
|
+
max: z25.number().optional(),
|
|
2861
|
+
width: z25.union([z25.number(), z25.string()]).optional(),
|
|
2862
|
+
sortable: z25.boolean().optional(),
|
|
2863
|
+
/** A filter under the header: free text, a choice of values, or a minimum number. */
|
|
2864
|
+
filter: z25.enum(["text", "select", "min"]).optional(),
|
|
2865
|
+
/** Choices for a select filter; default: the values in the data (browser mode). */
|
|
2866
|
+
filterOptions: z25.array(z25.string()).optional()
|
|
2867
|
+
}).strict();
|
|
2868
|
+
var Agg = z25.enum(["sum", "avg", "min", "max", "count"]);
|
|
2869
|
+
var schema = z25.object({
|
|
2870
|
+
...Common2,
|
|
2871
|
+
columns: z25.array(Column).optional(),
|
|
2872
|
+
/** Columns from the data: a path in the datasource result to a list of { key, label }. */
|
|
2873
|
+
columnsFrom: z25.object({
|
|
2874
|
+
path: z25.string(),
|
|
2875
|
+
key: z25.string().default("key"),
|
|
2876
|
+
label: z25.string().default("label"),
|
|
2877
|
+
type: Column.shape.type,
|
|
2878
|
+
format: Format.optional()
|
|
2879
|
+
}).strict().optional(),
|
|
2880
|
+
totals: z25.object({ label: z25.string().default("Total"), columns: z25.record(Agg) }).strict().optional(),
|
|
2881
|
+
pivot: z25.object({ rows: z25.union([z25.string(), z25.array(z25.string())]), cols: z25.string(), value: z25.string() }).strict().optional(),
|
|
2882
|
+
/**
|
|
2883
|
+
* Pages. "client": the table slices the rows it has. "server": the table writes page, pageSize and offset to
|
|
2884
|
+
* `panels.<id>.ui` for the datasource's query (e.g. "page": "${panels.heats.ui.page ?? 1}") and reads the
|
|
2885
|
+
* total at `totalPath` in the datasource result.
|
|
2886
|
+
*/
|
|
2887
|
+
pagination: z25.object({
|
|
2888
|
+
enabled: z25.boolean().default(true),
|
|
2889
|
+
mode: z25.enum(["client", "server"]).default("client"),
|
|
2890
|
+
pageSize: z25.number().int().min(1).max(500).default(20),
|
|
2891
|
+
pageSizes: z25.array(z25.number().int().min(1)).default([10, 20, 50, 100]),
|
|
2892
|
+
totalPath: z25.string().optional()
|
|
2893
|
+
}).strict().optional(),
|
|
2894
|
+
/** A search box. "server": writes `ui.search` (debounced) for the datasource; "client": matches row text. */
|
|
2895
|
+
search: z25.union([
|
|
2896
|
+
z25.boolean(),
|
|
2897
|
+
z25.object({
|
|
2898
|
+
enabled: z25.boolean().default(true),
|
|
2899
|
+
mode: z25.enum(["client", "server"]).default("client"),
|
|
2900
|
+
placeholder: z25.string().optional(),
|
|
2901
|
+
/** Fields to search in (client); default every field. */
|
|
2902
|
+
fields: z25.array(z25.string()).optional()
|
|
2903
|
+
}).strict()
|
|
2904
|
+
]).optional(),
|
|
2905
|
+
/** Click a header to sort. "server": writes `ui.sortKey`, `ui.sortOrder` and `ui.ordering` ("-field" for descending). */
|
|
2906
|
+
sorting: z25.object({
|
|
2907
|
+
enabled: z25.boolean().default(true),
|
|
2908
|
+
mode: z25.enum(["client", "server"]).default("client"),
|
|
2909
|
+
default: z25.object({ key: z25.string(), order: z25.enum(["asc", "desc"]).default("asc") }).strict().optional()
|
|
2910
|
+
}).strict().optional(),
|
|
2911
|
+
/** Per-column filters (columns with `filter`). "server": writes `ui.filters` ({ column: value }). */
|
|
2912
|
+
filtering: z25.object({ enabled: z25.boolean().default(true), mode: z25.enum(["client", "server"]).default("client") }).strict().optional(),
|
|
2913
|
+
sticky: z25.boolean().default(true),
|
|
2914
|
+
rowKey: z25.string().optional(),
|
|
2915
|
+
/** Rows shown in grey, e.g. "row.pending == 0" (nothing to act on). */
|
|
2916
|
+
rowMutedWhen: z25.string().optional(),
|
|
2917
|
+
/** Render only visible rows; for long tables. */
|
|
2918
|
+
virtual: z25.boolean().default(false),
|
|
2919
|
+
density: z25.enum(["compact", "comfortable"]).optional()
|
|
2920
|
+
}).strict();
|
|
2921
|
+
var TableContract = {
|
|
2922
|
+
kind: "Table",
|
|
2923
|
+
version: 1,
|
|
2924
|
+
schema
|
|
2925
|
+
};
|
|
2926
|
+
|
|
2927
|
+
// src/widgets/schemas/Tiles.ts
|
|
2928
|
+
import { z as z26 } from "zod";
|
|
2929
|
+
var ToneOrMuted = z26.enum(["good", "warn", "bad", "neutral", "info", "muted"]);
|
|
2930
|
+
var TilesContract = {
|
|
2931
|
+
kind: "Tiles",
|
|
2932
|
+
version: 1,
|
|
2933
|
+
schema: z26.object({
|
|
2934
|
+
...Common2,
|
|
2935
|
+
label: z26.string(),
|
|
2936
|
+
value: z26.string(),
|
|
2937
|
+
/** Small text under the number: plain ("heats") or per row ("of ${row.total} pending"). */
|
|
2938
|
+
caption: z26.string().optional(),
|
|
2939
|
+
/** Optional status dot per tile. */
|
|
2940
|
+
status: z26.string().optional(),
|
|
2941
|
+
statusMap: ToneMap.optional(),
|
|
2942
|
+
/** Number colour by sign, e.g. { "positive": "bad", "zero": "muted" } (red if waiting, grey if 0). */
|
|
2943
|
+
valueTone: z26.object({ positive: ToneOrMuted.optional(), zero: ToneOrMuted.optional(), negative: ToneOrMuted.optional() }).strict().optional(),
|
|
2944
|
+
/** A badge field per tile, e.g. heats per furnace. */
|
|
2945
|
+
count: z26.string().optional(),
|
|
2946
|
+
format: Format.optional(),
|
|
2947
|
+
decimals: z26.number().int().min(0).max(6).optional(),
|
|
2948
|
+
unit: z26.string().optional(),
|
|
2949
|
+
/** Most tiles in one row; fewer when the card is narrow (see minTileWidth). */
|
|
2950
|
+
columns: z26.number().int().min(1).max(12).optional(),
|
|
2951
|
+
/** Narrowest a tile gets, in px, before the row wraps (or scrolls when wrap is off). */
|
|
2952
|
+
minTileWidth: z26.number().int().min(60).max(600).default(128),
|
|
2953
|
+
/** Wrap onto new lines when the row is full; off = one row that scrolls sideways. */
|
|
2954
|
+
wrap: z26.boolean().default(true),
|
|
2955
|
+
selectable: z26.boolean().default(false),
|
|
2956
|
+
/** The selected tile's label value, e.g. "${filters.stage}". */
|
|
2957
|
+
selected: z26.unknown().optional()
|
|
2958
|
+
}).strict()
|
|
2959
|
+
};
|
|
2960
|
+
|
|
2961
|
+
// src/widgets/schemas/atoms.ts
|
|
2962
|
+
import { z as z27 } from "zod";
|
|
2963
|
+
var Atom = {
|
|
2964
|
+
data: z27.unknown().optional(),
|
|
2965
|
+
options: z27.record(z27.unknown()).optional()
|
|
2966
|
+
};
|
|
2967
|
+
var ICONS = {
|
|
2968
|
+
bolt: "M13 2 4 14h7l-1 8 9-12h-7z",
|
|
2969
|
+
fire: "M12 3c1 4 5 5 5 10a5 5 0 0 1-10 0c0-3 2-4 2-7 2 1 3 3 3 5 1-2 1-5 0-8z",
|
|
2970
|
+
factory: "M3 21V10l5 3V10l5 3V6l8 4v11z",
|
|
2971
|
+
clock: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18zM12 7v5l3 2",
|
|
2972
|
+
check: "M20 6 9 17l-5-5",
|
|
2973
|
+
alert: "M12 3 2 20h20zM12 10v4M12 17h.01",
|
|
2974
|
+
up: "M7 14l5-5 5 5",
|
|
2975
|
+
down: "M7 10l5 5 5-5",
|
|
2976
|
+
gauge: "M4 18a8 8 0 1 1 16 0M12 18l4-6",
|
|
2977
|
+
box: "M3 7l9-4 9 4v10l-9 4-9-4zM3 7l9 4 9-4M12 11v10",
|
|
2978
|
+
user: "M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0",
|
|
2979
|
+
money: "M3 7h18v10H3zM12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"
|
|
2980
|
+
};
|
|
2981
|
+
var ICON_NAMES = Object.keys(ICONS);
|
|
2982
|
+
var Size = z27.enum(["xs", "sm", "md", "lg", "xl"]);
|
|
2983
|
+
var ToneName = z27.enum(["default", "subtle", "primary", "good", "warn", "bad", "info"]);
|
|
2984
|
+
var TextContract = {
|
|
2985
|
+
kind: "Text",
|
|
2986
|
+
version: 1,
|
|
2987
|
+
small: true,
|
|
2988
|
+
schema: z27.object({
|
|
2989
|
+
...Atom,
|
|
2990
|
+
/** The words; `{value}` is replaced by the bound value. Also takes ${…} templates. */
|
|
2991
|
+
text: z27.string().default("Label"),
|
|
2992
|
+
/** Field of the data shown as {value}. */
|
|
2993
|
+
field: z27.string().optional(),
|
|
2994
|
+
size: Size.default("sm"),
|
|
2995
|
+
weight: z27.enum(["regular", "medium", "bold"]).default("regular"),
|
|
2996
|
+
color: ToneName.default("subtle"),
|
|
2997
|
+
align: z27.enum(["left", "center", "right"]).default("left"),
|
|
2998
|
+
/** Text when there is no value. */
|
|
2999
|
+
emptyText: z27.string().optional()
|
|
3000
|
+
}).strict()
|
|
3001
|
+
};
|
|
3002
|
+
var ValueContract = {
|
|
3003
|
+
kind: "Value",
|
|
3004
|
+
version: 1,
|
|
3005
|
+
small: true,
|
|
3006
|
+
schema: z27.object({
|
|
3007
|
+
...Atom,
|
|
3008
|
+
/** Field of the data to show; leave empty when the data is the number itself. */
|
|
3009
|
+
field: z27.string().optional(),
|
|
3010
|
+
format: Format.optional(),
|
|
3011
|
+
decimals: z27.number().int().min(0).max(6).optional(),
|
|
3012
|
+
unit: z27.string().optional(),
|
|
3013
|
+
prefix: z27.string().optional(),
|
|
3014
|
+
size: Size.default("lg"),
|
|
3015
|
+
/** Colour the number: fixed, or good/bad against the target. */
|
|
3016
|
+
color: z27.enum(["default", "primary", "byTarget", "good", "warn", "bad"]).default("default"),
|
|
3017
|
+
/** A number, or a field of the data. */
|
|
3018
|
+
target: z27.union([z27.number(), z27.string()]).optional(),
|
|
3019
|
+
goodWhen: z27.enum(["up", "down"]).default("up"),
|
|
3020
|
+
countUp: z27.boolean().default(true)
|
|
3021
|
+
}).strict()
|
|
3022
|
+
};
|
|
3023
|
+
var ProgressContract = {
|
|
3024
|
+
kind: "Progress",
|
|
3025
|
+
version: 1,
|
|
3026
|
+
small: true,
|
|
3027
|
+
schema: z27.object({
|
|
3028
|
+
...Atom,
|
|
3029
|
+
field: z27.string().optional(),
|
|
3030
|
+
/** The value that means full: a number or a field of the data. */
|
|
3031
|
+
max: z27.union([z27.number(), z27.string()]).default(100),
|
|
3032
|
+
color: z27.enum(["primary", "good", "warn", "bad", "info", "byTarget"]).default("primary"),
|
|
3033
|
+
/** With byTarget: green from this share of max (0–100). */
|
|
3034
|
+
goodFrom: z27.number().min(0).max(100).default(100),
|
|
3035
|
+
showPercent: z27.boolean().default(false),
|
|
3036
|
+
thickness: z27.number().int().min(2).max(24).default(6)
|
|
3037
|
+
}).strict()
|
|
3038
|
+
};
|
|
3039
|
+
var IconContract = {
|
|
3040
|
+
kind: "Icon",
|
|
3041
|
+
version: 1,
|
|
3042
|
+
small: true,
|
|
3043
|
+
schema: z27.object({
|
|
3044
|
+
...Atom,
|
|
3045
|
+
icon: z27.enum(ICON_NAMES).default("bolt"),
|
|
3046
|
+
size: z27.number().int().min(12).max(96).default(24),
|
|
3047
|
+
color: ToneName.default("primary"),
|
|
3048
|
+
/** A soft round background behind the icon. */
|
|
3049
|
+
background: z27.boolean().default(true)
|
|
3050
|
+
}).strict()
|
|
3051
|
+
};
|
|
3052
|
+
var DividerContract = {
|
|
3053
|
+
kind: "Divider",
|
|
3054
|
+
version: 1,
|
|
3055
|
+
small: true,
|
|
3056
|
+
schema: z27.object({
|
|
3057
|
+
...Atom,
|
|
3058
|
+
direction: z27.enum(["horizontal", "vertical"]).default("horizontal"),
|
|
3059
|
+
dashed: z27.boolean().default(false)
|
|
3060
|
+
}).strict()
|
|
3061
|
+
};
|
|
3062
|
+
|
|
3063
|
+
// src/widgets/schemas/charts.ts
|
|
3064
|
+
import { z as z28 } from "zod";
|
|
3065
|
+
var Y = z28.union([z28.string(), z28.array(z28.string()).min(1)]);
|
|
3066
|
+
var cartesianProps = {
|
|
3067
|
+
...Common2,
|
|
3068
|
+
x: z28.string(),
|
|
3069
|
+
y: Y.optional(),
|
|
3070
|
+
seriesBy: z28.string().optional(),
|
|
3071
|
+
labels: z28.record(z28.string()).optional(),
|
|
3072
|
+
unit: z28.string().optional(),
|
|
3073
|
+
format: Format.optional(),
|
|
3074
|
+
decimals: z28.number().int().min(0).max(6).optional(),
|
|
3075
|
+
/** A number, or a path in the datasource result. */
|
|
3076
|
+
target: z28.union([z28.number(), z28.string()]).optional(),
|
|
3077
|
+
targetLabel: z28.string().optional()
|
|
3078
|
+
};
|
|
3079
|
+
var BarChartContract = {
|
|
3080
|
+
kind: "BarChart",
|
|
3081
|
+
version: 1,
|
|
3082
|
+
schema: z28.object({
|
|
3083
|
+
...cartesianProps,
|
|
3084
|
+
stacked: z28.boolean().default(false),
|
|
3085
|
+
normalized: z28.boolean().default(false),
|
|
3086
|
+
horizontal: z28.boolean().default(false),
|
|
3087
|
+
/** Floating bars between two fields. */
|
|
3088
|
+
range: z28.object({ low: z28.string(), high: z28.string() }).strict().optional(),
|
|
3089
|
+
/** Show this many bars, scroll for the rest. */
|
|
3090
|
+
pageSize: z28.number().int().min(1).optional(),
|
|
3091
|
+
/** "average": green at or above the average, red below (single series, 3+ full buckets). */
|
|
3092
|
+
colorBy: z28.enum(["average", "none"]).default("none"),
|
|
3093
|
+
/** Field marking a partial bucket (today so far): pale bar, "so far", left out of the average. */
|
|
3094
|
+
partial: z28.string().optional(),
|
|
3095
|
+
/** Values on the bars; "auto" shows them for 7 bars or fewer. */
|
|
3096
|
+
valueLabels: z28.union([z28.literal("auto"), z28.boolean()]).default("auto"),
|
|
3097
|
+
/** Dashed average line, with its legend text (`${avg}` = the average). */
|
|
3098
|
+
averageLine: z28.union([z28.boolean(), z28.string()]).optional(),
|
|
3099
|
+
/** Legend texts for colorBy average. */
|
|
3100
|
+
legendLabels: z28.object({ above: z28.string(), below: z28.string() }).strict().optional()
|
|
3101
|
+
}).strict()
|
|
3102
|
+
};
|
|
3103
|
+
var LineChartContract = {
|
|
3104
|
+
kind: "LineChart",
|
|
3105
|
+
version: 1,
|
|
3106
|
+
schema: z28.object({
|
|
3107
|
+
...cartesianProps,
|
|
3108
|
+
area: z28.boolean().default(false),
|
|
3109
|
+
gradient: z28.boolean().default(false),
|
|
3110
|
+
smooth: z28.boolean().default(false)
|
|
3111
|
+
}).strict()
|
|
3112
|
+
};
|
|
3113
|
+
var PieChartContract = {
|
|
3114
|
+
kind: "PieChart",
|
|
3115
|
+
version: 1,
|
|
3116
|
+
schema: z28.object({
|
|
3117
|
+
...Common2,
|
|
3118
|
+
label: z28.string(),
|
|
3119
|
+
value: z28.string(),
|
|
3120
|
+
donut: z28.boolean().default(false),
|
|
3121
|
+
unit: z28.string().optional(),
|
|
3122
|
+
format: Format.optional(),
|
|
3123
|
+
decimals: z28.number().int().optional()
|
|
3124
|
+
}).strict()
|
|
3125
|
+
};
|
|
3126
|
+
var ScatterContract = {
|
|
3127
|
+
kind: "Scatter",
|
|
3128
|
+
version: 1,
|
|
3129
|
+
schema: z28.object({
|
|
3130
|
+
...Common2,
|
|
3131
|
+
x: z28.string(),
|
|
3132
|
+
y: z28.string(),
|
|
3133
|
+
size: z28.string().optional(),
|
|
3134
|
+
series: z28.string().optional(),
|
|
3135
|
+
xLabel: z28.string().optional(),
|
|
3136
|
+
yLabel: z28.string().optional()
|
|
3137
|
+
}).strict()
|
|
3138
|
+
};
|
|
3139
|
+
var Band = z28.object({ to: z28.number(), tone: z28.enum(["good", "warn", "bad", "neutral", "info"]) }).strict();
|
|
3140
|
+
var GaugeContract = {
|
|
3141
|
+
kind: "Gauge",
|
|
3142
|
+
version: 1,
|
|
3143
|
+
schema: z28.object({
|
|
3144
|
+
...Common2,
|
|
3145
|
+
min: z28.number().default(0),
|
|
3146
|
+
max: z28.number().default(100),
|
|
3147
|
+
bands: z28.array(Band).optional(),
|
|
3148
|
+
shape: z28.enum(["arc", "circle"]).default("arc"),
|
|
3149
|
+
unit: z28.string().optional(),
|
|
3150
|
+
format: Format.optional(),
|
|
3151
|
+
decimals: z28.number().int().optional()
|
|
3152
|
+
}).strict()
|
|
3153
|
+
};
|
|
3154
|
+
var MatrixChartContract = {
|
|
3155
|
+
kind: "MatrixChart",
|
|
3156
|
+
version: 1,
|
|
3157
|
+
schema: z28.object({
|
|
3158
|
+
...Common2,
|
|
3159
|
+
rows: z28.string(),
|
|
3160
|
+
cols: z28.string(),
|
|
3161
|
+
value: z28.string(),
|
|
3162
|
+
unit: z28.string().optional(),
|
|
3163
|
+
format: Format.optional(),
|
|
3164
|
+
decimals: z28.number().int().optional()
|
|
3165
|
+
}).strict()
|
|
3166
|
+
};
|
|
3167
|
+
|
|
3168
|
+
// src/widgets/schemas/layout.ts
|
|
3169
|
+
import { z as z29 } from "zod";
|
|
3170
|
+
var RowContract = {
|
|
3171
|
+
...ContainerContract,
|
|
3172
|
+
kind: "Row"
|
|
3173
|
+
};
|
|
3174
|
+
var ColumnContract = {
|
|
3175
|
+
...ContainerContract,
|
|
3176
|
+
kind: "Column"
|
|
3177
|
+
};
|
|
3178
|
+
var GAP = z29.number().int().min(0).max(64).default(8);
|
|
3179
|
+
var CardContract = {
|
|
3180
|
+
kind: "Card",
|
|
3181
|
+
version: 1,
|
|
3182
|
+
slots: { body: { label: "Body" } },
|
|
3183
|
+
schema: z29.object({
|
|
3184
|
+
...Common2,
|
|
3185
|
+
direction: z29.enum(["column", "row"]).default("column"),
|
|
3186
|
+
gap: GAP,
|
|
3187
|
+
align: z29.enum(["stretch", "start", "center", "end"]).default("stretch")
|
|
3188
|
+
}).strict()
|
|
3189
|
+
};
|
|
3190
|
+
var TabsContract = {
|
|
3191
|
+
kind: "Tabs",
|
|
3192
|
+
version: 1,
|
|
3193
|
+
openSlots: true,
|
|
3194
|
+
schema: z29.object({
|
|
3195
|
+
...Common2,
|
|
3196
|
+
tabs: z29.array(z29.object({ key: z29.string().regex(/^[A-Za-z][\w-]*$/), label: z29.string() }).strict()).min(1).default([
|
|
3197
|
+
{ key: "tab1", label: "Tab 1" },
|
|
3198
|
+
{ key: "tab2", label: "Tab 2" }
|
|
3199
|
+
]),
|
|
3200
|
+
/** The tab open first. */
|
|
3201
|
+
initial: z29.string().optional()
|
|
3202
|
+
}).strict()
|
|
3203
|
+
};
|
|
3204
|
+
var RepeaterContract = {
|
|
3205
|
+
kind: "Repeater",
|
|
3206
|
+
version: 1,
|
|
3207
|
+
slots: { item: { label: "Each item" } },
|
|
3208
|
+
schema: z29.object({
|
|
3209
|
+
...Common2,
|
|
3210
|
+
layout: z29.enum(["grid", "list"]).default("grid"),
|
|
3211
|
+
/** Grid: the narrowest an item gets before the row wraps, in px. */
|
|
3212
|
+
minItemWidth: z29.number().int().min(60).max(1200).default(220),
|
|
3213
|
+
gap: z29.number().int().min(0).max(64).default(12),
|
|
3214
|
+
/** Show at most this many rows. */
|
|
3215
|
+
limit: z29.number().int().min(1).optional(),
|
|
3216
|
+
emptyText: z29.string().default("Nothing to show")
|
|
3217
|
+
}).strict()
|
|
3218
|
+
};
|
|
3219
|
+
|
|
3220
|
+
// src/widgets/schemas/index.ts
|
|
3221
|
+
var builtInWidgetContracts = [
|
|
3222
|
+
KpiContract,
|
|
3223
|
+
TilesContract,
|
|
3224
|
+
BarChartContract,
|
|
3225
|
+
LineChartContract,
|
|
3226
|
+
PieChartContract,
|
|
3227
|
+
ScatterContract,
|
|
3228
|
+
GaugeContract,
|
|
3229
|
+
BreakdownContract,
|
|
3230
|
+
MatrixChartContract,
|
|
3231
|
+
TableContract,
|
|
3232
|
+
StageTrackerContract,
|
|
3233
|
+
StateTimelineContract,
|
|
3234
|
+
StatusContract,
|
|
3235
|
+
CardGridContract,
|
|
3236
|
+
ImageMapContract,
|
|
3237
|
+
SparklineContract,
|
|
3238
|
+
ContentContract,
|
|
3239
|
+
ImageContract,
|
|
3240
|
+
ContainerContract,
|
|
3241
|
+
RowContract,
|
|
3242
|
+
ColumnContract,
|
|
3243
|
+
CardContract,
|
|
3244
|
+
TabsContract,
|
|
3245
|
+
RepeaterContract,
|
|
3246
|
+
FilterContract,
|
|
3247
|
+
TextContract,
|
|
3248
|
+
ValueContract,
|
|
3249
|
+
ProgressContract,
|
|
3250
|
+
IconContract,
|
|
3251
|
+
DividerContract
|
|
3252
|
+
];
|
|
3253
|
+
var builtInWidgetChecks = contractChecks(builtInWidgetContracts);
|
|
3254
|
+
|
|
3255
|
+
export {
|
|
3256
|
+
ExpressionError,
|
|
3257
|
+
parse,
|
|
3258
|
+
compile,
|
|
3259
|
+
scope,
|
|
3260
|
+
evaluate,
|
|
3261
|
+
evaluateSafe,
|
|
3262
|
+
translator,
|
|
3263
|
+
parseDuration,
|
|
3264
|
+
plantDayStart,
|
|
3265
|
+
plantDate,
|
|
3266
|
+
createHelpers,
|
|
3267
|
+
placeholders,
|
|
3268
|
+
expressionReferences,
|
|
3269
|
+
templateReferences,
|
|
3270
|
+
collectReferences,
|
|
3271
|
+
interpolate,
|
|
3272
|
+
resolve,
|
|
3273
|
+
interpolateUrl,
|
|
3274
|
+
resolveRequest,
|
|
3275
|
+
DataError,
|
|
3276
|
+
mergeConnections,
|
|
3277
|
+
resolveBaseUrl,
|
|
3278
|
+
buildUrl,
|
|
3279
|
+
buildRequestUrl,
|
|
3280
|
+
graphqlData,
|
|
3281
|
+
createHttpClient,
|
|
3282
|
+
Id,
|
|
3283
|
+
Duration,
|
|
3284
|
+
Template,
|
|
3285
|
+
Expression,
|
|
3286
|
+
Callback,
|
|
3287
|
+
isCallbackSource,
|
|
3288
|
+
JsonValue,
|
|
3289
|
+
StatusTone,
|
|
3290
|
+
FnProp,
|
|
3291
|
+
isSafeUrl,
|
|
3292
|
+
safeLink,
|
|
3293
|
+
ActionRef,
|
|
3294
|
+
ACTION_KINDS,
|
|
3295
|
+
ACTION_SCHEMAS,
|
|
3296
|
+
Action,
|
|
3297
|
+
Handler,
|
|
3298
|
+
EventHandler,
|
|
3299
|
+
EventMap,
|
|
3300
|
+
NamedAction,
|
|
3301
|
+
TokenSource,
|
|
3302
|
+
Auth,
|
|
3303
|
+
Connection,
|
|
3304
|
+
TransformStep,
|
|
3305
|
+
BUILT_IN_DATASOURCE_TYPES,
|
|
3306
|
+
Datasource,
|
|
3307
|
+
LayoutItem,
|
|
3308
|
+
BREAKPOINTS,
|
|
3309
|
+
Layout,
|
|
3310
|
+
Grid,
|
|
3311
|
+
DATE_PRESETS,
|
|
3312
|
+
VARIABLE_KINDS,
|
|
3313
|
+
Variable,
|
|
3314
|
+
PanelControl,
|
|
3315
|
+
Drill,
|
|
3316
|
+
DataBinding,
|
|
3317
|
+
Panel,
|
|
3318
|
+
Modal,
|
|
3319
|
+
API_VERSION,
|
|
3320
|
+
SCHEMA_URL,
|
|
3321
|
+
RESERVED_STATE_KEYS,
|
|
3322
|
+
Display,
|
|
3323
|
+
Metadata,
|
|
3324
|
+
Requires,
|
|
3325
|
+
Spec,
|
|
3326
|
+
Dashboard,
|
|
3327
|
+
MigrationError,
|
|
3328
|
+
migrateDocument,
|
|
3329
|
+
RENDERER_VERSION,
|
|
3330
|
+
satisfies,
|
|
3331
|
+
validateDocument,
|
|
3332
|
+
loadDocument,
|
|
3333
|
+
dashboardJsonSchema,
|
|
3334
|
+
TransformError,
|
|
3335
|
+
applyTransform,
|
|
3336
|
+
createWidgetRegistry,
|
|
3337
|
+
checkWidget,
|
|
3338
|
+
widgetChecks,
|
|
3339
|
+
BreakdownContract,
|
|
3340
|
+
CardGridContract,
|
|
3341
|
+
ContainerContract,
|
|
3342
|
+
ContentContract,
|
|
3343
|
+
FilterContract,
|
|
3344
|
+
ImageContract,
|
|
3345
|
+
ImageMapContract,
|
|
3346
|
+
KpiContract,
|
|
3347
|
+
SparklineContract,
|
|
3348
|
+
StageTrackerContract,
|
|
3349
|
+
StateTimelineContract,
|
|
3350
|
+
StatusContract,
|
|
3351
|
+
TableContract,
|
|
3352
|
+
TilesContract,
|
|
3353
|
+
ICONS,
|
|
3354
|
+
TextContract,
|
|
3355
|
+
ValueContract,
|
|
3356
|
+
ProgressContract,
|
|
3357
|
+
IconContract,
|
|
3358
|
+
DividerContract,
|
|
3359
|
+
BarChartContract,
|
|
3360
|
+
LineChartContract,
|
|
3361
|
+
PieChartContract,
|
|
3362
|
+
ScatterContract,
|
|
3363
|
+
GaugeContract,
|
|
3364
|
+
MatrixChartContract,
|
|
3365
|
+
RowContract,
|
|
3366
|
+
ColumnContract,
|
|
3367
|
+
CardContract,
|
|
3368
|
+
TabsContract,
|
|
3369
|
+
RepeaterContract,
|
|
3370
|
+
builtInWidgetChecks
|
|
3371
|
+
};
|
|
3372
|
+
//# sourceMappingURL=chunk-ZUNMBDGH.js.map
|