ata-validator 1.3.0 → 1.5.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,19 @@
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.5.0 - 2026-08-05
6
+
7
+ ### Added
8
+
9
+ - `propertyDependencies`, a JSON Schema v1 [proposal](https://github.com/json-schema-org/json-schema-spec/blob/main/specs/proposals/propertyDependencies.md), selects a subschema by the value of a property rather than by its presence. It replaces the `oneOf` and `if`/`then` patterns normally used to branch on a discriminator field, and reads as `{ "propertyDependencies": { "type": { "customer": { ... }, "employee": { ... } } } }`. The proposal defines the keyword as equivalent to an `if`/`then` on `const`, and `tests/test_property_dependencies.js` checks that equivalence case by case rather than asserting a separate expectation, alongside the proposal's own test files from the official suite: 36 of 38, the two remaining being a `$dynamicRef` scope gap the `if`/`then` form of the same schema hits identically.
10
+ - The keyword is implemented in the interpreted engine. Both JS compiler paths decline a schema that uses it rather than emitting nothing for a keyword they do not know, which would make the constraint vacuous.
11
+
12
+ ## 1.4.0 - 2026-08-04
13
+
14
+ ### Fixed
15
+
16
+ - 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.
17
+
5
18
  ## 1.3.0 - 2026-08-02
6
19
 
7
20
  ### 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;
@@ -1040,8 +1061,11 @@ class Validator {
1040
1061
  this._ensureNative();
1041
1062
  const _hasDynRef = this._schemaStr.includes('"$dynamicRef"') || this._schemaStr.includes('"$dynamicAnchor"')
1042
1063
  const _hasUneval = this._schemaStr.includes('"unevaluatedProperties"') || this._schemaStr.includes('"unevaluatedItems"')
1064
+ // propertyDependencies exists only in the interpreted engine, so a schema
1065
+ // using it goes there even when it also uses $dynamicRef.
1066
+ const _hasPropDeps = this._schemaStr.includes('"propertyDependencies"')
1043
1067
  let _validate;
1044
- if (_hasDynRef && !_hasUneval) {
1068
+ if (_hasDynRef && !_hasUneval && !_hasPropDeps) {
1045
1069
  // validateJSON is the C++ path with full anchor-map support; the NAPI
1046
1070
  // direct V8 `validate` path has no anchor maps.
1047
1071
  _validate = (data) => this._compiled.validateJSON(JSON.stringify(data));
@@ -102,6 +102,16 @@ function walkSchema(node, baseUri, state, isResourceRoot) {
102
102
  const list = node[kw];
103
103
  if (Array.isArray(list)) for (const sub of list) walkSchema(sub, baseUri, state, false);
104
104
  }
105
+ // propertyDependencies nests one level deeper than the other maps:
106
+ // property name -> property value -> schema.
107
+ const propDeps = node.propertyDependencies;
108
+ if (propDeps && typeof propDeps === 'object' && !Array.isArray(propDeps)) {
109
+ for (const choices of Object.values(propDeps)) {
110
+ if (choices && typeof choices === 'object' && !Array.isArray(choices)) {
111
+ for (const sub of Object.values(choices)) walkSchema(sub, baseUri, state, false);
112
+ }
113
+ }
114
+ }
105
115
  }
106
116
 
107
117
  // ---------- ref resolution ----------
@@ -504,6 +514,23 @@ class Interpreter {
504
514
  }
505
515
  }
506
516
  }
517
+ // propertyDependencies: like dependentSchemas but keyed on the property's
518
+ // value rather than its presence. Only string values can match, since the
519
+ // inner keys are object keys. Equivalent to
520
+ // `if: { properties: { p: { const: v } }, required: [p] }, then: <schema>`.
521
+ if (schema.propertyDependencies && typeof schema.propertyDependencies === 'object') {
522
+ for (const [key, choices] of Object.entries(schema.propertyDependencies)) {
523
+ if (!choices || typeof choices !== 'object' || Array.isArray(choices)) continue;
524
+ if (!Object.prototype.hasOwnProperty.call(data, key)) continue;
525
+ const value = data[key];
526
+ if (typeof value !== 'string') continue;
527
+ if (!Object.prototype.hasOwnProperty.call(choices, value)) continue;
528
+ const sub = { props: null, items: null };
529
+ const branchPath = schemaPath + '/propertyDependencies/' + escapePointer(key) + '/' + escapePointer(value);
530
+ if (!this.eval(choices[value], data, base, dynScope, errors, instancePath, branchPath, stack, sub)) valid = false;
531
+ else mergeAnnotations(local, sub);
532
+ }
533
+ }
507
534
  }
508
535
 
509
536
  // in-place applicators
@@ -115,6 +115,7 @@ function compileToJS(schema, defs, schemaMap) {
115
115
  // Bail on features that are too complex for JS fast path
116
116
  if (schema.patternProperties ||
117
117
  schema.dependentSchemas ||
118
+ schema.propertyDependencies ||
118
119
  schema.propertyNames) {
119
120
  return null
120
121
  }
@@ -749,6 +750,11 @@ function codegenSafe(schema, schemaMap) {
749
750
  if (typeof schema === 'boolean') return true
750
751
  if (typeof schema !== 'object' || schema === null) return true
751
752
 
753
+ // propertyDependencies is a proposal the interpreted engine implements and
754
+ // neither JS path does. Emitting nothing for it would make the keyword
755
+ // vacuous, so hand the schema over rather than silently ignore a constraint.
756
+ if (schema.propertyDependencies !== undefined) return false
757
+
752
758
  // Only bail on $dynamicRef if it can't be resolved at compile time
753
759
  if (schema.$dynamicRef && !schema.$dynamicRef.startsWith('#')) return false
754
760
 
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.5.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "1.3.0",
3
+ "version": "1.5.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_property_dependencies.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.5.0",
116
+ "@ata-validator/native-linux-x64-gnu": "1.5.0",
117
+ "@ata-validator/native-linux-arm64-gnu": "1.5.0",
118
+ "@ata-validator/native-linux-x64-musl": "1.5.0",
119
+ "@ata-validator/native-linux-arm64-musl": "1.5.0",
120
+ "@ata-validator/native-win32-x64": "1.5.0"
121
121
  },
122
122
  "peerDependencies": {
123
123
  "yaml": "^2.0.0"