ata-validator 1.30.2 → 1.30.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/index.js +73 -21
  2. package/lib/version.js +1 -1
  3. package/package.json +9 -9
package/index.js CHANGED
@@ -1672,37 +1672,59 @@ class Validator {
1672
1672
  this.isValid = (buf) => {
1673
1673
  self._ensureNative();
1674
1674
  const slot = self._fastSlot;
1675
- self.isValid = (b) => {
1676
- if (typeof b === 'string') b = Buffer.from(b);
1677
- else if (!(b instanceof Uint8Array)) throw new TypeError('isValid() requires a Buffer, Uint8Array, or string. For parsed objects, use isValidObject().');
1678
- return native.rawFastValidate(slot, b);
1679
- };
1675
+ self.isValid = slot < 0
1676
+ ? (b) => self._slowBufferValid(b, 'isValid')
1677
+ : (b) => {
1678
+ if (typeof b === 'string') b = Buffer.from(b);
1679
+ else if (!(b instanceof Uint8Array)) throw new TypeError('isValid() requires a Buffer, Uint8Array, or string. For parsed objects, use isValidObject().');
1680
+ return native.rawFastValidate(slot, b);
1681
+ };
1680
1682
  return self.isValid(buf);
1681
1683
  };
1682
1684
  this.countValid = (ndjsonBuf) => {
1683
1685
  self._ensureNative();
1684
1686
  const slot = self._fastSlot;
1685
- self.countValid = (b) => {
1686
- if (typeof b === 'string') b = Buffer.from(b);
1687
- else if (!(b instanceof Uint8Array)) throw new TypeError('countValid() requires a Buffer, Uint8Array, or string');
1688
- const r = native.rawNDJSONValidate(slot, b);
1689
- let c = 0;
1690
- for (let i = 0; i < r.length; i++) if (r[i]) c++;
1691
- return c;
1692
- };
1687
+ self.countValid = slot < 0
1688
+ ? (b) => {
1689
+ if (typeof b !== 'string' && !(b instanceof Uint8Array)) throw new TypeError('countValid() requires a Buffer, Uint8Array, or string');
1690
+ const text = typeof b === 'string' ? b : Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString('utf8');
1691
+ let c = 0;
1692
+ for (const line of text.split('\n')) {
1693
+ if (line.trim() === '') continue;
1694
+ if (self._slowBufferValid(line, 'countValid')) c++;
1695
+ }
1696
+ return c;
1697
+ }
1698
+ : (b) => {
1699
+ if (typeof b === 'string') b = Buffer.from(b);
1700
+ else if (!(b instanceof Uint8Array)) throw new TypeError('countValid() requires a Buffer, Uint8Array, or string');
1701
+ const r = native.rawNDJSONValidate(slot, b);
1702
+ let c = 0;
1703
+ for (let i = 0; i < r.length; i++) if (r[i]) c++;
1704
+ return c;
1705
+ };
1693
1706
  return self.countValid(ndjsonBuf);
1694
1707
  };
1695
1708
  this.batchIsValid = (buffers) => {
1696
1709
  self._ensureNative();
1697
1710
  const slot = self._fastSlot;
1698
- self.batchIsValid = (bufs) => {
1699
- let v = 0;
1700
- for (const b of bufs) {
1701
- if (!(b instanceof Uint8Array)) throw new TypeError('batchIsValid() requires Buffer or Uint8Array elements');
1702
- if (native.rawFastValidate(slot, b)) v++;
1711
+ self.batchIsValid = slot < 0
1712
+ ? (bufs) => {
1713
+ let v = 0;
1714
+ for (const b of bufs) {
1715
+ if (!(b instanceof Uint8Array)) throw new TypeError('batchIsValid() requires Buffer or Uint8Array elements');
1716
+ if (self._slowBufferValid(b, 'batchIsValid')) v++;
1717
+ }
1718
+ return v;
1703
1719
  }
1704
- return v;
1705
- };
1720
+ : (bufs) => {
1721
+ let v = 0;
1722
+ for (const b of bufs) {
1723
+ if (!(b instanceof Uint8Array)) throw new TypeError('batchIsValid() requires Buffer or Uint8Array elements');
1724
+ if (native.rawFastValidate(slot, b)) v++;
1725
+ }
1726
+ return v;
1727
+ };
1706
1728
  return self.batchIsValid(buffers);
1707
1729
  };
1708
1730
  }
@@ -2106,7 +2128,37 @@ class Validator {
2106
2128
  nativeSchemaStr = JSON.stringify(merged);
2107
2129
  }
2108
2130
  this._compiled = new native.CompiledSchema(nativeSchemaStr);
2109
- this._fastSlot = native.fastRegister(nativeSchemaStr);
2131
+ // The fast registry is a fixed array of slots in the addon, and registering
2132
+ // a distinct schema past the last one throws. It is an accelerator for the
2133
+ // buffer path, not a requirement, so a full registry leaves the slot at -1
2134
+ // and the buffer methods answer from the JS engine instead. Letting this
2135
+ // throw made every validator built after the 4096th unusable on that path.
2136
+ try {
2137
+ this._fastSlot = native.fastRegister(nativeSchemaStr);
2138
+ } catch {
2139
+ this._fastSlot = -1;
2140
+ }
2141
+ }
2142
+
2143
+ // The buffer path without a fast slot: decode, parse, and hand the value to
2144
+ // the engine that does not need one. Slower than the zero-copy walk, and the
2145
+ // same answer. A negative slot must never reach rawFastValidate, whose bounds
2146
+ // check would report a valid document as invalid.
2147
+ _slowBufferValid(input, who) {
2148
+ let text;
2149
+ if (typeof input === 'string') text = input;
2150
+ else if (input instanceof Uint8Array) {
2151
+ text = Buffer.from(input.buffer, input.byteOffset, input.byteLength).toString('utf8');
2152
+ } else {
2153
+ throw new TypeError(who + '() requires a Buffer, Uint8Array, or string');
2154
+ }
2155
+ let parsed;
2156
+ try {
2157
+ parsed = JSON.parse(text);
2158
+ } catch {
2159
+ return false;
2160
+ }
2161
+ return this.isValidObject(parsed);
2110
2162
  }
