ata-validator 1.51.0 → 1.53.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 +26 -20
- package/compat.js +314 -29
- package/index.bundle.mjs +15 -0
- package/lib/aot-impl.js +2 -2
- package/lib/combined-runtime.js +4 -1
- package/lib/compat-errors.js +131 -17
- package/lib/draft7.js +65 -35
- package/lib/error-runtime.js +5 -1
- package/lib/interpreter-core.js +297 -14
- package/lib/js-compiler-errors.js +15 -15
- package/lib/js-compiler.js +196 -45
- package/lib/keywords.js +24 -1
- package/lib/levenshtein.js +21 -5
- package/lib/plan-compiler.js +8 -3
- package/lib/safe-regex.js +33 -14
- package/lib/schema-scan.js +29 -1
- package/lib/validator-core.js +99 -13
- package/lib/version.js +1 -1
- package/package.json +10 -8
|
@@ -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
|
|
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})){
|
|
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}
|
|
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})){
|
|
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})){
|
|
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
|
|
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
|
|
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
|
|
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(
|
|
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}{
|
|
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}{
|
|
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}{
|
|
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})){
|
|
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})){
|
|
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(`}}`)
|