zod 3.25.12-alpha.0 → 3.25.13

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 (191) hide show
  1. package/package.json +16 -17
  2. package/dist/types/index.d.ts +0 -3
  3. package/dist/types/index.js +0 -3
  4. package/dist/types/v3/ZodError.d.ts +0 -164
  5. package/dist/types/v3/ZodError.js +0 -132
  6. package/dist/types/v3/benchmarks/datetime.d.ts +0 -5
  7. package/dist/types/v3/benchmarks/datetime.js +0 -49
  8. package/dist/types/v3/benchmarks/discriminatedUnion.d.ts +0 -5
  9. package/dist/types/v3/benchmarks/discriminatedUnion.js +0 -74
  10. package/dist/types/v3/benchmarks/index.d.ts +0 -1
  11. package/dist/types/v3/benchmarks/index.js +0 -54
  12. package/dist/types/v3/benchmarks/ipv4.d.ts +0 -5
  13. package/dist/types/v3/benchmarks/ipv4.js +0 -49
  14. package/dist/types/v3/benchmarks/object.d.ts +0 -5
  15. package/dist/types/v3/benchmarks/object.js +0 -65
  16. package/dist/types/v3/benchmarks/primitives.d.ts +0 -5
  17. package/dist/types/v3/benchmarks/primitives.js +0 -154
  18. package/dist/types/v3/benchmarks/realworld.d.ts +0 -5
  19. package/dist/types/v3/benchmarks/realworld.js +0 -51
  20. package/dist/types/v3/benchmarks/string.d.ts +0 -5
  21. package/dist/types/v3/benchmarks/string.js +0 -50
  22. package/dist/types/v3/benchmarks/union.d.ts +0 -5
  23. package/dist/types/v3/benchmarks/union.js +0 -74
  24. package/dist/types/v3/errors.d.ts +0 -5
  25. package/dist/types/v3/errors.js +0 -9
  26. package/dist/types/v3/external.d.ts +0 -6
  27. package/dist/types/v3/external.js +0 -6
  28. package/dist/types/v3/helpers/enumUtil.d.ts +0 -8
  29. package/dist/types/v3/helpers/enumUtil.js +0 -1
  30. package/dist/types/v3/helpers/errorUtil.d.ts +0 -9
  31. package/dist/types/v3/helpers/errorUtil.js +0 -6
  32. package/dist/types/v3/helpers/parseUtil.d.ts +0 -78
  33. package/dist/types/v3/helpers/parseUtil.js +0 -109
  34. package/dist/types/v3/helpers/partialUtil.d.ts +0 -8
  35. package/dist/types/v3/helpers/partialUtil.js +0 -1
  36. package/dist/types/v3/helpers/typeAliases.d.ts +0 -2
  37. package/dist/types/v3/helpers/typeAliases.js +0 -1
  38. package/dist/types/v3/helpers/util.d.ts +0 -85
  39. package/dist/types/v3/helpers/util.js +0 -133
  40. package/dist/types/v3/index.d.ts +0 -4
  41. package/dist/types/v3/index.js +0 -4
  42. package/dist/types/v3/locales/en.d.ts +0 -3
  43. package/dist/types/v3/locales/en.js +0 -107
  44. package/dist/types/v3/standard-schema.d.ts +0 -102
  45. package/dist/types/v3/standard-schema.js +0 -1
  46. package/dist/types/v3/tests/Mocker.d.ts +0 -17
  47. package/dist/types/v3/tests/Mocker.js +0 -53
  48. package/dist/types/v3/tests/language-server.source.d.ts +0 -70
  49. package/dist/types/v3/tests/language-server.source.js +0 -45
  50. package/dist/types/v3/types.d.ts +0 -1031
  51. package/dist/types/v3/types.js +0 -3713
  52. package/dist/types/v4/classic/checks.d.ts +0 -1
  53. package/dist/types/v4/classic/checks.js +0 -1
  54. package/dist/types/v4/classic/coerce.d.ts +0 -17
  55. package/dist/types/v4/classic/coerce.js +0 -17
  56. package/dist/types/v4/classic/compat.d.ts +0 -48
  57. package/dist/types/v4/classic/compat.js +0 -33
  58. package/dist/types/v4/classic/errors.d.ts +0 -30
  59. package/dist/types/v4/classic/errors.js +0 -41
  60. package/dist/types/v4/classic/external.d.ts +0 -8
  61. package/dist/types/v4/classic/external.js +0 -11
  62. package/dist/types/v4/classic/index.d.ts +0 -4
  63. package/dist/types/v4/classic/index.js +0 -4
  64. package/dist/types/v4/classic/iso.d.ts +0 -22
  65. package/dist/types/v4/classic/iso.js +0 -30
  66. package/dist/types/v4/classic/parse.d.ts +0 -23
  67. package/dist/types/v4/classic/parse.js +0 -6
  68. package/dist/types/v4/classic/schemas.d.ts +0 -653
  69. package/dist/types/v4/classic/schemas.js +0 -1012
  70. package/dist/types/v4/core/api.d.ts +0 -273
  71. package/dist/types/v4/core/api.js +0 -867
  72. package/dist/types/v4/core/checks.d.ts +0 -277
  73. package/dist/types/v4/core/checks.js +0 -535
  74. package/dist/types/v4/core/config.d.ts +0 -9
  75. package/dist/types/v4/core/config.js +0 -6
  76. package/dist/types/v4/core/core.d.ts +0 -43
  77. package/dist/types/v4/core/core.js +0 -53
  78. package/dist/types/v4/core/doc.d.ts +0 -14
  79. package/dist/types/v4/core/doc.js +0 -36
  80. package/dist/types/v4/core/errors.d.ts +0 -204
  81. package/dist/types/v4/core/errors.js +0 -206
  82. package/dist/types/v4/core/function.d.ts +0 -35
  83. package/dist/types/v4/core/function.js +0 -70
  84. package/dist/types/v4/core/index.d.ts +0 -15
  85. package/dist/types/v4/core/index.js +0 -15
  86. package/dist/types/v4/core/json-schema.d.ts +0 -100
  87. package/dist/types/v4/core/json-schema.js +0 -1
  88. package/dist/types/v4/core/parse.d.ts +0 -25
  89. package/dist/types/v4/core/parse.js +0 -57
  90. package/dist/types/v4/core/regexes.d.ts +0 -62
  91. package/dist/types/v4/core/regexes.js +0 -93
  92. package/dist/types/v4/core/registries.d.ts +0 -32
  93. package/dist/types/v4/core/registries.js +0 -42
  94. package/dist/types/v4/core/schemas.d.ts +0 -975
  95. package/dist/types/v4/core/schemas.js +0 -1740
  96. package/dist/types/v4/core/standard-schema.d.ts +0 -55
  97. package/dist/types/v4/core/standard-schema.js +0 -1
  98. package/dist/types/v4/core/to-json-schema.d.ts +0 -84
  99. package/dist/types/v4/core/to-json-schema.js +0 -665
  100. package/dist/types/v4/core/util.d.ts +0 -186
  101. package/dist/types/v4/core/util.js +0 -469
  102. package/dist/types/v4/core/versions.d.ts +0 -5
  103. package/dist/types/v4/core/versions.js +0 -5
  104. package/dist/types/v4/core/zsf.d.ts +0 -91
  105. package/dist/types/v4/core/zsf.js +0 -171
  106. package/dist/types/v4/index.d.ts +0 -3
  107. package/dist/types/v4/index.js +0 -3
  108. package/dist/types/v4/locales/ar.d.ts +0 -7
  109. package/dist/types/v4/locales/ar.js +0 -115
  110. package/dist/types/v4/locales/az.d.ts +0 -7
  111. package/dist/types/v4/locales/az.js +0 -114
  112. package/dist/types/v4/locales/be.d.ts +0 -7
  113. package/dist/types/v4/locales/be.js +0 -163
  114. package/dist/types/v4/locales/ca.d.ts +0 -7
  115. package/dist/types/v4/locales/ca.js +0 -117
  116. package/dist/types/v4/locales/cs.d.ts +0 -7
  117. package/dist/types/v4/locales/cs.js +0 -134
  118. package/dist/types/v4/locales/de.d.ts +0 -7
  119. package/dist/types/v4/locales/de.js +0 -115
  120. package/dist/types/v4/locales/en.d.ts +0 -7
  121. package/dist/types/v4/locales/en.js +0 -117
  122. package/dist/types/v4/locales/es.d.ts +0 -7
  123. package/dist/types/v4/locales/es.js +0 -116
  124. package/dist/types/v4/locales/fa.d.ts +0 -7
  125. package/dist/types/v4/locales/fa.js +0 -121
  126. package/dist/types/v4/locales/fi.d.ts +0 -7
  127. package/dist/types/v4/locales/fi.js +0 -121
  128. package/dist/types/v4/locales/fr.d.ts +0 -7
  129. package/dist/types/v4/locales/fr.js +0 -115
  130. package/dist/types/v4/locales/frCA.d.ts +0 -7
  131. package/dist/types/v4/locales/frCA.js +0 -116
  132. package/dist/types/v4/locales/he.d.ts +0 -7
  133. package/dist/types/v4/locales/he.js +0 -116
  134. package/dist/types/v4/locales/hu.d.ts +0 -7
  135. package/dist/types/v4/locales/hu.js +0 -116
  136. package/dist/types/v4/locales/id.d.ts +0 -7
  137. package/dist/types/v4/locales/id.js +0 -115
  138. package/dist/types/v4/locales/index.d.ts +0 -34
  139. package/dist/types/v4/locales/index.js +0 -34
  140. package/dist/types/v4/locales/it.d.ts +0 -7
  141. package/dist/types/v4/locales/it.js +0 -116
  142. package/dist/types/v4/locales/ja.d.ts +0 -7
  143. package/dist/types/v4/locales/ja.js +0 -114
  144. package/dist/types/v4/locales/ko.d.ts +0 -7
  145. package/dist/types/v4/locales/ko.js +0 -120
  146. package/dist/types/v4/locales/mk.d.ts +0 -7
  147. package/dist/types/v4/locales/mk.js +0 -117
  148. package/dist/types/v4/locales/ms.d.ts +0 -7
  149. package/dist/types/v4/locales/ms.js +0 -115
  150. package/dist/types/v4/locales/no.d.ts +0 -7
  151. package/dist/types/v4/locales/no.js +0 -115
  152. package/dist/types/v4/locales/ota.d.ts +0 -7
  153. package/dist/types/v4/locales/ota.js +0 -116
  154. package/dist/types/v4/locales/pl.d.ts +0 -7
  155. package/dist/types/v4/locales/pl.js +0 -116
  156. package/dist/types/v4/locales/pt.d.ts +0 -7
  157. package/dist/types/v4/locales/pt.js +0 -115
  158. package/dist/types/v4/locales/ru.d.ts +0 -7
  159. package/dist/types/v4/locales/ru.js +0 -163
  160. package/dist/types/v4/locales/sl.d.ts +0 -7
  161. package/dist/types/v4/locales/sl.js +0 -116
  162. package/dist/types/v4/locales/ta.d.ts +0 -7
  163. package/dist/types/v4/locales/ta.js +0 -116
  164. package/dist/types/v4/locales/th.d.ts +0 -7
  165. package/dist/types/v4/locales/th.js +0 -116
  166. package/dist/types/v4/locales/tr.d.ts +0 -7
  167. package/dist/types/v4/locales/tr.js +0 -114
  168. package/dist/types/v4/locales/ua.d.ts +0 -7
  169. package/dist/types/v4/locales/ua.js +0 -116
  170. package/dist/types/v4/locales/ur.d.ts +0 -7
  171. package/dist/types/v4/locales/ur.js +0 -116
  172. package/dist/types/v4/locales/vi.d.ts +0 -7
  173. package/dist/types/v4/locales/vi.js +0 -115
  174. package/dist/types/v4/locales/zh-CN.d.ts +0 -7
  175. package/dist/types/v4/locales/zh-CN.js +0 -115
  176. package/dist/types/v4/locales/zh-tw.d.ts +0 -7
  177. package/dist/types/v4/locales/zh-tw.js +0 -116
  178. package/dist/types/v4/mini/checks.d.ts +0 -1
  179. package/dist/types/v4/mini/checks.js +0 -1
  180. package/dist/types/v4/mini/coerce.d.ts +0 -7
  181. package/dist/types/v4/mini/coerce.js +0 -17
  182. package/dist/types/v4/mini/external.d.ts +0 -7
  183. package/dist/types/v4/mini/external.js +0 -7
  184. package/dist/types/v4/mini/index.d.ts +0 -3
  185. package/dist/types/v4/mini/index.js +0 -3
  186. package/dist/types/v4/mini/iso.d.ts +0 -22
  187. package/dist/types/v4/mini/iso.js +0 -30
  188. package/dist/types/v4/mini/parse.d.ts +0 -1
  189. package/dist/types/v4/mini/parse.js +0 -1
  190. package/dist/types/v4/mini/schemas.d.ts +0 -405
  191. package/dist/types/v4/mini/schemas.js +0 -738
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,65 +0,0 @@
1
- import Benchmark from "benchmark";
2
- import { z } from "zod/v3";
3
- const emptySuite = new Benchmark.Suite("z.object: empty");
4
- const shortSuite = new Benchmark.Suite("z.object: short");
5
- const longSuite = new Benchmark.Suite("z.object: long");
6
- const empty = z.object({});
7
- const short = z.object({
8
- string: z.string(),
9
- });
10
- const long = z.object({
11
- string: z.string(),
12
- number: z.number(),
13
- boolean: z.boolean(),
14
- });
15
- emptySuite
16
- .add("valid", () => {
17
- empty.parse({});
18
- })
19
- .add("valid: extra keys", () => {
20
- empty.parse({ string: "string" });
21
- })
22
- .add("invalid: null", () => {
23
- try {
24
- empty.parse(null);
25
- }
26
- catch (_err) { }
27
- })
28
- .on("cycle", (e) => {
29
- console.log(`${emptySuite.name}: ${e.target}`);
30
- });
31
- shortSuite
32
- .add("valid", () => {
33
- short.parse({ string: "string" });
34
- })
35
- .add("valid: extra keys", () => {
36
- short.parse({ string: "string", number: 42 });
37
- })
38
- .add("invalid: null", () => {
39
- try {
40
- short.parse(null);
41
- }
42
- catch (_err) { }
43
- })
44
- .on("cycle", (e) => {
45
- console.log(`${shortSuite.name}: ${e.target}`);
46
- });
47
- longSuite
48
- .add("valid", () => {
49
- long.parse({ string: "string", number: 42, boolean: true });
50
- })
51
- .add("valid: extra keys", () => {
52
- long.parse({ string: "string", number: 42, boolean: true, list: [] });
53
- })
54
- .add("invalid: null", () => {
55
- try {
56
- long.parse(null);
57
- }
58
- catch (_err) { }
59
- })
60
- .on("cycle", (e) => {
61
- console.log(`${longSuite.name}: ${e.target}`);
62
- });
63
- export default {
64
- suites: [emptySuite, shortSuite, longSuite],
65
- };
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,154 +0,0 @@
1
- import Benchmark from "benchmark";
2
- import { z } from "zod/v3";
3
- import { Mocker } from "../tests/Mocker.js";
4
- const val = new Mocker();
5
- const enumSuite = new Benchmark.Suite("z.enum");
6
- const enumSchema = z.enum(["a", "b", "c"]);
7
- enumSuite
8
- .add("valid", () => {
9
- enumSchema.parse("a");
10
- })
11
- .add("invalid", () => {
12
- try {
13
- enumSchema.parse("x");
14
- }
15
- catch (_e) { }
16
- })
17
- .on("cycle", (e) => {
18
- console.log(`z.enum: ${e.target}`);
19
- });
20
- const longEnumSuite = new Benchmark.Suite("long z.enum");
21
- const longEnumSchema = z.enum([
22
- "one",
23
- "two",
24
- "three",
25
- "four",
26
- "five",
27
- "six",
28
- "seven",
29
- "eight",
30
- "nine",
31
- "ten",
32
- "eleven",
33
- "twelve",
34
- "thirteen",
35
- "fourteen",
36
- "fifteen",
37
- "sixteen",
38
- "seventeen",
39
- ]);
40
- longEnumSuite
41
- .add("valid", () => {
42
- longEnumSchema.parse("five");
43
- })
44
- .add("invalid", () => {
45
- try {
46
- longEnumSchema.parse("invalid");
47
- }
48
- catch (_e) { }
49
- })
50
- .on("cycle", (e) => {
51
- console.log(`long z.enum: ${e.target}`);
52
- });
53
- const undefinedSuite = new Benchmark.Suite("z.undefined");
54
- const undefinedSchema = z.undefined();
55
- undefinedSuite
56
- .add("valid", () => {
57
- undefinedSchema.parse(undefined);
58
- })
59
- .add("invalid", () => {
60
- try {
61
- undefinedSchema.parse(1);
62
- }
63
- catch (_e) { }
64
- })
65
- .on("cycle", (e) => {
66
- console.log(`z.undefined: ${e.target}`);
67
- });
68
- const literalSuite = new Benchmark.Suite("z.literal");
69
- const short = "short";
70
- const bad = "bad";
71
- const literalSchema = z.literal("short");
72
- literalSuite
73
- .add("valid", () => {
74
- literalSchema.parse(short);
75
- })
76
- .add("invalid", () => {
77
- try {
78
- literalSchema.parse(bad);
79
- }
80
- catch (_e) { }
81
- })
82
- .on("cycle", (e) => {
83
- console.log(`z.literal: ${e.target}`);
84
- });
85
- const numberSuite = new Benchmark.Suite("z.number");
86
- const numberSchema = z.number().int();
87
- numberSuite
88
- .add("valid", () => {
89
- numberSchema.parse(1);
90
- })
91
- .add("invalid type", () => {
92
- try {
93
- numberSchema.parse("bad");
94
- }
95
- catch (_e) { }
96
- })
97
- .add("invalid number", () => {
98
- try {
99
- numberSchema.parse(0.5);
100
- }
101
- catch (_e) { }
102
- })
103
- .on("cycle", (e) => {
104
- console.log(`z.number: ${e.target}`);
105
- });
106
- const dateSuite = new Benchmark.Suite("z.date");
107
- const plainDate = z.date();
108
- const minMaxDate = z.date().min(new Date("2021-01-01")).max(new Date("2030-01-01"));
109
- dateSuite
110
- .add("valid", () => {
111
- plainDate.parse(new Date());
112
- })
113
- .add("invalid", () => {
114
- try {
115
- plainDate.parse(1);
116
- }
117
- catch (_e) { }
118
- })
119
- .add("valid min and max", () => {
120
- minMaxDate.parse(new Date("2023-01-01"));
121
- })
122
- .add("invalid min", () => {
123
- try {
124
- minMaxDate.parse(new Date("2019-01-01"));
125
- }
126
- catch (_e) { }
127
- })
128
- .add("invalid max", () => {
129
- try {
130
- minMaxDate.parse(new Date("2031-01-01"));
131
- }
132
- catch (_e) { }
133
- })
134
- .on("cycle", (e) => {
135
- console.log(`z.date: ${e.target}`);
136
- });
137
- const symbolSuite = new Benchmark.Suite("z.symbol");
138
- const symbolSchema = z.symbol();
139
- symbolSuite
140
- .add("valid", () => {
141
- symbolSchema.parse(val.symbol);
142
- })
143
- .add("invalid", () => {
144
- try {
145
- symbolSchema.parse(1);
146
- }
147
- catch (_e) { }
148
- })
149
- .on("cycle", (e) => {
150
- console.log(`z.symbol: ${e.target}`);
151
- });
152
- export default {
153
- suites: [enumSuite, longEnumSuite, undefinedSuite, literalSuite, numberSuite, dateSuite, symbolSuite],
154
- };
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,51 +0,0 @@
1
- import Benchmark from "benchmark";
2
- import { z } from "zod/v3";
3
- const shortSuite = new Benchmark.Suite("realworld");
4
- const People = z.array(z.object({
5
- type: z.literal("person"),
6
- hair: z.enum(["blue", "brown"]),
7
- active: z.boolean(),
8
- name: z.string(),
9
- age: z.number().int(),
10
- hobbies: z.array(z.string()),
11
- address: z.object({
12
- street: z.string(),
13
- zip: z.string(),
14
- country: z.string(),
15
- }),
16
- }));
17
- let i = 0;
18
- function num() {
19
- return ++i;
20
- }
21
- function str() {
22
- return (++i % 100).toString(16);
23
- }
24
- function array(fn) {
25
- return Array.from({ length: ++i % 10 }, () => fn());
26
- }
27
- const people = Array.from({ length: 100 }, () => {
28
- return {
29
- type: "person",
30
- hair: i % 2 ? "blue" : "brown",
31
- active: !!(i % 2),
32
- name: str(),
33
- age: num(),
34
- hobbies: array(str),
35
- address: {
36
- street: str(),
37
- zip: str(),
38
- country: str(),
39
- },
40
- };
41
- });
42
- shortSuite
43
- .add("valid", () => {
44
- People.parse(people);
45
- })
46
- .on("cycle", (e) => {
47
- console.log(`${shortSuite.name}: ${e.target}`);
48
- });
49
- export default {
50
- suites: [shortSuite],
51
- };
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,50 +0,0 @@
1
- import Benchmark from "benchmark";
2
- import { z } from "zod/v3";
3
- const SUITE_NAME = "z.string";
4
- const suite = new Benchmark.Suite(SUITE_NAME);
5
- const empty = "";
6
- const short = "short";
7
- const long = "long".repeat(256);
8
- const manual = (str) => {
9
- if (typeof str !== "string") {
10
- throw new Error("Not a string");
11
- }
12
- return str;
13
- };
14
- const stringSchema = z.string();
15
- const optionalStringSchema = z.string().optional();
16
- const optionalNullableStringSchema = z.string().optional().nullable();
17
- suite
18
- .add("empty string", () => {
19
- stringSchema.parse(empty);
20
- })
21
- .add("short string", () => {
22
- stringSchema.parse(short);
23
- })
24
- .add("long string", () => {
25
- stringSchema.parse(long);
26
- })
27
- .add("optional string", () => {
28
- optionalStringSchema.parse(long);
29
- })
30
- .add("nullable string", () => {
31
- optionalNullableStringSchema.parse(long);
32
- })
33
- .add("nullable (null) string", () => {
34
- optionalNullableStringSchema.parse(null);
35
- })
36
- .add("invalid: null", () => {
37
- try {
38
- stringSchema.parse(null);
39
- }
40
- catch (_err) { }
41
- })
42
- .add("manual parser: long", () => {
43
- manual(long);
44
- })
45
- .on("cycle", (e) => {
46
- console.log(`${SUITE_NAME}: ${e.target}`);
47
- });
48
- export default {
49
- suites: [suite],
50
- };
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,74 +0,0 @@
1
- import Benchmark from "benchmark";
2
- import { z } from "zod/v3";
3
- const doubleSuite = new Benchmark.Suite("z.union: double");
4
- const manySuite = new Benchmark.Suite("z.union: many");
5
- const aSchema = z.object({
6
- type: z.literal("a"),
7
- });
8
- const objA = {
9
- type: "a",
10
- };
11
- const bSchema = z.object({
12
- type: z.literal("b"),
13
- });
14
- const objB = {
15
- type: "b",
16
- };
17
- const cSchema = z.object({
18
- type: z.literal("c"),
19
- });
20
- const objC = {
21
- type: "c",
22
- };
23
- const dSchema = z.object({
24
- type: z.literal("d"),
25
- });
26
- const double = z.union([aSchema, bSchema]);
27
- const many = z.union([aSchema, bSchema, cSchema, dSchema]);
28
- doubleSuite
29
- .add("valid: a", () => {
30
- double.parse(objA);
31
- })
32
- .add("valid: b", () => {
33
- double.parse(objB);
34
- })
35
- .add("invalid: null", () => {
36
- try {
37
- double.parse(null);
38
- }
39
- catch (_err) { }
40
- })
41
- .add("invalid: wrong shape", () => {
42
- try {
43
- double.parse(objC);
44
- }
45
- catch (_err) { }
46
- })
47
- .on("cycle", (e) => {
48
- console.log(`${doubleSuite.name}: ${e.target}`);
49
- });
50
- manySuite
51
- .add("valid: a", () => {
52
- many.parse(objA);
53
- })
54
- .add("valid: c", () => {
55
- many.parse(objC);
56
- })
57
- .add("invalid: null", () => {
58
- try {
59
- many.parse(null);
60
- }
61
- catch (_err) { }
62
- })
63
- .add("invalid: wrong shape", () => {
64
- try {
65
- many.parse({ type: "unknown" });
66
- }
67
- catch (_err) { }
68
- })
69
- .on("cycle", (e) => {
70
- console.log(`${manySuite.name}: ${e.target}`);
71
- });
72
- export default {
73
- suites: [doubleSuite, manySuite],
74
- };
@@ -1,5 +0,0 @@
1
- import type { ZodErrorMap } from "./ZodError.js";
2
- import defaultErrorMap from "./locales/en.js";
3
- export { defaultErrorMap };
4
- export declare function setErrorMap(map: ZodErrorMap): void;
5
- export declare function getErrorMap(): ZodErrorMap;
@@ -1,9 +0,0 @@
1
- import defaultErrorMap from "./locales/en.js";
2
- let overrideErrorMap = defaultErrorMap;
3
- export { defaultErrorMap };
4
- export function setErrorMap(map) {
5
- overrideErrorMap = map;
6
- }
7
- export function getErrorMap() {
8
- return overrideErrorMap;
9
- }
@@ -1,6 +0,0 @@
1
- export * from "./errors.js";
2
- export * from "./helpers/parseUtil.js";
3
- export * from "./helpers/typeAliases.js";
4
- export * from "./helpers/util.js";
5
- export * from "./types.js";
6
- export * from "./ZodError.js";
@@ -1,6 +0,0 @@
1
- export * from "./errors.js";
2
- export * from "./helpers/parseUtil.js";
3
- export * from "./helpers/typeAliases.js";
4
- export * from "./helpers/util.js";
5
- export * from "./types.js";
6
- export * from "./ZodError.js";
@@ -1,8 +0,0 @@
1
- export declare namespace enumUtil {
2
- type UnionToIntersectionFn<T> = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never;
3
- type GetUnionLast<T> = UnionToIntersectionFn<T> extends () => infer Last ? Last : never;
4
- type UnionToTuple<T, Tuple extends unknown[] = []> = [T] extends [never] ? Tuple : UnionToTuple<Exclude<T, GetUnionLast<T>>, [GetUnionLast<T>, ...Tuple]>;
5
- type CastToStringTuple<T> = T extends [string, ...string[]] ? T : never;
6
- export type UnionToTupleString<T> = CastToStringTuple<UnionToTuple<T>>;
7
- export {};
8
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- export declare namespace errorUtil {
2
- type ErrMessage = string | {
3
- message?: string | undefined;
4
- };
5
- const errToObj: (message?: ErrMessage) => {
6
- message?: string | undefined;
7
- };
8
- const toString: (message?: ErrMessage) => string | undefined;
9
- }
@@ -1,6 +0,0 @@
1
- export var errorUtil;
2
- (function (errorUtil) {
3
- errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
4
- // biome-ignore lint:
5
- errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
6
- })(errorUtil || (errorUtil = {}));
@@ -1,78 +0,0 @@
1
- import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.js";
2
- import type { ZodParsedType } from "./util.js";
3
- export declare const makeIssue: (params: {
4
- data: any;
5
- path: (string | number)[];
6
- errorMaps: ZodErrorMap[];
7
- issueData: IssueData;
8
- }) => ZodIssue;
9
- export type ParseParams = {
10
- path: (string | number)[];
11
- errorMap: ZodErrorMap;
12
- async: boolean;
13
- };
14
- export type ParsePathComponent = string | number;
15
- export type ParsePath = ParsePathComponent[];
16
- export declare const EMPTY_PATH: ParsePath;
17
- export interface ParseContext {
18
- readonly common: {
19
- readonly issues: ZodIssue[];
20
- readonly contextualErrorMap?: ZodErrorMap | undefined;
21
- readonly async: boolean;
22
- };
23
- readonly path: ParsePath;
24
- readonly schemaErrorMap?: ZodErrorMap | undefined;
25
- readonly parent: ParseContext | null;
26
- readonly data: any;
27
- readonly parsedType: ZodParsedType;
28
- }
29
- export type ParseInput = {
30
- data: any;
31
- path: (string | number)[];
32
- parent: ParseContext;
33
- };
34
- export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
35
- export type ObjectPair = {
36
- key: SyncParseReturnType<any>;
37
- value: SyncParseReturnType<any>;
38
- };
39
- export declare class ParseStatus {
40
- value: "aborted" | "dirty" | "valid";
41
- dirty(): void;
42
- abort(): void;
43
- static mergeArray(status: ParseStatus, results: SyncParseReturnType<any>[]): SyncParseReturnType;
44
- static mergeObjectAsync(status: ParseStatus, pairs: {
45
- key: ParseReturnType<any>;
46
- value: ParseReturnType<any>;
47
- }[]): Promise<SyncParseReturnType<any>>;
48
- static mergeObjectSync(status: ParseStatus, pairs: {
49
- key: SyncParseReturnType<any>;
50
- value: SyncParseReturnType<any>;
51
- alwaysSet?: boolean;
52
- }[]): SyncParseReturnType;
53
- }
54
- export interface ParseResult {
55
- status: "aborted" | "dirty" | "valid";
56
- data: any;
57
- }
58
- export type INVALID = {
59
- status: "aborted";
60
- };
61
- export declare const INVALID: INVALID;
62
- export type DIRTY<T> = {
63
- status: "dirty";
64
- value: T;
65
- };
66
- export declare const DIRTY: <T>(value: T) => DIRTY<T>;
67
- export type OK<T> = {
68
- status: "valid";
69
- value: T;
70
- };
71
- export declare const OK: <T>(value: T) => OK<T>;
72
- export type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
73
- export type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
74
- export type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
75
- export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
76
- export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
77
- export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T>;
78
- export declare const isAsync: <T>(x: ParseReturnType<T>) => x is AsyncParseReturnType<T>;
@@ -1,109 +0,0 @@
1
- import { getErrorMap } from "../errors.js";
2
- import defaultErrorMap from "../locales/en.js";
3
- export const makeIssue = (params) => {
4
- const { data, path, errorMaps, issueData } = params;
5
- const fullPath = [...path, ...(issueData.path || [])];
6
- const fullIssue = {
7
- ...issueData,
8
- path: fullPath,
9
- };
10
- if (issueData.message !== undefined) {
11
- return {
12
- ...issueData,
13
- path: fullPath,
14
- message: issueData.message,
15
- };
16
- }
17
- let errorMessage = "";
18
- const maps = errorMaps
19
- .filter((m) => !!m)
20
- .slice()
21
- .reverse();
22
- for (const map of maps) {
23
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
24
- }
25
- return {
26
- ...issueData,
27
- path: fullPath,
28
- message: errorMessage,
29
- };
30
- };
31
- export const EMPTY_PATH = [];
32
- export function addIssueToContext(ctx, issueData) {
33
- const overrideMap = getErrorMap();
34
- const issue = makeIssue({
35
- issueData: issueData,
36
- data: ctx.data,
37
- path: ctx.path,
38
- errorMaps: [
39
- ctx.common.contextualErrorMap, // contextual error map is first priority
40
- ctx.schemaErrorMap, // then schema-bound map if available
41
- overrideMap, // then global override map
42
- overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map
43
- ].filter((x) => !!x),
44
- });
45
- ctx.common.issues.push(issue);
46
- }
47
- export class ParseStatus {
48
- constructor() {
49
- this.value = "valid";
50
- }
51
- dirty() {
52
- if (this.value === "valid")
53
- this.value = "dirty";
54
- }
55
- abort() {
56
- if (this.value !== "aborted")
57
- this.value = "aborted";
58
- }
59
- static mergeArray(status, results) {
60
- const arrayValue = [];
61
- for (const s of results) {
62
- if (s.status === "aborted")
63
- return INVALID;
64
- if (s.status === "dirty")
65
- status.dirty();
66
- arrayValue.push(s.value);
67
- }
68
- return { status: status.value, value: arrayValue };
69
- }
70
- static async mergeObjectAsync(status, pairs) {
71
- const syncPairs = [];
72
- for (const pair of pairs) {
73
- const key = await pair.key;
74
- const value = await pair.value;
75
- syncPairs.push({
76
- key,
77
- value,
78
- });
79
- }
80
- return ParseStatus.mergeObjectSync(status, syncPairs);
81
- }
82
- static mergeObjectSync(status, pairs) {
83
- const finalObject = {};
84
- for (const pair of pairs) {
85
- const { key, value } = pair;
86
- if (key.status === "aborted")
87
- return INVALID;
88
- if (value.status === "aborted")
89
- return INVALID;
90
- if (key.status === "dirty")
91
- status.dirty();
92
- if (value.status === "dirty")
93
- status.dirty();
94
- if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
95
- finalObject[key.value] = value.value;
96
- }
97
- }
98
- return { status: status.value, value: finalObject };
99
- }
100
- }
101
- export const INVALID = Object.freeze({
102
- status: "aborted",
103
- });
104
- export const DIRTY = (value) => ({ status: "dirty", value });
105
- export const OK = (value) => ({ status: "valid", value });
106
- export const isAborted = (x) => x.status === "aborted";
107
- export const isDirty = (x) => x.status === "dirty";
108
- export const isValid = (x) => x.status === "valid";
109
- export const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;