2111
2163
 
2112
2164
  addSchema(schema) {
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.30.2';
10
+ module.exports = '1.30.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ata-validator",
3
- "version": "1.30.2",
3
+ "version": "1.30.3",
4
4
  "description": "JSON Schema validation that compiles for speed and still runs where code generation is blocked. Compiled and interpreted engines answer identically at 100% of the official suite. TypeScript inference, Standard Schema V1, and a build step that emits dependency-free modules.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -51,7 +51,7 @@
51
51
  "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",
52
52
  "build": "cmake-js build --target ata",
53
53
  "rebuild": "cmake-js rebuild --target ata",
54
- "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_v1_dialect.js && node tests/test_buffer_path_parity.js && node tests/test_buffer_gate.js && node tests/test_scanner_differential.js && node tests/test_validate_json_scanner_cost.js && node tests/test_buffer_reject_cost.js && node tests/test_nan_verdict.js && node tests/test_remove_additional_nested.js && node tests/test_exclusive_bounds.js && node tests/test_engine_differential.js && node tests/test_error_shape_differential.js && node tests/test_output_format.js && node tests/test_retry_message.js && node tests/test_describe_schema.js && node tests/test_aot_parse.js && node tests/test_draft7_semantics.js && node tests/test_metaschema_ref.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_native_loaded.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_format_mode.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_engine_option.js && node tests/test_compile_cache_order.js && node tests/test_engine_diagnostic.js && node tests/test_format_engine_parity.js && node tests/test_error_accumulator_collision.js && node tests/test_uri_helper_parity.js && node tests/test_formats_single_pass.js && node tests/test_email_format_cost.js && node tests/test_format_single_error.js && node tests/test_defs_pointer_alias.js && node tests/test_cross_doc_root_ref.js && node tests/test_codegen_entrypoint_agreement.js && node tests/test_hybrid_agreement.js && node tests/test_codegen_edge_shapes.js && node tests/test_deferred_def_scope.js && node tests/test_node_scoped_ctx_flags.js && node tests/test_ajv_errors.js && node tests/test_custom_keywords.js && node tests/test_strict_schema.js && node tests/test_aot_external_checks.js && node tests/test_ajv_parity.js && node tests/test_user_format_error_path.js && node tests/test_unevaluated_error_path.js && node tests/test_unevaluated_error_shape.js && node tests/test_pattern_properties_errors.js && node tests/test_additional_properties_scaling.js && node tests/test_additional_props_combined_cost.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_code_lookup.js && node tests/test_error_order.js && node tests/test_error_order_ordinal.js && node tests/test_rejection_shape.js && node tests/test_lazy_normalization.js && node tests/test_value_equality.js && node tests/test_vocabulary.js && node tests/test_schema_scan.js && node tests/test_lazy_errors.js && node tests/test_single_pass_errors.js && node tests/test_lazy_json_errors.js && node tests/test_lazy_instance.js && node tests/test_cyclic_input.js && node tests/test_native_error_codes.js && node tests/test_verdict_preprocess.js && node tests/test_defaults_own_keys.js && node tests/test_plan_compiler.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_enrich_received.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_malformed_json_termination.js && node tests/test_data_positions.js && node tests/test_targeted_positions.js && node tests/test_position_map_cost.js && node tests/test_targeted_positions_cost.js && node tests/test_aot_staleness.js && node tests/test_file_positions.js && node tests/test_aot_positions_cost.js && node tests/test_schema_hash.js && node tests/test_render_shared.js && node tests/test_renderers.js && node tests/test_additive_fields.js && node tests/test_diagnostic_source.js && node tests/test_diagnose.js && node tests/test_correlate.js && node tests/test_diagnostics_score.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",
54
+ "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_v1_dialect.js && node tests/test_buffer_path_parity.js && node tests/test_buffer_gate.js && node tests/test_scanner_differential.js && node tests/test_validate_json_scanner_cost.js && node tests/test_buffer_reject_cost.js && node tests/test_nan_verdict.js && node tests/test_remove_additional_nested.js && node tests/test_exclusive_bounds.js && node tests/test_engine_differential.js && node tests/test_error_shape_differential.js && node tests/test_output_format.js && node tests/test_retry_message.js && node tests/test_describe_schema.js && node tests/test_aot_parse.js && node tests/test_draft7_semantics.js && node tests/test_metaschema_ref.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_native_loaded.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_format_mode.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_engine_option.js && node tests/test_compile_cache_order.js && node tests/test_engine_diagnostic.js && node tests/test_format_engine_parity.js && node tests/test_error_accumulator_collision.js && node tests/test_uri_helper_parity.js && node tests/test_formats_single_pass.js && node tests/test_email_format_cost.js && node tests/test_format_single_error.js && node tests/test_defs_pointer_alias.js && node tests/test_cross_doc_root_ref.js && node tests/test_codegen_entrypoint_agreement.js && node tests/test_hybrid_agreement.js && node tests/test_codegen_edge_shapes.js && node tests/test_deferred_def_scope.js && node tests/test_node_scoped_ctx_flags.js && node tests/test_fast_slot_exhaustion.js && node tests/test_ajv_errors.js && node tests/test_custom_keywords.js && node tests/test_strict_schema.js && node tests/test_aot_external_checks.js && node tests/test_ajv_parity.js && node tests/test_user_format_error_path.js && node tests/test_unevaluated_error_path.js && node tests/test_unevaluated_error_shape.js && node tests/test_pattern_properties_errors.js && node tests/test_additional_properties_scaling.js && node tests/test_additional_props_combined_cost.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_code_lookup.js && node tests/test_error_order.js && node tests/test_error_order_ordinal.js && node tests/test_rejection_shape.js && node tests/test_lazy_normalization.js && node tests/test_value_equality.js && node tests/test_vocabulary.js && node tests/test_schema_scan.js && node tests/test_lazy_errors.js && node tests/test_single_pass_errors.js && node tests/test_lazy_json_errors.js && node tests/test_lazy_instance.js && node tests/test_cyclic_input.js && node tests/test_native_error_codes.js && node tests/test_verdict_preprocess.js && node tests/test_defaults_own_keys.js && node tests/test_plan_compiler.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_enrich_received.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_malformed_json_termination.js && node tests/test_data_positions.js && node tests/test_targeted_positions.js && node tests/test_position_map_cost.js && node tests/test_targeted_positions_cost.js && node tests/test_aot_staleness.js && node tests/test_file_positions.js && node tests/test_aot_positions_cost.js && node tests/test_schema_hash.js && node tests/test_render_shared.js && node tests/test_renderers.js && node tests/test_additive_fields.js && node tests/test_diagnostic_source.js && node tests/test_diagnose.js && node tests/test_correlate.js && node tests/test_diagnostics_score.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",
55
55
  "bench:size": "node benchmark/bench_aot_size.mjs",
56
56
  "test:suite": "node tests/run_suite.js && node tests/run_suite.js draft7 && node tests/run_suite.js v1",
57
57
  "test:compat": "node tests/test_compat.js",
@@ -121,13 +121,13 @@
121
121
  "LICENSE"
122
122
  ],
123
123
  "optionalDependencies": {
124
- "@ata-validator/native-darwin-arm64": "1.30.2",
125
- "@ata-validator/native-darwin-x64": "1.30.2",
126
- "@ata-validator/native-linux-arm64-gnu": "1.30.2",
127
- "@ata-validator/native-linux-arm64-musl": "1.30.2",
128
- "@ata-validator/native-linux-x64-gnu": "1.30.2",
129
- "@ata-validator/native-linux-x64-musl": "1.30.2",
130
- "@ata-validator/native-win32-x64": "1.30.2"
124
+ "@ata-validator/native-darwin-arm64": "1.30.3",
125
+ "@ata-validator/native-darwin-x64": "1.30.3",
126
+ "@ata-validator/native-linux-arm64-gnu": "1.30.3",
127
+ "@ata-validator/native-linux-arm64-musl": "1.30.3",
128
+ "@ata-validator/native-linux-x64-gnu": "1.30.3",
129
+ "@ata-validator/native-linux-x64-musl": "1.30.3",
130
+ "@ata-validator/native-win32-x64": "1.30.3"
131
131
  },
132
132
  "peerDependencies": {
133
133
  "yaml": "^2.0.0"