ata-validator 1.34.0 → 1.35.0
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 +16 -15
- package/compiled.d.ts +17 -0
- package/compiled.js +7 -0
- package/compiled.mjs +3 -0
- package/index.browser.mjs +3 -2
- package/index.js +606 -2991
- package/index.mjs +1 -1
- package/lib/aot-build.js +40 -0
- package/lib/buffer-gate.js +0 -1
- package/lib/compiled.js +84 -0
- package/lib/enrich-error.js +7 -0
- package/lib/formats-source.js +323 -0
- package/lib/formats.js +1 -317
- package/lib/interpreter.js +4 -4
- package/lib/js-compiler.js +5 -5
- package/lib/rejections.js +309 -0
- package/lib/validator-core.js +2052 -0
- package/lib/version.js +1 -1
- package/lib/vocabularies.js +1 -2
- package/package.json +17 -9
package/README.md
CHANGED
|
@@ -240,20 +240,21 @@ is the most common way to get a misleading number out of this library.
|
|
|
240
240
|
|
|
241
241
|
| | compiled with `ata build` | runtime `new Validator(schema)` |
|
|
242
242
|
|---|---|---|
|
|
243
|
-
| In a bundle, gzipped | **2.2 KB** |
|
|
244
|
-
| Time to a served request | **3.5 ms** |
|
|
243
|
+
| In a bundle, gzipped | **2.2 KB** | 93.2 KB |
|
|
244
|
+
| Time to a served request | **3.5 ms** | 7.7 ms |
|
|
245
245
|
| Schema known when | build time | any time |
|
|
246
246
|
|
|
247
|
-
The bundle row is the ten-field user schema in
|
|
248
|
-
every export of the compiled module against
|
|
249
|
-
`bun build --minify --target=browser` on ata 1.
|
|
250
|
-
Bun 1.4, best of seven,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
the checks your schema asks
|
|
255
|
-
|
|
256
|
-
|
|
247
|
+
The bundle row is the ten-field user schema in
|
|
248
|
+
`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
|
|
251
|
+
`benchmark/bundle`, against 3.5 ms for the same app doing no validation at all, so the
|
|
252
|
+
compiled path costs nothing measurable to start. The runtime figure is what it is because
|
|
253
|
+
a schema that arrives at run time can use any keyword, so the whole engine has to be
|
|
254
|
+
there. The compiled module imports nothing and contains only the checks your schema asks
|
|
255
|
+
for.
|
|
256
|
+
|
|
257
|
+
**On a server, use whichever fits your schemas.** 93 KB of JavaScript on a Node or Bun
|
|
257
258
|
process is not a cost anyone notices, and the runtime API is the simpler thing to reach
|
|
258
259
|
for. Speed is the same either way once warm.
|
|
259
260
|
|
|
@@ -485,7 +486,7 @@ const v = new Validator(schema, {
|
|
|
485
486
|
|
|
486
487
|
### Build-time compile (`ata compile`)
|
|
487
488
|
|
|
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.
|
|
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.
|
|
489
490
|
|
|
490
491
|
```bash
|
|
491
492
|
npx ata compile schemas/user.json -o src/generated/user.validator.mjs
|
|
@@ -527,11 +528,11 @@ npx ata build 'schemas/*.json' --out-dir build/validators --check
|
|
|
527
528
|
Run with `--watch` during development for incremental rebuilds.
|
|
528
529
|
|
|
529
530
|
Bundle sizes for the 10-field user schema in `tests/fixtures/error-dx/user.schema.json`,
|
|
530
|
-
minified and gzipped, measured with `bun build --minify --target=browser` on ata 1.
|
|
531
|
+
minified and gzipped, measured with `bun build --minify --target=browser` on ata 1.35.0:
|
|
531
532
|
|
|
532
533
|
| What the app imports | Size | Notes |
|
|
533
534
|
|---|---|---|
|
|
534
|
-
| `Validator` from `ata-validator` |
|
|
535
|
+
| `Validator` from `ata-validator` | 93.2 KB | The compiler ships with it, because a runtime schema can use any keyword |
|
|
535
536
|
| `isValid` from the compiled module | **1.3 KB** | Nothing else is reachable, so the error collector is dropped |
|
|
536
537
|
| `validate` from the compiled module | **2.0 KB** | Adds the detailed error collector |
|
|
537
538
|
|
package/compiled.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// ata-validator/compiled: the wrapper a bundler plugin puts in place of
|
|
2
|
+
// `new Validator(schema)` for a schema known at build time.
|
|
3
|
+
import type { ValidationResult } from './index.js';
|
|
4
|
+
|
|
5
|
+
export interface CompiledModule {
|
|
6
|
+
validate(data: unknown): { valid: boolean; errors: unknown[] };
|
|
7
|
+
isValid(data: unknown): boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CompiledValidator<T = unknown> {
|
|
11
|
+
validate(data: unknown): ValidationResult<T>;
|
|
12
|
+
isValidObject(data: unknown): data is T;
|
|
13
|
+
validateJSON(json: string): { valid: boolean; errors: unknown[] };
|
|
14
|
+
isValidJSON(json: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function fromCompiled<T = unknown>(mod: CompiledModule, schema: object): CompiledValidator<T>;
|
package/compiled.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ata-validator/compiled: the wrapper a bundler plugin puts in place of
|
|
4
|
+
// `new Validator(schema)` when the schema is known at build time. It takes the
|
|
5
|
+
// module `compiledModuleFor(schema)` from ata-validator/build wrote, and answers
|
|
6
|
+
// as a default Validator does, without the runtime compiler in the bundle.
|
|
7
|
+
module.exports = require('./lib/compiled.js');
|
package/compiled.mjs
ADDED
package/index.browser.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// Browser ESM entry
|
|
1
|
+
// Browser ESM entry: the same code, with the native addon stubbed out by the
|
|
2
|
+
// bundler through the package.json "browser" field.
|
|
2
3
|
import mod from './index.js';
|
|
3
|
-
export const { Validator, validate, validateAsync, parseAsync, version, createPaddedBuffer, SIMDJSON_PADDING, renderPretty, renderCompact,
|
|
4
|
+
export const { Validator, compile, validate, validateAsync, parseAsync, version, createPaddedBuffer, SIMDJSON_PADDING, parseJSON, toTypeScript, defineSchema, renderPretty, renderCompact, toOutput, toRetryMessage, describeSchema, renderJSON } = mod;
|
|
4
5
|
export default mod;
|