@jetio/validator 1.0.2 → 1.0.4
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 +25 -59
- package/dist/compileSchema.d.ts +0 -1
- package/dist/compileSchema.js +129 -67
- package/dist/compileSchema.js.map +1 -1
- package/dist/index.cjs.js +165 -84
- package/dist/index.esm.js +165 -84
- package/dist/jet-validator.js +36 -16
- package/dist/jet-validator.js.map +1 -1
- package/dist/resolver.js +1 -1
- package/dist/resolver.js.map +1 -1
- package/dist/src/compileSchema.d.ts +0 -1
- package/dist/validator.umd.js +165 -88
- package/package.json +8 -2
package/dist/index.cjs.js
CHANGED
|
@@ -249,7 +249,6 @@ class Compiler {
|
|
|
249
249
|
this.validateKeywords = new Set();
|
|
250
250
|
this.notLogic = false;
|
|
251
251
|
this.noreturn = false;
|
|
252
|
-
this.neutralError = false;
|
|
253
252
|
this.standAlone = false;
|
|
254
253
|
this.hasCompileKeyword = false;
|
|
255
254
|
this.needslen_of = false;
|
|
@@ -442,11 +441,10 @@ class Compiler {
|
|
|
442
441
|
return src.join("");
|
|
443
442
|
}
|
|
444
443
|
const schema = rootSchema;
|
|
445
|
-
const varName =
|
|
446
|
-
!this.options.
|
|
447
|
-
!this.options.coerceTypes
|
|
444
|
+
const varName = accessPattern === "rootData" ||
|
|
445
|
+
(inlined && (schema.default === undefined || !this.options.useDefaults))
|
|
448
446
|
? accessPattern
|
|
449
|
-
: "
|
|
447
|
+
: "jv" + counter++;
|
|
450
448
|
this.initializeDefault(src, schema, varName, accessPattern, inlined);
|
|
451
449
|
let shouldTrackProps;
|
|
452
450
|
let shouldTrackItems;
|
|
@@ -490,11 +488,16 @@ class Compiler {
|
|
|
490
488
|
return src.join("");
|
|
491
489
|
}
|
|
492
490
|
initializeDefault(src, schema, varName, accessPattern, inlined) {
|
|
493
|
-
if (
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
491
|
+
if (accessPattern !== "rootData") {
|
|
492
|
+
if (schema.default !== undefined && this.options.useDefaults) {
|
|
493
|
+
src.push(`let ${varName} = ${accessPattern};`, `if (${varName} === undefined || ${varName} === null) {`, `${varName} = ${JSON.stringify(schema.default)};`, "}");
|
|
494
|
+
}
|
|
495
|
+
else if (!inlined) {
|
|
496
|
+
const keyword = this.options.removeAdditional || this.options.coerceTypes
|
|
497
|
+
? "let"
|
|
498
|
+
: "const";
|
|
499
|
+
src.push(`${keyword} ${varName} = ${accessPattern};`);
|
|
500
|
+
}
|
|
498
501
|
}
|
|
499
502
|
if (this.options.coerceTypes) {
|
|
500
503
|
if (schema.type === "number" || schema.type === "integer") {
|
|
@@ -610,10 +613,20 @@ class Compiler {
|
|
|
610
613
|
src.push(`if(${extra.before} true){`);
|
|
611
614
|
src.push(`const ${funcValidator}Result = ${awaitPrefix}${schema.__functionName}${callArgs};`);
|
|
612
615
|
if (this.options.allErrors) {
|
|
613
|
-
src.push(`if (!${funcValidator}Result)
|
|
616
|
+
src.push(`if (!${funcValidator}Result){${extra.after}${this.notLogic ? "" : `${this.errorVariable} = ${this.errorVariable}.concat(${schema.__functionName}.errors);`}}`);
|
|
614
617
|
}
|
|
615
618
|
else {
|
|
616
|
-
|
|
619
|
+
if (this.noreturn) {
|
|
620
|
+
src.push(`if (!${funcValidator}Result){${extra.after}${this.notLogic ? "" : `${schema.__functionName}.errors.length > 1 ? (${this.errorVariable} = ${this.errorVariable}.concat(${schema.__functionName}.errors)) : ${this.errorVariable}.push(${schema.__functionName}.errors[0]);`}}`);
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
if (this.mainFunctionName === schema.__functionName) {
|
|
624
|
+
src.push(`if (!${funcValidator}Result){${this.notLogic ? extra.after : `return false;`}}`);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
src.push(`if (!${funcValidator}Result){${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${schema.__functionName}.errors;return false;`}}`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
617
630
|
}
|
|
618
631
|
if (extra.before != "")
|
|
619
632
|
src.push(`}`);
|
|
@@ -639,10 +652,20 @@ class Compiler {
|
|
|
639
652
|
src.push(`if(${extra.before} true){`);
|
|
640
653
|
src.push(`const ${refValidator}Result = ${awaitPrefix}${functionName}${callArgs};`);
|
|
641
654
|
if (this.options.allErrors) {
|
|
642
|
-
src.push(`if (!${refValidator}Result)
|
|
655
|
+
src.push(`if (!${refValidator}Result){${extra.after}${this.notLogic ? "" : `${this.errorVariable} = ${this.errorVariable}.concat(${functionName}.errors);`}}`);
|
|
643
656
|
}
|
|
644
657
|
else {
|
|
645
|
-
|
|
658
|
+
if (this.noreturn) {
|
|
659
|
+
src.push(`if (!${refValidator}Result){${extra.after}${this.notLogic ? "" : `${functionName}.errors.length > 1 ? (${this.errorVariable} = ${this.errorVariable}.concat(${functionName}.errors)) : ${this.errorVariable}.push(${functionName}.errors[0]);`}}`);
|
|
660
|
+
}
|
|
661
|
+
else {
|
|
662
|
+
if (this.mainFunctionName === functionName) {
|
|
663
|
+
src.push(`if (!${refValidator}Result){${this.notLogic ? extra.after : `return false;`}}`);
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
src.push(`if (!${refValidator}Result){${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${functionName}.errors;return false;`}}`);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
646
669
|
}
|
|
647
670
|
if (extra.before != "")
|
|
648
671
|
src.push(`}`);
|
|
@@ -661,12 +684,12 @@ class Compiler {
|
|
|
661
684
|
return `(${args.join(", ")})`;
|
|
662
685
|
}
|
|
663
686
|
handleLogicalOperators(src, schema, varName, pathContext, trackingState, extra) {
|
|
687
|
+
if (schema.allOf)
|
|
688
|
+
this.handleAllOfOperator(src, schema, varName, pathContext, trackingState, extra);
|
|
664
689
|
if (schema.not)
|
|
665
690
|
this.handleNotOperator(src, schema, varName, pathContext, extra);
|
|
666
691
|
if (schema.anyOf)
|
|
667
692
|
this.handleAnyOfOperator(src, schema, varName, pathContext, trackingState, extra);
|
|
668
|
-
if (schema.allOf)
|
|
669
|
-
this.handleAllOfOperator(src, schema, varName, pathContext, trackingState, extra);
|
|
670
693
|
if (schema.oneOf)
|
|
671
694
|
this.handleOneOfOperator(src, schema, varName, pathContext, trackingState, extra);
|
|
672
695
|
}
|
|
@@ -700,9 +723,12 @@ class Compiler {
|
|
|
700
723
|
let firstLength = "";
|
|
701
724
|
const anyOfValid = "anyOfValid" + counter++;
|
|
702
725
|
src.push(`let ${anyOfValid} = false;`);
|
|
703
|
-
const anyOfError =
|
|
704
|
-
|
|
726
|
+
const anyOfError = this.noreturn
|
|
727
|
+
? this.errorVariable
|
|
728
|
+
: "anyOfErr" + counter++;
|
|
729
|
+
if (!this.options.allErrors && !this.noreturn)
|
|
705
730
|
src.push(`let ${anyOfError} = [];`);
|
|
731
|
+
const error = this.errorVariable;
|
|
706
732
|
schema.anyOf.forEach((subSchema, index) => {
|
|
707
733
|
const branch = `branch${counter++}Valid`;
|
|
708
734
|
if (!this.options.allErrors)
|
|
@@ -713,24 +739,27 @@ class Compiler {
|
|
|
713
739
|
const configs = this.createSubschemaOptions(trackingState, pathContext, `anyOf/${index}`, schema);
|
|
714
740
|
configs.pathContext.alt = `${pathContext.schema}/anyOf/${index}`;
|
|
715
741
|
configs.pathContext.alt2 = `${pathContext.schema}/anyOf`;
|
|
742
|
+
let errorCountVar = "anyErrCnt" + counter++;
|
|
716
743
|
if (this.options.allErrors) {
|
|
717
744
|
validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, extra, true);
|
|
718
745
|
}
|
|
719
746
|
else {
|
|
747
|
+
this.errorVariable = anyOfError;
|
|
720
748
|
validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, {
|
|
721
749
|
before: `${branch} && `,
|
|
722
|
-
after: `${branch} = false
|
|
723
|
-
refAfter: `${branch} = false;${this.notLogic ? "" : `${anyOfError} = ${anyOfError}.concat(${this.mainFunctionName}.errors);`}`,
|
|
750
|
+
after: `${branch} = false;`,
|
|
724
751
|
}, true);
|
|
725
752
|
}
|
|
726
|
-
this.noreturn = noreturn;
|
|
727
|
-
let errorCountVar;
|
|
728
753
|
if (this.options.allErrors) {
|
|
729
|
-
errorCountVar = "anyErrCnt" + counter++;
|
|
730
754
|
src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
|
|
731
755
|
if (index === 0)
|
|
732
756
|
firstLength = errorCountVar;
|
|
733
757
|
}
|
|
758
|
+
else if (index === 0) {
|
|
759
|
+
src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
|
|
760
|
+
firstLength = errorCountVar;
|
|
761
|
+
}
|
|
762
|
+
this.noreturn = noreturn;
|
|
734
763
|
if (index > 0 &&
|
|
735
764
|
!trackingState.shouldTrackEvaluatedProperties &&
|
|
736
765
|
!trackingState.shouldTrackEvaluatedItems) {
|
|
@@ -765,27 +794,36 @@ class Compiler {
|
|
|
765
794
|
}
|
|
766
795
|
});
|
|
767
796
|
if (this.options.allErrors) {
|
|
768
|
-
src.push(`if (${anyOfValid}) {${this.errorVariable}.length = ${firstLength};}${extra.after != "" ? `else{${extra.after}}` : ""}`);
|
|
797
|
+
src.push(`if (${anyOfValid} && ${this.errorVariable}.length != ${firstLength}) {${this.errorVariable}.length = ${firstLength};}${extra.after != "" ? `else if(!${anyOfValid}){${extra.after}}` : ""}`);
|
|
769
798
|
}
|
|
770
799
|
else {
|
|
771
|
-
|
|
800
|
+
if (this.noreturn) {
|
|
801
|
+
src.push(`if (${anyOfValid} && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(!${anyOfValid}){${extra.after}}`);
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
src.push(`if (${anyOfValid} && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(!${anyOfValid}){${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${this.errorVariable};return false;`}}`);
|
|
805
|
+
}
|
|
806
|
+
this.errorVariable = error;
|
|
772
807
|
}
|
|
773
808
|
}
|
|
774
809
|
handleOneOfOperator(src, schema, varName, pathContext, trackingState, extra) {
|
|
775
810
|
if (!schema.oneOf)
|
|
776
811
|
return;
|
|
777
812
|
let firstLength = "";
|
|
778
|
-
const oneOfErrors =
|
|
813
|
+
const oneOfErrors = this.noreturn
|
|
814
|
+
? this.errorVariable
|
|
815
|
+
: `oneOfErrors${counter++}`;
|
|
779
816
|
const validSchemaCount = "validSchemaCount" + counter++;
|
|
780
817
|
src.push(`let ${validSchemaCount} = 0;`);
|
|
781
|
-
if (!this.options.allErrors)
|
|
818
|
+
if (!this.options.allErrors && !this.noreturn)
|
|
782
819
|
src.push(`let ${oneOfErrors} = [];`);
|
|
820
|
+
const noreturn = this.noreturn;
|
|
821
|
+
const error = this.errorVariable;
|
|
783
822
|
schema.oneOf.forEach((subSchema, index) => {
|
|
784
823
|
const branch = `branch${counter++}Valid`;
|
|
785
|
-
if (!this.options.allErrors
|
|
824
|
+
if (!this.options.allErrors)
|
|
786
825
|
src.push(`let ${branch} = true;`);
|
|
787
826
|
let validatorFn;
|
|
788
|
-
const noreturn = this.noreturn;
|
|
789
827
|
this.noreturn = true;
|
|
790
828
|
const configs = this.createSubschemaOptions(trackingState, pathContext, `oneOf/${index}`, schema);
|
|
791
829
|
configs.pathContext.alt = `${pathContext.schema}/oneOf/${index}`;
|
|
@@ -794,20 +832,22 @@ class Compiler {
|
|
|
794
832
|
validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, extra, true);
|
|
795
833
|
}
|
|
796
834
|
else {
|
|
835
|
+
this.errorVariable = oneOfErrors;
|
|
797
836
|
validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, {
|
|
798
837
|
before: `${branch} && `,
|
|
799
|
-
after: `${branch} = false
|
|
800
|
-
refAfter: `${branch} = false;${this.notLogic ? "" : `${oneOfErrors} = ${oneOfErrors}.concat(${this.mainFunctionName}.errors);`}`,
|
|
838
|
+
after: `${branch} = false;`,
|
|
801
839
|
}, true);
|
|
802
840
|
}
|
|
803
|
-
|
|
804
|
-
let errorCountVar;
|
|
841
|
+
let errorCountVar = "oneErrCnt" + counter++;
|
|
805
842
|
if (this.options.allErrors) {
|
|
806
|
-
errorCountVar = "oneErrCnt" + counter;
|
|
807
843
|
src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
|
|
808
844
|
if (index === 0)
|
|
809
845
|
firstLength = errorCountVar;
|
|
810
846
|
}
|
|
847
|
+
else if (index === 0) {
|
|
848
|
+
src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
|
|
849
|
+
firstLength = errorCountVar;
|
|
850
|
+
}
|
|
811
851
|
if (index > 0 &&
|
|
812
852
|
!trackingState.shouldTrackEvaluatedProperties &&
|
|
813
853
|
!trackingState.shouldTrackEvaluatedItems) {
|
|
@@ -842,7 +882,7 @@ class Compiler {
|
|
|
842
882
|
}
|
|
843
883
|
});
|
|
844
884
|
if (this.options.allErrors) {
|
|
845
|
-
src.push(`if (${validSchemaCount} == 1) {${this.errorVariable}.length = ${firstLength};}
|
|
885
|
+
src.push(`if (${validSchemaCount} == 1 && ${this.errorVariable}.length != ${firstLength}) {${this.errorVariable}.length = ${firstLength};}else if(${validSchemaCount} != 1){${this.buildErrorReturn(pathContext, {
|
|
846
886
|
keyword: "oneOf",
|
|
847
887
|
value: varName,
|
|
848
888
|
message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
|
|
@@ -850,14 +890,23 @@ class Compiler {
|
|
|
850
890
|
})}${extra.after}}`);
|
|
851
891
|
}
|
|
852
892
|
else {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
893
|
+
if (noreturn) {
|
|
894
|
+
src.push(`if (${validSchemaCount} == 1 && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(${validSchemaCount} != 1){${this.buildErrorReturn(pathContext, {
|
|
895
|
+
keyword: "oneOf",
|
|
896
|
+
value: varName,
|
|
897
|
+
message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
|
|
898
|
+
expected: '"exactly one schema"',
|
|
899
|
+
})}${extra.after}}`);
|
|
900
|
+
}
|
|
901
|
+
else {
|
|
902
|
+
src.push(`if (${validSchemaCount} == 1 && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(${validSchemaCount} != 1){${this.buildErrorReturn(pathContext, {
|
|
903
|
+
keyword: "oneOf",
|
|
904
|
+
value: varName,
|
|
905
|
+
message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
|
|
906
|
+
expected: '"exactly one schema"',
|
|
907
|
+
})}${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${this.errorVariable};return false;`}}`);
|
|
908
|
+
}
|
|
909
|
+
this.errorVariable = error;
|
|
861
910
|
this.noreturn = noreturn;
|
|
862
911
|
}
|
|
863
912
|
}
|
|
@@ -1445,7 +1494,7 @@ class Compiler {
|
|
|
1445
1494
|
else {
|
|
1446
1495
|
const data = this.jetValidator.getFormat(schema.format);
|
|
1447
1496
|
if (!data) {
|
|
1448
|
-
|
|
1497
|
+
console.warn(`Format '${schema.format}' not found will be ignored`);
|
|
1449
1498
|
}
|
|
1450
1499
|
const format = typeof data === "object" && "validate" in data ? data.validate : data;
|
|
1451
1500
|
const formatType = typeof data === "object" &&
|
|
@@ -1567,24 +1616,39 @@ class Compiler {
|
|
|
1567
1616
|
if (Array.isArray(schema.required)) {
|
|
1568
1617
|
if (this.options.allErrors ||
|
|
1569
1618
|
schema.required.length > this.options.loopRequired) {
|
|
1570
|
-
const arr = JSON.stringify(schema.required);
|
|
1571
|
-
const arrVar = `arr${src.length}${counter++}`;
|
|
1572
|
-
const iVar = `i${src.length}${counter++}`;
|
|
1573
|
-
src.push(`const ${arrVar} = ${arr};`);
|
|
1574
1619
|
if (extra.before != "")
|
|
1575
1620
|
src.push(`if(${extra.before} true){`);
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1621
|
+
if (schema.required.length > this.options.loopRequired) {
|
|
1622
|
+
const arr = JSON.stringify(schema.required);
|
|
1623
|
+
const arrVar = `arr${src.length}${counter++}`;
|
|
1624
|
+
const iVar = `i${src.length}${counter++}`;
|
|
1625
|
+
src.push(`const ${arrVar} = ${arr};`);
|
|
1626
|
+
src.push(`for (let ${iVar} = 0; ${iVar} < ${arrVar}.length; ${iVar}++) {`);
|
|
1627
|
+
const prop = "prop" + counter++;
|
|
1628
|
+
src.push(`const ${prop} = ${arrVar}[${iVar}];`);
|
|
1629
|
+
addEvaluatedProperty(src, prop, trackingState);
|
|
1630
|
+
src.push(`if (${extra.before}${varName}[${prop}] === undefined) {${this.buildErrorReturn(pathContext, {
|
|
1631
|
+
keyword: "required",
|
|
1632
|
+
value: varName,
|
|
1633
|
+
message: `"Missing required field: " + ${prop} + " in data."`,
|
|
1634
|
+
expected: `${prop}`,
|
|
1635
|
+
schemaPath: `${pathContext.schema}`,
|
|
1636
|
+
})}${extra.after}}`);
|
|
1637
|
+
src.push(`}`);
|
|
1638
|
+
}
|
|
1639
|
+
else {
|
|
1640
|
+
for (const prop of schema.required) {
|
|
1641
|
+
const errorMessage = JSON.stringify(`Missing required field: ${prop} in data.`);
|
|
1642
|
+
const pstring = JSON.stringify(prop);
|
|
1643
|
+
src.push(`if (${extra.before}${varName}[${pstring}] === undefined) {${this.buildErrorReturn(pathContext, {
|
|
1644
|
+
keyword: "required",
|
|
1645
|
+
value: varName,
|
|
1646
|
+
message: errorMessage,
|
|
1647
|
+
expected: `${pstring}`,
|
|
1648
|
+
schemaPath: `${pathContext.schema}`,
|
|
1649
|
+
})}${extra.after}}`);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1588
1652
|
if (extra.before != "")
|
|
1589
1653
|
src.push(`}`);
|
|
1590
1654
|
}
|
|
@@ -2252,9 +2316,7 @@ class Compiler {
|
|
|
2252
2316
|
buildErrorReturn(pathContext, error, spreads) {
|
|
2253
2317
|
if (this.notLogic)
|
|
2254
2318
|
return "";
|
|
2255
|
-
|
|
2256
|
-
return "return false;";
|
|
2257
|
-
let result = this.options.allErrors
|
|
2319
|
+
let result = this.options.allErrors || this.noreturn
|
|
2258
2320
|
? `${this.errorVariable}.push({`
|
|
2259
2321
|
: `${this.mainFunctionName}.errors = [{`;
|
|
2260
2322
|
const escapedDataPath = escapeTemplateString(error.dataPath || pathContext.data || "/");
|
|
@@ -2262,11 +2324,11 @@ class Compiler {
|
|
|
2262
2324
|
result += `dataPath: \`${escapedDataPath}\`,`;
|
|
2263
2325
|
result += `schemaPath: \`${escapedSchemaPath}\`,`;
|
|
2264
2326
|
result += `keyword: "${error.keyword}",`;
|
|
2327
|
+
if (error.expected) {
|
|
2328
|
+
result += `expected: ${error.expected},`;
|
|
2329
|
+
}
|
|
2265
2330
|
if (this.options.verbose) {
|
|
2266
2331
|
result += `value: ${error.value},`;
|
|
2267
|
-
if (error.expected) {
|
|
2268
|
-
result += `expected: ${error.expected},`;
|
|
2269
|
-
}
|
|
2270
2332
|
}
|
|
2271
2333
|
let errorMessage;
|
|
2272
2334
|
if (this.options.errorMessage && typeof this.schema !== "boolean") {
|
|
@@ -2335,7 +2397,7 @@ class Compiler {
|
|
|
2335
2397
|
result += `,${spreads}`;
|
|
2336
2398
|
}
|
|
2337
2399
|
result += "}";
|
|
2338
|
-
if (this.options.allErrors) {
|
|
2400
|
+
if (this.options.allErrors || this.noreturn) {
|
|
2339
2401
|
result += ");";
|
|
2340
2402
|
}
|
|
2341
2403
|
else {
|
|
@@ -5082,7 +5144,7 @@ class SchemaResolver {
|
|
|
5082
5144
|
throw Error(`[${mode}] Unknown type ${type}`);
|
|
5083
5145
|
}
|
|
5084
5146
|
}
|
|
5085
|
-
for (const keyword of allPossibleIncompatible) {
|
|
5147
|
+
for (const keyword of Array.from(allPossibleIncompatible)) {
|
|
5086
5148
|
const incompatibleWithAll = types.every((type) => incompatibleKeywords[type]?.includes(keyword));
|
|
5087
5149
|
if (incompatibleWithAll && schema[keyword] !== undefined) {
|
|
5088
5150
|
throw Error(`[${mode}] Keyword "${keyword}" is incompatible with ${types.length > 1 ? "all types" : "type"} "${types.join(", ")}"`);
|
|
@@ -5644,6 +5706,7 @@ class JetValidator {
|
|
|
5644
5706
|
const fconfig = {
|
|
5645
5707
|
...config,
|
|
5646
5708
|
};
|
|
5709
|
+
const has$Data = compileContext.uses$Data;
|
|
5647
5710
|
if (typeof resolvedSchema === "boolean")
|
|
5648
5711
|
fconfig.allErrors = false;
|
|
5649
5712
|
const compiler = new Compiler(refables, mainSchema, fconfig, this, allKeywords, compileContext, false);
|
|
@@ -5676,22 +5739,6 @@ class JetValidator {
|
|
|
5676
5739
|
if (validate)
|
|
5677
5740
|
customKeywords.set(keywordDef, validate);
|
|
5678
5741
|
}
|
|
5679
|
-
if (typeof resolvedSchema !== "boolean") {
|
|
5680
|
-
if (allFormats.size > 0) {
|
|
5681
|
-
for (const validatorKey of allFormats) {
|
|
5682
|
-
const validator = this.formatValidators[validatorKey];
|
|
5683
|
-
if (validator) {
|
|
5684
|
-
if (typeof validator === "function" ||
|
|
5685
|
-
validator instanceof RegExp) {
|
|
5686
|
-
formatValidators[validatorKey] = validator;
|
|
5687
|
-
}
|
|
5688
|
-
else {
|
|
5689
|
-
formatValidators[validatorKey] = validator.validate;
|
|
5690
|
-
}
|
|
5691
|
-
}
|
|
5692
|
-
}
|
|
5693
|
-
}
|
|
5694
|
-
}
|
|
5695
5742
|
const asyncPrefix = config.async ? "async " : "";
|
|
5696
5743
|
let functionDeclaration = "validate(rootData";
|
|
5697
5744
|
if (compileContext.hasRootReference) {
|
|
@@ -5724,6 +5771,40 @@ class JetValidator {
|
|
|
5724
5771
|
regexArgs.push(new RegExp(key));
|
|
5725
5772
|
}
|
|
5726
5773
|
}
|
|
5774
|
+
if (typeof resolvedSchema !== "boolean") {
|
|
5775
|
+
if (has$Data) {
|
|
5776
|
+
const formatKeys = Array.isArray(fconfig.formats) && fconfig.formats.length > 0
|
|
5777
|
+
? fconfig.formats
|
|
5778
|
+
: Object.keys(this.formatValidators);
|
|
5779
|
+
for (const validatorKey of formatKeys) {
|
|
5780
|
+
const validator = this.formatValidators[validatorKey];
|
|
5781
|
+
if (validator) {
|
|
5782
|
+
if (typeof validator === "function" ||
|
|
5783
|
+
validator instanceof RegExp) {
|
|
5784
|
+
formatValidators[validatorKey] = validator;
|
|
5785
|
+
}
|
|
5786
|
+
else {
|
|
5787
|
+
formatValidators[validatorKey] = validator.validate;
|
|
5788
|
+
}
|
|
5789
|
+
}
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5792
|
+
else if (allFormats.size > 0) {
|
|
5793
|
+
for (const validatorKey of allFormats) {
|
|
5794
|
+
const validator = this.formatValidators[validatorKey];
|
|
5795
|
+
if (validator) {
|
|
5796
|
+
if (typeof validator === "function" ||
|
|
5797
|
+
validator instanceof RegExp) {
|
|
5798
|
+
formatValidators[validatorKey] = validator;
|
|
5799
|
+
}
|
|
5800
|
+
else {
|
|
5801
|
+
formatValidators[validatorKey] = validator.validate;
|
|
5802
|
+
}
|
|
5803
|
+
}
|
|
5804
|
+
}
|
|
5805
|
+
}
|
|
5806
|
+
}
|
|
5807
|
+
Object.values(formatValidators);
|
|
5727
5808
|
return new Function("formatValidators", "deepEqual", "canonicalStringify", "customKeywords", "len_of", ...regexParams, finalSource)(formatValidators, deepEqual, canonicalStringify, customKeywords, len_of, ...regexArgs);
|
|
5728
5809
|
}
|
|
5729
5810
|
compile(fschema, config) {
|