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