z-schema 12.2.0 → 12.4.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.
Files changed (111) hide show
  1. package/README.md +2 -2
  2. package/bin/z-schema +1 -1
  3. package/cjs/{index.js → index.cjs} +838 -707
  4. package/cjs/{index.d.ts → index.d.cts} +47 -26
  5. package/dist/{errors.d.mts → errors.d.ts} +2 -2
  6. package/dist/{errors.mjs → errors.js} +1 -2
  7. package/dist/{format-validators.mjs → format-validators.js} +60 -43
  8. package/dist/{index.d.mts → index.d.ts} +9 -9
  9. package/dist/{index.mjs → index.js} +3 -3
  10. package/dist/{json-schema-versions.d.mts → json-schema-versions.d.ts} +34 -3
  11. package/dist/{json-schema.d.mts → json-schema.d.ts} +7 -7
  12. package/dist/{json-schema.mjs → json-schema.js} +6 -5
  13. package/dist/{json-validation.mjs → json-validation.js} +144 -127
  14. package/dist/{report.d.mts → report.d.ts} +8 -9
  15. package/dist/{report.mjs → report.js} +28 -31
  16. package/dist/{schema-cache.d.mts → schema-cache.d.ts} +5 -5
  17. package/dist/{schema-cache.mjs → schema-cache.js} +10 -11
  18. package/dist/{schema-compiler.d.mts → schema-compiler.d.ts} +4 -4
  19. package/dist/{schema-compiler.mjs → schema-compiler.js} +101 -79
  20. package/dist/{schema-validator.d.mts → schema-validator.d.ts} +5 -5
  21. package/dist/{schema-validator.mjs → schema-validator.js} +138 -166
  22. package/dist/utils/{array.mjs → array.js} +4 -3
  23. package/dist/utils/{base64.mjs → base64.js} +3 -2
  24. package/dist/utils/{clone.mjs → clone.js} +18 -20
  25. package/dist/utils/hostname.js +176 -0
  26. package/dist/utils/{json.mjs → json.js} +13 -8
  27. package/dist/utils/{schema-regex.mjs → schema-regex.js} +5 -5
  28. package/dist/utils/{time.mjs → time.js} +8 -8
  29. package/dist/utils/unicode.js +22 -0
  30. package/dist/utils/{what-is.mjs → what-is.js} +1 -2
  31. package/dist/validation/{array.mjs → array.js} +18 -20
  32. package/dist/validation/{combinators.mjs → combinators.js} +16 -16
  33. package/dist/validation/{numeric.mjs → numeric.js} +11 -11
  34. package/dist/validation/{object.mjs → object.js} +35 -34
  35. package/dist/validation/{ref.mjs → ref.js} +5 -5
  36. package/dist/validation/{shared.mjs → shared.js} +15 -12
  37. package/dist/validation/{string.mjs → string.js} +35 -35
  38. package/dist/validation/type.js +34 -0
  39. package/dist/{z-schema-base.d.mts → z-schema-base.d.ts} +11 -12
  40. package/dist/{z-schema-base.mjs → z-schema-base.js} +45 -40
  41. package/dist/{z-schema-options.d.mts → z-schema-options.d.ts} +3 -3
  42. package/dist/{z-schema-options.mjs → z-schema-options.js} +5 -5
  43. package/dist/{z-schema-reader.d.mts → z-schema-reader.d.ts} +1 -1
  44. package/dist/{z-schema-versions.mjs → z-schema-versions.js} +21 -21
  45. package/dist/{z-schema.d.mts → z-schema.d.ts} +5 -13
  46. package/dist/{z-schema.mjs → z-schema.js} +38 -48
  47. package/package.json +24 -25
  48. package/src/errors.ts +1 -2
  49. package/src/format-validators.ts +173 -67
  50. package/src/json-schema-versions.ts +56 -2
  51. package/src/json-schema.ts +10 -9
  52. package/src/json-validation.ts +189 -146
  53. package/src/report.ts +37 -49
  54. package/src/schema-cache.ts +13 -13
  55. package/src/schema-compiler.ts +170 -117
  56. package/src/schema-validator.ts +239 -238
  57. package/src/utils/array.ts +9 -6
  58. package/src/utils/base64.ts +13 -2
  59. package/src/utils/clone.ts +28 -30
  60. package/src/utils/date.ts +6 -3
  61. package/src/utils/hostname.ts +257 -31
  62. package/src/utils/json.ts +16 -9
  63. package/src/utils/properties.ts +2 -2
  64. package/src/utils/schema-regex.ts +4 -4
  65. package/src/utils/time.ts +8 -7
  66. package/src/utils/unicode.ts +12 -5
  67. package/src/utils/what-is.ts +1 -5
  68. package/src/validation/array.ts +24 -22
  69. package/src/validation/combinators.ts +14 -14
  70. package/src/validation/numeric.ts +14 -28
  71. package/src/validation/object.ts +32 -36
  72. package/src/validation/ref.ts +5 -6
  73. package/src/validation/shared.ts +22 -21
  74. package/src/validation/string.ts +36 -42
  75. package/src/validation/type.ts +17 -17
  76. package/src/z-schema-base.ts +49 -38
  77. package/src/z-schema-options.ts +4 -3
  78. package/src/z-schema.ts +35 -45
  79. package/umd/ZSchema.js +853 -715
  80. package/umd/ZSchema.min.js +2 -2
  81. package/umd/package.json +3 -0
  82. package/dist/utils/hostname.mjs +0 -75
  83. package/dist/utils/unicode.mjs +0 -12
  84. package/dist/validation/type.mjs +0 -32
  85. /package/dist/{format-validators.d.mts → format-validators.d.ts} +0 -0
  86. /package/dist/{json-schema-versions.mjs → json-schema-versions.js} +0 -0
  87. /package/dist/schemas/{draft-04-schema.mjs → draft-04-schema.js} +0 -0
  88. /package/dist/schemas/{draft-06-schema.mjs → draft-06-schema.js} +0 -0
  89. /package/dist/schemas/{draft-07-schema.mjs → draft-07-schema.js} +0 -0
  90. /package/dist/schemas/{draft-2019-09-meta-applicator.mjs → draft-2019-09-meta-applicator.js} +0 -0
  91. /package/dist/schemas/{draft-2019-09-meta-content.mjs → draft-2019-09-meta-content.js} +0 -0
  92. /package/dist/schemas/{draft-2019-09-meta-core.mjs → draft-2019-09-meta-core.js} +0 -0
  93. /package/dist/schemas/{draft-2019-09-meta-format.mjs → draft-2019-09-meta-format.js} +0 -0
  94. /package/dist/schemas/{draft-2019-09-meta-meta-data.mjs → draft-2019-09-meta-meta-data.js} +0 -0
  95. /package/dist/schemas/{draft-2019-09-meta-validation.mjs → draft-2019-09-meta-validation.js} +0 -0
  96. /package/dist/schemas/{draft-2019-09-schema.mjs → draft-2019-09-schema.js} +0 -0
  97. /package/dist/schemas/{draft-2020-12-meta-applicator.mjs → draft-2020-12-meta-applicator.js} +0 -0
  98. /package/dist/schemas/{draft-2020-12-meta-content.mjs → draft-2020-12-meta-content.js} +0 -0
  99. /package/dist/schemas/{draft-2020-12-meta-core.mjs → draft-2020-12-meta-core.js} +0 -0
  100. /package/dist/schemas/{draft-2020-12-meta-format-annotation.mjs → draft-2020-12-meta-format-annotation.js} +0 -0
  101. /package/dist/schemas/{draft-2020-12-meta-format-assertion.mjs → draft-2020-12-meta-format-assertion.js} +0 -0
  102. /package/dist/schemas/{draft-2020-12-meta-meta-data.mjs → draft-2020-12-meta-meta-data.js} +0 -0
  103. /package/dist/schemas/{draft-2020-12-meta-unevaluated.mjs → draft-2020-12-meta-unevaluated.js} +0 -0
  104. /package/dist/schemas/{draft-2020-12-meta-validation.mjs → draft-2020-12-meta-validation.js} +0 -0
  105. /package/dist/schemas/{draft-2020-12-schema.mjs → draft-2020-12-schema.js} +0 -0
  106. /package/dist/utils/{constants.mjs → constants.js} +0 -0
  107. /package/dist/utils/{date.mjs → date.js} +0 -0
  108. /package/dist/utils/{properties.mjs → properties.js} +0 -0
  109. /package/dist/utils/{symbols.mjs → symbols.js} +0 -0
  110. /package/dist/utils/{uri.mjs → uri.js} +0 -0
  111. /package/dist/{z-schema-reader.mjs → z-schema-reader.js} +0 -0
