@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
|
@@ -1,18 +1,198 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var ErrorCode = {
|
|
5
|
+
SCHEMA: "E_SCHEMA",
|
|
6
|
+
MISSING_PATH: "E_MISSING_PATH",
|
|
7
|
+
TYPE: "E_TYPE",
|
|
8
|
+
DIVISION_BY_ZERO: "E_DIVISION_BY_ZERO",
|
|
9
|
+
DATE_INVALID: "E_DATE_INVALID",
|
|
10
|
+
VAR_NOT_FOUND: "E_VAR_NOT_FOUND",
|
|
11
|
+
NODE_SHAPE: "E_NODE_SHAPE",
|
|
12
|
+
ASSERT: "E_ASSERT",
|
|
13
|
+
BUDGET: "E_BUDGET"
|
|
14
|
+
};
|
|
15
|
+
var PrismError = class extends Error {
|
|
16
|
+
code;
|
|
17
|
+
context;
|
|
18
|
+
constructor(message, code, context) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "PrismError";
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.context = context;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
4
25
|
var JsonPrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).describe("JSON primitive: string | number | boolean | null");
|
|
5
26
|
var JsonValueSchema = z.lazy(
|
|
6
27
|
() => z.union([JsonPrimitiveSchema, z.array(JsonValueSchema), z.record(z.string(), JsonValueSchema)])
|
|
7
28
|
).describe("Any JSON value: primitive, array, or object");
|
|
8
29
|
z.record(z.string(), JsonValueSchema).describe("JSON object mapping string keys to JSON values");
|
|
30
|
+
|
|
31
|
+
// src/schemas/guards.ts
|
|
32
|
+
var hasKey = (value, key) => typeof value === "object" && value !== null && !Array.isArray(value) && key in value;
|
|
33
|
+
var isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
34
|
+
var isJsonArray = (value) => Array.isArray(value);
|
|
35
|
+
var isRefNode = (v) => hasKey(v, "$ref");
|
|
36
|
+
var isConstNode = (v) => hasKey(v, "$const");
|
|
37
|
+
var isVarNode = (v) => hasKey(v, "$var");
|
|
38
|
+
var isGetNode = (v) => hasKey(v, "$get");
|
|
39
|
+
var isWithNode = (v) => hasKey(v, "$with");
|
|
40
|
+
var isMapNode = (v) => hasKey(v, "$map");
|
|
41
|
+
var isFilterNode = (v) => hasKey(v, "$filter");
|
|
42
|
+
var isReduceNode = (v) => hasKey(v, "$reduce");
|
|
43
|
+
var isSliceNode = (v) => hasKey(v, "$slice");
|
|
44
|
+
var isFlattenNode = (v) => hasKey(v, "$flatten");
|
|
45
|
+
var isUniqueNode = (v) => hasKey(v, "$unique");
|
|
46
|
+
var isSortByNode = (v) => hasKey(v, "$sortBy");
|
|
47
|
+
var isAddNode = (v) => hasKey(v, "$add");
|
|
48
|
+
var isSubNode = (v) => hasKey(v, "$sub");
|
|
49
|
+
var isMulNode = (v) => hasKey(v, "$mul");
|
|
50
|
+
var isDivNode = (v) => hasKey(v, "$div");
|
|
51
|
+
var isRoundNode = (v) => hasKey(v, "$round");
|
|
52
|
+
var isModNode = (v) => hasKey(v, "$mod");
|
|
53
|
+
var isToNumberNode = (v) => hasKey(v, "$toNumber");
|
|
54
|
+
var isJoinNode = (v) => hasKey(v, "$join");
|
|
55
|
+
var isToStringNode = (v) => hasKey(v, "$toString");
|
|
56
|
+
var isInterpolateNode = (v) => hasKey(v, "$interpolate");
|
|
57
|
+
var isFillNode = (v) => hasKey(v, "$fill");
|
|
58
|
+
var isTrimNode = (v) => hasKey(v, "$trim");
|
|
59
|
+
var isLowerNode = (v) => hasKey(v, "$lower");
|
|
60
|
+
var isUpperNode = (v) => hasKey(v, "$upper");
|
|
61
|
+
var isSplitNode = (v) => hasKey(v, "$split");
|
|
62
|
+
var isReplaceNode = (v) => hasKey(v, "$replace");
|
|
63
|
+
var isEqNode = (v) => hasKey(v, "$eq");
|
|
64
|
+
var isNeqNode = (v) => hasKey(v, "$neq");
|
|
65
|
+
var isGtNode = (v) => hasKey(v, "$gt");
|
|
66
|
+
var isGteNode = (v) => hasKey(v, "$gte");
|
|
67
|
+
var isLtNode = (v) => hasKey(v, "$lt");
|
|
68
|
+
var isLteNode = (v) => hasKey(v, "$lte");
|
|
69
|
+
var isEmptyNode = (v) => hasKey(v, "$empty");
|
|
70
|
+
var isStartsWithNode = (v) => hasKey(v, "$startsWith");
|
|
71
|
+
var isEndsWithNode = (v) => hasKey(v, "$endsWith");
|
|
72
|
+
var isContainsNode = (v) => hasKey(v, "$contains");
|
|
73
|
+
var isNotNode = (v) => hasKey(v, "$not");
|
|
74
|
+
var isAndNode = (v) => hasKey(v, "$and");
|
|
75
|
+
var isOrNode = (v) => hasKey(v, "$or");
|
|
76
|
+
var isMergeNode = (v) => hasKey(v, "$merge");
|
|
77
|
+
var isCoalesceNode = (v) => hasKey(v, "$coalesce");
|
|
78
|
+
var isCaseNode = (v) => hasKey(v, "$case");
|
|
79
|
+
var isEntriesOfNode = (v) => hasKey(v, "$entriesOf");
|
|
80
|
+
var isKeyByNode = (v) => hasKey(v, "$keyBy");
|
|
81
|
+
var isGroupByNode = (v) => hasKey(v, "$groupBy");
|
|
82
|
+
var isKeysNode = (v) => hasKey(v, "$keys");
|
|
83
|
+
var isValuesNode = (v) => hasKey(v, "$values");
|
|
84
|
+
var isFromEntriesNode = (v) => hasKey(v, "$fromEntries");
|
|
85
|
+
var isPickNode = (v) => hasKey(v, "$pick");
|
|
86
|
+
var isOmitNode = (v) => hasKey(v, "$omit");
|
|
87
|
+
var isHasNode = (v) => hasKey(v, "$has");
|
|
88
|
+
var isRenameKeysNode = (v) => hasKey(v, "$renameKeys");
|
|
89
|
+
var isUpdateNode = (v) => hasKey(v, "$update");
|
|
90
|
+
var isAssertNode = (v) => hasKey(v, "$assert");
|
|
91
|
+
var isWalkNode = (v) => hasKey(v, "$walk");
|
|
92
|
+
var isTypeNode = (v) => hasKey(v, "$type");
|
|
93
|
+
var isLengthNode = (v) => hasKey(v, "$length");
|
|
94
|
+
var isDateNode = (v) => hasKey(v, "$date");
|
|
95
|
+
var isDateAddNode = (v) => hasKey(v, "$dateAdd");
|
|
96
|
+
var isDateDiffNode = (v) => hasKey(v, "$dateDiff");
|
|
97
|
+
var isLocaleDateNode = (v) => hasKey(v, "$localeDate");
|
|
98
|
+
var isLocaleMoneyNode = (v) => hasKey(v, "$localeMoney");
|
|
99
|
+
var isLocaleNumberNode = (v) => hasKey(v, "$localeNumber");
|
|
100
|
+
var isSumNode = (v) => hasKey(v, "$sum");
|
|
101
|
+
var isAvgNode = (v) => hasKey(v, "$avg");
|
|
102
|
+
var isCountNode = (v) => hasKey(v, "$count");
|
|
103
|
+
var isMinNode = (v) => hasKey(v, "$min");
|
|
104
|
+
var isMaxNode = (v) => hasKey(v, "$max");
|
|
105
|
+
var isPluckNode = (v) => hasKey(v, "$pluck");
|
|
106
|
+
var isTakeNode = (v) => hasKey(v, "$take");
|
|
107
|
+
var isDropNode = (v) => hasKey(v, "$drop");
|
|
108
|
+
var isMatchNode = (v) => hasKey(v, "$match");
|
|
109
|
+
var isFlatMapNode = (v) => hasKey(v, "$flatMap");
|
|
110
|
+
var isPlainObject = (value) => isJsonObject(value) && !Object.keys(value).some((k) => k.startsWith("$"));
|
|
111
|
+
|
|
112
|
+
// src/utils/jsonpath.ts
|
|
113
|
+
var pathRefusal = (path) => `Not a path Prism reads: "${path}". A path is keys and indexes only, as in $.rows[0].sku; for every item of a list use $map or $pluck.`;
|
|
114
|
+
var refuse = (path) => {
|
|
115
|
+
throw new PrismError(pathRefusal(path), ErrorCode.SCHEMA, { op: "$ref", path });
|
|
116
|
+
};
|
|
117
|
+
var isReadablePath = (path) => {
|
|
118
|
+
if (!path.includes("[") && !path.includes("..")) return true;
|
|
119
|
+
try {
|
|
120
|
+
parseJsonPath(path);
|
|
121
|
+
return true;
|
|
122
|
+
} catch {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var parseJsonPath = (path) => {
|
|
127
|
+
if (!path.startsWith("$.")) return [];
|
|
128
|
+
const segments = [];
|
|
129
|
+
let cursor = 2;
|
|
130
|
+
let currentKey = "";
|
|
131
|
+
const pushKey = () => {
|
|
132
|
+
if (currentKey.length > 0) {
|
|
133
|
+
segments.push({ type: "key", key: currentKey });
|
|
134
|
+
currentKey = "";
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
while (cursor < path.length) {
|
|
138
|
+
const char = path[cursor];
|
|
139
|
+
if (char === ".") {
|
|
140
|
+
if (path[cursor - 1] === ".") refuse(path);
|
|
141
|
+
pushKey();
|
|
142
|
+
cursor++;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (char === "[") {
|
|
146
|
+
pushKey();
|
|
147
|
+
cursor++;
|
|
148
|
+
let numBuf = "";
|
|
149
|
+
while (cursor < path.length && path[cursor] !== "]") {
|
|
150
|
+
numBuf += path[cursor];
|
|
151
|
+
cursor++;
|
|
152
|
+
}
|
|
153
|
+
if (path[cursor] !== "]") refuse(path);
|
|
154
|
+
cursor++;
|
|
155
|
+
const index = Number(numBuf);
|
|
156
|
+
if (numBuf.trim() === "" || !Number.isInteger(index) || index < 0) refuse(path);
|
|
157
|
+
segments.push({ type: "index", index });
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
currentKey += char;
|
|
161
|
+
cursor++;
|
|
162
|
+
}
|
|
163
|
+
pushKey();
|
|
164
|
+
return segments;
|
|
165
|
+
};
|
|
166
|
+
var cache = /* @__PURE__ */ new Map();
|
|
167
|
+
var parseJsonPathCached = (path) => {
|
|
168
|
+
const cached = cache.get(path);
|
|
169
|
+
if (cached) return cached;
|
|
170
|
+
const parsed = parseJsonPath(path);
|
|
171
|
+
cache.set(path, parsed);
|
|
172
|
+
return parsed;
|
|
173
|
+
};
|
|
174
|
+
var getByPath = (root, segments) => {
|
|
175
|
+
let current = root;
|
|
176
|
+
for (const segment of segments) {
|
|
177
|
+
if (segment.type === "key") {
|
|
178
|
+
if (!isJsonObject(current)) return void 0;
|
|
179
|
+
current = current[segment.key];
|
|
180
|
+
} else {
|
|
181
|
+
if (!isJsonArray(current)) return void 0;
|
|
182
|
+
current = current[segment.index];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return current;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/schemas/ops/core.schema.ts
|
|
9
189
|
var _NodeSchema = z.any();
|
|
10
190
|
var setNodeSchema = (schema) => {
|
|
11
191
|
_NodeSchema = schema;
|
|
12
192
|
};
|
|
13
193
|
var node = () => _NodeSchema;
|
|
14
194
|
var RefNodeSchema = z.object({
|
|
15
|
-
$ref: 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.')
|
|
195
|
+
$ref: z.string().regex(/^\$(\..*)?$/).refine(isReadablePath, { error: (issue) => pathRefusal(String(issue.input)) }).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.')
|
|
16
196
|
}).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.");
|
|
17
197
|
var ConstNodeSchema = z.object({
|
|
18
198
|
$const: JsonValueSchema.describe("Any JSON value to return as-is.")
|
|
@@ -92,12 +272,20 @@ var AddNodeSchema = z.object({ $add: pairOf("Two numeric operands to add.") }).s
|
|
|
92
272
|
var SubNodeSchema = z.object({ $sub: pairOf("Two numeric operands to subtract (a - b).") }).strict().describe("Subtract second number from first.");
|
|
93
273
|
var MulNodeSchema = z.object({ $mul: pairOf("Two numeric operands to multiply.") }).strict().describe("Multiply two numbers.");
|
|
94
274
|
var DivNodeSchema = 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.");
|
|
275
|
+
var ModNodeSchema = z.object({ $mod: pairOf("Two numeric operands: the remainder of a divided by b. Throws on division by zero.") }).strict().describe("The remainder of the first number divided by the second, with the sign of the second: for a positive divisor n it is always from 0 up to n, also for a negative first number. Throws E_DIVISION_BY_ZERO if divisor is 0.");
|
|
95
276
|
var RoundNodeSchema = z.object({
|
|
96
277
|
$round: z.object({
|
|
97
278
|
value: z.lazy(node3).describe("Numeric value to round."),
|
|
98
|
-
digits: z.number().int().nonnegative().optional().default(0).describe("Decimal places. Default: 0.")
|
|
279
|
+
digits: z.number().int().nonnegative().optional().default(0).describe("Decimal places. Default: 0."),
|
|
280
|
+
mode: z.enum(["nearest", "floor", "ceil"]).optional().describe('Which way to round: "nearest" (the default), "floor" (down, toward negative infinity) or "ceil" (up).')
|
|
99
281
|
}).strict()
|
|
100
|
-
}).strict().describe(
|
|
282
|
+
}).strict().describe('Round a number to N decimal places: to the nearest, or down ("floor") or up ("ceil") with `mode`.');
|
|
283
|
+
var ToNumberNodeSchema = z.object({
|
|
284
|
+
$toNumber: z.object({
|
|
285
|
+
value: z.lazy(node3).describe('A number, or text that is a number written in digits: "42", "-3.5", " 1e3 ".'),
|
|
286
|
+
fallback: z.lazy(node3).optional().describe("What to answer when the value is not a number and not such text. Without it that is an error.")
|
|
287
|
+
}).strict()
|
|
288
|
+
}).strict().describe("A number from a number or from numeric text, as data from a form, a CSV or an API often has it. Anything else (other text, true, null, an object) throws E_TYPE unless `fallback` is given.");
|
|
101
289
|
var _NodeSchema4 = z.any();
|
|
102
290
|
var setNodeSchema4 = (schema) => {
|
|
103
291
|
_NodeSchema4 = schema;
|
|
@@ -132,9 +320,10 @@ var ReplaceNodeSchema = z.object({
|
|
|
132
320
|
$replace: z.object({
|
|
133
321
|
value: z.lazy(node4).describe("String to search in."),
|
|
134
322
|
search: z.string().describe("Substring to find."),
|
|
135
|
-
replacement: z.string().describe("Replacement string.")
|
|
323
|
+
replacement: z.string().describe("Replacement string."),
|
|
324
|
+
all: z.boolean().optional().describe("true replaces every occurrence. Default: only the first.")
|
|
136
325
|
}).strict()
|
|
137
|
-
}).strict().describe("Replace the first occurrence of a substring
|
|
326
|
+
}).strict().describe("Replace the first occurrence of a substring, or every occurrence with `all: true`.");
|
|
138
327
|
var _NodeSchema5 = z.any();
|
|
139
328
|
var setNodeSchema5 = (schema) => {
|
|
140
329
|
_NodeSchema5 = schema;
|
|
@@ -434,7 +623,9 @@ var OP_KEYS = [
|
|
|
434
623
|
"$sub",
|
|
435
624
|
"$mul",
|
|
436
625
|
"$div",
|
|
626
|
+
"$mod",
|
|
437
627
|
"$round",
|
|
628
|
+
"$toNumber",
|
|
438
629
|
"$fill",
|
|
439
630
|
"$join",
|
|
440
631
|
"$toString",
|
|
@@ -502,15 +693,67 @@ var hasValidOptionalMeta = (obj) => {
|
|
|
502
693
|
if (!Array.isArray(meta)) return false;
|
|
503
694
|
return meta.every((f) => typeof f === "string" && f.length > 0);
|
|
504
695
|
};
|
|
696
|
+
var NodeArraySchema = z.array(z.lazy(() => NodeSchema));
|
|
697
|
+
var TemplateSchema = z.record(z.string().regex(TEMPLATE_KEY, { error: (issue) => templateKeyRefusal(issue.input) }), z.lazy(() => NodeSchema)).refine((o) => hasValidOptionalMeta(o), { message: "__optional must be an array of non-empty field name strings." });
|
|
698
|
+
var opMembersOf = (options) => {
|
|
699
|
+
const members = /* @__PURE__ */ new Map();
|
|
700
|
+
for (const option of options) {
|
|
701
|
+
const { def } = option._zod;
|
|
702
|
+
const keys = "shape" in def && typeof def.shape === "object" && def.shape !== null ? Object.keys(def.shape) : [];
|
|
703
|
+
const [key] = keys;
|
|
704
|
+
if (keys.length === 1 && key !== void 0 && isOpKey(key)) members.set(key, option);
|
|
705
|
+
}
|
|
706
|
+
return members;
|
|
707
|
+
};
|
|
708
|
+
var memberOf = (value, ops) => {
|
|
709
|
+
if (value === null || typeof value !== "object") return JsonPrimitiveSchema;
|
|
710
|
+
if (Array.isArray(value)) return NodeArraySchema;
|
|
711
|
+
const proto = Object.getPrototypeOf(value);
|
|
712
|
+
if (proto !== Object.prototype && proto !== null) return void 0;
|
|
713
|
+
let op;
|
|
714
|
+
let count = 0;
|
|
715
|
+
for (const key in value) {
|
|
716
|
+
count += 1;
|
|
717
|
+
if (key.startsWith("$")) op = key;
|
|
718
|
+
}
|
|
719
|
+
if (op === void 0) return TemplateSchema;
|
|
720
|
+
return count === 1 ? ops.get(op) : void 0;
|
|
721
|
+
};
|
|
722
|
+
var quick = /* @__PURE__ */ new WeakSet();
|
|
723
|
+
var walking = /* @__PURE__ */ new WeakSet();
|
|
724
|
+
var NodeUnion = z.core.$constructor("PrismNodeUnion", (inst, def) => {
|
|
725
|
+
z.ZodUnion.init(inst, def);
|
|
726
|
+
const ops = opMembersOf(def.options);
|
|
727
|
+
const walk = inst._zod.parse;
|
|
728
|
+
inst._zod.parse = (payload, ctx) => {
|
|
729
|
+
if (ctx.async !== false || walking.has(ctx)) return walk(payload, ctx);
|
|
730
|
+
const member = memberOf(payload.value, ops);
|
|
731
|
+
if (quick.has(ctx)) {
|
|
732
|
+
if (member !== void 0) return member._zod.run(payload, ctx);
|
|
733
|
+
payload.issues.push({ code: "custom", input: payload.value, inst });
|
|
734
|
+
return payload;
|
|
735
|
+
}
|
|
736
|
+
if (member !== void 0) {
|
|
737
|
+
const own = { async: false, ...ctx.jitless === void 0 ? {} : { jitless: ctx.jitless } };
|
|
738
|
+
quick.add(own);
|
|
739
|
+
const tried = member._zod.run({ value: payload.value, issues: [] }, own);
|
|
740
|
+
if (!(tried instanceof Promise) && tried.issues.length === 0) return tried;
|
|
741
|
+
}
|
|
742
|
+
walking.add(ctx);
|
|
743
|
+
try {
|
|
744
|
+
return walk(payload, ctx);
|
|
745
|
+
} finally {
|
|
746
|
+
walking.delete(ctx);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
});
|
|
505
750
|
var NodeSchema = z.lazy(
|
|
506
|
-
() =>
|
|
507
|
-
// Core
|
|
751
|
+
() => new NodeUnion({ type: "union", options: [
|
|
508
752
|
RefNodeSchema,
|
|
509
753
|
ConstNodeSchema,
|
|
510
754
|
VarNodeSchema,
|
|
511
755
|
GetNodeSchema,
|
|
512
756
|
WithNodeSchema,
|
|
513
|
-
// Array
|
|
514
757
|
MapNodeSchema,
|
|
515
758
|
FilterNodeSchema,
|
|
516
759
|
ReduceNodeSchema,
|
|
@@ -518,13 +761,13 @@ var NodeSchema = z.lazy(
|
|
|
518
761
|
FlattenNodeSchema,
|
|
519
762
|
UniqueNodeSchema,
|
|
520
763
|
SortByNodeSchema,
|
|
521
|
-
// Math
|
|
522
764
|
AddNodeSchema,
|
|
523
765
|
SubNodeSchema,
|
|
524
766
|
MulNodeSchema,
|
|
525
767
|
DivNodeSchema,
|
|
768
|
+
ModNodeSchema,
|
|
526
769
|
RoundNodeSchema,
|
|
527
|
-
|
|
770
|
+
ToNumberNodeSchema,
|
|
528
771
|
FillNodeSchema,
|
|
529
772
|
JoinNodeSchema,
|
|
530
773
|
ToStringNodeSchema,
|
|
@@ -534,7 +777,6 @@ var NodeSchema = z.lazy(
|
|
|
534
777
|
UpperNodeSchema,
|
|
535
778
|
SplitNodeSchema,
|
|
536
779
|
ReplaceNodeSchema,
|
|
537
|
-
// Predicates
|
|
538
780
|
EqNodeSchema,
|
|
539
781
|
NeqNodeSchema,
|
|
540
782
|
GtNodeSchema,
|
|
@@ -545,18 +787,15 @@ var NodeSchema = z.lazy(
|
|
|
545
787
|
StartsWithNodeSchema,
|
|
546
788
|
EndsWithNodeSchema,
|
|
547
789
|
ContainsNodeSchema,
|
|
548
|
-
// Logic
|
|
549
790
|
NotNodeSchema,
|
|
550
791
|
AndNodeSchema,
|
|
551
792
|
OrNodeSchema,
|
|
552
|
-
// Structure
|
|
553
793
|
MergeNodeSchema,
|
|
554
794
|
CoalesceNodeSchema,
|
|
555
795
|
CaseNodeSchema,
|
|
556
796
|
EntriesOfNodeSchema,
|
|
557
797
|
KeyByNodeSchema,
|
|
558
798
|
GroupByNodeSchema,
|
|
559
|
-
// Object
|
|
560
799
|
KeysNodeSchema,
|
|
561
800
|
ValuesNodeSchema,
|
|
562
801
|
FromEntriesNodeSchema,
|
|
@@ -564,15 +803,12 @@ var NodeSchema = z.lazy(
|
|
|
564
803
|
OmitNodeSchema,
|
|
565
804
|
TypeNodeSchema,
|
|
566
805
|
LengthNodeSchema,
|
|
567
|
-
// Time
|
|
568
806
|
DateNodeSchema,
|
|
569
807
|
DateAddNodeSchema,
|
|
570
808
|
DateDiffNodeSchema,
|
|
571
|
-
// Locale-aware formatting
|
|
572
809
|
LocaleDateNodeSchema,
|
|
573
810
|
LocaleMoneyNodeSchema,
|
|
574
811
|
LocaleNumberNodeSchema,
|
|
575
|
-
// Sugar
|
|
576
812
|
SumNodeSchema,
|
|
577
813
|
AvgNodeSchema,
|
|
578
814
|
CountNodeSchema,
|
|
@@ -583,25 +819,15 @@ var NodeSchema = z.lazy(
|
|
|
583
819
|
DropNodeSchema,
|
|
584
820
|
MatchNodeSchema,
|
|
585
821
|
FlatMapNodeSchema,
|
|
586
|
-
// Transform (rewriting a document)
|
|
587
822
|
HasNodeSchema,
|
|
588
823
|
RenameKeysNodeSchema,
|
|
589
824
|
UpdateNodeSchema,
|
|
590
825
|
AssertNodeSchema,
|
|
591
826
|
WalkNodeSchema,
|
|
592
|
-
// Primitives
|
|
593
827
|
JsonPrimitiveSchema,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
// A `$` key is not a template key. Said in the KEY schema, not a
|
|
598
|
-
// refinement: a refinement leaves this branch structurally matched, and
|
|
599
|
-
// zod then reports its complaint instead of the union's — so a typo inside
|
|
600
|
-
// a real op (`{ $get: { pathh } }`) read as "plain object must not contain
|
|
601
|
-
// $ op keys" at the root. As a key pattern it is also plain JSON Schema
|
|
602
|
-
// (`propertyNames`), which the grammar snapshot and agent prompts read.
|
|
603
|
-
z.record(z.string().regex(TEMPLATE_KEY, { error: (issue) => templateKeyRefusal(issue.input) }), z.lazy(() => NodeSchema)).refine((o) => hasValidOptionalMeta(o), { message: "__optional must be an array of non-empty field name strings." })
|
|
604
|
-
]).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
|
|
828
|
+
NodeArraySchema,
|
|
829
|
+
TemplateSchema
|
|
830
|
+
] }).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
|
|
605
831
|
);
|
|
606
832
|
setNodeSchema(NodeSchema);
|
|
607
833
|
setNodeSchema2(NodeSchema);
|
|
@@ -619,85 +845,6 @@ var ConfigSchema = NodeSchema.describe(
|
|
|
619
845
|
"A Prism config: the top-level transformation definition. Can be any valid node."
|
|
620
846
|
);
|
|
621
847
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
var isJsonArray = (value) => Array.isArray(value);
|
|
626
|
-
var isRefNode = (v) => hasKey(v, "$ref");
|
|
627
|
-
var isConstNode = (v) => hasKey(v, "$const");
|
|
628
|
-
var isVarNode = (v) => hasKey(v, "$var");
|
|
629
|
-
var isGetNode = (v) => hasKey(v, "$get");
|
|
630
|
-
var isWithNode = (v) => hasKey(v, "$with");
|
|
631
|
-
var isMapNode = (v) => hasKey(v, "$map");
|
|
632
|
-
var isFilterNode = (v) => hasKey(v, "$filter");
|
|
633
|
-
var isReduceNode = (v) => hasKey(v, "$reduce");
|
|
634
|
-
var isSliceNode = (v) => hasKey(v, "$slice");
|
|
635
|
-
var isFlattenNode = (v) => hasKey(v, "$flatten");
|
|
636
|
-
var isUniqueNode = (v) => hasKey(v, "$unique");
|
|
637
|
-
var isSortByNode = (v) => hasKey(v, "$sortBy");
|
|
638
|
-
var isAddNode = (v) => hasKey(v, "$add");
|
|
639
|
-
var isSubNode = (v) => hasKey(v, "$sub");
|
|
640
|
-
var isMulNode = (v) => hasKey(v, "$mul");
|
|
641
|
-
var isDivNode = (v) => hasKey(v, "$div");
|
|
642
|
-
var isRoundNode = (v) => hasKey(v, "$round");
|
|
643
|
-
var isJoinNode = (v) => hasKey(v, "$join");
|
|
644
|
-
var isToStringNode = (v) => hasKey(v, "$toString");
|
|
645
|
-
var isInterpolateNode = (v) => hasKey(v, "$interpolate");
|
|
646
|
-
var isFillNode = (v) => hasKey(v, "$fill");
|
|
647
|
-
var isTrimNode = (v) => hasKey(v, "$trim");
|
|
648
|
-
var isLowerNode = (v) => hasKey(v, "$lower");
|
|
649
|
-
var isUpperNode = (v) => hasKey(v, "$upper");
|
|
650
|
-
var isSplitNode = (v) => hasKey(v, "$split");
|
|
651
|
-
var isReplaceNode = (v) => hasKey(v, "$replace");
|
|
652
|
-
var isEqNode = (v) => hasKey(v, "$eq");
|
|
653
|
-
var isNeqNode = (v) => hasKey(v, "$neq");
|
|
654
|
-
var isGtNode = (v) => hasKey(v, "$gt");
|
|
655
|
-
var isGteNode = (v) => hasKey(v, "$gte");
|
|
656
|
-
var isLtNode = (v) => hasKey(v, "$lt");
|
|
657
|
-
var isLteNode = (v) => hasKey(v, "$lte");
|
|
658
|
-
var isEmptyNode = (v) => hasKey(v, "$empty");
|
|
659
|
-
var isStartsWithNode = (v) => hasKey(v, "$startsWith");
|
|
660
|
-
var isEndsWithNode = (v) => hasKey(v, "$endsWith");
|
|
661
|
-
var isContainsNode = (v) => hasKey(v, "$contains");
|
|
662
|
-
var isNotNode = (v) => hasKey(v, "$not");
|
|
663
|
-
var isAndNode = (v) => hasKey(v, "$and");
|
|
664
|
-
var isOrNode = (v) => hasKey(v, "$or");
|
|
665
|
-
var isMergeNode = (v) => hasKey(v, "$merge");
|
|
666
|
-
var isCoalesceNode = (v) => hasKey(v, "$coalesce");
|
|
667
|
-
var isCaseNode = (v) => hasKey(v, "$case");
|
|
668
|
-
var isEntriesOfNode = (v) => hasKey(v, "$entriesOf");
|
|
669
|
-
var isKeyByNode = (v) => hasKey(v, "$keyBy");
|
|
670
|
-
var isGroupByNode = (v) => hasKey(v, "$groupBy");
|
|
671
|
-
var isKeysNode = (v) => hasKey(v, "$keys");
|
|
672
|
-
var isValuesNode = (v) => hasKey(v, "$values");
|
|
673
|
-
var isFromEntriesNode = (v) => hasKey(v, "$fromEntries");
|
|
674
|
-
var isPickNode = (v) => hasKey(v, "$pick");
|
|
675
|
-
var isOmitNode = (v) => hasKey(v, "$omit");
|
|
676
|
-
var isHasNode = (v) => hasKey(v, "$has");
|
|
677
|
-
var isRenameKeysNode = (v) => hasKey(v, "$renameKeys");
|
|
678
|
-
var isUpdateNode = (v) => hasKey(v, "$update");
|
|
679
|
-
var isAssertNode = (v) => hasKey(v, "$assert");
|
|
680
|
-
var isWalkNode = (v) => hasKey(v, "$walk");
|
|
681
|
-
var isTypeNode = (v) => hasKey(v, "$type");
|
|
682
|
-
var isLengthNode = (v) => hasKey(v, "$length");
|
|
683
|
-
var isDateNode = (v) => hasKey(v, "$date");
|
|
684
|
-
var isDateAddNode = (v) => hasKey(v, "$dateAdd");
|
|
685
|
-
var isDateDiffNode = (v) => hasKey(v, "$dateDiff");
|
|
686
|
-
var isLocaleDateNode = (v) => hasKey(v, "$localeDate");
|
|
687
|
-
var isLocaleMoneyNode = (v) => hasKey(v, "$localeMoney");
|
|
688
|
-
var isLocaleNumberNode = (v) => hasKey(v, "$localeNumber");
|
|
689
|
-
var isSumNode = (v) => hasKey(v, "$sum");
|
|
690
|
-
var isAvgNode = (v) => hasKey(v, "$avg");
|
|
691
|
-
var isCountNode = (v) => hasKey(v, "$count");
|
|
692
|
-
var isMinNode = (v) => hasKey(v, "$min");
|
|
693
|
-
var isMaxNode = (v) => hasKey(v, "$max");
|
|
694
|
-
var isPluckNode = (v) => hasKey(v, "$pluck");
|
|
695
|
-
var isTakeNode = (v) => hasKey(v, "$take");
|
|
696
|
-
var isDropNode = (v) => hasKey(v, "$drop");
|
|
697
|
-
var isMatchNode = (v) => hasKey(v, "$match");
|
|
698
|
-
var isFlatMapNode = (v) => hasKey(v, "$flatMap");
|
|
699
|
-
var isPlainObject = (value) => isJsonObject(value) && !Object.keys(value).some((k) => k.startsWith("$"));
|
|
700
|
-
|
|
701
|
-
export { ConfigSchema, NodeSchema, OPTIONAL_FIELDS_KEY, OP_KEYS, isAddNode, isAndNode, isAssertNode, isAvgNode, isCaseNode, isCoalesceNode, isConstNode, isContainsNode, isCountNode, isDateAddNode, isDateDiffNode, isDateNode, isDivNode, isDropNode, isEmptyNode, isEndsWithNode, isEntriesOfNode, isEqNode, isFillNode, isFilterNode, isFlatMapNode, isFlattenNode, isFromEntriesNode, isGetNode, isGroupByNode, isGtNode, isGteNode, isHasNode, isInterpolateNode, isJoinNode, isJsonArray, isJsonObject, isKeyByNode, isKeysNode, isLengthNode, isLocaleDateNode, isLocaleMoneyNode, isLocaleNumberNode, isLowerNode, isLtNode, isLteNode, isMapNode, isMatchNode, isMaxNode, isMergeNode, isMinNode, isMulNode, isNeqNode, isNotNode, isOmitNode, isOrNode, isPickNode, isPlainObject, isPluckNode, isReduceNode, isRefNode, isRenameKeysNode, isReplaceNode, isRoundNode, isSliceNode, isSortByNode, isSplitNode, isStartsWithNode, isSubNode, isSumNode, isTakeNode, isToStringNode, isTrimNode, isTypeNode, isUniqueNode, isUpdateNode, isUpperNode, isValuesNode, isVarNode, isWalkNode, isWithNode };
|
|
702
|
-
//# sourceMappingURL=chunk-O3OJAQWA.js.map
|
|
703
|
-
//# sourceMappingURL=chunk-O3OJAQWA.js.map
|
|
848
|
+
export { ConfigSchema, ErrorCode, NodeSchema, OPTIONAL_FIELDS_KEY, OP_KEYS, PrismError, getByPath, isAddNode, isAndNode, isAssertNode, isAvgNode, isCaseNode, isCoalesceNode, isConstNode, isContainsNode, isCountNode, isDateAddNode, isDateDiffNode, isDateNode, isDivNode, isDropNode, isEmptyNode, isEndsWithNode, isEntriesOfNode, isEqNode, isFillNode, isFilterNode, isFlatMapNode, isFlattenNode, isFromEntriesNode, isGetNode, isGroupByNode, isGtNode, isGteNode, isHasNode, isInterpolateNode, isJoinNode, isJsonArray, isJsonObject, isKeyByNode, isKeysNode, isLengthNode, isLocaleDateNode, isLocaleMoneyNode, isLocaleNumberNode, isLowerNode, isLtNode, isLteNode, isMapNode, isMatchNode, isMaxNode, isMergeNode, isMinNode, isModNode, isMulNode, isNeqNode, isNotNode, isOmitNode, isOrNode, isPickNode, isPlainObject, isPluckNode, isReduceNode, isRefNode, isRenameKeysNode, isReplaceNode, isRoundNode, isSliceNode, isSortByNode, isSplitNode, isStartsWithNode, isSubNode, isSumNode, isTakeNode, isToNumberNode, isToStringNode, isTrimNode, isTypeNode, isUniqueNode, isUpdateNode, isUpperNode, isValuesNode, isVarNode, isWalkNode, isWithNode, parseJsonPath, parseJsonPathCached };
|
|
849
|
+
//# sourceMappingURL=chunk-WKS4OCKN.js.map
|
|
850
|
+
//# sourceMappingURL=chunk-WKS4OCKN.js.map
|