ata-validator 1.60.0 → 1.61.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/README.md +107 -4
- package/bin/ata.js +84 -0
- package/build.d.ts +29 -0
- package/build.mjs +2 -0
- package/compiled.d.ts +3 -1
- package/index.browser.mjs +2 -2
- package/index.bundle.mjs +2 -2
- package/index.d.ts +9 -0
- package/index.edge.mjs +2 -2
- package/index.js +48 -0
- package/index.mjs +1 -1
- package/index.node.mjs +1 -1
- package/lib/aot-build.js +73 -6
- package/lib/aot-impl.js +14 -19
- package/lib/bun-target.js +612 -0
- package/lib/codegen-engine.js +9 -3
- package/lib/combined-runtime.js +1 -1
- package/lib/formats.js +1 -1
- package/lib/js-compiler-errors.js +45 -10
- package/lib/js-compiler.js +92 -13
- package/lib/public-api.js +1 -0
- package/lib/tier0.js +1 -1
- package/lib/validator-core.js +36 -3
- package/lib/verify.js +321 -0
- package/lib/version.js +1 -1
- package/lite.js +1 -0
- package/lite.mjs +1 -1
- package/package.json +10 -9
package/lib/aot-impl.js
CHANGED
|
@@ -367,7 +367,7 @@ function defaultsDecl(validator) {
|
|
|
367
367
|
if (defaults.buildDefaultsApplier(schema) === null) return '';
|
|
368
368
|
const embedded = require('./schema-strip').stripAnnotationsKeepingDefaults(schema);
|
|
369
369
|
const text = JSON.stringify(JSON.stringify(embedded)).replace(/</g, '\\u003c');
|
|
370
|
-
return `const _ataDefaults = (function () {\nconst MAX_DEPTH = ${defaults.MAX_DEPTH};\n${
|
|
370
|
+
return `const _ataDefaults = (function () {\nconst MAX_DEPTH = ${defaults.MAX_DEPTH};\n${loadAotOrder().take('defaults.js', defaults.EMBED)}\nreturn buildDefaultsApplier;\n})();\n` +
|
|
371
371
|
`let _ataFill;\nfunction applyDefaults(d) { (_ataFill || (_ataFill = _ataDefaults(JSON.parse(${text}))))(d); }\n`;
|
|
372
372
|
}
|
|
373
373
|
|
|
@@ -458,7 +458,7 @@ function toStandaloneModule(validator, opts) {
|
|
|
458
458
|
// sorts by each error site's ordinal, the collector writes it (`_o`).
|
|
459
459
|
const schemaForErrors = typeof validator._schemaObj === 'object' ? validator._schemaObj : {};
|
|
460
460
|
ordered = !!(opts && opts.order === true);
|
|
461
|
-
const noOrdinal = !ordered || !
|
|
461
|
+
const noOrdinal = !ordered || !loadAotOrder().wantsOrdinals(schemaForErrors);
|
|
462
462
|
jsErrFn = compileToJSCodegenWithErrors(
|
|
463
463
|
schemaForErrors,
|
|
464
464
|
null,
|
|
@@ -600,7 +600,7 @@ function toStandaloneModule(validator, opts) {
|
|
|
600
600
|
compactCore = `let _ataErrs = null;\nfunction _ataErrors(d) { if (_ataErrs === null) _ataErrs = _ataCreateErrors(JSON.parse(${text})${rtOpts ? ', { ' + rtOpts + ' }' : ''}); return _ataErrs(d); }\n`;
|
|
601
601
|
}
|
|
602
602
|
const orderDecl = errCore && ordered && errorRuntime === null && onePass === null
|
|
603
|
-
?
|
|
603
|
+
? loadAotOrder().orderDecl(validator._schemaObj)
|
|
604
604
|
: '';
|
|
605
605
|
// Asked for and not given: stub errors, the one-pass function, or no error
|
|
606
606
|
// code generated. The caller is told rather than handed the collector's
|
|
@@ -736,20 +736,15 @@ function validate(data) { ${pre.call}${validBody}; }
|
|
|
736
736
|
${parseCore}${positionsCore}${fillDecl}${hashDecl}${exports}`;
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
-
//
|
|
740
|
-
//
|
|
741
|
-
//
|
|
742
|
-
//
|
|
743
|
-
//
|
|
744
|
-
//
|
|
745
|
-
//
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
// that.
|
|
749
|
-
const ERROR_RUNTIME_MODULE = './error-runtime';
|
|
750
|
-
// Reads the library's files too, at build time (see lib/aot-order.js).
|
|
751
|
-
const AOT_ORDER_MODULE = './aot-order';
|
|
752
|
-
function loadErrorRuntime() { return require(ERROR_RUNTIME_MODULE); }
|
|
739
|
+
// The error runtime and the order helpers are required by their literal
|
|
740
|
+
// names: an executable compiled ahead of time (Bun) loads a module from a
|
|
741
|
+
// computed path by throwing, and warns about every such require at build
|
|
742
|
+
// time. Both modules read the library's own files with fs at build time;
|
|
743
|
+
// a bundle for a runtime without fs is kept away from lib/aot-order.js by
|
|
744
|
+
// the package's `browser` field, and lib/error-runtime.js loads fs only in
|
|
745
|
+
// the functions that read files.
|
|
746
|
+
function loadErrorRuntime() { return require('./error-runtime'); }
|
|
747
|
+
function loadAotOrder() { return require('./aot-order'); }
|
|
753
748
|
|
|
754
749
|
// The schema hash a module stamps, once per validator: a plugin writes both
|
|
755
750
|
// modules of a schema (self-contained and compact) from one validator, and
|
|
@@ -973,7 +968,7 @@ function bundleStandalone(Validator, schemas, opts) {
|
|
|
973
968
|
v._ensureCompiled();
|
|
974
969
|
const jsFn = v._jsFn;
|
|
975
970
|
if (!jsFn || !jsFn._hybridSource) return null;
|
|
976
|
-
const noOrdinal = !ordered || !
|
|
971
|
+
const noOrdinal = !ordered || !loadAotOrder().wantsOrdinals(v._schemaObj);
|
|
977
972
|
// The schema the validator compiled, not the one the caller passed. They
|
|
978
973
|
// differ whenever anything prepared the schema: draft-07 normalization,
|
|
979
974
|
// `format` removed under assertFormat: false, keywords outside the
|
|
@@ -1040,7 +1035,7 @@ function bundleStandalone(Validator, schemas, opts) {
|
|
|
1040
1035
|
// In order: the collector's errors sorted as the runtime sorts them.
|
|
1041
1036
|
const hasErr = !!(jsErrFn && jsErrFn._errSource);
|
|
1042
1037
|
const errDecl = ordered && hasErr
|
|
1043
|
-
? `${
|
|
1038
|
+
? `${loadAotOrder().orderDecl(v._schemaObj)}var E=function(d){var r=(function(d){var _all=true;${errBody}})(d);return r&&r.errors?{valid:false,errors:_ataOrder(r.errors)}:r};`
|
|
1044
1039
|
: `var E=function(d){var _all=true;${errBody}};`;
|
|
1045
1040
|
if (opts && opts.verbose) {
|
|
1046
1041
|
// Embed the schema and a small resolver so errors carry parentSchema.
|