@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.
@@ -251,7 +251,6 @@
251
251
  this.validateKeywords = new Set();
252
252
  this.notLogic = false;
253
253
  this.noreturn = false;
254
- this.neutralError = false;
255
254
  this.standAlone = false;
256
255
  this.hasCompileKeyword = false;
257
256
  this.needslen_of = false;
@@ -444,11 +443,10 @@
444
443
  return src.join("");
445
444
  }
446
445
  const schema = rootSchema;
447
- const varName = (schema.default === undefined || !this.options.useDefaults) &&
448
- !this.options.removeAdditional &&
449
- !this.options.coerceTypes
446
+ const varName = accessPattern === "rootData" ||
447
+ (inlined && (schema.default === undefined || !this.options.useDefaults))
450
448
  ? accessPattern
451
- : "var" + counter++;
449
+ : "jv" + counter++;
452
450
  this.initializeDefault(src, schema, varName, accessPattern, inlined);
453
451
  let shouldTrackProps;
454
452
  let shouldTrackItems;
@@ -492,11 +490,16 @@
492
490
  return src.join("");
493
491
  }
494
492
  initializeDefault(src, schema, varName, accessPattern, inlined) {
495
- if (schema.default !== undefined && this.options.useDefaults) {
496
- src.push(`let ${varName} = ${accessPattern};`, `if (${varName} === undefined || ${varName} === null) {`, `${varName} = ${JSON.stringify(schema.default)};`, "}");
497
- }
498
- else if (this.options.removeAdditional || this.options.coerceTypes) {
499
- src.push(`let ${varName} = ${accessPattern};`);
493
+ if (accessPattern !== "rootData") {
494
+ if (schema.default !== undefined && this.options.useDefaults) {
495
+ src.push(`let ${varName} = ${accessPattern};`, `if (${varName} === undefined || ${varName} === null) {`, `${varName} = ${JSON.stringify(schema.default)};`, "}");
496
+ }
497
+ else if (!inlined) {
498
+ const keyword = this.options.removeAdditional || this.options.coerceTypes
499
+ ? "let"
500
+ : "const";
501
+ src.push(`${keyword} ${varName} = ${accessPattern};`);
502
+ }
500
503
  }
501
504
  if (this.options.coerceTypes) {
502
505
  if (schema.type === "number" || schema.type === "integer") {
@@ -605,7 +608,6 @@
605
608
  }
606
609
  }
607
610
  initializeSchemaRefables(src, schema, varName, pathContext, trackingState, extra) {
608
- var _a;
609
611
  const funcValidator = "func" + counter++;
610
612
  const callArgs = this.buildRefCallArgs(varName, pathContext, trackingState, "#");
611
613
  const awaitPrefix = this.options.async ? "await " : "";
@@ -613,16 +615,25 @@
613
615
  src.push(`if(${extra.before} true){`);
614
616
  src.push(`const ${funcValidator}Result = ${awaitPrefix}${schema.__functionName}${callArgs};`);
615
617
  if (this.options.allErrors) {
616
- src.push(`if (!${funcValidator}Result) {${this.errorVariable} = ${this.errorVariable}.concat(${schema.__functionName}.errors);${extra.refAfter || extra.after}}`);
618
+ src.push(`if (!${funcValidator}Result){${extra.after}${this.notLogic ? "" : `${this.errorVariable} = ${this.errorVariable}.concat(${schema.__functionName}.errors);`}}`);
617
619
  }
618
620
  else {
619
- src.push(`if (!${funcValidator}Result){${this.mainFunctionName}.errors = ${schema.__functionName}.errors;${(_a = extra.refAfter) !== null && _a !== void 0 ? _a : extra.after}${this.noreturn ? "" : "return false;"}}`);
621
+ if (this.noreturn) {
622
+ 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]);`}}`);
623
+ }
624
+ else {
625
+ if (this.mainFunctionName === schema.__functionName) {
626
+ src.push(`if (!${funcValidator}Result){${this.notLogic ? extra.after : `return false;`}}`);
627
+ }
628
+ else {
629
+ src.push(`if (!${funcValidator}Result){${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${schema.__functionName}.errors;return false;`}}`);
630
+ }
631
+ }
620
632
  }
621
633
  if (extra.before != "")
622
634
  src.push(`}`);
623
635
  }
624
636
  handleReference(src, schema, varName, pathContext, trackingState, extra) {
625
- var _a;
626
637
  const refType = schema.$ref ? "$ref" : "$dynamicRef";
627
638
  const refValue = schema.$ref || schema.$dynamicRef;
628
639
  if (refValue === "*unavailable") {
@@ -643,10 +654,20 @@
643
654
  src.push(`if(${extra.before} true){`);
644
655
  src.push(`const ${refValidator}Result = ${awaitPrefix}${functionName}${callArgs};`);
645
656
  if (this.options.allErrors) {
646
- src.push(`if (!${refValidator}Result) {${this.errorVariable} = ${this.errorVariable}.concat(${functionName}.errors);${extra.refAfter || extra.after}}`);
657
+ src.push(`if (!${refValidator}Result){${extra.after}${this.notLogic ? "" : `${this.errorVariable} = ${this.errorVariable}.concat(${functionName}.errors);`}}`);
647
658
  }
648
659
  else {
649
- src.push(`if (!${refValidator}Result){${this.mainFunctionName}.errors = ${functionName}.errors;${(_a = extra.refAfter) !== null && _a !== void 0 ? _a : extra.after}${this.noreturn ? "" : "return false;"}}`);
660
+ if (this.noreturn) {
661
+ 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]);`}}`);
662
+ }
663
+ else {
664
+ if (this.mainFunctionName === functionName) {
665
+ src.push(`if (!${refValidator}Result){${this.notLogic ? extra.after : `return false;`}}`);
666
+ }
667
+ else {
668
+ src.push(`if (!${refValidator}Result){${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${functionName}.errors;return false;`}}`);
669
+ }
670
+ }
650
671
  }
