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/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${require(AOT_ORDER_MODULE).take('defaults.js', defaults.EMBED)}\nreturn buildDefaultsApplier;\n})();\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 || !require(AOT_ORDER_MODULE).wantsOrdinals(schemaForErrors);
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
- ? require(AOT_ORDER_MODULE).orderDecl(validator._schemaObj)
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
- // Why a validator cannot be written as a compact module, or null when it can.
740
- // The error runtime walks the embedded schema with the interpreted engine and
741
- // knows nothing the schema does not say, so anything the validator adds from
742
- // outside the schema keeps the module self-contained.
743
- // The error runtime's generator reads the library's own files with fs, and
744
- // runs in Node only (ata build, errorRuntimeSource). It is required through a
745
- // name rather than a literal so that a bundler following this module, in a
746
- // build of the package for a runtime without fs, does not try to bring fs
747
- // along: 1.49.0 bundled for such runtimes, and the generator must not break
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 || !require(AOT_ORDER_MODULE).wantsOrdinals(v._schemaObj);
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
- ? `${require(AOT_ORDER_MODULE).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};`
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.