@amritk/validation 0.6.1 → 0.6.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/README.md +18 -34
- package/dist/parsers/helpers/collect-imports.js +8 -8
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -211,35 +211,22 @@ document has to clone it first. `coerceX` returns a new value that shares
|
|
|
211
211
|
everything it did not touch, or the input itself when nothing needed coercing.
|
|
212
212
|
|
|
213
213
|
**It is faster where the input has to survive.** Against Ajv cloning first, so
|
|
214
|
-
both leave the caller's document alone
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
valid document is the common case and the widest gap: `coerceX` answers it with
|
|
231
|
-
`isX` and hands the input straight back, without walking it. `isX` builds
|
|
232
|
-
nothing — no error, no path — and stops at the first failure, answering a
|
|
233
|
-
`$ref` with the target's own `isX`; it calls `validateX` only for a schema that
|
|
234
|
-
folds to a constant. On valid input Ajv rewrites nothing, so it can
|
|
235
|
-
also be timed without the clone; `coerceX` is still ahead there on these
|
|
236
|
-
schemas, by 1.2–3.3×, but not on every one: on a large, union-heavy document
|
|
237
|
-
that the caller lets Ajv coerce in place, Ajv can come out modestly ahead. The
|
|
238
|
-
gap above is the clone, so it is real exactly where the caller cannot let Ajv
|
|
239
|
-
mutate its input.
|
|
240
|
-
The config case is the shape `--coerce` exists for: every coercible scalar sits
|
|
241
|
-
inside a union reached through `$ref`, and every union branch is tested by a
|
|
242
|
-
named function rather than a closure built per call.</sub>
|
|
214
|
+
both leave the caller's document alone, `coerceX` comes out ahead on every
|
|
215
|
+
schema in the bench, on both Bun and Node, whether the input is valid, needs
|
|
216
|
+
coercing, or cannot be coerced (`bun run bench:validators:coerce`, or
|
|
217
|
+
`bench:validators:coerce:node`). A valid document is the common case and the
|
|
218
|
+
widest gap: `coerceX` answers it with `isX` and hands the input straight back,
|
|
219
|
+
without walking it. `isX` builds nothing — no error, no path — and stops at the
|
|
220
|
+
first failure, answering a `$ref` with the target's own `isX`; it calls
|
|
221
|
+
`validateX` only for a schema that folds to a constant. On valid input Ajv
|
|
222
|
+
rewrites nothing, so it can also be timed without the clone; `coerceX` is still
|
|
223
|
+
ahead there on the bench schemas, but not on every one: on a large, union-heavy
|
|
224
|
+
document that the caller lets Ajv coerce in place, Ajv can come out modestly
|
|
225
|
+
ahead. Much of the gap is the clone, so it is real exactly where the caller
|
|
226
|
+
cannot let Ajv mutate its input. The bench's `config` case is the shape
|
|
227
|
+
`--coerce` exists for: every coercible scalar sits inside a union reached
|
|
228
|
+
through `$ref`, and every union branch is tested by a named function rather
|
|
229
|
+
than a closure built per call.
|
|
243
230
|
|
|
244
231
|
The errors differ in one way worth knowing if you key diagnostics on
|
|
245
232
|
`path + keyword + params`: an `additionalProperties` error points **at the
|
|
@@ -315,18 +302,15 @@ made. `bun run bench` measures it anyway, and the deltas wander either side of
|
|
|
315
302
|
zero between runs, which is what process-level variance looks like when there is
|
|
316
303
|
no underlying difference.
|
|
317
304
|
|
|
318
|
-
What does change is
|
|
305
|
+
What does change is what a build that reaches every mode emits:
|
|
319
306
|
|
|
320
307
|
| | before (both engines directly) | after |
|
|
321
308
|
|:---|:---|:---|
|
|
322
|
-
| codegen for the whole matrix | 2.9 ms | 2.7 ms |
|
|
323
|
-
| emitted bytes | 46.0 KiB | 45.8 KiB |
|
|
324
309
|
| files | 7 | 6 |
|
|
325
310
|
| declarations of `Order` | **2** | **1** |
|
|
326
|
-
| per-mode codegen | — | equal or slightly lower |
|
|
327
311
|
| per-mode bytes | — | identical |
|
|
328
312
|
|
|
329
|
-
The one that matters is the
|
|
313
|
+
The one that matters is the declarations row. Reaching every mode
|
|
330
314
|
used to mean running both generators yourself and shipping two trees for one
|
|
331
315
|
schema, including two declarations of the same type — structurally
|
|
332
316
|
interchangeable, but two things to keep in step. Now there is one.
|
|
@@ -113,12 +113,12 @@ const collectImportTargets = (schema, options) => {
|
|
|
113
113
|
collectRefsFromValue(record.additionalProperties);
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
|
-
if (record
|
|
116
|
+
if (record["type"] === "array" && hasItems(record) && !Array.isArray(record.items) && hasRef(record.items)) {
|
|
117
117
|
collectRefsFromValue(record.items);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
if (Object.hasOwn(record, "properties") && typeof record
|
|
121
|
-
for (const value2 of Object.values(record
|
|
120
|
+
if (Object.hasOwn(record, "properties") && typeof record["properties"] === "object" && record["properties"] !== null) {
|
|
121
|
+
for (const value2 of Object.values(record["properties"])) {
|
|
122
122
|
collectRefsFromValue(value2);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -145,19 +145,19 @@ const collectImportTargets = (schema, options) => {
|
|
|
145
145
|
if (hasAdditionalProperties(record)) {
|
|
146
146
|
collectRefsFromValue(record.additionalProperties);
|
|
147
147
|
}
|
|
148
|
-
if (Object.hasOwn(record, "patternProperties") && typeof record
|
|
149
|
-
for (const value2 of Object.values(record
|
|
148
|
+
if (Object.hasOwn(record, "patternProperties") && typeof record["patternProperties"] === "object" && record["patternProperties"] !== null) {
|
|
149
|
+
for (const value2 of Object.values(record["patternProperties"])) {
|
|
150
150
|
collectRefsFromValue(value2);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
if (Object.hasOwn(record, "if")) {
|
|
154
|
-
collectRefsFromValue(record
|
|
154
|
+
collectRefsFromValue(record["if"]);
|
|
155
155
|
}
|
|
156
156
|
if (Object.hasOwn(record, "then")) {
|
|
157
|
-
collectRefsFromValue(record
|
|
157
|
+
collectRefsFromValue(record["then"]);
|
|
158
158
|
}
|
|
159
159
|
if (Object.hasOwn(record, "else")) {
|
|
160
|
-
collectRefsFromValue(record
|
|
160
|
+
collectRefsFromValue(record["else"]);
|
|
161
161
|
}
|
|
162
162
|
};
|
|
163
163
|
if (typeof schema === "object" && schema !== null && hasRef(schema)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/validation",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "One generator surface over mjst's types, validators, coercers, repairers and parsers.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -73,20 +73,20 @@
|
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@amritk/helpers": "^0.26.
|
|
77
|
-
"json-schema-typed": "^
|
|
76
|
+
"@amritk/helpers": "^0.26.1",
|
|
77
|
+
"json-schema-typed": "^9.0.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@amritk/runtime-validators": "^0.15.2",
|
|
81
81
|
"@ryoppippi/unplugin-typia": "^2.6.5",
|
|
82
|
-
"@scalar/openapi-parser": "^0.
|
|
82
|
+
"@scalar/openapi-parser": "^0.29.27",
|
|
83
83
|
"@sinclair/typebox": "^0.34.49",
|
|
84
84
|
"ajv": "^8.17.1",
|
|
85
85
|
"ajv-formats": "^3.0.1",
|
|
86
86
|
"benny": "^3.7.1",
|
|
87
|
-
"esbuild": "^0.28.
|
|
87
|
+
"esbuild": "^0.28.2",
|
|
88
88
|
"typescript": "^5.9.3",
|
|
89
|
-
"typia": "^
|
|
90
|
-
"zod": "^4.
|
|
89
|
+
"typia": "^15.4.1",
|
|
90
|
+
"zod": "^4.6.7"
|
|
91
91
|
}
|
|
92
92
|
}
|