ata-validator 0.13.1 → 0.13.3

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 +12 -0
  2. package/index.js +31 -11
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
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.3 — 2026-05-13
6
+
7
+ ### Fixed
8
+
9
+ - **`Validator.bundleStandalone` dropped hoisted anyOf/oneOf branch helpers from the bundle output.** Schemas whose codegen hoists branch functions like `_af1_b0` to the per-schema preamble (e.g. allOf wrapping an anyOf, or schemas pulled into a cross-`$ref` bundle) emitted JS that referenced these helpers without defining them, so loading the bundle threw `ReferenceError: _af1_b0 is not defined` on first validation. The standalone preamble now propagates through to the bundle alongside the format-closure serialization that was already there. `toStandalone` (single-schema) was unaffected. Fixes #24.
10
+
11
+ ## 0.13.2 — 2026-05-09
12
+
13
+ ### Fixed
14
+
15
+ - **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.
16
+
5
17
  ## 0.13.1 — 2026-05-09
6
18
 
7
19
  ### 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
@@ -1242,6 +1256,12 @@ Validator.bundleStandalone = function (schemas, opts) {
1242
1256
  .map(({ name, fn }) => `var ${name}=${fn.toString()};`)
1243
1257
  .join('\n');
1244
1258
  }
1259
+ // Include hoisted anyOf/oneOf branch helpers (e.g. `_af1_b0`) so the
1260
+ // bundle output is self-contained. `toStandalone` emits this same source
1261
+ // for single-schema standalone output.
1262
+ if (jsFn._preambleSource) {
1263
+ preamble = preamble ? `${preamble}\n${jsFn._preambleSource}` : jsFn._preambleSource;
1264
+ }
1245
1265
  if (opts && opts.verbose) {
1246
1266
  // Embed the schema and a small resolver so errors carry parentSchema.
1247
1267
  const schemaLit = JSON.stringify(typeof schema === 'string' ? JSON.parse(schema) : schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
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 && node tests/test_bundle_standalone.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",