@niscorp/prism 0.2.0 → 0.2.2

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 (43) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/DESIGN.md +2 -1
  3. package/DOCS.md +29 -0
  4. package/README.md +49 -3
  5. package/dist/agent.cjs +4 -756
  6. package/dist/agent.cjs.map +1 -1
  7. package/dist/agent.js +2 -2
  8. package/dist/chunk-26VYDHHC.cjs +784 -0
  9. package/dist/chunk-26VYDHHC.cjs.map +1 -0
  10. package/dist/{chunk-BRIXDNJQ.js → chunk-O3OJAQWA.js} +3 -3
  11. package/dist/chunk-O3OJAQWA.js.map +1 -0
  12. package/dist/chunk-V426VIRI.cjs +1168 -0
  13. package/dist/chunk-V426VIRI.cjs.map +1 -0
  14. package/dist/{chunk-3GAYBBNH.js → chunk-VC4PRB4H.js} +21 -4
  15. package/dist/chunk-VC4PRB4H.js.map +1 -0
  16. package/dist/chunk-W32JXP33.cjs +147 -0
  17. package/dist/chunk-W32JXP33.cjs.map +1 -0
  18. package/dist/{chunk-3PYQITGE.js → chunk-XRK55NPE.js} +3 -3
  19. package/dist/{chunk-3PYQITGE.js.map → chunk-XRK55NPE.js.map} +1 -1
  20. package/dist/examples/index.cjs +1543 -0
  21. package/dist/examples/index.cjs.map +1 -0
  22. package/dist/examples/index.d.cts +26 -0
  23. package/dist/examples/index.d.ts +26 -0
  24. package/dist/examples/index.js +1540 -0
  25. package/dist/examples/index.js.map +1 -0
  26. package/dist/index.cjs +190 -2048
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +5 -82
  29. package/dist/index.d.ts +5 -82
  30. package/dist/index.js +5 -5
  31. package/dist/migrations/index.cjs +7 -1775
  32. package/dist/migrations/index.cjs.map +1 -1
  33. package/dist/migrations/index.d.cts +3 -2
  34. package/dist/migrations/index.d.ts +3 -2
  35. package/dist/migrations/index.js +3 -18
  36. package/dist/migrations/index.js.map +1 -1
  37. package/dist/profiles-C6r-x-Vj.d.cts +83 -0
  38. package/dist/profiles-C6r-x-Vj.d.ts +83 -0
  39. package/dist/transform-DcVcOBzQ.d.cts +3 -0
  40. package/dist/transform-DcVcOBzQ.d.ts +3 -0
  41. package/package.json +19 -8
  42. package/dist/chunk-3GAYBBNH.js.map +0 -1
  43. package/dist/chunk-BRIXDNJQ.js.map +0 -1
