@niscorp/prism 0.3.1 → 0.3.3
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 +37 -0
- package/DESIGN.md +18 -8
- package/DOCS.md +20 -7
- package/dist/agent.cjs +4 -4
- package/dist/agent.js +2 -2
- package/dist/{chunk-WKS4OCKN.js → chunk-OL4CCYWX.js} +213 -87
- package/dist/chunk-OL4CCYWX.js.map +1 -0
- package/dist/{chunk-6PD7M2F3.cjs → chunk-QUI2X5JB.cjs} +220 -86
- package/dist/chunk-QUI2X5JB.cjs.map +1 -0
- package/dist/{chunk-OWKINPR5.cjs → chunk-ROYHYYIL.cjs} +5 -5
- package/dist/{chunk-OWKINPR5.cjs.map → chunk-ROYHYYIL.cjs.map} +1 -1
- package/dist/{chunk-GK4CIKKT.js → chunk-VNGBVDUM.js} +3 -3
- package/dist/{chunk-GK4CIKKT.js.map → chunk-VNGBVDUM.js.map} +1 -1
- package/dist/index.cjs +541 -364
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +341 -164
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.cjs +2 -2
- package/dist/migrations/index.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-6PD7M2F3.cjs.map +0 -1
- package/dist/chunk-WKS4OCKN.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkROYHYYIL_cjs = require('./chunk-ROYHYYIL.cjs');
|
|
4
|
+
var chunkQUI2X5JB_cjs = require('./chunk-QUI2X5JB.cjs');
|
|
5
5
|
var strata = require('@niscorp/strata');
|
|
6
6
|
var dayjs = require('dayjs');
|
|
7
7
|
var utc = require('dayjs/plugin/utc.js');
|
|
@@ -29,7 +29,31 @@ var explainOne = (issue, prefix) => {
|
|
|
29
29
|
}
|
|
30
30
|
return bestDepth <= here.length ? [{ path: here, message: "Not a Prism node: no op matches, and it is not a plain value." }] : best;
|
|
31
31
|
};
|
|
32
|
-
var
|
|
32
|
+
var valueAt = (value, path) => path.reduce((at, key) => typeof at === "object" && at !== null ? Reflect.get(at, key) : void 0, value);
|
|
33
|
+
var opOf = (value, path) => {
|
|
34
|
+
const last = path[path.length - 1];
|
|
35
|
+
if (typeof last === "string" && last.startsWith("$") && chunkQUI2X5JB_cjs.formOf(last) === void 0) return void 0;
|
|
36
|
+
const here = valueAt(value, path);
|
|
37
|
+
if (typeof here === "object" && here !== null && !Array.isArray(here)) {
|
|
38
|
+
const ops = Object.keys(here).filter((key) => chunkQUI2X5JB_cjs.formOf(key) !== void 0);
|
|
39
|
+
if (ops.length === 1) return ops[0];
|
|
40
|
+
}
|
|
41
|
+
for (const back of [1, 2]) {
|
|
42
|
+
const i = path.length - back;
|
|
43
|
+
const key = path[i];
|
|
44
|
+
if (typeof key !== "string" || chunkQUI2X5JB_cjs.formOf(key) === void 0) continue;
|
|
45
|
+
const holder = valueAt(value, path.slice(0, i));
|
|
46
|
+
if (typeof holder === "object" && holder !== null && Object.keys(holder).length === 1) return key;
|
|
47
|
+
}
|
|
48
|
+
return void 0;
|
|
49
|
+
};
|
|
50
|
+
var withForm = (explained, value) => {
|
|
51
|
+
const op = opOf(value, explained.path);
|
|
52
|
+
const form = op === void 0 ? void 0 : chunkQUI2X5JB_cjs.formOf(op);
|
|
53
|
+
return form === void 0 ? explained : { ...explained, message: `${explained.message.replace(/\.$/, "")}. Form: ${form}` };
|
|
54
|
+
};
|
|
55
|
+
var explainIssues = (issues, value) => issues.flatMap((i) => explainOne(i, [])).map((explained) => withForm(explained, value));
|
|
56
|
+
var issuesText = (explained) => explained.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
|
|
33
57
|
|
|
34
58
|
// src/sugar/rewriters.ts
|
|
35
59
|
var rewriteSum = (node, recurse) => ({
|
|
@@ -156,24 +180,24 @@ var desugar = (node) => {
|
|
|
156
180
|
if (node === null || node === void 0) return node;
|
|
157
181
|
if (typeof node !== "object") return node;
|
|
158
182
|
if (Array.isArray(node)) return node.map(desugar);
|
|
159
|
-
if (
|
|
183
|
+
if (chunkQUI2X5JB_cjs.isWithNode(node)) {
|
|
160
184
|
const bindings = {};
|
|
161
185
|
for (const [name, expr] of Object.entries(node.$with.let)) bindings[name] = desugar(expr);
|
|
162
186
|
return { $with: { let: bindings, value: desugar(node.$with.value) } };
|
|
163
187
|
}
|
|
164
|
-
if (
|
|
165
|
-
if (
|
|
166
|
-
if (
|
|
167
|
-
if (
|
|
168
|
-
if (
|
|
169
|
-
if (
|
|
170
|
-
if (
|
|
171
|
-
if (
|
|
172
|
-
if (
|
|
173
|
-
if (
|
|
174
|
-
if (
|
|
175
|
-
if (
|
|
176
|
-
if (
|
|
188
|
+
if (chunkQUI2X5JB_cjs.isRenameKeysNode(node)) return { $renameKeys: { ...node.$renameKeys, from: desugar(node.$renameKeys.from) } };
|
|
189
|
+
if (chunkQUI2X5JB_cjs.isConstNode(node)) return node;
|
|
190
|
+
if (chunkQUI2X5JB_cjs.isSumNode(node)) return rewriteSum(node, desugar);
|
|
191
|
+
if (chunkQUI2X5JB_cjs.isAvgNode(node)) return rewriteAvg(node, desugar);
|
|
192
|
+
if (chunkQUI2X5JB_cjs.isCountNode(node)) return rewriteCount(node, desugar);
|
|
193
|
+
if (chunkQUI2X5JB_cjs.isMinNode(node)) return rewriteMin(node, desugar);
|
|
194
|
+
if (chunkQUI2X5JB_cjs.isMaxNode(node)) return rewriteMax(node, desugar);
|
|
195
|
+
if (chunkQUI2X5JB_cjs.isPluckNode(node)) return rewritePluck(node, desugar);
|
|
196
|
+
if (chunkQUI2X5JB_cjs.isTakeNode(node)) return rewriteTake(node, desugar);
|
|
197
|
+
if (chunkQUI2X5JB_cjs.isDropNode(node)) return rewriteDrop(node, desugar);
|
|
198
|
+
if (chunkQUI2X5JB_cjs.isMatchNode(node)) return rewriteMatch(node, desugar);
|
|
199
|
+
if (chunkQUI2X5JB_cjs.isFlatMapNode(node)) return rewriteFlatMap(node, desugar);
|
|
200
|
+
if (chunkQUI2X5JB_cjs.isJsonObject(node)) {
|
|
177
201
|
const result = {};
|
|
178
202
|
for (const [key, value] of Object.entries(node)) {
|
|
179
203
|
result[key] = desugar(value);
|
|
@@ -186,12 +210,14 @@ var desugar = (node) => {
|
|
|
186
210
|
// src/engine/budget.ts
|
|
187
211
|
var DEFAULT_LIMITS = { maxSteps: 1e6, maxStringLength: 1e6, maxValues: 1e6 };
|
|
188
212
|
var createBudget = (limits) => ({ limits: { ...DEFAULT_LIMITS, ...limits }, steps: 0, sizes: /* @__PURE__ */ new WeakMap() });
|
|
189
|
-
var refuse = (what, limit) => {
|
|
190
|
-
|
|
213
|
+
var refuse = (what, limit, node) => {
|
|
214
|
+
const message = `Evaluation stopped: ${what} (limit ${limit}).`;
|
|
215
|
+
if (typeof node === "object" && node !== null) return chunkQUI2X5JB_cjs.failAt(message, chunkQUI2X5JB_cjs.ErrorCode.BUDGET, { details: { limit } }, { node, form: false });
|
|
216
|
+
throw new chunkQUI2X5JB_cjs.PrismError(message, chunkQUI2X5JB_cjs.ErrorCode.BUDGET, { details: { limit } });
|
|
191
217
|
};
|
|
192
|
-
var spendStep = (budget) => {
|
|
218
|
+
var spendStep = (budget, node) => {
|
|
193
219
|
budget.steps += 1;
|
|
194
|
-
if (budget.steps > budget.limits.maxSteps) refuse("it evaluated too many nodes", budget.limits.maxSteps);
|
|
220
|
+
if (budget.steps > budget.limits.maxSteps) refuse("it evaluated too many nodes", budget.limits.maxSteps, node);
|
|
195
221
|
};
|
|
196
222
|
var sizeOf = (value, budget) => {
|
|
197
223
|
if (value === null || typeof value !== "object") return 1;
|
|
@@ -205,14 +231,14 @@ var sizeOf = (value, budget) => {
|
|
|
205
231
|
budget.sizes.set(value, size);
|
|
206
232
|
return size;
|
|
207
233
|
};
|
|
208
|
-
var measureString = (value, budget) => {
|
|
209
|
-
if (typeof value === "string" && value.length > budget.limits.maxStringLength) refuse(`a string of ${value.length} characters`, budget.limits.maxStringLength);
|
|
234
|
+
var measureString = (value, budget, node) => {
|
|
235
|
+
if (typeof value === "string" && value.length > budget.limits.maxStringLength) refuse(`a string of ${value.length} characters`, budget.limits.maxStringLength, node);
|
|
210
236
|
};
|
|
211
|
-
var measure = (value, budget) => {
|
|
237
|
+
var measure = (value, budget, node) => {
|
|
212
238
|
if (budget === void 0) return;
|
|
213
|
-
measureString(value, budget);
|
|
239
|
+
measureString(value, budget, node);
|
|
214
240
|
if (value !== null && typeof value === "object" && sizeOf(value, budget) > budget.limits.maxValues) {
|
|
215
|
-
refuse("a result
|
|
241
|
+
refuse("a result with too many values", budget.limits.maxValues, node);
|
|
216
242
|
}
|
|
217
243
|
};
|
|
218
244
|
|
|
@@ -221,10 +247,17 @@ var SEGMENTS_KEY = "__segments";
|
|
|
221
247
|
var isSegmentsArray = (value) => Array.isArray(value);
|
|
222
248
|
var opRef = (node, context, _evaluate) => {
|
|
223
249
|
const attached = Reflect.get(node, SEGMENTS_KEY);
|
|
224
|
-
const segments = isSegmentsArray(attached) ? attached :
|
|
225
|
-
const resolved =
|
|
226
|
-
if (resolved === void 0)
|
|
227
|
-
|
|
250
|
+
const segments = isSegmentsArray(attached) ? attached : chunkQUI2X5JB_cjs.parseJsonPathCached(node.$ref);
|
|
251
|
+
const resolved = chunkQUI2X5JB_cjs.getByPath(context.source, segments);
|
|
252
|
+
if (resolved === void 0) {
|
|
253
|
+
const steps = segments.map((s) => s.type === "key" ? s.key : s.index);
|
|
254
|
+
return chunkQUI2X5JB_cjs.failAt("Path not found.", chunkQUI2X5JB_cjs.ErrorCode.MISSING_PATH, { op: "$ref", path: node.$ref }, {
|
|
255
|
+
node,
|
|
256
|
+
op: "$ref",
|
|
257
|
+
form: false,
|
|
258
|
+
detail: () => `$ref ${JSON.stringify(node.$ref)} ${chunkQUI2X5JB_cjs.whereStopped(context.source, steps, (count) => chunkQUI2X5JB_cjs.jsonPathUpTo(segments, count))}`
|
|
259
|
+
});
|
|
260
|
+
}
|
|
228
261
|
return resolved;
|
|
229
262
|
};
|
|
230
263
|
var copyOf = (value) => {
|
|
@@ -237,33 +270,50 @@ var copyOf = (value) => {
|
|
|
237
270
|
var opConst = (node, context, _evaluate) => context.kept === true ? copyOf(node.$const) : node.$const;
|
|
238
271
|
var opVar = (node, context, _evaluate) => {
|
|
239
272
|
const value = context.vars[node.$var];
|
|
240
|
-
if (value === void 0)
|
|
241
|
-
|
|
273
|
+
if (value === void 0) {
|
|
274
|
+
const names = Object.keys(context.vars).filter((name) => !name.startsWith("__"));
|
|
275
|
+
const scope = names.length === 0 ? "No variable is in scope here." : `In scope: ${names.join(", ")}.`;
|
|
276
|
+
return chunkQUI2X5JB_cjs.failAt(`Variable not found: ${node.$var}. ${scope}`, chunkQUI2X5JB_cjs.ErrorCode.VAR_NOT_FOUND, { op: "$var", path: node.$var }, { node, op: "$var", form: false });
|
|
277
|
+
}
|
|
242
278
|
return value;
|
|
243
279
|
};
|
|
280
|
+
var getStopped = (node, root, count, context, evaluate2) => {
|
|
281
|
+
const unbudgeted = { ...context, budget: void 0 };
|
|
282
|
+
const steps = node.$get.path.slice(0, count).map((segment) => {
|
|
283
|
+
const evaluated = typeof segment === "object" && segment !== null ? evaluate2(segment, unbudgeted) : segment;
|
|
284
|
+
return typeof evaluated === "number" ? evaluated : String(evaluated);
|
|
285
|
+
});
|
|
286
|
+
return `$get.path ${JSON.stringify(steps)} ${chunkQUI2X5JB_cjs.whereStopped(root, steps, (upTo) => upTo === 0 ? "from" : JSON.stringify(steps.slice(0, upTo)), true)}`;
|
|
287
|
+
};
|
|
244
288
|
var opGet = (node, context, evaluate2) => {
|
|
245
289
|
const { from, path, fallback } = node.$get;
|
|
246
|
-
|
|
247
|
-
|
|
290
|
+
const root = evaluate2(from, context);
|
|
291
|
+
let current2 = root;
|
|
292
|
+
for (let i = 0; i < path.length; i++) {
|
|
293
|
+
const segment = path[i];
|
|
248
294
|
const evaluated = typeof segment === "object" && segment !== null ? evaluate2(segment, context) : segment;
|
|
249
295
|
if (typeof evaluated === "number") {
|
|
250
|
-
if (!
|
|
296
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(current2)) {
|
|
251
297
|
if (fallback !== void 0) return evaluate2(fallback, context);
|
|
252
|
-
|
|
298
|
+
return chunkQUI2X5JB_cjs.failAt(getStopped(node, root, i + 1, context, evaluate2), chunkQUI2X5JB_cjs.ErrorCode.TYPE, { op: "$get" }, { node, op: "$get", field: "path", form: true });
|
|
253
299
|
}
|
|
254
300
|
current2 = current2[evaluated];
|
|
255
301
|
} else {
|
|
256
302
|
const key = String(evaluated);
|
|
257
|
-
if (
|
|
303
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(current2) && chunkQUI2X5JB_cjs.INDEX_TEXT.test(key)) {
|
|
304
|
+
current2 = current2[Number(key)];
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(current2)) {
|
|
258
308
|
if (fallback !== void 0) return evaluate2(fallback, context);
|
|
259
|
-
|
|
309
|
+
return chunkQUI2X5JB_cjs.failAt(getStopped(node, root, i + 1, context, evaluate2), chunkQUI2X5JB_cjs.ErrorCode.TYPE, { op: "$get" }, { node, op: "$get", field: "path", form: true });
|
|
260
310
|
}
|
|
261
311
|
current2 = current2[key];
|
|
262
312
|
}
|
|
263
313
|
}
|
|
264
314
|
if (current2 === void 0) {
|
|
265
315
|
if (fallback !== void 0) return evaluate2(fallback, context);
|
|
266
|
-
|
|
316
|
+
return chunkQUI2X5JB_cjs.failAt("Path not found.", chunkQUI2X5JB_cjs.ErrorCode.MISSING_PATH, { op: "$get" }, { node, op: "$get", field: "path", form: true, detail: () => getStopped(node, root, path.length, context, evaluate2) });
|
|
267
317
|
}
|
|
268
318
|
return current2;
|
|
269
319
|
};
|
|
@@ -272,7 +322,7 @@ var opWith = (node, context, evaluate2) => {
|
|
|
272
322
|
const extendedVars = { ...context.vars };
|
|
273
323
|
for (const [name, expr] of Object.entries(declarations)) {
|
|
274
324
|
extendedVars[name] = evaluate2(expr, context);
|
|
275
|
-
measure(extendedVars[name] ?? null, context.budget);
|
|
325
|
+
measure(extendedVars[name] ?? null, context.budget, node);
|
|
276
326
|
}
|
|
277
327
|
return evaluate2(value, { ...context, vars: extendedVars });
|
|
278
328
|
};
|
|
@@ -295,15 +345,26 @@ var loopScope = (context) => {
|
|
|
295
345
|
return { scope: { ...context, vars }, vars };
|
|
296
346
|
};
|
|
297
347
|
|
|
348
|
+
// src/ops/refuse.ts
|
|
349
|
+
var writtenNote = (written) => chunkQUI2X5JB_cjs.isPlainObject(written) ? ` That object was written in the program as ${chunkQUI2X5JB_cjs.clip(JSON.stringify(written), 60)}, and an object without a "$" key builds an object; put the node itself there.` : "";
|
|
350
|
+
var TEXT_LIKE = "text, a number, true, false or null";
|
|
351
|
+
var isTextLike = (value) => value === null || typeof value !== "object";
|
|
352
|
+
var refuseType = ({ node, op, field, needs, got, written, contextOp }) => chunkQUI2X5JB_cjs.failAt(
|
|
353
|
+
`${field === void 0 ? op : `${op}.${field}`} needs ${needs}, but got ${chunkQUI2X5JB_cjs.describeValue(got)}.${writtenNote(written)}`,
|
|
354
|
+
chunkQUI2X5JB_cjs.ErrorCode.TYPE,
|
|
355
|
+
{ op: contextOp ?? op },
|
|
356
|
+
{ node, op, ...field === void 0 ? {} : { field }, form: true }
|
|
357
|
+
);
|
|
358
|
+
|
|
298
359
|
// src/ops/array.ops.ts
|
|
299
|
-
var requireArray = (value, op) => {
|
|
300
|
-
if (!
|
|
301
|
-
|
|
360
|
+
var requireArray = (value, node, op, field, written) => {
|
|
361
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(value))
|
|
362
|
+
return refuseType({ node, op, ...field === void 0 ? {} : { field }, needs: "a list", got: value, written, contextOp: field === void 0 ? op : `${op}.${field}` });
|
|
302
363
|
return value;
|
|
303
364
|
};
|
|
304
365
|
var opMap = (node, context, evaluate2) => {
|
|
305
366
|
const { over, as, body } = node.$map;
|
|
306
|
-
const input = requireArray(evaluate2(over, context), "$map
|
|
367
|
+
const input = requireArray(evaluate2(over, context), node, "$map", "over", over);
|
|
307
368
|
const result = [];
|
|
308
369
|
const { scope, vars } = loopScope(context);
|
|
309
370
|
for (const item of input) {
|
|
@@ -314,7 +375,7 @@ var opMap = (node, context, evaluate2) => {
|
|
|
314
375
|
};
|
|
315
376
|
var opFilter = (node, context, evaluate2) => {
|
|
316
377
|
const { over, as, when } = node.$filter;
|
|
317
|
-
const input = requireArray(evaluate2(over, context), "$filter
|
|
378
|
+
const input = requireArray(evaluate2(over, context), node, "$filter", "over", over);
|
|
318
379
|
const result = [];
|
|
319
380
|
const { scope, vars } = loopScope(context);
|
|
320
381
|
for (const item of input) {
|
|
@@ -326,14 +387,14 @@ var opFilter = (node, context, evaluate2) => {
|
|
|
326
387
|
};
|
|
327
388
|
var opReduce = (node, context, evaluate2) => {
|
|
328
389
|
const { over, as, acc: accName = "acc", init, body } = node.$reduce;
|
|
329
|
-
const input = requireArray(evaluate2(over, context), "$reduce
|
|
390
|
+
const input = requireArray(evaluate2(over, context), node, "$reduce", "over", over);
|
|
330
391
|
let accumulator = evaluate2(init, context);
|
|
331
392
|
const { scope, vars } = loopScope(context);
|
|
332
393
|
for (const item of input) {
|
|
333
394
|
vars[as] = item;
|
|
334
395
|
vars[accName] = accumulator;
|
|
335
396
|
accumulator = evaluate2(body, scope);
|
|
336
|
-
measure(accumulator, context.budget);
|
|
397
|
+
measure(accumulator, context.budget, node);
|
|
337
398
|
}
|
|
338
399
|
return accumulator;
|
|
339
400
|
};
|
|
@@ -341,20 +402,20 @@ var opSlice = (node, context, evaluate2) => {
|
|
|
341
402
|
const { from, start, end } = node.$slice;
|
|
342
403
|
const input = evaluate2(from, context);
|
|
343
404
|
if (typeof input === "string") return input.slice(start, end);
|
|
344
|
-
if (
|
|
345
|
-
|
|
405
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(input)) return input.slice(start, end);
|
|
406
|
+
return refuseType({ node, op: "$slice", field: "from", needs: "a list or text", got: input, written: from, contextOp: "$slice" });
|
|
346
407
|
};
|
|
347
408
|
var opFlatten = (node, context, evaluate2) => {
|
|
348
|
-
const input = requireArray(evaluate2(node.$flatten, context), "$flatten");
|
|
409
|
+
const input = requireArray(evaluate2(node.$flatten, context), node, "$flatten", void 0, node.$flatten);
|
|
349
410
|
const result = [];
|
|
350
411
|
for (const item of input) {
|
|
351
|
-
if (
|
|
412
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(item)) result.push(...item);
|
|
352
413
|
else result.push(item);
|
|
353
414
|
}
|
|
354
415
|
return result;
|
|
355
416
|
};
|
|
356
417
|
var opUnique = (node, context, evaluate2) => {
|
|
357
|
-
const input = requireArray(evaluate2(node.$unique, context), "$unique");
|
|
418
|
+
const input = requireArray(evaluate2(node.$unique, context), node, "$unique", void 0, node.$unique);
|
|
358
419
|
const seen = /* @__PURE__ */ new Set();
|
|
359
420
|
const result = [];
|
|
360
421
|
for (const item of input) {
|
|
@@ -366,12 +427,13 @@ var opUnique = (node, context, evaluate2) => {
|
|
|
366
427
|
}
|
|
367
428
|
return result;
|
|
368
429
|
};
|
|
369
|
-
var sortKey = (key) => {
|
|
430
|
+
var sortKey = (key, node) => {
|
|
370
431
|
if (key !== null && typeof key === "object") {
|
|
371
|
-
|
|
372
|
-
`$sortBy.by answered ${
|
|
373
|
-
|
|
374
|
-
{ op: "$sortBy" }
|
|
432
|
+
return chunkQUI2X5JB_cjs.failAt(
|
|
433
|
+
`$sortBy.by answered ${chunkQUI2X5JB_cjs.describeValue(key)}; a sort key is a string or a number. To sort by two keys, sort by the second and then by the first: the sort keeps the order of equal items.`,
|
|
434
|
+
chunkQUI2X5JB_cjs.ErrorCode.TYPE,
|
|
435
|
+
{ op: "$sortBy" },
|
|
436
|
+
{ node, op: "$sortBy", field: "by", form: true }
|
|
375
437
|
);
|
|
376
438
|
}
|
|
377
439
|
return key;
|
|
@@ -380,11 +442,11 @@ var NULL_KIND = 3;
|
|
|
380
442
|
var kindOf = (key) => key === null ? NULL_KIND : typeof key === "number" ? 0 : typeof key === "string" ? 1 : 2;
|
|
381
443
|
var opSortBy = (node, context, evaluate2) => {
|
|
382
444
|
const { over, as, by, dir = "asc" } = node.$sortBy;
|
|
383
|
-
const input = requireArray(evaluate2(over, context), "$sortBy
|
|
445
|
+
const input = requireArray(evaluate2(over, context), node, "$sortBy", "over", over);
|
|
384
446
|
const { scope, vars } = loopScope(context);
|
|
385
447
|
const keyed = input.map((item) => {
|
|
386
448
|
vars[as] = item;
|
|
387
|
-
return { item, key: sortKey(evaluate2(by, scope)) };
|
|
449
|
+
return { item, key: sortKey(evaluate2(by, scope), node) };
|
|
388
450
|
});
|
|
389
451
|
keyed.sort((a, b) => {
|
|
390
452
|
const kindA = kindOf(a.key);
|
|
@@ -397,33 +459,41 @@ var opSortBy = (node, context, evaluate2) => {
|
|
|
397
459
|
};
|
|
398
460
|
|
|
399
461
|
// src/ops/math.ops.ts
|
|
400
|
-
var requireNumbers = (node, context, evaluate2, op) => {
|
|
401
|
-
const a = evaluate2(
|
|
402
|
-
const b = evaluate2(
|
|
403
|
-
if (typeof a !== "number" || typeof b !== "number")
|
|
404
|
-
|
|
462
|
+
var requireNumbers = (node, pair, context, evaluate2, op) => {
|
|
463
|
+
const a = evaluate2(pair[0], context);
|
|
464
|
+
const b = evaluate2(pair[1], context);
|
|
465
|
+
if (typeof a !== "number" || typeof b !== "number") {
|
|
466
|
+
const wrong = typeof a === "number" ? 1 : 0;
|
|
467
|
+
return chunkQUI2X5JB_cjs.failAt(
|
|
468
|
+
`${op} needs two numbers, but got ${chunkQUI2X5JB_cjs.describeValue(a)} and ${chunkQUI2X5JB_cjs.describeValue(b)}.${writtenNote(pair[wrong])}`,
|
|
469
|
+
chunkQUI2X5JB_cjs.ErrorCode.TYPE,
|
|
470
|
+
{ op },
|
|
471
|
+
{ node, op, field: String(wrong), form: true }
|
|
472
|
+
);
|
|
473
|
+
}
|
|
405
474
|
return [a, b];
|
|
406
475
|
};
|
|
476
|
+
var refuseZero = (node, op) => chunkQUI2X5JB_cjs.failAt(`Division by zero: the second value of ${op} is 0.`, chunkQUI2X5JB_cjs.ErrorCode.DIVISION_BY_ZERO, { op }, { node, op, field: "1", form: false });
|
|
407
477
|
var opAdd = (node, context, evaluate2) => {
|
|
408
|
-
const [a, b] = requireNumbers(node.$add, context, evaluate2, "$add");
|
|
478
|
+
const [a, b] = requireNumbers(node, node.$add, context, evaluate2, "$add");
|
|
409
479
|
return a + b;
|
|
410
480
|
};
|
|
411
481
|
var opSub = (node, context, evaluate2) => {
|
|
412
|
-
const [a, b] = requireNumbers(node.$sub, context, evaluate2, "$sub");
|
|
482
|
+
const [a, b] = requireNumbers(node, node.$sub, context, evaluate2, "$sub");
|
|
413
483
|
return a - b;
|
|
414
484
|
};
|
|
415
485
|
var opMul = (node, context, evaluate2) => {
|
|
416
|
-
const [a, b] = requireNumbers(node.$mul, context, evaluate2, "$mul");
|
|
486
|
+
const [a, b] = requireNumbers(node, node.$mul, context, evaluate2, "$mul");
|
|
417
487
|
return a * b;
|
|
418
488
|
};
|
|
419
489
|
var opDiv = (node, context, evaluate2) => {
|
|
420
|
-
const [a, b] = requireNumbers(node.$div, context, evaluate2, "$div");
|
|
421
|
-
if (b === 0)
|
|
490
|
+
const [a, b] = requireNumbers(node, node.$div, context, evaluate2, "$div");
|
|
491
|
+
if (b === 0) return refuseZero(node, "$div");
|
|
422
492
|
return a / b;
|
|
423
493
|
};
|
|
424
494
|
var opMod = (node, context, evaluate2) => {
|
|
425
|
-
const [a, b] = requireNumbers(node.$mod, context, evaluate2, "$mod");
|
|
426
|
-
if (b === 0)
|
|
495
|
+
const [a, b] = requireNumbers(node, node.$mod, context, evaluate2, "$mod");
|
|
496
|
+
if (b === 0) return refuseZero(node, "$mod");
|
|
427
497
|
const remainder = a % b;
|
|
428
498
|
if (remainder === 0) return 0;
|
|
429
499
|
return remainder < 0 !== b < 0 ? remainder + b : remainder;
|
|
@@ -431,19 +501,12 @@ var opMod = (node, context, evaluate2) => {
|
|
|
431
501
|
var ROUNDING = { nearest: Math.round, floor: Math.floor, ceil: Math.ceil };
|
|
432
502
|
var opRound = (node, context, evaluate2) => {
|
|
433
503
|
const value = evaluate2(node.$round.value, context);
|
|
434
|
-
if (typeof value !== "number")
|
|
435
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected number for $round", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$round" });
|
|
504
|
+
if (typeof value !== "number") return refuseType({ node, op: "$round", field: "value", needs: "a number", got: value, written: node.$round.value });
|
|
436
505
|
const digits = node.$round.digits ?? 0;
|
|
437
506
|
const factor = Math.pow(10, digits);
|
|
438
507
|
return ROUNDING[node.$round.mode ?? "nearest"](value * factor) / factor;
|
|
439
508
|
};
|
|
440
509
|
var NUMERIC_TEXT = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
|
|
441
|
-
var whatIs = (value) => {
|
|
442
|
-
if (typeof value === "string") return JSON.stringify(value.slice(0, 40));
|
|
443
|
-
if (value === null) return "null";
|
|
444
|
-
if (Array.isArray(value)) return "a list";
|
|
445
|
-
return typeof value === "object" ? "an object" : String(value);
|
|
446
|
-
};
|
|
447
510
|
var opToNumber = (node, context, evaluate2) => {
|
|
448
511
|
const value = evaluate2(node.$toNumber.value, context);
|
|
449
512
|
if (typeof value === "number") return value;
|
|
@@ -453,14 +516,22 @@ var opToNumber = (node, context, evaluate2) => {
|
|
|
453
516
|
if (Number.isFinite(parsed)) return parsed;
|
|
454
517
|
}
|
|
455
518
|
if (node.$toNumber.fallback !== void 0) return evaluate2(node.$toNumber.fallback, context);
|
|
456
|
-
|
|
519
|
+
return refuseType({ node, op: "$toNumber", field: "value", needs: "a number or numeric text", got: value, written: node.$toNumber.value, contextOp: "$toNumber" });
|
|
457
520
|
};
|
|
458
521
|
|
|
459
522
|
// src/ops/string.ops.ts
|
|
460
523
|
var opJoin = (node, context, evaluate2) => {
|
|
461
524
|
const { parts, sep = "" } = node.$join;
|
|
462
525
|
const list = evaluate2(parts, context);
|
|
463
|
-
if (!Array.isArray(list))
|
|
526
|
+
if (!Array.isArray(list)) return refuseType({ node, op: "$join", field: "parts", needs: "a list", got: list, written: parts });
|
|
527
|
+
const wrong = list.findIndex((part) => !isTextLike(part));
|
|
528
|
+
if (wrong !== -1)
|
|
529
|
+
return chunkQUI2X5JB_cjs.failAt(
|
|
530
|
+
`$join.parts needs items that are ${TEXT_LIKE}, but item ${wrong} is ${chunkQUI2X5JB_cjs.describeValue(list[wrong])}.${Array.isArray(parts) ? writtenNote(parts[wrong]) : ""}`,
|
|
531
|
+
chunkQUI2X5JB_cjs.ErrorCode.TYPE,
|
|
532
|
+
{ op: "$join" },
|
|
533
|
+
{ node, op: "$join", field: "parts", form: true }
|
|
534
|
+
);
|
|
464
535
|
return list.map((p) => String(p ?? "")).join(sep);
|
|
465
536
|
};
|
|
466
537
|
var opToString = (node, context, evaluate2) => {
|
|
@@ -472,17 +543,23 @@ var opToString = (node, context, evaluate2) => {
|
|
|
472
543
|
var opInterpolate = (node, context, evaluate2) => {
|
|
473
544
|
const { template, values: valuesNode } = node.$interpolate;
|
|
474
545
|
const values = evaluate2(valuesNode, context);
|
|
475
|
-
if (!
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
546
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(values)) return refuseType({ node, op: "$interpolate", field: "values", needs: "an object", got: values, written: valuesNode });
|
|
547
|
+
return template.replace(/\{\{(\w+)\}\}/g, (_match, key) => {
|
|
548
|
+
const value = values[key] ?? "";
|
|
549
|
+
if (!isTextLike(value))
|
|
550
|
+
return chunkQUI2X5JB_cjs.failAt(
|
|
551
|
+
`$interpolate.values needs ${TEXT_LIKE} for {{${key}}}, but "${key}" is ${chunkQUI2X5JB_cjs.describeValue(value)}.`,
|
|
552
|
+
chunkQUI2X5JB_cjs.ErrorCode.TYPE,
|
|
553
|
+
{ op: "$interpolate" },
|
|
554
|
+
{ node, op: "$interpolate", field: "values", form: true }
|
|
555
|
+
);
|
|
556
|
+
return String(value);
|
|
557
|
+
});
|
|
481
558
|
};
|
|
482
559
|
var fillOne = (value) => {
|
|
483
560
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return value;
|
|
484
561
|
const { phrase, slots } = value;
|
|
485
|
-
if (typeof phrase !== "string" || !
|
|
562
|
+
if (typeof phrase !== "string" || !chunkQUI2X5JB_cjs.isJsonObject(slots)) return value;
|
|
486
563
|
return phrase.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (hole, name) => {
|
|
487
564
|
const slot = slots[name];
|
|
488
565
|
if (slot === void 0 || slot === null) return hole;
|
|
@@ -493,32 +570,27 @@ var fillOne = (value) => {
|
|
|
493
570
|
var opFill = (node, context, evaluate2) => fillOne(evaluate2(node.$fill, context));
|
|
494
571
|
var opTrim = (node, context, evaluate2) => {
|
|
495
572
|
const value = evaluate2(node.$trim, context);
|
|
496
|
-
if (typeof value !== "string")
|
|
497
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected string for $trim", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$trim" });
|
|
573
|
+
if (typeof value !== "string") return refuseType({ node, op: "$trim", needs: "text", got: value, written: node.$trim });
|
|
498
574
|
return value.trim();
|
|
499
575
|
};
|
|
500
576
|
var opLower = (node, context, evaluate2) => {
|
|
501
577
|
const value = evaluate2(node.$lower, context);
|
|
502
|
-
if (typeof value !== "string")
|
|
503
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected string for $lower", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$lower" });
|
|
578
|
+
if (typeof value !== "string") return refuseType({ node, op: "$lower", needs: "text", got: value, written: node.$lower });
|
|
504
579
|
return value.toLowerCase();
|
|
505
580
|
};
|
|
506
581
|
var opUpper = (node, context, evaluate2) => {
|
|
507
582
|
const value = evaluate2(node.$upper, context);
|
|
508
|
-
if (typeof value !== "string")
|
|
509
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected string for $upper", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$upper" });
|
|
583
|
+
if (typeof value !== "string") return refuseType({ node, op: "$upper", needs: "text", got: value, written: node.$upper });
|
|
510
584
|
return value.toUpperCase();
|
|
511
585
|
};
|
|
512
586
|
var opSplit = (node, context, evaluate2) => {
|
|
513
587
|
const value = evaluate2(node.$split.value, context);
|
|
514
|
-
if (typeof value !== "string")
|
|
515
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected string for $split", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$split" });
|
|
588
|
+
if (typeof value !== "string") return refuseType({ node, op: "$split", field: "value", needs: "text", got: value, written: node.$split.value });
|
|
516
589
|
return value.split(node.$split.sep);
|
|
517
590
|
};
|
|
518
591
|
var opReplace = (node, context, evaluate2) => {
|
|
519
592
|
const value = evaluate2(node.$replace.value, context);
|
|
520
|
-
if (typeof value !== "string")
|
|
521
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected string for $replace", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$replace" });
|
|
593
|
+
if (typeof value !== "string") return refuseType({ node, op: "$replace", field: "value", needs: "text", got: value, written: node.$replace.value });
|
|
522
594
|
const { search, replacement, all } = node.$replace;
|
|
523
595
|
return all === true ? value.replaceAll(search, replacement) : value.replace(search, replacement);
|
|
524
596
|
};
|
|
@@ -534,45 +606,52 @@ var opNeq = (node, context, evaluate2) => {
|
|
|
534
606
|
const b = evaluate2(node.$neq[1], context);
|
|
535
607
|
return !jsonEqual(a, b);
|
|
536
608
|
};
|
|
537
|
-
var compareOp = (pair, context, evaluate2, op, test) => {
|
|
609
|
+
var compareOp = (node, pair, context, evaluate2, op, test) => {
|
|
538
610
|
const a = evaluate2(pair[0], context);
|
|
539
611
|
const b = evaluate2(pair[1], context);
|
|
540
612
|
const cmp = compare(a, b);
|
|
541
|
-
if (cmp === void 0)
|
|
542
|
-
|
|
613
|
+
if (cmp === void 0) {
|
|
614
|
+
const wrong = typeof a === "number" || typeof a === "string" ? 1 : 0;
|
|
615
|
+
return chunkQUI2X5JB_cjs.failAt(
|
|
616
|
+
`${op} needs two numbers or two texts, but got ${chunkQUI2X5JB_cjs.describeValue(a)} and ${chunkQUI2X5JB_cjs.describeValue(b)}.${writtenNote(pair[wrong])}`,
|
|
617
|
+
chunkQUI2X5JB_cjs.ErrorCode.TYPE,
|
|
618
|
+
{ op },
|
|
619
|
+
{ node, op, field: String(wrong), form: true }
|
|
620
|
+
);
|
|
621
|
+
}
|
|
543
622
|
return test(cmp);
|
|
544
623
|
};
|
|
545
|
-
var opGt = (node, ctx, ev) => compareOp(node.$gt, ctx, ev, "$gt", (c) => c > 0);
|
|
546
|
-
var opGte = (node, ctx, ev) => compareOp(node.$gte, ctx, ev, "$gte", (c) => c >= 0);
|
|
547
|
-
var opLt = (node, ctx, ev) => compareOp(node.$lt, ctx, ev, "$lt", (c) => c < 0);
|
|
548
|
-
var opLte = (node, ctx, ev) => compareOp(node.$lte, ctx, ev, "$lte", (c) => c <= 0);
|
|
624
|
+
var opGt = (node, ctx, ev) => compareOp(node, node.$gt, ctx, ev, "$gt", (c) => c > 0);
|
|
625
|
+
var opGte = (node, ctx, ev) => compareOp(node, node.$gte, ctx, ev, "$gte", (c) => c >= 0);
|
|
626
|
+
var opLt = (node, ctx, ev) => compareOp(node, node.$lt, ctx, ev, "$lt", (c) => c < 0);
|
|
627
|
+
var opLte = (node, ctx, ev) => compareOp(node, node.$lte, ctx, ev, "$lte", (c) => c <= 0);
|
|
549
628
|
var opEmpty = (node, context, evaluate2) => {
|
|
550
629
|
const value = evaluate2(node.$empty, context);
|
|
551
630
|
if (value === null || value === void 0) return true;
|
|
552
631
|
if (typeof value === "string") return value.length === 0;
|
|
553
|
-
if (
|
|
554
|
-
if (
|
|
632
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(value)) return value.length === 0;
|
|
633
|
+
if (chunkQUI2X5JB_cjs.isJsonObject(value)) return Object.keys(value).length === 0;
|
|
555
634
|
return false;
|
|
556
635
|
};
|
|
557
636
|
var opStartsWith = (node, context, evaluate2) => {
|
|
558
637
|
const value = evaluate2(node.$startsWith.value, context);
|
|
559
638
|
const prefix = evaluate2(node.$startsWith.prefix, context);
|
|
560
|
-
if (typeof value !== "string"
|
|
561
|
-
|
|
639
|
+
if (typeof value !== "string") return refuseType({ node, op: "$startsWith", field: "value", needs: "text", got: value, written: node.$startsWith.value });
|
|
640
|
+
if (typeof prefix !== "string") return refuseType({ node, op: "$startsWith", field: "prefix", needs: "text", got: prefix, written: node.$startsWith.prefix });
|
|
562
641
|
return value.startsWith(prefix);
|
|
563
642
|
};
|
|
564
643
|
var opEndsWith = (node, context, evaluate2) => {
|
|
565
644
|
const value = evaluate2(node.$endsWith.value, context);
|
|
566
645
|
const suffix = evaluate2(node.$endsWith.suffix, context);
|
|
567
|
-
if (typeof value !== "string"
|
|
568
|
-
|
|
646
|
+
if (typeof value !== "string") return refuseType({ node, op: "$endsWith", field: "value", needs: "text", got: value, written: node.$endsWith.value });
|
|
647
|
+
if (typeof suffix !== "string") return refuseType({ node, op: "$endsWith", field: "suffix", needs: "text", got: suffix, written: node.$endsWith.suffix });
|
|
569
648
|
return value.endsWith(suffix);
|
|
570
649
|
};
|
|
571
650
|
var opContains = (node, context, evaluate2) => {
|
|
572
651
|
const value = evaluate2(node.$contains.value, context);
|
|
573
652
|
const search = evaluate2(node.$contains.search, context);
|
|
574
|
-
if (typeof value !== "string"
|
|
575
|
-
|
|
653
|
+
if (typeof value !== "string") return refuseType({ node, op: "$contains", field: "value", needs: "text", got: value, written: node.$contains.value });
|
|
654
|
+
if (typeof search !== "string") return refuseType({ node, op: "$contains", field: "search", needs: "text", got: search, written: node.$contains.search });
|
|
576
655
|
return value.includes(search);
|
|
577
656
|
};
|
|
578
657
|
|
|
@@ -598,10 +677,10 @@ var opOr = (node, context, evaluate2) => {
|
|
|
598
677
|
// src/ops/structure.ops.ts
|
|
599
678
|
var opMerge = (node, context, evaluate2) => {
|
|
600
679
|
const result = {};
|
|
601
|
-
for (
|
|
680
|
+
for (let index = 0; index < node.$merge.length; index++) {
|
|
681
|
+
const part = node.$merge[index];
|
|
602
682
|
const evaluated = evaluate2(part, context);
|
|
603
|
-
if (!
|
|
604
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected object for $merge element", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$merge" });
|
|
683
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(evaluated)) return refuseType({ node, op: "$merge", field: String(index), needs: "an object", got: evaluated, written: part, contextOp: "$merge" });
|
|
605
684
|
Object.assign(result, evaluated);
|
|
606
685
|
}
|
|
607
686
|
return result;
|
|
@@ -623,20 +702,19 @@ var opCase = (node, context, evaluate2) => {
|
|
|
623
702
|
};
|
|
624
703
|
var opEntriesOf = (node, context, evaluate2) => {
|
|
625
704
|
const value = evaluate2(node.$entriesOf, context);
|
|
626
|
-
if (!
|
|
627
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected object for $entriesOf", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$entriesOf" });
|
|
705
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(value)) return refuseType({ node, op: "$entriesOf", needs: "an object", got: value, written: node.$entriesOf });
|
|
628
706
|
return Object.entries(value).map(([k, v]) => [k, v]);
|
|
629
707
|
};
|
|
630
708
|
var opKeyBy = (node, context, evaluate2) => {
|
|
631
709
|
const { over, as, key: keyExpr } = node.$keyBy;
|
|
632
710
|
const input = evaluate2(over, context);
|
|
633
|
-
if (!
|
|
634
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected array for $keyBy.over", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$keyBy" });
|
|
711
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(input)) return refuseType({ node, op: "$keyBy", field: "over", needs: "a list", got: input, written: over, contextOp: "$keyBy" });
|
|
635
712
|
const result = {};
|
|
636
713
|
const { scope, vars } = loopScope(context);
|
|
637
714
|
for (const item of input) {
|
|
638
715
|
vars[as] = item;
|
|
639
716
|
const key = evaluate2(keyExpr, scope);
|
|
717
|
+
if (!isTextLike(key)) return refuseType({ node, op: "$keyBy", field: "key", needs: TEXT_LIKE, got: key, written: keyExpr, contextOp: "$keyBy" });
|
|
640
718
|
result[String(key)] = item;
|
|
641
719
|
}
|
|
642
720
|
return result;
|
|
@@ -644,13 +722,14 @@ var opKeyBy = (node, context, evaluate2) => {
|
|
|
644
722
|
var opGroupBy = (node, context, evaluate2) => {
|
|
645
723
|
const { over, as, key: keyExpr } = node.$groupBy;
|
|
646
724
|
const input = evaluate2(over, context);
|
|
647
|
-
if (!
|
|
648
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected array for $groupBy.over", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$groupBy" });
|
|
725
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(input)) return refuseType({ node, op: "$groupBy", field: "over", needs: "a list", got: input, written: over, contextOp: "$groupBy" });
|
|
649
726
|
const result = {};
|
|
650
727
|
const { scope, vars } = loopScope(context);
|
|
651
728
|
for (const item of input) {
|
|
652
729
|
vars[as] = item;
|
|
653
|
-
const
|
|
730
|
+
const value = evaluate2(keyExpr, scope);
|
|
731
|
+
if (!isTextLike(value)) return refuseType({ node, op: "$groupBy", field: "key", needs: TEXT_LIKE, got: value, written: keyExpr, contextOp: "$groupBy" });
|
|
732
|
+
const key = String(value);
|
|
654
733
|
if (!result[key]) result[key] = [];
|
|
655
734
|
result[key].push(item);
|
|
656
735
|
}
|
|
@@ -660,32 +739,29 @@ var opGroupBy = (node, context, evaluate2) => {
|
|
|
660
739
|
// src/ops/object.ops.ts
|
|
661
740
|
var opKeys = (node, context, evaluate2) => {
|
|
662
741
|
const value = evaluate2(node.$keys, context);
|
|
663
|
-
if (!
|
|
664
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected object for $keys", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$keys" });
|
|
742
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(value)) return refuseType({ node, op: "$keys", needs: "an object", got: value, written: node.$keys });
|
|
665
743
|
return Object.keys(value);
|
|
666
744
|
};
|
|
667
745
|
var opValues = (node, context, evaluate2) => {
|
|
668
746
|
const value = evaluate2(node.$values, context);
|
|
669
|
-
if (!
|
|
670
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected object for $values", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$values" });
|
|
747
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(value)) return refuseType({ node, op: "$values", needs: "an object", got: value, written: node.$values });
|
|
671
748
|
return Object.values(value);
|
|
672
749
|
};
|
|
673
750
|
var opFromEntries = (node, context, evaluate2) => {
|
|
674
751
|
const value = evaluate2(node.$fromEntries, context);
|
|
675
|
-
if (!
|
|
676
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected array for $fromEntries", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$fromEntries" });
|
|
752
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(value)) return refuseType({ node, op: "$fromEntries", needs: "a list of [key, value] pairs", got: value, written: node.$fromEntries });
|
|
677
753
|
const result = {};
|
|
678
|
-
for (
|
|
679
|
-
|
|
680
|
-
|
|
754
|
+
for (let index = 0; index < value.length; index++) {
|
|
755
|
+
const entry = value[index];
|
|
756
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(entry) || entry.length < 2)
|
|
757
|
+
return chunkQUI2X5JB_cjs.failAt(`$fromEntries needs a list of [key, value] pairs, but item ${index} is ${chunkQUI2X5JB_cjs.describeValue(entry)}.`, chunkQUI2X5JB_cjs.ErrorCode.TYPE, { op: "$fromEntries" }, { node, op: "$fromEntries", form: true });
|
|
681
758
|
result[String(entry[0])] = entry[1];
|
|
682
759
|
}
|
|
683
760
|
return result;
|
|
684
761
|
};
|
|
685
762
|
var opPick = (node, context, evaluate2) => {
|
|
686
763
|
const value = evaluate2(node.$pick.from, context);
|
|
687
|
-
if (!
|
|
688
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected object for $pick", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$pick" });
|
|
764
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(value)) return refuseType({ node, op: "$pick", field: "from", needs: "an object", got: value, written: node.$pick.from, contextOp: "$pick" });
|
|
689
765
|
const result = {};
|
|
690
766
|
for (const key of node.$pick.keys) {
|
|
691
767
|
if (key in value) result[key] = value[key];
|
|
@@ -694,8 +770,7 @@ var opPick = (node, context, evaluate2) => {
|
|
|
694
770
|
};
|
|
695
771
|
var opOmit = (node, context, evaluate2) => {
|
|
696
772
|
const value = evaluate2(node.$omit.from, context);
|
|
697
|
-
if (!
|
|
698
|
-
throw new chunk6PD7M2F3_cjs.PrismError("Expected object for $omit", chunk6PD7M2F3_cjs.ErrorCode.TYPE, { op: "$omit" });
|
|
773
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(value)) return refuseType({ node, op: "$omit", field: "from", needs: "an object", got: value, written: node.$omit.from, contextOp: "$omit" });
|
|
699
774
|
const keysToOmit = new Set(node.$omit.keys);
|
|
700
775
|
const result = {};
|
|
701
776
|
for (const [k, v] of Object.entries(value)) {
|
|
@@ -706,14 +781,14 @@ var opOmit = (node, context, evaluate2) => {
|
|
|
706
781
|
var opType = (node, context, evaluate2) => {
|
|
707
782
|
const value = evaluate2(node.$type, context);
|
|
708
783
|
if (value === null) return "null";
|
|
709
|
-
if (
|
|
784
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(value)) return "array";
|
|
710
785
|
return typeof value;
|
|
711
786
|
};
|
|
712
787
|
var opLength = (node, context, evaluate2) => {
|
|
713
788
|
const value = evaluate2(node.$length, context);
|
|
714
789
|
if (typeof value === "string") return value.length;
|
|
715
|
-
if (
|
|
716
|
-
|
|
790
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(value)) return value.length;
|
|
791
|
+
return refuseType({ node, op: "$length", needs: "a list or text", got: value, written: node.$length });
|
|
717
792
|
};
|
|
718
793
|
|
|
719
794
|
// src/ops/transform.ops.ts
|
|
@@ -721,10 +796,10 @@ var has = (value, path) => {
|
|
|
721
796
|
let at = value;
|
|
722
797
|
for (const segment of path) {
|
|
723
798
|
if (typeof segment === "number") {
|
|
724
|
-
if (!
|
|
799
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(at) || segment >= at.length) return false;
|
|
725
800
|
at = at[segment] ?? null;
|
|
726
801
|
} else {
|
|
727
|
-
if (!
|
|
802
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(at) || !Object.prototype.hasOwnProperty.call(at, segment)) return false;
|
|
728
803
|
at = at[segment] ?? null;
|
|
729
804
|
}
|
|
730
805
|
}
|
|
@@ -733,7 +808,7 @@ var has = (value, path) => {
|
|
|
733
808
|
var opHas = (node, context, evaluate2) => has(evaluate2(node.$has.from, context), node.$has.path);
|
|
734
809
|
var opRenameKeys = (node, context, evaluate2) => {
|
|
735
810
|
const value = evaluate2(node.$renameKeys.from, context);
|
|
736
|
-
if (!
|
|
811
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(value)) return refuseType({ node, op: "$renameKeys", field: "from", needs: "an object", got: value, written: node.$renameKeys.from, contextOp: "$renameKeys" });
|
|
737
812
|
const { map } = node.$renameKeys;
|
|
738
813
|
const renamedTo = new Set(Object.entries(map).filter(([from]) => Object.prototype.hasOwnProperty.call(value, from)).map(([, to]) => to));
|
|
739
814
|
const result = {};
|
|
@@ -747,31 +822,31 @@ var opRenameKeys = (node, context, evaluate2) => {
|
|
|
747
822
|
var current = (value, path) => {
|
|
748
823
|
let at = value;
|
|
749
824
|
for (const segment of path) {
|
|
750
|
-
if (typeof segment === "number") at =
|
|
751
|
-
else at =
|
|
825
|
+
if (typeof segment === "number") at = chunkQUI2X5JB_cjs.isJsonArray(at) ? at[segment] ?? null : null;
|
|
826
|
+
else at = chunkQUI2X5JB_cjs.isJsonObject(at) ? at[segment] ?? null : null;
|
|
752
827
|
}
|
|
753
828
|
return at;
|
|
754
829
|
};
|
|
755
|
-
var setIn = (value, path, next, full) => {
|
|
830
|
+
var setIn = (value, path, next, full, node) => {
|
|
756
831
|
const [head, ...rest] = path;
|
|
757
832
|
if (head === void 0) return next;
|
|
758
833
|
if (typeof head === "number") {
|
|
759
|
-
if (!
|
|
760
|
-
|
|
834
|
+
if (!chunkQUI2X5JB_cjs.isJsonArray(value) || head >= value.length) {
|
|
835
|
+
return chunkQUI2X5JB_cjs.failAt(`No array item at ${full.join(".")}: the value there is ${chunkQUI2X5JB_cjs.describeValue(value)}.`, chunkQUI2X5JB_cjs.ErrorCode.MISSING_PATH, { op: "$update", path: full.join(".") }, { node, op: "$update", field: "path", form: false });
|
|
761
836
|
}
|
|
762
|
-
return value.map((item, i) => i === head ? setIn(item, rest, next, full) : item);
|
|
837
|
+
return value.map((item, i) => i === head ? setIn(item, rest, next, full, node) : item);
|
|
763
838
|
}
|
|
764
|
-
const base =
|
|
765
|
-
return { ...base, [head]: setIn(base[head] ?? null, rest, next, full) };
|
|
839
|
+
const base = chunkQUI2X5JB_cjs.isJsonObject(value) ? value : {};
|
|
840
|
+
return { ...base, [head]: setIn(base[head] ?? null, rest, next, full, node) };
|
|
766
841
|
};
|
|
767
842
|
var opUpdate = (node, context, evaluate2) => {
|
|
768
843
|
const { from, path, value, as } = node.$update;
|
|
769
844
|
const source = evaluate2(from, context);
|
|
770
845
|
const next = evaluate2(value, { ...context, vars: { ...context.vars, [as ?? "current"]: current(source, path) } });
|
|
771
|
-
return setIn(source, path, next, path);
|
|
846
|
+
return setIn(source, path, next, path, node);
|
|
772
847
|
};
|
|
773
848
|
var opAssert = (node, context, evaluate2) => {
|
|
774
|
-
if (!evaluate2(node.$assert.when, context)) throw new
|
|
849
|
+
if (!evaluate2(node.$assert.when, context)) throw new chunkQUI2X5JB_cjs.PrismError(node.$assert.message, chunkQUI2X5JB_cjs.ErrorCode.ASSERT, { op: "$assert" });
|
|
775
850
|
return evaluate2(node.$assert.value, context);
|
|
776
851
|
};
|
|
777
852
|
var opWalk = (node, context, evaluate2) => {
|
|
@@ -784,8 +859,8 @@ var opWalk = (node, context, evaluate2) => {
|
|
|
784
859
|
return { matched: false, value };
|
|
785
860
|
};
|
|
786
861
|
const children = (value, visit) => {
|
|
787
|
-
if (
|
|
788
|
-
if (
|
|
862
|
+
if (chunkQUI2X5JB_cjs.isJsonArray(value)) return value.map(visit);
|
|
863
|
+
if (chunkQUI2X5JB_cjs.isJsonObject(value)) return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, visit(v)]));
|
|
789
864
|
return value;
|
|
790
865
|
};
|
|
791
866
|
const post = (value) => rewrite(children(value, post)).value;
|
|
@@ -795,32 +870,32 @@ var opWalk = (node, context, evaluate2) => {
|
|
|
795
870
|
dayjs__default.default.extend(utc__default.default);
|
|
796
871
|
var DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
|
|
797
872
|
var isDateOnly = (value) => typeof value === "string" && DATE_ONLY.test(value);
|
|
798
|
-
var parseDate = (value, op) => {
|
|
873
|
+
var parseDate = (value, node, op, field, written, contextOp) => {
|
|
799
874
|
if (typeof value !== "string" && typeof value !== "number")
|
|
800
|
-
|
|
875
|
+
return refuseType({ node, op, field, needs: "a date, as text or a number", got: value, written, contextOp });
|
|
801
876
|
const d = isDateOnly(value) ? dayjs__default.default.utc(value) : dayjs__default.default(value);
|
|
802
877
|
if (!d.isValid())
|
|
803
|
-
|
|
878
|
+
return chunkQUI2X5JB_cjs.failAt(`Invalid date for ${contextOp}: ${chunkQUI2X5JB_cjs.clip(String(value), 60)}`, chunkQUI2X5JB_cjs.ErrorCode.DATE_INVALID, { op: contextOp }, { node, op, field, form: false });
|
|
804
879
|
return d;
|
|
805
880
|
};
|
|
806
881
|
var opDate = (node, context, evaluate2) => {
|
|
807
882
|
const value = evaluate2(node.$date.value, context);
|
|
808
|
-
const d = parseDate(value, "$date");
|
|
883
|
+
const d = parseDate(value, node, "$date", "value", node.$date.value, "$date");
|
|
809
884
|
const instance = node.$date.utc ? d.utc() : d;
|
|
810
885
|
if (node.$date.format) return instance.format(node.$date.format);
|
|
811
886
|
return instance.toISOString();
|
|
812
887
|
};
|
|
813
888
|
var opDateAdd = (node, context, evaluate2) => {
|
|
814
889
|
const value = evaluate2(node.$dateAdd.date, context);
|
|
815
|
-
const d = parseDate(value, "$dateAdd");
|
|
890
|
+
const d = parseDate(value, node, "$dateAdd", "date", node.$dateAdd.date, "$dateAdd");
|
|
816
891
|
const moved = d.add(node.$dateAdd.amount, node.$dateAdd.unit);
|
|
817
892
|
return isDateOnly(value) ? moved.format("YYYY-MM-DD") : moved.toISOString();
|
|
818
893
|
};
|
|
819
894
|
var opDateDiff = (node, context, evaluate2) => {
|
|
820
895
|
const from = evaluate2(node.$dateDiff.from, context);
|
|
821
896
|
const to = evaluate2(node.$dateDiff.to, context);
|
|
822
|
-
const fromDate = parseDate(from, "$dateDiff.from");
|
|
823
|
-
const toDate = parseDate(to, "$dateDiff.to");
|
|
897
|
+
const fromDate = parseDate(from, node, "$dateDiff", "from", node.$dateDiff.from, "$dateDiff.from");
|
|
898
|
+
const toDate = parseDate(to, node, "$dateDiff", "to", node.$dateDiff.to, "$dateDiff.to");
|
|
824
899
|
return toDate.diff(fromDate, node.$dateDiff.unit);
|
|
825
900
|
};
|
|
826
901
|
|
|
@@ -828,9 +903,9 @@ var opDateDiff = (node, context, evaluate2) => {
|
|
|
828
903
|
var DATE_FORMATTERS = /* @__PURE__ */ new Map();
|
|
829
904
|
var NUMBER_FORMATTERS = /* @__PURE__ */ new Map();
|
|
830
905
|
var DATE_ONLY2 = /^\d{4}-\d{2}-\d{2}$/;
|
|
831
|
-
var localeOf = (value, op) => {
|
|
906
|
+
var localeOf = (value, node, op, written) => {
|
|
832
907
|
if (typeof value !== "string" || value.trim() === "")
|
|
833
|
-
|
|
908
|
+
return refuseType({ node, op, field: "locale", needs: 'a locale tag such as "de-AT"', got: value, written, contextOp: op });
|
|
834
909
|
return value;
|
|
835
910
|
};
|
|
836
911
|
var isBlank = (value) => value === null || value === void 0 || value === "";
|
|
@@ -839,16 +914,16 @@ var fallbackOf = (raw, context, evaluate2) => {
|
|
|
839
914
|
const resolved = evaluate2(raw, context);
|
|
840
915
|
return resolved === null || resolved === void 0 ? "" : resolved;
|
|
841
916
|
};
|
|
842
|
-
var numberOf = (value, op) => {
|
|
917
|
+
var numberOf = (value, node, op, written) => {
|
|
843
918
|
const parsed = typeof value === "number" ? value : Number(value);
|
|
844
|
-
if (!Number.isFinite(parsed))
|
|
919
|
+
if (!Number.isFinite(parsed)) return refuseType({ node, op, field: "value", needs: "a number or numeric text", got: value, written, contextOp: op });
|
|
845
920
|
return parsed;
|
|
846
921
|
};
|
|
847
922
|
var opLocaleDate = (node, context, evaluate2) => {
|
|
848
923
|
const spec = node.$localeDate;
|
|
849
924
|
const value = evaluate2(spec.value, context);
|
|
850
925
|
if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
|
|
851
|
-
const locale = localeOf(evaluate2(spec.locale, context), "$localeDate");
|
|
926
|
+
const locale = localeOf(evaluate2(spec.locale, context), node, "$localeDate", spec.locale);
|
|
852
927
|
const authored = spec.options ?? { dateStyle: "medium" };
|
|
853
928
|
const dateOnly = typeof value === "string" && DATE_ONLY2.test(value);
|
|
854
929
|
const options = {
|
|
@@ -857,7 +932,7 @@ var opLocaleDate = (node, context, evaluate2) => {
|
|
|
857
932
|
};
|
|
858
933
|
const parsed = typeof value === "number" ? new Date(value) : new Date(String(value));
|
|
859
934
|
if (Number.isNaN(parsed.getTime()))
|
|
860
|
-
|
|
935
|
+
return chunkQUI2X5JB_cjs.failAt(`Invalid date for $localeDate: ${chunkQUI2X5JB_cjs.clip(String(value), 60)}`, chunkQUI2X5JB_cjs.ErrorCode.DATE_INVALID, { op: "$localeDate" }, { node, op: "$localeDate", field: "value", form: false });
|
|
861
936
|
const key = `${locale}\0${JSON.stringify(options)}`;
|
|
862
937
|
let formatter = DATE_FORMATTERS.get(key);
|
|
863
938
|
if (formatter === void 0) {
|
|
@@ -883,12 +958,12 @@ var opLocaleMoney = (node, context, evaluate2) => {
|
|
|
883
958
|
const spec = node.$localeMoney;
|
|
884
959
|
const value = evaluate2(spec.value, context);
|
|
885
960
|
if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
|
|
886
|
-
const locale = localeOf(evaluate2(spec.locale, context), "$localeMoney");
|
|
961
|
+
const locale = localeOf(evaluate2(spec.locale, context), node, "$localeMoney", spec.locale);
|
|
887
962
|
const rawCurrency = evaluate2(spec.currency, context);
|
|
888
963
|
if (typeof rawCurrency !== "string" || rawCurrency.trim() === "")
|
|
889
|
-
|
|
964
|
+
return refuseType({ node, op: "$localeMoney", field: "currency", needs: 'an ISO-4217 currency code such as "EUR"', got: rawCurrency, written: spec.currency, contextOp: "$localeMoney" });
|
|
890
965
|
const currency = rawCurrency.toUpperCase();
|
|
891
|
-
const amount = numberOf(value, "$localeMoney");
|
|
966
|
+
const amount = numberOf(value, node, "$localeMoney", spec.value);
|
|
892
967
|
const major = spec.minorUnits === false ? amount : amount / minorUnitDivisor(locale, currency);
|
|
893
968
|
const options = {
|
|
894
969
|
style: "currency",
|
|
@@ -911,7 +986,7 @@ var opLocaleNumber = (node, context, evaluate2) => {
|
|
|
911
986
|
const spec = node.$localeNumber;
|
|
912
987
|
const value = evaluate2(spec.value, context);
|
|
913
988
|
if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
|
|
914
|
-
const locale = localeOf(evaluate2(spec.locale, context), "$localeNumber");
|
|
989
|
+
const locale = localeOf(evaluate2(spec.locale, context), node, "$localeNumber", spec.locale);
|
|
915
990
|
const options = {
|
|
916
991
|
style: spec.style ?? "decimal",
|
|
917
992
|
...spec.digits === void 0 ? {} : { maximumFractionDigits: spec.digits },
|
|
@@ -924,7 +999,7 @@ var opLocaleNumber = (node, context, evaluate2) => {
|
|
|
924
999
|
formatter = new Intl.NumberFormat(locale, options);
|
|
925
1000
|
NUMBER_FORMATTERS.set(key, formatter);
|
|
926
1001
|
}
|
|
927
|
-
return formatter.format(numberOf(value, "$localeNumber"));
|
|
1002
|
+
return formatter.format(numberOf(value, node, "$localeNumber", spec.value));
|
|
928
1003
|
};
|
|
929
1004
|
|
|
930
1005
|
// src/engine/optimize.ts
|
|
@@ -945,71 +1020,71 @@ var freezeConstant = (value) => {
|
|
|
945
1020
|
for (const inner of Object.values(value)) freezeConstant(inner);
|
|
946
1021
|
};
|
|
947
1022
|
var resolveHandler = (node) => {
|
|
948
|
-
if (
|
|
949
|
-
if (
|
|
950
|
-
if (
|
|
951
|
-
if (
|
|
952
|
-
if (
|
|
953
|
-
if (
|
|
954
|
-
if (
|
|
955
|
-
if (
|
|
956
|
-
if (
|
|
957
|
-
if (
|
|
958
|
-
if (
|
|
959
|
-
if (
|
|
960
|
-
if (
|
|
961
|
-
if (
|
|
962
|
-
if (
|
|
963
|
-
if (
|
|
964
|
-
if (
|
|
965
|
-
if (
|
|
966
|
-
if (
|
|
967
|
-
if (
|
|
968
|
-
if (
|
|
969
|
-
if (
|
|
970
|
-
if (
|
|
971
|
-
if (
|
|
972
|
-
if (
|
|
973
|
-
if (
|
|
974
|
-
if (
|
|
975
|
-
if (
|
|
976
|
-
if (
|
|
977
|
-
if (
|
|
978
|
-
if (
|
|
979
|
-
if (
|
|
980
|
-
if (
|
|
981
|
-
if (
|
|
982
|
-
if (
|
|
983
|
-
if (
|
|
984
|
-
if (
|
|
985
|
-
if (
|
|
986
|
-
if (
|
|
987
|
-
if (
|
|
988
|
-
if (
|
|
989
|
-
if (
|
|
990
|
-
if (
|
|
991
|
-
if (
|
|
992
|
-
if (
|
|
993
|
-
if (
|
|
994
|
-
if (
|
|
995
|
-
if (
|
|
996
|
-
if (
|
|
997
|
-
if (
|
|
998
|
-
if (
|
|
999
|
-
if (
|
|
1000
|
-
if (
|
|
1001
|
-
if (
|
|
1002
|
-
if (
|
|
1003
|
-
if (
|
|
1004
|
-
if (
|
|
1005
|
-
if (
|
|
1006
|
-
if (
|
|
1007
|
-
if (
|
|
1008
|
-
if (
|
|
1009
|
-
if (
|
|
1010
|
-
if (
|
|
1011
|
-
if (
|
|
1012
|
-
if (
|
|
1023
|
+
if (chunkQUI2X5JB_cjs.isRefNode(node)) return eraseOp(opRef);
|
|
1024
|
+
if (chunkQUI2X5JB_cjs.isConstNode(node)) return eraseOp(opConst);
|
|
1025
|
+
if (chunkQUI2X5JB_cjs.isVarNode(node)) return eraseOp(opVar);
|
|
1026
|
+
if (chunkQUI2X5JB_cjs.isGetNode(node)) return eraseOp(opGet);
|
|
1027
|
+
if (chunkQUI2X5JB_cjs.isWithNode(node)) return eraseOp(opWith);
|
|
1028
|
+
if (chunkQUI2X5JB_cjs.isMapNode(node)) return eraseOp(opMap);
|
|
1029
|
+
if (chunkQUI2X5JB_cjs.isFilterNode(node)) return eraseOp(opFilter);
|
|
1030
|
+
if (chunkQUI2X5JB_cjs.isReduceNode(node)) return eraseOp(opReduce);
|
|
1031
|
+
if (chunkQUI2X5JB_cjs.isSliceNode(node)) return eraseOp(opSlice);
|
|
1032
|
+
if (chunkQUI2X5JB_cjs.isFlattenNode(node)) return eraseOp(opFlatten);
|
|
1033
|
+
if (chunkQUI2X5JB_cjs.isUniqueNode(node)) return eraseOp(opUnique);
|
|
1034
|
+
if (chunkQUI2X5JB_cjs.isSortByNode(node)) return eraseOp(opSortBy);
|
|
1035
|
+
if (chunkQUI2X5JB_cjs.isAddNode(node)) return eraseOp(opAdd);
|
|
1036
|
+
if (chunkQUI2X5JB_cjs.isSubNode(node)) return eraseOp(opSub);
|
|
1037
|
+
if (chunkQUI2X5JB_cjs.isMulNode(node)) return eraseOp(opMul);
|
|
1038
|
+
if (chunkQUI2X5JB_cjs.isDivNode(node)) return eraseOp(opDiv);
|
|
1039
|
+
if (chunkQUI2X5JB_cjs.isRoundNode(node)) return eraseOp(opRound);
|
|
1040
|
+
if (chunkQUI2X5JB_cjs.isModNode(node)) return eraseOp(opMod);
|
|
1041
|
+
if (chunkQUI2X5JB_cjs.isToNumberNode(node)) return eraseOp(opToNumber);
|
|
1042
|
+
if (chunkQUI2X5JB_cjs.isJoinNode(node)) return eraseOp(opJoin);
|
|
1043
|
+
if (chunkQUI2X5JB_cjs.isToStringNode(node)) return eraseOp(opToString);
|
|
1044
|
+
if (chunkQUI2X5JB_cjs.isInterpolateNode(node)) return eraseOp(opInterpolate);
|
|
1045
|
+
if (chunkQUI2X5JB_cjs.isFillNode(node)) return eraseOp(opFill);
|
|
1046
|
+
if (chunkQUI2X5JB_cjs.isTrimNode(node)) return eraseOp(opTrim);
|
|
1047
|
+
if (chunkQUI2X5JB_cjs.isLowerNode(node)) return eraseOp(opLower);
|
|
1048
|
+
if (chunkQUI2X5JB_cjs.isUpperNode(node)) return eraseOp(opUpper);
|
|
1049
|
+
if (chunkQUI2X5JB_cjs.isSplitNode(node)) return eraseOp(opSplit);
|
|
1050
|
+
if (chunkQUI2X5JB_cjs.isReplaceNode(node)) return eraseOp(opReplace);
|
|
1051
|
+
if (chunkQUI2X5JB_cjs.isEqNode(node)) return eraseOp(opEq);
|
|
1052
|
+
if (chunkQUI2X5JB_cjs.isNeqNode(node)) return eraseOp(opNeq);
|
|
1053
|
+
if (chunkQUI2X5JB_cjs.isGtNode(node)) return eraseOp(opGt);
|
|
1054
|
+
if (chunkQUI2X5JB_cjs.isGteNode(node)) return eraseOp(opGte);
|
|
1055
|
+
if (chunkQUI2X5JB_cjs.isLtNode(node)) return eraseOp(opLt);
|
|
1056
|
+
if (chunkQUI2X5JB_cjs.isLteNode(node)) return eraseOp(opLte);
|
|
1057
|
+
if (chunkQUI2X5JB_cjs.isEmptyNode(node)) return eraseOp(opEmpty);
|
|
1058
|
+
if (chunkQUI2X5JB_cjs.isStartsWithNode(node)) return eraseOp(opStartsWith);
|
|
1059
|
+
if (chunkQUI2X5JB_cjs.isEndsWithNode(node)) return eraseOp(opEndsWith);
|
|
1060
|
+
if (chunkQUI2X5JB_cjs.isContainsNode(node)) return eraseOp(opContains);
|
|
1061
|
+
if (chunkQUI2X5JB_cjs.isNotNode(node)) return eraseOp(opNot);
|
|
1062
|
+
if (chunkQUI2X5JB_cjs.isAndNode(node)) return eraseOp(opAnd);
|
|
1063
|
+
if (chunkQUI2X5JB_cjs.isOrNode(node)) return eraseOp(opOr);
|
|
1064
|
+
if (chunkQUI2X5JB_cjs.isMergeNode(node)) return eraseOp(opMerge);
|
|
1065
|
+
if (chunkQUI2X5JB_cjs.isCoalesceNode(node)) return eraseOp(opCoalesce);
|
|
1066
|
+
if (chunkQUI2X5JB_cjs.isCaseNode(node)) return eraseOp(opCase);
|
|
1067
|
+
if (chunkQUI2X5JB_cjs.isEntriesOfNode(node)) return eraseOp(opEntriesOf);
|
|
1068
|
+
if (chunkQUI2X5JB_cjs.isKeyByNode(node)) return eraseOp(opKeyBy);
|
|
1069
|
+
if (chunkQUI2X5JB_cjs.isGroupByNode(node)) return eraseOp(opGroupBy);
|
|
1070
|
+
if (chunkQUI2X5JB_cjs.isKeysNode(node)) return eraseOp(opKeys);
|
|
1071
|
+
if (chunkQUI2X5JB_cjs.isValuesNode(node)) return eraseOp(opValues);
|
|
1072
|
+
if (chunkQUI2X5JB_cjs.isFromEntriesNode(node)) return eraseOp(opFromEntries);
|
|
1073
|
+
if (chunkQUI2X5JB_cjs.isPickNode(node)) return eraseOp(opPick);
|
|
1074
|
+
if (chunkQUI2X5JB_cjs.isOmitNode(node)) return eraseOp(opOmit);
|
|
1075
|
+
if (chunkQUI2X5JB_cjs.isTypeNode(node)) return eraseOp(opType);
|
|
1076
|
+
if (chunkQUI2X5JB_cjs.isLengthNode(node)) return eraseOp(opLength);
|
|
1077
|
+
if (chunkQUI2X5JB_cjs.isHasNode(node)) return eraseOp(opHas);
|
|
1078
|
+
if (chunkQUI2X5JB_cjs.isRenameKeysNode(node)) return eraseOp(opRenameKeys);
|
|
1079
|
+
if (chunkQUI2X5JB_cjs.isUpdateNode(node)) return eraseOp(opUpdate);
|
|
1080
|
+
if (chunkQUI2X5JB_cjs.isAssertNode(node)) return eraseOp(opAssert);
|
|
1081
|
+
if (chunkQUI2X5JB_cjs.isWalkNode(node)) return eraseOp(opWalk);
|
|
1082
|
+
if (chunkQUI2X5JB_cjs.isDateNode(node)) return eraseOp(opDate);
|
|
1083
|
+
if (chunkQUI2X5JB_cjs.isDateAddNode(node)) return eraseOp(opDateAdd);
|
|
1084
|
+
if (chunkQUI2X5JB_cjs.isDateDiffNode(node)) return eraseOp(opDateDiff);
|
|
1085
|
+
if (chunkQUI2X5JB_cjs.isLocaleDateNode(node)) return eraseOp(opLocaleDate);
|
|
1086
|
+
if (chunkQUI2X5JB_cjs.isLocaleMoneyNode(node)) return eraseOp(opLocaleMoney);
|
|
1087
|
+
if (chunkQUI2X5JB_cjs.isLocaleNumberNode(node)) return eraseOp(opLocaleNumber);
|
|
1013
1088
|
return void 0;
|
|
1014
1089
|
};
|
|
1015
1090
|
var isFoldableLiteral = (node) => {
|
|
@@ -1017,8 +1092,8 @@ var isFoldableLiteral = (node) => {
|
|
|
1017
1092
|
const t = typeof node;
|
|
1018
1093
|
if (t === "string" || t === "number" || t === "boolean") return true;
|
|
1019
1094
|
if (Array.isArray(node)) return node.every(isFoldableLiteral);
|
|
1020
|
-
if (!
|
|
1021
|
-
if (
|
|
1095
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(node)) return false;
|
|
1096
|
+
if (chunkQUI2X5JB_cjs.isConstNode(node)) return isFoldableLiteral(node.$const);
|
|
1022
1097
|
if (Object.keys(node).some((k) => k.startsWith("$"))) return false;
|
|
1023
1098
|
return Object.values(node).every(isFoldableLiteral);
|
|
1024
1099
|
};
|
|
@@ -1030,8 +1105,8 @@ var optimizeNode = (node, stats, evaluate2) => {
|
|
|
1030
1105
|
for (const child of node) out.push(optimizeNode(child, stats, evaluate2));
|
|
1031
1106
|
return out;
|
|
1032
1107
|
}
|
|
1033
|
-
if (!
|
|
1034
|
-
if (
|
|
1108
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(node)) return node;
|
|
1109
|
+
if (chunkQUI2X5JB_cjs.isConstNode(node)) {
|
|
1035
1110
|
const literal = { ...node };
|
|
1036
1111
|
freezeConstant(literal["$const"]);
|
|
1037
1112
|
attachNonEnumerable(literal, HANDLER_KEY, eraseOp(opConst));
|
|
@@ -1044,15 +1119,15 @@ var optimizeNode = (node, stats, evaluate2) => {
|
|
|
1044
1119
|
return out;
|
|
1045
1120
|
};
|
|
1046
1121
|
let optimized;
|
|
1047
|
-
if (
|
|
1122
|
+
if (chunkQUI2X5JB_cjs.isWithNode(node)) {
|
|
1048
1123
|
optimized = { $with: { let: optimizeValues(node.$with.let), value: optimizeNode(node.$with.value, stats, evaluate2) } };
|
|
1049
|
-
} else if (
|
|
1124
|
+
} else if (chunkQUI2X5JB_cjs.isRenameKeysNode(node)) {
|
|
1050
1125
|
optimized = { $renameKeys: { ...node.$renameKeys, from: optimizeNode(node.$renameKeys.from, stats, evaluate2) } };
|
|
1051
1126
|
} else {
|
|
1052
1127
|
optimized = optimizeValues(node);
|
|
1053
1128
|
}
|
|
1054
|
-
if (
|
|
1055
|
-
const segments =
|
|
1129
|
+
if (chunkQUI2X5JB_cjs.isRefNode(optimized)) {
|
|
1130
|
+
const segments = chunkQUI2X5JB_cjs.parseJsonPath(optimized.$ref);
|
|
1056
1131
|
if (segments.length > 0) {
|
|
1057
1132
|
attachNonEnumerable(optimized, SEGMENTS_KEY2, segments);
|
|
1058
1133
|
stats.refsInlined += 1;
|
|
@@ -1063,7 +1138,7 @@ var optimizeNode = (node, stats, evaluate2) => {
|
|
|
1063
1138
|
attachNonEnumerable(optimized, HANDLER_KEY, handler);
|
|
1064
1139
|
stats.handlersAttached += 1;
|
|
1065
1140
|
}
|
|
1066
|
-
if (handler !== void 0 && !
|
|
1141
|
+
if (handler !== void 0 && !chunkQUI2X5JB_cjs.isConstNode(optimized) && !chunkQUI2X5JB_cjs.isRefNode(optimized) && !chunkQUI2X5JB_cjs.isVarNode(optimized)) {
|
|
1067
1142
|
const allFoldable = Object.entries(optimized).every(([key, value]) => {
|
|
1068
1143
|
if (key === HANDLER_KEY || key === SEGMENTS_KEY2) return true;
|
|
1069
1144
|
return isFoldableLiteral(value);
|
|
@@ -1093,19 +1168,19 @@ var annotateNode = (node) => {
|
|
|
1093
1168
|
for (const child of node) annotateNode(child);
|
|
1094
1169
|
return;
|
|
1095
1170
|
}
|
|
1096
|
-
if (!
|
|
1097
|
-
if (
|
|
1171
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(node)) return;
|
|
1172
|
+
if (chunkQUI2X5JB_cjs.isWithNode(node)) {
|
|
1098
1173
|
for (const value of Object.values(node.$with.let)) annotateNode(value);
|
|
1099
1174
|
annotateNode(node.$with.value);
|
|
1100
|
-
} else if (
|
|
1175
|
+
} else if (chunkQUI2X5JB_cjs.isRenameKeysNode(node)) {
|
|
1101
1176
|
annotateNode(node.$renameKeys.from);
|
|
1102
|
-
} else if (!
|
|
1177
|
+
} else if (!chunkQUI2X5JB_cjs.isConstNode(node)) {
|
|
1103
1178
|
for (const value of Object.values(node)) annotateNode(value);
|
|
1104
1179
|
} else {
|
|
1105
1180
|
freezeConstant(node.$const);
|
|
1106
1181
|
}
|
|
1107
|
-
if (
|
|
1108
|
-
const segments =
|
|
1182
|
+
if (chunkQUI2X5JB_cjs.isRefNode(node)) {
|
|
1183
|
+
const segments = chunkQUI2X5JB_cjs.parseJsonPath(node.$ref);
|
|
1109
1184
|
if (segments.length > 0) attachNonEnumerable(node, SEGMENTS_KEY2, segments);
|
|
1110
1185
|
}
|
|
1111
1186
|
const handler = resolveHandler(node);
|
|
@@ -1113,15 +1188,88 @@ var annotateNode = (node) => {
|
|
|
1113
1188
|
};
|
|
1114
1189
|
var rehydrate = (core) => annotateNode(core);
|
|
1115
1190
|
|
|
1191
|
+
// src/engine/place.ts
|
|
1192
|
+
var findPath = (tree, matches) => {
|
|
1193
|
+
const at = [];
|
|
1194
|
+
const walk2 = (value) => {
|
|
1195
|
+
if (matches(value)) return true;
|
|
1196
|
+
if (value === null || typeof value !== "object") return false;
|
|
1197
|
+
for (const [key, child] of Object.entries(value)) {
|
|
1198
|
+
at.push(key);
|
|
1199
|
+
if (walk2(child)) return true;
|
|
1200
|
+
at.pop();
|
|
1201
|
+
}
|
|
1202
|
+
return false;
|
|
1203
|
+
};
|
|
1204
|
+
return walk2(tree) ? at : void 0;
|
|
1205
|
+
};
|
|
1206
|
+
var soleOpOf = (node) => {
|
|
1207
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(node)) return void 0;
|
|
1208
|
+
const keys = Object.keys(node);
|
|
1209
|
+
return keys.length === 1 && keys[0] !== void 0 && keys[0].startsWith("$") ? keys[0] : void 0;
|
|
1210
|
+
};
|
|
1211
|
+
var MARK = "\0prism-field:";
|
|
1212
|
+
var authorPosition = (authored, treePath) => {
|
|
1213
|
+
const path = [];
|
|
1214
|
+
let node = authored;
|
|
1215
|
+
let rest = treePath;
|
|
1216
|
+
let sugar;
|
|
1217
|
+
while (rest.length > 0) {
|
|
1218
|
+
const [key] = rest;
|
|
1219
|
+
if (key !== void 0 && typeof node === "object" && node !== null && Object.prototype.hasOwnProperty.call(node, key)) {
|
|
1220
|
+
path.push(key);
|
|
1221
|
+
node = Reflect.get(node, key);
|
|
1222
|
+
rest = rest.slice(1);
|
|
1223
|
+
sugar = void 0;
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
const op = soleOpOf(node);
|
|
1227
|
+
if (op === void 0 || !chunkQUI2X5JB_cjs.isJsonObject(node)) return void 0;
|
|
1228
|
+
const fields = node[op];
|
|
1229
|
+
const names = chunkQUI2X5JB_cjs.isJsonObject(fields) ? Object.keys(fields) : [];
|
|
1230
|
+
const rewritten = desugar({ [op]: Object.fromEntries(names.map((name) => [name, `${MARK}${name}`])) });
|
|
1231
|
+
const landed = names.map((name) => ({ name, at: findPath(rewritten, (value) => value === `${MARK}${name}`) })).find(({ at }) => at !== void 0 && at.every((segment, i) => rest[i] === segment));
|
|
1232
|
+
if (landed?.at === void 0 || !chunkQUI2X5JB_cjs.isJsonObject(fields)) return { path: [...path, op], sugar: op };
|
|
1233
|
+
path.push(op, landed.name);
|
|
1234
|
+
node = fields[landed.name];
|
|
1235
|
+
rest = rest.slice(landed.at.length);
|
|
1236
|
+
sugar = op;
|
|
1237
|
+
}
|
|
1238
|
+
return sugar === void 0 ? { path } : { path, sugar };
|
|
1239
|
+
};
|
|
1240
|
+
var pathText = (path) => path.length === 0 ? "(root)" : path.join(".");
|
|
1241
|
+
var placeError = (error, tree, authored) => {
|
|
1242
|
+
if (!(error instanceof chunkQUI2X5JB_cjs.PrismError)) return;
|
|
1243
|
+
const origin = chunkQUI2X5JB_cjs.takeOrigin(error);
|
|
1244
|
+
if (origin === void 0) return;
|
|
1245
|
+
const parts = [error.message];
|
|
1246
|
+
if (origin.detail !== void 0) parts.push(origin.detail());
|
|
1247
|
+
const tail = [origin.op, origin.field].filter((part) => part !== void 0);
|
|
1248
|
+
let formOp = origin.op;
|
|
1249
|
+
const nodePath = findPath(tree, (value) => value === origin.node);
|
|
1250
|
+
if (nodePath !== void 0) {
|
|
1251
|
+
const treePath = [...nodePath, ...tail];
|
|
1252
|
+
const position = authored === void 0 ? { path: treePath } : authorPosition(authored, treePath) ?? { path: treePath };
|
|
1253
|
+
if (position.sugar === void 0) parts.push(`At ${pathText(position.path)}.`);
|
|
1254
|
+
else {
|
|
1255
|
+
parts.push(`At ${pathText(position.path)}, in the ${origin.op ?? "node"} that ${position.sugar} runs as.`);
|
|
1256
|
+
formOp = position.sugar;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
const form = origin.form && formOp !== void 0 ? chunkQUI2X5JB_cjs.formOf(formOp) : void 0;
|
|
1260
|
+
if (form !== void 0) parts.push(`Form: ${form}`);
|
|
1261
|
+
error.message = parts.join(" ");
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1116
1264
|
// src/engine/evaluate.ts
|
|
1117
1265
|
var HANDLER_KEY2 = "__op";
|
|
1118
1266
|
var isAttachedFn = (value) => typeof value === "function";
|
|
1119
1267
|
var evaluateNode = (node, context) => {
|
|
1120
1268
|
const { budget } = context;
|
|
1121
1269
|
if (budget === void 0) return evaluateUnbudgeted(node, context);
|
|
1122
|
-
spendStep(budget);
|
|
1270
|
+
spendStep(budget, node);
|
|
1123
1271
|
const out = evaluateUnbudgeted(node, context);
|
|
1124
|
-
measureString(out, budget);
|
|
1272
|
+
measureString(out, budget, node);
|
|
1125
1273
|
return out;
|
|
1126
1274
|
};
|
|
1127
1275
|
var evaluateUnbudgeted = (node, context) => {
|
|
@@ -1132,130 +1280,155 @@ var evaluateUnbudgeted = (node, context) => {
|
|
|
1132
1280
|
const obj = node;
|
|
1133
1281
|
const attached = obj[HANDLER_KEY2];
|
|
1134
1282
|
if (isAttachedFn(attached)) return attached(obj, context, evaluateNode);
|
|
1135
|
-
if (
|
|
1283
|
+
if (chunkQUI2X5JB_cjs.isPlainObject(obj)) {
|
|
1136
1284
|
const result = {};
|
|
1137
|
-
if (!(
|
|
1285
|
+
if (!(chunkQUI2X5JB_cjs.OPTIONAL_FIELDS_KEY in obj)) {
|
|
1138
1286
|
for (const key of Object.keys(obj)) result[key] = evaluateNode(obj[key], context);
|
|
1139
1287
|
return result;
|
|
1140
1288
|
}
|
|
1141
1289
|
const optionalFields = new Set(
|
|
1142
|
-
Array.isArray(obj[
|
|
1290
|
+
Array.isArray(obj[chunkQUI2X5JB_cjs.OPTIONAL_FIELDS_KEY]) ? obj[chunkQUI2X5JB_cjs.OPTIONAL_FIELDS_KEY] : []
|
|
1143
1291
|
);
|
|
1144
1292
|
for (const [key, value] of Object.entries(obj)) {
|
|
1145
|
-
if (key ===
|
|
1293
|
+
if (key === chunkQUI2X5JB_cjs.OPTIONAL_FIELDS_KEY) continue;
|
|
1146
1294
|
const isOptional = optionalFields.has(key);
|
|
1147
1295
|
try {
|
|
1148
1296
|
const evaluated = evaluateNode(value, context);
|
|
1149
1297
|
if (isOptional && (evaluated === null || evaluated === void 0)) continue;
|
|
1150
1298
|
result[key] = evaluated;
|
|
1151
1299
|
} catch (error) {
|
|
1152
|
-
if (isOptional && error instanceof
|
|
1300
|
+
if (isOptional && error instanceof chunkQUI2X5JB_cjs.PrismError && error.code === chunkQUI2X5JB_cjs.ErrorCode.MISSING_PATH) continue;
|
|
1153
1301
|
throw error;
|
|
1154
1302
|
}
|
|
1155
1303
|
}
|
|
1156
1304
|
return result;
|
|
1157
1305
|
}
|
|
1158
|
-
if (
|
|
1159
|
-
if (
|
|
1160
|
-
if (
|
|
1161
|
-
if (
|
|
1162
|
-
if (
|
|
1163
|
-
if (
|
|
1164
|
-
if (
|
|
1165
|
-
if (
|
|
1166
|
-
if (
|
|
1167
|
-
if (
|
|
1168
|
-
if (
|
|
1169
|
-
if (
|
|
1170
|
-
if (
|
|
1171
|
-
if (
|
|
1172
|
-
if (
|
|
1173
|
-
if (
|
|
1174
|
-
if (
|
|
1175
|
-
if (
|
|
1176
|
-
if (
|
|
1177
|
-
if (
|
|
1178
|
-
if (
|
|
1179
|
-
if (
|
|
1180
|
-
if (
|
|
1181
|
-
if (
|
|
1182
|
-
if (
|
|
1183
|
-
if (
|
|
1184
|
-
if (
|
|
1185
|
-
if (
|
|
1186
|
-
if (
|
|
1187
|
-
if (
|
|
1188
|
-
if (
|
|
1189
|
-
if (
|
|
1190
|
-
if (
|
|
1191
|
-
if (
|
|
1192
|
-
if (
|
|
1193
|
-
if (
|
|
1194
|
-
if (
|
|
1195
|
-
if (
|
|
1196
|
-
if (
|
|
1197
|
-
if (
|
|
1198
|
-
if (
|
|
1199
|
-
if (
|
|
1200
|
-
if (
|
|
1201
|
-
if (
|
|
1202
|
-
if (
|
|
1203
|
-
if (
|
|
1204
|
-
if (
|
|
1205
|
-
if (
|
|
1206
|
-
if (
|
|
1207
|
-
if (
|
|
1208
|
-
if (
|
|
1209
|
-
if (
|
|
1210
|
-
if (
|
|
1211
|
-
if (
|
|
1212
|
-
if (
|
|
1213
|
-
if (
|
|
1214
|
-
if (
|
|
1215
|
-
if (
|
|
1216
|
-
if (
|
|
1217
|
-
if (
|
|
1218
|
-
if (
|
|
1219
|
-
if (
|
|
1220
|
-
if (
|
|
1221
|
-
if (
|
|
1222
|
-
if (
|
|
1306
|
+
if (chunkQUI2X5JB_cjs.isRefNode(obj)) return opRef(obj, context);
|
|
1307
|
+
if (chunkQUI2X5JB_cjs.isConstNode(obj)) return opConst(obj, context);
|
|
1308
|
+
if (chunkQUI2X5JB_cjs.isVarNode(obj)) return opVar(obj, context);
|
|
1309
|
+
if (chunkQUI2X5JB_cjs.isGetNode(obj)) return opGet(obj, context, evaluateNode);
|
|
1310
|
+
if (chunkQUI2X5JB_cjs.isWithNode(obj)) return opWith(obj, context, evaluateNode);
|
|
1311
|
+
if (chunkQUI2X5JB_cjs.isMapNode(obj)) return opMap(obj, context, evaluateNode);
|
|
1312
|
+
if (chunkQUI2X5JB_cjs.isFilterNode(obj)) return opFilter(obj, context, evaluateNode);
|
|
1313
|
+
if (chunkQUI2X5JB_cjs.isReduceNode(obj)) return opReduce(obj, context, evaluateNode);
|
|
1314
|
+
if (chunkQUI2X5JB_cjs.isSliceNode(obj)) return opSlice(obj, context, evaluateNode);
|
|
1315
|
+
if (chunkQUI2X5JB_cjs.isFlattenNode(obj)) return opFlatten(obj, context, evaluateNode);
|
|
1316
|
+
if (chunkQUI2X5JB_cjs.isUniqueNode(obj)) return opUnique(obj, context, evaluateNode);
|
|
1317
|
+
if (chunkQUI2X5JB_cjs.isSortByNode(obj)) return opSortBy(obj, context, evaluateNode);
|
|
1318
|
+
if (chunkQUI2X5JB_cjs.isAddNode(obj)) return opAdd(obj, context, evaluateNode);
|
|
1319
|
+
if (chunkQUI2X5JB_cjs.isSubNode(obj)) return opSub(obj, context, evaluateNode);
|
|
1320
|
+
if (chunkQUI2X5JB_cjs.isMulNode(obj)) return opMul(obj, context, evaluateNode);
|
|
1321
|
+
if (chunkQUI2X5JB_cjs.isDivNode(obj)) return opDiv(obj, context, evaluateNode);
|
|
1322
|
+
if (chunkQUI2X5JB_cjs.isRoundNode(obj)) return opRound(obj, context, evaluateNode);
|
|
1323
|
+
if (chunkQUI2X5JB_cjs.isModNode(obj)) return opMod(obj, context, evaluateNode);
|
|
1324
|
+
if (chunkQUI2X5JB_cjs.isToNumberNode(obj)) return opToNumber(obj, context, evaluateNode);
|
|
1325
|
+
if (chunkQUI2X5JB_cjs.isJoinNode(obj)) return opJoin(obj, context, evaluateNode);
|
|
1326
|
+
if (chunkQUI2X5JB_cjs.isToStringNode(obj)) return opToString(obj, context, evaluateNode);
|
|
1327
|
+
if (chunkQUI2X5JB_cjs.isInterpolateNode(obj)) return opInterpolate(obj, context, evaluateNode);
|
|
1328
|
+
if (chunkQUI2X5JB_cjs.isFillNode(obj)) return opFill(obj, context, evaluateNode);
|
|
1329
|
+
if (chunkQUI2X5JB_cjs.isTrimNode(obj)) return opTrim(obj, context, evaluateNode);
|
|
1330
|
+
if (chunkQUI2X5JB_cjs.isLowerNode(obj)) return opLower(obj, context, evaluateNode);
|
|
1331
|
+
if (chunkQUI2X5JB_cjs.isUpperNode(obj)) return opUpper(obj, context, evaluateNode);
|
|
1332
|
+
if (chunkQUI2X5JB_cjs.isSplitNode(obj)) return opSplit(obj, context, evaluateNode);
|
|
1333
|
+
if (chunkQUI2X5JB_cjs.isReplaceNode(obj)) return opReplace(obj, context, evaluateNode);
|
|
1334
|
+
if (chunkQUI2X5JB_cjs.isEqNode(obj)) return opEq(obj, context, evaluateNode);
|
|
1335
|
+
if (chunkQUI2X5JB_cjs.isNeqNode(obj)) return opNeq(obj, context, evaluateNode);
|
|
1336
|
+
if (chunkQUI2X5JB_cjs.isGtNode(obj)) return opGt(obj, context, evaluateNode);
|
|
1337
|
+
if (chunkQUI2X5JB_cjs.isGteNode(obj)) return opGte(obj, context, evaluateNode);
|
|
1338
|
+
if (chunkQUI2X5JB_cjs.isLtNode(obj)) return opLt(obj, context, evaluateNode);
|
|
1339
|
+
if (chunkQUI2X5JB_cjs.isLteNode(obj)) return opLte(obj, context, evaluateNode);
|
|
1340
|
+
if (chunkQUI2X5JB_cjs.isEmptyNode(obj)) return opEmpty(obj, context, evaluateNode);
|
|
1341
|
+
if (chunkQUI2X5JB_cjs.isStartsWithNode(obj)) return opStartsWith(obj, context, evaluateNode);
|
|
1342
|
+
if (chunkQUI2X5JB_cjs.isEndsWithNode(obj)) return opEndsWith(obj, context, evaluateNode);
|
|
1343
|
+
if (chunkQUI2X5JB_cjs.isContainsNode(obj)) return opContains(obj, context, evaluateNode);
|
|
1344
|
+
if (chunkQUI2X5JB_cjs.isNotNode(obj)) return opNot(obj, context, evaluateNode);
|
|
1345
|
+
if (chunkQUI2X5JB_cjs.isAndNode(obj)) return opAnd(obj, context, evaluateNode);
|
|
1346
|
+
if (chunkQUI2X5JB_cjs.isOrNode(obj)) return opOr(obj, context, evaluateNode);
|
|
1347
|
+
if (chunkQUI2X5JB_cjs.isMergeNode(obj)) return opMerge(obj, context, evaluateNode);
|
|
1348
|
+
if (chunkQUI2X5JB_cjs.isCoalesceNode(obj)) return opCoalesce(obj, context, evaluateNode);
|
|
1349
|
+
if (chunkQUI2X5JB_cjs.isCaseNode(obj)) return opCase(obj, context, evaluateNode);
|
|
1350
|
+
if (chunkQUI2X5JB_cjs.isEntriesOfNode(obj)) return opEntriesOf(obj, context, evaluateNode);
|
|
1351
|
+
if (chunkQUI2X5JB_cjs.isKeyByNode(obj)) return opKeyBy(obj, context, evaluateNode);
|
|
1352
|
+
if (chunkQUI2X5JB_cjs.isGroupByNode(obj)) return opGroupBy(obj, context, evaluateNode);
|
|
1353
|
+
if (chunkQUI2X5JB_cjs.isKeysNode(obj)) return opKeys(obj, context, evaluateNode);
|
|
1354
|
+
if (chunkQUI2X5JB_cjs.isValuesNode(obj)) return opValues(obj, context, evaluateNode);
|
|
1355
|
+
if (chunkQUI2X5JB_cjs.isFromEntriesNode(obj)) return opFromEntries(obj, context, evaluateNode);
|
|
1356
|
+
if (chunkQUI2X5JB_cjs.isPickNode(obj)) return opPick(obj, context, evaluateNode);
|
|
1357
|
+
if (chunkQUI2X5JB_cjs.isOmitNode(obj)) return opOmit(obj, context, evaluateNode);
|
|
1358
|
+
if (chunkQUI2X5JB_cjs.isTypeNode(obj)) return opType(obj, context, evaluateNode);
|
|
1359
|
+
if (chunkQUI2X5JB_cjs.isLengthNode(obj)) return opLength(obj, context, evaluateNode);
|
|
1360
|
+
if (chunkQUI2X5JB_cjs.isHasNode(obj)) return opHas(obj, context, evaluateNode);
|
|
1361
|
+
if (chunkQUI2X5JB_cjs.isRenameKeysNode(obj)) return opRenameKeys(obj, context, evaluateNode);
|
|
1362
|
+
if (chunkQUI2X5JB_cjs.isUpdateNode(obj)) return opUpdate(obj, context, evaluateNode);
|
|
1363
|
+
if (chunkQUI2X5JB_cjs.isAssertNode(obj)) return opAssert(obj, context, evaluateNode);
|
|
1364
|
+
if (chunkQUI2X5JB_cjs.isWalkNode(obj)) return opWalk(obj, context, evaluateNode);
|
|
1365
|
+
if (chunkQUI2X5JB_cjs.isDateNode(obj)) return opDate(obj, context, evaluateNode);
|
|
1366
|
+
if (chunkQUI2X5JB_cjs.isDateAddNode(obj)) return opDateAdd(obj, context, evaluateNode);
|
|
1367
|
+
if (chunkQUI2X5JB_cjs.isDateDiffNode(obj)) return opDateDiff(obj, context, evaluateNode);
|
|
1368
|
+
if (chunkQUI2X5JB_cjs.isLocaleDateNode(obj)) return opLocaleDate(obj, context, evaluateNode);
|
|
1369
|
+
if (chunkQUI2X5JB_cjs.isLocaleMoneyNode(obj)) return opLocaleMoney(obj, context, evaluateNode);
|
|
1370
|
+
if (chunkQUI2X5JB_cjs.isLocaleNumberNode(obj)) return opLocaleNumber(obj, context, evaluateNode);
|
|
1223
1371
|
const unknownKeys = Object.keys(obj).filter((k) => k.startsWith("$"));
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1372
|
+
const preview = JSON.stringify(obj).slice(0, 100);
|
|
1373
|
+
return chunkQUI2X5JB_cjs.failAt(
|
|
1374
|
+
`No op answers this node: ${chunkQUI2X5JB_cjs.clip(JSON.stringify(obj), 100)} (keys: ${unknownKeys.join(", ")}). The tree did not go through the schema.`,
|
|
1375
|
+
chunkQUI2X5JB_cjs.ErrorCode.NODE_SHAPE,
|
|
1376
|
+
{ details: { keys: unknownKeys, preview } },
|
|
1377
|
+
{ node: obj, form: false }
|
|
1378
|
+
);
|
|
1227
1379
|
};
|
|
1228
|
-
var
|
|
1229
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return
|
|
1230
|
-
if (typeof value === "number") return Number.isFinite(value)
|
|
1231
|
-
if (Array.isArray(value))
|
|
1232
|
-
|
|
1380
|
+
var notJson = (value, at) => {
|
|
1381
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") return void 0;
|
|
1382
|
+
if (typeof value === "number") return Number.isFinite(value) ? void 0 : `${at} is ${value}`;
|
|
1383
|
+
if (Array.isArray(value)) {
|
|
1384
|
+
for (const index of Object.keys(value)) {
|
|
1385
|
+
const found = notJson(value[Number(index)], `${at}[${index}]`);
|
|
1386
|
+
if (found !== void 0) return found;
|
|
1387
|
+
}
|
|
1388
|
+
return void 0;
|
|
1389
|
+
}
|
|
1390
|
+
if (typeof value !== "object") return `${at} is ${value === void 0 ? "undefined" : `a ${typeof value}`}`;
|
|
1233
1391
|
const proto = Object.getPrototypeOf(value);
|
|
1234
|
-
|
|
1392
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
1393
|
+
const tag = Object.prototype.toString.call(value).slice(8, -1);
|
|
1394
|
+
return `${at} is ${tag === "Object" ? "an instance of a class" : `a ${tag}`}`;
|
|
1395
|
+
}
|
|
1396
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
1397
|
+
const found = notJson(inner, `${at}.${key}`);
|
|
1398
|
+
if (found !== void 0) return found;
|
|
1399
|
+
}
|
|
1400
|
+
return void 0;
|
|
1235
1401
|
};
|
|
1236
1402
|
var checked = (config) => {
|
|
1237
|
-
if (strata.exceedsDepth(config)) throw new
|
|
1238
|
-
const parsed =
|
|
1403
|
+
if (strata.exceedsDepth(config)) throw new chunkQUI2X5JB_cjs.PrismError(`Invalid config: ${strata.depthRefusal()}`, chunkQUI2X5JB_cjs.ErrorCode.SCHEMA, { details: { issues: [{ path: "root", message: strata.depthRefusal() }] } });
|
|
1404
|
+
const parsed = chunkQUI2X5JB_cjs.ConfigSchema.safeParse(config);
|
|
1239
1405
|
if (!parsed.success) {
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1406
|
+
const explained = explainIssues(parsed.error.issues, config);
|
|
1407
|
+
const issues = explained.map((i) => ({ path: i.path.join(".") || "root", message: i.message }));
|
|
1408
|
+
throw new chunkQUI2X5JB_cjs.PrismError(`Invalid config: ${issuesText(explained)}`, chunkQUI2X5JB_cjs.ErrorCode.SCHEMA, { details: { issues } });
|
|
1242
1409
|
}
|
|
1243
1410
|
return desugar(parsed.data);
|
|
1244
1411
|
};
|
|
1245
|
-
var run = (tree, source, limits, kept) => {
|
|
1412
|
+
var run = (tree, source, limits, kept, authored) => {
|
|
1246
1413
|
const budget = createBudget(limits);
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1414
|
+
try {
|
|
1415
|
+
const result = evaluateNode(tree, kept ? { source, vars: {}, budget, kept } : { source, vars: {}, budget });
|
|
1416
|
+
measure(result, budget);
|
|
1417
|
+
return result;
|
|
1418
|
+
} catch (error) {
|
|
1419
|
+
placeError(error, tree, authored);
|
|
1420
|
+
throw error;
|
|
1421
|
+
}
|
|
1250
1422
|
};
|
|
1251
1423
|
var keptTrees = /* @__PURE__ */ new WeakMap();
|
|
1252
1424
|
var evaluate = (config, source, options) => {
|
|
1253
1425
|
if (options?.check === "always") {
|
|
1254
|
-
|
|
1255
|
-
|
|
1426
|
+
const wrong = notJson(source, "source");
|
|
1427
|
+
if (wrong !== void 0) throw new chunkQUI2X5JB_cjs.PrismError(`The source must be plain JSON: ${wrong}.`, chunkQUI2X5JB_cjs.ErrorCode.TYPE);
|
|
1428
|
+
return run(checked(config), source, options.limits, false, config);
|
|
1256
1429
|
}
|
|
1257
1430
|
const input = source;
|
|
1258
|
-
if (typeof config !== "object" || config === null) return run(checked(config), input, options?.limits, false);
|
|
1431
|
+
if (typeof config !== "object" || config === null) return run(checked(config), input, options?.limits, false, config);
|
|
1259
1432
|
let kept = keptTrees.get(config);
|
|
1260
1433
|
if (kept === void 0) {
|
|
1261
1434
|
kept = { tree: checked(config), optimized: false };
|
|
@@ -1264,7 +1437,7 @@ var evaluate = (config, source, options) => {
|
|
|
1264
1437
|
kept.tree = optimize(kept.tree, evaluateNode).node;
|
|
1265
1438
|
kept.optimized = true;
|
|
1266
1439
|
}
|
|
1267
|
-
return run(kept.tree, input, options?.limits, true);
|
|
1440
|
+
return run(kept.tree, input, options?.limits, true, config);
|
|
1268
1441
|
};
|
|
1269
1442
|
var evaluateSafe = (config, source, options) => {
|
|
1270
1443
|
try {
|
|
@@ -1286,7 +1459,7 @@ var walk = (node, stats, depth) => {
|
|
|
1286
1459
|
for (const child of node) walk(child, stats, depth + 1);
|
|
1287
1460
|
return;
|
|
1288
1461
|
}
|
|
1289
|
-
if (!
|
|
1462
|
+
if (!chunkQUI2X5JB_cjs.isJsonObject(node)) return;
|
|
1290
1463
|
for (const key of Object.keys(node)) {
|
|
1291
1464
|
if (key.startsWith("$")) {
|
|
1292
1465
|
stats.opCount[key] = (stats.opCount[key] ?? 0) + 1;
|
|
@@ -1306,11 +1479,10 @@ var hashSha256 = async (data) => {
|
|
|
1306
1479
|
return Array.from(new Uint8Array(buffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1307
1480
|
};
|
|
1308
1481
|
var compile = async (config, options) => {
|
|
1309
|
-
if (strata.exceedsDepth(config)) throw new
|
|
1310
|
-
const parsed =
|
|
1482
|
+
if (strata.exceedsDepth(config)) throw new chunkQUI2X5JB_cjs.PrismError(`Invalid config: ${strata.depthRefusal()}`, chunkQUI2X5JB_cjs.ErrorCode.SCHEMA);
|
|
1483
|
+
const parsed = chunkQUI2X5JB_cjs.ConfigSchema.safeParse(config);
|
|
1311
1484
|
if (!parsed.success) {
|
|
1312
|
-
|
|
1313
|
-
throw new chunk6PD7M2F3_cjs.PrismError(`Invalid config: ${issues}`, chunk6PD7M2F3_cjs.ErrorCode.SCHEMA);
|
|
1485
|
+
throw new chunkQUI2X5JB_cjs.PrismError(`Invalid config: ${issuesText(explainIssues(parsed.error.issues, config))}`, chunkQUI2X5JB_cjs.ErrorCode.SCHEMA);
|
|
1314
1486
|
}
|
|
1315
1487
|
const desugared = desugar(parsed.data);
|
|
1316
1488
|
const { node: core, stats: optimizations } = optimize(desugared, evaluateNode);
|
|
@@ -1357,17 +1529,22 @@ var execute = (ir, source, limits) => {
|
|
|
1357
1529
|
hydrated.add(core);
|
|
1358
1530
|
}
|
|
1359
1531
|
const budget = createBudget(limits);
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1532
|
+
try {
|
|
1533
|
+
const result = evaluateNode(core, { source, vars: {}, budget });
|
|
1534
|
+
measure(result, budget);
|
|
1535
|
+
return result;
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
placeError(error, core);
|
|
1538
|
+
throw error;
|
|
1539
|
+
}
|
|
1363
1540
|
};
|
|
1364
1541
|
var validate = (config) => {
|
|
1365
1542
|
if (strata.exceedsDepth(config)) return { ok: false, issues: [{ path: [], message: strata.depthRefusal() }] };
|
|
1366
|
-
const parsed =
|
|
1543
|
+
const parsed = chunkQUI2X5JB_cjs.ConfigSchema.safeParse(config);
|
|
1367
1544
|
if (!parsed.success) {
|
|
1368
1545
|
return {
|
|
1369
1546
|
ok: false,
|
|
1370
|
-
issues: explainIssues(parsed.error.issues)
|
|
1547
|
+
issues: explainIssues(parsed.error.issues, config)
|
|
1371
1548
|
};
|
|
1372
1549
|
}
|
|
1373
1550
|
return { ok: true, data: parsed.data };
|
|
@@ -1375,39 +1552,39 @@ var validate = (config) => {
|
|
|
1375
1552
|
|
|
1376
1553
|
Object.defineProperty(exports, "MAPPING_OPS", {
|
|
1377
1554
|
enumerable: true,
|
|
1378
|
-
get: function () { return
|
|
1555
|
+
get: function () { return chunkROYHYYIL_cjs.MAPPING_OPS; }
|
|
1379
1556
|
});
|
|
1380
1557
|
Object.defineProperty(exports, "getConfigJsonSchema", {
|
|
1381
1558
|
enumerable: true,
|
|
1382
|
-
get: function () { return
|
|
1559
|
+
get: function () { return chunkROYHYYIL_cjs.getConfigJsonSchema; }
|
|
1383
1560
|
});
|
|
1384
1561
|
Object.defineProperty(exports, "getNodeJsonSchema", {
|
|
1385
1562
|
enumerable: true,
|
|
1386
|
-
get: function () { return
|
|
1563
|
+
get: function () { return chunkROYHYYIL_cjs.getNodeJsonSchema; }
|
|
1387
1564
|
});
|
|
1388
1565
|
Object.defineProperty(exports, "getProfileJsonSchema", {
|
|
1389
1566
|
enumerable: true,
|
|
1390
|
-
get: function () { return
|
|
1567
|
+
get: function () { return chunkROYHYYIL_cjs.getProfileJsonSchema; }
|
|
1391
1568
|
});
|
|
1392
1569
|
Object.defineProperty(exports, "ConfigSchema", {
|
|
1393
1570
|
enumerable: true,
|
|
1394
|
-
get: function () { return
|
|
1571
|
+
get: function () { return chunkQUI2X5JB_cjs.ConfigSchema; }
|
|
1395
1572
|
});
|
|
1396
1573
|
Object.defineProperty(exports, "ErrorCode", {
|
|
1397
1574
|
enumerable: true,
|
|
1398
|
-
get: function () { return
|
|
1575
|
+
get: function () { return chunkQUI2X5JB_cjs.ErrorCode; }
|
|
1399
1576
|
});
|
|
1400
1577
|
Object.defineProperty(exports, "NodeSchema", {
|
|
1401
1578
|
enumerable: true,
|
|
1402
|
-
get: function () { return
|
|
1579
|
+
get: function () { return chunkQUI2X5JB_cjs.NodeSchema; }
|
|
1403
1580
|
});
|
|
1404
1581
|
Object.defineProperty(exports, "OP_KEYS", {
|
|
1405
1582
|
enumerable: true,
|
|
1406
|
-
get: function () { return
|
|
1583
|
+
get: function () { return chunkQUI2X5JB_cjs.OP_KEYS; }
|
|
1407
1584
|
});
|
|
1408
1585
|
Object.defineProperty(exports, "PrismError", {
|
|
1409
1586
|
enumerable: true,
|
|
1410
|
-
get: function () { return
|
|
1587
|
+
get: function () { return chunkQUI2X5JB_cjs.PrismError; }
|
|
1411
1588
|
});
|
|
1412
1589
|
exports.DEFAULT_LIMITS = DEFAULT_LIMITS;
|
|
1413
1590
|
exports.compile = compile;
|