651
672
  if (extra.before != "")
652
673
  src.push(`}`);
@@ -665,12 +686,12 @@
665
686
  return `(${args.join(", ")})`;
666
687
  }
667
688
  handleLogicalOperators(src, schema, varName, pathContext, trackingState, extra) {
689
+ if (schema.allOf)
690
+ this.handleAllOfOperator(src, schema, varName, pathContext, trackingState, extra);
668
691
  if (schema.not)
669
692
  this.handleNotOperator(src, schema, varName, pathContext, extra);
670
693
  if (schema.anyOf)
671
694
  this.handleAnyOfOperator(src, schema, varName, pathContext, trackingState, extra);
672
- if (schema.allOf)
673
- this.handleAllOfOperator(src, schema, varName, pathContext, trackingState, extra);
674
695
  if (schema.oneOf)
675
696
  this.handleOneOfOperator(src, schema, varName, pathContext, trackingState, extra);
676
697
  }
@@ -699,15 +720,17 @@
699
720
  })}${extra.after}};`);
700
721
  }
701
722
  handleAnyOfOperator(src, schema, varName, pathContext, trackingState, extra) {
702
- var _a;
703
723
  if (!schema.anyOf)
704
724
  return;
705
725
  let firstLength = "";
706
726
  const anyOfValid = "anyOfValid" + counter++;
707
727
  src.push(`let ${anyOfValid} = false;`);
708
- const anyOfError = "anyOfErr" + counter++;
709
- if (!this.options.allErrors && !this.notLogic)
728
+ const anyOfError = this.noreturn
729
+ ? this.errorVariable
730
+ : "anyOfErr" + counter++;
731
+ if (!this.options.allErrors && !this.noreturn)
710
732
  src.push(`let ${anyOfError} = [];`);
733
+ const error = this.errorVariable;
711
734
  schema.anyOf.forEach((subSchema, index) => {
712
735
  const branch = `branch${counter++}Valid`;
713
736
  if (!this.options.allErrors)
@@ -718,24 +741,27 @@
718
741
  const configs = this.createSubschemaOptions(trackingState, pathContext, `anyOf/${index}`, schema);
719
742
  configs.pathContext.alt = `${pathContext.schema}/anyOf/${index}`;
720
743
  configs.pathContext.alt2 = `${pathContext.schema}/anyOf`;
744
+ let errorCountVar = "anyErrCnt" + counter++;
721
745
  if (this.options.allErrors) {
722
746
  validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, extra, true);
723
747
  }
724
748
  else {
749
+ this.errorVariable = anyOfError;
725
750
  validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, {
726
751
  before: `${branch} && `,
727
- after: `${branch} = false;${this.notLogic ? "" : `${anyOfError}.push(${this.mainFunctionName}.errors[0]);`}`,
728
- refAfter: `${branch} = false;${this.notLogic ? "" : `${anyOfError} = ${anyOfError}.concat(${this.mainFunctionName}.errors);`}`,
752
+ after: `${branch} = false;`,
729
753
  }, true);
730
754
  }
731
- this.noreturn = noreturn;
732
- let errorCountVar;
733
755
  if (this.options.allErrors) {
734
- errorCountVar = "anyErrCnt" + counter++;
735
756
  src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
736
757
  if (index === 0)
737
758
  firstLength = errorCountVar;
738
759
  }
760
+ else if (index === 0) {
761
+ src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
762
+ firstLength = errorCountVar;
763
+ }
764
+ this.noreturn = noreturn;
739
765
  if (index > 0 &&
740
766
  !trackingState.shouldTrackEvaluatedProperties &&
741
767
  !trackingState.shouldTrackEvaluatedItems) {
@@ -770,28 +796,36 @@
770
796
  }
771
797
  });
772
798
  if (this.options.allErrors) {
773
- src.push(`if (${anyOfValid}) {${this.errorVariable}.length = ${firstLength};}${extra.after != "" ? `else{${extra.after}}` : ""}`);
799
+ src.push(`if (${anyOfValid} && ${this.errorVariable}.length != ${firstLength}) {${this.errorVariable}.length = ${firstLength};}${extra.after != "" ? `else if(!${anyOfValid}){${extra.after}}` : ""}`);
774
800
  }
775
801
  else {
776
- src.push(`if (${anyOfValid}){${this.mainFunctionName}.errors = undefined}else {${this.notLogic ? "" : `${this.mainFunctionName}.errors = ${anyOfError};`}${(_a = extra.refAfter) !== null && _a !== void 0 ? _a : extra.after}${this.noreturn ? "" : "return false;"}}`);
802
+ if (this.noreturn) {
803
+ src.push(`if (${anyOfValid} && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(!${anyOfValid}){${extra.after}}`);
804
+ }
805
+ else {
806
+ 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;`}}`);
807
+ }
808
+ this.errorVariable = error;
777
809
  }
778
810
  }
779
811
  handleOneOfOperator(src, schema, varName, pathContext, trackingState, extra) {
780
- var _a;
781
812
  if (!schema.oneOf)
782
813
  return;
783
814
  let firstLength = "";
784
- const oneOfErrors = `oneOfErrors${counter++}`;
815
+ const oneOfErrors = this.noreturn
816
+ ? this.errorVariable
817
+ : `oneOfErrors${counter++}`;
785
818
  const validSchemaCount = "validSchemaCount" + counter++;
786
819
  src.push(`let ${validSchemaCount} = 0;`);
787
- if (!this.options.allErrors)
820
+ if (!this.options.allErrors && !this.noreturn)
788
821
  src.push(`let ${oneOfErrors} = [];`);
822
+ const noreturn = this.noreturn;
823
+ const error = this.errorVariable;
789
824
  schema.oneOf.forEach((subSchema, index) => {
790
825
  const branch = `branch${counter++}Valid`;
791
- if (!this.options.allErrors && !this.notLogic)
826
+ if (!this.options.allErrors)
792
827
  src.push(`let ${branch} = true;`);
793
828
  let validatorFn;
794
- const noreturn = this.noreturn;
795
829
  this.noreturn = true;
796
830
  const configs = this.createSubschemaOptions(trackingState, pathContext, `oneOf/${index}`, schema);
797
831
  configs.pathContext.alt = `${pathContext.schema}/oneOf/${index}`;
@@ -800,20 +834,22 @@
800
834
  validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, extra, true);
801
835
  }
802
836
  else {
837
+ this.errorVariable = oneOfErrors;
803
838
  validatorFn = this.compileSchema(subSchema, configs.pathContext, configs.trackingState, varName, {
804
839
  before: `${branch} && `,
805
- after: `${branch} = false;${this.notLogic ? "" : `${oneOfErrors}.push(${this.mainFunctionName}.errors[0]);`}`,
806
- refAfter: `${branch} = false;${this.notLogic ? "" : `${oneOfErrors} = ${oneOfErrors}.concat(${this.mainFunctionName}.errors);`}`,
840
+ after: `${branch} = false;`,
807
841
  }, true);
808
842
  }
809
- this.noreturn = noreturn;
810
- let errorCountVar;
843
+ let errorCountVar = "oneErrCnt" + counter++;
811
844
  if (this.options.allErrors) {
812
- errorCountVar = "oneErrCnt" + counter;
813
845
  src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
814
846
  if (index === 0)
815
847
  firstLength = errorCountVar;
816
848
  }
849
+ else if (index === 0) {
850
+ src.push(`const ${errorCountVar} = ${this.errorVariable}.length;`);
851
+ firstLength = errorCountVar;
852
+ }
817
853
  if (index > 0 &&
818
854
  !trackingState.shouldTrackEvaluatedProperties &&
819
855
  !trackingState.shouldTrackEvaluatedItems) {
@@ -848,7 +884,7 @@
848
884
  }
849
885
  });
850
886
  if (this.options.allErrors) {
851
- src.push(`if (${validSchemaCount} == 1) {${this.errorVariable}.length = ${firstLength};} else{${this.buildErrorReturn(pathContext, {
887
+ src.push(`if (${validSchemaCount} == 1 && ${this.errorVariable}.length != ${firstLength}) {${this.errorVariable}.length = ${firstLength};}else if(${validSchemaCount} != 1){${this.buildErrorReturn(pathContext, {
852
888
  keyword: "oneOf",
853
889
  value: varName,
854
890
  message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
@@ -856,14 +892,23 @@
856
892
  })}${extra.after}}`);
857
893
  }
858
894
  else {
859
- const noreturn = this.noreturn;
860
- this.noreturn = true;
861
- src.push(`if (${validSchemaCount} == 1){${this.mainFunctionName}.errors = undefined}else {${this.buildErrorReturn(pathContext, {
862
- keyword: "oneOf",
863
- value: varName,
864
- message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
865
- expected: '"exactly one schema"',
866
- })}${this.notLogic ? "" : `${oneOfErrors}.push(${this.mainFunctionName}.errors[0]);${this.mainFunctionName}.errors = ${oneOfErrors};`}${(_a = extra.refAfter) !== null && _a !== void 0 ? _a : extra.after}${noreturn ? "" : "return false;"}}`);
895
+ if (noreturn) {
896
+ src.push(`if (${validSchemaCount} == 1 && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(${validSchemaCount} != 1){${this.buildErrorReturn(pathContext, {
897
+ keyword: "oneOf",
898
+ value: varName,
899
+ message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
900
+ expected: '"exactly one schema"',
901
+ })}${extra.after}}`);
902
+ }
903
+ else {
904
+ src.push(`if (${validSchemaCount} == 1 && ${this.errorVariable}.length != ${firstLength}){${this.errorVariable}.length = ${firstLength};}else if(${validSchemaCount} != 1){${this.buildErrorReturn(pathContext, {
905
+ keyword: "oneOf",
906
+ value: varName,
907
+ message: `"Data must validate against exactly one schema, but matched "+ ${validSchemaCount}`,
908
+ expected: '"exactly one schema"',
909
+ })}${this.notLogic ? extra.after : `${this.mainFunctionName}.errors = ${this.errorVariable};return false;`}}`);
910
+ }
911
+ this.errorVariable = error;
867
912
  this.noreturn = noreturn;
868
913
  }
869
914
  }
@@ -1452,7 +1497,7 @@
1452
1497
  else {
1453
1498
  const data = this.jetValidator.getFormat(schema.format);
1454
1499
  if (!data) {
1455
- throw new Error(`Format '${schema.format}' not found`);
1500
+ console.warn(`Format '${schema.format}' not found will be ignored`);
1456
1501
  }
1457
1502
  const format = typeof data === "object" && "validate" in data ? data.validate : data;
1458
1503
  const formatType = typeof data === "object" &&
@@ -1574,24 +1619,39 @@
1574
1619
  if (Array.isArray(schema.required)) {
1575
1620
  if (this.options.allErrors ||
1576
1621
  schema.required.length > this.options.loopRequired) {
1577
- const arr = JSON.stringify(schema.required);
1578
- const arrVar = `arr${src.length}${counter++}`;
1579
- const iVar = `i${src.length}${counter++}`;
1580
- src.push(`const ${arrVar} = ${arr};`);
1581
1622
  if (extra.before != "")
1582
1623
  src.push(`if(${extra.before} true){`);
1583
- src.push(`for (let ${iVar} = 0; ${iVar} < ${arrVar}.length; ${iVar}++) {`);
1584
- const prop = "prop" + counter++;
1585
- src.push(`const ${prop} = ${arrVar}[${iVar}];`);
1586
- addEvaluatedProperty(src, prop, trackingState);
1587
- src.push(`if (${extra.before}${varName}[${prop}] === undefined) {${this.buildErrorReturn(pathContext, {
1588
- keyword: "required",
1589
- value: varName,
1590
- message: `"Missing required field: " + ${prop} + " in data."`,
1591
- expected: `${prop}`,
1592
- schemaPath: `${pathContext.schema}`,
1593
- })}${extra.after}}`);
1594
- src.push(`}`);
1624
+ if (schema.required.length > this.options.loopRequired) {
1625
+ const arr = JSON.stringify(schema.required);
1626
+ const arrVar = `arr${src.length}${counter++}`;
1627
+ const iVar = `i${src.length}${counter++}`;
1628
+ src.push(`const ${arrVar} = ${arr};`);
1629
+ src.push(`for (let ${iVar} = 0; ${iVar} < ${arrVar}.length; ${iVar}++) {`);
1630
+ const prop = "prop" + counter++;
1631
+ src.push(`const ${prop} = ${arrVar}[${iVar}];`);
1632
+ addEvaluatedProperty(src, prop, trackingState);
1633
+ src.push(`if (${extra.before}${varName}[${prop}] === undefined) {${this.buildErrorReturn(pathContext, {
1634
+ keyword: "required",
1635
+ value: varName,
1636
+ message: `"Missing required field: " + ${prop} + " in data."`,
1637
+ expected: `${prop}`,
1638
+ schemaPath: `${pathContext.schema}`,
1639
+ })}${extra.after}}`);
1640
+ src.push(`}`);
1641
+ }
1642
+ else {
1643
+ for (const prop of schema.required) {
1644
+ const errorMessage = JSON.stringify(`Missing required field: ${prop} in data.`);
1645
+ const pstring = JSON.stringify(prop);
1646
+ src.push(`if (${extra.before}${varName}[${pstring}] === undefined) {${this.buildErrorReturn(pathContext, {
1647
+ keyword: "required",
1648
+ value: varName,
1649
+ message: errorMessage,
1650
+ expected: `${pstring}`,
1651
+ schemaPath: `${pathContext.schema}`,
1652
+ })}${extra.after}}`);
1653
+ }
1654
+ }
1595
1655
  if (extra.before != "")
1596
1656
  src.push(`}`);
1597
1657
  }
@@ -2261,9 +2321,7 @@
2261
2321
  var _a;
2262
2322
  if (this.notLogic)
2263
2323
  return "";
2264
- if (this.neutralError)
2265
- return "return false;";
2266
- let result = this.options.allErrors
2324
+ let result = this.options.allErrors || this.noreturn
2267
2325
  ? `${this.errorVariable}.push({`
2268
2326
  : `${this.mainFunctionName}.errors = [{`;
2269
2327
  const escapedDataPath = escapeTemplateString(error.dataPath || pathContext.data || "/");
@@ -2271,11 +2329,11 @@
2271
2329
  result += `dataPath: \`${escapedDataPath}\`,`;
2272
2330
  result += `schemaPath: \`${escapedSchemaPath}\`,`;
2273
2331
  result += `keyword: "${error.keyword}",`;
2332
+ if (error.expected) {
2333
+ result += `expected: ${error.expected},`;
2334
+ }
2274
2335
  if (this.options.verbose) {
2275
2336
  result += `value: ${error.value},`;
2276
- if (error.expected) {
2277
- result += `expected: ${error.expected},`;
2278
- }
2279
2337
  }
2280
2338
  let errorMessage;
2281
2339
  if (this.options.errorMessage && typeof this.schema !== "boolean") {
@@ -2344,7 +2402,7 @@
2344
2402
  result += `,${spreads}`;
2345
2403
  }
2346
2404
  result += "}";
2347
- if (this.options.allErrors) {
2405
+ if (this.options.allErrors || this.noreturn) {
2348
2406
  result += ");";
2349
2407
  }
2350
2408
  else {
@@ -5098,7 +5156,7 @@
5098
5156
  throw Error(`[${mode}] Unknown type ${type}`);
5099
5157
  }
5100
5158
  }
5101
- for (const keyword of allPossibleIncompatible) {
5159
+ for (const keyword of Array.from(allPossibleIncompatible)) {
5102
5160
  const incompatibleWithAll = types.every((type) => { var _a; return (_a = incompatibleKeywords[type]) === null || _a === void 0 ? void 0 : _a.includes(keyword); });
5103
5161
  if (incompatibleWithAll && schema[keyword] !== undefined) {
5104
5162
  throw Error(`[${mode}] Keyword "${keyword}" is incompatible with ${types.length > 1 ? "all types" : "type"} "${types.join(", ")}"`);
@@ -5666,6 +5724,7 @@
5666
5724
  const fconfig = {
5667
5725
  ...config,
5668
5726
  };
5727
+ const has$Data = compileContext.uses$Data;
5669
5728
  if (typeof resolvedSchema === "boolean")
5670
5729
  fconfig.allErrors = false;
5671
5730
  const compiler = new Compiler(refables, mainSchema, fconfig, this, allKeywords, compileContext, false);
@@ -5698,22 +5757,6 @@
5698
5757
  if (validate)
5699
5758
  customKeywords.set(keywordDef, validate);
5700
5759
  }
5701
- if (typeof resolvedSchema !== "boolean") {
5702
- if (allFormats.size > 0) {
5703
- for (const validatorKey of allFormats) {
5704
- const validator = this.formatValidators[validatorKey];
5705
- if (validator) {
5706
- if (typeof validator === "function" ||
5707
- validator instanceof RegExp) {
5708
- formatValidators[validatorKey] = validator;
5709
- }
5710
- else {
5711
- formatValidators[validatorKey] = validator.validate;
5712
- }
5713
- }
5714
- }
5715
- }
5716
- }
5717
5760
  const asyncPrefix = config.async ? "async " : "";
5718
5761
  let functionDeclaration = "validate(rootData";
5719
5762
  if (compileContext.hasRootReference) {
@@ -5746,6 +5789,40 @@
5746
5789
  regexArgs.push(new RegExp(key));
5747
5790
  }
5748
5791
  }
5792
+ if (typeof resolvedSchema !== "boolean") {
5793
+ if (has$Data) {
5794
+ const formatKeys = Array.isArray(fconfig.formats) && fconfig.formats.length > 0
5795
+ ? fconfig.formats
5796
+ : Object.keys(this.formatValidators);
5797
+ for (const validatorKey of formatKeys) {
5798
+ const validator = this.formatValidators[validatorKey];
5799
+ if (validator) {
5800
+ if (typeof validator === "function" ||
5801
+ validator instanceof RegExp) {
5802
+ formatValidators[validatorKey] = validator;
5803
+ }
5804
+ else {
5805
+ formatValidators[validatorKey] = validator.validate;
5806
+ }
5807
+ }
5808
+ }
5809
+ }
5810
+ else if (allFormats.size > 0) {
5811
+ for (const validatorKey of allFormats) {
5812
+ const validator = this.formatValidators[validatorKey];
5813
+ if (validator) {
5814
+ if (typeof validator === "function" ||
5815
+ validator instanceof RegExp) {
5816
+ formatValidators[validatorKey] = validator;
5817
+ }
5818
+ else {
5819
+ formatValidators[validatorKey] = validator.validate;
5820
+ }
5821
+ }
5822
+ }
5823
+ }
5824
+ }
5825
+ Object.values(formatValidators);
5749
5826
  return new Function("formatValidators", "deepEqual", "canonicalStringify", "customKeywords", "len_of", ...regexParams, finalSource)(formatValidators, deepEqual, canonicalStringify, customKeywords, len_of, ...regexArgs);
5750
5827
  }
5751
5828
  compile(fschema, config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetio/validator",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "The fastest JSON Schema validator for JavaScript and TypeScript. Supports Draft 06, 07, 2019-09, and 2020-12.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -50,7 +50,11 @@
50
50
  "draft-2020-12",
51
51
  "draft-2019-09",
52
52
  "draft-07",
53
- "draft-06"
53
+ "draft-06",
54
+ "JSON",
55
+ "jsonschema",
56
+ "json-schema-validator",
57
+ "json-schema-validation"
54
58
  ],
55
59
  "author": "Great Venerable",
56
60
  "license": "MIT",
@@ -60,6 +64,7 @@
60
64
  },
61
65
  "sideEffects": false,
62
66
  "devDependencies": {
67
+ "@rollup/plugin-node-resolve": "^16.0.3",
63
68
  "@rollup/plugin-terser": "^0.4.4",
64
69
  "@types/node": "^18.19.127",
65
70
  "@typescript-eslint/eslint-plugin": "^5.58.0",
@@ -71,6 +76,7 @@
71
76
  "rollup-plugin-filesize": "^7.0.0",
72
77
  "rollup-plugin-typescript2": "^0.36.0",
73
78
  "rollup-plugin-visualizer": "^5.14.0",
79
+ "terser": "^5.46.0",
74
80
  "ts-node": "^10.9.2",
75
81
  "typescript": "^5.8.3"
76
82
  },