ata-validator 1.3.0 → 1.4.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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to ata-validator are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/), and this project adheres to semantic versioning.
4
4
 
5
+ ## 1.4.0 - 2026-08-04
6
+
7
+ ### Fixed
8
+
9
+ - Where `new Function` is unavailable, validation now runs on the interpreted engine instead of degrading quietly. Cloudflare Workers, Deno Deploy and pages under a strict Content-Security-Policy refuse code generation; the closure-based path does not call `new Function` itself, so it survived the refusal and went on to handle schemas it gets wrong. Against the full suite with code generation blocked, ata scored 1188 of 1290 with 30 schemas failing to build. It now scores 1286 of 1290 with none, which is the same as the compiled path within one case. Draft 7 is 910 of 922. `tests/test_no_eval.js` runs the whole suite with `eval` and `new Function` blocked so this is checked rather than assumed.
10
+
5
11
  ## 1.3.0 - 2026-08-02
6
12
 
7
13
  ### Added
package/README.md CHANGED
@@ -20,7 +20,7 @@ The `ata-validator` package itself is pure JavaScript. The native accelerator (s
20
20
  npm install ata-validator --omit=optional
21
21
  ```
22
22
 
23
- or set `ATA_NO_NATIVE=1` at runtime. Typical schemas compile to specialized JS; shapes the compiler cannot represent (some `$dynamicRef`, cyclic `$ref`, unusual keyword interactions) fall back to an interpreted engine, so every schema validates in every environment. The pure-JS setup passes 99.8% of the official draft 2020-12 test suite. Only the buffer and parallel APIs (`isValid` on raw buffers, `countValid`, `batchIsValid`, `validateAndParse`) need the native engine and say so with a clear error.
23
+ or set `ATA_NO_NATIVE=1` at runtime. Typical schemas compile to specialized JS; shapes the compiler cannot represent (some `$dynamicRef`, cyclic `$ref`, unusual keyword interactions) fall back to an interpreted engine, so every schema validates in every environment. The pure-JS setup scores the same on the official suite as the native one, 1285 of 1290 Draft 2020-12 cases; the two miss a different `$dynamicRef` scope corner each. Only the buffer and parallel APIs (`isValid` on raw buffers, `countValid`, `batchIsValid`, `validateAndParse`) need the native engine and say so with a clear error.
24
24
 
25
25
  In your code:
26
26
 
@@ -466,14 +466,17 @@ Copy-paste recipes for the common frameworks. Most need 10-20 lines of glue. See
466
466
 
467
467
  ### Known limitations
468
468
 
469
- The Draft 2020-12 pass rate (1188 of 1190 applicable cases, 99.8%, in the pure-JS configuration; 1190 of 1190 with the native accelerator installed, which covers the two remaining `$dynamicRef` scope corners) excludes areas that are deliberate scope decisions for 1.x:
469
+ Running the whole Draft 2020-12 suite with nothing excluded, `format` and `default` under specification semantics (`assertFormat: false`, `useDefaults: false`), gives 1285 of 1290 cases, 99.6%. Draft 7 gives 911 of 922, 98.8%. `npm run test:suite` reproduces both and lists the remaining failures by name.
470
+
471
+ Areas that remain deliberate scope decisions for 1.x:
470
472
 
471
473
  - **Remote `$ref` over the network** is not fetched. Register cross-schema refs explicitly with `schemas: [...]` or `addSchema()`.
472
474
  - **`$vocabulary`** is not implemented; custom vocabularies are ignored rather than enforced.
473
475
  - **`contentEncoding` / `contentMediaType` / `contentSchema`** are annotation-only, as the spec permits, and are not validated.
474
476
  - **`minLength`/`maxLength`** count UTF-16 code units, not grapheme clusters.
475
- - **Infinite-loop detection** suite cases are skipped; circular `$ref` chains are cut off by a recursion depth guard instead.
476
- - **`default`** optional suite tests are excluded; ata applies `default` values to validated data, where the spec treats `default` as a non-enforcing annotation.
477
+ - **Infinite-loop detection** relies on a recursion depth guard that cuts off circular `$ref` chains.
478
+ - **`default`** values are applied to validated data by default, where the spec treats `default` as a non-enforcing annotation. Pass `useDefaults: false` for the specification behavior.
479
+ - **`format`** is asserted by default rather than treated as an annotation. Pass `assertFormat: false` for the specification behavior.
477
480
 
478
481
  If one of these blocks you, open an issue; scope decisions get revisited with real use cases.
479
482
 
package/index.js CHANGED
@@ -271,6 +271,21 @@ function buildPreprocessCodegen(schema, options) {
271
271
  }
272
272
  }
273
273
 
274
+ // Cloudflare Workers, Deno Deploy and pages under a strict Content-Security-
275
+ // Policy refuse `new Function`. Probed once, lazily, because the answer cannot
276
+ // change within a realm and the probe itself is a code generation attempt.
277
+ let _codegenAvailable = null;
278
+ function codegenAvailable() {
279
+ if (_codegenAvailable === null) {
280
+ try {
281
+ _codegenAvailable = new Function('return 1')() === 1;
282
+ } catch {
283
+ _codegenAvailable = false;
284
+ }
285
+ }
286
+ return _codegenAvailable;
287
+ }
288
+
274
289
  // Schema compilation cache: same schema string -> reuse compiled functions
275
290
  const _compileCache = new Map();
276
291
 
@@ -709,7 +724,13 @@ class Validator {
709
724
  const cached = this._userFormats ? null : _compileCache.get(mapKey);
710
725
  let jsFn, jsCombinedFn, jsErrFn, _isCodegen = false;
711
726
  var _forceNapi = typeof process !== 'undefined' && process.env && process.env.ATA_FORCE_NAPI;
712
- if (cached && !_forceNapi) {
727
+ // Where source cannot be turned into a function, neither JS path is usable.
728
+ // The closure path does not call `new Function` itself, so it survives the
729
+ // block and would quietly handle schemas it gets wrong; the interpreted
730
+ // engine is both eval-free and more correct, so go straight there.
731
+ if (!codegenAvailable()) {
732
+ jsFn = null; jsCombinedFn = null; jsErrFn = null;
733
+ } else if (cached && !_forceNapi) {
713
734
  jsFn = cached.jsFn;
714
735
  jsCombinedFn = cached.combined;
715
736
  jsErrFn = cached.errFn;
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.3.0';
10
+ module.exports = '1.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "JSON Schema validation with first-class TypeScript and zero runtime cost. AOT compile to per-schema ESM modules with zero validator dependency. Generic Validator<T> for TypeBox/Zod/Valibot composition. Optional runtime API. Standard Schema V1 compatible.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -44,9 +44,9 @@
44
44
  "release:check": "node scripts/regen-safe-regex-source.js && node tests/test_pack_purity.js && node scripts/check-doc-coverage.js && node tests/test_error_codes_lock.js && node tests/test_safe_regex_source_sync.js && node tests/test_version_sync.js",
45
45
  "build": "cmake-js build --target ata",
46
46
  "rebuild": "cmake-js rebuild --target ata",
47
- "test": "node test.js && node tests/test_removed_aot_methods.js && node tests/test_no_native.js && node tests/test_pure_js_unsupported.js && node tests/test_native_load_order.js && node tests/test_pack_purity.js && node tests/test_make_native_package.js && node tests/test_browser_nofs.js && node tests/test_browser_imports_guard.js && node tests/test_version_sync.js && node tests/test_safe_regex_source_sync.js && node tests/test_t_builder.js && node tests/test_async_refine.js && node tests/test_safe_regex.js && node tests/test_safe_regex_integration.js && node tests/test_aot_build.js && node tests/test_aot_differential.js && node tests/test_aot_cli_build.js && node tests/test_aot_cli_smoke.js && node tests/test_bundle_standalone.js && node tests/test_standalone_anyof.js && node tests/test_standalone_formats.js && node tests/test_aot_additional_props_errors.js && node tests/test_id_anchor_refs.js && node tests/test_engine_routing.js && node tests/test_format_engine_parity.js && node tests/test_defs_pointer_alias.js && node tests/test_no_input_mutation.js && node tests/test_typed_validator_runner.js && node tests/test_define_schema.js && node tests/test_error_codes_lock.js && node tests/test_error_order.js && node tests/test_nullable.js && node tests/test_validate_and_parse.js && node tests/test_validate_data.js && node tests/test_enrich_error.js && node tests/test_rich_errors_optout.js && node tests/test_error_messages.js && node tests/test_source_positions.js && node tests/fuzz_positions.js && node tests/test_data_positions.js && node tests/test_render_shared.js && node tests/test_renderers.js && node tests/test_runtime_error_dx.js && node tests/test_aot_error_dx.js && node tests/test_abort_early.js && node tests/test_branch_collapse.js && node tests/test_suggestions.js && node tests/test_cli_validate.js && node tests/test_cli_version.js && node benchmark/bench_aot_size.mjs",
47
+ "test": "node test.js && node tests/test_removed_aot_methods.js && node tests/test_no_native.js && node tests/test_no_eval.js && node tests/test_pure_js_unsupported.js && node tests/test_native_load_order.js && node tests/test_pack_purity.js && node tests/test_make_native_package.js && node tests/test_browser_nofs.js && node tests/test_browser_imports_guard.js && node tests/test_version_sync.js && node tests/test_safe_regex_source_sync.js && node tests/test_t_builder.js && node tests/test_async_refine.js && node tests/test_safe_regex.js && node tests/test_safe_regex_integration.js && node tests/test_aot_build.js && node tests/test_aot_differential.js && node tests/test_aot_cli_build.js && node tests/test_aot_cli_smoke.js && node tests/test_bundle_standalone.js && node tests/test_standalone_anyof.js && node tests/test_standalone_formats.js && node tests/test_aot_additional_props_errors.js && node tests/test_id_anchor_refs.js && node tests/test_engine_routing.js && node tests/test_format_engine_parity.js && node tests/test_defs_pointer_alias.js && node tests/test_no_input_mutation.js && node tests/test_typed_validator_runner.js && node tests/test_define_schema.js && node tests/test_error_codes_lock.js && node tests/test_error_order.js && node tests/test_nullable.js && node tests/test_validate_and_parse.js && node tests/test_validate_data.js && node tests/test_enrich_error.js && node tests/test_rich_errors_optout.js && node tests/test_error_messages.js && node tests/test_source_positions.js && node tests/fuzz_positions.js && node tests/test_data_positions.js && node tests/test_render_shared.js && node tests/test_renderers.js && node tests/test_runtime_error_dx.js && node tests/test_aot_error_dx.js && node tests/test_abort_early.js && node tests/test_branch_collapse.js && node tests/test_suggestions.js && node tests/test_cli_validate.js && node tests/test_cli_version.js && node benchmark/bench_aot_size.mjs",
48
48
  "bench:size": "node benchmark/bench_aot_size.mjs",
49
- "test:suite": "node tests/run_suite.js",
49
+ "test:suite": "node tests/run_suite.js && node tests/run_suite.js draft7",
50
50
  "test:compat": "node tests/test_compat.js",
51
51
  "test:standard-schema": "node tests/test_standard_schema.js",
52
52
  "test:browser": "node tests/test_browser.js",
@@ -112,12 +112,12 @@
112
112
  "LICENSE"
113
113
  ],
114
114
  "optionalDependencies": {
115
- "@ata-validator/native-darwin-arm64": "1.3.0",
116
- "@ata-validator/native-linux-x64-gnu": "1.3.0",
117
- "@ata-validator/native-linux-arm64-gnu": "1.3.0",
118
- "@ata-validator/native-linux-x64-musl": "1.3.0",
119
- "@ata-validator/native-linux-arm64-musl": "1.3.0",
120
- "@ata-validator/native-win32-x64": "1.3.0"
115
+ "@ata-validator/native-darwin-arm64": "1.4.0",
116
+ "@ata-validator/native-linux-x64-gnu": "1.4.0",
117
+ "@ata-validator/native-linux-arm64-gnu": "1.4.0",
118
+ "@ata-validator/native-linux-x64-musl": "1.4.0",
119
+ "@ata-validator/native-linux-arm64-musl": "1.4.0",
120
+ "@ata-validator/native-win32-x64": "1.4.0"
121
121
  },
122
122
  "peerDependencies": {
123
123
  "yaml": "^2.0.0"