ata-validator 1.36.0 → 1.36.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 CHANGED
@@ -101,16 +101,15 @@ file.
101
101
  | Bundle (gzipped) | simple | 1.3 KB | 58.1 KB | 43.9x smaller |
102
102
  | Bundle (gzipped) | complex | 7.8 KB | 58.1 KB | 7.4x smaller |
103
103
  | Bundle (gzipped) | nested | 4.5 KB | 58.1 KB | 12.9x smaller |
104
- | Cold start | simple | 22 ms | 44 ms | 2.0x faster |
105
- | Throughput (1M ops) | simple | 266 Mops/s | 109 Mops/s | 2.4x faster |
106
- | Compile time | simple | 19 µs | 1.67 ms | 87x faster |
104
+ | Cold start | simple | 22 ms | 40 ms | 1.8x faster |
105
+ | Throughput (1M ops) | simple | 269 Mops/s | 116 Mops/s | 2.3x faster |
106
+ | Compile time | simple | 19 µs | 1.63 ms | 85x faster |
107
107
 
108
108
  The runtime column is the default validator most frameworks ship. Reproduce on your machine
109
109
  with `npm run bench:aot-vs-ajv`. Numbers from one run on Apple M4 Pro, Node 25.2.1, 2026-09-28,
110
- on ata-validator 1.33.1. The runtime column's bundle measured 52.7 KB on the previous run and
111
- 58.1 KB now, with ata's modules unchanged in size. Across three runs throughput moved
112
- between 231 and 280 Mops/s against 97 to 109, cold start between 21 and 22 ms against 40 to 44,
113
- and the compile ratio between 80x and 87x. The throughput row times a single one-million-call
110
+ on ata-validator 1.36.0. Across four runs throughput moved between 213 and 269 Mops/s against
111
+ 94 to 116, cold start between 21 and 22 ms against 40 to 42, and the compile ratio between 79x
112
+ and 90x. The throughput row times a single one-million-call
114
113
  loop of a few milliseconds, so it moves the most from run to run; treat the last three rows as
115
114
  an order of magnitude rather than a constant.
116
115
 
@@ -240,21 +239,21 @@ is the most common way to get a misleading number out of this library.
240
239
 
241
240
  | | compiled with `ata build` | runtime `new Validator(schema)` |
242
241
  |---|---|---|
243
- | In a bundle, gzipped | **2.2 KB** | 93.2 KB |
244
- | Time to a served request | **3.5 ms** | 7.7 ms |
242
+ | In a bundle, gzipped | **2.2 KB** | 95.6 KB |
243
+ | Time to a served request | **3.5 ms** | 7.8 ms |
245
244
  | Schema known when | build time | any time |
246
245
 
247
246
  The bundle row is the ten-field user schema in
248
247
  `tests/fixtures/error-dx/user.schema.json`, every export of the compiled module against
249
- `new Validator(schema)`, built with `bun build --minify --target=browser` on ata 1.35.0.
250
- The startup row is a Hono route on Bun 1.4, best of seven, median of three rounds, from
248
+ `new Validator(schema)`, built with `bun build --minify --target=browser` on ata 1.36.0.
249
+ The startup row is a Hono route on Bun 1.4, median of nine interleaved runs, from
251
250
  `benchmark/bundle`, against 3.5 ms for the same app doing no validation at all, so the
252
251
  compiled path costs nothing measurable to start. The runtime figure is what it is because
253
252
  a schema that arrives at run time can use any keyword, so the whole engine has to be
254
253
  there. The compiled module imports nothing and contains only the checks your schema asks
255
254
  for.
256
255
 
257
- **On a server, use whichever fits your schemas.** 93 KB of JavaScript on a Node or Bun
256
+ **On a server, use whichever fits your schemas.** 96 KB of JavaScript on a Node or Bun
258
257
  process is not a cost anyone notices, and the runtime API is the simpler thing to reach
259
258
  for. Speed is the same either way once warm.
260
259
 
