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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.25.12-alpha.0",
3
+ "version": "3.25.13",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",
@@ -11,91 +11,91 @@
11
11
  "license": "MIT",
12
12
  "sideEffects": false,
13
13
  "main": "./dist/commonjs/index.js",
14
- "types": "./dist/types/index.d.ts",
14
+ "types": "./dist/esm/index.d.ts",
15
15
  "module": "./dist/esm/index.js",
16
16
  "exports": {
17
17
  "./package.json": "./package.json",
18
18
  ".": {
19
19
  "import": {
20
20
  "@zod/source": "./src/index.ts",
21
- "types": "./dist/types/index.d.ts",
21
+ "types": "./dist/esm/index.d.ts",
22
22
  "default": "./dist/esm/index.js"
23
23
  },
24
24
  "require": {
25
25
  "@zod/source": "./src/index.ts",
26
- "types": "./dist/types/index.d.ts",
26
+ "types": "./dist/esm/index.d.ts",
27
27
  "default": "./dist/commonjs/index.js"
28
28
  }
29
29
  },
30
30
  "./v3": {
31
31
  "import": {
32
32
  "@zod/source": "./src/v3/index.ts",
33
- "types": "./dist/types/v3/index.d.ts",
33
+ "types": "./dist/esm/v3/index.d.ts",
34
34
  "default": "./dist/esm/v3/index.js"
35
35
  },
36
36
  "require": {
37
37
  "@zod/source": "./src/v3/index.ts",
38
- "types": "./dist/types/v3/index.d.ts",
38
+ "types": "./dist/esm/v3/index.d.ts",
39
39
  "default": "./dist/commonjs/v3/index.js"
40
40
  }
41
41
  },
42
42
  "./v4": {
43
43
  "import": {
44
44
  "@zod/source": "./src/v4/index.ts",
45
- "types": "./dist/types/v4/index.d.ts",
45
+ "types": "./dist/esm/v4/index.d.ts",
46
46
  "default": "./dist/esm/v4/index.js"
47
47
  },
48
48
  "require": {
49
49
  "@zod/source": "./src/v4/index.ts",
50
- "types": "./dist/types/v4/index.d.ts",
50
+ "types": "./dist/esm/v4/index.d.ts",
51
51
  "default": "./dist/commonjs/v4/index.js"
52
52
  }
53
53
  },
54
54
  "./v4-mini": {
55
55
  "import": {
56
56
  "@zod/source": "./src/v4/mini/index.ts",
57
- "types": "./dist/types/v4/mini/index.d.ts",
57
+ "types": "./dist/esm/v4/mini/index.d.ts",
58
58
  "default": "./dist/esm/v4/mini/index.js"
59
59
  },
60
60
  "require": {
61
61
  "@zod/source": "./src/v4/mini/index.ts",
62
- "types": "./dist/types/v4/mini/index.d.ts",
62
+ "types": "./dist/esm/v4/mini/index.d.ts",
63
63
  "default": "./dist/commonjs/v4/mini/index.js"
64
64
  }
65
65
  },
66
66
  "./v4/core": {
67
67
  "import": {
68
68
  "@zod/source": "./src/v4/core/index.ts",
69
- "types": "./dist/types/v4/core/index.d.ts",
69
+ "types": "./dist/esm/v4/core/index.d.ts",
70
70
  "default": "./dist/esm/v4/core/index.js"
71
71
  },
72
72
  "require": {
73
73
  "@zod/source": "./src/v4/core/index.ts",
74
- "types": "./dist/types/v4/core/index.d.ts",
74
+ "types": "./dist/esm/v4/core/index.d.ts",
75
75
  "default": "./dist/commonjs/v4/core/index.js"
76
76
  }
77
77
  },
78
78
  "./v4/locales": {
79
79
  "import": {
80
80
  "@zod/source": "./src/v4/locales/index.ts",
81
- "types": "./dist/types/v4/locales/index.d.ts",
81
+ "types": "./dist/esm/v4/locales/index.d.ts",
82
82
  "default": "./dist/esm/v4/locales/index.js"
83
83
  },
84
84
  "require": {
85
85
  "@zod/source": "./src/v4/locales/index.ts",
86
- "types": "./dist/types/v4/locales/index.d.ts",
86
+ "types": "./dist/esm/v4/locales/index.d.ts",
87
87
  "default": "./dist/commonjs/v4/locales/index.js"
88
88
  }
89
89
  },
90
90
  "./v4/locales/*": {
91
91
  "import": {
92
92
  "@zod/source": "./src/v4/locales/*",
93
- "types": "./dist/types/v4/locales/*",
93
+ "types": "./dist/esm/v4/locales/*",
94
94
  "default": "./dist/esm/v4/locales/*"
95
95
  },
96
96
  "require": {
97
97
  "@zod/source": "./src/v4/locales/*",
98
- "types": "./dist/types/v4/locales/*",
98
+ "types": "./dist/esm/v4/locales/*",
99
99
  "default": "./dist/commonjs/v4/locales/*"
100
100
  }
101
101
  }
@@ -111,7 +111,6 @@
111
111
  "./v4/locales": "./src/v4/locales/index.ts",
112
112
  "./v4/locales/*": "./src/v4/locales/*"
113
113
  },
