ata-validator 1.33.2 → 1.34.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/compat.d.ts +15 -4
- package/compat.js +1 -0
- package/compat.mjs +3 -1
- package/index.d.ts +16 -1
- package/index.js +9 -6
- package/lib/compat-errors.js +18 -1
- package/lib/version.js +1 -1
- package/package.json +9 -9
package/compat.d.ts
CHANGED
|
@@ -36,14 +36,25 @@ declare class Ata {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
declare namespace Ata {
|
|
39
|
-
|
|
39
|
+
/** The same class under the name ajv 8 exports it by: `import { Ajv } from 'ata-validator/compat'`. */
|
|
40
|
+
const Ajv: typeof Ata;
|
|
41
|
+
type Ajv = Ata;
|
|
42
|
+
// Generic the way the reference's ErrorObject is, so code that names
|
|
43
|
+
// `ErrorObject<string, Record<string, any>, unknown>` compiles against this
|
|
44
|
+
// entry unchanged, and an error from here passes where one from the
|
|
45
|
+
// reference is expected.
|
|
46
|
+
interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
|
|
40
47
|
instancePath: string;
|
|
41
48
|
schemaPath: string;
|
|
42
|
-
keyword:
|
|
43
|
-
params:
|
|
49
|
+
keyword: K;
|
|
50
|
+
params: P;
|
|
44
51
|
message: string;
|
|
45
52
|
/** Present when `verbose: true`. */
|
|
46
|
-
|
|
53
|
+
schema?: S;
|
|
54
|
+
/** Present when `verbose: true`. */
|
|
55
|
+
parentSchema?: Record<string, any>;
|
|
56
|
+
/** Present when `verbose: true`. */
|
|
57
|
+
data?: unknown;
|
|
47
58
|
/** Present on errors produced under `propertyNames`. */
|
|
48
59
|
propertyName?: string;
|
|
49
60
|
[extra: string]: unknown;
|
package/compat.js
CHANGED
package/compat.mjs
CHANGED
package/index.d.ts
CHANGED
|
@@ -564,7 +564,22 @@ export interface ValidatorConstructor {
|
|
|
564
564
|
/** Compile a schema into a reusable validator. */
|
|
565
565
|
export const Validator: ValidatorConstructor;
|
|
566
566
|
|
|
567
|
-
/**
|
|
567
|
+
/**
|
|
568
|
+
* One-shot validate: validates data against a schema or an existing
|
|
569
|
+
* {@link Validator} and returns the result. A schema written with
|
|
570
|
+
* {@link defineSchema} (or as a `const` literal) types `data` from the schema
|
|
571
|
+
* itself. The last form takes the type as an argument for a schema TypeScript
|
|
572
|
+
* cannot see into, such as one read from a file; that type is an assertion,
|
|
573
|
+
* not something the schema is checked against.
|
|
574
|
+
*/
|
|
575
|
+
export function validate<T>(
|
|
576
|
+
validator: Validator<T>,
|
|
577
|
+
data: unknown
|
|
578
|
+
): ValidationResult<T>;
|
|
579
|
+
export function validate<const S extends JSONSchema>(
|
|
580
|
+
schema: S,
|
|
581
|
+
data: unknown
|
|
582
|
+
): ValidationResult<Infer<S>>;
|
|
568
583
|
export function validate<T = unknown>(
|
|
569
584
|
schema: object | string,
|
|
570
585
|
data: unknown
|
package/index.js
CHANGED
|
@@ -2523,13 +2523,16 @@ class Validator {
|
|
|
2523
2523
|
}
|
|
2524
2524
|
}
|
|
2525
2525
|
|
|
2526
|
+
// One-shot validate. It goes through a Validator like every other entry
|
|
2527
|
+
// point, so the result has one shape everywhere: `data` on success, errors
|
|
2528
|
+
// with a code, a keyword and an instancePath. From the first native binding
|
|
2529
|
+
// until 1.33.3 it handed the schema straight to the native engine whenever
|
|
2530
|
+
// the addon was loaded, which is every default install on a supported
|
|
2531
|
+
// platform, and returned that engine's raw result: numeric codes, `path`
|
|
2532
|
+
// instead of `instancePath`, no keyword, and no `data`. The compile cache keeps
|
|
2533
|
+
// a schema passed again from compiling again.
|
|
2526
2534
|
function validate(schema, data) {
|
|
2527
|
-
if (
|
|
2528
|
-
const schemaStr =
|
|
2529
|
-
typeof schema === "string" ? schema : JSON.stringify(schema);
|
|
2530
|
-
return native.validate(schemaStr, data);
|
|
2531
|
-
}
|
|
2532
|
-
// JS fallback: compile and validate
|
|
2535
|
+
if (schema instanceof Validator) return schema.validate(data);
|
|
2533
2536
|
const v = new Validator(typeof schema === "string" ? JSON.parse(schema) : schema);
|
|
2534
2537
|
return v.validate(data);
|
|
2535
2538
|
}
|
package/lib/compat-errors.js
CHANGED
|
@@ -369,8 +369,25 @@ function createShaper({ Validator, rootId, rootDoc, schemas, options, allErrors,
|
|
|
369
369
|
return group.length;
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
// A `type` error the way the reference words it. ata folds `nullable: true`
|
|
373
|
+
// into the type union before compiling, so its own error names the union:
|
|
374
|
+
// `must be integer, null`. The reference names the type as written, adding
|
|
375
|
+
// `null` only when the written type is already a list, and joins a list
|
|
376
|
+
// with a bare comma: `must be integer`, `must be string,number,null`. The
|
|
377
|
+
// node is read from the schema as the caller passed it.
|
|
378
|
+
function asReferenceType(e) {
|
|
379
|
+
if (e.keyword !== 'type' || typeof e.message !== 'string' || !e.message.startsWith('must be ')) return e;
|
|
380
|
+
const ptr = pointerOf(e.schemaPath || '');
|
|
381
|
+
if (!ptr.endsWith('/type')) return e;
|
|
382
|
+
const node = walkPointer(rootDoc, ptr.slice(0, -'/type'.length));
|
|
383
|
+
let t = node && typeof node === 'object' && node.type !== undefined ? node.type : e.params && e.params.type;
|
|
384
|
+
if (t === undefined) return e;
|
|
385
|
+
if (node && node.nullable === true && Array.isArray(t) && !t.includes('null')) t = [...t, 'null'];
|
|
386
|
+
return { ...e, params: { ...e.params, type: t }, message: 'must be ' + (Array.isArray(t) ? t.join(',') : t) };
|
|
387
|
+
}
|
|
388
|
+
|
|
372
389
|
return function shapeErrors(errors, data) {
|
|
373
|
-
const shaped = shape(errors, data, '').map(asReferenceKeyword);
|
|
390
|
+
const shaped = shape(errors, data, '').map(asReferenceKeyword).map(asReferenceType);
|
|
374
391
|
if (allErrors) return shaped;
|
|
375
392
|
const n = groupEnd(shaped);
|
|
376
393
|
return shaped.slice(0, n);
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ata-validator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.0",
|
|
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_uri_fast_path.js && node tests/test_extend_verdict.js && node tests/test_ipv4_regex.js && node tests/test_ipv6_fast_path.js && node tests/test_nested_recursion_decline.js && node tests/test_generator_error_content.js && node tests/test_inherited_key_presence.js && node tests/test_proto_accessor.js && node tests/test_hybrid_tier.js && node tests/test_first_rejection_builds_one.js && node tests/test_container_local.js && node tests/test_fixed_pattern_inline.js && node tests/test_plan_source.js && node tests/test_fused_remove_additional.js && node tests/test_runtime_parse.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",
|
|
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_uri_fast_path.js && node tests/test_extend_verdict.js && node tests/test_ipv4_regex.js && node tests/test_ipv6_fast_path.js && node tests/test_nested_recursion_decline.js && node tests/test_generator_error_content.js && node tests/test_inherited_key_presence.js && node tests/test_proto_accessor.js && node tests/test_hybrid_tier.js && node tests/test_first_rejection_builds_one.js && node tests/test_container_local.js && node tests/test_one_shot_validate.js && node tests/test_fixed_pattern_inline.js && node tests/test_plan_source.js && node tests/test_fused_remove_additional.js && node tests/test_runtime_parse.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.
|
|
125
|
-
"@ata-validator/native-darwin-x64": "1.
|
|
126
|
-
"@ata-validator/native-linux-arm64-gnu": "1.
|
|
127
|
-
"@ata-validator/native-linux-arm64-musl": "1.
|
|
128
|
-
"@ata-validator/native-linux-x64-gnu": "1.
|
|
129
|
-
"@ata-validator/native-linux-x64-musl": "1.
|
|
130
|
-
"@ata-validator/native-win32-x64": "1.
|
|
124
|
+
"@ata-validator/native-darwin-arm64": "1.34.0",
|
|
125
|
+
"@ata-validator/native-darwin-x64": "1.34.0",
|
|
126
|
+
"@ata-validator/native-linux-arm64-gnu": "1.34.0",
|
|
127
|
+
"@ata-validator/native-linux-arm64-musl": "1.34.0",
|
|
128
|
+
"@ata-validator/native-linux-x64-gnu": "1.34.0",
|
|
129
|
+
"@ata-validator/native-linux-x64-musl": "1.34.0",
|
|
130
|
+
"@ata-validator/native-win32-x64": "1.34.0"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
|
133
133
|
"yaml": "^2.0.0"
|