@@ -486,7 +485,7 @@ const v = new Validator(schema, {
486
485
 
487
486
  ### Build-time compile (`ata compile`)
488
487
 
489
- The `ata` CLI turns a JSON Schema file into a self-contained JavaScript module. No runtime dependency on `ata-validator`, so only the generated validator ships to the browser. For the ten-field user schema in `tests/fixtures/error-dx/user.schema.json` the module is 2.2 KB gzipped, full error detail included, against 93.2 KB for the runtime bundled for the browser.
488
+ The `ata` CLI turns a JSON Schema file into a self-contained JavaScript module. No runtime dependency on `ata-validator`, so only the generated validator ships to the browser. For the ten-field user schema in `tests/fixtures/error-dx/user.schema.json` the module is 2.2 KB gzipped, full error detail included, against 95.6 KB for the runtime bundled for the browser.
490
489
 
491
490
  ```bash
492
491
  npx ata compile schemas/user.json -o src/generated/user.validator.mjs
@@ -528,11 +527,11 @@ npx ata build 'schemas/*.json' --out-dir build/validators --check
528
527
  Run with `--watch` during development for incremental rebuilds.
529
528
 
530
529
  Bundle sizes for the 10-field user schema in `tests/fixtures/error-dx/user.schema.json`,
531
- minified and gzipped, measured with `bun build --minify --target=browser` on ata 1.35.0:
530
+ minified and gzipped, measured with `bun build --minify --target=browser` on ata 1.36.0:
532
531
 
533
532
  | What the app imports | Size | Notes |
534
533
  |---|---|---|
535
- | `Validator` from `ata-validator` | 93.2 KB | The compiler ships with it, because a runtime schema can use any keyword |
534
+ | `Validator` from `ata-validator` | 95.6 KB | The compiler ships with it, because a runtime schema can use any keyword |
536
535
  | `isValid` from the compiled module | **1.3 KB** | Nothing else is reachable, so the error collector is dropped |
537
536
  | `validate` from the compiled module | **2.0 KB** | Adds the detailed error collector |
538
537
 
@@ -541,6 +540,16 @@ bundling it makes no difference: importing only `isValid` already leaves the err
541
540
  collector unreachable, and a bundler drops it. Use the flag to cut the file on disk,
542
541
  not to cut what ships.
543
542
 
543
+ To get the compiled module without changing code written against the runtime API, use
544
+ `compileAway` in [`@ata-project/unplugin`](https://github.com/ata-core/unplugin-ata): a
545
+ `new Validator(schema)` whose schema is known at build time is replaced with the compiled
546
+ module wrapped by `fromCompiled()` from `ata-validator/compiled`, which answers `validate()`,
547
+ `isValidObject()`, `validateJSON()` and `isValidJSON()` as the runtime does, defaults and errors
548
+ included. For the plugin's three-schema test entry a minified Vite build goes from 115.7 KB to
549
+ 15.5 KB gzipped. In Node, loading the wrapper and a compiled module and answering the first two
550
+ checks takes 1.12 ms where the runtime takes 6.63 ms (median of 15 fresh processes). Across
551
+ SchemaStore's 977 schemas, 725 can be compiled away; the rest stay on the runtime.
552
+
544
553
  Programmatic API if you prefer to script it:
545
554
 
546
555
  ```javascript
@@ -557,7 +566,7 @@ through a `setFormats()` export the module carries. `docs/API.md` has the
557
566
  details.
558
567
 
559
568
  **Fastify startup, 10 route schemas, from a cold process to the first validated request:
560
- ajv 20.2 ms, ata 2.7 ms, no build step required.** ata registers in 0.2 ms of that and
569
+ ajv 19.9 ms, ata 2.9 ms, no build step required.** ata registers in 0.5 ms of that and
561
570
  compiles on the first request, so counting only registration would overstate the gap.
562
571
  Reproduce with `node benchmark/bench_fastify_boot.mjs`.
563
572
 
@@ -218,7 +218,9 @@ function codegenAvailable() {
218
218
  // Schema compilation cache: same schema string -> reuse compiled functions
219
219
  const _compileCache = new Map();
220
220
  // Generated preprocess passes, keyed like _compileCache plus the options that
221
- // shape the pass. `null` records that the generator produced none.
221
+ // shape the pass. Only passes that exist are kept: a schema with nothing to
222
+ // rewrite answers `null` quickly, and keeping that answer held its key, the
223
+ // whole schema text, for every such validator, 0.2 KB each.
222
224
  const _preprocessCache = new Map();
223
225
 
224
226
  // Object identity cache: same schema object reference -> reuse entire compiled state
@@ -908,7 +910,7 @@ class Validator {
908
910
  if (hit !== undefined) preprocess = hit;
909
911
  else {
910
912
  preprocess = _codegen.buildPreprocess(preprocessSchema, options) || null;
911
- if (ppKey !== null) _preprocessCache.set(ppKey, preprocess);
913
+ if (ppKey !== null && preprocess !== null) _preprocessCache.set(ppKey, preprocess);
912
914
  }
913
915
  }
914
916
  if (!preprocess) {
package/lib/version.js CHANGED
@@ -7,4 +7,4 @@
7
7
  //
8
8
  // Kept in lockstep with package.json by `tests/test_version_sync.js`.
9
9
 
10
- module.exports = '1.36.0';
10
+ module.exports = '1.36.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "1.36.0",
3
+ "version": "1.36.1",
4
4
  "description": "JSON Schema validation that compiles for speed and still runs where code generation is blocked. Compiled and interpreted engines answer identically at 100% of the official suite. TypeScript inference, Standard Schema V1, and a build step that emits dependency-free modules.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -134,13 +134,13 @@
134
134
  "LICENSE"
135
135
  ],
136
136
  "optionalDependencies": {
137
- "@ata-validator/native-darwin-arm64": "1.36.0",
138
- "@ata-validator/native-darwin-x64": "1.36.0",
139
- "@ata-validator/native-linux-arm64-gnu": "1.36.0",
140
- "@ata-validator/native-linux-arm64-musl": "1.36.0",
141
- "@ata-validator/native-linux-x64-gnu": "1.36.0",
142
- "@ata-validator/native-linux-x64-musl": "1.36.0",
143
- "@ata-validator/native-win32-x64": "1.36.0"
137
+ "@ata-validator/native-darwin-arm64": "1.36.1",
138
+ "@ata-validator/native-darwin-x64": "1.36.1",
139
+ "@ata-validator/native-linux-arm64-gnu": "1.36.1",
140
+ "@ata-validator/native-linux-arm64-musl": "1.36.1",
141
+ "@ata-validator/native-linux-x64-gnu": "1.36.1",
142
+ "@ata-validator/native-linux-x64-musl": "1.36.1",
143
+ "@ata-validator/native-win32-x64": "1.36.1"
144
144
  },
145
145
  "peerDependencies": {
146
146
  "yaml": "^2.0.0"