@niscorp/prism 0.3.1 → 0.3.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.
- package/CHANGELOG.md +29 -0
- package/DESIGN.md +6 -2
- package/DOCS.md +18 -5
- package/dist/agent.cjs +4 -4
- package/dist/agent.js +2 -2
- package/dist/{chunk-WKS4OCKN.js → chunk-OL4CCYWX.js} +213 -87
- package/dist/chunk-OL4CCYWX.js.map +1 -0
- package/dist/{chunk-6PD7M2F3.cjs → chunk-QUI2X5JB.cjs} +220 -86
- package/dist/chunk-QUI2X5JB.cjs.map +1 -0
- package/dist/{chunk-OWKINPR5.cjs → chunk-ROYHYYIL.cjs} +5 -5
- package/dist/{chunk-OWKINPR5.cjs.map → chunk-ROYHYYIL.cjs.map} +1 -1
- package/dist/{chunk-GK4CIKKT.js → chunk-VNGBVDUM.js} +3 -3
- package/dist/{chunk-GK4CIKKT.js.map → chunk-VNGBVDUM.js.map} +1 -1
- package/dist/index.cjs +541 -364
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +341 -164
- package/dist/index.js.map +1 -1
- package/dist/migrations/index.cjs +2 -2
- package/dist/migrations/index.js +1 -1
- package/package.json +7 -7
- package/dist/chunk-6PD7M2F3.cjs.map +0 -1
- package/dist/chunk-WKS4OCKN.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @niscorp/prism
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7bcf306: An error says what the op got, where in the program, and the op's form, in its message. The message is what a caller passes on to a program's author, often a model that sees nothing else, and it said too little to fix anything: `Expected string for $trim`, `Path not found`, `Invalid config`.
|
|
8
|
+
- **A wrong type** names the value and where: `$trim needs text, but got an object: {"value":"Quarterly contributor outreach"}. … At $map.body.title.$trim. Form: {"$trim": <node>}`. Where the field was written as an object without a `$` key, it says such an object builds an object. The form is printed from the schema.
|
|
9
|
+
- **A path that found nothing** says where it stopped and what is there: `$ref "$.rows.name" stopped at "name": the value at $.rows is a list of 1 item: […], and a list is read by index, a number`. A missing key lists the keys there; a `$var` that is not there lists the variables in scope.
|
|
10
|
+
- **Inside a sugar op** the position is the author's: `At s.$sum, in the $add that $sum runs as.`
|
|
11
|
+
- **A refused config** puts its issues in `evaluate`'s message, as `compile` did, each with the form of the op it is on: `Invalid config: x: Unrecognized key: "fallback". Form: {"$trim": <node>}`. `validate`'s issue messages carry the same form.
|
|
12
|
+
- **An object whose only key names an op is checked as that op alone.** A reader of `ConfigSchema`'s issues that picks among a union's branches, as cortex's `flattenSchemaIssues` does, now gets the op's own issues (`$map/over: Unrecognized keys: "as", "body"`) instead of `$map: Invalid key in record`, and an op name that does not exist reads `Not a Prism op…`. Which configs are accepted is unchanged.
|
|
13
|
+
- The budget says where evaluation stopped; `E_NODE_SHAPE` puts the node in its message; `check: 'always'` names the first value of a source that is not plain JSON (`source.d is a Date`).
|
|
14
|
+
|
|
15
|
+
Codes, `PrismError`, `.context` (`op`, `path`, `details`) and every export are unchanged. `$assert`'s message is the program's own and is unchanged.
|
|
16
|
+
|
|
17
|
+
**What to change:** nothing. Code that compared a message's exact text gets the new text.
|
|
18
|
+
|
|
19
|
+
- ee625f7: `$get` reads a path segment of digits as an index when the value there is a list: `["link", "0"]` reads the first item of `link`, as `["link", 0]` does, and as JavaScript and JSON Pointer read it. Only digits count: `"01"`, `"-1"` and `" 0"` stay keys, and a key asked of a list is refused as before (`E_TYPE`, or the fallback).
|
|
20
|
+
|
|
21
|
+
Before, `"0"` on a list was a key, which a list does not have: without a `fallback` it threw `E_TYPE`, and with one it answered the fallback for every item, which is easy to miss. A model writing a mapping wrote `["link", "0"]` with a `null` fallback and got `null` for all twelve records; lyra's people roll reads its page cursor with `["0", field]` and has answered `""` every time.
|
|
22
|
+
|
|
23
|
+
**What to change:** nothing. A config that used a digit key on a list and relied on getting its fallback now gets the item.
|
|
24
|
+
|
|
25
|
+
- ef23b8e: `$join`, `$interpolate`, `$keyBy` and `$groupBy` refuse an object or a list where they need text, with `E_TYPE` and a message that says which item or key and what it was. They turned it into text with `String()`: an object became `"[object Object]"` and a list its items joined by commas, and nothing said so.
|
|
26
|
+
- `$join`: a part that is an object or a list (`$join.parts needs items that are text, a number, true, false or null, but item 1 is an object: {"a":1}.`). `null` is still `""`.
|
|
27
|
+
- `$interpolate`: a value for a `{{key}}` in the template that is an object or a list. A value the template does not use is not looked at, and a missing one is still `""`.
|
|
28
|
+
- `$keyBy` and `$groupBy`: a key that is an object or a list. Text, numbers, `true`, `false` and `null` are keys as before.
|
|
29
|
+
|
|
30
|
+
**What to change:** a config that joined or interpolated an object or a list, or grouped by one, now fails instead of answering `"[object Object]"` or `"a,b"`. Pick the field you meant (`$get`), or join the list first (`$join`).
|
|
31
|
+
|
|
3
32
|
## 0.3.1
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/DESIGN.md
CHANGED
|
@@ -138,6 +138,8 @@ All errors are `PrismError` instances with a `.code` string and optional `.conte
|
|
|
138
138
|
| `E_ASSERT` | A config's own `$assert` refused its input |
|
|
139
139
|
| `E_BUDGET` | An evaluation went past its budget (`engine/budget.ts`) |
|
|
140
140
|
|
|
141
|
+
The message is the one thing a caller passes on to the author, so it carries what the op got, the position in the program and, for a wrong type, the op's form (DOCS.md, "What a message says"). An op refuses through `failAt` (`errors.ts`), which keeps the node beside the error; `evaluate` and `execute` catch it once on the way out and `placeError` (`engine/place.ts`) finds the node and writes the position. Describing, finding and printing happen only for an error, never while a program succeeds.
|
|
142
|
+
|
|
141
143
|
---
|
|
142
144
|
|
|
143
145
|
## File Structure
|
|
@@ -145,7 +147,7 @@ All errors are `PrismError` instances with a `.code` string and optional `.conte
|
|
|
145
147
|
```
|
|
146
148
|
src/
|
|
147
149
|
├── index.ts # Public API barrel
|
|
148
|
-
├── errors.ts # PrismError + error codes
|
|
150
|
+
├── errors.ts # PrismError + error codes; failAt keeps the node an error came from
|
|
149
151
|
├── types.ts # JsonValue, EvalContext, CompiledIr, etc.
|
|
150
152
|
├── schemas/
|
|
151
153
|
│ ├── index.ts # Schema barrel
|
|
@@ -173,9 +175,11 @@ src/
|
|
|
173
175
|
│ ├── optimize.ts # Compile-time passes (ref segments, handlers, constant folding)
|
|
174
176
|
│ ├── budget.ts # Limits: steps, string length, result size
|
|
175
177
|
│ ├── execute.ts # CompiledIr + source → result
|
|
178
|
+
│ ├── place.ts # On the way out: an error's position, in the author's config, and the op's form
|
|
176
179
|
│ ├── validate.ts # Config validation
|
|
177
180
|
│ └── documentation.ts # JSON Schema generation
|
|
178
181
|
├── ops/ # One implementation file per category
|
|
182
|
+
│ ├── refuse.ts # The sentence for an op given the wrong kind of value
|
|
179
183
|
│ ├── core.ops.ts
|
|
180
184
|
│ ├── array.ops.ts
|
|
181
185
|
│ ├── math.ops.ts
|
|
@@ -224,7 +228,7 @@ and a mapping over a thousand rows would otherwise build a thousand of them.
|
|
|
224
228
|
|
|
225
229
|
1. **Linear if-chain over Map dispatch.** Type narrowing. Each guard narrows the node type. A Map would need casts.
|
|
226
230
|
|
|
227
|
-
2. **Desugar before execution, not during.** One canonical representation. Compiler stores desugared form.
|
|
231
|
+
2. **Desugar before execution, not during.** One canonical representation. Compiler stores desugared form. An error inside a sugar op names the core op that refused and the sugar op the author wrote: `engine/place.ts` follows the position back into the author's config, and where a sugar op's keys stop matching, rewrites a copy of it with a marker in each field to see where each field went. Nothing records the rewrite while it runs; the work is done only for an error.
|
|
228
232
|
|
|
229
233
|
3. **JSONPath subset, not full spec.** Filters, recursive descent, and unions overlap with `$filter`, `$map`, and `$merge`. The subset covers path access; ops cover everything else.
|
|
230
234
|
|
package/DOCS.md
CHANGED
|
@@ -81,7 +81,7 @@ Throws `E_VAR_NOT_FOUND` if the variable doesn't exist in scope.
|
|
|
81
81
|
|
|
82
82
|
### `$get` — Dynamic path access
|
|
83
83
|
|
|
84
|
-
Navigates into a value using an array of path segments. Segments can be strings (object keys), numbers (array indices), or node expressions (evaluated dynamically).
|
|
84
|
+
Navigates into a value using an array of path segments. Segments can be strings (object keys), numbers (array indices), or node expressions (evaluated dynamically). On a list, a string of digits is an index too, as JavaScript and JSON Pointer read it: `["link", "0"]` and `["link", 0]` both read the first item of `link`. Only digits count: `"01"`, `"-1"` and `" 0"` are keys, and a list has none.
|
|
85
85
|
|
|
86
86
|
```json
|
|
87
87
|
{ "$get": { "from": { "$ref": "$.user" }, "path": ["address", "city"] } }
|
|
@@ -278,7 +278,7 @@ A number is answered as it is. Text is read as a number when it is one written i
|
|
|
278
278
|
```json
|
|
279
279
|
{ "$join": { "parts": [{ "$ref": "$.first" }, { "$ref": "$.last" }], "sep": " " } }
|
|
280
280
|
```
|
|
281
|
-
Parts are coerced to strings. `sep` defaults to `""`. `parts` may also be any
|
|
281
|
+
Parts are coerced to strings; `null` is `""`. A part that is an object or a list is refused (`E_TYPE`): it has no text of its own. `sep` defaults to `""`. `parts` may also be any
|
|
282
282
|
node that evaluates to an array — a mapped list, a `$var`:
|
|
283
283
|
```json
|
|
284
284
|
{ "$join": { "parts": { "$map": { "over": { "$ref": "$.tags" }, "as": "t", "body": { "$upper": { "$var": "t" } } } }, "sep": ", " } }
|
|
@@ -299,7 +299,7 @@ Numbers → `"42"`, null → `"null"`, objects → JSON string.
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
```
|
|
302
|
-
Replaces `{{key}}` placeholders with values from the evaluated object. Missing keys become empty strings.
|
|
302
|
+
Replaces `{{key}}` placeholders with values from the evaluated object. Missing keys become empty strings. A value that is an object or a list is refused (`E_TYPE`).
|
|
303
303
|
|
|
304
304
|
### `$fill` — Fill a counted phrase
|
|
305
305
|
```json
|
|
@@ -442,7 +442,7 @@ Evaluates branches in order, returns the `then` of the first truthy `when`. Fall
|
|
|
442
442
|
```
|
|
443
443
|
`[{ "id": "u1", "name": "Alice" }]` → `{ "u1": { "id": "u1", "name": "Alice" } }`
|
|
444
444
|
|
|
445
|
-
Last element wins on key collision.
|
|
445
|
+
Last element wins on key collision. A key is text, a number, `true`, `false` or `null`, written as text; an object or a list is refused (`E_TYPE`).
|
|
446
446
|
|
|
447
447
|
### `$groupBy` — Array to grouped object
|
|
448
448
|
```json
|
|
@@ -454,7 +454,7 @@ Last element wins on key collision.
|
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
```
|
|
457
|
-
Groups elements into arrays by computed key: `{ "fruit": [...], "vegetable": [...] }`
|
|
457
|
+
Groups elements into arrays by computed key: `{ "fruit": [...], "vegetable": [...] }`. A key is text, a number, `true`, `false` or `null`, written as text; an object or a list is refused (`E_TYPE`).
|
|
458
458
|
|
|
459
459
|
---
|
|
460
460
|
|
|
@@ -832,4 +832,17 @@ each time it appears, as it would be serialized: a `$reduce` whose body is
|
|
|
832
832
|
|
|
833
833
|
All errors are instances of `PrismError` with `.code` and optional `.context`.
|
|
834
834
|
|
|
835
|
+
**What a message says.** The message is written for the program's author, often a model that sees nothing else, so it carries everything needed to fix the program:
|
|
836
|
+
|
|
837
|
+
- **what the op got:** `null`, `the number 5`, `text "…"` (up to 60 characters), `a list of 2 items: […]` or `an object: {…}` (up to 80 characters of JSON). Where the field was written in the program as an object without a `$` key, it says so: such an object builds an object.
|
|
838
|
+
- **where:** `At $map.body.title.$trim.`, a position in the config as it was handed to `evaluate`. Inside a sugar op it is the sugar op's position (`At s.$sum, in the $add that $sum runs as.`). `execute` gives the position in the compiled tree.
|
|
839
|
+
- **the op's form**, for a wrong type and for a `$get` path: `Form: {"$split": {"value": <node>, "sep": <text>}}`, printed from the schema.
|
|
840
|
+
- for a path that found nothing, where it stopped and what is there (`stopped at "fields": the value at $.records is a list of 2 items`); for a variable that is not there, the ones in scope.
|
|
841
|
+
|
|
842
|
+
A refused config says the same in `evaluate`'s and `compile`'s message: `Invalid config: <path>: <issue>; …`, with the form of the op the issue is on. `.context` is unchanged: `op`, `path` and `details` are as before.
|
|
843
|
+
|
|
844
|
+
```
|
|
845
|
+
$trim needs text, but got an object: {"value":"Quarterly contributor outreach"}. That object was written in the program as {"value":{"$get":…}}, and an object without a "$" key builds an object; put the node itself there. At $map.body.title.$trim. Form: {"$trim": <node>}
|
|
846
|
+
```
|
|
847
|
+
|
|
835
848
|
**Valid, and what it does not promise.** `validate`, `evaluate` and `compile` hold a config to the same schema, so a config that validates has no node the evaluator cannot dispatch: every object in it is an op Prism has or a plain object with no `$` key. It can still fail on the data it is given — a missing path, a wrong type, a budget. `E_NODE_SHAPE` is what is left for a tree the schema never saw: an IR handed to `execute`, which does not validate.
|
package/dist/agent.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkROYHYYIL_cjs = require('./chunk-ROYHYYIL.cjs');
|
|
4
|
+
var chunkQUI2X5JB_cjs = require('./chunk-QUI2X5JB.cjs');
|
|
5
5
|
var zod = require('zod');
|
|
6
6
|
var cortex = require('@niscorp/cortex');
|
|
7
7
|
|
|
@@ -21,7 +21,7 @@ Worked example (illustrative only \u2014 read the schema for op details):
|
|
|
21
21
|
INPUT { "sampleInput": { "first": "Ada", "last": "Lovelace" }, "targetShape": { "fullName": "" } }
|
|
22
22
|
data { "fullName": { "$interpolate": { "template": "{{f}} {{l}}", "values": { "f": { "$ref": "$.first" }, "l": { "$ref": "$.last" } } } } }`;
|
|
23
23
|
var OUTPUT_DOC = `OUTPUT SCHEMA \u2014 your output MUST validate against this JSON Schema:
|
|
24
|
-
${JSON.stringify(
|
|
24
|
+
${JSON.stringify(chunkROYHYYIL_cjs.getProfileJsonSchema(chunkROYHYYIL_cjs.MAPPING_OPS, "draft-7"))}`;
|
|
25
25
|
var mappingAgent = cortex.defineAgent({
|
|
26
26
|
id: "prism.mapping",
|
|
27
27
|
description: "Generates a Prism transformation config from a sample input row and a target shape.",
|
|
@@ -29,7 +29,7 @@ var mappingAgent = cortex.defineAgent({
|
|
|
29
29
|
// Validated against the full grammar, documented with the mapping profile:
|
|
30
30
|
// a config using an op outside the profile is still accepted. The doc keeps
|
|
31
31
|
// cortex's own heading, "OUTPUT SCHEMA", which its finish protocol names.
|
|
32
|
-
output: { schema:
|
|
32
|
+
output: { schema: chunkQUI2X5JB_cjs.ConfigSchema, doc: OUTPUT_DOC }
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
exports.MappingAgentInputSchema = MappingAgentInputSchema;
|
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-VNGBVDUM.js';
|
|
2
|
+
import { ConfigSchema } from './chunk-OL4CCYWX.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { defineAgent } from '@niscorp/cortex';
|
|
5
5
|
|
|
@@ -22,6 +22,26 @@ var PrismError = class extends Error {
|
|
|
22
22
|
this.context = context;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
+
var origins = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
var takeOrigin = (error) => {
|
|
27
|
+
const origin = origins.get(error);
|
|
28
|
+
origins.delete(error);
|
|
29
|
+
return origin;
|
|
30
|
+
};
|
|
31
|
+
var failAt = (message, code, context, origin) => {
|
|
32
|
+
const error = new PrismError(message, code, context);
|
|
33
|
+
origins.set(error, origin);
|
|
34
|
+
throw error;
|
|
35
|
+
};
|
|
36
|
+
var clip = (text, max) => text.length > max ? `${text.slice(0, max)}\u2026` : text;
|
|
37
|
+
var describeValue = (value) => {
|
|
38
|
+
if (value === null || value === void 0) return "null";
|
|
39
|
+
if (typeof value === "string") return `text ${clip(JSON.stringify(value), 60)}`;
|
|
40
|
+
if (typeof value === "number" || typeof value === "boolean") return `the ${typeof value} ${String(value)}`;
|
|
41
|
+
const json = clip(JSON.stringify(value) ?? String(value), 80);
|
|
42
|
+
if (Array.isArray(value)) return `a list of ${value.length} item${value.length === 1 ? "" : "s"}: ${json}`;
|
|
43
|
+
return `an object: ${json}`;
|
|
44
|
+
};
|
|
25
45
|
var JsonPrimitiveSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).describe("JSON primitive: string | number | boolean | null");
|
|
26
46
|
var JsonValueSchema = z.lazy(
|
|
27
47
|
() => z.union([JsonPrimitiveSchema, z.array(JsonValueSchema), z.record(z.string(), JsonValueSchema)])
|
|
@@ -171,6 +191,32 @@ var parseJsonPathCached = (path) => {
|
|
|
171
191
|
cache.set(path, parsed);
|
|
172
192
|
return parsed;
|
|
173
193
|
};
|
|
194
|
+
var INDEX_TEXT = /^(0|[1-9][0-9]*)$/;
|
|
195
|
+
var MAX_KEYS = 10;
|
|
196
|
+
var whereStopped = (root, steps, nameUpTo, digitsIndex = false) => {
|
|
197
|
+
let at = root;
|
|
198
|
+
for (const [i, raw] of steps.entries()) {
|
|
199
|
+
const here = nameUpTo(i);
|
|
200
|
+
const shown = JSON.stringify(raw);
|
|
201
|
+
const step = digitsIndex && typeof raw === "string" && isJsonArray(at) && INDEX_TEXT.test(raw) ? Number(raw) : raw;
|
|
202
|
+
if (typeof step === "number") {
|
|
203
|
+
if (!isJsonArray(at)) return `stopped at ${shown}: the value at ${here} is ${describeValue(at)}, and only a list is read by index.`;
|
|
204
|
+
if (at[step] === void 0) return `stopped at ${shown}: the list at ${here} has ${at.length} item${at.length === 1 ? "" : "s"}.`;
|
|
205
|
+
at = at[step];
|
|
206
|
+
} else {
|
|
207
|
+
if (isJsonArray(at)) return `stopped at ${shown}: the value at ${here} is ${describeValue(at)}, and a list is read by index, a number; for every item use $map.`;
|
|
208
|
+
if (!isJsonObject(at)) return `stopped at ${shown}: the value at ${here} is ${describeValue(at)}, which has no keys.`;
|
|
209
|
+
if (at[step] === void 0) {
|
|
210
|
+
const keys = Object.keys(at);
|
|
211
|
+
const listed = keys.slice(0, MAX_KEYS).join(", ") + (keys.length > MAX_KEYS ? ", \u2026" : "");
|
|
212
|
+
return `stopped at ${shown}: the object at ${here} has no key ${shown} (${keys.length === 0 ? "it has no keys" : `its keys: ${listed}`}).`;
|
|
213
|
+
}
|
|
214
|
+
at = at[step];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return "";
|
|
218
|
+
};
|
|
219
|
+
var jsonPathUpTo = (segments, count) => segments.slice(0, count).reduce((text, s) => s.type === "key" ? `${text}.${s.key}` : `${text}[${s.index}]`, "$");
|
|
174
220
|
var getByPath = (root, segments) => {
|
|
175
221
|
let current = root;
|
|
176
222
|
for (const segment of segments) {
|
|
@@ -705,19 +751,26 @@ var opMembersOf = (options) => {
|
|
|
705
751
|
}
|
|
706
752
|
return members;
|
|
707
753
|
};
|
|
708
|
-
var
|
|
709
|
-
if (value === null || typeof value !== "object") return JsonPrimitiveSchema;
|
|
710
|
-
if (Array.isArray(value)) return NodeArraySchema;
|
|
754
|
+
var isPlainProto = (value) => {
|
|
711
755
|
const proto = Object.getPrototypeOf(value);
|
|
712
|
-
|
|
713
|
-
|
|
756
|
+
return proto === Object.prototype || proto === null;
|
|
757
|
+
};
|
|
758
|
+
var soleOpKey = (value) => {
|
|
759
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || !isPlainProto(value)) return void 0;
|
|
760
|
+
let sole;
|
|
714
761
|
let count = 0;
|
|
715
762
|
for (const key in value) {
|
|
716
763
|
count += 1;
|
|
717
|
-
|
|
764
|
+
sole = key;
|
|
718
765
|
}
|
|
719
|
-
|
|
720
|
-
|
|
766
|
+
return count === 1 && sole !== void 0 && sole.startsWith("$") ? sole : void 0;
|
|
767
|
+
};
|
|
768
|
+
var memberOf = (value) => {
|
|
769
|
+
if (value === null || typeof value !== "object") return JsonPrimitiveSchema;
|
|
770
|
+
if (Array.isArray(value)) return NodeArraySchema;
|
|
771
|
+
if (!isPlainProto(value)) return void 0;
|
|
772
|
+
for (const key in value) if (key.startsWith("$")) return void 0;
|
|
773
|
+
return TemplateSchema;
|
|
721
774
|
};
|
|
722
775
|
var quick = /* @__PURE__ */ new WeakSet();
|
|
723
776
|
var walking = /* @__PURE__ */ new WeakSet();
|
|
@@ -726,8 +779,15 @@ var NodeUnion = z.core.$constructor("PrismNodeUnion", (inst, def) => {
|
|
|
726
779
|
const ops = opMembersOf(def.options);
|
|
727
780
|
const walk = inst._zod.parse;
|
|
728
781
|
inst._zod.parse = (payload, ctx) => {
|
|
782
|
+
const sole = soleOpKey(payload.value);
|
|
783
|
+
if (sole !== void 0) {
|
|
784
|
+
const op = ops.get(sole);
|
|
785
|
+
if (op !== void 0) return op._zod.run(payload, ctx);
|
|
786
|
+
payload.issues.push({ code: "custom", input: payload.value, path: [sole], message: templateKeyRefusal(sole), inst });
|
|
787
|
+
return payload;
|
|
788
|
+
}
|
|
729
789
|
if (ctx.async !== false || walking.has(ctx)) return walk(payload, ctx);
|
|
730
|
-
const member = memberOf(payload.value
|
|
790
|
+
const member = memberOf(payload.value);
|
|
731
791
|
if (quick.has(ctx)) {
|
|
732
792
|
if (member !== void 0) return member._zod.run(payload, ctx);
|
|
733
793
|
payload.issues.push({ code: "custom", input: payload.value, inst });
|
|
@@ -747,88 +807,154 @@ var NodeUnion = z.core.$constructor("PrismNodeUnion", (inst, def) => {
|
|
|
747
807
|
}
|
|
748
808
|
};
|
|
749
809
|
});
|
|
810
|
+
var OP_MEMBERS = [
|
|
811
|
+
RefNodeSchema,
|
|
812
|
+
ConstNodeSchema,
|
|
813
|
+
VarNodeSchema,
|
|
814
|
+
GetNodeSchema,
|
|
815
|
+
WithNodeSchema,
|
|
816
|
+
MapNodeSchema,
|
|
817
|
+
FilterNodeSchema,
|
|
818
|
+
ReduceNodeSchema,
|
|
819
|
+
SliceNodeSchema,
|
|
820
|
+
FlattenNodeSchema,
|
|
821
|
+
UniqueNodeSchema,
|
|
822
|
+
SortByNodeSchema,
|
|
823
|
+
AddNodeSchema,
|
|
824
|
+
SubNodeSchema,
|
|
825
|
+
MulNodeSchema,
|
|
826
|
+
DivNodeSchema,
|
|
827
|
+
ModNodeSchema,
|
|
828
|
+
RoundNodeSchema,
|
|
829
|
+
ToNumberNodeSchema,
|
|
830
|
+
FillNodeSchema,
|
|
831
|
+
JoinNodeSchema,
|
|
832
|
+
ToStringNodeSchema,
|
|
833
|
+
InterpolateNodeSchema,
|
|
834
|
+
TrimNodeSchema,
|
|
835
|
+
LowerNodeSchema,
|
|
836
|
+
UpperNodeSchema,
|
|
837
|
+
SplitNodeSchema,
|
|
838
|
+
ReplaceNodeSchema,
|
|
839
|
+
EqNodeSchema,
|
|
840
|
+
NeqNodeSchema,
|
|
841
|
+
GtNodeSchema,
|
|
842
|
+
GteNodeSchema,
|
|
843
|
+
LtNodeSchema,
|
|
844
|
+
LteNodeSchema,
|
|
845
|
+
EmptyNodeSchema,
|
|
846
|
+
StartsWithNodeSchema,
|
|
847
|
+
EndsWithNodeSchema,
|
|
848
|
+
ContainsNodeSchema,
|
|
849
|
+
NotNodeSchema,
|
|
850
|
+
AndNodeSchema,
|
|
851
|
+
OrNodeSchema,
|
|
852
|
+
MergeNodeSchema,
|
|
853
|
+
CoalesceNodeSchema,
|
|
854
|
+
CaseNodeSchema,
|
|
855
|
+
EntriesOfNodeSchema,
|
|
856
|
+
KeyByNodeSchema,
|
|
857
|
+
GroupByNodeSchema,
|
|
858
|
+
KeysNodeSchema,
|
|
859
|
+
ValuesNodeSchema,
|
|
860
|
+
FromEntriesNodeSchema,
|
|
861
|
+
PickNodeSchema,
|
|
862
|
+
OmitNodeSchema,
|
|
863
|
+
TypeNodeSchema,
|
|
864
|
+
LengthNodeSchema,
|
|
865
|
+
DateNodeSchema,
|
|
866
|
+
DateAddNodeSchema,
|
|
867
|
+
DateDiffNodeSchema,
|
|
868
|
+
LocaleDateNodeSchema,
|
|
869
|
+
LocaleMoneyNodeSchema,
|
|
870
|
+
LocaleNumberNodeSchema,
|
|
871
|
+
SumNodeSchema,
|
|
872
|
+
AvgNodeSchema,
|
|
873
|
+
CountNodeSchema,
|
|
874
|
+
MinNodeSchema,
|
|
875
|
+
MaxNodeSchema,
|
|
876
|
+
PluckNodeSchema,
|
|
877
|
+
TakeNodeSchema,
|
|
878
|
+
DropNodeSchema,
|
|
879
|
+
MatchNodeSchema,
|
|
880
|
+
FlatMapNodeSchema,
|
|
881
|
+
HasNodeSchema,
|
|
882
|
+
RenameKeysNodeSchema,
|
|
883
|
+
UpdateNodeSchema,
|
|
884
|
+
AssertNodeSchema,
|
|
885
|
+
WalkNodeSchema
|
|
886
|
+
];
|
|
750
887
|
var NodeSchema = z.lazy(
|
|
751
888
|
() => new NodeUnion({ type: "union", options: [
|
|
752
|
-
|
|
753
|
-
ConstNodeSchema,
|
|
754
|
-
VarNodeSchema,
|
|
755
|
-
GetNodeSchema,
|
|
756
|
-
WithNodeSchema,
|
|
757
|
-
MapNodeSchema,
|
|
758
|
-
FilterNodeSchema,
|
|
759
|
-
ReduceNodeSchema,
|
|
760
|
-
SliceNodeSchema,
|
|
761
|
-
FlattenNodeSchema,
|
|
762
|
-
UniqueNodeSchema,
|
|
763
|
-
SortByNodeSchema,
|
|
764
|
-
AddNodeSchema,
|
|
765
|
-
SubNodeSchema,
|
|
766
|
-
MulNodeSchema,
|
|
767
|
-
DivNodeSchema,
|
|
768
|
-
ModNodeSchema,
|
|
769
|
-
RoundNodeSchema,
|
|
770
|
-
ToNumberNodeSchema,
|
|
771
|
-
FillNodeSchema,
|
|
772
|
-
JoinNodeSchema,
|
|
773
|
-
ToStringNodeSchema,
|
|
774
|
-
InterpolateNodeSchema,
|
|
775
|
-
TrimNodeSchema,
|
|
776
|
-
LowerNodeSchema,
|
|
777
|
-
UpperNodeSchema,
|
|
778
|
-
SplitNodeSchema,
|
|
779
|
-
ReplaceNodeSchema,
|
|
780
|
-
EqNodeSchema,
|
|
781
|
-
NeqNodeSchema,
|
|
782
|
-
GtNodeSchema,
|
|
783
|
-
GteNodeSchema,
|
|
784
|
-
LtNodeSchema,
|
|
785
|
-
LteNodeSchema,
|
|
786
|
-
EmptyNodeSchema,
|
|
787
|
-
StartsWithNodeSchema,
|
|
788
|
-
EndsWithNodeSchema,
|
|
789
|
-
ContainsNodeSchema,
|
|
790
|
-
NotNodeSchema,
|
|
791
|
-
AndNodeSchema,
|
|
792
|
-
OrNodeSchema,
|
|
793
|
-
MergeNodeSchema,
|
|
794
|
-
CoalesceNodeSchema,
|
|
795
|
-
CaseNodeSchema,
|
|
796
|
-
EntriesOfNodeSchema,
|
|
797
|
-
KeyByNodeSchema,
|
|
798
|
-
GroupByNodeSchema,
|
|
799
|
-
KeysNodeSchema,
|
|
800
|
-
ValuesNodeSchema,
|
|
801
|
-
FromEntriesNodeSchema,
|
|
802
|
-
PickNodeSchema,
|
|
803
|
-
OmitNodeSchema,
|
|
804
|
-
TypeNodeSchema,
|
|
805
|
-
LengthNodeSchema,
|
|
806
|
-
DateNodeSchema,
|
|
807
|
-
DateAddNodeSchema,
|
|
808
|
-
DateDiffNodeSchema,
|
|
809
|
-
LocaleDateNodeSchema,
|
|
810
|
-
LocaleMoneyNodeSchema,
|
|
811
|
-
LocaleNumberNodeSchema,
|
|
812
|
-
SumNodeSchema,
|
|
813
|
-
AvgNodeSchema,
|
|
814
|
-
CountNodeSchema,
|
|
815
|
-
MinNodeSchema,
|
|
816
|
-
MaxNodeSchema,
|
|
817
|
-
PluckNodeSchema,
|
|
818
|
-
TakeNodeSchema,
|
|
819
|
-
DropNodeSchema,
|
|
820
|
-
MatchNodeSchema,
|
|
821
|
-
FlatMapNodeSchema,
|
|
822
|
-
HasNodeSchema,
|
|
823
|
-
RenameKeysNodeSchema,
|
|
824
|
-
UpdateNodeSchema,
|
|
825
|
-
AssertNodeSchema,
|
|
826
|
-
WalkNodeSchema,
|
|
889
|
+
...OP_MEMBERS,
|
|
827
890
|
JsonPrimitiveSchema,
|
|
828
891
|
NodeArraySchema,
|
|
829
892
|
TemplateSchema
|
|
830
893
|
] }).describe("A Prism node: an op, a plain JSON value, an array of nodes, or a plain object template.")
|
|
831
894
|
);
|
|
895
|
+
var isMember = (value) => typeof value === "object" && value !== null && "_zod" in value;
|
|
896
|
+
var shapeOf = (schema) => {
|
|
897
|
+
const { def } = schema._zod;
|
|
898
|
+
const inner = (key) => {
|
|
899
|
+
const value = Reflect.get(def, key);
|
|
900
|
+
return isMember(value) ? shapeOf(value) : "<any JSON>";
|
|
901
|
+
};
|
|
902
|
+
const list = (key) => {
|
|
903
|
+
const value = Reflect.get(def, key);
|
|
904
|
+
return Array.isArray(value) ? value.filter(isMember) : [];
|
|
905
|
+
};
|
|
906
|
+
switch (def.type) {
|
|
907
|
+
case "lazy": {
|
|
908
|
+
const getter = Reflect.get(def, "getter");
|
|
909
|
+
return typeof getter === "function" && getter() === NodeSchema ? "<node>" : "<any JSON>";
|
|
910
|
+
}
|
|
911
|
+
case "string":
|
|
912
|
+
return "<text>";
|
|
913
|
+
case "number":
|
|
914
|
+
return "<number>";
|
|
915
|
+
case "boolean":
|
|
916
|
+
return "true|false";
|
|
917
|
+
case "null":
|
|
918
|
+
return "null";
|
|
919
|
+
case "enum": {
|
|
920
|
+
const entries = Reflect.get(def, "entries");
|
|
921
|
+
return typeof entries === "object" && entries !== null ? Object.values(entries).map((v) => JSON.stringify(v)).join("|") : "<text>";
|
|
922
|
+
}
|
|
923
|
+
case "optional":
|
|
924
|
+
case "default":
|
|
925
|
+
case "nullable":
|
|
926
|
+
case "readonly":
|
|
927
|
+
case "prefault":
|
|
928
|
+
return inner("innerType");
|
|
929
|
+
case "array":
|
|
930
|
+
return `[${inner("element")}, \u2026]`;
|
|
931
|
+
case "tuple":
|
|
932
|
+
return `[${list("items").map(shapeOf).join(", ")}]`;
|
|
933
|
+
case "union":
|
|
934
|
+
return list("options").map(shapeOf).join(" or ");
|
|
935
|
+
case "record":
|
|
936
|
+
return `{<name>: ${inner("valueType")}}`;
|
|
937
|
+
case "object": {
|
|
938
|
+
const shape = Reflect.get(def, "shape");
|
|
939
|
+
if (typeof shape !== "object" || shape === null) return "{\u2026}";
|
|
940
|
+
const fields = Object.entries(shape).filter((entry) => isMember(entry[1])).map(([key, field]) => {
|
|
941
|
+
const optional = field._zod.def.type === "optional" || field._zod.def.type === "default";
|
|
942
|
+
return `"${key}"${optional ? "?" : ""}: ${shapeOf(field)}`;
|
|
943
|
+
});
|
|
944
|
+
return `{${fields.join(", ")}}`;
|
|
945
|
+
}
|
|
946
|
+
default:
|
|
947
|
+
return `<${def.type}>`;
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
var forms;
|
|
951
|
+
var formOf = (op) => {
|
|
952
|
+
forms ??= opMembersOf(OP_MEMBERS);
|
|
953
|
+
const member = forms.get(op);
|
|
954
|
+
const shape = member === void 0 ? void 0 : Reflect.get(member._zod.def, "shape");
|
|
955
|
+
const field = typeof shape === "object" && shape !== null ? Reflect.get(shape, op) : void 0;
|
|
956
|
+
return isMember(field) ? `{"${op}": ${shapeOf(field)}}` : void 0;
|
|
957
|
+
};
|
|
832
958
|
setNodeSchema(NodeSchema);
|
|
833
959
|
setNodeSchema2(NodeSchema);
|
|
834
960
|
setNodeSchema3(NodeSchema);
|
|
@@ -845,6 +971,6 @@ var ConfigSchema = NodeSchema.describe(
|
|
|
845
971
|
"A Prism config: the top-level transformation definition. Can be any valid node."
|
|
846
972
|
);
|
|
847
973
|
|
|
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-
|
|
850
|
-
//# sourceMappingURL=chunk-
|
|
974
|
+
export { ConfigSchema, ErrorCode, INDEX_TEXT, NodeSchema, OPTIONAL_FIELDS_KEY, OP_KEYS, PrismError, clip, describeValue, failAt, formOf, 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, jsonPathUpTo, parseJsonPath, parseJsonPathCached, takeOrigin, whereStopped };
|
|
975
|
+
//# sourceMappingURL=chunk-OL4CCYWX.js.map
|
|
976
|
+
//# sourceMappingURL=chunk-OL4CCYWX.js.map
|