ata-validator 1.42.0 → 1.43.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/index.js CHANGED
@@ -503,7 +503,7 @@ function installCodegenPaths (ctx) {
503
503
  // The verdict function alone, for isValidObject() before a full compile: the
504
504
  // error and combined generators are left for the first rejection.
505
505
  installCodegenPaths.compileVerdict = function compileVerdict () {
506
- const { compileCacheKey, _compileCache, _bindVerdict, _rememberInstance } = core._internals;
506
+ const { compileCacheKey, _compileCache, _compileCacheSet, _bindVerdict, _rememberInstance } = core._internals;
507
507
  if (!this._schemaStr) this._schemaStr = JSON.stringify(this._schemaObj);
508
508
  const sm = this._schemaMap.size > 0 ? this._schemaMap : null;
509
509
  const mapKey = compileCacheKey(this._schemaStr, this._schemaMap);
@@ -532,7 +532,7 @@ installCodegenPaths.compileVerdict = function compileVerdict () {
532
532
  // validator that later reuses this entry reports the same engine it
533
533
  // would have compiled to.
534
534
  if (!uf && !this._keywords) {
535
- if (!cached) _compileCache.set(mapKey, { jsFn, combined: undefined, errFn: undefined, isCodegen: !!_cg, full: false });
535
+ if (!cached) _compileCacheSet(mapKey, { jsFn, combined: undefined, errFn: undefined, isCodegen: !!_cg, full: false });
536
536
  else cached.jsFn = jsFn;
537
537
  }
538
538
  }
@@ -44,6 +44,21 @@ function __ataScore (errs) {
44
44
  // `title`, or the titles in `titles` when given (the generated code passes
45
45
  // each branch's result as it is rather than copying it to add one).
46
46
  // Returns the single error to report, or null when the keyword is satisfied.
47
+ // oneOf passed by more than one branch; generated code builds it from a count.
48
+ function __ataMulti (passIdx, total, pp, sp, o) {
49
+ const multi = {
50
+ code: 'ATA4002',
51
+ keyword: 'oneOf',
52
+ instancePath: pp || '',
53
+ path: pp || '',
54
+ schemaPath: sp,
55
+ message: 'value matched ' + passIdx.length + ' of ' + total + ' oneOf variants, expected exactly one',
56
+ params: { passingSchemas: passIdx },
57
+ };
58
+ if (o !== null) Object.defineProperty(multi, '_o', { value: o });
59
+ return multi;
60
+ }
61
+
47
62
  function __ataCollapse (kw, br, pp, sp, o, titles) {
48
63
  let passN = 0;
49
64
  for (let i = 0; i < br.length; i++) if (br[i].valid) passN++;
@@ -53,17 +68,7 @@ function __ataCollapse (kw, br, pp, sp, o, titles) {
53
68
  if (pass.length > 1) {
54
69
  const passIdx = [];
55
70
  for (let i = 0; i < br.length; i++) if (br[i].valid) passIdx.push(i);
56
- const multi = {
57
- code: 'ATA4002',
58
- keyword: 'oneOf',
59
- instancePath: pp || '',
60
- path: pp || '',
61
- schemaPath: sp,
62
- message: 'value matched ' + pass.length + ' of ' + br.length + ' oneOf variants, expected exactly one',
63
- params: { passingSchemas: passIdx },
64
- };
65
- if (o !== null) Object.defineProperty(multi, '_o', { value: o });
66
- return multi;
71
+ return __ataMulti(passIdx, br.length, pp, sp, o);
67
72
  }
68
73
  } else if (pass.length >= 1) {
69
74
  return null;
@@ -97,12 +102,13 @@ function collapseBranches ({ keyword, branchResults, parentPath, parentSchemaPat
97
102
  return __ataCollapse(keyword, branchResults, parentPath, parentSchemaPath, ordinal === undefined ? null : ordinal);
98
103
  }
99
104
 
100
- // The three declarations as source, for the generated code to carry. Derived
105
+ // The four declarations as source, for the generated code to carry. Derived
101
106
  // from the functions above rather than written out again, so a fix to one
102
107
  // cannot miss the other. `tests/test_branch_collapse.js` runs both.
103
108
  function embedSource () {
104
109
  return 'const __ATA_SEVERITY=' + JSON.stringify(__ATA_SEVERITY) + ';' +
105
110
  'const __ataScore=' + __ataScore.toString() + ';' +
111
+ 'const __ataMulti=' + __ataMulti.toString() + ';' +
106
112
  'const __ataCollapse=' + __ataCollapse.toString() + ';';
107
113
  }
108
114
 
@@ -30,7 +30,7 @@ function errorSite (keyword, schemaPath, params, format) {
30
30
  };
31
31
  }
32
32
 
33
- function makeRich (site, path, params, message, value, root) {
33
+ function makeRich (site, path, params, message, value, root, spPrefix) {
34
34
  // As resolveAt: a root that is null, undefined, '' or NaN resolves nothing.
35
35
  const at = (!root && root !== 0 && root !== false) ? MISSING : value;
36
36
  const out = {
@@ -40,7 +40,7 @@ function makeRich (site, path, params, message, value, root) {
40
40
  path,
41
41
  expected: site.expected === NO_EXPECTED ? expectedFor({ keyword: site.keyword, params }) : site.expected,
42
42
  received: at === MISSING ? undefined : reprValue(at),
43
- schemaPath: site.schemaPath,
43
+ schemaPath: spPrefix === undefined ? site.schemaPath : spPrefix + site.schemaPath,
44
44
  docUrl: site.docUrl,
45
45
  instancePath: path,
46
46
  dataPath: path,