@@ -1,75 +0,0 @@
1
- import isIPModule from "validator/lib/isIP.js";
2
- import punycode from "punycode/punycode.js";
3
- //#region src/utils/hostname.ts
4
- const IDN_SEPARATOR_REGEX = /[\u3002\uff0e\uff61]/g;
5
- const IDN_SEPARATOR_TEST_REGEX = /[\u3002\uff0e\uff61]/;
6
- const splitHostnameLabels = (hostname) => {
7
- if (hostname.length === 0 || hostname.length > 255) return null;
8
- if (hostname.startsWith(".") || hostname.endsWith(".")) return null;
9
- const labels = hostname.split(".");
10
- if (labels.some((label) => label.length === 0 || label.length > 63)) return null;
11
- return labels;
12
- };
13
- const isAsciiHostnameLabel = (label) => /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(label);
14
- const isGreek = (char) => /\p{Script=Greek}/u.test(char);
15
- const isHebrew = (char) => /\p{Script=Hebrew}/u.test(char);
16
- const hasCjkKanaOrHan = (input) => /[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]/u.test(input);
17
- const toUnicodeLabel = (label) => {
18
- if (!/^xn--/i.test(label)) return label;
19
- try {
20
- return punycode.toUnicode(label.toLowerCase());
21
- } catch (_e) {
22
- return null;
23
- }
24
- };
25
- const isValidIdnUnicodeLabel = (label) => {
26
- if (label.startsWith("-") || label.endsWith("-")) return false;
27
- if (label.length >= 4 && label[2] === "-" && label[3] === "-" && !/^xn--/i.test(label)) return false;
28
- if (/^\p{M}/u.test(label)) return false;
29
- if (/[\u302e\u302f\u0640\u07fa]/u.test(label)) return false;
30
- for (let idx = 0; idx < label.length; idx++) {
31
- const char = label[idx];
32
- if (char === "·") {
33
- if (idx === 0 || idx === label.length - 1 || label[idx - 1] !== "l" || label[idx + 1] !== "l") return false;
34
- }
35
- if (char === "͵") {
36
- if (idx === label.length - 1 || !isGreek(label[idx + 1])) return false;
37
- }
38
- if (char === "׳" || char === "״") {
39
- if (idx === 0 || !isHebrew(label[idx - 1])) return false;
40
- }
41
- if (char === "‍") {
42
- if (idx === 0 || label[idx - 1] !== "्") return false;
43
- }
44
- }
45
- if (label.includes("・") && !hasCjkKanaOrHan(label.replace(/\u30fb/g, ""))) return false;
46
- const hasArabicIndic = /[\u0660-\u0669]/.test(label);
47
- const hasExtendedArabicIndic = /[\u06f0-\u06f9]/.test(label);
48
- if (hasArabicIndic && hasExtendedArabicIndic) return false;
49
- return true;
50
- };
51
- const isValidHostname = (hostname) => {
52
- if (IDN_SEPARATOR_TEST_REGEX.test(hostname) || /[^\x00-\x7F]/.test(hostname)) return false;
53
- if (isIPModule.default(hostname, 4)) return false;
54
- const labels = splitHostnameLabels(hostname);
55
- if (labels === null) return false;
56
- for (const label of labels) {
57
- if (!isAsciiHostnameLabel(label)) return false;
58
- if (/^xn--/i.test(label)) {
59
- const unicodeLabel = toUnicodeLabel(label);
60
- if (unicodeLabel === null || !isValidIdnUnicodeLabel(unicodeLabel)) return false;
61
- }
62
- }
63
- return true;
64
- };
65
- const isValidIdnHostname = (hostname) => {
66
- const labels = splitHostnameLabels(hostname.replace(IDN_SEPARATOR_REGEX, "."));
67
- if (labels === null) return false;
68
- for (const label of labels) {
69
- const unicodeLabel = toUnicodeLabel(label);
70
- if (unicodeLabel === null || !isValidIdnUnicodeLabel(unicodeLabel)) return false;
71
- }
72
- return true;
73
- };
74
- //#endregion
75
- export { isValidHostname, isValidIdnHostname };
@@ -1,12 +0,0 @@
1
- //#region src/utils/unicode.ts
2
- /**
3
- * Returns the number of Unicode code points in the string.
4
- * Uses the built-in string iterator which correctly handles surrogate pairs.
5
- */
6
- function unicodeLength(str) {
7
- let count = 0;
8
- for (const _cp of str) count++;
9
- return count;
10
- }
11
- //#endregion
12
- export { unicodeLength };
@@ -1,32 +0,0 @@
1
- import { whatIs } from "../utils/what-is.mjs";
2
- import { areEqual } from "../utils/json.mjs";
3
- import { shouldSkipValidate } from "./shared.mjs";
4
- //#region src/validation/type.ts
5
- function typeValidator(report, schema, json) {
6
- if (shouldSkipValidate(this.validateOptions, ["INVALID_TYPE"])) return;
7
- const jsonType = whatIs(json);
8
- if (typeof schema.type === "string") {
9
- if (jsonType !== schema.type && (jsonType !== "integer" || schema.type !== "number")) report.addError("INVALID_TYPE", [schema.type, jsonType], void 0, schema, "type");
10
- } else if (!schema.type.includes(jsonType) && (jsonType !== "integer" || !schema.type.includes("number"))) report.addError("INVALID_TYPE", [JSON.stringify(schema.type), jsonType], void 0, schema, "type");
11
- }
12
- function enumValidator(report, schema, json) {
13
- if (shouldSkipValidate(this.validateOptions, ["ENUM_CASE_MISMATCH", "ENUM_MISMATCH"])) return;
14
- let match = false, caseInsensitiveMatch = false;
15
- for (const enumVal of schema.enum) if (areEqual(json, enumVal, { maxDepth: this.options.maxRecursionDepth })) {
16
- match = true;
17
- break;
18
- } else if (areEqual(json, enumVal, {
19
- caseInsensitiveComparison: true,
20
- maxDepth: this.options.maxRecursionDepth
21
- })) caseInsensitiveMatch = true;
22
- if (match === false) {
23
- const error = caseInsensitiveMatch && this.options.enumCaseInsensitiveComparison ? "ENUM_CASE_MISMATCH" : "ENUM_MISMATCH";
24
- report.addError(error, [JSON.stringify(json)], void 0, schema, "enum");
25
- }
26
- }
27
- function constValidator(report, schema, json) {
28
- const constValue = schema.const;
29
- if (areEqual(json, constValue, { maxDepth: this.options.maxRecursionDepth }) === false) report.addError("CONST", [JSON.stringify(constValue)], void 0, schema, void 0);
30
- }
31
- //#endregion
32
- export { constValidator, enumValidator, typeValidator };
File without changes
File without changes
File without changes
File without changes
File without changes