@@ -1,1763 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var zod = require('zod');
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/schemas/config.schema.ts
14
- var JsonPrimitiveSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]).describe("JSON primitive: string | number | boolean | null");
15
- var JsonValueSchema = zod.z.lazy(
16
- () => zod.z.union([JsonPrimitiveSchema, zod.z.array(JsonValueSchema), zod.z.record(zod.z.string(), JsonValueSchema)])
17
- ).describe("Any JSON value: primitive, array, or object");
18
- zod.z.record(zod.z.string(), JsonValueSchema).describe("JSON object mapping string keys to JSON values");
19
- var _NodeSchema = zod.z.any();
20
- var setNodeSchema = (schema) => {
21
- _NodeSchema = schema;
22
- };
23
- var node = () => _NodeSchema;
24
- var RefNodeSchema = zod.z.object({
25
- $ref: zod.z.string().regex(/^\$(\..*)?$/).describe('JSONPath from the source root: "$" is the whole source; "$.user.name", "$.items[0].sku" reach into it. Only reads from source data, not variables. For variables use $var, for navigating into variables use $get.')
26
- }).strict().describe("Read a value from the source data by static JSONPath. Use $ref for source access, $var for variables, $get for navigating into variables or dynamic paths.");
27
- var ConstNodeSchema = zod.z.object({
28
- $const: JsonValueSchema.describe("Any JSON value to return as-is.")
29
- }).strict().describe("Return a literal JSON value unchanged.");
30
- var VarNodeSchema = zod.z.object({
31
- $var: zod.z.string().min(1).describe("Variable name bound by $with, $map, $filter, $reduce, or $sortBy.")
32
- }).strict().describe("Read a scoped variable by name. Variables are created by $with (let bindings), $map/$filter/$reduce/$sortBy (loop element). Returns the whole variable \u2014 use $get to navigate into it.");
33
- var GetNodeSchema = zod.z.object({
34
- $get: zod.z.object({
35
- from: zod.z.lazy(node).describe("Source value to navigate into."),
36
- path: zod.z.array(zod.z.union([zod.z.string(), zod.z.number(), zod.z.lazy(node)])).min(1).describe("Path segments: string keys, numeric indices, or node expressions."),
37
- fallback: zod.z.lazy(node).optional().describe("Fallback value when path is missing.")
38
- }).strict()
39
- }).strict().describe('Navigate into a value by path. Use to access fields on variables: {$get: {from: {$var: "item"}, path: ["name"]}}. Also supports dynamic path segments (nodes as segments) and fallback values. Prefer $ref for simple source access.');
40
- var WithNodeSchema = zod.z.object({
41
- $with: zod.z.object({
42
- let: zod.z.record(zod.z.string(), zod.z.lazy(node)).describe("Variable bindings: name \u2192 expression evaluated in current scope."),
43
- value: zod.z.lazy(node).describe("Expression evaluated with the declared variables in scope.")
44
- }).strict()
45
- }).strict().describe("Bind variables in a scoped block: { $with: { let: { x: ... }, value: ... } }");
46
- var _NodeSchema2 = zod.z.any();
47
- var setNodeSchema2 = (schema) => {
48
- _NodeSchema2 = schema;
49
- };
50
- var node2 = () => _NodeSchema2;
51
- var MapNodeSchema = zod.z.object({
52
- $map: zod.z.object({
53
- over: zod.z.lazy(node2).describe("Array to iterate over."),
54
- as: zod.z.string().min(1).describe("Variable name for the current element."),
55
- body: zod.z.lazy(node2).describe("Expression evaluated for each element.")
56
- }).strict()
57
- }).strict().describe("Map over an array, transforming each element.");
58
- var FilterNodeSchema = zod.z.object({
59
- $filter: zod.z.object({
60
- over: zod.z.lazy(node2).describe("Array to filter."),
61
- as: zod.z.string().min(1).describe("Variable name for the current element."),
62
- when: zod.z.lazy(node2).describe("Condition \u2014 keeps element when truthy.")
63
- }).strict()
64
- }).strict().describe("Filter an array, keeping elements where condition is truthy.");
65
- var ReduceNodeSchema = zod.z.object({
66
- $reduce: zod.z.object({
67
- over: zod.z.lazy(node2).describe("Array to reduce."),
68
- as: zod.z.string().min(1).describe("Variable name for the current element."),
69
- acc: zod.z.string().min(1).optional().default("acc").describe('Accumulator variable name. Default: "acc".'),
70
- init: zod.z.lazy(node2).describe("Initial accumulator value."),
71
- body: zod.z.lazy(node2).describe("Expression evaluated for each element with both element and accumulator in scope.")
72
- }).strict()
73
- }).strict().describe("Reduce an array to a single value using an accumulator.");
74
- var SliceNodeSchema = zod.z.object({
75
- $slice: zod.z.object({
76
- from: zod.z.lazy(node2).describe("Array or string to slice."),
77
- start: zod.z.number().int().optional().describe("Start index (inclusive). Default: 0."),
78
- end: zod.z.number().int().optional().describe("End index (exclusive). Default: length.")
79
- }).strict()
80
- }).strict().describe("Slice an array or string by start/end indices.");
81
- var FlattenNodeSchema = zod.z.object({
82
- $flatten: zod.z.lazy(node2).describe("Array of arrays to flatten one level.")
83
- }).strict().describe("Flatten a nested array by one level.");
84
- var UniqueNodeSchema = zod.z.object({
85
- $unique: zod.z.lazy(node2).describe("Array to deduplicate.")
86
- }).strict().describe("Remove duplicate values from an array (compared by JSON.stringify).");
87
- var SortByNodeSchema = zod.z.object({
88
- $sortBy: zod.z.object({
89
- over: zod.z.lazy(node2).describe("Array to sort."),
90
- as: zod.z.string().min(1).describe("Variable name for the current element."),
91
- by: zod.z.lazy(node2).describe("Expression to compute the sort key."),
92
- dir: zod.z.enum(["asc", "desc"]).optional().default("asc").describe('Sort direction. Default: "asc".')
93
- }).strict()
94
- }).strict().describe("Sort an array by a computed key.");
95
- var _NodeSchema3 = zod.z.any();
96
- var setNodeSchema3 = (schema) => {
97
- _NodeSchema3 = schema;
98
- };
99
- var node3 = () => _NodeSchema3;
100
- var pairOf = (desc) => zod.z.tuple([zod.z.lazy(node3), zod.z.lazy(node3)]).describe(desc);
101
- var AddNodeSchema = zod.z.object({ $add: pairOf("Two numeric operands to add.") }).strict().describe("Add two numbers.");
102
- var SubNodeSchema = zod.z.object({ $sub: pairOf("Two numeric operands to subtract (a - b).") }).strict().describe("Subtract second number from first.");
103
- var MulNodeSchema = zod.z.object({ $mul: pairOf("Two numeric operands to multiply.") }).strict().describe("Multiply two numbers.");
104
- var DivNodeSchema = zod.z.object({ $div: pairOf("Two numeric operands to divide (a / b). Throws on division by zero.") }).strict().describe("Divide first number by second. Throws E_DIVISION_BY_ZERO if divisor is 0.");
105
- var RoundNodeSchema = zod.z.object({
106
- $round: zod.z.object({
107
- value: zod.z.lazy(node3).describe("Numeric value to round."),
108
- digits: zod.z.number().int().nonnegative().optional().default(0).describe("Decimal places. Default: 0.")
109
- }).strict()
110
- }).strict().describe("Round a number to N decimal places.");
111
- var _NodeSchema4 = zod.z.any();
112
- var setNodeSchema4 = (schema) => {
113
- _NodeSchema4 = schema;
114
- };
115
- var node4 = () => _NodeSchema4;
116
- var JoinNodeSchema = zod.z.object({
117
- $join: zod.z.object({
118
- parts: zod.z.lazy(node4).describe("Values to concatenate (coerced to string): a literal list of nodes, or any node that evaluates to an array \u2014 a mapped list, a $var."),
119
- sep: zod.z.string().optional().default("").describe('Separator between parts. Default: "".')
120
- }).strict()
121
- }).strict().describe("Concatenate values into a string with an optional separator.");
122
- var ToStringNodeSchema = zod.z.object({ $toString: zod.z.lazy(node4).describe("Value to stringify via String().") }).strict().describe("Convert a value to its string representation.");
123
- var InterpolateNodeSchema = zod.z.object({
124
- $interpolate: zod.z.object({
125
- template: zod.z.string().describe("Template with {{key}} placeholders."),
126
- values: zod.z.lazy(node4).describe("Object whose keys replace {{key}} placeholders.")
127
- }).strict()
128
- }).strict().describe("Replace {{key}} placeholders in a template with values from an object.");
129
- var FillNodeSchema = zod.z.object({
130
- $fill: zod.z.lazy(node4).describe("A pattern value `{ phrase, slots }` \u2014 filled with its own slots, source language. Non-patterns pass through.")
131
- }).strict().describe('Fill a counted phrase: `{ phrase: "{n} of {total}", slots: { n: 1, total: 12 } }` \u2192 "1 of 12".');
132
- var TrimNodeSchema = zod.z.object({ $trim: zod.z.lazy(node4).describe("String to trim whitespace from.") }).strict().describe("Trim leading and trailing whitespace from a string.");
133
- var LowerNodeSchema = zod.z.object({ $lower: zod.z.lazy(node4).describe("String to lowercase.") }).strict().describe("Convert a string to lowercase.");
134
- var UpperNodeSchema = zod.z.object({ $upper: zod.z.lazy(node4).describe("String to uppercase.") }).strict().describe("Convert a string to uppercase.");
135
- var SplitNodeSchema = zod.z.object({
136
- $split: zod.z.object({
137
- value: zod.z.lazy(node4).describe("String to split."),
138
- sep: zod.z.string().describe("Separator to split on.")
139
- }).strict()
140
- }).strict().describe("Split a string into an array by separator.");
141
- var ReplaceNodeSchema = zod.z.object({
142
- $replace: zod.z.object({
143
- value: zod.z.lazy(node4).describe("String to search in."),
144
- search: zod.z.string().describe("Substring to find."),
145
- replacement: zod.z.string().describe("Replacement string.")
146
- }).strict()
147
- }).strict().describe("Replace the first occurrence of a substring.");
148
- var _NodeSchema5 = zod.z.any();
149
- var setNodeSchema5 = (schema) => {
150
- _NodeSchema5 = schema;
151
- };
152
- var node5 = () => _NodeSchema5;
153
- var pairOf2 = (desc) => zod.z.tuple([zod.z.lazy(node5), zod.z.lazy(node5)]).describe(desc);
154
- var EqNodeSchema = zod.z.object({ $eq: pairOf2("Two values to compare for deep equality.") }).strict().describe("Deep equality comparison (JSON.stringify-based). Returns true or false.");
155
- var NeqNodeSchema = zod.z.object({ $neq: pairOf2("Two values to compare for inequality.") }).strict().describe("Deep inequality comparison. Returns true or false.");
156
- var GtNodeSchema = zod.z.object({ $gt: pairOf2("Two values: returns true if first > second (numbers or strings).") }).strict().describe("Greater than comparison for numbers or strings.");
157
- var GteNodeSchema = zod.z.object({ $gte: pairOf2("Two values: returns true if first >= second.") }).strict().describe("Greater than or equal comparison.");
158
- var LtNodeSchema = zod.z.object({ $lt: pairOf2("Two values: returns true if first < second.") }).strict().describe("Less than comparison.");
159
- var LteNodeSchema = zod.z.object({ $lte: pairOf2("Two values: returns true if first <= second.") }).strict().describe("Less than or equal comparison.");
160
- var EmptyNodeSchema = zod.z.object({ $empty: zod.z.lazy(node5).describe('Value to check for emptiness (null, "", [], {}).') }).strict().describe("Returns true if value is null, empty string, empty array, or empty object.");
161
- var StartsWithNodeSchema = zod.z.object({
162
- $startsWith: zod.z.object({
163
- value: zod.z.lazy(node5).describe("String to check."),
164
- prefix: zod.z.lazy(node5).describe("Expected prefix.")
165
- }).strict()
166
- }).strict().describe("Returns true if string starts with prefix.");
167
- var EndsWithNodeSchema = zod.z.object({
168
- $endsWith: zod.z.object({
169
- value: zod.z.lazy(node5).describe("String to check."),
170
- suffix: zod.z.lazy(node5).describe("Expected suffix.")
171
- }).strict()
172
- }).strict().describe("Returns true if string ends with suffix.");
173
- var ContainsNodeSchema = zod.z.object({
174
- $contains: zod.z.object({
175
- value: zod.z.lazy(node5).describe("String to search in."),
176
- search: zod.z.lazy(node5).describe("Substring to find.")
177
- }).strict()
178
- }).strict().describe("Returns true if string contains the search substring.");
179
- var _NodeSchema6 = zod.z.any();
180
- var setNodeSchema6 = (schema) => {
181
- _NodeSchema6 = schema;
182
- };
183
- var node6 = () => _NodeSchema6;
184
- var NotNodeSchema = zod.z.object({ $not: zod.z.lazy(node6).describe("Value to negate (truthy \u2192 false, falsy \u2192 true).") }).strict().describe("Boolean negation of a truthy/falsy value.");
185
- var AndNodeSchema = zod.z.object({
186
- $and: zod.z.array(zod.z.lazy(node6)).min(1).describe("Values to AND. Short-circuits: returns last truthy or first falsy.")
187
- }).strict().describe("Short-circuit logical AND.");
188
- var OrNodeSchema = zod.z.object({
189
- $or: zod.z.array(zod.z.lazy(node6)).min(1).describe("Values to OR. Short-circuits: returns first truthy or last falsy.")
190
- }).strict().describe("Short-circuit logical OR.");
191
- var _NodeSchema7 = zod.z.any();
192
- var setNodeSchema7 = (schema) => {
193
- _NodeSchema7 = schema;
194
- };
195
- var node7 = () => _NodeSchema7;
196
- var MergeNodeSchema = zod.z.object({
197
- $merge: zod.z.array(zod.z.lazy(node7)).min(1).describe("Objects to shallow-merge (left to right, later wins).")
198
- }).strict().describe("Shallow merge multiple objects. Later values overwrite earlier ones.");
199
- var CoalesceNodeSchema = zod.z.object({
200
- $coalesce: zod.z.array(zod.z.lazy(node7)).min(1).describe("Values to try in order. Returns first non-null/non-undefined.")
201
- }).strict().describe("Return the first non-null, non-undefined value.");
202
- var CaseNodeSchema = zod.z.object({
203
- $case: zod.z.object({
204
- branches: zod.z.array(
205
- zod.z.object({
206
- when: zod.z.lazy(node7).describe("Condition to evaluate."),
207
- then: zod.z.lazy(node7).describe("Value to return if condition is truthy.")
208
- }).strict()
209
- ).min(1).describe("Ordered list of when/then branches."),
210
- else: zod.z.lazy(node7).optional().describe("Fallback value if no branch matches. Default: null.")
211
- }).strict()
212
- }).strict().describe("Conditional branching: evaluates branches in order, returns first match or else.");
213
- var EntriesOfNodeSchema = zod.z.object({ $entriesOf: zod.z.lazy(node7).describe("Object to convert to [key, value][] entries.") }).strict().describe("Convert an object to an array of [key, value] pairs.");
214
- var KeyByNodeSchema = zod.z.object({
215
- $keyBy: zod.z.object({
216
- over: zod.z.lazy(node7).describe("Array to group."),
217
- as: zod.z.string().min(1).describe("Variable name for the current element."),
218
- key: zod.z.lazy(node7).describe("Expression to compute the key (last wins on collision).")
219
- }).strict()
220
- }).strict().describe("Convert an array to an object keyed by a computed value. Last element wins on key collision.");
221
- var GroupByNodeSchema = zod.z.object({
222
- $groupBy: zod.z.object({
223
- over: zod.z.lazy(node7).describe("Array to group."),
224
- as: zod.z.string().min(1).describe("Variable name for the current element."),
225
- key: zod.z.lazy(node7).describe("Expression to compute the group key.")
226
- }).strict()
227
- }).strict().describe("Group array elements into an object of arrays by computed key.");
228
- var _NodeSchema8 = zod.z.any();
229
- var setNodeSchema8 = (schema) => {
230
- _NodeSchema8 = schema;
231
- };
232
- var node8 = () => _NodeSchema8;
233
- var KeysNodeSchema = zod.z.object({ $keys: zod.z.lazy(node8).describe("Object to extract keys from.") }).strict().describe("Return the keys of an object as a string array.");
234
- var ValuesNodeSchema = zod.z.object({ $values: zod.z.lazy(node8).describe("Object to extract values from.") }).strict().describe("Return the values of an object as an array.");
235
- var FromEntriesNodeSchema = zod.z.object({
236
- $fromEntries: zod.z.lazy(node8).describe("Array of [key, value] pairs to convert to an object.")
237
- }).strict().describe("Convert [key, value][] entries into an object.");
238
- var PickNodeSchema = zod.z.object({
239
- $pick: zod.z.object({
240
- from: zod.z.lazy(node8).describe("Source object."),
241
- keys: zod.z.array(zod.z.string()).min(1).describe("Keys to keep.")
242
- }).strict()
243
- }).strict().describe("Pick specific keys from an object, discarding the rest.");
244
- var OmitNodeSchema = zod.z.object({
245
- $omit: zod.z.object({
246
- from: zod.z.lazy(node8).describe("Source object."),
247
- keys: zod.z.array(zod.z.string()).min(1).describe("Keys to remove.")
248
- }).strict()
249
- }).strict().describe("Remove specific keys from an object, keeping the rest.");
250
- var TypeNodeSchema = zod.z.object({ $type: zod.z.lazy(node8).describe("Value to get the type of.") }).strict().describe('Returns the type as a string: "string", "number", "boolean", "null", "array", or "object".');
251
- var LengthNodeSchema = zod.z.object({ $length: zod.z.lazy(node8).describe("Array or string to measure.") }).strict().describe("Return the length of an array or string.");
252
- var _NodeSchema9 = zod.z.any();
253
- var setNodeSchema9 = (schema) => {
254
- _NodeSchema9 = schema;
255
- };
256
- var node9 = () => _NodeSchema9;
257
- var TimeUnit = zod.z.enum(["year", "month", "day", "hour", "minute", "second"]).describe("Time unit for date arithmetic.");
258
- var DateNodeSchema = zod.z.object({
259
- $date: zod.z.object({
260
- value: zod.z.lazy(node9).describe("Date value (ISO string or timestamp)."),
261
- format: zod.z.string().optional().describe("Output format string (dayjs format). Default: ISO 8601."),
262
- utc: zod.z.boolean().optional().default(false).describe("Format in UTC. Default: false.")
263
- }).strict()
264
- }).strict().describe("Format a date value.");
265
- var DateAddNodeSchema = zod.z.object({
266
- $dateAdd: zod.z.object({
267
- date: zod.z.lazy(node9).describe("Base date (ISO string or timestamp)."),
268
- amount: zod.z.number().describe("Amount to add (can be negative)."),
269
- unit: TimeUnit
270
- }).strict()
271
- }).strict().describe("Add a duration to a date. Returns ISO string.");
272
- var DateDiffNodeSchema = zod.z.object({
273
- $dateDiff: zod.z.object({
274
- from: zod.z.lazy(node9).describe("Start date."),
275
- to: zod.z.lazy(node9).describe("End date."),
276
- unit: TimeUnit
277
- }).strict()
278
- }).strict().describe("Calculate difference between two dates. Returns a number.");
279
- var _NodeSchema10 = zod.z.any();
280
- var setNodeSchema10 = (schema) => {
281
- _NodeSchema10 = schema;
282
- };
283
- var node10 = () => _NodeSchema10;
284
- var localeField = zod.z.lazy(node10).describe('BCP-47 locale tag ("de-AT", "en-GB"). Required \u2014 a default renders plausible nonsense for everybody it is wrong for.');
285
- var fallbackField = zod.z.lazy(node10).optional().describe('Rendered when the value is null/undefined/empty. Default: "".');
286
- var DateStyle = zod.z.enum(["full", "long", "medium", "short"]);
287
- var IntlDateOptionsSchema = zod.z.object({
288
- dateStyle: DateStyle.optional().describe("Whole-date preset. Mutually exclusive with the field-by-field options below."),
289
- timeStyle: DateStyle.optional().describe("Whole-time preset. Mutually exclusive with the field-by-field options below."),
290
- weekday: zod.z.enum(["long", "short", "narrow"]).optional(),
291
- year: zod.z.enum(["numeric", "2-digit"]).optional(),
292
- month: zod.z.enum(["numeric", "2-digit", "long", "short", "narrow"]).optional(),
293
- day: zod.z.enum(["numeric", "2-digit"]).optional(),
294
- hour: zod.z.enum(["numeric", "2-digit"]).optional(),
295
- minute: zod.z.enum(["numeric", "2-digit"]).optional(),
296
- second: zod.z.enum(["numeric", "2-digit"]).optional(),
297
- hour12: zod.z.boolean().optional().describe("Force 12/24-hour. Omit to take the locale's own convention \u2014 which is the point of asking for a locale."),
298
- timeZone: zod.z.string().optional().describe('IANA zone. Omit and a DATE-only value ("2026-03-14") is read as UTC, which is what stops it rendering as the 13th west of Greenwich.')
299
- }).strict();
300
- var LocaleDateNodeSchema = zod.z.object({
301
- $localeDate: zod.z.object({
302
- value: zod.z.lazy(node10).describe("ISO string, DATE-only string, or epoch milliseconds."),
303
- locale: localeField,
304
- options: IntlDateOptionsSchema.optional().describe('Defaults to { dateStyle: "medium" }.'),
305
- fallback: fallbackField
306
- }).strict()
307
- }).strict().describe("Format a date for a human reading in a given locale (Intl.DateTimeFormat).");
308
- var LocaleMoneyNodeSchema = zod.z.object({
309
- $localeMoney: zod.z.object({
310
- value: zod.z.lazy(node10).describe("The amount. Minor units (cents) unless `minorUnits` is false."),
311
- currency: zod.z.lazy(node10).describe('ISO-4217 code \u2014 "EUR", "CHF". Required: an amount without one is a number, not money.'),
312
- locale: localeField,
313
- minorUnits: zod.z.boolean().optional().describe(
314
- "Value is in the currency's minor unit. Default true. The divisor comes from the CURRENCY, not a hardcoded 100 \u2014 JPY has no minor unit and dividing it would be a hundredfold error."
315
- ),
316
- digits: zod.z.number().int().min(0).max(20).optional().describe("Fraction digits. Default: the currency's own (2 for EUR, 0 for JPY)."),
317
- fallback: fallbackField
318
- }).strict()
319
- }).strict().describe("Format an amount as money in a given locale (Intl.NumberFormat, style currency).");
320
- var LocaleNumberNodeSchema = zod.z.object({
321
- $localeNumber: zod.z.object({
322
- value: zod.z.lazy(node10).describe("The number to format."),
323
- locale: localeField,
324
- style: zod.z.enum(["decimal", "percent"]).optional().describe('Default "decimal". "percent" multiplies by 100 \u2014 pass 0.42, not 42.'),
325
- digits: zod.z.number().int().min(0).max(20).optional().describe("Maximum fraction digits. Default: the locale's own."),
326
- minDigits: zod.z.number().int().min(0).max(20).optional().describe("Minimum fraction digits \u2014 for a column that should not ragged-edge."),
327
- compact: zod.z.boolean().optional().describe('Short form \u2014 "1.2K", "1,2 Tsd.". For a headline figure, never for money owed.'),
328
- fallback: fallbackField
329
- }).strict()
330
- }).strict().describe("Format a number in a given locale (Intl.NumberFormat).");
331
- var _NodeSchema11 = zod.z.any();
332
- var setNodeSchema11 = (schema) => {
333
- _NodeSchema11 = schema;
334
- };
335
- var node11 = () => _NodeSchema11;
336
- var overOnly = (desc) => zod.z.object({ over: zod.z.lazy(node11).describe(desc) }).strict();
337
- var SumNodeSchema = zod.z.object({ $sum: overOnly("Array of numbers to sum.") }).strict().describe("Sugar: sum all elements in an array. Desugars to $reduce + $add.");
338
- var AvgNodeSchema = zod.z.object({ $avg: overOnly("Array of numbers to average.") }).strict().describe("Sugar: average all elements in an array. Desugars to $div($sum, $count).");
339
- var CountNodeSchema = zod.z.object({ $count: overOnly("Array to count elements of.") }).strict().describe("Sugar: count elements in an array. Desugars to $reduce.");
340
- var MinNodeSchema = zod.z.object({ $min: overOnly("Array of numbers to find minimum.") }).strict().describe("Sugar: find minimum value in an array. Desugars to $reduce + $lt.");
341
- var MaxNodeSchema = zod.z.object({ $max: overOnly("Array of numbers to find maximum.") }).strict().describe("Sugar: find maximum value in an array. Desugars to $reduce + $gt.");
342
- var PluckNodeSchema = zod.z.object({
343
- $pluck: zod.z.object({
344
- over: zod.z.lazy(node11).describe("Array of objects to extract from."),
345
- key: zod.z.string().min(1).describe("Key to extract from each object.")
346
- }).strict()
347
- }).strict().describe("Sugar: extract a single field from each element. Desugars to $map + $get.");
348
- var TakeNodeSchema = zod.z.object({
349
- $take: zod.z.object({
350
- from: zod.z.lazy(node11).describe("Array to take from."),
351
- count: zod.z.number().int().nonnegative().describe("Number of elements to take from the start.")
352
- }).strict()
353
- }).strict().describe("Sugar: take first N elements. Desugars to $slice.");
354
- var DropNodeSchema = zod.z.object({
355
- $drop: zod.z.object({
356
- from: zod.z.lazy(node11).describe("Array to drop from."),
357
- count: zod.z.number().int().nonnegative().describe("Number of elements to skip from the start.")
358
- }).strict()
359
- }).strict().describe("Sugar: skip first N elements. Desugars to $slice.");
360
- var MatchNodeSchema = zod.z.object({
361
- $match: zod.z.object({
362
- over: zod.z.lazy(node11).describe("Array to search within."),
363
- as: zod.z.string().min(1).describe("Variable name for the current element."),
364
- search: zod.z.lazy(node11).describe("String to search for (uses $contains).")
365
- }).strict()
366
- }).strict().describe("Sugar: filter array by string containment. Desugars to $filter + $contains.");
367
- var FlatMapNodeSchema = zod.z.object({
368
- $flatMap: zod.z.object({
369
- over: zod.z.lazy(node11).describe("Array to flat-map over."),
370
- as: zod.z.string().min(1).describe("Variable name for the current element."),
371
- body: zod.z.lazy(node11).describe("Expression that returns an array for each element.")
372
- }).strict()
373
- }).strict().describe("Sugar: map then flatten one level. Desugars to $map + $flatten.");
374
- var _NodeSchema12 = zod.z.any();
375
- var setNodeSchema12 = (schema) => {
376
- _NodeSchema12 = schema;
377
- };
378
- var node12 = () => _NodeSchema12;
379
- var PathSchema = zod.z.array(zod.z.union([zod.z.string(), zod.z.number().int().nonnegative()])).min(1).describe("Literal path segments: object keys (strings) and array indexes (numbers).");
380
- var HasNodeSchema = zod.z.object({
381
- $has: zod.z.object({
382
- from: zod.z.lazy(node12).describe("The value to look into."),
383
- path: PathSchema
384
- }).strict()
385
- }).strict().describe("True when the whole path exists \u2014 a key present with a null value counts; a missing one does not.");
386
- var RenameKeysNodeSchema = zod.z.object({
387
- $renameKeys: zod.z.object({
388
- from: zod.z.lazy(node12).describe("The object whose keys to rename."),
389
- map: zod.z.record(zod.z.string(), zod.z.string()).describe("Old key \u2192 new key. Keys not listed, and listed keys that are absent, are left alone.")
390
- }).strict()
391
- }).strict().describe(
392
- "The object with keys renamed IN PLACE \u2014 each renamed key keeps its position. If a new name is already a key of the object, that entry is replaced by the renamed one."
393
- );
394
- var UpdateNodeSchema = zod.z.object({
395
- $update: zod.z.object({
396
- from: zod.z.lazy(node12).describe("The value to copy with one path changed."),
397
- path: PathSchema,
398
- value: zod.z.lazy(node12).describe("The new value at `path`. The value currently there (null when absent) is bound as `$var` `as`."),
399
- as: zod.z.string().min(1).optional().describe('The variable name the current value is bound to (default "current").')
400
- }).strict()
401
- }).strict().describe(
402
- "A copy of `from` with the value at `path` replaced and everything else identical. Missing objects along a string path are created; an index that does not exist is an error."
403
- );
404
- var AssertNodeSchema = zod.z.object({
405
- $assert: zod.z.object({
406
- when: zod.z.lazy(node12).describe("Must be truthy."),
407
- message: zod.z.string().min(1).describe("What went wrong, for a person \u2014 the whole error text."),
408
- value: zod.z.lazy(node12).describe("Returned when `when` holds.")
409
- }).strict()
410
- }).strict().describe("Fail with `message` (E_ASSERT) unless `when` is truthy; otherwise evaluate to `value`. How a migration refuses a shape it cannot handle.");
411
- var WalkNodeSchema = zod.z.object({
412
- $walk: zod.z.object({
413
- over: zod.z.lazy(node12).describe("The tree to rewrite \u2014 any JSON value."),
414
- as: zod.z.string().min(1).describe("The variable each visited node is bound to."),
415
- rules: zod.z.array(
416
- zod.z.object({
417
- when: zod.z.lazy(node12).describe("Evaluated with the node bound to `as`; the first truthy rule wins."),
418
- then: zod.z.lazy(node12).describe("The node's replacement.")
419
- }).strict()
420
- ).min(1).describe("Tried in order at every node. No rule matches: the node is kept."),
421
- order: zod.z.enum(["post", "pre"]).optional().describe(
422
- "post (default): a node's children are rewritten first, and its rules see the rewritten children. pre: rules see the node as it was, then the walk descends into whatever they returned."
423
- )
424
- }).strict()
425
- }).strict().describe(
426
- "Rewrite every node of a tree \u2014 objects, arrays and leaves, at any depth \u2014 by rules. Structural: it always terminates, and a replacement is never walked again at its own level."
427
- );
428
-
429
- // src/schemas/node.schema.ts
430
- var OP_KEYS = [
431
- "$ref",
432
- "$const",
433
- "$var",
434
- "$get",
435
- "$with",
436
- "$map",
437
- "$filter",
438
- "$reduce",
439
- "$slice",
440
- "$flatten",
441
- "$unique",
442
- "$sortBy",
443
- "$add",
444
- "$sub",
445
- "$mul",
446
- "$div",
447
- "$round",
448
- "$fill",
449
- "$join",
450
- "$toString",
451
- "$interpolate",
452
- "$trim",
453
- "$lower",
454
- "$upper",
455
- "$split",
456
- "$replace",
457
- "$eq",
458
- "$neq",
459
- "$gt",
460
- "$gte",
461
- "$lt",
462
- "$lte",
463
- "$empty",
464
- "$startsWith",
465
- "$endsWith",
466
- "$contains",
467
- "$not",
468
- "$and",
469
- "$or",
470
- "$merge",
471
- "$coalesce",
472
- "$case",
473
- "$entriesOf",
474
- "$keyBy",
475
- "$groupBy",
476
- "$keys",
477
- "$values",
478
- "$fromEntries",
479
- "$pick",
480
- "$omit",
481
- "$type",
482
- "$length",
483
- "$date",
484
- "$dateAdd",
485
- "$dateDiff",
486
- "$localeDate",
487
- "$localeMoney",
488
- "$localeNumber",
489
- "$sum",
490
- "$avg",
491
- "$count",
492
- "$min",
493
- "$max",
494
- "$pluck",
495
- "$take",
496
- "$drop",
497
- "$match",
498
- "$flatMap",
499
- "$has",
500
- "$renameKeys",
501
- "$update",
502
- "$assert",
503
- "$walk"
504
- ];
505
- var OPTIONAL_FIELDS_KEY = "__optional";
506
- var TEMPLATE_KEY = /^(?!\$)/;
507
- var isOpKey = (key) => OP_KEYS.some((op) => op === key);
508
- var templateKeyRefusal = (key) => isOpKey(key) ? "An op name cannot be a plain object key. Use the op itself." : 'Not a Prism op. A key that starts with "$" names an op; data with such a key goes in $const.';
509
- var hasValidOptionalMeta = (obj) => {
510
- const meta = obj[OPTIONAL_FIELDS_KEY];
511
- if (meta === void 0) return true;
512
- if (!Array.isArray(meta)) return false;
513
- return meta.every((f) => typeof f === "string" && f.length > 0);
514
- };
515
- var NodeSchema = zod.z.lazy(
516
- () => zod.z.union([
517
- // Core
518
- RefNodeSchema,
519
- ConstNodeSchema,
520
- VarNodeSchema,
521
- GetNodeSchema,
522
- WithNodeSchema,
523
- // Array
524
- MapNodeSchema,
525
- FilterNodeSchema,
526
- ReduceNodeSchema,
527
- SliceNodeSchema,
528
- FlattenNodeSchema,
529
- UniqueNodeSchema,
530
- SortByNodeSchema,
531
- // Math
532
- AddNodeSchema,
533
- SubNodeSchema,
534
- MulNodeSchema,
535
- DivNodeSchema,
536
- RoundNodeSchema,
537
- // String
538
- FillNodeSchema,
539
- JoinNodeSchema,
540
- ToStringNodeSchema,
541
- InterpolateNodeSchema,
542
- TrimNodeSchema,
543
- LowerNodeSchema,
544
- UpperNodeSchema,
545
- SplitNodeSchema,
546
- ReplaceNodeSchema,
547
- // Predicates
548
- EqNodeSchema,
549
- NeqNodeSchema,
550
- GtNodeSchema,
551
- GteNodeSchema,
552
- LtNodeSchema,
553
- LteNodeSchema,
554
- EmptyNodeSchema,
555
- StartsWithNodeSchema,
556
- EndsWithNodeSchema,
557
- ContainsNodeSchema,
558
- // Logic
559
- NotNodeSchema,
560
- AndNodeSchema,
561
- OrNodeSchema,
562
- // Structure
563
- MergeNodeSchema,
564
- CoalesceNodeSchema,
565
- CaseNodeSchema,
566
- EntriesOfNodeSchema,
567
- KeyByNodeSchema,
568
- GroupByNodeSchema,
569
- // Object
570
- KeysNodeSchema,
571
- ValuesNodeSchema,
572
- FromEntriesNodeSchema,
573
- PickNodeSchema,
574
- OmitNodeSchema,
575
- TypeNodeSchema,
576
- LengthNodeSchema,
577
- // Time
578
- DateNodeSchema,
579
- DateAddNodeSchema,
580
- DateDiffNodeSchema,
581
- // Locale-aware formatting
582
- LocaleDateNodeSchema,
583
- LocaleMoneyNodeSchema,
584
- LocaleNumberNodeSchema,
585
- // Sugar
586
- SumNodeSchema,
587
- AvgNodeSchema,
588
- CountNodeSchema,
589
- MinNodeSchema,
590
- MaxNodeSchema,
591
- PluckNodeSchema,
592
- TakeNodeSchema,
593
- DropNodeSchema,
594
- MatchNodeSchema,
595
- FlatMapNodeSchema,
596
- // Transform (rewriting a document)
597
- HasNodeSchema,
598
- RenameKeysNodeSchema,
599
- UpdateNodeSchema,
600
- AssertNodeSchema,
601
- WalkNodeSchema,
602
- // Primitives
603
- JsonPrimitiveSchema,
604
- // Arrays of nodes
605
- zod.z.array(zod.z.lazy(() => NodeSchema)),
606
- // Plain objects (no `$` keys, recursive values)
607
- // A `$` key is not a template key. Said in the KEY schema, not a
608
- // refinement: a refinement leaves this branch structurally matched, and
609
- // zod then reports its complaint instead of the union's — so a typo inside
610
- // a real op (`{ $get: { pathh } }`) read as "plain object must not contain
611
- // $ op keys" at the root. As a key pattern it is also plain JSON Schema
612
- // (`propertyNames`), which the grammar snapshot and agent prompts read.
613
- zod.z.record(zod.z.string().regex(TEMPLATE_KEY, { error: (issue) => templateKeyRefusal(issue.input) }), zod.z.lazy(() => NodeSchema)).refine((o) => hasValidOptionalMeta(o), { message: "__optional must be an array of non-empty field name strings." })
614
- ]).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
615
- );
616
- setNodeSchema(NodeSchema);
617
- setNodeSchema2(NodeSchema);
618
- setNodeSchema3(NodeSchema);
619
- setNodeSchema4(NodeSchema);
620
- setNodeSchema5(NodeSchema);
621
- setNodeSchema6(NodeSchema);
622
- setNodeSchema7(NodeSchema);
623
- setNodeSchema8(NodeSchema);
624
- setNodeSchema9(NodeSchema);
625
- setNodeSchema10(NodeSchema);
626
- setNodeSchema11(NodeSchema);
627
- setNodeSchema12(NodeSchema);
628
-
629
- // src/schemas/config.schema.ts
630
- var ConfigSchema = NodeSchema.describe(
631
- "A Prism config: the top-level transformation definition. Can be any valid node."
632
- );
633
-
634
- // src/utils/issues.ts
635
- var segmentsOf = (path) => path.map((p) => typeof p === "number" ? p : String(p));
636
- var explainOne = (issue, prefix) => {
637
- const here = [...prefix, ...segmentsOf(issue.path)];
638
- if (issue.code === "invalid_key") return [{ path: here, message: issue.issues[0]?.message ?? issue.message }];
639
- if (issue.code !== "invalid_union" || issue.errors.length === 0) return [{ path: here, message: issue.message }];
640
- let best = [];
641
- let bestDepth = -1;
642
- for (const branch of issue.errors) {
643
- const explained = branch.flatMap((i) => explainOne(i, here));
644
- const depth = Math.max(...explained.map((e) => e.path.length));
645
- if (depth > bestDepth || depth === bestDepth && explained.length < best.length) {
646
- best = explained;
647
- bestDepth = depth;
648
- }
649
- }
650
- return bestDepth <= here.length ? [{ path: here, message: "Not a Prism node: no op matches, and it is not a plain value." }] : best;
651
- };
652
- var explainIssues = (issues) => issues.flatMap((i) => explainOne(i, []));
653
-
654
- // src/errors.ts
655
- var ErrorCode = {
656
- SCHEMA: "E_SCHEMA",
657
- MISSING_PATH: "E_MISSING_PATH",
658
- TYPE: "E_TYPE",
659
- DIVISION_BY_ZERO: "E_DIVISION_BY_ZERO",
660
- DATE_INVALID: "E_DATE_INVALID",
661
- VAR_NOT_FOUND: "E_VAR_NOT_FOUND",
662
- NODE_SHAPE: "E_NODE_SHAPE",
663
- // A config's own `$assert` refused its input.
664
- ASSERT: "E_ASSERT",
665
- // An evaluation past its budget (engine/budget.ts).
666
- BUDGET: "E_BUDGET"
667
- };
668
- var PrismError = class extends Error {
669
- code;
670
- context;
671
- constructor(message, code, context) {
672
- super(message);
673
- this.name = "PrismError";
674
- this.code = code;
675
- this.context = context;
676
- }
677
- };
678
-
679
- // src/schemas/guards.ts
680
- var hasKey = (value, key) => typeof value === "object" && value !== null && !Array.isArray(value) && key in value;
681
- var isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
682
- var isJsonArray = (value) => Array.isArray(value);
683
- var isRefNode = (v) => hasKey(v, "$ref");
684
- var isConstNode = (v) => hasKey(v, "$const");
685
- var isVarNode = (v) => hasKey(v, "$var");
686
- var isGetNode = (v) => hasKey(v, "$get");
687
- var isWithNode = (v) => hasKey(v, "$with");
688
- var isMapNode = (v) => hasKey(v, "$map");
689
- var isFilterNode = (v) => hasKey(v, "$filter");
690
- var isReduceNode = (v) => hasKey(v, "$reduce");
691
- var isSliceNode = (v) => hasKey(v, "$slice");
692
- var isFlattenNode = (v) => hasKey(v, "$flatten");
693
- var isUniqueNode = (v) => hasKey(v, "$unique");
694
- var isSortByNode = (v) => hasKey(v, "$sortBy");
695
- var isAddNode = (v) => hasKey(v, "$add");
696
- var isSubNode = (v) => hasKey(v, "$sub");
697
- var isMulNode = (v) => hasKey(v, "$mul");
698
- var isDivNode = (v) => hasKey(v, "$div");
699
- var isRoundNode = (v) => hasKey(v, "$round");
700
- var isJoinNode = (v) => hasKey(v, "$join");
701
- var isToStringNode = (v) => hasKey(v, "$toString");
702
- var isInterpolateNode = (v) => hasKey(v, "$interpolate");
703
- var isFillNode = (v) => hasKey(v, "$fill");
704
- var isTrimNode = (v) => hasKey(v, "$trim");
705
- var isLowerNode = (v) => hasKey(v, "$lower");
706
- var isUpperNode = (v) => hasKey(v, "$upper");
707
- var isSplitNode = (v) => hasKey(v, "$split");
708
- var isReplaceNode = (v) => hasKey(v, "$replace");
709
- var isEqNode = (v) => hasKey(v, "$eq");
710
- var isNeqNode = (v) => hasKey(v, "$neq");
711
- var isGtNode = (v) => hasKey(v, "$gt");
712
- var isGteNode = (v) => hasKey(v, "$gte");
713
- var isLtNode = (v) => hasKey(v, "$lt");
714
- var isLteNode = (v) => hasKey(v, "$lte");
715
- var isEmptyNode = (v) => hasKey(v, "$empty");
716
- var isStartsWithNode = (v) => hasKey(v, "$startsWith");
717
- var isEndsWithNode = (v) => hasKey(v, "$endsWith");
718
- var isContainsNode = (v) => hasKey(v, "$contains");
719
- var isNotNode = (v) => hasKey(v, "$not");
720
- var isAndNode = (v) => hasKey(v, "$and");
721
- var isOrNode = (v) => hasKey(v, "$or");
722
- var isMergeNode = (v) => hasKey(v, "$merge");
723
- var isCoalesceNode = (v) => hasKey(v, "$coalesce");
724
- var isCaseNode = (v) => hasKey(v, "$case");
725
- var isEntriesOfNode = (v) => hasKey(v, "$entriesOf");
726
- var isKeyByNode = (v) => hasKey(v, "$keyBy");
727
- var isGroupByNode = (v) => hasKey(v, "$groupBy");
728
- var isKeysNode = (v) => hasKey(v, "$keys");
729
- var isValuesNode = (v) => hasKey(v, "$values");
730
- var isFromEntriesNode = (v) => hasKey(v, "$fromEntries");
731
- var isPickNode = (v) => hasKey(v, "$pick");
732
- var isOmitNode = (v) => hasKey(v, "$omit");
733
- var isHasNode = (v) => hasKey(v, "$has");
734
- var isRenameKeysNode = (v) => hasKey(v, "$renameKeys");
735
- var isUpdateNode = (v) => hasKey(v, "$update");
736
- var isAssertNode = (v) => hasKey(v, "$assert");
737
- var isWalkNode = (v) => hasKey(v, "$walk");
738
- var isTypeNode = (v) => hasKey(v, "$type");
739
- var isLengthNode = (v) => hasKey(v, "$length");
740
- var isDateNode = (v) => hasKey(v, "$date");
741
- var isDateAddNode = (v) => hasKey(v, "$dateAdd");
742
- var isDateDiffNode = (v) => hasKey(v, "$dateDiff");
743
- var isLocaleDateNode = (v) => hasKey(v, "$localeDate");
744
- var isLocaleMoneyNode = (v) => hasKey(v, "$localeMoney");
745
- var isLocaleNumberNode = (v) => hasKey(v, "$localeNumber");
746
- var isSumNode = (v) => hasKey(v, "$sum");
747
- var isAvgNode = (v) => hasKey(v, "$avg");
748
- var isCountNode = (v) => hasKey(v, "$count");
749
- var isMinNode = (v) => hasKey(v, "$min");
750
- var isMaxNode = (v) => hasKey(v, "$max");
751
- var isPluckNode = (v) => hasKey(v, "$pluck");
752
- var isTakeNode = (v) => hasKey(v, "$take");
753
- var isDropNode = (v) => hasKey(v, "$drop");
754
- var isMatchNode = (v) => hasKey(v, "$match");
755
- var isFlatMapNode = (v) => hasKey(v, "$flatMap");
756
- var isPlainObject = (value) => isJsonObject(value) && !Object.keys(value).some((k) => k.startsWith("$"));
757
-
758
- // src/sugar/rewriters.ts
759
- var rewriteSum = (node13, recurse) => ({
760
- $reduce: {
761
- over: recurse(node13.$sum.over),
762
- as: "__x",
763
- acc: "__acc",
764
- init: { $const: 0 },
765
- body: { $add: [{ $var: "__acc" }, { $var: "__x" }] }
766
- }
767
- });
768
- var rewriteCount = (node13, recurse) => ({
769
- $reduce: {
770
- over: recurse(node13.$count.over),
771
- as: "__x",
772
- acc: "__acc",
773
- init: { $const: 0 },
774
- body: { $add: [{ $var: "__acc" }, { $const: 1 }] }
775
- }
776
- });
777
- var rewriteAvg = (node13, recurse) => {
778
- const over = recurse(node13.$avg.over);
779
- return {
780
- $div: [
781
- {
782
- $reduce: {
783
- over,
784
- as: "__x",
785
- acc: "__acc",
786
- init: { $const: 0 },
787
- body: { $add: [{ $var: "__acc" }, { $var: "__x" }] }
788
- }
789
- },
790
- {
791
- $reduce: {
792
- over,
793
- as: "__x",
794
- acc: "__acc",
795
- init: { $const: 0 },
796
- body: { $add: [{ $var: "__acc" }, { $const: 1 }] }
797
- }
798
- }
799
- ]
800
- };
801
- };
802
- var rewriteMin = (node13, recurse) => ({
803
- $reduce: {
804
- over: recurse(node13.$min.over),
805
- as: "__x",
806
- acc: "__acc",
807
- init: { $const: null },
808
- body: {
809
- $case: {
810
- branches: [
811
- { when: { $eq: [{ $var: "__acc" }, null] }, then: { $var: "__x" } },
812
- { when: { $lt: [{ $var: "__x" }, { $var: "__acc" }] }, then: { $var: "__x" } }
813
- ],
814
- else: { $var: "__acc" }
815
- }
816
- }
817
- }
818
- });
819
- var rewriteMax = (node13, recurse) => ({
820
- $reduce: {
821
- over: recurse(node13.$max.over),
822
- as: "__x",
823
- acc: "__acc",
824
- init: { $const: null },
825
- body: {
826
- $case: {
827
- branches: [
828
- { when: { $eq: [{ $var: "__acc" }, null] }, then: { $var: "__x" } },
829
- { when: { $gt: [{ $var: "__x" }, { $var: "__acc" }] }, then: { $var: "__x" } }
830
- ],
831
- else: { $var: "__acc" }
832
- }
833
- }
834
- }
835
- });
836
- var rewritePluck = (node13, recurse) => ({
837
- $map: {
838
- over: recurse(node13.$pluck.over),
839
- as: "__item",
840
- body: { $get: { from: { $var: "__item" }, path: [node13.$pluck.key] } }
841
- }
842
- });
843
- var rewriteTake = (node13, recurse) => ({
844
- $slice: {
845
- from: recurse(node13.$take.from),
846
- start: 0,
847
- end: node13.$take.count
848
- }
849
- });
850
- var rewriteDrop = (node13, recurse) => ({
851
- $slice: {
852
- from: recurse(node13.$drop.from),
853
- start: node13.$drop.count
854
- }
855
- });
856
- var rewriteMatch = (node13, recurse) => ({
857
- $filter: {
858
- over: recurse(node13.$match.over),
859
- as: node13.$match.as,
860
- when: {
861
- $contains: {
862
- value: { $var: node13.$match.as },
863
- search: recurse(node13.$match.search)
864
- }
865
- }
866
- }
867
- });
868
- var rewriteFlatMap = (node13, recurse) => ({
869
- $flatten: {
870
- $map: {
871
- over: recurse(node13.$flatMap.over),
872
- as: node13.$flatMap.as,
873
- body: recurse(node13.$flatMap.body)
874
- }
875
- }
876
- });
877
-
878
- // src/sugar/desugar.ts
879
- var desugar = (node13) => {
880
- if (node13 === null || node13 === void 0) return node13;
881
- if (typeof node13 !== "object") return node13;
882
- if (Array.isArray(node13)) return node13.map(desugar);
883
- if (isSumNode(node13)) return rewriteSum(node13, desugar);
884
- if (isAvgNode(node13)) return rewriteAvg(node13, desugar);
885
- if (isCountNode(node13)) return rewriteCount(node13, desugar);
886
- if (isMinNode(node13)) return rewriteMin(node13, desugar);
887
- if (isMaxNode(node13)) return rewriteMax(node13, desugar);
888
- if (isPluckNode(node13)) return rewritePluck(node13, desugar);
889
- if (isTakeNode(node13)) return rewriteTake(node13, desugar);
890
- if (isDropNode(node13)) return rewriteDrop(node13, desugar);
891
- if (isMatchNode(node13)) return rewriteMatch(node13, desugar);
892
- if (isFlatMapNode(node13)) return rewriteFlatMap(node13, desugar);
893
- if (isJsonObject(node13)) {
894
- const result = {};
895
- for (const [key, value] of Object.entries(node13)) {
896
- result[key] = desugar(value);
897
- }
898
- return result;
899
- }
900
- return node13;
901
- };
902
-
903
- // src/engine/budget.ts
904
- var DEFAULT_LIMITS = { maxSteps: 1e6, maxStringLength: 1e6, maxValues: 1e6 };
905
- var createBudget = (limits) => ({ limits: { ...DEFAULT_LIMITS, ...limits }, steps: 0, sizes: /* @__PURE__ */ new WeakMap() });
906
- var refuse = (what, limit) => {
907
- throw new PrismError(`Evaluation stopped: ${what} (limit ${limit})`, ErrorCode.BUDGET, { details: { limit } });
908
- };
909
- var spendStep = (budget) => {
910
- budget.steps += 1;
911
- if (budget.steps > budget.limits.maxSteps) refuse("it evaluated too many nodes", budget.limits.maxSteps);
912
- };
913
- var sizeOf = (value, budget) => {
914
- if (value === null || typeof value !== "object") return 1;
915
- const known = budget.sizes.get(value);
916
- if (known !== void 0) return known;
917
- let size = 1;
918
- for (const inner of Array.isArray(value) ? value : Object.values(value)) {
919
- size += sizeOf(inner, budget);
920
- if (size > budget.limits.maxValues) break;
921
- }
922
- budget.sizes.set(value, size);
923
- return size;
924
- };
925
- var measureString = (value, budget) => {
926
- if (typeof value === "string" && value.length > budget.limits.maxStringLength) refuse(`a string of ${value.length} characters`, budget.limits.maxStringLength);
927
- };
928
- var measure = (value, budget) => {
929
- if (budget === void 0) return;
930
- measureString(value, budget);
931
- if (value !== null && typeof value === "object" && sizeOf(value, budget) > budget.limits.maxValues) {
932
- refuse("a result holding too many values", budget.limits.maxValues);
933
- }
934
- };
935
-
936
- // src/utils/jsonpath.ts
937
- var parseJsonPath = (path) => {
938
- if (!path.startsWith("$.")) return [];
939
- const segments = [];
940
- let cursor = 2;
941
- let currentKey = "";
942
- const pushKey = () => {
943
- if (currentKey.length > 0) {
944
- segments.push({ type: "key", key: currentKey });
945
- currentKey = "";
946
- }
947
- };
948
- while (cursor < path.length) {
949
- const char = path[cursor];
950
- if (char === ".") {
951
- pushKey();
952
- cursor++;
953
- continue;
954
- }
955
- if (char === "[") {
956
- pushKey();
957
- cursor++;
958
- let numBuf = "";
959
- while (cursor < path.length && path[cursor] !== "]") {
960
- numBuf += path[cursor];
961
- cursor++;
962
- }
963
- if (path[cursor] !== "]") return [];
964
- cursor++;
965
- const index = Number(numBuf);
966
- if (!Number.isInteger(index) || index < 0) return [];
967
- segments.push({ type: "index", index });
968
- continue;
969
- }
970
- currentKey += char;
971
- cursor++;
972
- }
973
- pushKey();
974
- return segments;
975
- };
976
- var cache = /* @__PURE__ */ new Map();
977
- var parseJsonPathCached = (path) => {
978
- const cached = cache.get(path);
979
- if (cached) return cached;
980
- const parsed = parseJsonPath(path);
981
- cache.set(path, parsed);
982
- return parsed;
983
- };
984
- var getByPath = (root, segments) => {
985
- let current2 = root;
986
- for (const segment of segments) {
987
- if (segment.type === "key") {
988
- if (!isJsonObject(current2)) return void 0;
989
- current2 = current2[segment.key];
990
- } else {
991
- if (!isJsonArray(current2)) return void 0;
992
- current2 = current2[segment.index];
993
- }
994
- }
995
- return current2;
996
- };
997
-
998
- // src/ops/core.ops.ts
999
- var SEGMENTS_KEY = "__segments";
1000
- var isSegmentsArray = (value) => Array.isArray(value);
1001
- var opRef = (node13, context, _evaluate) => {
1002
- const attached = Reflect.get(node13, SEGMENTS_KEY);
1003
- const segments = isSegmentsArray(attached) ? attached : parseJsonPathCached(node13.$ref);
1004
- const resolved = getByPath(context.source, segments);
1005
- if (resolved === void 0)
1006
- throw new PrismError("Path not found", ErrorCode.MISSING_PATH, { op: "$ref", path: node13.$ref });
1007
- return resolved;
1008
- };
1009
- var opConst = (node13, _context, _evaluate) => node13.$const;
1010
- var opVar = (node13, context, _evaluate) => {
1011
- const value = context.vars[node13.$var];
1012
- if (value === void 0)
1013
- throw new PrismError(`Variable not found: ${node13.$var}`, ErrorCode.VAR_NOT_FOUND, { op: "$var", path: node13.$var });
1014
- return value;
1015
- };
1016
- var opGet = (node13, context, evaluate2) => {
1017
- const { from, path, fallback } = node13.$get;
1018
- let current2 = evaluate2(from, context);
1019
- for (const segment of path) {
1020
- const evaluated = typeof segment === "object" && segment !== null ? evaluate2(segment, context) : segment;
1021
- if (typeof evaluated === "number") {
1022
- if (!isJsonArray(current2)) {
1023
- if (fallback !== void 0) return evaluate2(fallback, context);
1024
- throw new PrismError("Expected array for index access", ErrorCode.TYPE, { op: "$get" });
1025
- }
1026
- current2 = current2[evaluated];
1027
- } else {
1028
- const key = String(evaluated);
1029
- if (!isJsonObject(current2)) {
1030
- if (fallback !== void 0) return evaluate2(fallback, context);
1031
- throw new PrismError("Expected object for key access", ErrorCode.TYPE, { op: "$get" });
1032
- }
1033
- current2 = current2[key];
1034
- }
1035
- }
1036
- if (current2 === void 0) {
1037
- if (fallback !== void 0) return evaluate2(fallback, context);
1038
- throw new PrismError("Path not found", ErrorCode.MISSING_PATH, { op: "$get" });
1039
- }
1040
- return current2;
1041
- };
1042
- var opWith = (node13, context, evaluate2) => {
1043
- const { let: declarations, value } = node13.$with;
1044
- const extendedVars = { ...context.vars };
1045
- for (const [name, expr] of Object.entries(declarations)) {
1046
- extendedVars[name] = evaluate2(expr, context);
1047
- measure(extendedVars[name] ?? null, context.budget);
1048
- }
1049
- return evaluate2(value, { ...context, vars: extendedVars });
1050
- };
1051
-
1052
- // src/utils/compare.ts
1053
- var jsonEqual = (a, b) => JSON.stringify(a) === JSON.stringify(b);
1054
- var compare = (a, b) => {
1055
- if (typeof a === "number" && typeof b === "number") return a - b;
1056
- if (typeof a === "string" && typeof b === "string") return a < b ? -1 : a > b ? 1 : 0;
1057
- return void 0;
1058
- };
1059
-
1060
- // src/ops/array.ops.ts
1061
- var requireArray = (value, op) => {
1062
- if (!isJsonArray(value))
1063
- throw new PrismError(`Expected array for ${op}`, ErrorCode.TYPE, { op });
1064
- return value;
1065
- };
1066
- var opMap = (node13, context, evaluate2) => {
1067
- const { over, as, body } = node13.$map;
1068
- const input = requireArray(evaluate2(over, context), "$map.over");
1069
- const result = [];
1070
- for (const item of input) {
1071
- result.push(evaluate2(body, { ...context, vars: { ...context.vars, [as]: item } }));
1072
- }
1073
- return result;
1074
- };
1075
- var opFilter = (node13, context, evaluate2) => {
1076
- const { over, as, when } = node13.$filter;
1077
- const input = requireArray(evaluate2(over, context), "$filter.over");
1078
- const result = [];
1079
- for (const item of input) {
1080
- const condition = evaluate2(when, { ...context, vars: { ...context.vars, [as]: item } });
1081
- if (condition) result.push(item);
1082
- }
1083
- return result;
1084
- };
1085
- var opReduce = (node13, context, evaluate2) => {
1086
- const { over, as, acc: accName = "acc", init, body } = node13.$reduce;
1087
- const input = requireArray(evaluate2(over, context), "$reduce.over");
1088
- let accumulator = evaluate2(init, context);
1089
- for (const item of input) {
1090
- accumulator = evaluate2(body, {
1091
- ...context,
1092
- vars: { ...context.vars, [as]: item, [accName]: accumulator }
1093
- });
1094
- measure(accumulator, context.budget);
1095
- }
1096
- return accumulator;
1097
- };
1098
- var opSlice = (node13, context, evaluate2) => {
1099
- const { from, start, end } = node13.$slice;
1100
- const input = evaluate2(from, context);
1101
- if (typeof input === "string") return input.slice(start, end);
1102
- if (isJsonArray(input)) return input.slice(start, end);
1103
- throw new PrismError("Expected array or string for $slice", ErrorCode.TYPE, { op: "$slice" });
1104
- };
1105
- var opFlatten = (node13, context, evaluate2) => {
1106
- const input = requireArray(evaluate2(node13.$flatten, context), "$flatten");
1107
- const result = [];
1108
- for (const item of input) {
1109
- if (isJsonArray(item)) result.push(...item);
1110
- else result.push(item);
1111
- }
1112
- return result;
1113
- };
1114
- var opUnique = (node13, context, evaluate2) => {
1115
- const input = requireArray(evaluate2(node13.$unique, context), "$unique");
1116
- const seen = /* @__PURE__ */ new Set();
1117
- const result = [];
1118
- for (const item of input) {
1119
- const key = JSON.stringify(item);
1120
- if (!seen.has(key)) {
1121
- seen.add(key);
1122
- result.push(item);
1123
- }
1124
- }
1125
- return result;
1126
- };
1127
- var opSortBy = (node13, context, evaluate2) => {
1128
- const { over, as, by, dir = "asc" } = node13.$sortBy;
1129
- const input = requireArray(evaluate2(over, context), "$sortBy.over");
1130
- const keyed = input.map((item) => ({
1131
- item,
1132
- key: evaluate2(by, { ...context, vars: { ...context.vars, [as]: item } })
1133
- }));
1134
- keyed.sort((a, b) => {
1135
- const cmp = compare(a.key, b.key);
1136
- if (cmp === void 0) return 0;
1137
- return dir === "desc" ? -cmp : cmp;
1138
- });
1139
- return keyed.map((k) => k.item);
1140
- };
1141
-
1142
- // src/ops/math.ops.ts
1143
- var requireNumbers = (node13, context, evaluate2, op) => {
1144
- const a = evaluate2(node13[0], context);
1145
- const b = evaluate2(node13[1], context);
1146
- if (typeof a !== "number" || typeof b !== "number")
1147
- throw new PrismError(`Expected numbers for ${op}`, ErrorCode.TYPE, { op });
1148
- return [a, b];
1149
- };
1150
- var opAdd = (node13, context, evaluate2) => {
1151
- const [a, b] = requireNumbers(node13.$add, context, evaluate2, "$add");
1152
- return a + b;
1153
- };
1154
- var opSub = (node13, context, evaluate2) => {
1155
- const [a, b] = requireNumbers(node13.$sub, context, evaluate2, "$sub");
1156
- return a - b;
1157
- };
1158
- var opMul = (node13, context, evaluate2) => {
1159
- const [a, b] = requireNumbers(node13.$mul, context, evaluate2, "$mul");
1160
- return a * b;
1161
- };
1162
- var opDiv = (node13, context, evaluate2) => {
1163
- const [a, b] = requireNumbers(node13.$div, context, evaluate2, "$div");
1164
- if (b === 0) throw new PrismError("Division by zero", ErrorCode.DIVISION_BY_ZERO, { op: "$div" });
1165
- return a / b;
1166
- };
1167
- var opRound = (node13, context, evaluate2) => {
1168
- const value = evaluate2(node13.$round.value, context);
1169
- if (typeof value !== "number")
1170
- throw new PrismError("Expected number for $round", ErrorCode.TYPE, { op: "$round" });
1171
- const digits = node13.$round.digits ?? 0;
1172
- const factor = Math.pow(10, digits);
1173
- return Math.round(value * factor) / factor;
1174
- };
1175
-
1176
- // src/ops/string.ops.ts
1177
- var opJoin = (node13, context, evaluate2) => {
1178
- const { parts, sep = "" } = node13.$join;
1179
- const list = evaluate2(parts, context);
1180
- if (!Array.isArray(list)) throw new PrismError("Expected $join.parts to evaluate to an array", ErrorCode.TYPE, { op: "$join" });
1181
- return list.map((p) => String(p ?? "")).join(sep);
1182
- };
1183
- var opToString = (node13, context, evaluate2) => {
1184
- const value = evaluate2(node13.$toString, context);
1185
- if (value === null) return "null";
1186
- if (typeof value === "object") return JSON.stringify(value);
1187
- return String(value);
1188
- };
1189
- var opInterpolate = (node13, context, evaluate2) => {
1190
- const { template, values: valuesNode } = node13.$interpolate;
1191
- const values = evaluate2(valuesNode, context);
1192
- if (!isJsonObject(values))
1193
- throw new PrismError("Expected object for $interpolate.values", ErrorCode.TYPE, { op: "$interpolate" });
1194
- return template.replace(
1195
- /\{\{(\w+)\}\}/g,
1196
- (_match, key) => String(values[key] ?? "")
1197
- );
1198
- };
1199
- var fillOne = (value) => {
1200
- if (value === null || typeof value !== "object" || Array.isArray(value)) return value;
1201
- const { phrase, slots } = value;
1202
- if (typeof phrase !== "string" || !isJsonObject(slots)) return value;
1203
- return phrase.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (hole, name) => {
1204
- const slot = slots[name];
1205
- if (slot === void 0 || slot === null) return hole;
1206
- const filled = fillOne(slot);
1207
- return typeof filled === "object" ? hole : String(filled);
1208
- });
1209
- };
1210
- var opFill = (node13, context, evaluate2) => fillOne(evaluate2(node13.$fill, context));
1211
- var opTrim = (node13, context, evaluate2) => {
1212
- const value = evaluate2(node13.$trim, context);
1213
- if (typeof value !== "string")
1214
- throw new PrismError("Expected string for $trim", ErrorCode.TYPE, { op: "$trim" });
1215
- return value.trim();
1216
- };
1217
- var opLower = (node13, context, evaluate2) => {
1218
- const value = evaluate2(node13.$lower, context);
1219
- if (typeof value !== "string")
1220
- throw new PrismError("Expected string for $lower", ErrorCode.TYPE, { op: "$lower" });
1221
- return value.toLowerCase();
1222
- };
1223
- var opUpper = (node13, context, evaluate2) => {
1224
- const value = evaluate2(node13.$upper, context);
1225
- if (typeof value !== "string")
1226
- throw new PrismError("Expected string for $upper", ErrorCode.TYPE, { op: "$upper" });
1227
- return value.toUpperCase();
1228
- };
1229
- var opSplit = (node13, context, evaluate2) => {
1230
- const value = evaluate2(node13.$split.value, context);
1231
- if (typeof value !== "string")
1232
- throw new PrismError("Expected string for $split", ErrorCode.TYPE, { op: "$split" });
1233
- return value.split(node13.$split.sep);
1234
- };
1235
- var opReplace = (node13, context, evaluate2) => {
1236
- const value = evaluate2(node13.$replace.value, context);
1237
- if (typeof value !== "string")
1238
- throw new PrismError("Expected string for $replace", ErrorCode.TYPE, { op: "$replace" });
1239
- return value.replace(node13.$replace.search, node13.$replace.replacement);
1240
- };
1241
-
1242
- // src/ops/predicate.ops.ts
1243
- var opEq = (node13, context, evaluate2) => {
1244
- const a = evaluate2(node13.$eq[0], context);
1245
- const b = evaluate2(node13.$eq[1], context);
1246
- return jsonEqual(a, b);
1247
- };
1248
- var opNeq = (node13, context, evaluate2) => {
1249
- const a = evaluate2(node13.$neq[0], context);
1250
- const b = evaluate2(node13.$neq[1], context);
1251
- return !jsonEqual(a, b);
1252
- };
1253
- var compareOp = (pair, context, evaluate2, op, test) => {
1254
- const a = evaluate2(pair[0], context);
1255
- const b = evaluate2(pair[1], context);
1256
- const cmp = compare(a, b);
1257
- if (cmp === void 0)
1258
- throw new PrismError(`Cannot compare values for ${op}`, ErrorCode.TYPE, { op });
1259
- return test(cmp);
1260
- };
1261
- var opGt = (node13, ctx, ev) => compareOp(node13.$gt, ctx, ev, "$gt", (c) => c > 0);
1262
- var opGte = (node13, ctx, ev) => compareOp(node13.$gte, ctx, ev, "$gte", (c) => c >= 0);
1263
- var opLt = (node13, ctx, ev) => compareOp(node13.$lt, ctx, ev, "$lt", (c) => c < 0);
1264
- var opLte = (node13, ctx, ev) => compareOp(node13.$lte, ctx, ev, "$lte", (c) => c <= 0);
1265
- var opEmpty = (node13, context, evaluate2) => {
1266
- const value = evaluate2(node13.$empty, context);
1267
- if (value === null || value === void 0) return true;
1268
- if (typeof value === "string") return value.length === 0;
1269
- if (isJsonArray(value)) return value.length === 0;
1270
- if (isJsonObject(value)) return Object.keys(value).length === 0;
1271
- return false;
1272
- };
1273
- var opStartsWith = (node13, context, evaluate2) => {
1274
- const value = evaluate2(node13.$startsWith.value, context);
1275
- const prefix = evaluate2(node13.$startsWith.prefix, context);
1276
- if (typeof value !== "string" || typeof prefix !== "string")
1277
- throw new PrismError("Expected strings for $startsWith", ErrorCode.TYPE, { op: "$startsWith" });
1278
- return value.startsWith(prefix);
1279
- };
1280
- var opEndsWith = (node13, context, evaluate2) => {
1281
- const value = evaluate2(node13.$endsWith.value, context);
1282
- const suffix = evaluate2(node13.$endsWith.suffix, context);
1283
- if (typeof value !== "string" || typeof suffix !== "string")
1284
- throw new PrismError("Expected strings for $endsWith", ErrorCode.TYPE, { op: "$endsWith" });
1285
- return value.endsWith(suffix);
1286
- };
1287
- var opContains = (node13, context, evaluate2) => {
1288
- const value = evaluate2(node13.$contains.value, context);
1289
- const search = evaluate2(node13.$contains.search, context);
1290
- if (typeof value !== "string" || typeof search !== "string")
1291
- throw new PrismError("Expected strings for $contains", ErrorCode.TYPE, { op: "$contains" });
1292
- return value.includes(search);
1293
- };
1294
-
1295
- // src/ops/logic.ops.ts
1296
- var opNot = (node13, context, evaluate2) => !evaluate2(node13.$not, context);
1297
- var opAnd = (node13, context, evaluate2) => {
1298
- let last = true;
1299
- for (const operand of node13.$and) {
1300
- last = evaluate2(operand, context);
1301
- if (!last) return last;
1302
- }
1303
- return last;
1304
- };
1305
- var opOr = (node13, context, evaluate2) => {
1306
- let last = false;
1307
- for (const operand of node13.$or) {
1308
- last = evaluate2(operand, context);
1309
- if (last) return last;
1310
- }
1311
- return last;
1312
- };
1313
-
1314
- // src/ops/structure.ops.ts
1315
- var opMerge = (node13, context, evaluate2) => {
1316
- const result = {};
1317
- for (const part of node13.$merge) {
1318
- const evaluated = evaluate2(part, context);
1319
- if (!isJsonObject(evaluated))
1320
- throw new PrismError("Expected object for $merge element", ErrorCode.TYPE, { op: "$merge" });
1321
- Object.assign(result, evaluated);
1322
- }
1323
- return result;
1324
- };
1325
- var opCoalesce = (node13, context, evaluate2) => {
1326
- for (const candidate of node13.$coalesce) {
1327
- const value = evaluate2(candidate, context);
1328
- if (value !== null && value !== void 0) return value;
1329
- }
1330
- return null;
1331
- };
1332
- var opCase = (node13, context, evaluate2) => {
1333
- for (const branch of node13.$case.branches) {
1334
- const condition = evaluate2(branch.when, context);
1335
- if (condition) return evaluate2(branch.then, context);
1336
- }
1337
- if (node13.$case.else !== void 0) return evaluate2(node13.$case.else, context);
1338
- return null;
1339
- };
1340
- var opEntriesOf = (node13, context, evaluate2) => {
1341
- const value = evaluate2(node13.$entriesOf, context);
1342
- if (!isJsonObject(value))
1343
- throw new PrismError("Expected object for $entriesOf", ErrorCode.TYPE, { op: "$entriesOf" });
1344
- return Object.entries(value).map(([k, v]) => [k, v]);
1345
- };
1346
- var opKeyBy = (node13, context, evaluate2) => {
1347
- const { over, as, key: keyExpr } = node13.$keyBy;
1348
- const input = evaluate2(over, context);
1349
- if (!isJsonArray(input))
1350
- throw new PrismError("Expected array for $keyBy.over", ErrorCode.TYPE, { op: "$keyBy" });
1351
- const result = {};
1352
- for (const item of input) {
1353
- const key = evaluate2(keyExpr, { ...context, vars: { ...context.vars, [as]: item } });
1354
- result[String(key)] = item;
1355
- }
1356
- return result;
1357
- };
1358
- var opGroupBy = (node13, context, evaluate2) => {
1359
- const { over, as, key: keyExpr } = node13.$groupBy;
1360
- const input = evaluate2(over, context);
1361
- if (!isJsonArray(input))
1362
- throw new PrismError("Expected array for $groupBy.over", ErrorCode.TYPE, { op: "$groupBy" });
1363
- const result = {};
1364
- for (const item of input) {
1365
- const key = String(evaluate2(keyExpr, { ...context, vars: { ...context.vars, [as]: item } }));
1366
- if (!result[key]) result[key] = [];
1367
- result[key].push(item);
1368
- }
1369
- return result;
1370
- };
1371
-
1372
- // src/ops/object.ops.ts
1373
- var opKeys = (node13, context, evaluate2) => {
1374
- const value = evaluate2(node13.$keys, context);
1375
- if (!isJsonObject(value))
1376
- throw new PrismError("Expected object for $keys", ErrorCode.TYPE, { op: "$keys" });
1377
- return Object.keys(value);
1378
- };
1379
- var opValues = (node13, context, evaluate2) => {
1380
- const value = evaluate2(node13.$values, context);
1381
- if (!isJsonObject(value))
1382
- throw new PrismError("Expected object for $values", ErrorCode.TYPE, { op: "$values" });
1383
- return Object.values(value);
1384
- };
1385
- var opFromEntries = (node13, context, evaluate2) => {
1386
- const value = evaluate2(node13.$fromEntries, context);
1387
- if (!isJsonArray(value))
1388
- throw new PrismError("Expected array for $fromEntries", ErrorCode.TYPE, { op: "$fromEntries" });
1389
- const result = {};
1390
- for (const entry of value) {
1391
- if (!isJsonArray(entry) || entry.length < 2)
1392
- throw new PrismError("Expected [key, value] pairs for $fromEntries", ErrorCode.TYPE, { op: "$fromEntries" });
1393
- result[String(entry[0])] = entry[1];
1394
- }
1395
- return result;
1396
- };
1397
- var opPick = (node13, context, evaluate2) => {
1398
- const value = evaluate2(node13.$pick.from, context);
1399
- if (!isJsonObject(value))
1400
- throw new PrismError("Expected object for $pick", ErrorCode.TYPE, { op: "$pick" });
1401
- const result = {};
1402
- for (const key of node13.$pick.keys) {
1403
- if (key in value) result[key] = value[key];
1404
- }
1405
- return result;
1406
- };
1407
- var opOmit = (node13, context, evaluate2) => {
1408
- const value = evaluate2(node13.$omit.from, context);
1409
- if (!isJsonObject(value))
1410
- throw new PrismError("Expected object for $omit", ErrorCode.TYPE, { op: "$omit" });
1411
- const keysToOmit = new Set(node13.$omit.keys);
1412
- const result = {};
1413
- for (const [k, v] of Object.entries(value)) {
1414
- if (!keysToOmit.has(k)) result[k] = v;
1415
- }
1416
- return result;
1417
- };
1418
- var opType = (node13, context, evaluate2) => {
1419
- const value = evaluate2(node13.$type, context);
1420
- if (value === null) return "null";
1421
- if (isJsonArray(value)) return "array";
1422
- return typeof value;
1423
- };
1424
- var opLength = (node13, context, evaluate2) => {
1425
- const value = evaluate2(node13.$length, context);
1426
- if (typeof value === "string") return value.length;
1427
- if (isJsonArray(value)) return value.length;
1428
- throw new PrismError("Expected array or string for $length", ErrorCode.TYPE, { op: "$length" });
1429
- };
1430
-
1431
- // src/ops/transform.ops.ts
1432
- var has = (value, path) => {
1433
- let at = value;
1434
- for (const segment of path) {
1435
- if (typeof segment === "number") {
1436
- if (!isJsonArray(at) || segment >= at.length) return false;
1437
- at = at[segment] ?? null;
1438
- } else {
1439
- if (!isJsonObject(at) || !Object.prototype.hasOwnProperty.call(at, segment)) return false;
1440
- at = at[segment] ?? null;
1441
- }
1442
- }
1443
- return true;
1444
- };
1445
- var opHas = (node13, context, evaluate2) => has(evaluate2(node13.$has.from, context), node13.$has.path);
1446
- var opRenameKeys = (node13, context, evaluate2) => {
1447
- const value = evaluate2(node13.$renameKeys.from, context);
1448
- if (!isJsonObject(value)) throw new PrismError("Expected object for $renameKeys", ErrorCode.TYPE, { op: "$renameKeys" });
1449
- const { map } = node13.$renameKeys;
1450
- const renamedTo = new Set(Object.entries(map).filter(([from]) => Object.prototype.hasOwnProperty.call(value, from)).map(([, to]) => to));
1451
- const result = {};
1452
- for (const [key, v] of Object.entries(value)) {
1453
- const target = map[key];
1454
- if (target !== void 0) result[target] = v;
1455
- else if (!renamedTo.has(key)) result[key] = v;
1456
- }
1457
- return result;
1458
- };
1459
- var current = (value, path) => {
1460
- let at = value;
1461
- for (const segment of path) {
1462
- if (typeof segment === "number") at = isJsonArray(at) ? at[segment] ?? null : null;
1463
- else at = isJsonObject(at) ? at[segment] ?? null : null;
1464
- }
1465
- return at;
1466
- };
1467
- var setIn = (value, path, next, full) => {
1468
- const [head, ...rest] = path;
1469
- if (head === void 0) return next;
1470
- if (typeof head === "number") {
1471
- if (!isJsonArray(value) || head >= value.length) {
1472
- throw new PrismError(`No array item at ${full.join(".")}`, ErrorCode.MISSING_PATH, { op: "$update", path: full.join(".") });
1473
- }
1474
- return value.map((item, i) => i === head ? setIn(item, rest, next, full) : item);
1475
- }
1476
- const base = isJsonObject(value) ? value : {};
1477
- return { ...base, [head]: setIn(base[head] ?? null, rest, next, full) };
1478
- };
1479
- var opUpdate = (node13, context, evaluate2) => {
1480
- const { from, path, value, as } = node13.$update;
1481
- const source = evaluate2(from, context);
1482
- const next = evaluate2(value, { ...context, vars: { ...context.vars, [as ?? "current"]: current(source, path) } });
1483
- return setIn(source, path, next, path);
1484
- };
1485
- var opAssert = (node13, context, evaluate2) => {
1486
- if (!evaluate2(node13.$assert.when, context)) throw new PrismError(node13.$assert.message, ErrorCode.ASSERT, { op: "$assert" });
1487
- return evaluate2(node13.$assert.value, context);
1488
- };
1489
- var opWalk = (node13, context, evaluate2) => {
1490
- const { over, as, rules, order } = node13.$walk;
1491
- const rewrite = (value) => {
1492
- const scope = { ...context, vars: { ...context.vars, [as]: value } };
1493
- for (const rule of rules) {
1494
- if (evaluate2(rule.when, scope)) return { matched: true, value: evaluate2(rule.then, scope) };
1495
- }
1496
- return { matched: false, value };
1497
- };
1498
- const children = (value, visit) => {
1499
- if (isJsonArray(value)) return value.map(visit);
1500
- if (isJsonObject(value)) return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, visit(v)]));
1501
- return value;
1502
- };
1503
- const post = (value) => rewrite(children(value, post)).value;
1504
- const pre = (value) => children(rewrite(value).value, pre);
1505
- return (order ?? "post") === "pre" ? pre(evaluate2(over, context)) : post(evaluate2(over, context));
1506
- };
1507
- dayjs__default.default.extend(utc__default.default);
1508
- var DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/;
1509
- var isDateOnly = (value) => typeof value === "string" && DATE_ONLY.test(value);
1510
- var parseDate = (value, op) => {
1511
- if (typeof value !== "string" && typeof value !== "number")
1512
- throw new PrismError(`Expected string or number for ${op}`, ErrorCode.TYPE, { op });
1513
- const d = isDateOnly(value) ? dayjs__default.default.utc(value) : dayjs__default.default(value);
1514
- if (!d.isValid())
1515
- throw new PrismError(`Invalid date for ${op}: ${String(value)}`, ErrorCode.DATE_INVALID, { op });
1516
- return d;
1517
- };
1518
- var opDate = (node13, context, evaluate2) => {
1519
- const value = evaluate2(node13.$date.value, context);
1520
- const d = parseDate(value, "$date");
1521
- const instance = node13.$date.utc ? d.utc() : d;
1522
- if (node13.$date.format) return instance.format(node13.$date.format);
1523
- return instance.toISOString();
1524
- };
1525
- var opDateAdd = (node13, context, evaluate2) => {
1526
- const value = evaluate2(node13.$dateAdd.date, context);
1527
- const d = parseDate(value, "$dateAdd");
1528
- const moved = d.add(node13.$dateAdd.amount, node13.$dateAdd.unit);
1529
- return isDateOnly(value) ? moved.format("YYYY-MM-DD") : moved.toISOString();
1530
- };
1531
- var opDateDiff = (node13, context, evaluate2) => {
1532
- const from = evaluate2(node13.$dateDiff.from, context);
1533
- const to = evaluate2(node13.$dateDiff.to, context);
1534
- const fromDate = parseDate(from, "$dateDiff.from");
1535
- const toDate = parseDate(to, "$dateDiff.to");
1536
- return toDate.diff(fromDate, node13.$dateDiff.unit);
1537
- };
1538
-
1539
- // src/ops/intl.ops.ts
1540
- var DATE_FORMATTERS = /* @__PURE__ */ new Map();
1541
- var NUMBER_FORMATTERS = /* @__PURE__ */ new Map();
1542
- var DATE_ONLY2 = /^\d{4}-\d{2}-\d{2}$/;
1543
- var localeOf = (value, op) => {
1544
- if (typeof value !== "string" || value.trim() === "")
1545
- throw new PrismError(`${op} needs a locale tag (e.g. "de-AT")`, ErrorCode.TYPE, { op });
1546
- return value;
1547
- };
1548
- var isBlank = (value) => value === null || value === void 0 || value === "";
1549
- var fallbackOf = (raw, context, evaluate2) => {
1550
- if (raw === void 0) return "";
1551
- const resolved = evaluate2(raw, context);
1552
- return resolved === null || resolved === void 0 ? "" : resolved;
1553
- };
1554
- var numberOf = (value, op) => {
1555
- const parsed = typeof value === "number" ? value : Number(value);
1556
- if (!Number.isFinite(parsed)) throw new PrismError(`${op} expected a number, got ${JSON.stringify(value)}`, ErrorCode.TYPE, { op });
1557
- return parsed;
1558
- };
1559
- var opLocaleDate = (node13, context, evaluate2) => {
1560
- const spec = node13.$localeDate;
1561
- const value = evaluate2(spec.value, context);
1562
- if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
1563
- const locale = localeOf(evaluate2(spec.locale, context), "$localeDate");
1564
- const authored = spec.options ?? { dateStyle: "medium" };
1565
- const dateOnly = typeof value === "string" && DATE_ONLY2.test(value);
1566
- const options = {
1567
- ...authored,
1568
- ...authored.timeZone === void 0 && dateOnly ? { timeZone: "UTC" } : {}
1569
- };
1570
- const parsed = typeof value === "number" ? new Date(value) : new Date(String(value));
1571
- if (Number.isNaN(parsed.getTime()))
1572
- throw new PrismError(`Invalid date for $localeDate: ${String(value)}`, ErrorCode.DATE_INVALID, { op: "$localeDate" });
1573
- const key = `${locale}\0${JSON.stringify(options)}`;
1574
- let formatter = DATE_FORMATTERS.get(key);
1575
- if (formatter === void 0) {
1576
- formatter = new Intl.DateTimeFormat(locale, options);
1577
- DATE_FORMATTERS.set(key, formatter);
1578
- }
1579
- return formatter.format(parsed);
1580
- };
1581
- var minorUnitDivisor = (locale, currency) => {
1582
- const key = `divisor\0${locale}\0${currency}`;
1583
- let formatter = NUMBER_FORMATTERS.get(key);
1584
- if (formatter === void 0) {
1585
- try {
1586
- formatter = new Intl.NumberFormat(locale, { style: "currency", currency });
1587
- } catch {
1588
- return 100;
1589
- }
1590
- NUMBER_FORMATTERS.set(key, formatter);
1591
- }
1592
- return 10 ** (formatter.resolvedOptions().maximumFractionDigits ?? 2);
1593
- };
1594
- var opLocaleMoney = (node13, context, evaluate2) => {
1595
- const spec = node13.$localeMoney;
1596
- const value = evaluate2(spec.value, context);
1597
- if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
1598
- const locale = localeOf(evaluate2(spec.locale, context), "$localeMoney");
1599
- const rawCurrency = evaluate2(spec.currency, context);
1600
- if (typeof rawCurrency !== "string" || rawCurrency.trim() === "")
1601
- throw new PrismError("$localeMoney needs an ISO-4217 currency code", ErrorCode.TYPE, { op: "$localeMoney" });
1602
- const currency = rawCurrency.toUpperCase();
1603
- const amount = numberOf(value, "$localeMoney");
1604
- const major = spec.minorUnits === false ? amount : amount / minorUnitDivisor(locale, currency);
1605
- const options = {
1606
- style: "currency",
1607
- currency,
1608
- ...spec.digits === void 0 ? {} : { minimumFractionDigits: spec.digits, maximumFractionDigits: spec.digits }
1609
- };
1610
- const key = `${locale}\0${JSON.stringify(options)}`;
1611
- let formatter = NUMBER_FORMATTERS.get(key);
1612
- if (formatter === void 0) {
1613
- try {
1614
- formatter = new Intl.NumberFormat(locale, options);
1615
- } catch {
1616
- return `${currency} ${major.toFixed(spec.digits ?? 2)}`;
1617
- }
1618
- NUMBER_FORMATTERS.set(key, formatter);
1619
- }
1620
- return formatter.format(major);
1621
- };
1622
- var opLocaleNumber = (node13, context, evaluate2) => {
1623
- const spec = node13.$localeNumber;
1624
- const value = evaluate2(spec.value, context);
1625
- if (isBlank(value)) return fallbackOf(spec.fallback, context, evaluate2);
1626
- const locale = localeOf(evaluate2(spec.locale, context), "$localeNumber");
1627
- const options = {
1628
- style: spec.style ?? "decimal",
1629
- ...spec.digits === void 0 ? {} : { maximumFractionDigits: spec.digits },
1630
- ...spec.minDigits === void 0 ? {} : { minimumFractionDigits: spec.minDigits },
1631
- ...spec.compact === true ? { notation: "compact" } : {}
1632
- };
1633
- const key = `${locale}\0${JSON.stringify(options)}`;
1634
- let formatter = NUMBER_FORMATTERS.get(key);
1635
- if (formatter === void 0) {
1636
- formatter = new Intl.NumberFormat(locale, options);
1637
- NUMBER_FORMATTERS.set(key, formatter);
1638
- }
1639
- return formatter.format(numberOf(value, "$localeNumber"));
1640
- };
1641
-
1642
- // src/engine/evaluate.ts
1643
- var HANDLER_KEY = "__op";
1644
- var isAttachedFn = (value) => typeof value === "function";
1645
- var evaluateNode = (node13, context) => {
1646
- const { budget } = context;
1647
- if (budget === void 0) return evaluateUnbudgeted(node13, context);
1648
- spendStep(budget);
1649
- const out = evaluateUnbudgeted(node13, context);
1650
- measureString(out, budget);
1651
- return out;
1652
- };
1653
- var evaluateUnbudgeted = (node13, context) => {
1654
- if (node13 === null || node13 === void 0) return null;
1655
- if (typeof node13 === "string" || typeof node13 === "number" || typeof node13 === "boolean") return node13;
1656
- if (Array.isArray(node13)) return node13.map((n) => evaluateNode(n, context));
1657
- if (typeof node13 !== "object") return null;
1658
- const obj = node13;
1659
- const attached = obj[HANDLER_KEY];
1660
- if (isAttachedFn(attached)) return attached(obj, context, evaluateNode);
1661
- if (isRefNode(obj)) return opRef(obj, context);
1662
- if (isConstNode(obj)) return opConst(obj);
1663
- if (isVarNode(obj)) return opVar(obj, context);
1664
- if (isGetNode(obj)) return opGet(obj, context, evaluateNode);
1665
- if (isWithNode(obj)) return opWith(obj, context, evaluateNode);
1666
- if (isMapNode(obj)) return opMap(obj, context, evaluateNode);
1667
- if (isFilterNode(obj)) return opFilter(obj, context, evaluateNode);
1668
- if (isReduceNode(obj)) return opReduce(obj, context, evaluateNode);
1669
- if (isSliceNode(obj)) return opSlice(obj, context, evaluateNode);
1670
- if (isFlattenNode(obj)) return opFlatten(obj, context, evaluateNode);
1671
- if (isUniqueNode(obj)) return opUnique(obj, context, evaluateNode);
1672
- if (isSortByNode(obj)) return opSortBy(obj, context, evaluateNode);
1673
- if (isAddNode(obj)) return opAdd(obj, context, evaluateNode);
1674
- if (isSubNode(obj)) return opSub(obj, context, evaluateNode);
1675
- if (isMulNode(obj)) return opMul(obj, context, evaluateNode);
1676
- if (isDivNode(obj)) return opDiv(obj, context, evaluateNode);
1677
- if (isRoundNode(obj)) return opRound(obj, context, evaluateNode);
1678
- if (isJoinNode(obj)) return opJoin(obj, context, evaluateNode);
1679
- if (isToStringNode(obj)) return opToString(obj, context, evaluateNode);
1680
- if (isInterpolateNode(obj)) return opInterpolate(obj, context, evaluateNode);
1681
- if (isFillNode(obj)) return opFill(obj, context, evaluateNode);
1682
- if (isTrimNode(obj)) return opTrim(obj, context, evaluateNode);
1683
- if (isLowerNode(obj)) return opLower(obj, context, evaluateNode);
1684
- if (isUpperNode(obj)) return opUpper(obj, context, evaluateNode);
1685
- if (isSplitNode(obj)) return opSplit(obj, context, evaluateNode);
1686
- if (isReplaceNode(obj)) return opReplace(obj, context, evaluateNode);
1687
- if (isEqNode(obj)) return opEq(obj, context, evaluateNode);
1688
- if (isNeqNode(obj)) return opNeq(obj, context, evaluateNode);
1689
- if (isGtNode(obj)) return opGt(obj, context, evaluateNode);
1690
- if (isGteNode(obj)) return opGte(obj, context, evaluateNode);
1691
- if (isLtNode(obj)) return opLt(obj, context, evaluateNode);
1692
- if (isLteNode(obj)) return opLte(obj, context, evaluateNode);
1693
- if (isEmptyNode(obj)) return opEmpty(obj, context, evaluateNode);
1694
- if (isStartsWithNode(obj)) return opStartsWith(obj, context, evaluateNode);
1695
- if (isEndsWithNode(obj)) return opEndsWith(obj, context, evaluateNode);
1696
- if (isContainsNode(obj)) return opContains(obj, context, evaluateNode);
1697
- if (isNotNode(obj)) return opNot(obj, context, evaluateNode);
1698
- if (isAndNode(obj)) return opAnd(obj, context, evaluateNode);
1699
- if (isOrNode(obj)) return opOr(obj, context, evaluateNode);
1700
- if (isMergeNode(obj)) return opMerge(obj, context, evaluateNode);
1701
- if (isCoalesceNode(obj)) return opCoalesce(obj, context, evaluateNode);
1702
- if (isCaseNode(obj)) return opCase(obj, context, evaluateNode);
1703
- if (isEntriesOfNode(obj)) return opEntriesOf(obj, context, evaluateNode);
1704
- if (isKeyByNode(obj)) return opKeyBy(obj, context, evaluateNode);
1705
- if (isGroupByNode(obj)) return opGroupBy(obj, context, evaluateNode);
1706
- if (isKeysNode(obj)) return opKeys(obj, context, evaluateNode);
1707
- if (isValuesNode(obj)) return opValues(obj, context, evaluateNode);
1708
- if (isFromEntriesNode(obj)) return opFromEntries(obj, context, evaluateNode);
1709
- if (isPickNode(obj)) return opPick(obj, context, evaluateNode);
1710
- if (isOmitNode(obj)) return opOmit(obj, context, evaluateNode);
1711
- if (isTypeNode(obj)) return opType(obj, context, evaluateNode);
1712
- if (isLengthNode(obj)) return opLength(obj, context, evaluateNode);
1713
- if (isHasNode(obj)) return opHas(obj, context, evaluateNode);
1714
- if (isRenameKeysNode(obj)) return opRenameKeys(obj, context, evaluateNode);
1715
- if (isUpdateNode(obj)) return opUpdate(obj, context, evaluateNode);
1716
- if (isAssertNode(obj)) return opAssert(obj, context, evaluateNode);
1717
- if (isWalkNode(obj)) return opWalk(obj, context, evaluateNode);
1718
- if (isDateNode(obj)) return opDate(obj, context, evaluateNode);
1719
- if (isDateAddNode(obj)) return opDateAdd(obj, context, evaluateNode);
1720
- if (isDateDiffNode(obj)) return opDateDiff(obj, context, evaluateNode);
1721
- if (isLocaleDateNode(obj)) return opLocaleDate(obj, context, evaluateNode);
1722
- if (isLocaleMoneyNode(obj)) return opLocaleMoney(obj, context, evaluateNode);
1723
- if (isLocaleNumberNode(obj)) return opLocaleNumber(obj, context, evaluateNode);
1724
- if (isPlainObject(obj)) {
1725
- const optionalFields = new Set(
1726
- Array.isArray(obj[OPTIONAL_FIELDS_KEY]) ? obj[OPTIONAL_FIELDS_KEY] : []
1727
- );
1728
- const result = {};
1729
- for (const [key, value] of Object.entries(obj)) {
1730
- if (key === OPTIONAL_FIELDS_KEY) continue;
1731
- const isOptional = optionalFields.has(key);
1732
- try {
1733
- const evaluated = evaluateNode(value, context);
1734
- if (isOptional && (evaluated === null || evaluated === void 0)) continue;
1735
- result[key] = evaluated;
1736
- } catch (error) {
1737
- if (isOptional && error instanceof PrismError && error.code === ErrorCode.MISSING_PATH) continue;
1738
- throw error;
1739
- }
1740
- }
1741
- return result;
1742
- }
1743
- const unknownKeys = Object.keys(obj).filter((k) => k.startsWith("$"));
1744
- throw new PrismError("Unsupported node shape", ErrorCode.NODE_SHAPE, {
1745
- details: { keys: unknownKeys, preview: JSON.stringify(obj).slice(0, 100) }
1746
- });
1747
- };
1748
- var evaluate = (config, source, limits) => {
1749
- if (strata.exceedsDepth(config)) throw new PrismError("Invalid config", ErrorCode.SCHEMA, { details: { issues: [{ path: "root", message: strata.depthRefusal() }] } });
1750
- const parsed = ConfigSchema.safeParse(config);
1751
- if (!parsed.success) {
1752
- const issues = explainIssues(parsed.error.issues).map((i) => ({ path: i.path.join(".") || "root", message: i.message }));
1753
- throw new PrismError("Invalid config", ErrorCode.SCHEMA, { details: { issues } });
1754
- }
1755
- const desugared = desugar(parsed.data);
1756
- const budget = createBudget(limits);
1757
- const result = evaluateNode(desugared, { source, vars: {}, budget });
1758
- measure(result, budget);
1759
- return result;
1760
- };
3
+ var chunkV426VIRI_cjs = require('../chunk-V426VIRI.cjs');
4
+ var chunk26VYDHHC_cjs = require('../chunk-26VYDHHC.cjs');
1761
5
 
