@amritk/mjst 0.27.3 → 0.28.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/README.md +5 -3
- package/dist/cli-config.d.ts +3 -3
- package/dist/load-schema.d.ts +6 -3
- package/dist/load-schema.js +2 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -176,8 +176,10 @@ tree-shake identically (verified against esbuild and rollup).
|
|
|
176
176
|
|
|
177
177
|
A schema can split its definitions across files. When a schema references another
|
|
178
178
|
document — `{ "$ref": "./address.json" }` or `{ "$ref": "./common.json#/$defs/id" }` —
|
|
179
|
-
mjst
|
|
180
|
-
|
|
179
|
+
mjst bundles those cross-file targets before generating: each one is pulled into the
|
|
180
|
+
schema's `$defs` once and its refs point there, so the generator sees a single schema
|
|
181
|
+
and still emits one named type per shared definition — the same output as if the
|
|
182
|
+
definitions had been written in one file:
|
|
181
183
|
|
|
182
184
|
```bash
|
|
183
185
|
npx mjst --schema ./order.json --out-dir ./generated
|
|
@@ -472,7 +474,7 @@ usage error. Run `mjst markdown --help` for details.
|
|
|
472
474
|
<td align="center"><code>false</code></td>
|
|
473
475
|
</tr>
|
|
474
476
|
<tr>
|
|
475
|
-
<td colspan="4">Also emit a coerceX alongside each validateX. It moves scalars toward the type the schema declares and then runs the very same validateX over the result, so a config value written the YAML way reads the same whether it came from a config file or an extension. The input is never modified and nothing is substituted: a value that cannot be coerced into a valid one reaches the validator untouched, so the error names what the caller actually wrote, with the keyword and params that rejected it. The table is Ajv's coerceTypes minus the cells where Ajv guesses — no whitespace-to-zero, no hex or Infinity strings, and nothing coerced to or from null, deliberately, since null usually means not set — so every scalar this coerces, Ajv coerces to the same value, and the rest become errors rather than silent repairs. Moving off Ajv, check how your callers treat a rejected value: a caller that reads rejection as absence silently drops any block holding a null that Ajv used to coerce, so surface the errors or allow null in the schema. Coercion reaches through $ref, allOf, if/then/else and unions. At a union a value that already matches a branch as written is left alone; otherwise each branch coerces it its own way, and the result is taken only when every branch that then accepts it agrees on it. So the answer does not depend on the order the union was written in, and a const false branch keeps false where Ajv turns it into the string false through an earlier string branch. A valid document comes back as the very same object. Where the caller cannot let Ajv mutate its input, so Ajv has to clone it first, coerceX
|
|
477
|
+
<td colspan="4">Also emit a coerceX alongside each validateX. It moves scalars toward the type the schema declares and then runs the very same validateX over the result, so a config value written the YAML way reads the same whether it came from a config file or an extension. The input is never modified and nothing is substituted: a value that cannot be coerced into a valid one reaches the validator untouched, so the error names what the caller actually wrote, with the keyword and params that rejected it. The table is Ajv's coerceTypes minus the cells where Ajv guesses — no whitespace-to-zero, no hex or Infinity strings, and nothing coerced to or from null, deliberately, since null usually means not set — so every scalar this coerces, Ajv coerces to the same value, and the rest become errors rather than silent repairs. Moving off Ajv, check how your callers treat a rejected value: a caller that reads rejection as absence silently drops any block holding a null that Ajv used to coerce, so surface the errors or allow null in the schema. Coercion reaches through $ref, allOf, if/then/else and unions. At a union a value that already matches a branch as written is left alone; otherwise each branch coerces it its own way, and the result is taken only when every branch that then accepts it agrees on it. So the answer does not depend on the order the union was written in, and a const false branch keeps false where Ajv turns it into the string false through an earlier string branch. A valid document comes back as the very same object. Where the caller cannot let Ajv mutate its input, so Ajv has to clone it first, coerceX is faster, by the widest margin on valid input; where the caller lets Ajv coerce its document in place there is no clone to save, and on a large document Ajv can come out modestly ahead. Requires validators.</td>
|
|
476
478
|
</tr>
|
|
477
479
|
<tr>
|
|
478
480
|
<td>🔧 <code>repair</code></td>
|
package/dist/cli-config.d.ts
CHANGED
|
@@ -113,9 +113,9 @@ export type CliConfig = {
|
|
|
113
113
|
*
|
|
114
114
|
* A document that is already valid is answered by `isX` alone where that is a
|
|
115
115
|
* standalone guard, and handed back as the very same object. Where the caller
|
|
116
|
-
* cannot let Ajv mutate its input, so Ajv has to clone it first, `coerceX`
|
|
117
|
-
*
|
|
118
|
-
*
|
|
116
|
+
* cannot let Ajv mutate its input, so Ajv has to clone it first, `coerceX` is
|
|
117
|
+
* faster, by the widest margin on valid input (`bench:validators:coerce`).
|
|
118
|
+
* Where the caller owns the document and lets Ajv
|
|
119
119
|
* coerce it in place, there is no clone to save, and on a large document Ajv
|
|
120
120
|
* can come out modestly ahead.
|
|
121
121
|
*
|
package/dist/load-schema.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ import type { CliConfig } from './cli-config.js';
|
|
|
6
6
|
* pointers is parsed as-is — the generator resolves those internal `$ref`s
|
|
7
7
|
* itself into named type files, so inlining them here would collapse that
|
|
8
8
|
* structure. When a cross-file or remote `$ref` is present (which the generator
|
|
9
|
-
* cannot follow on its own), the schema is
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* cannot follow on its own), the schema is *bundled* with `@amritk/resolve-refs`:
|
|
10
|
+
* every external target is pulled into the root's `$defs` once and its refs point
|
|
11
|
+
* there, so the generator sees a single document and still turns each shared
|
|
12
|
+
* schema into one named type. Inlining instead lost those names for internal refs
|
|
13
|
+
* too — any one external `$ref` turned every shared schema into a copy at each use,
|
|
14
|
+
* which on layered schemas is exponential in the output. Any resolve failures are surfaced as a CLI error rather than silently yielding
|
|
12
15
|
* a half-resolved schema.
|
|
13
16
|
*
|
|
14
17
|
* Avro splits the difference, and is the reason this is not a plain
|
package/dist/load-schema.js
CHANGED
|
@@ -12,7 +12,8 @@ const loadSchema = async (config, schemaPath) => {
|
|
|
12
12
|
return data;
|
|
13
13
|
const { resolved, errors } = await resolveRefsFromFile(schemaPath, {
|
|
14
14
|
...buildResolveOptions(config, schemaPath),
|
|
15
|
-
rootDocument: data
|
|
15
|
+
rootDocument: data,
|
|
16
|
+
bundle: true
|
|
16
17
|
});
|
|
17
18
|
if (errors.length > 0)
|
|
18
19
|
throw new Error(formatResolveErrors(schemaPath, errors));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/mjst",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"@amritk/generate-examples": "^0.8.12",
|
|
56
56
|
"@amritk/generate-markdown": "^0.12.0",
|
|
57
57
|
"@amritk/helpers": "^0.26.0",
|
|
58
|
-
"@amritk/lint": "^0.
|
|
58
|
+
"@amritk/lint": "^0.10.1",
|
|
59
59
|
"@amritk/validation": "^0.6.1",
|
|
60
|
-
"@amritk/resolve-refs": "^0.
|
|
61
|
-
"@amritk/yaml": "^0.8.
|
|
60
|
+
"@amritk/resolve-refs": "^0.10.0",
|
|
61
|
+
"@amritk/yaml": "^0.8.1",
|
|
62
62
|
"fast-glob": "^3.3.2",
|
|
63
63
|
"json-schema-typed": "^8.0.1",
|
|
64
64
|
"yargs": "^17.7.2"
|