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