114
- "cjsDialects": ["types"],
115
114
  "sourceDialects": ["@zod/source"],
116
115
  "exclude": ["./src/**/*.test.ts"]
117
116
  },
@@ -1,3 +0,0 @@
1
- import z3 from "./v3/index.js";
2
- export * from "./v3/index.js";
3
- export default z3;
@@ -1,3 +0,0 @@
1
- import z3 from "./v3/index.js";
2
- export * from "./v3/index.js";
3
- export default z3;
@@ -1,164 +0,0 @@
1
- import type { Primitive } from "./helpers/typeAliases.js";
2
- import { util, type ZodParsedType } from "./helpers/util.js";
3
- import type { TypeOf, ZodType } from "./index.js";
4
- type allKeys<T> = T extends any ? keyof T : never;
5
- export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
6
- export type typeToFlattenedError<T, U = string> = {
7
- formErrors: U[];
8
- fieldErrors: {
9
- [P in allKeys<T>]?: U[];
10
- };
11
- };
12
- export declare const ZodIssueCode: {
13
- invalid_type: "invalid_type";
14
- invalid_literal: "invalid_literal";
15
- custom: "custom";
16
- invalid_union: "invalid_union";
17
- invalid_union_discriminator: "invalid_union_discriminator";
18
- invalid_enum_value: "invalid_enum_value";
19
- unrecognized_keys: "unrecognized_keys";
20
- invalid_arguments: "invalid_arguments";
21
- invalid_return_type: "invalid_return_type";
22
- invalid_date: "invalid_date";
23
- invalid_string: "invalid_string";
24
- too_small: "too_small";
25
- too_big: "too_big";
26
- invalid_intersection_types: "invalid_intersection_types";
27
- not_multiple_of: "not_multiple_of";
28
- not_finite: "not_finite";
29
- };
30
- export type ZodIssueCode = keyof typeof ZodIssueCode;
31
- export type ZodIssueBase = {
32
- path: (string | number)[];
33
- message?: string | undefined;
34
- };
35
- export interface ZodInvalidTypeIssue extends ZodIssueBase {
36
- code: typeof ZodIssueCode.invalid_type;
37
- expected: ZodParsedType;
38
- received: ZodParsedType;
39
- }
40
- export interface ZodInvalidLiteralIssue extends ZodIssueBase {
41
- code: typeof ZodIssueCode.invalid_literal;
42
- expected: unknown;
43
- received: unknown;
44
- }
45
- export interface ZodUnrecognizedKeysIssue extends ZodIssueBase {
46
- code: typeof ZodIssueCode.unrecognized_keys;
47
- keys: string[];
48
- }
49
- export interface ZodInvalidUnionIssue extends ZodIssueBase {
50
- code: typeof ZodIssueCode.invalid_union;
51
- unionErrors: ZodError[];
52
- }
53
- export interface ZodInvalidUnionDiscriminatorIssue extends ZodIssueBase {
54
- code: typeof ZodIssueCode.invalid_union_discriminator;
55
- options: Primitive[];
56
- }
57
- export interface ZodInvalidEnumValueIssue extends ZodIssueBase {
58
- received: string | number;
59
- code: typeof ZodIssueCode.invalid_enum_value;
60
- options: (string | number)[];
61
- }
62
- export interface ZodInvalidArgumentsIssue extends ZodIssueBase {
63
- code: typeof ZodIssueCode.invalid_arguments;
64
- argumentsError: ZodError;
65
- }
66
- export interface ZodInvalidReturnTypeIssue extends ZodIssueBase {
67
- code: typeof ZodIssueCode.invalid_return_type;
68
- returnTypeError: ZodError;
69
- }
70
- export interface ZodInvalidDateIssue extends ZodIssueBase {
71
- code: typeof ZodIssueCode.invalid_date;
72
- }
73
- export type StringValidation = "email" | "url" | "emoji" | "uuid" | "nanoid" | "regex" | "cuid" | "cuid2" | "ulid" | "datetime" | "date" | "time" | "duration" | "ip" | "cidr" | "base64" | "jwt" | "base64url" | {
74
- includes: string;
75
- position?: number | undefined;
76
- } | {
77
- startsWith: string;
78
- } | {
79
- endsWith: string;
80
- };
81
- export interface ZodInvalidStringIssue extends ZodIssueBase {
82
- code: typeof ZodIssueCode.invalid_string;
83
- validation: StringValidation;
84
- }
85
- export interface ZodTooSmallIssue extends ZodIssueBase {
86
- code: typeof ZodIssueCode.too_small;
87
- minimum: number | bigint;
88
- inclusive: boolean;
89
- exact?: boolean;
90
- type: "array" | "string" | "number" | "set" | "date" | "bigint";
91
- }
92
- export interface ZodTooBigIssue extends ZodIssueBase {
93
- code: typeof ZodIssueCode.too_big;
94
- maximum: number | bigint;
95
- inclusive: boolean;
96
- exact?: boolean;
97
- type: "array" | "string" | "number" | "set" | "date" | "bigint";
98
- }
99
- export interface ZodInvalidIntersectionTypesIssue extends ZodIssueBase {
100
- code: typeof ZodIssueCode.invalid_intersection_types;
101
- }
102
- export interface ZodNotMultipleOfIssue extends ZodIssueBase {
103
- code: typeof ZodIssueCode.not_multiple_of;
104
- multipleOf: number | bigint;
105
- }
106
- export interface ZodNotFiniteIssue extends ZodIssueBase {
107
- code: typeof ZodIssueCode.not_finite;
108
- }
109
- export interface ZodCustomIssue extends ZodIssueBase {
110
- code: typeof ZodIssueCode.custom;
111
- params?: {
112
- [k: string]: any;
113
- };
114
- }
115
- export type DenormalizedError = {
116
- [k: string]: DenormalizedError | string[];
117
- };
118
- export type ZodIssueOptionalMessage = ZodInvalidTypeIssue | ZodInvalidLiteralIssue | ZodUnrecognizedKeysIssue | ZodInvalidUnionIssue | ZodInvalidUnionDiscriminatorIssue | ZodInvalidEnumValueIssue | ZodInvalidArgumentsIssue | ZodInvalidReturnTypeIssue | ZodInvalidDateIssue | ZodInvalidStringIssue | ZodTooSmallIssue | ZodTooBigIssue | ZodInvalidIntersectionTypesIssue | ZodNotMultipleOfIssue | ZodNotFiniteIssue | ZodCustomIssue;
119
- export type ZodIssue = ZodIssueOptionalMessage & {
120
- fatal?: boolean | undefined;
121
- message: string;
122
- };
123
- export declare const quotelessJson: (obj: any) => string;
124
- type recursiveZodFormattedError<T> = T extends [any, ...any[]] ? {
125
- [K in keyof T]?: ZodFormattedError<T[K]>;
126
- } : T extends any[] ? {
127
- [k: number]: ZodFormattedError<T[number]>;
128
- } : T extends object ? {
129
- [K in keyof T]?: ZodFormattedError<T[K]>;
130
- } : unknown;
131
- export type ZodFormattedError<T, U = string> = {
132
- _errors: U[];
133
- } & recursiveZodFormattedError<NonNullable<T>>;
134
- export type inferFormattedError<T extends ZodType<any, any, any>, U = string> = ZodFormattedError<TypeOf<T>, U>;
135
- export declare class ZodError<T = any> extends Error {
136
- issues: ZodIssue[];
137
- get errors(): ZodIssue[];
138
- constructor(issues: ZodIssue[]);
139
- format(): ZodFormattedError<T>;
140
- format<U>(mapper: (issue: ZodIssue) => U): ZodFormattedError<T, U>;
141
- static create: (issues: ZodIssue[]) => ZodError<any>;
142
- static assert(value: unknown): asserts value is ZodError;
143
- toString(): string;
144
- get message(): string;
145
- get isEmpty(): boolean;
146
- addIssue: (sub: ZodIssue) => void;
147
- addIssues: (subs?: ZodIssue[]) => void;
148
- flatten(): typeToFlattenedError<T>;
149
- flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
150
- get formErrors(): typeToFlattenedError<T, string>;
151
- }
152
- type stripPath<T extends object> = T extends any ? util.OmitKeys<T, "path"> : never;
153
- export type IssueData = stripPath<ZodIssueOptionalMessage> & {
154
- path?: (string | number)[];
155
- fatal?: boolean | undefined;
156
- };
157
- export type ErrorMapCtx = {
158
- defaultError: string;
159
- data: any;
160
- };
161
- export type ZodErrorMap = (issue: ZodIssueOptionalMessage, _ctx: ErrorMapCtx) => {
162
- message: string;
163
- };
164
- export {};
@@ -1,132 +0,0 @@
1
- import { util } from "./helpers/util.js";
2
- export const ZodIssueCode = util.arrayToEnum([
3
- "invalid_type",
4
- "invalid_literal",
5
- "custom",
6
- "invalid_union",
7
- "invalid_union_discriminator",
8
- "invalid_enum_value",
9
- "unrecognized_keys",
10
- "invalid_arguments",
11
- "invalid_return_type",
12
- "invalid_date",
13
- "invalid_string",
14
- "too_small",
15
- "too_big",
16
- "invalid_intersection_types",
17
- "not_multiple_of",
18
- "not_finite",
19
- ]);
20
- export const quotelessJson = (obj) => {
21
- const json = JSON.stringify(obj, null, 2);
22
- return json.replace(/"([^"]+)":/g, "$1:");
23
- };
24
- export class ZodError extends Error {
25
- get errors() {
26
- return this.issues;
27
- }
28
- constructor(issues) {
29
- super();
30
- this.issues = [];
31
- this.addIssue = (sub) => {
32
- this.issues = [...this.issues, sub];
33
- };
34
- this.addIssues = (subs = []) => {
35
- this.issues = [...this.issues, ...subs];
36
- };
37
- const actualProto = new.target.prototype;
38
- if (Object.setPrototypeOf) {
39
- // eslint-disable-next-line ban/ban
40
- Object.setPrototypeOf(this, actualProto);
41
- }
42
- else {
43
- this.__proto__ = actualProto;
44
- }
45
- this.name = "ZodError";
46
- this.issues = issues;
47
- }
48
- format(_mapper) {
49
- const mapper = _mapper ||
50
- function (issue) {
51
- return issue.message;
52
- };
53
- const fieldErrors = { _errors: [] };
54
- const processError = (error) => {
55
- for (const issue of error.issues) {
56
- if (issue.code === "invalid_union") {
57
- issue.unionErrors.map(processError);
58
- }
59
- else if (issue.code === "invalid_return_type") {
60
- processError(issue.returnTypeError);
61
- }
62
- else if (issue.code === "invalid_arguments") {
63
- processError(issue.argumentsError);
64
- }
65
- else if (issue.path.length === 0) {
66
- fieldErrors._errors.push(mapper(issue));
67
- }
68
- else {
69
- let curr = fieldErrors;
70
- let i = 0;
71
- while (i < issue.path.length) {
72
- const el = issue.path[i];
73
- const terminal = i === issue.path.length - 1;
74
- if (!terminal) {
75
- curr[el] = curr[el] || { _errors: [] };
76
- // if (typeof el === "string") {
77
- // curr[el] = curr[el] || { _errors: [] };
78
- // } else if (typeof el === "number") {
79
- // const errorArray: any = [];
80
- // errorArray._errors = [];
81
- // curr[el] = curr[el] || errorArray;
82
- // }
83
- }
84
- else {
85
- curr[el] = curr[el] || { _errors: [] };
86
- curr[el]._errors.push(mapper(issue));
87
- }
88
- curr = curr[el];
89
- i++;
90
- }
91
- }
92
- }
93
- };
94
- processError(this);
95
- return fieldErrors;
96
- }
97
- static assert(value) {
98
- if (!(value instanceof ZodError)) {
99
- throw new Error(`Not a ZodError: ${value}`);
100
- }
101
- }
102
- toString() {
103
- return this.message;
104
- }
105
- get message() {
106
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
107
- }
108
- get isEmpty() {
109
- return this.issues.length === 0;
110
- }
111
- flatten(mapper = (issue) => issue.message) {
112
- const fieldErrors = {};
113
- const formErrors = [];
114
- for (const sub of this.issues) {
115
- if (sub.path.length > 0) {
116
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
117
- fieldErrors[sub.path[0]].push(mapper(sub));
118
- }
119
- else {
120
- formErrors.push(mapper(sub));
121
- }
122
- }
123
- return { formErrors, fieldErrors };
124
- }
125
- get formErrors() {
126
- return this.flatten();
127
- }
128
- }
129
- ZodError.create = (issues) => {
130
- const error = new ZodError(issues);
131
- return error;
132
- };
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,49 +0,0 @@
1
- import Benchmark from "benchmark";
2
- const datetimeValidationSuite = new Benchmark.Suite("datetime");
3
- const DATA = "2021-01-01";
4
- const MONTHS_31 = new Set([1, 3, 5, 7, 8, 10, 12]);
5
- const MONTHS_30 = new Set([4, 6, 9, 11]);
6
- const simpleDatetimeRegex = /^(\d{4})-(\d{2})-(\d{2})$/;
7
- const datetimeRegexNoLeapYearValidation = /^\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\d|2\d))$/;
8
- const datetimeRegexWithLeapYearValidation = /^((\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\d|3[01])|(0[469]|11)-(0[1-9]|[12]\d|30)|(02)-(0[1-9]|1\d|2[0-8])))$/;
9
- datetimeValidationSuite
10
- .add("new Date()", () => {
11
- return !Number.isNaN(new Date(DATA).getTime());
12
- })
13
- .add("regex (no validation)", () => {
14
- return simpleDatetimeRegex.test(DATA);
15
- })
16
- .add("regex (no leap year)", () => {
17
- return datetimeRegexNoLeapYearValidation.test(DATA);
18
- })
19
- .add("regex (w/ leap year)", () => {
20
- return datetimeRegexWithLeapYearValidation.test(DATA);
21
- })
22
- .add("capture groups + code", () => {
23
- const match = DATA.match(simpleDatetimeRegex);
24
- if (!match)
25
- return false;
26
- // Extract year, month, and day from the capture groups
27
- const year = Number.parseInt(match[1], 10);
28
- const month = Number.parseInt(match[2], 10); // month is 0-indexed in JavaScript Date, so subtract 1
29
- const day = Number.parseInt(match[3], 10);
30
- if (month === 2) {
31
- if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
32
- return day <= 29;
33
- }
34
- return day <= 28;
35
- }
36
- if (MONTHS_30.has(month)) {
37
- return day <= 30;
38
- }
39
- if (MONTHS_31.has(month)) {
40
- return day <= 31;
41
- }
42
- return false;
43
- })
44
- .on("cycle", (e) => {
45
- console.log(`${datetimeValidationSuite.name}: ${e.target}`);
46
- });
47
- export default {
48
- suites: [datetimeValidationSuite],
49
- };
@@ -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.discriminatedUnion: double");
4
- const manySuite = new Benchmark.Suite("z.discriminatedUnion: 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.discriminatedUnion("type", [aSchema, bSchema]);
27
- const many = z.discriminatedUnion("type", [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 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- import datetimeBenchmarks from "./datetime.js";
2
- import discriminatedUnionBenchmarks from "./discriminatedUnion.js";
3
- import ipv4Benchmarks from "./ipv4.js";
4
- import objectBenchmarks from "./object.js";
5
- import primitiveBenchmarks from "./primitives.js";
6
- import realworld from "./realworld.js";
7
- import stringBenchmarks from "./string.js";
8
- import unionBenchmarks from "./union.js";
9
- const argv = process.argv.slice(2);
10
- let suites = [];
11
- if (!argv.length) {
12
- suites = [
13
- ...realworld.suites,
14
- ...primitiveBenchmarks.suites,
15
- ...stringBenchmarks.suites,
16
- ...objectBenchmarks.suites,
17
- ...unionBenchmarks.suites,
18
- ...discriminatedUnionBenchmarks.suites,
19
- ];
20
- }
21
- else {
22
- if (argv.includes("--realworld")) {
23
- suites.push(...realworld.suites);
24
- }
25
- if (argv.includes("--primitives")) {
26
- suites.push(...primitiveBenchmarks.suites);
27
- }
28
- if (argv.includes("--string")) {
29
- suites.push(...stringBenchmarks.suites);
30
- }
31
- if (argv.includes("--object")) {
32
- suites.push(...objectBenchmarks.suites);
33
- }
34
- if (argv.includes("--union")) {
35
- suites.push(...unionBenchmarks.suites);
36
- }
37
- if (argv.includes("--discriminatedUnion")) {
38
- suites.push(...datetimeBenchmarks.suites);
39
- }
40
- if (argv.includes("--datetime")) {
41
- suites.push(...datetimeBenchmarks.suites);
42
- }
43
- if (argv.includes("--ipv4")) {
44
- suites.push(...ipv4Benchmarks.suites);
45
- }
46
- }
47
- for (const suite of suites) {
48
- suite.run({});
49
- }
50
- // exit on Ctrl-C
51
- process.on("SIGINT", function () {
52
- console.log("Exiting...");
53
- process.exit();
54
- });
@@ -1,5 +0,0 @@
1
- import Benchmark from "benchmark";
2
- declare const _default: {
3
- suites: Benchmark.Suite[];
4
- };
5
- export default _default;
@@ -1,49 +0,0 @@
1
- import Benchmark from "benchmark";
2
- const suite = new Benchmark.Suite("ipv4");
3
- const DATA = "127.0.0.1";
4
- const ipv4RegexA = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
5
- const ipv4RegexB = /^(?:(?:(?=(25[0-5]))\1|(?=(2[0-4][0-9]))\2|(?=(1[0-9]{2}))\3|(?=([0-9]{1,2}))\4)\.){3}(?:(?=(25[0-5]))\5|(?=(2[0-4][0-9]))\6|(?=(1[0-9]{2}))\7|(?=([0-9]{1,2}))\8)$/;
6
- const ipv4RegexC = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
7
- const ipv4RegexD = /^(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/;
8
- const ipv4RegexE = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]|)\d)$/;
9
- const ipv4RegexF = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
10
- const ipv4RegexG = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$/;
11
- const ipv4RegexH = /^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$/;
12
- const ipv4RegexI = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
13
- suite
14
- .add("A", () => {
15
- return ipv4RegexA.test(DATA);
16
- })
17
- .add("B", () => {
18
- return ipv4RegexB.test(DATA);
19
- })
20
- .add("C", () => {
21
- return ipv4RegexC.test(DATA);
22
- })
23
- .add("D", () => {
24
- return ipv4RegexD.test(DATA);
25
- })
26
- .add("E", () => {
27
- return ipv4RegexE.test(DATA);
28
- })
29
- .add("F", () => {
30
- return ipv4RegexF.test(DATA);
31
- })
32
- .add("G", () => {
33
- return ipv4RegexG.test(DATA);
34
- })
35
- .add("H", () => {
36
- return ipv4RegexH.test(DATA);
37
- })
38
- .add("I", () => {
39
- return ipv4RegexI.test(DATA);
40
- })
41
- .on("cycle", (e) => {
42
- console.log(`${suite.name}: ${e.target}`);
43
- });
44
- export default {
45
- suites: [suite],
46
- };
47
- if (require.main === module) {
48
- suite.run();
49
- }