@niscorp/prism 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +203 -0
- package/DESIGN.md +9 -8
- package/DOCS.md +71 -26
- package/README.md +45 -24
- package/dist/agent.cjs +7 -9
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.js +5 -7
- package/dist/agent.js.map +1 -1
- package/dist/{chunk-26VYDHHC.cjs → chunk-6PD7M2F3.cjs} +266 -112
- package/dist/chunk-6PD7M2F3.cjs.map +1 -0
- package/dist/{chunk-XRK55NPE.js → chunk-GK4CIKKT.js} +5 -10
- package/dist/chunk-GK4CIKKT.js.map +1 -0
- package/dist/{chunk-W32JXP33.cjs → chunk-OWKINPR5.cjs} +7 -12
- package/dist/chunk-OWKINPR5.cjs.map +1 -0
- package/dist/{chunk-O3OJAQWA.js → chunk-WKS4OCKN.js} +260 -113
- package/dist/chunk-WKS4OCKN.js.map +1 -0
- package/dist/examples/index.cjs +25 -2
- package/dist/examples/index.cjs.map +1 -1
- package/dist/examples/index.d.cts +1 -1
- package/dist/examples/index.d.ts +1 -1
- package/dist/examples/index.js +25 -2
- package/dist/examples/index.js.map +1 -1
- package/dist/index.cjs +1223 -139
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +1119 -28
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.cjs +8 -17
- package/dist/migrations/index.cjs.map +1 -1
- package/dist/migrations/index.d.cts +0 -2
- package/dist/migrations/index.d.ts +0 -2
- package/dist/migrations/index.js +7 -12
- package/dist/migrations/index.js.map +1 -1
- package/dist/{profiles-C6r-x-Vj.d.cts → profiles-CPVfysxC.d.cts} +2 -1
- package/dist/{profiles-C6r-x-Vj.d.ts → profiles-CPVfysxC.d.ts} +2 -1
- package/package.json +7 -7
- package/dist/chunk-26VYDHHC.cjs.map +0 -1
- package/dist/chunk-O3OJAQWA.js.map +0 -1
- package/dist/chunk-V426VIRI.cjs +0 -1168
- package/dist/chunk-V426VIRI.cjs.map +0 -1
- package/dist/chunk-VC4PRB4H.js +0 -1086
- package/dist/chunk-VC4PRB4H.js.map +0 -1
- package/dist/chunk-W32JXP33.cjs.map +0 -1
- package/dist/chunk-XRK55NPE.js.map +0 -1
- package/dist/transform-DcVcOBzQ.d.cts +0 -3
- package/dist/transform-DcVcOBzQ.d.ts +0 -3
package/dist/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getProfileJsonSchema, MAPPING_OPS } from './chunk-
|
|
2
|
-
import { ConfigSchema } from './chunk-
|
|
1
|
+
import { getProfileJsonSchema, MAPPING_OPS } from './chunk-GK4CIKKT.js';
|
|
2
|
+
import { ConfigSchema } from './chunk-WKS4OCKN.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { defineAgent } from '@niscorp/cortex';
|
|
5
5
|
|
|
@@ -24,11 +24,9 @@ var mappingAgent = defineAgent({
|
|
|
24
24
|
id: "prism.mapping",
|
|
25
25
|
description: "Generates a Prism transformation config from a sample input row and a target shape.",
|
|
26
26
|
instructions: INSTRUCTIONS,
|
|
27
|
-
// Validated against the
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
// (schemas/profiles.ts). The heading is cortex's own (context/schema-doc.ts),
|
|
31
|
-
// so the finish protocol's "OUTPUT SCHEMA" still names it.
|
|
27
|
+
// Validated against the full grammar, documented with the mapping profile:
|
|
28
|
+
// a config using an op outside the profile is still accepted. The doc keeps
|
|
29
|
+
// cortex's own heading, "OUTPUT SCHEMA", which its finish protocol names.
|
|
32
30
|
output: { schema: ConfigSchema, doc: OUTPUT_DOC }
|
|
33
31
|
});
|
|
34
32
|
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/agent/mapping-agent.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../src/agent/mapping-agent.ts"],"names":[],"mappings":";;;;;AAOO,IAAM,uBAAA,GAA0B,EAAE,MAAA,CAAO;AAAA,EAC9C,WAAA,EAAa,CAAA,CACV,MAAA,CAAO,CAAA,CAAE,MAAA,EAAO,EAAG,CAAA,CAAE,OAAA,EAAS,CAAA,CAC9B,QAAA,CAAS,qFAAqF,CAAA;AAAA,EACjG,WAAA,EAAa,CAAA,CACV,OAAA,EAAQ,CACR,QAAA;AAAA,IACC;AAAA,GACF;AAAA,EACF,iBAAA,EAAmB,CAAA,CAChB,MAAA,CAAO,CAAA,CAAE,MAAA,EAAO,EAAG,CAAA,CAAE,MAAA,EAAQ,CAAA,CAC7B,QAAA,EAAS,CACT,SAAS,sFAAsF,CAAA;AAAA,EAClG,OAAO,CAAA,CACJ,MAAA,GACA,QAAA,EAAS,CACT,SAAS,8DAA8D;AAC5E,CAAC;AAMD,IAAM,YAAA,GAAe,CAAA;;AAAA;;AAAA;AAAA;AAAA,6IAAA,CAAA;AAQrB,IAAM,UAAA,GAAa,CAAA;AAAA,EAAwE,KAAK,SAAA,CAAU,oBAAA,CAAqB,WAAA,EAAa,SAAS,CAAC,CAAC,CAAA,CAAA;AAEhJ,IAAM,eAAwC,WAAA,CAAoB;AAAA,EACvE,EAAA,EAAI,eAAA;AAAA,EACJ,WAAA,EAAa,qFAAA;AAAA,EACb,YAAA,EAAc,YAAA;AAAA;AAAA;AAAA;AAAA,EAId,MAAA,EAAQ,EAAE,MAAA,EAAQ,YAAA,EAAc,KAAK,UAAA;AACvC,CAAC","file":"agent.js","sourcesContent":["import { z } from 'zod';\nimport { defineAgent, type AgentDefinition } from '@niscorp/cortex';\n\nimport { ConfigSchema, type Config } from '../schemas';\nimport { MAPPING_OPS } from '../schemas/profiles';\nimport { getProfileJsonSchema } from '../engine/documentation';\n\nexport const MappingAgentInputSchema = z.object({\n sampleInput: z\n .record(z.string(), z.unknown())\n .describe('A representative input row. The transformation will run against rows of this shape.'),\n targetShape: z\n .unknown()\n .describe(\n 'A JSON example of the desired output shape. Field values are placeholders; the agent infers the structure from this example.',\n ),\n fieldDescriptions: z\n .record(z.string(), z.string())\n .optional()\n .describe('Optional human-readable descriptions for fields the agent might not infer correctly.'),\n notes: z\n .string()\n .optional()\n .describe('Free-form additional context (data quirks, semantics, etc.).'),\n});\n\nexport type MappingAgentInput = z.infer<typeof MappingAgentInputSchema>;\n\nexport type MappingAgentOutput = Config;\n\nconst INSTRUCTIONS = `You are the Prism mapping agent. Given a sample input row and a target output shape, produce a Prism Config that maps rows of the input shape into the target shape.\n\nYour envelope's \\`data\\` is the Prism Config; \\`reasoning\\` is a one-sentence explanation of the mapping. The config must validate against the OUTPUT SCHEMA below (every constraint, format rule and example is in the schema's field descriptions).\n\nWorked example (illustrative only — read the schema for op details):\nINPUT { \"sampleInput\": { \"first\": \"Ada\", \"last\": \"Lovelace\" }, \"targetShape\": { \"fullName\": \"\" } }\ndata { \"fullName\": { \"$interpolate\": { \"template\": \"{{f}} {{l}}\", \"values\": { \"f\": { \"$ref\": \"$.first\" }, \"l\": { \"$ref\": \"$.last\" } } } } }`;\n\nconst OUTPUT_DOC = `OUTPUT SCHEMA — your output MUST validate against this JSON Schema:\\n${JSON.stringify(getProfileJsonSchema(MAPPING_OPS, 'draft-7'))}`;\n\nexport const mappingAgent: AgentDefinition<Config> = defineAgent<Config>({\n id: 'prism.mapping',\n description: 'Generates a Prism transformation config from a sample input row and a target shape.',\n instructions: INSTRUCTIONS,\n // Validated against the full grammar, documented with the mapping profile:\n // a config using an op outside the profile is still accepted. The doc keeps\n // cortex's own heading, \"OUTPUT SCHEMA\", which its finish protocol names.\n output: { schema: ConfigSchema, doc: OUTPUT_DOC },\n});\n"]}
|
|
@@ -2,19 +2,199 @@
|
|
|
2
2
|
|
|
3
3
|
var zod = require('zod');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
var ErrorCode = {
|
|
7
|
+
SCHEMA: "E_SCHEMA",
|
|
8
|
+
MISSING_PATH: "E_MISSING_PATH",
|
|
9
|
+
TYPE: "E_TYPE",
|
|
10
|
+
DIVISION_BY_ZERO: "E_DIVISION_BY_ZERO",
|
|
11
|
+
DATE_INVALID: "E_DATE_INVALID",
|
|
12
|
+
VAR_NOT_FOUND: "E_VAR_NOT_FOUND",
|
|
13
|
+
NODE_SHAPE: "E_NODE_SHAPE",
|
|
14
|
+
ASSERT: "E_ASSERT",
|
|
15
|
+
BUDGET: "E_BUDGET"
|
|
16
|
+
};
|
|
17
|
+
var PrismError = class extends Error {
|
|
18
|
+
code;
|
|
19
|
+
context;
|
|
20
|
+
constructor(message, code, context) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = "PrismError";
|
|
23
|
+
this.code = code;
|
|
24
|
+
this.context = context;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
6
27
|
var JsonPrimitiveSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]).describe("JSON primitive: string | number | boolean | null");
|
|
7
28
|
var JsonValueSchema = zod.z.lazy(
|
|
8
29
|
() => zod.z.union([JsonPrimitiveSchema, zod.z.array(JsonValueSchema), zod.z.record(zod.z.string(), JsonValueSchema)])
|
|
9
30
|
).describe("Any JSON value: primitive, array, or object");
|
|
10
31
|
zod.z.record(zod.z.string(), JsonValueSchema).describe("JSON object mapping string keys to JSON values");
|
|
32
|
+
|
|
33
|
+
// src/schemas/guards.ts
|
|
34
|
+
var hasKey = (value, key) => typeof value === "object" && value !== null && !Array.isArray(value) && key in value;
|
|
35
|
+
var isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
36
|
+
var isJsonArray = (value) => Array.isArray(value);
|
|
37
|
+
var isRefNode = (v) => hasKey(v, "$ref");
|
|
38
|
+
var isConstNode = (v) => hasKey(v, "$const");
|
|
39
|
+
var isVarNode = (v) => hasKey(v, "$var");
|
|
40
|
+
var isGetNode = (v) => hasKey(v, "$get");
|
|
41
|
+
var isWithNode = (v) => hasKey(v, "$with");
|
|
42
|
+
var isMapNode = (v) => hasKey(v, "$map");
|
|
43
|
+
var isFilterNode = (v) => hasKey(v, "$filter");
|
|
44
|
+
var isReduceNode = (v) => hasKey(v, "$reduce");
|
|
45
|
+
var isSliceNode = (v) => hasKey(v, "$slice");
|
|
46
|
+
var isFlattenNode = (v) => hasKey(v, "$flatten");
|
|
47
|
+
var isUniqueNode = (v) => hasKey(v, "$unique");
|
|
48
|
+
var isSortByNode = (v) => hasKey(v, "$sortBy");
|
|
49
|
+
var isAddNode = (v) => hasKey(v, "$add");
|
|
50
|
+
var isSubNode = (v) => hasKey(v, "$sub");
|
|
51
|
+
var isMulNode = (v) => hasKey(v, "$mul");
|
|
52
|
+
var isDivNode = (v) => hasKey(v, "$div");
|
|
53
|
+
var isRoundNode = (v) => hasKey(v, "$round");
|
|
54
|
+
var isModNode = (v) => hasKey(v, "$mod");
|
|
55
|
+
var isToNumberNode = (v) => hasKey(v, "$toNumber");
|
|
56
|
+
var isJoinNode = (v) => hasKey(v, "$join");
|
|
57
|
+
var isToStringNode = (v) => hasKey(v, "$toString");
|
|
58
|
+
var isInterpolateNode = (v) => hasKey(v, "$interpolate");
|
|
59
|
+
var isFillNode = (v) => hasKey(v, "$fill");
|
|
60
|
+
var isTrimNode = (v) => hasKey(v, "$trim");
|
|
61
|
+
var isLowerNode = (v) => hasKey(v, "$lower");
|
|
62
|
+
var isUpperNode = (v) => hasKey(v, "$upper");
|
|
63
|
+
var isSplitNode = (v) => hasKey(v, "$split");
|
|
64
|
+
var isReplaceNode = (v) => hasKey(v, "$replace");
|
|
65
|
+
var isEqNode = (v) => hasKey(v, "$eq");
|
|
66
|
+
var isNeqNode = (v) => hasKey(v, "$neq");
|
|
67
|
+
var isGtNode = (v) => hasKey(v, "$gt");
|
|
68
|
+
var isGteNode = (v) => hasKey(v, "$gte");
|
|
69
|
+
var isLtNode = (v) => hasKey(v, "$lt");
|
|
70
|
+
var isLteNode = (v) => hasKey(v, "$lte");
|
|
71
|
+
var isEmptyNode = (v) => hasKey(v, "$empty");
|
|
72
|
+
var isStartsWithNode = (v) => hasKey(v, "$startsWith");
|
|
73
|
+
var isEndsWithNode = (v) => hasKey(v, "$endsWith");
|
|
74
|
+
var isContainsNode = (v) => hasKey(v, "$contains");
|
|
75
|
+
var isNotNode = (v) => hasKey(v, "$not");
|
|
76
|
+
var isAndNode = (v) => hasKey(v, "$and");
|
|
77
|
+
var isOrNode = (v) => hasKey(v, "$or");
|
|
78
|
+
var isMergeNode = (v) => hasKey(v, "$merge");
|
|
79
|
+
var isCoalesceNode = (v) => hasKey(v, "$coalesce");
|
|
80
|
+
var isCaseNode = (v) => hasKey(v, "$case");
|
|
81
|
+
var isEntriesOfNode = (v) => hasKey(v, "$entriesOf");
|
|
82
|
+
var isKeyByNode = (v) => hasKey(v, "$keyBy");
|
|
83
|
+
var isGroupByNode = (v) => hasKey(v, "$groupBy");
|
|
84
|
+
var isKeysNode = (v) => hasKey(v, "$keys");
|
|
85
|
+
var isValuesNode = (v) => hasKey(v, "$values");
|
|
86
|
+
var isFromEntriesNode = (v) => hasKey(v, "$fromEntries");
|
|
87
|
+
var isPickNode = (v) => hasKey(v, "$pick");
|
|
88
|
+
var isOmitNode = (v) => hasKey(v, "$omit");
|
|
89
|
+
var isHasNode = (v) => hasKey(v, "$has");
|
|
90
|
+
var isRenameKeysNode = (v) => hasKey(v, "$renameKeys");
|
|
91
|
+
var isUpdateNode = (v) => hasKey(v, "$update");
|
|
92
|
+
var isAssertNode = (v) => hasKey(v, "$assert");
|
|
93
|
+
var isWalkNode = (v) => hasKey(v, "$walk");
|
|
94
|
+
var isTypeNode = (v) => hasKey(v, "$type");
|
|
95
|
+
var isLengthNode = (v) => hasKey(v, "$length");
|
|
96
|
+
var isDateNode = (v) => hasKey(v, "$date");
|
|
97
|
+
var isDateAddNode = (v) => hasKey(v, "$dateAdd");
|
|
98
|
+
var isDateDiffNode = (v) => hasKey(v, "$dateDiff");
|
|
99
|
+
var isLocaleDateNode = (v) => hasKey(v, "$localeDate");
|
|
100
|
+
var isLocaleMoneyNode = (v) => hasKey(v, "$localeMoney");
|
|
101
|
+
var isLocaleNumberNode = (v) => hasKey(v, "$localeNumber");
|
|
102
|
+
var isSumNode = (v) => hasKey(v, "$sum");
|
|
103
|
+
var isAvgNode = (v) => hasKey(v, "$avg");
|
|
104
|
+
var isCountNode = (v) => hasKey(v, "$count");
|
|
105
|
+
var isMinNode = (v) => hasKey(v, "$min");
|
|
106
|
+
var isMaxNode = (v) => hasKey(v, "$max");
|
|
107
|
+
var isPluckNode = (v) => hasKey(v, "$pluck");
|
|
108
|
+
var isTakeNode = (v) => hasKey(v, "$take");
|
|
109
|
+
var isDropNode = (v) => hasKey(v, "$drop");
|
|
110
|
+
var isMatchNode = (v) => hasKey(v, "$match");
|
|
111
|
+
var isFlatMapNode = (v) => hasKey(v, "$flatMap");
|
|
112
|
+
var isPlainObject = (value) => isJsonObject(value) && !Object.keys(value).some((k) => k.startsWith("$"));
|
|
113
|
+
|
|
114
|
+
// src/utils/jsonpath.ts
|
|
115
|
+
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.`;
|
|
116
|
+
var refuse = (path) => {
|
|
117
|
+
throw new PrismError(pathRefusal(path), ErrorCode.SCHEMA, { op: "$ref", path });
|
|
118
|
+
};
|
|
119
|
+
var isReadablePath = (path) => {
|
|
120
|
+
if (!path.includes("[") && !path.includes("..")) return true;
|
|
121
|
+
try {
|
|
122
|
+
parseJsonPath(path);
|
|
123
|
+
return true;
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var parseJsonPath = (path) => {
|
|
129
|
+
if (!path.startsWith("$.")) return [];
|
|
130
|
+
const segments = [];
|
|
131
|
+
let cursor = 2;
|
|
132
|
+
let currentKey = "";
|
|
133
|
+
const pushKey = () => {
|
|
134
|
+
if (currentKey.length > 0) {
|
|
135
|
+
segments.push({ type: "key", key: currentKey });
|
|
136
|
+
currentKey = "";
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
while (cursor < path.length) {
|
|
140
|
+
const char = path[cursor];
|
|
141
|
+
if (char === ".") {
|
|
142
|
+
if (path[cursor - 1] === ".") refuse(path);
|
|
143
|
+
pushKey();
|
|
144
|
+
cursor++;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (char === "[") {
|
|
148
|
+
pushKey();
|
|
149
|
+
cursor++;
|
|
150
|
+
let numBuf = "";
|
|
151
|
+
while (cursor < path.length && path[cursor] !== "]") {
|
|
152
|
+
numBuf += path[cursor];
|
|
153
|
+
cursor++;
|
|
154
|
+
}
|
|
155
|
+
if (path[cursor] !== "]") refuse(path);
|
|
156
|
+
cursor++;
|
|
157
|
+
const index = Number(numBuf);
|
|
158
|
+
if (numBuf.trim() === "" || !Number.isInteger(index) || index < 0) refuse(path);
|
|
159
|
+
segments.push({ type: "index", index });
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
currentKey += char;
|
|
163
|
+
cursor++;
|
|
164
|
+
}
|
|
165
|
+
pushKey();
|
|
166
|
+
return segments;
|
|
167
|
+
};
|
|
168
|
+
var cache = /* @__PURE__ */ new Map();
|
|
169
|
+
var parseJsonPathCached = (path) => {
|
|
170
|
+
const cached = cache.get(path);
|
|
171
|
+
if (cached) return cached;
|
|
172
|
+
const parsed = parseJsonPath(path);
|
|
173
|
+
cache.set(path, parsed);
|
|
174
|
+
return parsed;
|
|
175
|
+
};
|
|
176
|
+
var getByPath = (root, segments) => {
|
|
177
|
+
let current = root;
|
|
178
|
+
for (const segment of segments) {
|
|
179
|
+
if (segment.type === "key") {
|
|
180
|
+
if (!isJsonObject(current)) return void 0;
|
|
181
|
+
current = current[segment.key];
|
|
182
|
+
} else {
|
|
183
|
+
if (!isJsonArray(current)) return void 0;
|
|
184
|
+
current = current[segment.index];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return current;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/schemas/ops/core.schema.ts
|
|
11
191
|
var _NodeSchema = zod.z.any();
|
|
12
192
|
var setNodeSchema = (schema) => {
|
|
13
193
|
_NodeSchema = schema;
|
|
14
194
|
};
|
|
15
195
|
var node = () => _NodeSchema;
|
|
16
196
|
var RefNodeSchema = zod.z.object({
|
|
17
|
-
$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.')
|
|
197
|
+
$ref: zod.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.')
|
|
18
198
|
}).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.");
|
|
19
199
|
var ConstNodeSchema = zod.z.object({
|
|
20
200
|
$const: JsonValueSchema.describe("Any JSON value to return as-is.")
|
|
@@ -94,12 +274,20 @@ var AddNodeSchema = zod.z.object({ $add: pairOf("Two numeric operands to add.")
|
|
|
94
274
|
var SubNodeSchema = zod.z.object({ $sub: pairOf("Two numeric operands to subtract (a - b).") }).strict().describe("Subtract second number from first.");
|
|
95
275
|
var MulNodeSchema = zod.z.object({ $mul: pairOf("Two numeric operands to multiply.") }).strict().describe("Multiply two numbers.");
|
|
96
276
|
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.");
|
|
277
|
+
var ModNodeSchema = zod.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.");
|
|
97
278
|
var RoundNodeSchema = zod.z.object({
|
|
98
279
|
$round: zod.z.object({
|
|
99
280
|
value: zod.z.lazy(node3).describe("Numeric value to round."),
|
|
100
|
-
digits: zod.z.number().int().nonnegative().optional().default(0).describe("Decimal places. Default: 0.")
|
|
281
|
+
digits: zod.z.number().int().nonnegative().optional().default(0).describe("Decimal places. Default: 0."),
|
|
282
|
+
mode: zod.z.enum(["nearest", "floor", "ceil"]).optional().describe('Which way to round: "nearest" (the default), "floor" (down, toward negative infinity) or "ceil" (up).')
|
|
101
283
|
}).strict()
|
|
102
|
-
}).strict().describe(
|
|
284
|
+
}).strict().describe('Round a number to N decimal places: to the nearest, or down ("floor") or up ("ceil") with `mode`.');
|
|
285
|
+
var ToNumberNodeSchema = zod.z.object({
|
|
286
|
+
$toNumber: zod.z.object({
|
|
287
|
+
value: zod.z.lazy(node3).describe('A number, or text that is a number written in digits: "42", "-3.5", " 1e3 ".'),
|
|
288
|
+
fallback: zod.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.")
|
|
289
|
+
}).strict()
|
|
290
|
+
}).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.");
|
|
103
291
|
var _NodeSchema4 = zod.z.any();
|
|
104
292
|
var setNodeSchema4 = (schema) => {
|
|
105
293
|
_NodeSchema4 = schema;
|
|
@@ -134,9 +322,10 @@ var ReplaceNodeSchema = zod.z.object({
|
|
|
134
322
|
$replace: zod.z.object({
|
|
135
323
|
value: zod.z.lazy(node4).describe("String to search in."),
|
|
136
324
|
search: zod.z.string().describe("Substring to find."),
|
|
137
|
-
replacement: zod.z.string().describe("Replacement string.")
|
|
325
|
+
replacement: zod.z.string().describe("Replacement string."),
|
|
326
|
+
all: zod.z.boolean().optional().describe("true replaces every occurrence. Default: only the first.")
|
|
138
327
|
}).strict()
|
|
139
|
-
}).strict().describe("Replace the first occurrence of a substring
|
|
328
|
+
}).strict().describe("Replace the first occurrence of a substring, or every occurrence with `all: true`.");
|
|
140
329
|
var _NodeSchema5 = zod.z.any();
|
|
141
330
|
var setNodeSchema5 = (schema) => {
|
|
142
331
|
_NodeSchema5 = schema;
|
|
@@ -436,7 +625,9 @@ var OP_KEYS = [
|
|
|
436
625
|
"$sub",
|
|
437
626
|
"$mul",
|
|
438
627
|
"$div",
|
|
628
|
+
"$mod",
|
|
439
629
|
"$round",
|
|
630
|
+
"$toNumber",
|
|
440
631
|
"$fill",
|
|
441
632
|
"$join",
|
|
442
633
|
"$toString",
|
|
@@ -504,15 +695,67 @@ var hasValidOptionalMeta = (obj) => {
|
|
|
504
695
|
if (!Array.isArray(meta)) return false;
|
|
505
696
|
return meta.every((f) => typeof f === "string" && f.length > 0);
|
|
506
697
|
};
|
|
698
|
+
var NodeArraySchema = zod.z.array(zod.z.lazy(() => NodeSchema));
|
|
699
|
+
var TemplateSchema = 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." });
|
|
700
|
+
var opMembersOf = (options) => {
|
|
701
|
+
const members = /* @__PURE__ */ new Map();
|
|
702
|
+
for (const option of options) {
|
|
703
|
+
const { def } = option._zod;
|
|
704
|
+
const keys = "shape" in def && typeof def.shape === "object" && def.shape !== null ? Object.keys(def.shape) : [];
|
|
705
|
+
const [key] = keys;
|
|
706
|
+
if (keys.length === 1 && key !== void 0 && isOpKey(key)) members.set(key, option);
|
|
707
|
+
}
|
|
708
|
+
return members;
|
|
709
|
+
};
|
|
710
|
+
var memberOf = (value, ops) => {
|
|
711
|
+
if (value === null || typeof value !== "object") return JsonPrimitiveSchema;
|
|
712
|
+
if (Array.isArray(value)) return NodeArraySchema;
|
|
713
|
+
const proto = Object.getPrototypeOf(value);
|
|
714
|
+
if (proto !== Object.prototype && proto !== null) return void 0;
|
|
715
|
+
let op;
|
|
716
|
+
let count = 0;
|
|
717
|
+
for (const key in value) {
|
|
718
|
+
count += 1;
|
|
719
|
+
if (key.startsWith("$")) op = key;
|
|
720
|
+
}
|
|
721
|
+
if (op === void 0) return TemplateSchema;
|
|
722
|
+
return count === 1 ? ops.get(op) : void 0;
|
|
723
|
+
};
|
|
724
|
+
var quick = /* @__PURE__ */ new WeakSet();
|
|
725
|
+
var walking = /* @__PURE__ */ new WeakSet();
|
|
726
|
+
var NodeUnion = zod.z.core.$constructor("PrismNodeUnion", (inst, def) => {
|
|
727
|
+
zod.z.ZodUnion.init(inst, def);
|
|
728
|
+
const ops = opMembersOf(def.options);
|
|
729
|
+
const walk = inst._zod.parse;
|
|
730
|
+
inst._zod.parse = (payload, ctx) => {
|
|
731
|
+
if (ctx.async !== false || walking.has(ctx)) return walk(payload, ctx);
|
|
732
|
+
const member = memberOf(payload.value, ops);
|
|
733
|
+
if (quick.has(ctx)) {
|
|
734
|
+
if (member !== void 0) return member._zod.run(payload, ctx);
|
|
735
|
+
payload.issues.push({ code: "custom", input: payload.value, inst });
|
|
736
|
+
return payload;
|
|
737
|
+
}
|
|
738
|
+
if (member !== void 0) {
|
|
739
|
+
const own = { async: false, ...ctx.jitless === void 0 ? {} : { jitless: ctx.jitless } };
|
|
740
|
+
quick.add(own);
|
|
741
|
+
const tried = member._zod.run({ value: payload.value, issues: [] }, own);
|
|
742
|
+
if (!(tried instanceof Promise) && tried.issues.length === 0) return tried;
|
|
743
|
+
}
|
|
744
|
+
walking.add(ctx);
|
|
745
|
+
try {
|
|
746
|
+
return walk(payload, ctx);
|
|
747
|
+
} finally {
|
|
748
|
+
walking.delete(ctx);
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
});
|
|
507
752
|
var NodeSchema = zod.z.lazy(
|
|
508
|
-
() =>
|
|
509
|
-
// Core
|
|
753
|
+
() => new NodeUnion({ type: "union", options: [
|
|
510
754
|
RefNodeSchema,
|
|
511
755
|
ConstNodeSchema,
|
|
512
756
|
VarNodeSchema,
|
|
513
757
|
GetNodeSchema,
|
|
514
758
|
WithNodeSchema,
|
|
515
|
-
// Array
|
|
516
759
|
MapNodeSchema,
|
|
517
760
|
FilterNodeSchema,
|
|
518
761
|
ReduceNodeSchema,
|
|
@@ -520,13 +763,13 @@ var NodeSchema = zod.z.lazy(
|
|
|
520
763
|
FlattenNodeSchema,
|
|
521
764
|
UniqueNodeSchema,
|
|
522
765
|
SortByNodeSchema,
|
|
523
|
-
// Math
|
|
524
766
|
AddNodeSchema,
|
|
525
767
|
SubNodeSchema,
|
|
526
768
|
MulNodeSchema,
|
|
527
769
|
DivNodeSchema,
|
|
770
|
+
ModNodeSchema,
|
|
528
771
|
RoundNodeSchema,
|
|
529
|
-
|
|
772
|
+
ToNumberNodeSchema,
|
|
530
773
|
FillNodeSchema,
|
|
531
774
|
JoinNodeSchema,
|
|
532
775
|
ToStringNodeSchema,
|
|
@@ -536,7 +779,6 @@ var NodeSchema = zod.z.lazy(
|
|
|
536
779
|
UpperNodeSchema,
|
|
537
780
|
SplitNodeSchema,
|
|
538
781
|
ReplaceNodeSchema,
|
|
539
|
-
// Predicates
|
|
540
782
|
EqNodeSchema,
|
|
541
783
|
NeqNodeSchema,
|
|
542
784
|
GtNodeSchema,
|
|
@@ -547,18 +789,15 @@ var NodeSchema = zod.z.lazy(
|
|
|
547
789
|
StartsWithNodeSchema,
|
|
548
790
|
EndsWithNodeSchema,
|
|
549
791
|
ContainsNodeSchema,
|
|
550
|
-
// Logic
|
|
551
792
|
NotNodeSchema,
|
|
552
793
|
AndNodeSchema,
|
|
553
794
|
OrNodeSchema,
|
|
554
|
-
// Structure
|
|
555
795
|
MergeNodeSchema,
|
|
556
796
|
CoalesceNodeSchema,
|
|
557
797
|
CaseNodeSchema,
|
|
558
798
|
EntriesOfNodeSchema,
|
|
559
799
|
KeyByNodeSchema,
|
|
560
800
|
GroupByNodeSchema,
|
|
561
|
-
// Object
|
|
562
801
|
KeysNodeSchema,
|
|
563
802
|
ValuesNodeSchema,
|
|
564
803
|
FromEntriesNodeSchema,
|
|
@@ -566,15 +805,12 @@ var NodeSchema = zod.z.lazy(
|
|
|
566
805
|
OmitNodeSchema,
|
|
567
806
|
TypeNodeSchema,
|
|
568
807
|
LengthNodeSchema,
|
|
569
|
-
// Time
|
|
570
808
|
DateNodeSchema,
|
|
571
809
|
DateAddNodeSchema,
|
|
572
810
|
DateDiffNodeSchema,
|
|
573
|
-
// Locale-aware formatting
|
|
574
811
|
LocaleDateNodeSchema,
|
|
575
812
|
LocaleMoneyNodeSchema,
|
|
576
813
|
LocaleNumberNodeSchema,
|
|
577
|
-
// Sugar
|
|
578
814
|
SumNodeSchema,
|
|
579
815
|
AvgNodeSchema,
|
|
580
816
|
CountNodeSchema,
|
|
@@ -585,25 +821,15 @@ var NodeSchema = zod.z.lazy(
|
|
|
585
821
|
DropNodeSchema,
|
|
586
822
|
MatchNodeSchema,
|
|
587
823
|
FlatMapNodeSchema,
|
|
588
|
-
// Transform (rewriting a document)
|
|
589
824
|
HasNodeSchema,
|
|
590
825
|
RenameKeysNodeSchema,
|
|
591
826
|
UpdateNodeSchema,
|
|
592
827
|
AssertNodeSchema,
|
|
593
828
|
WalkNodeSchema,
|
|
594
|
-
// Primitives
|
|
595
829
|
JsonPrimitiveSchema,
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
// A `$` key is not a template key. Said in the KEY schema, not a
|
|
600
|
-
// refinement: a refinement leaves this branch structurally matched, and
|
|
601
|
-
// zod then reports its complaint instead of the union's — so a typo inside
|
|
602
|
-
// a real op (`{ $get: { pathh } }`) read as "plain object must not contain
|
|
603
|
-
// $ op keys" at the root. As a key pattern it is also plain JSON Schema
|
|
604
|
-
// (`propertyNames`), which the grammar snapshot and agent prompts read.
|
|
605
|
-
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." })
|
|
606
|
-
]).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
|
|
830
|
+
NodeArraySchema,
|
|
831
|
+
TemplateSchema
|
|
832
|
+
] }).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
|
|
607
833
|
);
|
|
608
834
|
setNodeSchema(NodeSchema);
|
|
609
835
|
setNodeSchema2(NodeSchema);
|
|
@@ -621,89 +847,13 @@ var ConfigSchema = NodeSchema.describe(
|
|
|
621
847
|
"A Prism config: the top-level transformation definition. Can be any valid node."
|
|
622
848
|
);
|
|
623
849
|
|
|
624
|
-
// src/schemas/guards.ts
|
|
625
|
-
var hasKey = (value, key) => typeof value === "object" && value !== null && !Array.isArray(value) && key in value;
|
|
626
|
-
var isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
627
|
-
var isJsonArray = (value) => Array.isArray(value);
|
|
628
|
-
var isRefNode = (v) => hasKey(v, "$ref");
|
|
629
|
-
var isConstNode = (v) => hasKey(v, "$const");
|
|
630
|
-
var isVarNode = (v) => hasKey(v, "$var");
|
|
631
|
-
var isGetNode = (v) => hasKey(v, "$get");
|
|
632
|
-
var isWithNode = (v) => hasKey(v, "$with");
|
|
633
|
-
var isMapNode = (v) => hasKey(v, "$map");
|
|
634
|
-
var isFilterNode = (v) => hasKey(v, "$filter");
|
|
635
|
-
var isReduceNode = (v) => hasKey(v, "$reduce");
|
|
636
|
-
var isSliceNode = (v) => hasKey(v, "$slice");
|
|
637
|
-
var isFlattenNode = (v) => hasKey(v, "$flatten");
|
|
638
|
-
var isUniqueNode = (v) => hasKey(v, "$unique");
|
|
639
|
-
var isSortByNode = (v) => hasKey(v, "$sortBy");
|
|
640
|
-
var isAddNode = (v) => hasKey(v, "$add");
|
|
641
|
-
var isSubNode = (v) => hasKey(v, "$sub");
|
|
642
|
-
var isMulNode = (v) => hasKey(v, "$mul");
|
|
643
|
-
var isDivNode = (v) => hasKey(v, "$div");
|
|
644
|
-
var isRoundNode = (v) => hasKey(v, "$round");
|
|
645
|
-
var isJoinNode = (v) => hasKey(v, "$join");
|
|
646
|
-
var isToStringNode = (v) => hasKey(v, "$toString");
|
|
647
|
-
var isInterpolateNode = (v) => hasKey(v, "$interpolate");
|
|
648
|
-
var isFillNode = (v) => hasKey(v, "$fill");
|
|
649
|
-
var isTrimNode = (v) => hasKey(v, "$trim");
|
|
650
|
-
var isLowerNode = (v) => hasKey(v, "$lower");
|
|
651
|
-
var isUpperNode = (v) => hasKey(v, "$upper");
|
|
652
|
-
var isSplitNode = (v) => hasKey(v, "$split");
|
|
653
|
-
var isReplaceNode = (v) => hasKey(v, "$replace");
|
|
654
|
-
var isEqNode = (v) => hasKey(v, "$eq");
|
|
655
|
-
var isNeqNode = (v) => hasKey(v, "$neq");
|
|
656
|
-
var isGtNode = (v) => hasKey(v, "$gt");
|
|
657
|
-
var isGteNode = (v) => hasKey(v, "$gte");
|
|
658
|
-
var isLtNode = (v) => hasKey(v, "$lt");
|
|
659
|
-
var isLteNode = (v) => hasKey(v, "$lte");
|
|
660
|
-
var isEmptyNode = (v) => hasKey(v, "$empty");
|
|
661
|
-
var isStartsWithNode = (v) => hasKey(v, "$startsWith");
|
|
662
|
-
var isEndsWithNode = (v) => hasKey(v, "$endsWith");
|
|
663
|
-
var isContainsNode = (v) => hasKey(v, "$contains");
|
|
664
|
-
var isNotNode = (v) => hasKey(v, "$not");
|
|
665
|
-
var isAndNode = (v) => hasKey(v, "$and");
|
|
666
|
-
var isOrNode = (v) => hasKey(v, "$or");
|
|
667
|
-
var isMergeNode = (v) => hasKey(v, "$merge");
|
|
668
|
-
var isCoalesceNode = (v) => hasKey(v, "$coalesce");
|
|
669
|
-
var isCaseNode = (v) => hasKey(v, "$case");
|
|
670
|
-
var isEntriesOfNode = (v) => hasKey(v, "$entriesOf");
|
|
671
|
-
var isKeyByNode = (v) => hasKey(v, "$keyBy");
|
|
672
|
-
var isGroupByNode = (v) => hasKey(v, "$groupBy");
|
|
673
|
-
var isKeysNode = (v) => hasKey(v, "$keys");
|
|
674
|
-
var isValuesNode = (v) => hasKey(v, "$values");
|
|
675
|
-
var isFromEntriesNode = (v) => hasKey(v, "$fromEntries");
|
|
676
|
-
var isPickNode = (v) => hasKey(v, "$pick");
|
|
677
|
-
var isOmitNode = (v) => hasKey(v, "$omit");
|
|
678
|
-
var isHasNode = (v) => hasKey(v, "$has");
|
|
679
|
-
var isRenameKeysNode = (v) => hasKey(v, "$renameKeys");
|
|
680
|
-
var isUpdateNode = (v) => hasKey(v, "$update");
|
|
681
|
-
var isAssertNode = (v) => hasKey(v, "$assert");
|
|
682
|
-
var isWalkNode = (v) => hasKey(v, "$walk");
|
|
683
|
-
var isTypeNode = (v) => hasKey(v, "$type");
|
|
684
|
-
var isLengthNode = (v) => hasKey(v, "$length");
|
|
685
|
-
var isDateNode = (v) => hasKey(v, "$date");
|
|
686
|
-
var isDateAddNode = (v) => hasKey(v, "$dateAdd");
|
|
687
|
-
var isDateDiffNode = (v) => hasKey(v, "$dateDiff");
|
|
688
|
-
var isLocaleDateNode = (v) => hasKey(v, "$localeDate");
|
|
689
|
-
var isLocaleMoneyNode = (v) => hasKey(v, "$localeMoney");
|
|
690
|
-
var isLocaleNumberNode = (v) => hasKey(v, "$localeNumber");
|
|
691
|
-
var isSumNode = (v) => hasKey(v, "$sum");
|
|
692
|
-
var isAvgNode = (v) => hasKey(v, "$avg");
|
|
693
|
-
var isCountNode = (v) => hasKey(v, "$count");
|
|
694
|
-
var isMinNode = (v) => hasKey(v, "$min");
|
|
695
|
-
var isMaxNode = (v) => hasKey(v, "$max");
|
|
696
|
-
var isPluckNode = (v) => hasKey(v, "$pluck");
|
|
697
|
-
var isTakeNode = (v) => hasKey(v, "$take");
|
|
698
|
-
var isDropNode = (v) => hasKey(v, "$drop");
|
|
699
|
-
var isMatchNode = (v) => hasKey(v, "$match");
|
|
700
|
-
var isFlatMapNode = (v) => hasKey(v, "$flatMap");
|
|
701
|
-
var isPlainObject = (value) => isJsonObject(value) && !Object.keys(value).some((k) => k.startsWith("$"));
|
|
702
|
-
|
|
703
850
|
exports.ConfigSchema = ConfigSchema;
|
|
851
|
+
exports.ErrorCode = ErrorCode;
|
|
704
852
|
exports.NodeSchema = NodeSchema;
|
|
705
853
|
exports.OPTIONAL_FIELDS_KEY = OPTIONAL_FIELDS_KEY;
|
|
706
854
|
exports.OP_KEYS = OP_KEYS;
|
|
855
|
+
exports.PrismError = PrismError;
|
|
856
|
+
exports.getByPath = getByPath;
|
|
707
857
|
exports.isAddNode = isAddNode;
|
|
708
858
|
exports.isAndNode = isAndNode;
|
|
709
859
|
exports.isAssertNode = isAssertNode;
|
|
@@ -750,6 +900,7 @@ exports.isMatchNode = isMatchNode;
|
|
|
750
900
|
exports.isMaxNode = isMaxNode;
|
|
751
901
|
exports.isMergeNode = isMergeNode;
|
|
752
902
|
exports.isMinNode = isMinNode;
|
|
903
|
+
exports.isModNode = isModNode;
|
|
753
904
|
exports.isMulNode = isMulNode;
|
|
754
905
|
exports.isNeqNode = isNeqNode;
|
|
755
906
|
exports.isNotNode = isNotNode;
|
|
@@ -770,6 +921,7 @@ exports.isStartsWithNode = isStartsWithNode;
|
|
|
770
921
|
exports.isSubNode = isSubNode;
|
|
771
922
|
exports.isSumNode = isSumNode;
|
|
772
923
|
exports.isTakeNode = isTakeNode;
|
|
924
|
+
exports.isToNumberNode = isToNumberNode;
|
|
773
925
|
exports.isToStringNode = isToStringNode;
|
|
774
926
|
exports.isTrimNode = isTrimNode;
|
|
775
927
|
exports.isTypeNode = isTypeNode;
|
|
@@ -780,5 +932,7 @@ exports.isValuesNode = isValuesNode;
|
|
|
780
932
|
exports.isVarNode = isVarNode;
|
|
781
933
|
exports.isWalkNode = isWalkNode;
|
|
782
934
|
exports.isWithNode = isWithNode;
|
|
783
|
-
|
|
784
|
-
|
|
935
|
+
exports.parseJsonPath = parseJsonPath;
|
|
936
|
+
exports.parseJsonPathCached = parseJsonPathCached;
|
|
937
|
+
//# sourceMappingURL=chunk-6PD7M2F3.cjs.map
|
|
938
|
+
//# sourceMappingURL=chunk-6PD7M2F3.cjs.map
|