1762
6
  // src/migrations/index.ts
1763
7
  var PRISM_SEQUENCE = {
@@ -1784,25 +28,13 @@ var PRISM_SEQUENCE = {
1784
28
  }
1785
29
  ]
1786
30
  };
1787
- var isJsonValue = (value) => {
1788
- if (value === null || typeof value === "string" || typeof value === "boolean") return true;
1789
- if (typeof value === "number") return Number.isFinite(value);
1790
- if (Array.isArray(value)) return value.every(isJsonValue);
1791
- if (typeof value === "object") return Object.values(value).every(isJsonValue);
1792
- return false;
1793
- };
1794
- var parsedConfigs = /* @__PURE__ */ new WeakMap();
1795
- var prismTransform = (config, source) => {
1796
- if (!isJsonValue(source)) throw new Error("A document to migrate must be plain JSON.");
1797
- const cached = typeof config === "object" && config !== null ? parsedConfigs.get(config) : void 0;
1798
- const parsed = cached ?? ConfigSchema.parse(config);
1799
- if (cached === void 0 && typeof config === "object" && config !== null) parsedConfigs.set(config, parsed);
1800
- return evaluate(parsed, source);
1801
- };
1802
- var PRISM_SCHEMAS = { "nisc.prism/config": ConfigSchema };
31
+ var PRISM_SCHEMAS = { "nisc.prism/config": chunk26VYDHHC_cjs.ConfigSchema };
1803
32
 
33
+ Object.defineProperty(exports, "prismTransform", {
34
+ enumerable: true,
35
+ get: function () { return chunkV426VIRI_cjs.prismTransform; }
36
+ });
1804
37
  exports.PRISM_SCHEMAS = PRISM_SCHEMAS;
1805
38
  exports.PRISM_SEQUENCE = PRISM_SEQUENCE;
1806
- exports.prismTransform = prismTransform;
1807
39
  //# sourceMappingURL=index.cjs.map
1808
40
  //# sourceMappingURL=index.cjs.map