ata-validator 0.13.1 → 0.13.2

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/index.js +25 -11
  3. package/package.json +2 -2
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
+ ## 0.13.2 — 2026-05-09
6
+
7
+ ### Fixed
8
+
9
+ - **Invalid validation crashed in environments without the native addon** (Cloudflare Workers, browsers, Bun without N-API). When the JS error-codegen probe couldn't produce a safe error function, `errFn` fell through to `this._compiled.validate(d)`. With no native addon `_compiled` stays `null`, so the call threw `TypeError: Cannot read properties of null (reading 'validate')`. Valid inputs were unaffected because they short-circuited before reaching `errFn`. The fallback now stays on a JS-only path when `native` isn't present, returning the boolean result with a generic detail-not-available error so callers see `{ valid: false, errors: [...] }` instead of a crash. Added `tests/test_no_native.js` (Workers-style sandbox) to lock the behavior. Fixes #22.
10
+
5
11
  ## 0.13.1 — 2026-05-09
6
12
 
7
13
  ### Fixed
package/index.js CHANGED
@@ -566,23 +566,37 @@ class Validator {
566
566
  safeErrFn = (d) => jsErrFn(d, true);
567
567
  } catch {}
568
568
  }
569
- // errFn: use JS codegen if safe, else lazy-native fallback
570
- // For unevaluated schemas without errFn, use jsFn as boolean-only fallback
569
+ // errFn: use JS codegen if safe, else native fallback (only when native
570
+ // is available). Environments without the native addon Cloudflare
571
+ // Workers, browser, Bun without N-API — get a JS-only fallback so the
572
+ // invalid path doesn't dereference a null _compiled.
571
573
  const hasUnevaluated = schemaObj && (schemaObj.unevaluatedProperties !== undefined || schemaObj.unevaluatedItems !== undefined || this._schemaStr.includes('unevaluatedProperties') || this._schemaStr.includes('unevaluatedItems'))
572
574
  const hasDynRef = this._schemaStr.includes('"$dynamicRef"') || this._schemaStr.includes('"$dynamicAnchor"')
575
+ const jsOnlyFallback = (d) => ({
576
+ valid: jsFn(d),
577
+ errors: jsFn(d) ? [] : [{
578
+ keyword: 'validation',
579
+ instancePath: '',
580
+ schemaPath: '',
581
+ params: {},
582
+ message: 'schema validation failed (detailed errors unavailable without native addon)'
583
+ }]
584
+ });
573
585
  const errFn =
574
586
  safeErrFn ||
575
587
  (hasUnevaluated
576
588
  ? (d) => ({ valid: jsFn(d), errors: jsFn(d) ? [] : [{ code: 'unevaluated', path: '', message: 'unevaluated property or item' }] })
577
- : hasDynRef
578
- ? (d) => {
579
- this._ensureNative();
580
- return this._compiled.validateJSON(JSON.stringify(d));
581
- }
582
- : (d) => {
583
- this._ensureNative();
584
- return this._compiled.validate(d);
585
- });
589
+ : !native
590
+ ? jsOnlyFallback
591
+ : hasDynRef
592
+ ? (d) => {
593
+ this._ensureNative();
594
+ return this._compiled.validateJSON(JSON.stringify(d));
595
+ }
596
+ : (d) => {
597
+ this._ensureNative();
598
+ return this._compiled.validate(d);
599
+ });
586
600
 
587
601
  // Best path: combined validator (single pass, validates + collects errors)
588
602
  // Valid data: returns VALID_RESULT, no allocation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Ultra-fast JSON Schema validator. 5x faster validation, 159,000x faster compilation. Works without native addon. Cross-schema $ref, Draft 2020-12 + Draft 7, V8-optimized JS codegen, simdjson, RE2, multi-core. Standard Schema V1 compatible.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -40,7 +40,7 @@
40
40
  "rebuild": "cmake-js rebuild --target ata",
41
41
  "prebuild": "pkg-prebuilds-copy --baseDir build/Release --source ata.node --name=ata --strip --napi_version=10",
42
42
  "prebuild-all": "npm run prebuild -- --arch x64 && npm run prebuild -- --arch arm64",
43
- "test": "node test.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",
43
+ "test": "node test.js && node tests/test_no_native.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",
44
44
  "test:suite": "node tests/run_suite.js",
45
45
  "test:compat": "node tests/test_compat.js",
46
46
  "test:standard-schema": "node tests/test_standard_schema.js",