@niscorp/prism 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +203 -0
  2. package/DESIGN.md +9 -8
  3. package/DOCS.md +71 -26
  4. package/README.md +45 -24
  5. package/dist/agent.cjs +7 -9
  6. package/dist/agent.cjs.map +1 -1
  7. package/dist/agent.js +5 -7
  8. package/dist/agent.js.map +1 -1
  9. package/dist/{chunk-26VYDHHC.cjs → chunk-6PD7M2F3.cjs} +266 -112
  10. package/dist/chunk-6PD7M2F3.cjs.map +1 -0
  11. package/dist/{chunk-XRK55NPE.js → chunk-GK4CIKKT.js} +5 -10
  12. package/dist/chunk-GK4CIKKT.js.map +1 -0
  13. package/dist/{chunk-W32JXP33.cjs → chunk-OWKINPR5.cjs} +7 -12
  14. package/dist/chunk-OWKINPR5.cjs.map +1 -0
  15. package/dist/{chunk-O3OJAQWA.js → chunk-WKS4OCKN.js} +260 -113
  16. package/dist/chunk-WKS4OCKN.js.map +1 -0
  17. package/dist/examples/index.cjs +25 -2
  18. package/dist/examples/index.cjs.map +1 -1
  19. package/dist/examples/index.d.cts +1 -1
  20. package/dist/examples/index.d.ts +1 -1
  21. package/dist/examples/index.js +25 -2
  22. package/dist/examples/index.js.map +1 -1
  23. package/dist/index.cjs +1223 -139
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +9 -6
  26. package/dist/index.d.ts +9 -6
  27. package/dist/index.js +1119 -28
  28. package/dist/index.js.map +1 -1
  29. package/dist/migrations/index.cjs +8 -17
  30. package/dist/migrations/index.cjs.map +1 -1
  31. package/dist/migrations/index.d.cts +0 -2
  32. package/dist/migrations/index.d.ts +0 -2
  33. package/dist/migrations/index.js +7 -12
  34. package/dist/migrations/index.js.map +1 -1
  35. package/dist/{profiles-C6r-x-Vj.d.cts → profiles-CPVfysxC.d.cts} +2 -1
  36. package/dist/{profiles-C6r-x-Vj.d.ts → profiles-CPVfysxC.d.ts} +2 -1
  37. package/package.json +7 -7
  38. package/dist/chunk-26VYDHHC.cjs.map +0 -1
  39. package/dist/chunk-O3OJAQWA.js.map +0 -1
  40. package/dist/chunk-V426VIRI.cjs +0 -1168
  41. package/dist/chunk-V426VIRI.cjs.map +0 -1
  42. package/dist/chunk-VC4PRB4H.js +0 -1086
  43. package/dist/chunk-VC4PRB4H.js.map +0 -1
  44. package/dist/chunk-W32JXP33.cjs.map +0 -1
  45. package/dist/chunk-XRK55NPE.js.map +0 -1
  46. package/dist/transform-DcVcOBzQ.d.cts +0 -3
  47. package/dist/transform-DcVcOBzQ.d.ts +0 -3
