ata-validator 1.50.0 → 1.52.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.
@@ -121,6 +121,9 @@ const _hop = Object.prototype.hasOwnProperty
121
121
  function _h (o, k) { return _hop.call(o, k) }
122
122
  function _ok (o, k) { return (_PN ? o.__proto__ : _gp(o)) === _OP || _hop.call(o, k) } // eslint-disable-line no-proto
123
123
  function _hall (o, ks) { for (let i = 0; i < ks.length; i++) if (!_hop.call(o, ks[i])) return false; return true }
124
+ // A key count that came out wrong, counted again over own keys unless the
125
+ // object is ordinary.
126
+ function _nk (o, n) { return (_PN ? o.__proto__ : _gp(o)) === _OP || Object.keys(o).length !== n } // eslint-disable-line no-proto
124
127
 
125
128
  // RFC 6901 escaping for a key only known at run time (the static ones are
126
129
  // escaped when the code is written).
@@ -140,7 +143,7 @@ function _rb (S, m) { if (S.length !== m) S.length = m }
140
143
 
141
144
  module.exports = {
142
145
  apState, ap, sr, srX, multiBranch,
143
- _PN, _OP, _gp, _hop, _h, _ok, _hall, _pe, _anT, _anF, _rb,
146
+ _PN, _OP, _gp, _hop, _h, _ok, _hall, _nk, _pe, _anT, _anF, _rb,
144
147
  }
145
148
  // Loaded when a program first asks for them: a schema without const, enum,
146
149
  // uniqueItems, oneOf or anyOf never needs these modules on its cold path.
