ata-validator 1.33.3 → 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 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** | 92.3 KB |
244
- | Time to a served request | **3.5 ms** | 11.2 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 `tests/fixtures/error-dx/user.schema.json`,
248
- every export of the compiled module against `new Validator(schema)`, built with
249
- `bun build --minify --target=browser` on ata 1.33.1. The startup row is a Hono route on
250
- Bun 1.4, best of seven, from `benchmark/bundle`, against 3.5 ms for the same app doing no
251
- validation at all, so the compiled path costs nothing measurable to start. The runtime
252
- figure is what it is because a schema that arrives at run time can use any keyword, so
253
- the whole engine has to be there. The compiled module imports nothing and contains only
254
- the checks your schema asks for.
255
-
256
- **On a server, use whichever fits your schemas.** 92 KB of JavaScript on a Node or Bun
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.6 KB gzipped, full error detail included, against 91 KB for the runtime bundled for the browser.
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.33.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` | 92.3 KB | The compiler ships with it, because a runtime schema can use any keyword |
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/compat.d.ts CHANGED
@@ -36,14 +36,25 @@ declare class Ata {
36
36
  }
37
37
 
38
38
  declare namespace Ata {
39
- interface ErrorObject {
39
+ /** The same class under the name ajv 8 exports it by: `import { Ajv } from 'ata-validator/compat'`. */
40
+ const Ajv: typeof Ata;
41
+ type Ajv = Ata;
42
+ // Generic the way the reference's ErrorObject is, so code that names
43
+ // `ErrorObject<string, Record<string, any>, unknown>` compiles against this
44
+ // entry unchanged, and an error from here passes where one from the
45
+ // reference is expected.
46
+ interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
40
47
  instancePath: string;
41
48
  schemaPath: string;
42
- keyword: string;
43
- params: Record<string, unknown>;
49
+ keyword: K;
50
+ params: P;
44
51
  message: string;
45
52
  /** Present when `verbose: true`. */
46
- parentSchema?: unknown;
53
+ schema?: S;
54
+ /** Present when `verbose: true`. */
55
+ parentSchema?: Record<string, any>;
56
+ /** Present when `verbose: true`. */
57
+ data?: unknown;
47
58
  /** Present on errors produced under `propertyNames`. */
48
59
  propertyName?: string;
49
60
  [extra: string]: unknown;
package/compat.js CHANGED
@@ -432,3 +432,4 @@ Ata.attachDataFrames = function attachDataFrames(errors, text) {
432
432
  module.exports = Ata;
433
433
  module.exports.default = Ata;
434
434
  module.exports.Ata = Ata;
435
+ module.exports.Ajv = Ata;
package/compat.mjs CHANGED
@@ -1,3 +1,5 @@
1
1
  import Ata from './compat.js';
2
- export { Ata };
2
+ // `Ajv` as well, so the named import ajv 8 documents,
3
+ // `import { Ajv } from 'ajv'`, changes only in the module name.
4
+ export { Ata, Ata as Ajv };
3
5
  export default Ata;
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
@@ -0,0 +1,3 @@
1
+ import mod from './compiled.js';
2
+ export const { fromCompiled } = mod;
3
+ export default mod;
package/index.browser.mjs CHANGED
@@ -1,4 +1,5 @@
1
- // Browser ESM entry — same code, native addon stubbed out by bundler via "browser" field.
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, renderJSON, toTypeScript } = mod;
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;