@@ -1,1168 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk26VYDHHC_cjs = require('./chunk-26VYDHHC.cjs');
4
- var strata = require('@niscorp/strata');
5
- var dayjs = require('dayjs');
6
- var utc = require('dayjs/plugin/utc.js');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
-
10
- var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
11
- var utc__default = /*#__PURE__*/_interopDefault(utc);
12
-
13
- // src/errors.ts
14
- var ErrorCode = {
15
- SCHEMA: "E_SCHEMA",
16
- MISSING_PATH: "E_MISSING_PATH",
17
- TYPE: "E_TYPE",
18
- DIVISION_BY_ZERO: "E_DIVISION_BY_ZERO",
19
- DATE_INVALID: "E_DATE_INVALID",
20
- VAR_NOT_FOUND: "E_VAR_NOT_FOUND",
21
- NODE_SHAPE: "E_NODE_SHAPE",
22
- // A config's own `$assert` refused its input.
23
- ASSERT: "E_ASSERT",
24
- // An evaluation past its budget (engine/budget.ts).
25
- BUDGET: "E_BUDGET"
26
- };
27
- var PrismError = class extends Error {
28
- code;
29
- context;
30
- constructor(message, code, context) {
31
- super(message);
32
- this.name = "PrismError";
33
- this.code = code;
34
- this.context = context;
35
- }
36
- };
37
-
38
- // src/engine/budget.ts
39
- var DEFAULT_LIMITS = { maxSteps: 1e6, maxStringLength: 1e6, maxValues: 1e6 };
40
- var createBudget = (limits) => ({ limits: { ...DEFAULT_LIMITS, ...limits }, steps: 0, sizes: /* @__PURE__ */ new WeakMap() });
41
- var refuse = (what, limit) => {
42
- throw new PrismError(`Evaluation stopped: ${what} (limit ${limit})`, ErrorCode.BUDGET, { details: { limit } });
43
- };
44
- var spendStep = (budget) => {
45
- budget.steps += 1;
46
- if (budget.steps > budget.limits.maxSteps) refuse("it evaluated too many nodes", budget.limits.maxSteps);
47
- };
48
- var sizeOf = (value, budget) => {
49
- if (value === null || typeof value !== "object") return 1;
50
- const known = budget.sizes.get(value);
51
- if (known !== void 0) return known;
52
- let size = 1;
53
- for (const inner of Array.isArray(value) ? value : Object.values(value)) {
54
- size += sizeOf(inner, budget);
55
- if (size > budget.limits.maxValues) break;
56
- }
57
- budget.sizes.set(value, size);
58
- return size;
59
- };
60
- var measureString = (value, budget) => {
61
- if (typeof value === "string" && value.length > budget.limits.maxStringLength) refuse(`a string of ${value.length} characters`, budget.limits.maxStringLength);
62
- };
63
- var measure = (value, budget) => {
64
- if (budget === void 0) return;
65
- measureString(value, budget);
66
- if (value !== null && typeof value === "object" && sizeOf(value, budget) > budget.limits.maxValues) {
67
- refuse("a result holding too many values", budget.limits.maxValues);
68
- }
69
- };
70
-
71
- // src/utils/issues.ts
72
- var segmentsOf = (path) => path.map((p) => typeof p === "number" ? p : String(p));
73
- var explainOne = (issue, prefix) => {
74
- const here = [...prefix, ...segmentsOf(issue.path)];
75
- if (issue.code === "invalid_key") return [{ path: here, message: issue.issues[0]?.message ?? issue.message }];
76
- if (issue.code !== "invalid_union" || issue.errors.length === 0) return [{ path: here, message: issue.message }];
77
- let best = [];
78
- let bestDepth = -1;
79
- for (const branch of issue.errors) {
80
- const explained = branch.flatMap((i) => explainOne(i, here));
81
- const depth = Math.max(...explained.map((e) => e.path.length));
82
- if (depth > bestDepth || depth === bestDepth && explained.length < best.length) {
83
- best = explained;
84
- bestDepth = depth;
85
- }
86
- }
87
- return bestDepth <= here.length ? [{ path: here, message: "Not a Prism node: no op matches, and it is not a plain value." }] : best;
88
- };
89
- var explainIssues = (issues) => issues.flatMap((i) => explainOne(i, []));
90
-
91
- // src/sugar/rewriters.ts
92
- var rewriteSum = (node, recurse) => ({
93
- $reduce: {
94
- over: recurse(node.$sum.over),
95
- as: "__x",
96
- acc: "__acc",
97
- init: { $const: 0 },
98
- body: { $add: [{ $var: "__acc" }, { $var: "__x" }] }
99
- }
100
- });
101
- var rewriteCount = (node, recurse) => ({
102
- $reduce: {
103
- over: recurse(node.$count.over),
104
- as: "__x",
105
- acc: "__acc",
106
- init: { $const: 0 },
107
- body: { $add: [{ $var: "__acc" }, { $const: 1 }] }
108
- }
109
- });
110
- var rewriteAvg = (node, recurse) => {
111
- const over = recurse(node.$avg.over);
112
- return {
113
- $div: [
114
- {
115
- $reduce: {
116
- over,
117
- as: "__x",
118
- acc: "__acc",
119
- init: { $const: 0 },
120
- body: { $add: [{ $var: "__acc" }, { $var: "__x" }] }
121
- }
122
- },
123
- {
124
- $reduce: {
125
- over,
126
- as: "__x",
127
- acc: "__acc",
128
- init: { $const: 0 },
129
- body: { $add: [{ $var: "__acc" }, { $const: 1 }] }
130
- }
131
- }
132
- ]
133
- };
134
- };
135
- var rewriteMin = (node, recurse) => ({
136
- $reduce: {
137
- over: recurse(node.$min.over),
138
- as: "__x",
139
- acc: "__acc",
140
- init: { $const: null },
141
- body: {
142
- $case: {
143
- branches: [
144
- { when: { $eq: [{ $var: "__acc" }, null] }, then: { $var: "__x" } },
145
- { when: { $lt: [{ $var: "__x" }, { $var: "__acc" }] }, then: { $var: "__x" } }
146
- ],
147
- else: { $var: "__acc" }
148
- }
149
- }
150
- }
151
- });
152
- var rewriteMax = (node, recurse) => ({
153
- $reduce: {
154
- over: recurse(node.$max.over),
155
- as: "__x",
156
- acc: "__acc",
157
- init: { $const: null },
158
- body: {
159
- $case: {
160
- branches: [
161
- { when: { $eq: [{ $var: "__acc" }, null] }, then: { $var: "__x" } },
162
- { when: { $gt: [{ $var: "__x" }, { $var: "__acc" }] }, then: { $var: "__x" } }
163
- ],
164
- else: { $var: "__acc" }
165
- }
166
- }
167
- }
168
- });
169
- var rewritePluck = (node, recurse) => ({
170
- $map: {
171
- over: recurse(node.$pluck.over),
172
- as: "__item",
173
- body: { $get: { from: { $var: "__item" }, path: [node.$pluck.key] } }
174
- }
175
- });
176
- var rewriteTake = (node, recurse) => ({
177
- $slice: {
178
- from: recurse(node.$take.from),
179
- start: 0,
180
- end: node.$take.count
181
- }
182
- });
183
- var rewriteDrop = (node, recurse) => ({
184
- $slice: {
185
- from: recurse(node.$drop.from),
186
- start: node.$drop.count
187
- }
188
- });
189
- var rewriteMatch = (node, recurse) => ({
190
- $filter: {
191
- over: recurse(node.$match.over),
192
- as: node.$match.as,
193
- when: {
194
- $contains: {
195
- value: { $var: node.$match.as },
196
- search: recurse(node.$match.search)
197
- }
198
- }
199
- }
200
- });
201
- var rewriteFlatMap = (node, recurse) => ({
202
- $flatten: {
203
- $map: {
204
- over: recurse(node.$flatMap.over),
205
- as: node.$flatMap.as,
206
- body: recurse(node.$flatMap.body)
207
- }
208
- }
209
- });
210
-
211
- // src/sugar/desugar.ts
212
- var desugar = (node) => {
213
- if (node === null || node === void 0) return node;
214
- if (typeof node !== "object") return node;
215
- if (Array.isArray(node)) return node.map(desugar);
216
- if (chunk26VYDHHC_cjs.isSumNode(node)) return rewriteSum(node, desugar);
217
- if (chunk26VYDHHC_cjs.isAvgNode(node)) return rewriteAvg(node, desugar);
218
- if (chunk26VYDHHC_cjs.isCountNode(node)) return rewriteCount(node, desugar);
219
- if (chunk26VYDHHC_cjs.isMinNode(node)) return rewriteMin(node, desugar);
220
- if (chunk26VYDHHC_cjs.isMaxNode(node)) return rewriteMax(node, desugar);
221
- if (chunk26VYDHHC_cjs.isPluckNode(node)) return rewritePluck(node, desugar);
222
- if (chunk26VYDHHC_cjs.isTakeNode(node)) return rewriteTake(node, desugar);
223
- if (chunk26VYDHHC_cjs.isDropNode(node)) return rewriteDrop(node, desugar);
224
- if (chunk26VYDHHC_cjs.isMatchNode(node)) return rewriteMatch(node, desugar);
225
- if (chunk26VYDHHC_cjs.isFlatMapNode(node)) return rewriteFlatMap(node, desugar);
226
- if (chunk26VYDHHC_cjs.isJsonObject(node)) {
227
- const result = {};
228
- for (const [key, value] of Object.entries(node)) {
229
- result[key] = desugar(value);
230
- }
231
- return result;
232
- }
233
- return node;
234
- };
235
-
236
- // src/utils/jsonpath.ts
237
- var parseJsonPath = (path) => {
238
- if (!path.startsWith("$.")) return [];
239
- const segments = [];
240
- let cursor = 2;
241
- let currentKey = "";
242
- const pushKey = () => {
243
- if (currentKey.length > 0) {
244
- segments.push({ type: "key", key: currentKey });
245
- currentKey = "";
246
- }
247
- };
248
- while (cursor < path.length) {
249
- const char = path[cursor];
250
- if (char === ".") {
251
- pushKey();
252
- cursor++;
253
- continue;
254
- }
255
- if (char === "[") {
256
- pushKey();
257
- cursor++;
258
- let numBuf = "";
259
- while (cursor < path.length && path[cursor] !== "]") {
260
- numBuf += path[cursor];
261
- cursor++;
262
- }
263
- if (path[cursor] !== "]") return [];
264
- cursor++;
265
- const index = Number(numBuf);
266
- if (!Number.isInteger(index) || index < 0) return [];
267
- segments.push({ type: "index", index });
268
- continue;
269
- }
270
- currentKey += char;
271
- cursor++;
272
- }
273
- pushKey();
274
- return segments;
275
- };
276
- var cache = /* @__PURE__ */ new Map();
277
- var parseJsonPathCached = (path) => {
278
- const cached = cache.get(path);
279
- if (cached) return cached;
280
- const parsed = parseJsonPath(path);
281
- cache.set(path, parsed);
282
- return parsed;
283
- };
284
- var primeJsonPathCache = (paths) => {
285
- for (const p of paths) {
286
- if (!cache.has(p)) cache.set(p, parseJsonPath(p));
287
- }
288
- };
289
- var getByPath = (root, segments) => {
290
- let current2 = root;
291
- for (const segment of segments) {
292
- if (segment.type === "key") {
293
- if (!chunk26VYDHHC_cjs.isJsonObject(current2)) return void 0;
294
- current2 = current2[segment.key];
295
- } else {
296
- if (!chunk26VYDHHC_cjs.isJsonArray(current2)) return void 0;
297
- current2 = current2[segment.index];
298
- }
299
- }
300
- return current2;
301
- };
302
-
303
- // src/ops/core.ops.ts
304
- var SEGMENTS_KEY = "__segments";
305
- var isSegmentsArray = (value) => Array.isArray(value);
306
- var opRef = (node, context, _evaluate) => {
307
- const attached = Reflect.get(node, SEGMENTS_KEY);
308
- const segments = isSegmentsArray(attached) ? attached : parseJsonPathCached(node.$ref);
309
- const resolved = getByPath(context.source, segments);
310
- if (resolved === void 0)
311
- throw new PrismError("Path not found", ErrorCode.MISSING_PATH, { op: "$ref", path: node.$ref });
312
- return resolved;
313
- };
314
- var opConst = (node, _context, _evaluate) => node.$const;
315
- var opVar = (node, context, _evaluate) => {
316
- const value = context.vars[node.$var];
317
- if (value === void 0)
318
- throw new PrismError(`Variable not found: ${node.$var}`, ErrorCode.VAR_NOT_FOUND, { op: "$var", path: node.$var });
319
- return value;
320
- };
321
- var opGet = (node, context, evaluate2) => {
322
- const { from, path, fallback } = node.$get;
323
- let current2 = evaluate2(from, context);
324
- for (const segment of path) {
325
- const evaluated = typeof segment === "object" && segment !== null ? evaluate2(segment, context) : segment;
326
- if (typeof evaluated === "number") {
327
- if (!chunk26VYDHHC_cjs.isJsonArray(current2)) {
328
- if (fallback !== void 0) return evaluate2(fallback, context);
329
- throw new PrismError("Expected array for index access", ErrorCode.TYPE, { op: "$get" });
330
- }
331
- current2 = current2[evaluated];
332
- } else {
333
- const key = String(evaluated);
334
- if (!chunk26VYDHHC_cjs.isJsonObject(current2)) {
335
- if (fallback !== void 0) return evaluate2(fallback, context);
336
- throw new PrismError("Expected object for key access", ErrorCode.TYPE, { op: "$get" });
337
- }
338
- current2 = current2[key];
339
- }
340
- }
341
- if (current2 === void 0) {
342
- if (fallback !== void 0) return evaluate2(fallback, context);
343
- throw new PrismError("Path not found", ErrorCode.MISSING_PATH, { op: "$get" });
344
- }
345
- return current2;
346
- };
347
- var opWith = (node, context, evaluate2) => {
348
- const { let: declarations, value } = node.$with;
349
- const extendedVars = { ...context.vars };
350
- for (const [name, expr] of Object.entries(declarations)) {
351
- extendedVars[name] = evaluate2(expr, context);
352
- measure(extendedVars[name] ?? null, context.budget);
353
- }
354
- return evaluate2(value, { ...context, vars: extendedVars });
355
- };
356
-
357
- // src/utils/compare.ts
358
- var jsonEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
359
- var compare = (a, b) => {
360
- if (typeof a === "number" && typeof b === "number") return a - b;
361
- if (typeof a === "string" && typeof b === "string") return a < b ? -1 : a > b ? 1 : 0;
362
- return void 0;
363
- };
364
-
365
- // src/ops/array.ops.ts
366
- var requireArray = (value, op) => {
367
- if (!chunk26VYDHHC_cjs.isJsonArray(value))
368
- throw new PrismError(`Expected array for ${op}`, ErrorCode.TYPE, { op });
369
- return value;
370
- };
371
- var opMap = (node, context, evaluate2) => {
372
- const { over, as, body } = node.$map;
373
- const input = requireArray(evaluate2(over, context), "$map.over");
374
- const result = [];
375
- for (const item of input) {
376
- result.push(evaluate2(body, { ...context, vars: { ...context.vars, [as]: item } }));
377
- }
378
- return result;
379
- };
380
- var opFilter = (node, context, evaluate2) => {
381
- const { over, as, when } = node.$filter;
382
- const input = requireArray(evaluate2(over, context), "$filter.over");
383
- const result = [];
384
- for (const item of input) {
385
- const condition = evaluate2(when, { ...context, vars: { ...context.vars, [as]: item } });
386
- if (condition) result.push(item);
387
- }
388
- return result;
389
- };
390
- var opReduce = (node, context, evaluate2) => {
391
- const { over, as, acc: accName = "acc", init, body } = node.$reduce;
392
- const input = requireArray(evaluate2(over, context), "$reduce.over");
393
- let accumulator = evaluate2(init, context);
394
- for (const item of input) {
395
- accumulator = evaluate2(body, {
396
- ...context,
397
- vars: { ...context.vars, [as]: item, [accName]: accumulator }
398
- });
399
- measure(accumulator, context.budget);
400
- }
401
- return accumulator;
402
- };
403
- var opSlice = (node, context, evaluate2) => {
404
- const { from, start, end } = node.$slice;
405
- const input = evaluate2(from, context);
406
- if (typeof input === "string") return input.slice(start, end);
407
- if (chunk26VYDHHC_cjs.isJsonArray(input)) return input.slice(start, end);
408
- throw new PrismError("Expected array or string for $slice", ErrorCode.TYPE, { op: "$slice" });
409
- };
410
- var opFlatten = (node, context, evaluate2) => {
411
- const input = requireArray(evaluate2(node.$flatten, context), "$flatten");
412
- const result = [];
413
- for (const item of input) {
414
- if (chunk26VYDHHC_cjs.isJsonArray(item)) result.push(...item);
415
- else result.push(item);
416
- }
417
- return result;
418
- };
419
- var opUnique = (node, context, evaluate2) => {
420
- const input = requireArray(evaluate2(node.$unique, context), "$unique");
421
- const seen = /* @__PURE__ */ new Set();
422
- const result = [];
423
- for (const item of input) {
424
- const key = JSON.stringify(item);
425
- if (!seen.has(key)) {
426
- seen.add(key);
427
- result.push(item);
428
- }
429
- }
430
- return result;
431
- };
432
- var opSortBy = (node, context, evaluate2) => {
433
- const { over, as, by, dir = "asc" } = node.$sortBy;
434
- const input = requireArray(evaluate2(over, context), "$sortBy.over");
435
- const keyed = input.map((item) => ({
436
- item,
437
- key: evaluate2(by, { ...context, vars: { ...context.vars, [as]: item } })
438
- }));
439
- keyed.sort((a, b) => {
440
- const cmp = compare(a.key, b.key);
441
- if (cmp === void 0) return 0;
442
- return dir === "desc" ? -cmp : cmp;
443
- });
444
- return keyed.map((k) => k.item);
445
- };
446
-
447
- // src/ops/math.ops.ts
448
- var requireNumbers = (node, context, evaluate2, op) => {
449
- const a = evaluate2(node[0], context);
450
- const b = evaluate2(node[1], context);
451
- if (typeof a !== "number" || typeof b !== "number")
452
- throw new PrismError(`Expected numbers for ${op}`, ErrorCode.TYPE, { op });
453
- return [a, b];
454
- };
455
- var opAdd = (node, context, evaluate2) => {
456
- const [a, b] = requireNumbers(node.$add, context, evaluate2, "$add");
457
- return a + b;
458
- };
459
- var opSub = (node, context, evaluate2) => {
460
- const [a, b] = requireNumbers(node.$sub, context, evaluate2, "$sub");
461
- return a - b;
462
- };
463
- var opMul = (node, context, evaluate2) => {
464
- const [a, b] = requireNumbers(node.$mul, context, evaluate2, "$mul");
465
- return a * b;
466
- };
467
- var opDiv = (node, context, evaluate2) => {
468
- const [a, b] = requireNumbers(node.$div, context, evaluate2, "$div");
469
- if (b === 0) throw new PrismError("Division by zero", ErrorCode.DIVISION_BY_ZERO, { op: "$div" });
470
- return a / b;
471
- };
472
- var opRound = (node, context, evaluate2) => {
473
- const value = evaluate2(node.$round.value, context);
474
- if (typeof value !== "number")
475
- throw new PrismError("Expected number for $round", ErrorCode.TYPE, { op: "$round" });
476
- const digits = node.$round.digits ?? 0;
477
- const factor = Math.pow(10, digits);
478
- return Math.round(value * factor) / factor;
479
- };
480
-
481
- // src/ops/string.ops.ts
482
- var opJoin = (node, context, evaluate2) => {
483
- const { parts, sep = "" } = node.$join;
484
- const list = evaluate2(parts, context);
485
- if (!Array.isArray(list)) throw new PrismError("Expected $join.parts to evaluate to an array", ErrorCode.TYPE, { op: "$join" });
486
- return list.map((p) => String(p ?? "")).join(sep);
487
- };
488
- var opToString = (node, context, evaluate2) => {
489
- const value = evaluate2(node.$toString, context);
490
- if (value === null) return "null";
491
- if (typeof value === "object") return JSON.stringify(value);
492
- return String(value);
493
- };
494
- var opInterpolate = (node, context, evaluate2) => {
495
- const { template, values: valuesNode } = node.$interpolate;
496
- const values = evaluate2(valuesNode, context);
497
- if (!chunk26VYDHHC_cjs.isJsonObject(values))
498
- throw new PrismError("Expected object for $interpolate.values", ErrorCode.TYPE, { op: "$interpolate" });
499
- return template.replace(
500
- /\{\{(\w+)\}\}/g,
501
- (_match, key) => String(values[key] ?? "")
502
- );
503
- };
504
- var fillOne = (value) => {
505
- if (value === null || typeof value !== "object" || Array.isArray(value)) return value;
506
- const { phrase, slots } = value;
507
- if (typeof phrase !== "string" || !chunk26VYDHHC_cjs.isJsonObject(slots)) return value;
508
- return phrase.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (hole, name) => {
509
- const slot = slots[name];
510
- if (slot === void 0 || slot === null) return hole;
511
- const filled = fillOne(slot);
512
- return typeof filled === "object" ? hole : String(filled);
513
- });
514
- };
515
- var opFill = (node, context, evaluate2) => fillOne(evaluate2(node.$fill, context));
516
- var opTrim = (node, context, evaluate2) => {
517
- const value = evaluate2(node.$trim, context);
518
- if (typeof value !== "string")
519
- throw new PrismError("Expected string for $trim", ErrorCode.TYPE, { op: "$trim" });
520
- return value.trim();
521
- };
522
- var opLower = (node, context, evaluate2) => {
523
- const value = evaluate2(node.$lower, context);
524
- if (typeof value !== "string")
525
- throw new PrismError("Expected string for $lower", ErrorCode.TYPE, { op: "$lower" });
526
- return value.toLowerCase();
527
- };
528
- var opUpper = (node, context, evaluate2) => {
529
- const value = evaluate2(node.$upper, context);
530
- if (typeof value !== "string")
531
- throw new PrismError("Expected string for $upper", ErrorCode.TYPE, { op: "$upper" });
532
- return value.toUpperCase();
533
- };
534
- var opSplit = (node, context, evaluate2) => {
535
- const value = evaluate2(node.$split.value, context);
536
- if (typeof value !== "string")
537
- throw new PrismError("Expected string for $split", ErrorCode.TYPE, { op: "$split" });
538
- return value.split(node.$split.sep);
539
- };
540
- var opReplace = (node, context, evaluate2) => {
541
- const value = evaluate2(node.$replace.value, context);
542
- if (typeof value !== "string")
543
- throw new PrismError("Expected string for $replace", ErrorCode.TYPE, { op: "$replace" });
544
- return value.replace(node.$replace.search, node.$replace.replacement);
545
- };
546
-
547
- // src/ops/predicate.ops.ts
548
- var opEq = (node, context, evaluate2) => {
549
- const a = evaluate2(node.$eq[0], context);
550
- const b = evaluate2(node.$eq[1], context);
551
- return jsonEqual(a, b);
552
- };
553
- var opNeq = (node, context, evaluate2) => {
554
- const a = evaluate2(node.$neq[0], context);
555
- const b = evaluate2(node.$neq[1], context);
556
- return !jsonEqual(a, b);
557
- };
558
- var compareOp = (pair, context, evaluate2, op, test) => {
559
- const a = evaluate2(pair[0], context);
560
- const b = evaluate2(pair[1], context);
561
- const cmp = compare(a, b);
562
- if (cmp === void 0)
563
- throw new PrismError(`Cannot compare values for ${op}`, ErrorCode.TYPE, { op });
564
- return test(cmp);
565
- };
566
- var opGt = (node, ctx, ev) => compareOp(node.$gt, ctx, ev, "$gt", (c) => c > 0);
567
- var opGte = (node, ctx, ev) => compareOp(node.$gte, ctx, ev, "$gte", (c) => c >= 0);
568
- var opLt = (node, ctx, ev) => compareOp(node.$lt, ctx, ev, "$lt", (c) => c < 0);
569
- var opLte = (node, ctx, ev) => compareOp(node.$lte, ctx, ev, "$lte", (c) => c <= 0);
570
- var opEmpty = (node, context, evaluate2) => {
571
- const value = evaluate2(node.$empty, context);
572
- if (value === null || value === void 0) return true;
573
- if (typeof value === "string") return value.length === 0;
574
- if (chunk26VYDHHC_cjs.isJsonArray(value)) return value.length === 0;
575
- if (chunk26VYDHHC_cjs.isJsonObject(value)) return Object.keys(value).length === 0;
576
- return false;
577
- };
578
- var opStartsWith = (node, context, evaluate2) => {
579
- const value = evaluate2(node.$startsWith.value, context);
580
- const prefix = evaluate2(node.$startsWith.prefix, context);
581
- if (typeof value !== "string" || typeof prefix !== "string")
582
- throw new PrismError("Expected strings for $startsWith", ErrorCode.TYPE, { op: "$startsWith" });
583
- return value.startsWith(prefix);
584
- };
585
- var opEndsWith = (node, context, evaluate2) => {
586
- const value = evaluate2(node.$endsWith.value, context);
587
- const suffix = evaluate2(node.$endsWith.suffix, context);
588
- if (typeof value !== "string" || typeof suffix !== "string")
589
- throw new PrismError("Expected strings for $endsWith", ErrorCode.TYPE, { op: "$endsWith" });
590
- return value.endsWith(suffix);
591
- };
592
- var opContains = (node, context, evaluate2) => {
593
- const value = evaluate2(node.$contains.value, context);
594
- const search = evaluate2(node.$contains.search, context);
595
- if (typeof value !== "string" || typeof search !== "string")
596
- throw new PrismError("Expected strings for $contains", ErrorCode.TYPE, { op: "$contains" });
597
- return value.includes(search);
598
- };
599
-
600
- // src/ops/logic.ops.ts
601
- var opNot = (node, context, evaluate2) => !evaluate2(node.$not, context);
602
- var opAnd = (node, context, evaluate2) => {
603
- let last = true;
604
- for (const operand of node.$and) {
605
- last = evaluate2(operand, context);
606
- if (!last) return last;
607
- }
608
- return last;
609
- };
610
- var opOr = (node, context, evaluate2) => {
611
- let last = false;
612
- for (const operand of node.$or) {
613
- last = evaluate2(operand, context);
614
- if (last) return last;
615
- }
616
- return last;
617
- };
618
-
619
- // src/ops/structure.ops.ts
620
- var opMerge = (node, context, evaluate2) => {
621
- const result = {};
622
- for (const part of node.$merge) {
623
- const evaluated = evaluate2(part, context);
624
- if (!chunk26VYDHHC_cjs.isJsonObject(evaluated))
625
- throw new PrismError("Expected object for $merge element", ErrorCode.TYPE, { op: "$merge" });
626
- Object.assign(result, evaluated);
627
- }
628
- return result;
629
- };
630
- var opCoalesce = (node, context, evaluate2) => {
631
- for (const candidate of node.$coalesce) {
632
- const value = evaluate2(candidate, context);
633
- if (value !== null && value !== void 0) return value;
634
- }
635
- return null;
636
- };
637
- var opCase = (node, context, evaluate2) => {
638
- for (const branch of node.$case.branches) {
639
- const condition = evaluate2(branch.when, context);
640
- if (condition) return evaluate2(branch.then, context);
641
- }
642
- if (node.$case.else !== void 0) return evaluate2(node.$case.else, context);
643
- return null;
644
- };
645
- var opEntriesOf = (node, context, evaluate2) => {
646
- const value = evaluate2(node.$entriesOf, context);
647
- if (!chunk26VYDHHC_cjs.isJsonObject(value))
648
- throw new PrismError("Expected object for $entriesOf", ErrorCode.TYPE, { op: "$entriesOf" });
649
- return Object.entries(value).map(([k, v]) => [k, v]);
650
- };
651
- var opKeyBy = (node, context, evaluate2) => {
652
- const { over, as, key: keyExpr } = node.$keyBy;
653
- const input = evaluate2(over, context);
654
- if (!chunk26VYDHHC_cjs.isJsonArray(input))
655
- throw new PrismError("Expected array for $keyBy.over", ErrorCode.TYPE, { op: "$keyBy" });
656
- const result = {};
657
- for (const item of input) {
658
- const key = evaluate2(keyExpr, { ...context, vars: { ...context.vars, [as]: item } });
659
- result[String(key)] = item;
660
- }
661
- return result;
662
- };
663
- var opGroupBy = (node, context, evaluate2) => {
664
- const { over, as, key: keyExpr } = node.$groupBy;
665
- const input = evaluate2(over, context);
666
- if (!chunk26VYDHHC_cjs.isJsonArray(input))
667
- throw new PrismError("Expected array for $groupBy.over", ErrorCode.TYPE, { op: "$groupBy" });
668
- const result = {};
669
- for (const item of input) {
670
- const key = String(evaluate2(keyExpr, { ...context, vars: { ...context.vars, [as]: item } }));
671
- if (!result[key]) result[key] = [];
672
- result[key].push(item);
673
- }
674
- return result;
675
- };
676
-
677
- // src/ops/object.ops.ts
678
- var opKeys = (node, context, evaluate2) => {
679
- const value = evaluate2(node.$keys, context);
680
- if (!chunk26VYDHHC_cjs.isJsonObject(value))
681
- throw new PrismError("Expected object for $keys", ErrorCode.TYPE, { op: "$keys" });
682
- return Object.keys(value);
683
- };
684
- var opValues = (node, context, evaluate2) => {
685
- const value = evaluate2(node.$values, context);
686
- if (!chunk26VYDHHC_cjs.isJsonObject(value))
687
- throw new PrismError("Expected object for $values", ErrorCode.TYPE, { op: "$values" });
688
- return Object.values(value);
689
- };
690
- var opFromEntries = (node, context, evaluate2) => {
691
- const value = evaluate2(node.$fromEntries, context);
692
- if (!chunk26VYDHHC_cjs.isJsonArray(value))
693
- throw new PrismError("Expected array for $fromEntries", ErrorCode.TYPE, { op: "$fromEntries" });
694
- const result = {};
695
- for (const entry of value) {
696
- if (!chunk26VYDHHC_cjs.isJsonArray(entry) || entry.length < 2)
697
- throw new PrismError("Expected [key, value] pairs for $fromEntries", ErrorCode.TYPE, { op: "$fromEntries" });
698
- result[String(entry[0])] = entry[1];
699
- }
700
- return result;
701
- };
702
- var opPick = (node, context, evaluate2) => {
703
- const value = evaluate2(node.$pick.from, context);
704
- if (!chunk26VYDHHC_cjs.isJsonObject(value))
705
- throw new PrismError("Expected object for $pick", ErrorCode.TYPE, { op: "$pick" });
706
- const result = {};
707
- for (const key of node.$pick.keys) {
708
- if (key in value) result[key] = value[key];
709
- }
710
- return result;
711
- };
712
- var opOmit = (node, context, evaluate2) => {
713
- const value = evaluate2(node.$omit.from, context);
714
- if (!chunk26VYDHHC_cjs.isJsonObject(value))
715
- throw new PrismError("Expected object for $omit", ErrorCode.TYPE, { op: "$omit" });
716
- const keysToOmit = new Set(node.$omit.keys);
717
- const result = {};
718
- for (const [k, v] of Object.entries(value)) {
719
- if (!keysToOmit.has(k)) result[k] = v;
720
- }
721
- return result;
722
- };
723
- var opType = (node, context, evaluate2) => {
724
- const value = evaluate2(node.$type, context);
725
- if (value === null) return "null";
726
- if (chunk26VYDHHC_cjs.isJsonArray(value)) return "array";
727
- return typeof value;
728
- };
729
- var opLength = (node, context, evaluate2) => {
730
- const value = evaluate2(node.$length, context);
731
- if (typeof value === "string") return value.length;
732
- if (chunk26VYDHHC_cjs.isJsonArray(value)) return value.length;
733
- throw new PrismError("Expected array or string for $length", ErrorCode.TYPE, { op: "$length" });
734
- };
735
-
736
- // src/ops/transform.ops.ts
737
- var has = (value, path) => {
738
- let at = value;
739
- for (const segment of path) {
740
- if (typeof segment === "number") {
741
- if (!chunk26VYDHHC_cjs.isJsonArray(at) || segment >= at.length) return false;
742
- at = at[segment] ?? null;
743
- } else {
744
- if (!chunk26VYDHHC_cjs.isJsonObject(at) || !Object.prototype.hasOwnProperty.call(at, segment)) return false;
745
- at = at[segment] ?? null;
746
- }
747
- }
748
- return true;
749
- };
750
- var opHas = (node, context, evaluate2) => has(evaluate2(node.$has.from, context), node.$has.path);
751
- var opRenameKeys = (node, context, evaluate2) => {
752
- const value = evaluate2(node.$renameKeys.from, context);
753
- if (!chunk26VYDHHC_cjs.isJsonObject(value)) throw new PrismError("Expected object for $renameKeys", ErrorCode.TYPE, { op: "$renameKeys" });
754
- const { map } = node.$renameKeys;
755
- const renamedTo = new Set(Object.entries(map).filter(([from]) => Object.prototype.hasOwnProperty.call(value, from)).map(([, to]) => to));
756
- const result = {};
757
- for (const [key, v] of Object.entries(value)) {
758
- const target = map[key];
759
- if (target !== void 0) result[target] = v;
760
- else if (!renamedTo.has(key)) result[key] = v;
761
- }
762
- return result;
763
- };
764
- var current = (value, path) => {
765
- let at = value;
766
- for (const segment of path) {
767
- if (typeof segment === "number") at = chunk26VYDHHC_cjs.isJsonArray(at) ? at[segment] ?? null : null;
768
- else at = chunk26VYDHHC_cjs.isJsonObject(at) ? at[segment] ?? null : null;
769
- }
770
- return at;
771
- };
772
- var setIn = (value, path, next, full) => {
773
- const [head, ...rest] = path;
774
- if (head === void 0) return next;
775
- if (typeof head === "number") {
776
- if (!chunk26VYDHHC_cjs.isJsonArray(value) || head >= value.length) {
777
- throw new PrismError(`No array item at ${full.join(".")}`, ErrorCode.MISSING_PATH, { op: "$update", path: full.join(".") });
778
- }
779
- return value.map((item, i) => i === head ? setIn(item, rest, next, full) : item);
780
- }
781
- const base = chunk26VYDHHC_cjs.isJsonObject(value) ? value : {};
782
- return { ...base, [head]: setIn(base[head] ?? null, rest, next, full) };
783
- };
784
- var opUpdate = (node, context, evaluate2) => {
785
- const { from, path, value, as } = node.$update;
786
- const source = evaluate2(from, context);
787
- const next = evaluate2(value, { ...context, vars: { ...context.vars, [as ?? "current"]: current(source, path) } });
788
- return setIn(source, path, next, path);
789
- };
790
- var opAssert = (node, context, evaluate2) => {
791
- if (!evaluate2(node.$assert.when, context)) throw new PrismError(node.$assert.message, ErrorCode.ASSERT, { op: "$assert" });
792
- return evaluate2(node.$assert.value, context);
793
- };
794
- var opWalk = (node, context, evaluate2) => {
795
- const { over, as, rules, order } = node.$walk;
796
- const rewrite = (value) => {
797
- const scope = { ...context, vars: { ...context.vars, [as]: value } };
798
- for (const rule of rules) {
799
- if (evaluate2(rule.when, scope)) return { matched: true, value: evaluate2(rule.then, scope) };
800
- }
801
- return { matched: false, value };
802
- };
803
- const children = (value, visit) => {
804
- if (chunk26VYDHHC_cjs.isJsonArray(value)) return value.map(visit);
805
- if (chunk26VYDHHC_cjs.isJsonObject(value)) return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, visit(v)]));
806
- return value;
807
- };
808
- const post = (value) => rewrite(children(value, post)).value;
809
- const pre = (value) => children(rewrite(value).value, pre);
810
- return (order ?? "post") === "pre" ? pre(evaluate2(over, context)) : post(evaluate2(over, context));
811
- };
812
- dayjs__default.default.extend(utc__default.default);
813
- var DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
814
- var isDateOnly = (value) => typeof value === "string" && DATE_ONLY.test(value);
815
- var parseDate = (value, op) => {
816
- if (typeof value !== "string" && typeof value !== "number")
817
- throw new PrismError(`Expected string or number for ${op}`, ErrorCode.TYPE, { op });
818
- const d = isDateOnly(value) ? dayjs__default.default.utc(value) : dayjs__default.default(value);
819
- if (!d.isValid())
820
- throw new PrismError(`Invalid date for ${op}: ${String(value)}`, ErrorCode.DATE_INVALID, { op });
821
- return d;
822
- };
823
- var opDate = (node, context, evaluate2) => {
824
- const value = evaluate2(node.$date.value, context);
825
- const d = parseDate(value, "$date");
826
- const instance = node.$date.utc ? d.utc() : d;
827
- if (node.$date.format) return instance.format(node.$date.format);
828
- return instance.toISOString();
829
- };
830
- var opDateAdd = (node, context, evaluate2) => {
831
- const value = evaluate2(node.$dateAdd.date, context);
832
- const d = parseDate(value, "$dateAdd");
833
- const moved = d.add(node.$dateAdd.amount, node.$dateAdd.unit);
834
- return isDateOnly(value) ? moved.format("YYYY-MM-DD") : moved.toISOString();
835
- };
836
- var opDateDiff = (node, context, evaluate2) => {
837
- const from = evaluate2(node.$dateDiff.from, context);
838
- const to = evaluate2(node.$dateDiff.to, context);
839
- const fromDate = parseDate(from, "$dateDiff.from");
840
- const toDate = parseDate(to, "$dateDiff.to");
841
- return toDate.diff(fromDate, node.$dateDiff.unit);
842
- };
843
-
844
- // src/ops/intl.ops.ts
845
- var DATE_FORMATTERS = /* @__PURE__ */ new Map();
846
- var NUMBER_FORMATTERS = /* @__PURE__ */ new Map();
847
- var DATE_ONLY2 = /^\d{4}-\d{2}-\d{2}$/;
848
- var localeOf = (value, op) => {
849
- if (typeof value !== "string" || value.trim() === "")
850
- throw new PrismError(`${op} needs a locale tag (e.g. "de-AT")`, ErrorCode.TYPE, { op });
851
- return value;
852
- };
853
- var isBlank = (value) => value === null || value === void 0 || value === "";
854
- var fallbackOf = (raw, context, evaluate2) => {
855
- if (raw === void 0) return "";
856
- const resolved = evaluate2(raw, context);
857
- return resolved === null || resolved === void 0 ? "" : resolved;
858
- };
859
- var numberOf = (value, op) => {
860
- const parsed = typeof value === "number" ? value : Number(value);
861
- if (!Number.isFinite(parsed)) throw new PrismError(`${op} expected a number, got ${JSON.stringify(value)}`, ErrorCode.TYPE, { op });
862
- return parsed;
863
- };
864
- var opLocaleDate = (node, context, evaluate2) => {
865
- const spec = node.$localeDate;
866
- const value = evaluate2(spec.value, context);
867
- if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
868
- const locale = localeOf(evaluate2(spec.locale, context), "$localeDate");
869
- const authored = spec.options ?? { dateStyle: "medium" };
870
- const dateOnly = typeof value === "string" && DATE_ONLY2.test(value);
871
- const options = {
872
- ...authored,
873
- ...authored.timeZone === void 0 && dateOnly ? { timeZone: "UTC" } : {}
874
- };
875
- const parsed = typeof value === "number" ? new Date(value) : new Date(String(value));
876
- if (Number.isNaN(parsed.getTime()))
877
- throw new PrismError(`Invalid date for $localeDate: ${String(value)}`, ErrorCode.DATE_INVALID, { op: "$localeDate" });
878
- const key = `${locale}\0${JSON.stringify(options)}`;
879
- let formatter = DATE_FORMATTERS.get(key);
880
- if (formatter === void 0) {
881
- formatter = new Intl.DateTimeFormat(locale, options);
882
- DATE_FORMATTERS.set(key, formatter);
883
- }
884
- return formatter.format(parsed);
885
- };
886
- var minorUnitDivisor = (locale, currency) => {
887
- const key = `divisor\0${locale}\0${currency}`;
888
- let formatter = NUMBER_FORMATTERS.get(key);
889
- if (formatter === void 0) {
890
- try {
891
- formatter = new Intl.NumberFormat(locale, { style: "currency", currency });
892
- } catch {
893
- return 100;
894
- }
895
- NUMBER_FORMATTERS.set(key, formatter);
896
- }
897
- return 10 ** (formatter.resolvedOptions().maximumFractionDigits ?? 2);
898
- };
899
- var opLocaleMoney = (node, context, evaluate2) => {
900
- const spec = node.$localeMoney;
901
- const value = evaluate2(spec.value, context);
902
- if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
903
- const locale = localeOf(evaluate2(spec.locale, context), "$localeMoney");
904
- const rawCurrency = evaluate2(spec.currency, context);
905
- if (typeof rawCurrency !== "string" || rawCurrency.trim() === "")
906
- throw new PrismError("$localeMoney needs an ISO-4217 currency code", ErrorCode.TYPE, { op: "$localeMoney" });
907
- const currency = rawCurrency.toUpperCase();
908
- const amount = numberOf(value, "$localeMoney");
909
- const major = spec.minorUnits === false ? amount : amount / minorUnitDivisor(locale, currency);
910
- const options = {
911
- style: "currency",
912
- currency,
913
- ...spec.digits === void 0 ? {} : { minimumFractionDigits: spec.digits, maximumFractionDigits: spec.digits }
914
- };
915
- const key = `${locale}\0${JSON.stringify(options)}`;
916
- let formatter = NUMBER_FORMATTERS.get(key);
917
- if (formatter === void 0) {
918
- try {
919
- formatter = new Intl.NumberFormat(locale, options);
920
- } catch {
921
- return `${currency} ${major.toFixed(spec.digits ?? 2)}`;
922
- }
923
- NUMBER_FORMATTERS.set(key, formatter);
924
- }
925
- return formatter.format(major);
926
- };
927
- var opLocaleNumber = (node, context, evaluate2) => {
928
- const spec = node.$localeNumber;
929
- const value = evaluate2(spec.value, context);
930
- if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
931
- const locale = localeOf(evaluate2(spec.locale, context), "$localeNumber");
932
- const options = {
933
- style: spec.style ?? "decimal",
934
- ...spec.digits === void 0 ? {} : { maximumFractionDigits: spec.digits },
935
- ...spec.minDigits === void 0 ? {} : { minimumFractionDigits: spec.minDigits },
936
- ...spec.compact === true ? { notation: "compact" } : {}
937
- };
938
- const key = `${locale}\0${JSON.stringify(options)}`;
939
- let formatter = NUMBER_FORMATTERS.get(key);
940
- if (formatter === void 0) {
941
- formatter = new Intl.NumberFormat(locale, options);
942
- NUMBER_FORMATTERS.set(key, formatter);
943
- }
944
- return formatter.format(numberOf(value, "$localeNumber"));
945
- };
946
-
947
- // src/engine/evaluate.ts
948
- var HANDLER_KEY = "__op";
949
- var isAttachedFn = (value) => typeof value === "function";
950
- var evaluateNode = (node, context) => {
951
- const { budget } = context;
952
- if (budget === void 0) return evaluateUnbudgeted(node, context);
953
- spendStep(budget);
954
- const out = evaluateUnbudgeted(node, context);
955
- measureString(out, budget);
956
- return out;
957
- };
958
- var evaluateUnbudgeted = (node, context) => {
959
- if (node === null || node === void 0) return null;
960
- if (typeof node === "string" || typeof node === "number" || typeof node === "boolean") return node;
961
- if (Array.isArray(node)) return node.map((n) => evaluateNode(n, context));
962
- if (typeof node !== "object") return null;
963
- const obj = node;
964
- const attached = obj[HANDLER_KEY];
965
- if (isAttachedFn(attached)) return attached(obj, context, evaluateNode);
966
- if (chunk26VYDHHC_cjs.isRefNode(obj)) return opRef(obj, context);
967
- if (chunk26VYDHHC_cjs.isConstNode(obj)) return opConst(obj);
968
- if (chunk26VYDHHC_cjs.isVarNode(obj)) return opVar(obj, context);
969
- if (chunk26VYDHHC_cjs.isGetNode(obj)) return opGet(obj, context, evaluateNode);
970
- if (chunk26VYDHHC_cjs.isWithNode(obj)) return opWith(obj, context, evaluateNode);
971
- if (chunk26VYDHHC_cjs.isMapNode(obj)) return opMap(obj, context, evaluateNode);
972
- if (chunk26VYDHHC_cjs.isFilterNode(obj)) return opFilter(obj, context, evaluateNode);
973
- if (chunk26VYDHHC_cjs.isReduceNode(obj)) return opReduce(obj, context, evaluateNode);
974
- if (chunk26VYDHHC_cjs.isSliceNode(obj)) return opSlice(obj, context, evaluateNode);
975
- if (chunk26VYDHHC_cjs.isFlattenNode(obj)) return opFlatten(obj, context, evaluateNode);
976
- if (chunk26VYDHHC_cjs.isUniqueNode(obj)) return opUnique(obj, context, evaluateNode);
977
- if (chunk26VYDHHC_cjs.isSortByNode(obj)) return opSortBy(obj, context, evaluateNode);
978
- if (chunk26VYDHHC_cjs.isAddNode(obj)) return opAdd(obj, context, evaluateNode);
979
- if (chunk26VYDHHC_cjs.isSubNode(obj)) return opSub(obj, context, evaluateNode);
980
- if (chunk26VYDHHC_cjs.isMulNode(obj)) return opMul(obj, context, evaluateNode);
981
- if (chunk26VYDHHC_cjs.isDivNode(obj)) return opDiv(obj, context, evaluateNode);
982
- if (chunk26VYDHHC_cjs.isRoundNode(obj)) return opRound(obj, context, evaluateNode);
983
- if (chunk26VYDHHC_cjs.isJoinNode(obj)) return opJoin(obj, context, evaluateNode);
984
- if (chunk26VYDHHC_cjs.isToStringNode(obj)) return opToString(obj, context, evaluateNode);
985
- if (chunk26VYDHHC_cjs.isInterpolateNode(obj)) return opInterpolate(obj, context, evaluateNode);
986
- if (chunk26VYDHHC_cjs.isFillNode(obj)) return opFill(obj, context, evaluateNode);
987
- if (chunk26VYDHHC_cjs.isTrimNode(obj)) return opTrim(obj, context, evaluateNode);
988
- if (chunk26VYDHHC_cjs.isLowerNode(obj)) return opLower(obj, context, evaluateNode);
989
- if (chunk26VYDHHC_cjs.isUpperNode(obj)) return opUpper(obj, context, evaluateNode);
990
- if (chunk26VYDHHC_cjs.isSplitNode(obj)) return opSplit(obj, context, evaluateNode);
991
- if (chunk26VYDHHC_cjs.isReplaceNode(obj)) return opReplace(obj, context, evaluateNode);
992
- if (chunk26VYDHHC_cjs.isEqNode(obj)) return opEq(obj, context, evaluateNode);
993
- if (chunk26VYDHHC_cjs.isNeqNode(obj)) return opNeq(obj, context, evaluateNode);
994
- if (chunk26VYDHHC_cjs.isGtNode(obj)) return opGt(obj, context, evaluateNode);
995
- if (chunk26VYDHHC_cjs.isGteNode(obj)) return opGte(obj, context, evaluateNode);
996
- if (chunk26VYDHHC_cjs.isLtNode(obj)) return opLt(obj, context, evaluateNode);
997
- if (chunk26VYDHHC_cjs.isLteNode(obj)) return opLte(obj, context, evaluateNode);
998
- if (chunk26VYDHHC_cjs.isEmptyNode(obj)) return opEmpty(obj, context, evaluateNode);
999
- if (chunk26VYDHHC_cjs.isStartsWithNode(obj)) return opStartsWith(obj, context, evaluateNode);
1000
- if (chunk26VYDHHC_cjs.isEndsWithNode(obj)) return opEndsWith(obj, context, evaluateNode);
1001
- if (chunk26VYDHHC_cjs.isContainsNode(obj)) return opContains(obj, context, evaluateNode);
1002
- if (chunk26VYDHHC_cjs.isNotNode(obj)) return opNot(obj, context, evaluateNode);
1003
- if (chunk26VYDHHC_cjs.isAndNode(obj)) return opAnd(obj, context, evaluateNode);
1004
- if (chunk26VYDHHC_cjs.isOrNode(obj)) return opOr(obj, context, evaluateNode);
1005
- if (chunk26VYDHHC_cjs.isMergeNode(obj)) return opMerge(obj, context, evaluateNode);
1006
- if (chunk26VYDHHC_cjs.isCoalesceNode(obj)) return opCoalesce(obj, context, evaluateNode);
1007
- if (chunk26VYDHHC_cjs.isCaseNode(obj)) return opCase(obj, context, evaluateNode);
1008
- if (chunk26VYDHHC_cjs.isEntriesOfNode(obj)) return opEntriesOf(obj, context, evaluateNode);
1009
- if (chunk26VYDHHC_cjs.isKeyByNode(obj)) return opKeyBy(obj, context, evaluateNode);
1010
- if (chunk26VYDHHC_cjs.isGroupByNode(obj)) return opGroupBy(obj, context, evaluateNode);
1011
- if (chunk26VYDHHC_cjs.isKeysNode(obj)) return opKeys(obj, context, evaluateNode);
1012
- if (chunk26VYDHHC_cjs.isValuesNode(obj)) return opValues(obj, context, evaluateNode);
1013
- if (chunk26VYDHHC_cjs.isFromEntriesNode(obj)) return opFromEntries(obj, context, evaluateNode);
1014
- if (chunk26VYDHHC_cjs.isPickNode(obj)) return opPick(obj, context, evaluateNode);
1015
- if (chunk26VYDHHC_cjs.isOmitNode(obj)) return opOmit(obj, context, evaluateNode);
1016
- if (chunk26VYDHHC_cjs.isTypeNode(obj)) return opType(obj, context, evaluateNode);
1017
- if (chunk26VYDHHC_cjs.isLengthNode(obj)) return opLength(obj, context, evaluateNode);
1018
- if (chunk26VYDHHC_cjs.isHasNode(obj)) return opHas(obj, context, evaluateNode);
1019
- if (chunk26VYDHHC_cjs.isRenameKeysNode(obj)) return opRenameKeys(obj, context, evaluateNode);
1020
- if (chunk26VYDHHC_cjs.isUpdateNode(obj)) return opUpdate(obj, context, evaluateNode);
1021
- if (chunk26VYDHHC_cjs.isAssertNode(obj)) return opAssert(obj, context, evaluateNode);
1022
- if (chunk26VYDHHC_cjs.isWalkNode(obj)) return opWalk(obj, context, evaluateNode);
1023
- if (chunk26VYDHHC_cjs.isDateNode(obj)) return opDate(obj, context, evaluateNode);
1024
- if (chunk26VYDHHC_cjs.isDateAddNode(obj)) return opDateAdd(obj, context, evaluateNode);
1025
- if (chunk26VYDHHC_cjs.isDateDiffNode(obj)) return opDateDiff(obj, context, evaluateNode);
1026
- if (chunk26VYDHHC_cjs.isLocaleDateNode(obj)) return opLocaleDate(obj, context, evaluateNode);
1027
- if (chunk26VYDHHC_cjs.isLocaleMoneyNode(obj)) return opLocaleMoney(obj, context, evaluateNode);
1028
- if (chunk26VYDHHC_cjs.isLocaleNumberNode(obj)) return opLocaleNumber(obj, context, evaluateNode);
1029
- if (chunk26VYDHHC_cjs.isPlainObject(obj)) {
1030
- const optionalFields = new Set(
1031
- Array.isArray(obj[chunk26VYDHHC_cjs.OPTIONAL_FIELDS_KEY]) ? obj[chunk26VYDHHC_cjs.OPTIONAL_FIELDS_KEY] : []
1032
- );
1033
- const result = {};
1034
- for (const [key, value] of Object.entries(obj)) {
1035
- if (key === chunk26VYDHHC_cjs.OPTIONAL_FIELDS_KEY) continue;
1036
- const isOptional = optionalFields.has(key);
1037
- try {
1038
- const evaluated = evaluateNode(value, context);
1039
- if (isOptional && (evaluated === null || evaluated === void 0)) continue;
1040
- result[key] = evaluated;
1041
- } catch (error) {
1042
- if (isOptional && error instanceof PrismError && error.code === ErrorCode.MISSING_PATH) continue;
1043
- throw error;
1044
- }
1045
- }
1046
- return result;
1047
- }
1048
- const unknownKeys = Object.keys(obj).filter((k) => k.startsWith("$"));
1049
- throw new PrismError("Unsupported node shape", ErrorCode.NODE_SHAPE, {
1050
- details: { keys: unknownKeys, preview: JSON.stringify(obj).slice(0, 100) }
1051
- });
1052
- };
1053
- var evaluate = (config, source, limits) => {
1054
- if (strata.exceedsDepth(config)) throw new PrismError("Invalid config", ErrorCode.SCHEMA, { details: { issues: [{ path: "root", message: strata.depthRefusal() }] } });
1055
- const parsed = chunk26VYDHHC_cjs.ConfigSchema.safeParse(config);
1056
- if (!parsed.success) {
1057
- const issues = explainIssues(parsed.error.issues).map((i) => ({ path: i.path.join(".") || "root", message: i.message }));
1058
- throw new PrismError("Invalid config", ErrorCode.SCHEMA, { details: { issues } });
1059
- }
1060
- const desugared = desugar(parsed.data);
1061
- const budget = createBudget(limits);
1062
- const result = evaluateNode(desugared, { source, vars: {}, budget });
1063
- measure(result, budget);
1064
- return result;
1065
- };
1066
- var evaluateSafe = (config, source, limits) => {
1067
- try {
1068
- return { ok: true, data: evaluate(config, source, limits) };
1069
- } catch (error) {
1070
- return { ok: false, error: error instanceof Error ? error : new Error(String(error)) };
1071
- }
1072
- };
1073
-
1074
- // src/engine/transform.ts
1075
- var isJsonValue = (value) => {
1076
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
1077
- if (typeof value === "number") return Number.isFinite(value);
1078
- if (Array.isArray(value)) return value.every(isJsonValue);
1079
- if (typeof value === "object") return Object.values(value).every(isJsonValue);
1080
- return false;
1081
- };
1082
- var parsedConfigs = /* @__PURE__ */ new WeakMap();
1083
- var prismTransform = (config, source) => {
1084
- if (!isJsonValue(source)) throw new Error("The source of a transform must be plain JSON.");
1085
- const cached = typeof config === "object" && config !== null ? parsedConfigs.get(config) : void 0;
1086
- const parsed = cached ?? chunk26VYDHHC_cjs.ConfigSchema.parse(config);
1087
- if (cached === void 0 && typeof config === "object" && config !== null) parsedConfigs.set(config, parsed);
1088
- return evaluate(parsed, source);
1089
- };
1090
-
1091
- exports.DEFAULT_LIMITS = DEFAULT_LIMITS;
1092
- exports.ErrorCode = ErrorCode;
1093
- exports.PrismError = PrismError;
1094
- exports.createBudget = createBudget;
1095
- exports.desugar = desugar;
1096
- exports.evaluate = evaluate;
1097
- exports.evaluateNode = evaluateNode;
1098
- exports.evaluateSafe = evaluateSafe;
1099
- exports.explainIssues = explainIssues;
1100
- exports.measure = measure;
1101
- exports.opAdd = opAdd;
1102
- exports.opAnd = opAnd;
1103
- exports.opAssert = opAssert;
1104
- exports.opCase = opCase;
1105
- exports.opCoalesce = opCoalesce;
1106
- exports.opConst = opConst;
1107
- exports.opContains = opContains;
1108
- exports.opDate = opDate;
1109
- exports.opDateAdd = opDateAdd;
1110
- exports.opDateDiff = opDateDiff;
1111
- exports.opDiv = opDiv;
1112
- exports.opEmpty = opEmpty;
1113
- exports.opEndsWith = opEndsWith;
1114
- exports.opEntriesOf = opEntriesOf;
1115
- exports.opEq = opEq;
1116
- exports.opFill = opFill;
1117
- exports.opFilter = opFilter;
1118
- exports.opFlatten = opFlatten;
1119
- exports.opFromEntries = opFromEntries;
1120
- exports.opGet = opGet;
1121
- exports.opGroupBy = opGroupBy;
1122
- exports.opGt = opGt;
1123
- exports.opGte = opGte;
1124
- exports.opHas = opHas;
1125
- exports.opInterpolate = opInterpolate;
1126
- exports.opJoin = opJoin;
1127
- exports.opKeyBy = opKeyBy;
1128
- exports.opKeys = opKeys;
1129
- exports.opLength = opLength;
1130
- exports.opLocaleDate = opLocaleDate;
1131
- exports.opLocaleMoney = opLocaleMoney;
1132
- exports.opLocaleNumber = opLocaleNumber;
1133
- exports.opLower = opLower;
1134
- exports.opLt = opLt;
1135
- exports.opLte = opLte;
1136
- exports.opMap = opMap;
1137
- exports.opMerge = opMerge;
1138
- exports.opMul = opMul;
1139
- exports.opNeq = opNeq;
1140
- exports.opNot = opNot;
1141
- exports.opOmit = opOmit;
1142
- exports.opOr = opOr;
1143
- exports.opPick = opPick;
1144
- exports.opReduce = opReduce;
1145
- exports.opRef = opRef;
1146
- exports.opRenameKeys = opRenameKeys;
1147
- exports.opReplace = opReplace;
1148
- exports.opRound = opRound;
1149
- exports.opSlice = opSlice;
1150
- exports.opSortBy = opSortBy;
1151
- exports.opSplit = opSplit;
1152
- exports.opStartsWith = opStartsWith;
1153
- exports.opSub = opSub;
1154
- exports.opToString = opToString;
1155
- exports.opTrim = opTrim;
1156
- exports.opType = opType;
1157
- exports.opUnique = opUnique;
1158
- exports.opUpdate = opUpdate;
1159
- exports.opUpper = opUpper;
1160
- exports.opValues = opValues;
1161
- exports.opVar = opVar;
1162
- exports.opWalk = opWalk;
1163
- exports.opWith = opWith;
1164
- exports.parseJsonPath = parseJsonPath;
1165
- exports.primeJsonPathCache = primeJsonPathCache;
1166
- exports.prismTransform = prismTransform;
1167
- //# sourceMappingURL=chunk-V426VIRI.cjs.map
1168
- //# sourceMappingURL=chunk-V426VIRI.cjs.map