@@ -94,7 +94,11 @@ function errorRuntimeSource(format, version, features, schemaMode) {
94
94
  const src = OPTIONAL[name] !== undefined && !want(name)
95
95
  ? OPTIONAL[name].stub
96
96
  : dropCommentLines(fs.readFileSync(path.join(__dirname, name + '.js'), 'utf8'), name);
97
- defs.push(`${JSON.stringify(name)}: function (module, exports, require) {\n${src}\n}`);
97
+ // The files' own require('./x') calls go to the table under another name:
98
+ // a tool that reads the runtime without scope (knip, a lint rule) took a
99
+ // local `require` for an import of a file that is not there.
100
+ const own = src.replace(/\brequire\((['"])\.\//g, '__ataReq($1./');
101
+ defs.push(`${JSON.stringify(name)}: function (module, exports, __ataReq) {\n${own}\n}`);
98
102
  }
99
103
  const { byKw, byFmt } = codeTable();
100
104
  const body = `// Auto-generated by ata-validator ${version}, do not edit.
@@ -9,7 +9,7 @@ const { compileFunction } = require('./compile-fn')
9
9
  // the first call that compiles errors. Everything here was written as part
10
10
  // of js-compiler.js and reads its helpers from that module's _internal.
11
11
  const core = require('./js-compiler')
12
- const { hasConstraints, assertEmitted, prepareForCodegen, sharedCodegenGate, codegenSafe, isSimplePN, hasUnresolvableRef, needsBaseTracking, _cpLen, sharedRt, DECLINE, bindRt, compileSafe, emitGuardState, withPlain, REF_NEUTRAL_SIBLINGS, resolveCrossSchemaRef, enumCondition, enumOperand, emitDeq, emitConstant, ownGuard, ownKeyExpr, multipleOfBad, compilePatternInline, useSafeEngine, reFlags, FORMAT_CODEGEN, PROTO_NAMES, setOwn, nestedGenCode, compileToJSCodegen, SKIP_VALUE_KEYS, skipString, CYCLE_DEPTH, cyclicDefNames, sharedDefNames, reFlagArg, hoistOnce, PTR_ESC_HELPER, unevalContributions, emitUq, uqSources, safeReClosure, fastPrefixCheck, replaceTopLevel, refTargetFor, genCode, addLocalAnnotations, addTopApplicatorAnnotations, protoIs, ANNOT_APPLICATORS, SIZE_SKIPS, emitRootGuard, emitGuardedRun } = core._internal
12
+ const { ownHead, hasConstraints, assertEmitted, prepareForCodegen, sharedCodegenGate, codegenSafe, isSimplePN, hasUnresolvableRef, needsBaseTracking, _cpLen, sharedRt, DECLINE, bindRt, compileSafe, emitGuardState, withPlain, REF_NEUTRAL_SIBLINGS, resolveCrossSchemaRef, enumCondition, enumOperand, emitDeq, emitConstant, ownGuard, ownKeyExpr, multipleOfBad, compilePatternInline, useSafeEngine, reFlags, FORMAT_CODEGEN, PROTO_NAMES, setOwn, nestedGenCode, compileToJSCodegen, SKIP_VALUE_KEYS, skipString, CYCLE_DEPTH, cyclicDefNames, sharedDefNames, reFlagArg, hoistOnce, PTR_ESC_HELPER, unevalContributions, emitUq, uqSources, safeReClosure, fastPrefixCheck, replaceTopLevel, refTargetFor, genCode, addLocalAnnotations, addTopApplicatorAnnotations, protoIs, ANNOT_APPLICATORS, SIZE_SKIPS, emitRootGuard, emitGuardedRun } = core._internal
13
13
 
14
14
 
15
15
  function emitPtrEsc(ctx) {
@@ -1313,7 +1313,7 @@ function genCodeENode(schema, v, pathExpr, lines, ctx, schemaPrefix) {
1313
1313
  // The name set is built once per call of the error function, not at every
1314
1314
  // object it checks: on a list of 1723 tokens it was 1723 Sets.
1315
1315
  ctx.helperCode.push(`const _a${ci}=new Set([${allowed}])`)
1316
- const inner = `let _x${ci}=0;for(const _f${ci} in ${v}){if(${gateTest}){_x${ci}=1;break}}if(_x${ci}){${detail}}`
1316
+ const inner = `let _x${ci}=0;${ownHead(ctx, v, `_f${ci}`, 'const')}{if(${gateTest}){_x${ci}=1;break}}if(_x${ci}){${detail}}`
1317
1317
  lines.push(isObj ? `{${inner}}` : `if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${inner}}`)
1318
1318
  }
1319
1319
 
@@ -1504,7 +1504,7 @@ function genPatternPropertiesE(schema, v, pathExpr, lines, ctx, schemaPrefix) {
1504
1504
  }
1505
1505
  const ri = ctx.regExpMap.get(pattern);
1506
1506
  const ki = ctx.varCounter++
1507
- lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){for(const _k${ki} in ${v}){if(_re${ri}.test(_k${ki})){`)
1507
+ lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${ownHead(ctx, v, `_k${ki}`, 'const')}{if(_re${ri}.test(_k${ki})){`)
1508
1508
  const _peFn = emitPtrEsc(ctx)
1509
1509
  const p = pathExpr ? `${pathExpr}+'/'+${_peFn}(_k${ki})` : `'/'+${_peFn}(_k${ki})`
1510
1510
  // The real pointer, so source maps can locate the failing keyword.
@@ -1538,7 +1538,7 @@ function genAdditionalSchemaE(schema, v, pathExpr, lines, ctx, schemaPrefix) {
1538
1538
  if (known.length) conds.push(`!_ak${ki}.has(_k${ki})`)
1539
1539
  if (patTests.length) conds.push(`!(${patTests.join('||')})`)
1540
1540
  const keep = conds.length ? `if(${conds.join('&&')}){` : `{`
1541
- lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${guard}for(const _k${ki} in ${v}){${keep}`)
1541
+ lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${guard}${ownHead(ctx, v, `_k${ki}`, 'const')}{${keep}`)
1542
1542
  const _peFn = emitPtrEsc(ctx)
1543
1543
  const p = pathExpr ? `${pathExpr}+'/'+${_peFn}(_k${ki})` : `'/'+${_peFn}(_k${ki})`
1544
1544
  genCodeE(schema.additionalProperties, `${v}[_k${ki}]`, p, lines, ctx, schemaPrefix + '/additionalProperties')
@@ -1559,13 +1559,13 @@ function genPropertyNamesFalseE(schema, v, pathExpr, lines, ctx, schemaPrefix) {
1559
1559
  // the object that carries the name, not to `/<key>`, which is where the
1560
1560
  // value lives. Same placement as the object-valued propertyNames branch.
1561
1561
  const p = pathExpr || '""'
1562
- lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){for(const _k${ki} in ${v}){_e.push({keyword:'not',instancePath:${p},schemaPath:'${schemaPrefix}/propertyNames'${ordinalField(ctx, `${schemaPrefix}/propertyNames`)},params:{},message:'boolean schema is false'});if(!_all)return{valid:false,errors:_e}}}`)
1562
+ lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${ownHead(ctx, v, `_k${ki}`, 'const')}{_e.push({keyword:'not',instancePath:${p},schemaPath:'${schemaPrefix}/propertyNames'${ordinalField(ctx, `${schemaPrefix}/propertyNames`)},params:{},message:'boolean schema is false'});if(!_all)return{valid:false,errors:_e}}}`)
1563
1563
  }
1564
1564
 
1565
1565
  function genPropertyNamesE(schema, v, pathExpr, lines, ctx, schemaPrefix, fail) {
1566
1566
  const pn = schema.propertyNames
1567
1567
  const ki = ctx.varCounter++
1568
- lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){for(const _k${ki} in ${v}){`)
1568
+ lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${ownHead(ctx, v, `_k${ki}`, 'const')}{`)
1569
1569
  // The subschema checks the key as a value, and its errors are reported at
1570
1570
  // the object, as the interpreter reports them.
1571
1571
  if (!isSimplePN(pn)) {
@@ -2523,14 +2523,14 @@ function genCodeCNode(schema, v, pathExpr, lines, ctx, schemaPrefix) {
2523
2523
  // leave `if()`, so the test is `true`.
2524
2524
  const gate = propKeys.map(k => `_f${ci}!==${JSON.stringify(k)}`).join('&&') || 'true'
2525
2525
  const checks = propKeys.map(k => `_k${ci}[_i]!==${JSON.stringify(k)}`).join('&&') || 'true'
2526
- body = `let _x${ci}=0;for(const _f${ci} in ${v}){if(${gate}){_x${ci}=1;break}}if(_x${ci}){${detail(checks)}}`
2526
+ body = `let _x${ci}=0;${ownHead(ctx, v, `_f${ci}`, 'const')}{if(${gate}){_x${ci}=1;break}}if(_x${ci}){${detail(checks)}}`
2527
2527
  } else {
2528
2528
  // The name set lives in the closure, built once with the function: built
2529
2529
  // in the body it was a 33-name Set on every call of this function, which
2530
2530
  // is where a rejected npm-badges document spent most of its 701 ns.
2531
2531
  ctx.closureVars.push(`_a${ci}`)
2532
2532
  ctx.closureVals.push(new Set(propKeys))
2533
- body = `let _x${ci}=0;for(const _f${ci} in ${v}){if(!_a${ci}.has(_f${ci})){_x${ci}=1;break}}if(_x${ci}){${detail(`!_a${ci}.has(_k${ci}[_i])`)}}`
2533
+ body = `let _x${ci}=0;${ownHead(ctx, v, `_f${ci}`, 'const')}{if(!_a${ci}.has(_f${ci})){_x${ci}=1;break}}if(_x${ci}){${detail(`!_a${ci}.has(_k${ci}[_i])`)}}`
2534
2534
  }
2535
2535
  // When every declared property is required, a clean object has exactly the
2536
2536
  // declared keys: if the enumerated count equals the declared count and
@@ -2545,7 +2545,7 @@ function genCodeCNode(schema, v, pathExpr, lines, ctx, schemaPrefix) {
2545
2545
  const req = new Set(Array.isArray(schema.required) ? schema.required : [])
2546
2546
  if (propKeys.length > 0 && propKeys.every((k) => req.has(k) && !PROTO_NAMES.has(k))) {
2547
2547
  const present = propKeys.map((k) => `${JSON.stringify(k)} in ${v}`).join('&&')
2548
- body = `let _n${ci}=0;for(const _f${ci} in ${v})_n${ci}++;if(_n${ci}!==${propKeys.length}||!(${present})){${body}}`
2548
+ body = `let _n${ci}=0;${ownHead(ctx, v, `_f${ci}`, 'const')}_n${ci}++;if(_n${ci}!==${propKeys.length}||!(${present})){${body}}`
2549
2549
  }
2550
2550
  lines.push(isObj
2551
2551
  ? `{${body}}`
@@ -2945,7 +2945,7 @@ function inlineUnevalBlock (schema, v, pathExpr, ctx, schemaPrefix, fail, counts
2945
2945
  } else {
2946
2946
  throw DECLINE
2947
2947
  }
2948
- if (body) out.push(`for(const ${kVar} in ${v}){if(!${ownKeyExpr(ctx, v, kVar).split(JSON.stringify(kVar)).join(kVar)})continue;let _ub${id}=0;switch(${kVar}){${cases}}if(_ub${id}!==0&&(${m}&_ub${id})!==0)continue;${allBit}${patBits}${body}}`)
2948
+ if (body) out.push(`${ownHead(ctx, v, kVar, 'const')}{if(!${ownKeyExpr(ctx, v, kVar).split(JSON.stringify(kVar)).join(kVar)})continue;let _ub${id}=0;switch(${kVar}){${cases}}if(_ub${id}!==0&&(${m}&_ub${id})!==0)continue;${allBit}${patBits}${body}}`)
2949
2949
  const text = out.join(';')
2950
2950
  ctx.plainReuse = prevReuse
2951
2951
  if (prevPk === undefined) ctx.plainOf.delete(v)
@@ -3357,7 +3357,7 @@ function genAdditionalSchemaC(schema, v, pathExpr, lines, ctx, schemaPrefix, isO
3357
3357
  const sub = []
3358
3358
  genCodeC(schema.additionalProperties, `${v}[${kVar}]`, p, sub, ctx, schemaPrefix + '/additionalProperties')
3359
3359
  if (sub.length === 0) return
3360
- lines.push(`${guard}{for(const ${kVar} in ${v}){${keep}{${sub.join('\n ')}\n }}}`)
3360
+ lines.push(`${guard}{${ownHead(ctx, v, kVar, 'const')}{${keep}{${sub.join('\n ')}\n }}}`)
3361
3361
  }
3362
3362
 
3363
3363
  function genPatternPropertiesC(schema, v, pathExpr, lines, ctx, schemaPrefix, fail, isObj) {
@@ -3397,7 +3397,7 @@ function genPatternPropertiesC(schema, v, pathExpr, lines, ctx, schemaPrefix, fa
3397
3397
  ctx.closureVals.push(new Set(propKeys))
3398
3398
  }
3399
3399
 
3400
- lines.push(`${guard}{for(const ${kVar} in ${v}){`)
3400
+ lines.push(`${guard}{${ownHead(ctx, v, kVar, 'const')}{`)
3401
3401
  // propertyNames checks (merged)
3402
3402
  if (pn) {
3403
3403
  if (pn.minLength !== undefined) lines.push(`if(${kVar}.length<${pn.minLength}){${fail('minLength', 'propertyNames/minLength', `{limit:${pn.minLength}}`, `'must NOT have fewer than ${pn.minLength} characters'`)}}`)
@@ -3434,7 +3434,7 @@ function genPatternPropertiesC(schema, v, pathExpr, lines, ctx, schemaPrefix, fa
3434
3434
  lines.push(`}}`)
3435
3435
  } else {
3436
3436
  handledPropertyNames = !!pn
3437
- lines.push(`${guard}{for(const ${kVar} in ${v}){`)
3437
+ lines.push(`${guard}{${ownHead(ctx, v, kVar, 'const')}{`)
3438
3438
  if (pn) {
3439
3439
  if (pn.minLength !== undefined) lines.push(`if(${kVar}.length<${pn.minLength}){${fail('minLength', 'propertyNames/minLength', `{limit:${pn.minLength}}`, `'must NOT have fewer than ${pn.minLength} characters'`)}}`)
3440
3440
  if (pn.maxLength !== undefined) lines.push(`if(${kVar}.length>${pn.maxLength}){${fail('maxLength', 'propertyNames/maxLength', `{limit:${pn.maxLength}}`, `'must NOT have more than ${pn.maxLength} characters'`)}}`)
@@ -3478,7 +3478,7 @@ function genDependentSchemasC(schema, v, pathExpr, lines, ctx, schemaPrefix) {
3478
3478
  function genPropertyNamesFalseC(schema, v, pathExpr, lines, ctx, schemaPrefix) {
3479
3479
  const ki = ctx.varCounter++
3480
3480
  const p = pathExpr || '""'
3481
- lines.push(`;if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){for(const _k${ki} in ${v}){${errPushC(ctx, 'not', `${schemaPrefix}/propertyNames`, pathExpr, '{}', "'boolean schema is false'", v, `{keyword:'not',instancePath:${p},schemaPath:'${schemaPrefix}/propertyNames'${ordinalField(ctx, `${schemaPrefix}/propertyNames`)},params:{},message:'boolean schema is false'}`)}}}`)
3481
+ lines.push(`;if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${ownHead(ctx, v, `_k${ki}`, 'const')}{${errPushC(ctx, 'not', `${schemaPrefix}/propertyNames`, pathExpr, '{}', "'boolean schema is false'", v, `{keyword:'not',instancePath:${p},schemaPath:'${schemaPrefix}/propertyNames'${ordinalField(ctx, `${schemaPrefix}/propertyNames`)},params:{},message:'boolean schema is false'}`)}}}`)
3482
3482
  }
3483
3483
 
3484
3484
  function genPropertyNamesC(schema, v, pathExpr, lines, ctx, schemaPrefix, fail) {
@@ -3488,7 +3488,7 @@ function genPropertyNamesC(schema, v, pathExpr, lines, ctx, schemaPrefix, fail)
3488
3488
  // here that would be the key where the interpreter's error points at the
3489
3489
  // object, so that one is left to the plain function and enrichment.
3490
3490
  if (!isSimplePN(pn) && ctx.rich) throw DECLINE
3491
- lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){for(const _k${ki} in ${v}){`)
3491
+ lines.push(`if(typeof ${v}==='object'&&${v}!==null&&!Array.isArray(${v})){${ownHead(ctx, v, `_k${ki}`, 'const')}{`)
3492
3492
  if (!isSimplePN(pn)) {
3493
3493
  genCodeC(pn, `_k${ki}`, pathExpr, lines, ctx, schemaPrefix + '/propertyNames')
3494
3494
  lines.push(`}}`)