ata-validator 0.17.0 → 0.17.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 +12 -0
  2. package/index.js +36 -2
  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.17.2 - 2026-05-24
6
+
7
+ ### Fixed
8
+
9
+ - `validate()` now returns the typed `data` on success, the validated input after any in-place coercion or defaults. The `ValidationResult<T>` type has carried `data: T` since 0.17.0, but the runtime never populated it, so `result.data` was `undefined`. `isValidObject()` and `abortEarly` stay allocation-free for callers that only need a boolean.
10
+
11
+ ## 0.17.1 - 2026-05-24
12
+
13
+ ### Fixed
14
+
15
+ - Standalone output for schemas with `anyOf` or `oneOf` no longer references undefined branch helpers. `toStandaloneModule` and `bundleCompact` now emit the hoisted branch functions, so the generated module runs instead of throwing on the first validation. `bundleStandalone` already emitted them.
16
+
5
17
  ## 0.17.0 - 2026-05-23
6
18
 
7
19
  ### Added
package/index.js CHANGED
@@ -1055,6 +1055,20 @@ class Validator {
1055
1055
  }
1056
1056
  }
1057
1057
 
1058
+ // validate() resolves a typed `data` on success: the validated input, after
1059
+ // any in-place coercion/defaults. This matches the ValidationResult<T>
1060
+ // contract. isValidObject() and abortEarly stay allocation-free for hot
1061
+ // paths that only need a boolean.
1062
+ if (this.validate) {
1063
+ const _bare = this.validate;
1064
+ this.validate = (data) => {
1065
+ const r = _bare(data);
1066
+ return (r.valid === true && r.data === undefined)
1067
+ ? { valid: true, data, errors: r.errors }
1068
+ : r;
1069
+ };
1070
+ }
1071
+
1058
1072
  // Save to identity cache for ultra-fast reuse with same schema object
1059
1073
  if (this._schemaObj && typeof this._schemaObj === 'object') {
1060
1074
  _identityCache.set(this._schemaObj, this);
@@ -1223,6 +1237,11 @@ module.exports = { boolFn, hybridFactory, errFn };
1223
1237
  if (lines.length) closureDecls = lines.join('\n') + '\n';
1224
1238
  }
1225
1239
 
1240
+ // Hoisted oneOf/anyOf branch checks live in the boolean fn's preamble (the
1241
+ // runtime emits them before the function). The standalone module must declare
1242
+ // them at module scope too, or _fn references undefined names (e.g. _af1_b0).
1243
+ const preambleDecls = jsFn._preambleSource ? jsFn._preambleSource + '\n' : '';
1244
+
1226
1245
  const validBody = errCore
1227
1246
  ? 'return _fn(data) ? VALID : { valid: false, errors: errFn(data, true).errors }'
1228
1247
  : 'return _fn(data) ? VALID : ABORT';
@@ -1245,7 +1264,7 @@ const ABORT = Object.freeze({
1245
1264
  path: '',
1246
1265
  })]),
1247
1266
  });
1248
- ${closureDecls}const _fn = function(d) {
1267
+ ${closureDecls}${preambleDecls}const _fn = function(d) {
1249
1268
  ${src}
1250
1269
  };
1251
1270
  ${errCore}function isValid(data) { return _fn(data); }
@@ -1320,6 +1339,15 @@ ${exports}`;
1320
1339
  return mod.boolFn(data) ? VALID_RESULT : errFn(data);
1321
1340
  }
1322
1341
  : (data) => (mod.boolFn(data) ? VALID_RESULT : errFn(data));
1342
+ {
1343
+ const _bare = v.validate;
1344
+ v.validate = (data) => {
1345
+ const r = _bare(data);
1346
+ return (r.valid === true && r.data === undefined)
1347
+ ? { valid: true, data, errors: r.errors }
1348
+ : r;
1349
+ };
1350
+ }
1323
1351
  v.isValidObject = mod.boolFn;
1324
1352
  v.isValidJSON = (jsonStr) => {
1325
1353
  try {
@@ -1520,8 +1548,14 @@ Validator.bundleCompact = function (schemas, opts) {
1520
1548
  typeof schema === "string" ? JSON.parse(schema) : schema,
1521
1549
  v._schemaMap,
1522
1550
  );
1551
+ // Hoisted anyOf/oneOf branch helpers (e.g. `_af1_b0`) must travel with the
1552
+ // hybrid body or it references undefined names. Prepending keeps dedup honest:
1553
+ // schemas with different branch sets no longer collide on body alone.
1554
+ const hybrid = jsFn._preambleSource
1555
+ ? `${jsFn._preambleSource}\n${jsFn._hybridSource}`
1556
+ : jsFn._hybridSource;
1523
1557
  return {
1524
- hybrid: jsFn._hybridSource,
1558
+ hybrid,
1525
1559
  err: jsErrFn && jsErrFn._errSource ? jsErrFn._errSource : null,
1526
1560
  };
1527
1561
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
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",
@@ -42,7 +42,7 @@
42
42
  "rebuild": "cmake-js rebuild --target ata",
43
43
  "prebuild": "pkg-prebuilds-copy --baseDir build/Release --source ata.node --name=ata --strip --napi_version=10",
44
44
  "prebuild-all": "npm run prebuild -- --arch x64 && npm run prebuild -- --arch arm64",
45
- "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 && node tests/test_typed_validator_runner.js && node tests/test_define_schema.js && node tests/test_error_codes_lock.js && node tests/test_nullable.js && node tests/test_validate_and_parse.js && node tests/test_enrich_error.js && node tests/test_rich_errors_optout.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 benchmark/bench_aot_size.mjs",
45
+ "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 && node tests/test_standalone_anyof.js && node tests/test_typed_validator_runner.js && node tests/test_define_schema.js && node tests/test_error_codes_lock.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_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 benchmark/bench_aot_size.mjs",
46
46
  "bench:size": "node benchmark/bench_aot_size.mjs",
47
47
  "test:suite": "node tests/run_suite.js",
48
48
  "test:compat": "node tests/test_compat.js",