oidc-spa 8.1.10 → 8.1.12

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 (186) hide show
  1. package/backend.d.ts +27 -6
  2. package/backend.js +124 -139
  3. package/backend.js.map +1 -1
  4. package/core/Oidc.d.ts +28 -4
  5. package/core/createOidc.d.ts +12 -3
  6. package/core/createOidc.js +1 -1
  7. package/core/createOidc.js.map +1 -1
  8. package/core/earlyInit.d.ts +1 -0
  9. package/core/earlyInit.js +11 -4
  10. package/core/earlyInit.js.map +1 -1
  11. package/core/loginOrGoToAuthServer.js +8 -3
  12. package/core/loginOrGoToAuthServer.js.map +1 -1
  13. package/core/oidcClientTsUserToTokens.d.ts +1 -1
  14. package/core/oidcClientTsUserToTokens.js.map +1 -1
  15. package/core/requiredPostHydrationReplaceNavigationUrl.d.ts +6 -0
  16. package/core/requiredPostHydrationReplaceNavigationUrl.js +12 -0
  17. package/core/requiredPostHydrationReplaceNavigationUrl.js.map +1 -0
  18. package/entrypoint.d.ts +1 -0
  19. package/entrypoint.js +3 -1
  20. package/entrypoint.js.map +1 -1
  21. package/esm/angular.d.ts +14 -4
  22. package/esm/angular.js +155 -10
  23. package/esm/angular.js.map +1 -1
  24. package/esm/backend.d.ts +48 -0
  25. package/esm/backend.js +259 -0
  26. package/esm/backend.js.map +1 -0
  27. package/esm/core/Oidc.d.ts +28 -4
  28. package/esm/core/createOidc.d.ts +12 -3
  29. package/esm/core/createOidc.js +1 -1
  30. package/esm/core/createOidc.js.map +1 -1
  31. package/esm/core/earlyInit.d.ts +1 -0
  32. package/esm/core/earlyInit.js +11 -4
  33. package/esm/core/earlyInit.js.map +1 -1
  34. package/esm/core/loginOrGoToAuthServer.js +8 -3
  35. package/esm/core/loginOrGoToAuthServer.js.map +1 -1
  36. package/esm/core/oidcClientTsUserToTokens.d.ts +1 -1
  37. package/esm/core/oidcClientTsUserToTokens.js.map +1 -1
  38. package/esm/core/requiredPostHydrationReplaceNavigationUrl.d.ts +6 -0
  39. package/esm/core/requiredPostHydrationReplaceNavigationUrl.js +8 -0
  40. package/esm/core/requiredPostHydrationReplaceNavigationUrl.js.map +1 -0
  41. package/esm/entrypoint.d.ts +1 -0
  42. package/esm/entrypoint.js +1 -0
  43. package/esm/entrypoint.js.map +1 -1
  44. package/esm/mock/oidc.d.ts +1 -1
  45. package/esm/mock/oidc.js.map +1 -1
  46. package/esm/react/react.d.ts +1 -1
  47. package/esm/tanstack-start/react/accessTokenValidation_rfc9068.d.ts +12 -0
  48. package/esm/tanstack-start/react/accessTokenValidation_rfc9068.js +95 -0
  49. package/esm/tanstack-start/react/accessTokenValidation_rfc9068.js.map +1 -0
  50. package/esm/tanstack-start/react/apiBuilder.d.ts +27 -0
  51. package/esm/tanstack-start/react/apiBuilder.js +58 -0
  52. package/esm/tanstack-start/react/apiBuilder.js.map +1 -0
  53. package/esm/tanstack-start/react/createOidcSpaApi.d.ts +9 -0
  54. package/esm/tanstack-start/react/createOidcSpaApi.js +679 -0
  55. package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -0
  56. package/esm/tanstack-start/react/index.d.ts +3 -0
  57. package/esm/tanstack-start/react/index.js +4 -0
  58. package/esm/tanstack-start/react/index.js.map +1 -0
  59. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.d.ts +4 -0
  60. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.js +8 -0
  61. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.js.map +1 -0
  62. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.d.ts +4 -0
  63. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.js +86 -0
  64. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.js.map +1 -0
  65. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.d.ts +1 -0
  66. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.js +13 -0
  67. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.js.map +1 -0
  68. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.d.ts +2 -0
  69. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.js +3 -0
  70. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.js.map +1 -0
  71. package/esm/tanstack-start/react/types.d.ts +355 -0
  72. package/esm/tanstack-start/react/types.js +2 -0
  73. package/esm/tanstack-start/react/types.js.map +1 -0
  74. package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.d.ts +2 -0
  75. package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js +25 -0
  76. package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js.map +1 -0
  77. package/esm/tools/GetterOrDirectValue.d.ts +1 -0
  78. package/esm/tools/GetterOrDirectValue.js +2 -0
  79. package/esm/tools/GetterOrDirectValue.js.map +1 -0
  80. package/esm/tools/ZodSchemaLike.d.ts +3 -0
  81. package/esm/tools/ZodSchemaLike.js +2 -0
  82. package/esm/tools/ZodSchemaLike.js.map +1 -0
  83. package/esm/tools/inferIsViteDev.d.ts +1 -0
  84. package/esm/tools/inferIsViteDev.js +6 -0
  85. package/esm/tools/inferIsViteDev.js.map +1 -0
  86. package/esm/tools/infer_import_meta_env_BASE_URL.d.ts +1 -0
  87. package/esm/tools/infer_import_meta_env_BASE_URL.js +15 -0
  88. package/esm/tools/infer_import_meta_env_BASE_URL.js.map +1 -0
  89. package/esm/tools/tsafe/uncapitalize.d.ts +2 -0
  90. package/esm/tools/tsafe/uncapitalize.js +5 -0
  91. package/esm/tools/tsafe/uncapitalize.js.map +1 -0
  92. package/esm/vendor/backend/evt.d.ts +2 -0
  93. package/esm/vendor/backend/evt.js +3286 -0
  94. package/esm/vendor/backend/jose.d.ts +1 -0
  95. package/esm/vendor/backend/jose.js +3546 -0
  96. package/esm/vendor/backend/tsafe.d.ts +5 -0
  97. package/esm/vendor/backend/tsafe.js +68 -0
  98. package/esm/vendor/backend/zod.d.ts +1 -0
  99. package/esm/vendor/backend/zod.js +4023 -0
  100. package/esm/vendor/frontend/worker-timers.js +261 -1
  101. package/mock/oidc.d.ts +1 -1
  102. package/mock/oidc.js.map +1 -1
  103. package/package.json +40 -4
  104. package/react/react.d.ts +1 -1
  105. package/src/angular.ts +224 -9
  106. package/src/backend.ts +201 -166
  107. package/src/core/Oidc.ts +41 -11
  108. package/src/core/createOidc.ts +12 -3
  109. package/src/core/earlyInit.ts +19 -4
  110. package/src/core/loginOrGoToAuthServer.ts +11 -3
  111. package/src/core/oidcClientTsUserToTokens.ts +2 -2
  112. package/src/core/requiredPostHydrationReplaceNavigationUrl.ts +11 -0
  113. package/src/entrypoint.ts +1 -0
  114. package/src/mock/oidc.ts +2 -2
  115. package/src/react/react.tsx +1 -1
  116. package/src/tanstack-start/react/accessTokenValidation_rfc9068.ts +135 -0
  117. package/src/tanstack-start/react/apiBuilder.ts +151 -0
  118. package/src/tanstack-start/react/createOidcSpaApi.tsx +1011 -0
  119. package/src/tanstack-start/react/index.ts +5 -0
  120. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.ts +8 -0
  121. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.tsx +127 -0
  122. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.ts +15 -0
  123. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.ts +2 -0
  124. package/src/tanstack-start/react/types.tsx +415 -0
  125. package/src/tanstack-start/react/withHandlingOidcPostLoginNavigation.tsx +35 -0
  126. package/src/tools/GetterOrDirectValue.ts +1 -0
  127. package/src/tools/ZodSchemaLike.ts +3 -0
  128. package/src/tools/getThisCodebaseRootDirPath_cjs.ts +19 -0
  129. package/src/tools/inferIsViteDev.ts +6 -0
  130. package/src/tools/infer_import_meta_env_BASE_URL.ts +19 -0
  131. package/src/tools/tsafe/uncapitalize.ts +4 -0
  132. package/src/vendor/backend/jose.ts +1 -0
  133. package/src/vendor/build-runtime/babel.ts +6 -0
  134. package/src/vendor/build-runtime/magic-string.ts +3 -0
  135. package/src/vite-plugin/detectProjectType.ts +20 -0
  136. package/src/vite-plugin/excludeModuleExportFromOptimizedDeps.ts +20 -0
  137. package/src/vite-plugin/handleClientEntrypoint.ts +260 -0
  138. package/src/vite-plugin/index.ts +1 -0
  139. package/src/vite-plugin/transformCreateFileRoute.ts +240 -0
  140. package/src/vite-plugin/vite-plugin.ts +54 -0
  141. package/tools/GetterOrDirectValue.d.ts +1 -0
  142. package/tools/GetterOrDirectValue.js +3 -0
  143. package/tools/GetterOrDirectValue.js.map +1 -0
  144. package/tools/ZodSchemaLike.d.ts +3 -0
  145. package/tools/ZodSchemaLike.js +3 -0
  146. package/tools/ZodSchemaLike.js.map +1 -0
  147. package/tools/getThisCodebaseRootDirPath_cjs.d.ts +2 -0
  148. package/tools/getThisCodebaseRootDirPath_cjs.js +53 -0
  149. package/tools/getThisCodebaseRootDirPath_cjs.js.map +1 -0
  150. package/tools/tsafe/uncapitalize.d.ts +2 -0
  151. package/tools/tsafe/uncapitalize.js +8 -0
  152. package/tools/tsafe/uncapitalize.js.map +1 -0
  153. package/vendor/backend/jose.d.ts +1 -0
  154. package/vendor/backend/jose.js +3 -0
  155. package/vendor/build-runtime/babel.d.ts +6 -0
  156. package/vendor/build-runtime/babel.js +3 -0
  157. package/vendor/build-runtime/magic-string.d.ts +2 -0
  158. package/vendor/build-runtime/magic-string.js +2 -0
  159. package/vendor/frontend/oidc-client-ts.js +0 -2
  160. package/vite-plugin/detectProjectType.d.ts +10 -0
  161. package/vite-plugin/detectProjectType.js +15 -0
  162. package/vite-plugin/detectProjectType.js.map +1 -0
  163. package/vite-plugin/excludeModuleExportFromOptimizedDeps.d.ts +4 -0
  164. package/vite-plugin/excludeModuleExportFromOptimizedDeps.js +50 -0
  165. package/vite-plugin/excludeModuleExportFromOptimizedDeps.js.map +1 -0
  166. package/vite-plugin/handleClientEntrypoint.d.ts +10 -0
  167. package/vite-plugin/handleClientEntrypoint.js +211 -0
  168. package/vite-plugin/handleClientEntrypoint.js.map +1 -0
  169. package/vite-plugin/index.d.ts +1 -0
  170. package/vite-plugin/index.js +6 -0
  171. package/vite-plugin/index.js.map +1 -0
  172. package/vite-plugin/transformCreateFileRoute.d.ts +10 -0
  173. package/vite-plugin/transformCreateFileRoute.js +173 -0
  174. package/vite-plugin/transformCreateFileRoute.js.map +1 -0
  175. package/vite-plugin/vite-plugin.d.ts +5 -0
  176. package/vite-plugin/vite-plugin.js +46 -0
  177. package/vite-plugin/vite-plugin.js.map +1 -0
  178. package/src/vendor/backend/jsonwebtoken.ts +0 -1
  179. package/src/vendor/backend/node-fetch.ts +0 -2
  180. package/src/vendor/backend/node-jose.ts +0 -1
  181. package/vendor/backend/jsonwebtoken.d.ts +0 -1
  182. package/vendor/backend/jsonwebtoken.js +0 -3
  183. package/vendor/backend/node-fetch.d.ts +0 -2
  184. package/vendor/backend/node-fetch.js +0 -2
  185. package/vendor/backend/node-jose.d.ts +0 -1
  186. package/vendor/backend/node-jose.js +0 -3
@@ -0,0 +1,4023 @@
1
+ // node_modules/zod/lib/index.mjs
2
+ var util;
3
+ (function(util2) {
4
+ util2.assertEqual = (val) => val;
5
+ function assertIs(_arg) {
6
+ }
7
+ util2.assertIs = assertIs;
8
+ function assertNever(_x) {
9
+ throw new Error();
10
+ }
11
+ util2.assertNever = assertNever;
12
+ util2.arrayToEnum = (items) => {
13
+ const obj = {};
14
+ for (const item of items) {
15
+ obj[item] = item;
16
+ }
17
+ return obj;
18
+ };
19
+ util2.getValidEnumValues = (obj) => {
20
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
21
+ const filtered = {};
22
+ for (const k of validKeys) {
23
+ filtered[k] = obj[k];
24
+ }
25
+ return util2.objectValues(filtered);
26
+ };
27
+ util2.objectValues = (obj) => {
28
+ return util2.objectKeys(obj).map(function(e) {
29
+ return obj[e];
30
+ });
31
+ };
32
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
33
+ const keys = [];
34
+ for (const key in object) {
35
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
36
+ keys.push(key);
37
+ }
38
+ }
39
+ return keys;
40
+ };
41
+ util2.find = (arr, checker) => {
42
+ for (const item of arr) {
43
+ if (checker(item))
44
+ return item;
45
+ }
46
+ return void 0;
47
+ };
48
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
49
+ function joinValues(array, separator = " | ") {
50
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
51
+ }
52
+ util2.joinValues = joinValues;
53
+ util2.jsonStringifyReplacer = (_, value) => {
54
+ if (typeof value === "bigint") {
55
+ return value.toString();
56
+ }
57
+ return value;
58
+ };
59
+ })(util || (util = {}));
60
+ var objectUtil;
61
+ (function(objectUtil2) {
62
+ objectUtil2.mergeShapes = (first, second) => {
63
+ return {
64
+ ...first,
65
+ ...second
66
+ // second overwrites first
67
+ };
68
+ };
69
+ })(objectUtil || (objectUtil = {}));
70
+ var ZodParsedType = util.arrayToEnum([
71
+ "string",
72
+ "nan",
73
+ "number",
74
+ "integer",
75
+ "float",
76
+ "boolean",
77
+ "date",
78
+ "bigint",
79
+ "symbol",
80
+ "function",
81
+ "undefined",
82
+ "null",
83
+ "array",
84
+ "object",
85
+ "unknown",
86
+ "promise",
87
+ "void",
88
+ "never",
89
+ "map",
90
+ "set"
91
+ ]);
92
+ var getParsedType = (data) => {
93
+ const t = typeof data;
94
+ switch (t) {
95
+ case "undefined":
96
+ return ZodParsedType.undefined;
97
+ case "string":
98
+ return ZodParsedType.string;
99
+ case "number":
100
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
101
+ case "boolean":
102
+ return ZodParsedType.boolean;
103
+ case "function":
104
+ return ZodParsedType.function;
105
+ case "bigint":
106
+ return ZodParsedType.bigint;
107
+ case "symbol":
108
+ return ZodParsedType.symbol;
109
+ case "object":
110
+ if (Array.isArray(data)) {
111
+ return ZodParsedType.array;
112
+ }
113
+ if (data === null) {
114
+ return ZodParsedType.null;
115
+ }
116
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
117
+ return ZodParsedType.promise;
118
+ }
119
+ if (typeof Map !== "undefined" && data instanceof Map) {
120
+ return ZodParsedType.map;
121
+ }
122
+ if (typeof Set !== "undefined" && data instanceof Set) {
123
+ return ZodParsedType.set;
124
+ }
125
+ if (typeof Date !== "undefined" && data instanceof Date) {
126
+ return ZodParsedType.date;
127
+ }
128
+ return ZodParsedType.object;
129
+ default:
130
+ return ZodParsedType.unknown;
131
+ }
132
+ };
133
+ var ZodIssueCode = util.arrayToEnum([
134
+ "invalid_type",
135
+ "invalid_literal",
136
+ "custom",
137
+ "invalid_union",
138
+ "invalid_union_discriminator",
139
+ "invalid_enum_value",
140
+ "unrecognized_keys",
141
+ "invalid_arguments",
142
+ "invalid_return_type",
143
+ "invalid_date",
144
+ "invalid_string",
145
+ "too_small",
146
+ "too_big",
147
+ "invalid_intersection_types",
148
+ "not_multiple_of",
149
+ "not_finite"
150
+ ]);
151
+ var quotelessJson = (obj) => {
152
+ const json = JSON.stringify(obj, null, 2);
153
+ return json.replace(/"([^"]+)":/g, "$1:");
154
+ };
155
+ var ZodError = class _ZodError extends Error {
156
+ constructor(issues) {
157
+ super();
158
+ this.issues = [];
159
+ this.addIssue = (sub) => {
160
+ this.issues = [...this.issues, sub];
161
+ };
162
+ this.addIssues = (subs = []) => {
163
+ this.issues = [...this.issues, ...subs];
164
+ };
165
+ const actualProto = new.target.prototype;
166
+ if (Object.setPrototypeOf) {
167
+ Object.setPrototypeOf(this, actualProto);
168
+ } else {
169
+ this.__proto__ = actualProto;
170
+ }
171
+ this.name = "ZodError";
172
+ this.issues = issues;
173
+ }
174
+ get errors() {
175
+ return this.issues;
176
+ }
177
+ format(_mapper) {
178
+ const mapper = _mapper || function(issue) {
179
+ return issue.message;
180
+ };
181
+ const fieldErrors = { _errors: [] };
182
+ const processError = (error) => {
183
+ for (const issue of error.issues) {
184
+ if (issue.code === "invalid_union") {
185
+ issue.unionErrors.map(processError);
186
+ } else if (issue.code === "invalid_return_type") {
187
+ processError(issue.returnTypeError);
188
+ } else if (issue.code === "invalid_arguments") {
189
+ processError(issue.argumentsError);
190
+ } else if (issue.path.length === 0) {
191
+ fieldErrors._errors.push(mapper(issue));
192
+ } else {
193
+ let curr = fieldErrors;
194
+ let i = 0;
195
+ while (i < issue.path.length) {
196
+ const el = issue.path[i];
197
+ const terminal = i === issue.path.length - 1;
198
+ if (!terminal) {
199
+ curr[el] = curr[el] || { _errors: [] };
200
+ } else {
201
+ curr[el] = curr[el] || { _errors: [] };
202
+ curr[el]._errors.push(mapper(issue));
203
+ }
204
+ curr = curr[el];
205
+ i++;
206
+ }
207
+ }
208
+ }
209
+ };
210
+ processError(this);
211
+ return fieldErrors;
212
+ }
213
+ static assert(value) {
214
+ if (!(value instanceof _ZodError)) {
215
+ throw new Error(`Not a ZodError: ${value}`);
216
+ }
217
+ }
218
+ toString() {
219
+ return this.message;
220
+ }
221
+ get message() {
222
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
223
+ }
224
+ get isEmpty() {
225
+ return this.issues.length === 0;
226
+ }
227
+ flatten(mapper = (issue) => issue.message) {
228
+ const fieldErrors = {};
229
+ const formErrors = [];
230
+ for (const sub of this.issues) {
231
+ if (sub.path.length > 0) {
232
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
233
+ fieldErrors[sub.path[0]].push(mapper(sub));
234
+ } else {
235
+ formErrors.push(mapper(sub));
236
+ }
237
+ }
238
+ return { formErrors, fieldErrors };
239
+ }
240
+ get formErrors() {
241
+ return this.flatten();
242
+ }
243
+ };
244
+ ZodError.create = (issues) => {
245
+ const error = new ZodError(issues);
246
+ return error;
247
+ };
248
+ var errorMap = (issue, _ctx) => {
249
+ let message;
250
+ switch (issue.code) {
251
+ case ZodIssueCode.invalid_type:
252
+ if (issue.received === ZodParsedType.undefined) {
253
+ message = "Required";
254
+ } else {
255
+ message = `Expected ${issue.expected}, received ${issue.received}`;
256
+ }
257
+ break;
258
+ case ZodIssueCode.invalid_literal:
259
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
260
+ break;
261
+ case ZodIssueCode.unrecognized_keys:
262
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
263
+ break;
264
+ case ZodIssueCode.invalid_union:
265
+ message = `Invalid input`;
266
+ break;
267
+ case ZodIssueCode.invalid_union_discriminator:
268
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
269
+ break;
270
+ case ZodIssueCode.invalid_enum_value:
271
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
272
+ break;
273
+ case ZodIssueCode.invalid_arguments:
274
+ message = `Invalid function arguments`;
275
+ break;
276
+ case ZodIssueCode.invalid_return_type:
277
+ message = `Invalid function return type`;
278
+ break;
279
+ case ZodIssueCode.invalid_date:
280
+ message = `Invalid date`;
281
+ break;
282
+ case ZodIssueCode.invalid_string:
283
+ if (typeof issue.validation === "object") {
284
+ if ("includes" in issue.validation) {
285
+ message = `Invalid input: must include "${issue.validation.includes}"`;
286
+ if (typeof issue.validation.position === "number") {
287
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
288
+ }
289
+ } else if ("startsWith" in issue.validation) {
290
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
291
+ } else if ("endsWith" in issue.validation) {
292
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
293
+ } else {
294
+ util.assertNever(issue.validation);
295
+ }
296
+ } else if (issue.validation !== "regex") {
297
+ message = `Invalid ${issue.validation}`;
298
+ } else {
299
+ message = "Invalid";
300
+ }
301
+ break;
302
+ case ZodIssueCode.too_small:
303
+ if (issue.type === "array")
304
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
305
+ else if (issue.type === "string")
306
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
307
+ else if (issue.type === "number")
308
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
309
+ else if (issue.type === "date")
310
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
311
+ else
312
+ message = "Invalid input";
313
+ break;
314
+ case ZodIssueCode.too_big:
315
+ if (issue.type === "array")
316
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
317
+ else if (issue.type === "string")
318
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
319
+ else if (issue.type === "number")
320
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
321
+ else if (issue.type === "bigint")
322
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
323
+ else if (issue.type === "date")
324
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
325
+ else
326
+ message = "Invalid input";
327
+ break;
328
+ case ZodIssueCode.custom:
329
+ message = `Invalid input`;
330
+ break;
331
+ case ZodIssueCode.invalid_intersection_types:
332
+ message = `Intersection results could not be merged`;
333
+ break;
334
+ case ZodIssueCode.not_multiple_of:
335
+ message = `Number must be a multiple of ${issue.multipleOf}`;
336
+ break;
337
+ case ZodIssueCode.not_finite:
338
+ message = "Number must be finite";
339
+ break;
340
+ default:
341
+ message = _ctx.defaultError;
342
+ util.assertNever(issue);
343
+ }
344
+ return { message };
345
+ };
346
+ var overrideErrorMap = errorMap;
347
+ function setErrorMap(map) {
348
+ overrideErrorMap = map;
349
+ }
350
+ function getErrorMap() {
351
+ return overrideErrorMap;
352
+ }
353
+ var makeIssue = (params) => {
354
+ const { data, path, errorMaps, issueData } = params;
355
+ const fullPath = [...path, ...issueData.path || []];
356
+ const fullIssue = {
357
+ ...issueData,
358
+ path: fullPath
359
+ };
360
+ if (issueData.message !== void 0) {
361
+ return {
362
+ ...issueData,
363
+ path: fullPath,
364
+ message: issueData.message
365
+ };
366
+ }
367
+ let errorMessage = "";
368
+ const maps = errorMaps.filter((m) => !!m).slice().reverse();
369
+ for (const map of maps) {
370
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
371
+ }
372
+ return {
373
+ ...issueData,
374
+ path: fullPath,
375
+ message: errorMessage
376
+ };
377
+ };
378
+ var EMPTY_PATH = [];
379
+ function addIssueToContext(ctx, issueData) {
380
+ const overrideMap = getErrorMap();
381
+ const issue = makeIssue({
382
+ issueData,
383
+ data: ctx.data,
384
+ path: ctx.path,
385
+ errorMaps: [
386
+ ctx.common.contextualErrorMap,
387
+ ctx.schemaErrorMap,
388
+ overrideMap,
389
+ overrideMap === errorMap ? void 0 : errorMap
390
+ // then global default map
391
+ ].filter((x) => !!x)
392
+ });
393
+ ctx.common.issues.push(issue);
394
+ }
395
+ var ParseStatus = class _ParseStatus {
396
+ constructor() {
397
+ this.value = "valid";
398
+ }
399
+ dirty() {
400
+ if (this.value === "valid")
401
+ this.value = "dirty";
402
+ }
403
+ abort() {
404
+ if (this.value !== "aborted")
405
+ this.value = "aborted";
406
+ }
407
+ static mergeArray(status, results) {
408
+ const arrayValue = [];
409
+ for (const s of results) {
410
+ if (s.status === "aborted")
411
+ return INVALID;
412
+ if (s.status === "dirty")
413
+ status.dirty();
414
+ arrayValue.push(s.value);
415
+ }
416
+ return { status: status.value, value: arrayValue };
417
+ }
418
+ static async mergeObjectAsync(status, pairs) {
419
+ const syncPairs = [];
420
+ for (const pair of pairs) {
421
+ const key = await pair.key;
422
+ const value = await pair.value;
423
+ syncPairs.push({
424
+ key,
425
+ value
426
+ });
427
+ }
428
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
429
+ }
430
+ static mergeObjectSync(status, pairs) {
431
+ const finalObject = {};
432
+ for (const pair of pairs) {
433
+ const { key, value } = pair;
434
+ if (key.status === "aborted")
435
+ return INVALID;
436
+ if (value.status === "aborted")
437
+ return INVALID;
438
+ if (key.status === "dirty")
439
+ status.dirty();
440
+ if (value.status === "dirty")
441
+ status.dirty();
442
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
443
+ finalObject[key.value] = value.value;
444
+ }
445
+ }
446
+ return { status: status.value, value: finalObject };
447
+ }
448
+ };
449
+ var INVALID = Object.freeze({
450
+ status: "aborted"
451
+ });
452
+ var DIRTY = (value) => ({ status: "dirty", value });
453
+ var OK = (value) => ({ status: "valid", value });
454
+ var isAborted = (x) => x.status === "aborted";
455
+ var isDirty = (x) => x.status === "dirty";
456
+ var isValid = (x) => x.status === "valid";
457
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
458
+ function __classPrivateFieldGet(receiver, state, kind, f) {
459
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
460
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
461
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
462
+ }
463
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
464
+ if (kind === "m") throw new TypeError("Private method is not writable");
465
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
466
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
467
+ return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
468
+ }
469
+ var errorUtil;
470
+ (function(errorUtil2) {
471
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
472
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
473
+ })(errorUtil || (errorUtil = {}));
474
+ var _ZodEnum_cache;
475
+ var _ZodNativeEnum_cache;
476
+ var ParseInputLazyPath = class {
477
+ constructor(parent, value, path, key) {
478
+ this._cachedPath = [];
479
+ this.parent = parent;
480
+ this.data = value;
481
+ this._path = path;
482
+ this._key = key;
483
+ }
484
+ get path() {
485
+ if (!this._cachedPath.length) {
486
+ if (this._key instanceof Array) {
487
+ this._cachedPath.push(...this._path, ...this._key);
488
+ } else {
489
+ this._cachedPath.push(...this._path, this._key);
490
+ }
491
+ }
492
+ return this._cachedPath;
493
+ }
494
+ };
495
+ var handleResult = (ctx, result) => {
496
+ if (isValid(result)) {
497
+ return { success: true, data: result.value };
498
+ } else {
499
+ if (!ctx.common.issues.length) {
500
+ throw new Error("Validation failed but no issues detected.");
501
+ }
502
+ return {
503
+ success: false,
504
+ get error() {
505
+ if (this._error)
506
+ return this._error;
507
+ const error = new ZodError(ctx.common.issues);
508
+ this._error = error;
509
+ return this._error;
510
+ }
511
+ };
512
+ }
513
+ };
514
+ function processCreateParams(params) {
515
+ if (!params)
516
+ return {};
517
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
518
+ if (errorMap2 && (invalid_type_error || required_error)) {
519
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
520
+ }
521
+ if (errorMap2)
522
+ return { errorMap: errorMap2, description };
523
+ const customMap = (iss, ctx) => {
524
+ var _a, _b;
525
+ const { message } = params;
526
+ if (iss.code === "invalid_enum_value") {
527
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
528
+ }
529
+ if (typeof ctx.data === "undefined") {
530
+ return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
531
+ }
532
+ if (iss.code !== "invalid_type")
533
+ return { message: ctx.defaultError };
534
+ return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
535
+ };
536
+ return { errorMap: customMap, description };
537
+ }
538
+ var ZodType = class {
539
+ constructor(def) {
540
+ this.spa = this.safeParseAsync;
541
+ this._def = def;
542
+ this.parse = this.parse.bind(this);
543
+ this.safeParse = this.safeParse.bind(this);
544
+ this.parseAsync = this.parseAsync.bind(this);
545
+ this.safeParseAsync = this.safeParseAsync.bind(this);
546
+ this.spa = this.spa.bind(this);
547
+ this.refine = this.refine.bind(this);
548
+ this.refinement = this.refinement.bind(this);
549
+ this.superRefine = this.superRefine.bind(this);
550
+ this.optional = this.optional.bind(this);
551
+ this.nullable = this.nullable.bind(this);
552
+ this.nullish = this.nullish.bind(this);
553
+ this.array = this.array.bind(this);
554
+ this.promise = this.promise.bind(this);
555
+ this.or = this.or.bind(this);
556
+ this.and = this.and.bind(this);
557
+ this.transform = this.transform.bind(this);
558
+ this.brand = this.brand.bind(this);
559
+ this.default = this.default.bind(this);
560
+ this.catch = this.catch.bind(this);
561
+ this.describe = this.describe.bind(this);
562
+ this.pipe = this.pipe.bind(this);
563
+ this.readonly = this.readonly.bind(this);
564
+ this.isNullable = this.isNullable.bind(this);
565
+ this.isOptional = this.isOptional.bind(this);
566
+ }
567
+ get description() {
568
+ return this._def.description;
569
+ }
570
+ _getType(input) {
571
+ return getParsedType(input.data);
572
+ }
573
+ _getOrReturnCtx(input, ctx) {
574
+ return ctx || {
575
+ common: input.parent.common,
576
+ data: input.data,
577
+ parsedType: getParsedType(input.data),
578
+ schemaErrorMap: this._def.errorMap,
579
+ path: input.path,
580
+ parent: input.parent
581
+ };
582
+ }
583
+ _processInputParams(input) {
584
+ return {
585
+ status: new ParseStatus(),
586
+ ctx: {
587
+ common: input.parent.common,
588
+ data: input.data,
589
+ parsedType: getParsedType(input.data),
590
+ schemaErrorMap: this._def.errorMap,
591
+ path: input.path,
592
+ parent: input.parent
593
+ }
594
+ };
595
+ }
596
+ _parseSync(input) {
597
+ const result = this._parse(input);
598
+ if (isAsync(result)) {
599
+ throw new Error("Synchronous parse encountered promise.");
600
+ }
601
+ return result;
602
+ }
603
+ _parseAsync(input) {
604
+ const result = this._parse(input);
605
+ return Promise.resolve(result);
606
+ }
607
+ parse(data, params) {
608
+ const result = this.safeParse(data, params);
609
+ if (result.success)
610
+ return result.data;
611
+ throw result.error;
612
+ }
613
+ safeParse(data, params) {
614
+ var _a;
615
+ const ctx = {
616
+ common: {
617
+ issues: [],
618
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
619
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
620
+ },
621
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
622
+ schemaErrorMap: this._def.errorMap,
623
+ parent: null,
624
+ data,
625
+ parsedType: getParsedType(data)
626
+ };
627
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
628
+ return handleResult(ctx, result);
629
+ }
630
+ async parseAsync(data, params) {
631
+ const result = await this.safeParseAsync(data, params);
632
+ if (result.success)
633
+ return result.data;
634
+ throw result.error;
635
+ }
636
+ async safeParseAsync(data, params) {
637
+ const ctx = {
638
+ common: {
639
+ issues: [],
640
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
641
+ async: true
642
+ },
643
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
644
+ schemaErrorMap: this._def.errorMap,
645
+ parent: null,
646
+ data,
647
+ parsedType: getParsedType(data)
648
+ };
649
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
650
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
651
+ return handleResult(ctx, result);
652
+ }
653
+ refine(check, message) {
654
+ const getIssueProperties = (val) => {
655
+ if (typeof message === "string" || typeof message === "undefined") {
656
+ return { message };
657
+ } else if (typeof message === "function") {
658
+ return message(val);
659
+ } else {
660
+ return message;
661
+ }
662
+ };
663
+ return this._refinement((val, ctx) => {
664
+ const result = check(val);
665
+ const setError = () => ctx.addIssue({
666
+ code: ZodIssueCode.custom,
667
+ ...getIssueProperties(val)
668
+ });
669
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
670
+ return result.then((data) => {
671
+ if (!data) {
672
+ setError();
673
+ return false;
674
+ } else {
675
+ return true;
676
+ }
677
+ });
678
+ }
679
+ if (!result) {
680
+ setError();
681
+ return false;
682
+ } else {
683
+ return true;
684
+ }
685
+ });
686
+ }
687
+ refinement(check, refinementData) {
688
+ return this._refinement((val, ctx) => {
689
+ if (!check(val)) {
690
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
691
+ return false;
692
+ } else {
693
+ return true;
694
+ }
695
+ });
696
+ }
697
+ _refinement(refinement) {
698
+ return new ZodEffects({
699
+ schema: this,
700
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
701
+ effect: { type: "refinement", refinement }
702
+ });
703
+ }
704
+ superRefine(refinement) {
705
+ return this._refinement(refinement);
706
+ }
707
+ optional() {
708
+ return ZodOptional.create(this, this._def);
709
+ }
710
+ nullable() {
711
+ return ZodNullable.create(this, this._def);
712
+ }
713
+ nullish() {
714
+ return this.nullable().optional();
715
+ }
716
+ array() {
717
+ return ZodArray.create(this, this._def);
718
+ }
719
+ promise() {
720
+ return ZodPromise.create(this, this._def);
721
+ }
722
+ or(option) {
723
+ return ZodUnion.create([this, option], this._def);
724
+ }
725
+ and(incoming) {
726
+ return ZodIntersection.create(this, incoming, this._def);
727
+ }
728
+ transform(transform) {
729
+ return new ZodEffects({
730
+ ...processCreateParams(this._def),
731
+ schema: this,
732
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
733
+ effect: { type: "transform", transform }
734
+ });
735
+ }
736
+ default(def) {
737
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
738
+ return new ZodDefault({
739
+ ...processCreateParams(this._def),
740
+ innerType: this,
741
+ defaultValue: defaultValueFunc,
742
+ typeName: ZodFirstPartyTypeKind.ZodDefault
743
+ });
744
+ }
745
+ brand() {
746
+ return new ZodBranded({
747
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
748
+ type: this,
749
+ ...processCreateParams(this._def)
750
+ });
751
+ }
752
+ catch(def) {
753
+ const catchValueFunc = typeof def === "function" ? def : () => def;
754
+ return new ZodCatch({
755
+ ...processCreateParams(this._def),
756
+ innerType: this,
757
+ catchValue: catchValueFunc,
758
+ typeName: ZodFirstPartyTypeKind.ZodCatch
759
+ });
760
+ }
761
+ describe(description) {
762
+ const This = this.constructor;
763
+ return new This({
764
+ ...this._def,
765
+ description
766
+ });
767
+ }
768
+ pipe(target) {
769
+ return ZodPipeline.create(this, target);
770
+ }
771
+ readonly() {
772
+ return ZodReadonly.create(this);
773
+ }
774
+ isOptional() {
775
+ return this.safeParse(void 0).success;
776
+ }
777
+ isNullable() {
778
+ return this.safeParse(null).success;
779
+ }
780
+ };
781
+ var cuidRegex = /^c[^\s-]{8,}$/i;
782
+ var cuid2Regex = /^[0-9a-z]+$/;
783
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
784
+ var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
785
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
786
+ var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
787
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
788
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
789
+ var emojiRegex;
790
+ var ipv4Regex = /^(?:(?: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])$/;
791
+ var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((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})))$/;
792
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
793
+ var dateRegexSource = `((\\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])))`;
794
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
795
+ function timeRegexSource(args) {
796
+ let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
797
+ if (args.precision) {
798
+ regex = `${regex}\\.\\d{${args.precision}}`;
799
+ } else if (args.precision == null) {
800
+ regex = `${regex}(\\.\\d+)?`;
801
+ }
802
+ return regex;
803
+ }
804
+ function timeRegex(args) {
805
+ return new RegExp(`^${timeRegexSource(args)}$`);
806
+ }
807
+ function datetimeRegex(args) {
808
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
809
+ const opts = [];
810
+ opts.push(args.local ? `Z?` : `Z`);
811
+ if (args.offset)
812
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
813
+ regex = `${regex}(${opts.join("|")})`;
814
+ return new RegExp(`^${regex}$`);
815
+ }
816
+ function isValidIP(ip, version) {
817
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
818
+ return true;
819
+ }
820
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
821
+ return true;
822
+ }
823
+ return false;
824
+ }
825
+ var ZodString = class _ZodString extends ZodType {
826
+ _parse(input) {
827
+ if (this._def.coerce) {
828
+ input.data = String(input.data);
829
+ }
830
+ const parsedType = this._getType(input);
831
+ if (parsedType !== ZodParsedType.string) {
832
+ const ctx2 = this._getOrReturnCtx(input);
833
+ addIssueToContext(ctx2, {
834
+ code: ZodIssueCode.invalid_type,
835
+ expected: ZodParsedType.string,
836
+ received: ctx2.parsedType
837
+ });
838
+ return INVALID;
839
+ }
840
+ const status = new ParseStatus();
841
+ let ctx = void 0;
842
+ for (const check of this._def.checks) {
843
+ if (check.kind === "min") {
844
+ if (input.data.length < check.value) {
845
+ ctx = this._getOrReturnCtx(input, ctx);
846
+ addIssueToContext(ctx, {
847
+ code: ZodIssueCode.too_small,
848
+ minimum: check.value,
849
+ type: "string",
850
+ inclusive: true,
851
+ exact: false,
852
+ message: check.message
853
+ });
854
+ status.dirty();
855
+ }
856
+ } else if (check.kind === "max") {
857
+ if (input.data.length > check.value) {
858
+ ctx = this._getOrReturnCtx(input, ctx);
859
+ addIssueToContext(ctx, {
860
+ code: ZodIssueCode.too_big,
861
+ maximum: check.value,
862
+ type: "string",
863
+ inclusive: true,
864
+ exact: false,
865
+ message: check.message
866
+ });
867
+ status.dirty();
868
+ }
869
+ } else if (check.kind === "length") {
870
+ const tooBig = input.data.length > check.value;
871
+ const tooSmall = input.data.length < check.value;
872
+ if (tooBig || tooSmall) {
873
+ ctx = this._getOrReturnCtx(input, ctx);
874
+ if (tooBig) {
875
+ addIssueToContext(ctx, {
876
+ code: ZodIssueCode.too_big,
877
+ maximum: check.value,
878
+ type: "string",
879
+ inclusive: true,
880
+ exact: true,
881
+ message: check.message
882
+ });
883
+ } else if (tooSmall) {
884
+ addIssueToContext(ctx, {
885
+ code: ZodIssueCode.too_small,
886
+ minimum: check.value,
887
+ type: "string",
888
+ inclusive: true,
889
+ exact: true,
890
+ message: check.message
891
+ });
892
+ }
893
+ status.dirty();
894
+ }
895
+ } else if (check.kind === "email") {
896
+ if (!emailRegex.test(input.data)) {
897
+ ctx = this._getOrReturnCtx(input, ctx);
898
+ addIssueToContext(ctx, {
899
+ validation: "email",
900
+ code: ZodIssueCode.invalid_string,
901
+ message: check.message
902
+ });
903
+ status.dirty();
904
+ }
905
+ } else if (check.kind === "emoji") {
906
+ if (!emojiRegex) {
907
+ emojiRegex = new RegExp(_emojiRegex, "u");
908
+ }
909
+ if (!emojiRegex.test(input.data)) {
910
+ ctx = this._getOrReturnCtx(input, ctx);
911
+ addIssueToContext(ctx, {
912
+ validation: "emoji",
913
+ code: ZodIssueCode.invalid_string,
914
+ message: check.message
915
+ });
916
+ status.dirty();
917
+ }
918
+ } else if (check.kind === "uuid") {
919
+ if (!uuidRegex.test(input.data)) {
920
+ ctx = this._getOrReturnCtx(input, ctx);
921
+ addIssueToContext(ctx, {
922
+ validation: "uuid",
923
+ code: ZodIssueCode.invalid_string,
924
+ message: check.message
925
+ });
926
+ status.dirty();
927
+ }
928
+ } else if (check.kind === "nanoid") {
929
+ if (!nanoidRegex.test(input.data)) {
930
+ ctx = this._getOrReturnCtx(input, ctx);
931
+ addIssueToContext(ctx, {
932
+ validation: "nanoid",
933
+ code: ZodIssueCode.invalid_string,
934
+ message: check.message
935
+ });
936
+ status.dirty();
937
+ }
938
+ } else if (check.kind === "cuid") {
939
+ if (!cuidRegex.test(input.data)) {
940
+ ctx = this._getOrReturnCtx(input, ctx);
941
+ addIssueToContext(ctx, {
942
+ validation: "cuid",
943
+ code: ZodIssueCode.invalid_string,
944
+ message: check.message
945
+ });
946
+ status.dirty();
947
+ }
948
+ } else if (check.kind === "cuid2") {
949
+ if (!cuid2Regex.test(input.data)) {
950
+ ctx = this._getOrReturnCtx(input, ctx);
951
+ addIssueToContext(ctx, {
952
+ validation: "cuid2",
953
+ code: ZodIssueCode.invalid_string,
954
+ message: check.message
955
+ });
956
+ status.dirty();
957
+ }
958
+ } else if (check.kind === "ulid") {
959
+ if (!ulidRegex.test(input.data)) {
960
+ ctx = this._getOrReturnCtx(input, ctx);
961
+ addIssueToContext(ctx, {
962
+ validation: "ulid",
963
+ code: ZodIssueCode.invalid_string,
964
+ message: check.message
965
+ });
966
+ status.dirty();
967
+ }
968
+ } else if (check.kind === "url") {
969
+ try {
970
+ new URL(input.data);
971
+ } catch (_a) {
972
+ ctx = this._getOrReturnCtx(input, ctx);
973
+ addIssueToContext(ctx, {
974
+ validation: "url",
975
+ code: ZodIssueCode.invalid_string,
976
+ message: check.message
977
+ });
978
+ status.dirty();
979
+ }
980
+ } else if (check.kind === "regex") {
981
+ check.regex.lastIndex = 0;
982
+ const testResult = check.regex.test(input.data);
983
+ if (!testResult) {
984
+ ctx = this._getOrReturnCtx(input, ctx);
985
+ addIssueToContext(ctx, {
986
+ validation: "regex",
987
+ code: ZodIssueCode.invalid_string,
988
+ message: check.message
989
+ });
990
+ status.dirty();
991
+ }
992
+ } else if (check.kind === "trim") {
993
+ input.data = input.data.trim();
994
+ } else if (check.kind === "includes") {
995
+ if (!input.data.includes(check.value, check.position)) {
996
+ ctx = this._getOrReturnCtx(input, ctx);
997
+ addIssueToContext(ctx, {
998
+ code: ZodIssueCode.invalid_string,
999
+ validation: { includes: check.value, position: check.position },
1000
+ message: check.message
1001
+ });
1002
+ status.dirty();
1003
+ }
1004
+ } else if (check.kind === "toLowerCase") {
1005
+ input.data = input.data.toLowerCase();
1006
+ } else if (check.kind === "toUpperCase") {
1007
+ input.data = input.data.toUpperCase();
1008
+ } else if (check.kind === "startsWith") {
1009
+ if (!input.data.startsWith(check.value)) {
1010
+ ctx = this._getOrReturnCtx(input, ctx);
1011
+ addIssueToContext(ctx, {
1012
+ code: ZodIssueCode.invalid_string,
1013
+ validation: { startsWith: check.value },
1014
+ message: check.message
1015
+ });
1016
+ status.dirty();
1017
+ }
1018
+ } else if (check.kind === "endsWith") {
1019
+ if (!input.data.endsWith(check.value)) {
1020
+ ctx = this._getOrReturnCtx(input, ctx);
1021
+ addIssueToContext(ctx, {
1022
+ code: ZodIssueCode.invalid_string,
1023
+ validation: { endsWith: check.value },
1024
+ message: check.message
1025
+ });
1026
+ status.dirty();
1027
+ }
1028
+ } else if (check.kind === "datetime") {
1029
+ const regex = datetimeRegex(check);
1030
+ if (!regex.test(input.data)) {
1031
+ ctx = this._getOrReturnCtx(input, ctx);
1032
+ addIssueToContext(ctx, {
1033
+ code: ZodIssueCode.invalid_string,
1034
+ validation: "datetime",
1035
+ message: check.message
1036
+ });
1037
+ status.dirty();
1038
+ }
1039
+ } else if (check.kind === "date") {
1040
+ const regex = dateRegex;
1041
+ if (!regex.test(input.data)) {
1042
+ ctx = this._getOrReturnCtx(input, ctx);
1043
+ addIssueToContext(ctx, {
1044
+ code: ZodIssueCode.invalid_string,
1045
+ validation: "date",
1046
+ message: check.message
1047
+ });
1048
+ status.dirty();
1049
+ }
1050
+ } else if (check.kind === "time") {
1051
+ const regex = timeRegex(check);
1052
+ if (!regex.test(input.data)) {
1053
+ ctx = this._getOrReturnCtx(input, ctx);
1054
+ addIssueToContext(ctx, {
1055
+ code: ZodIssueCode.invalid_string,
1056
+ validation: "time",
1057
+ message: check.message
1058
+ });
1059
+ status.dirty();
1060
+ }
1061
+ } else if (check.kind === "duration") {
1062
+ if (!durationRegex.test(input.data)) {
1063
+ ctx = this._getOrReturnCtx(input, ctx);
1064
+ addIssueToContext(ctx, {
1065
+ validation: "duration",
1066
+ code: ZodIssueCode.invalid_string,
1067
+ message: check.message
1068
+ });
1069
+ status.dirty();
1070
+ }
1071
+ } else if (check.kind === "ip") {
1072
+ if (!isValidIP(input.data, check.version)) {
1073
+ ctx = this._getOrReturnCtx(input, ctx);
1074
+ addIssueToContext(ctx, {
1075
+ validation: "ip",
1076
+ code: ZodIssueCode.invalid_string,
1077
+ message: check.message
1078
+ });
1079
+ status.dirty();
1080
+ }
1081
+ } else if (check.kind === "base64") {
1082
+ if (!base64Regex.test(input.data)) {
1083
+ ctx = this._getOrReturnCtx(input, ctx);
1084
+ addIssueToContext(ctx, {
1085
+ validation: "base64",
1086
+ code: ZodIssueCode.invalid_string,
1087
+ message: check.message
1088
+ });
1089
+ status.dirty();
1090
+ }
1091
+ } else {
1092
+ util.assertNever(check);
1093
+ }
1094
+ }
1095
+ return { status: status.value, value: input.data };
1096
+ }
1097
+ _regex(regex, validation, message) {
1098
+ return this.refinement((data) => regex.test(data), {
1099
+ validation,
1100
+ code: ZodIssueCode.invalid_string,
1101
+ ...errorUtil.errToObj(message)
1102
+ });
1103
+ }
1104
+ _addCheck(check) {
1105
+ return new _ZodString({
1106
+ ...this._def,
1107
+ checks: [...this._def.checks, check]
1108
+ });
1109
+ }
1110
+ email(message) {
1111
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1112
+ }
1113
+ url(message) {
1114
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1115
+ }
1116
+ emoji(message) {
1117
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1118
+ }
1119
+ uuid(message) {
1120
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1121
+ }
1122
+ nanoid(message) {
1123
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1124
+ }
1125
+ cuid(message) {
1126
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1127
+ }
1128
+ cuid2(message) {
1129
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1130
+ }
1131
+ ulid(message) {
1132
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1133
+ }
1134
+ base64(message) {
1135
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1136
+ }
1137
+ ip(options) {
1138
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1139
+ }
1140
+ datetime(options) {
1141
+ var _a, _b;
1142
+ if (typeof options === "string") {
1143
+ return this._addCheck({
1144
+ kind: "datetime",
1145
+ precision: null,
1146
+ offset: false,
1147
+ local: false,
1148
+ message: options
1149
+ });
1150
+ }
1151
+ return this._addCheck({
1152
+ kind: "datetime",
1153
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1154
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1155
+ local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1156
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
1157
+ });
1158
+ }
1159
+ date(message) {
1160
+ return this._addCheck({ kind: "date", message });
1161
+ }
1162
+ time(options) {
1163
+ if (typeof options === "string") {
1164
+ return this._addCheck({
1165
+ kind: "time",
1166
+ precision: null,
1167
+ message: options
1168
+ });
1169
+ }
1170
+ return this._addCheck({
1171
+ kind: "time",
1172
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1173
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
1174
+ });
1175
+ }
1176
+ duration(message) {
1177
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1178
+ }
1179
+ regex(regex, message) {
1180
+ return this._addCheck({
1181
+ kind: "regex",
1182
+ regex,
1183
+ ...errorUtil.errToObj(message)
1184
+ });
1185
+ }
1186
+ includes(value, options) {
1187
+ return this._addCheck({
1188
+ kind: "includes",
1189
+ value,
1190
+ position: options === null || options === void 0 ? void 0 : options.position,
1191
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
1192
+ });
1193
+ }
1194
+ startsWith(value, message) {
1195
+ return this._addCheck({
1196
+ kind: "startsWith",
1197
+ value,
1198
+ ...errorUtil.errToObj(message)
1199
+ });
1200
+ }
1201
+ endsWith(value, message) {
1202
+ return this._addCheck({
1203
+ kind: "endsWith",
1204
+ value,
1205
+ ...errorUtil.errToObj(message)
1206
+ });
1207
+ }
1208
+ min(minLength, message) {
1209
+ return this._addCheck({
1210
+ kind: "min",
1211
+ value: minLength,
1212
+ ...errorUtil.errToObj(message)
1213
+ });
1214
+ }
1215
+ max(maxLength, message) {
1216
+ return this._addCheck({
1217
+ kind: "max",
1218
+ value: maxLength,
1219
+ ...errorUtil.errToObj(message)
1220
+ });
1221
+ }
1222
+ length(len, message) {
1223
+ return this._addCheck({
1224
+ kind: "length",
1225
+ value: len,
1226
+ ...errorUtil.errToObj(message)
1227
+ });
1228
+ }
1229
+ /**
1230
+ * @deprecated Use z.string().min(1) instead.
1231
+ * @see {@link ZodString.min}
1232
+ */
1233
+ nonempty(message) {
1234
+ return this.min(1, errorUtil.errToObj(message));
1235
+ }
1236
+ trim() {
1237
+ return new _ZodString({
1238
+ ...this._def,
1239
+ checks: [...this._def.checks, { kind: "trim" }]
1240
+ });
1241
+ }
1242
+ toLowerCase() {
1243
+ return new _ZodString({
1244
+ ...this._def,
1245
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1246
+ });
1247
+ }
1248
+ toUpperCase() {
1249
+ return new _ZodString({
1250
+ ...this._def,
1251
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1252
+ });
1253
+ }
1254
+ get isDatetime() {
1255
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1256
+ }
1257
+ get isDate() {
1258
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1259
+ }
1260
+ get isTime() {
1261
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1262
+ }
1263
+ get isDuration() {
1264
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1265
+ }
1266
+ get isEmail() {
1267
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1268
+ }
1269
+ get isURL() {
1270
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1271
+ }
1272
+ get isEmoji() {
1273
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1274
+ }
1275
+ get isUUID() {
1276
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1277
+ }
1278
+ get isNANOID() {
1279
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1280
+ }
1281
+ get isCUID() {
1282
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1283
+ }
1284
+ get isCUID2() {
1285
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1286
+ }
1287
+ get isULID() {
1288
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1289
+ }
1290
+ get isIP() {
1291
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1292
+ }
1293
+ get isBase64() {
1294
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1295
+ }
1296
+ get minLength() {
1297
+ let min = null;
1298
+ for (const ch of this._def.checks) {
1299
+ if (ch.kind === "min") {
1300
+ if (min === null || ch.value > min)
1301
+ min = ch.value;
1302
+ }
1303
+ }
1304
+ return min;
1305
+ }
1306
+ get maxLength() {
1307
+ let max = null;
1308
+ for (const ch of this._def.checks) {
1309
+ if (ch.kind === "max") {
1310
+ if (max === null || ch.value < max)
1311
+ max = ch.value;
1312
+ }
1313
+ }
1314
+ return max;
1315
+ }
1316
+ };
1317
+ ZodString.create = (params) => {
1318
+ var _a;
1319
+ return new ZodString({
1320
+ checks: [],
1321
+ typeName: ZodFirstPartyTypeKind.ZodString,
1322
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1323
+ ...processCreateParams(params)
1324
+ });
1325
+ };
1326
+ function floatSafeRemainder(val, step) {
1327
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1328
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1329
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1330
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1331
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1332
+ return valInt % stepInt / Math.pow(10, decCount);
1333
+ }
1334
+ var ZodNumber = class _ZodNumber extends ZodType {
1335
+ constructor() {
1336
+ super(...arguments);
1337
+ this.min = this.gte;
1338
+ this.max = this.lte;
1339
+ this.step = this.multipleOf;
1340
+ }
1341
+ _parse(input) {
1342
+ if (this._def.coerce) {
1343
+ input.data = Number(input.data);
1344
+ }
1345
+ const parsedType = this._getType(input);
1346
+ if (parsedType !== ZodParsedType.number) {
1347
+ const ctx2 = this._getOrReturnCtx(input);
1348
+ addIssueToContext(ctx2, {
1349
+ code: ZodIssueCode.invalid_type,
1350
+ expected: ZodParsedType.number,
1351
+ received: ctx2.parsedType
1352
+ });
1353
+ return INVALID;
1354
+ }
1355
+ let ctx = void 0;
1356
+ const status = new ParseStatus();
1357
+ for (const check of this._def.checks) {
1358
+ if (check.kind === "int") {
1359
+ if (!util.isInteger(input.data)) {
1360
+ ctx = this._getOrReturnCtx(input, ctx);
1361
+ addIssueToContext(ctx, {
1362
+ code: ZodIssueCode.invalid_type,
1363
+ expected: "integer",
1364
+ received: "float",
1365
+ message: check.message
1366
+ });
1367
+ status.dirty();
1368
+ }
1369
+ } else if (check.kind === "min") {
1370
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1371
+ if (tooSmall) {
1372
+ ctx = this._getOrReturnCtx(input, ctx);
1373
+ addIssueToContext(ctx, {
1374
+ code: ZodIssueCode.too_small,
1375
+ minimum: check.value,
1376
+ type: "number",
1377
+ inclusive: check.inclusive,
1378
+ exact: false,
1379
+ message: check.message
1380
+ });
1381
+ status.dirty();
1382
+ }
1383
+ } else if (check.kind === "max") {
1384
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1385
+ if (tooBig) {
1386
+ ctx = this._getOrReturnCtx(input, ctx);
1387
+ addIssueToContext(ctx, {
1388
+ code: ZodIssueCode.too_big,
1389
+ maximum: check.value,
1390
+ type: "number",
1391
+ inclusive: check.inclusive,
1392
+ exact: false,
1393
+ message: check.message
1394
+ });
1395
+ status.dirty();
1396
+ }
1397
+ } else if (check.kind === "multipleOf") {
1398
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1399
+ ctx = this._getOrReturnCtx(input, ctx);
1400
+ addIssueToContext(ctx, {
1401
+ code: ZodIssueCode.not_multiple_of,
1402
+ multipleOf: check.value,
1403
+ message: check.message
1404
+ });
1405
+ status.dirty();
1406
+ }
1407
+ } else if (check.kind === "finite") {
1408
+ if (!Number.isFinite(input.data)) {
1409
+ ctx = this._getOrReturnCtx(input, ctx);
1410
+ addIssueToContext(ctx, {
1411
+ code: ZodIssueCode.not_finite,
1412
+ message: check.message
1413
+ });
1414
+ status.dirty();
1415
+ }
1416
+ } else {
1417
+ util.assertNever(check);
1418
+ }
1419
+ }
1420
+ return { status: status.value, value: input.data };
1421
+ }
1422
+ gte(value, message) {
1423
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1424
+ }
1425
+ gt(value, message) {
1426
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1427
+ }
1428
+ lte(value, message) {
1429
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1430
+ }
1431
+ lt(value, message) {
1432
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1433
+ }
1434
+ setLimit(kind, value, inclusive, message) {
1435
+ return new _ZodNumber({
1436
+ ...this._def,
1437
+ checks: [
1438
+ ...this._def.checks,
1439
+ {
1440
+ kind,
1441
+ value,
1442
+ inclusive,
1443
+ message: errorUtil.toString(message)
1444
+ }
1445
+ ]
1446
+ });
1447
+ }
1448
+ _addCheck(check) {
1449
+ return new _ZodNumber({
1450
+ ...this._def,
1451
+ checks: [...this._def.checks, check]
1452
+ });
1453
+ }
1454
+ int(message) {
1455
+ return this._addCheck({
1456
+ kind: "int",
1457
+ message: errorUtil.toString(message)
1458
+ });
1459
+ }
1460
+ positive(message) {
1461
+ return this._addCheck({
1462
+ kind: "min",
1463
+ value: 0,
1464
+ inclusive: false,
1465
+ message: errorUtil.toString(message)
1466
+ });
1467
+ }
1468
+ negative(message) {
1469
+ return this._addCheck({
1470
+ kind: "max",
1471
+ value: 0,
1472
+ inclusive: false,
1473
+ message: errorUtil.toString(message)
1474
+ });
1475
+ }
1476
+ nonpositive(message) {
1477
+ return this._addCheck({
1478
+ kind: "max",
1479
+ value: 0,
1480
+ inclusive: true,
1481
+ message: errorUtil.toString(message)
1482
+ });
1483
+ }
1484
+ nonnegative(message) {
1485
+ return this._addCheck({
1486
+ kind: "min",
1487
+ value: 0,
1488
+ inclusive: true,
1489
+ message: errorUtil.toString(message)
1490
+ });
1491
+ }
1492
+ multipleOf(value, message) {
1493
+ return this._addCheck({
1494
+ kind: "multipleOf",
1495
+ value,
1496
+ message: errorUtil.toString(message)
1497
+ });
1498
+ }
1499
+ finite(message) {
1500
+ return this._addCheck({
1501
+ kind: "finite",
1502
+ message: errorUtil.toString(message)
1503
+ });
1504
+ }
1505
+ safe(message) {
1506
+ return this._addCheck({
1507
+ kind: "min",
1508
+ inclusive: true,
1509
+ value: Number.MIN_SAFE_INTEGER,
1510
+ message: errorUtil.toString(message)
1511
+ })._addCheck({
1512
+ kind: "max",
1513
+ inclusive: true,
1514
+ value: Number.MAX_SAFE_INTEGER,
1515
+ message: errorUtil.toString(message)
1516
+ });
1517
+ }
1518
+ get minValue() {
1519
+ let min = null;
1520
+ for (const ch of this._def.checks) {
1521
+ if (ch.kind === "min") {
1522
+ if (min === null || ch.value > min)
1523
+ min = ch.value;
1524
+ }
1525
+ }
1526
+ return min;
1527
+ }
1528
+ get maxValue() {
1529
+ let max = null;
1530
+ for (const ch of this._def.checks) {
1531
+ if (ch.kind === "max") {
1532
+ if (max === null || ch.value < max)
1533
+ max = ch.value;
1534
+ }
1535
+ }
1536
+ return max;
1537
+ }
1538
+ get isInt() {
1539
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1540
+ }
1541
+ get isFinite() {
1542
+ let max = null, min = null;
1543
+ for (const ch of this._def.checks) {
1544
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1545
+ return true;
1546
+ } else if (ch.kind === "min") {
1547
+ if (min === null || ch.value > min)
1548
+ min = ch.value;
1549
+ } else if (ch.kind === "max") {
1550
+ if (max === null || ch.value < max)
1551
+ max = ch.value;
1552
+ }
1553
+ }
1554
+ return Number.isFinite(min) && Number.isFinite(max);
1555
+ }
1556
+ };
1557
+ ZodNumber.create = (params) => {
1558
+ return new ZodNumber({
1559
+ checks: [],
1560
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1561
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1562
+ ...processCreateParams(params)
1563
+ });
1564
+ };
1565
+ var ZodBigInt = class _ZodBigInt extends ZodType {
1566
+ constructor() {
1567
+ super(...arguments);
1568
+ this.min = this.gte;
1569
+ this.max = this.lte;
1570
+ }
1571
+ _parse(input) {
1572
+ if (this._def.coerce) {
1573
+ input.data = BigInt(input.data);
1574
+ }
1575
+ const parsedType = this._getType(input);
1576
+ if (parsedType !== ZodParsedType.bigint) {
1577
+ const ctx2 = this._getOrReturnCtx(input);
1578
+ addIssueToContext(ctx2, {
1579
+ code: ZodIssueCode.invalid_type,
1580
+ expected: ZodParsedType.bigint,
1581
+ received: ctx2.parsedType
1582
+ });
1583
+ return INVALID;
1584
+ }
1585
+ let ctx = void 0;
1586
+ const status = new ParseStatus();
1587
+ for (const check of this._def.checks) {
1588
+ if (check.kind === "min") {
1589
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1590
+ if (tooSmall) {
1591
+ ctx = this._getOrReturnCtx(input, ctx);
1592
+ addIssueToContext(ctx, {
1593
+ code: ZodIssueCode.too_small,
1594
+ type: "bigint",
1595
+ minimum: check.value,
1596
+ inclusive: check.inclusive,
1597
+ message: check.message
1598
+ });
1599
+ status.dirty();
1600
+ }
1601
+ } else if (check.kind === "max") {
1602
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1603
+ if (tooBig) {
1604
+ ctx = this._getOrReturnCtx(input, ctx);
1605
+ addIssueToContext(ctx, {
1606
+ code: ZodIssueCode.too_big,
1607
+ type: "bigint",
1608
+ maximum: check.value,
1609
+ inclusive: check.inclusive,
1610
+ message: check.message
1611
+ });
1612
+ status.dirty();
1613
+ }
1614
+ } else if (check.kind === "multipleOf") {
1615
+ if (input.data % check.value !== BigInt(0)) {
1616
+ ctx = this._getOrReturnCtx(input, ctx);
1617
+ addIssueToContext(ctx, {
1618
+ code: ZodIssueCode.not_multiple_of,
1619
+ multipleOf: check.value,
1620
+ message: check.message
1621
+ });
1622
+ status.dirty();
1623
+ }
1624
+ } else {
1625
+ util.assertNever(check);
1626
+ }
1627
+ }
1628
+ return { status: status.value, value: input.data };
1629
+ }
1630
+ gte(value, message) {
1631
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1632
+ }
1633
+ gt(value, message) {
1634
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1635
+ }
1636
+ lte(value, message) {
1637
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1638
+ }
1639
+ lt(value, message) {
1640
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1641
+ }
1642
+ setLimit(kind, value, inclusive, message) {
1643
+ return new _ZodBigInt({
1644
+ ...this._def,
1645
+ checks: [
1646
+ ...this._def.checks,
1647
+ {
1648
+ kind,
1649
+ value,
1650
+ inclusive,
1651
+ message: errorUtil.toString(message)
1652
+ }
1653
+ ]
1654
+ });
1655
+ }
1656
+ _addCheck(check) {
1657
+ return new _ZodBigInt({
1658
+ ...this._def,
1659
+ checks: [...this._def.checks, check]
1660
+ });
1661
+ }
1662
+ positive(message) {
1663
+ return this._addCheck({
1664
+ kind: "min",
1665
+ value: BigInt(0),
1666
+ inclusive: false,
1667
+ message: errorUtil.toString(message)
1668
+ });
1669
+ }
1670
+ negative(message) {
1671
+ return this._addCheck({
1672
+ kind: "max",
1673
+ value: BigInt(0),
1674
+ inclusive: false,
1675
+ message: errorUtil.toString(message)
1676
+ });
1677
+ }
1678
+ nonpositive(message) {
1679
+ return this._addCheck({
1680
+ kind: "max",
1681
+ value: BigInt(0),
1682
+ inclusive: true,
1683
+ message: errorUtil.toString(message)
1684
+ });
1685
+ }
1686
+ nonnegative(message) {
1687
+ return this._addCheck({
1688
+ kind: "min",
1689
+ value: BigInt(0),
1690
+ inclusive: true,
1691
+ message: errorUtil.toString(message)
1692
+ });
1693
+ }
1694
+ multipleOf(value, message) {
1695
+ return this._addCheck({
1696
+ kind: "multipleOf",
1697
+ value,
1698
+ message: errorUtil.toString(message)
1699
+ });
1700
+ }
1701
+ get minValue() {
1702
+ let min = null;
1703
+ for (const ch of this._def.checks) {
1704
+ if (ch.kind === "min") {
1705
+ if (min === null || ch.value > min)
1706
+ min = ch.value;
1707
+ }
1708
+ }
1709
+ return min;
1710
+ }
1711
+ get maxValue() {
1712
+ let max = null;
1713
+ for (const ch of this._def.checks) {
1714
+ if (ch.kind === "max") {
1715
+ if (max === null || ch.value < max)
1716
+ max = ch.value;
1717
+ }
1718
+ }
1719
+ return max;
1720
+ }
1721
+ };
1722
+ ZodBigInt.create = (params) => {
1723
+ var _a;
1724
+ return new ZodBigInt({
1725
+ checks: [],
1726
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1727
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1728
+ ...processCreateParams(params)
1729
+ });
1730
+ };
1731
+ var ZodBoolean = class extends ZodType {
1732
+ _parse(input) {
1733
+ if (this._def.coerce) {
1734
+ input.data = Boolean(input.data);
1735
+ }
1736
+ const parsedType = this._getType(input);
1737
+ if (parsedType !== ZodParsedType.boolean) {
1738
+ const ctx = this._getOrReturnCtx(input);
1739
+ addIssueToContext(ctx, {
1740
+ code: ZodIssueCode.invalid_type,
1741
+ expected: ZodParsedType.boolean,
1742
+ received: ctx.parsedType
1743
+ });
1744
+ return INVALID;
1745
+ }
1746
+ return OK(input.data);
1747
+ }
1748
+ };
1749
+ ZodBoolean.create = (params) => {
1750
+ return new ZodBoolean({
1751
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1752
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1753
+ ...processCreateParams(params)
1754
+ });
1755
+ };
1756
+ var ZodDate = class _ZodDate extends ZodType {
1757
+ _parse(input) {
1758
+ if (this._def.coerce) {
1759
+ input.data = new Date(input.data);
1760
+ }
1761
+ const parsedType = this._getType(input);
1762
+ if (parsedType !== ZodParsedType.date) {
1763
+ const ctx2 = this._getOrReturnCtx(input);
1764
+ addIssueToContext(ctx2, {
1765
+ code: ZodIssueCode.invalid_type,
1766
+ expected: ZodParsedType.date,
1767
+ received: ctx2.parsedType
1768
+ });
1769
+ return INVALID;
1770
+ }
1771
+ if (isNaN(input.data.getTime())) {
1772
+ const ctx2 = this._getOrReturnCtx(input);
1773
+ addIssueToContext(ctx2, {
1774
+ code: ZodIssueCode.invalid_date
1775
+ });
1776
+ return INVALID;
1777
+ }
1778
+ const status = new ParseStatus();
1779
+ let ctx = void 0;
1780
+ for (const check of this._def.checks) {
1781
+ if (check.kind === "min") {
1782
+ if (input.data.getTime() < check.value) {
1783
+ ctx = this._getOrReturnCtx(input, ctx);
1784
+ addIssueToContext(ctx, {
1785
+ code: ZodIssueCode.too_small,
1786
+ message: check.message,
1787
+ inclusive: true,
1788
+ exact: false,
1789
+ minimum: check.value,
1790
+ type: "date"
1791
+ });
1792
+ status.dirty();
1793
+ }
1794
+ } else if (check.kind === "max") {
1795
+ if (input.data.getTime() > check.value) {
1796
+ ctx = this._getOrReturnCtx(input, ctx);
1797
+ addIssueToContext(ctx, {
1798
+ code: ZodIssueCode.too_big,
1799
+ message: check.message,
1800
+ inclusive: true,
1801
+ exact: false,
1802
+ maximum: check.value,
1803
+ type: "date"
1804
+ });
1805
+ status.dirty();
1806
+ }
1807
+ } else {
1808
+ util.assertNever(check);
1809
+ }
1810
+ }
1811
+ return {
1812
+ status: status.value,
1813
+ value: new Date(input.data.getTime())
1814
+ };
1815
+ }
1816
+ _addCheck(check) {
1817
+ return new _ZodDate({
1818
+ ...this._def,
1819
+ checks: [...this._def.checks, check]
1820
+ });
1821
+ }
1822
+ min(minDate, message) {
1823
+ return this._addCheck({
1824
+ kind: "min",
1825
+ value: minDate.getTime(),
1826
+ message: errorUtil.toString(message)
1827
+ });
1828
+ }
1829
+ max(maxDate, message) {
1830
+ return this._addCheck({
1831
+ kind: "max",
1832
+ value: maxDate.getTime(),
1833
+ message: errorUtil.toString(message)
1834
+ });
1835
+ }
1836
+ get minDate() {
1837
+ let min = null;
1838
+ for (const ch of this._def.checks) {
1839
+ if (ch.kind === "min") {
1840
+ if (min === null || ch.value > min)
1841
+ min = ch.value;
1842
+ }
1843
+ }
1844
+ return min != null ? new Date(min) : null;
1845
+ }
1846
+ get maxDate() {
1847
+ let max = null;
1848
+ for (const ch of this._def.checks) {
1849
+ if (ch.kind === "max") {
1850
+ if (max === null || ch.value < max)
1851
+ max = ch.value;
1852
+ }
1853
+ }
1854
+ return max != null ? new Date(max) : null;
1855
+ }
1856
+ };
1857
+ ZodDate.create = (params) => {
1858
+ return new ZodDate({
1859
+ checks: [],
1860
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1861
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1862
+ ...processCreateParams(params)
1863
+ });
1864
+ };
1865
+ var ZodSymbol = class extends ZodType {
1866
+ _parse(input) {
1867
+ const parsedType = this._getType(input);
1868
+ if (parsedType !== ZodParsedType.symbol) {
1869
+ const ctx = this._getOrReturnCtx(input);
1870
+ addIssueToContext(ctx, {
1871
+ code: ZodIssueCode.invalid_type,
1872
+ expected: ZodParsedType.symbol,
1873
+ received: ctx.parsedType
1874
+ });
1875
+ return INVALID;
1876
+ }
1877
+ return OK(input.data);
1878
+ }
1879
+ };
1880
+ ZodSymbol.create = (params) => {
1881
+ return new ZodSymbol({
1882
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
1883
+ ...processCreateParams(params)
1884
+ });
1885
+ };
1886
+ var ZodUndefined = class extends ZodType {
1887
+ _parse(input) {
1888
+ const parsedType = this._getType(input);
1889
+ if (parsedType !== ZodParsedType.undefined) {
1890
+ const ctx = this._getOrReturnCtx(input);
1891
+ addIssueToContext(ctx, {
1892
+ code: ZodIssueCode.invalid_type,
1893
+ expected: ZodParsedType.undefined,
1894
+ received: ctx.parsedType
1895
+ });
1896
+ return INVALID;
1897
+ }
1898
+ return OK(input.data);
1899
+ }
1900
+ };
1901
+ ZodUndefined.create = (params) => {
1902
+ return new ZodUndefined({
1903
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
1904
+ ...processCreateParams(params)
1905
+ });
1906
+ };
1907
+ var ZodNull = class extends ZodType {
1908
+ _parse(input) {
1909
+ const parsedType = this._getType(input);
1910
+ if (parsedType !== ZodParsedType.null) {
1911
+ const ctx = this._getOrReturnCtx(input);
1912
+ addIssueToContext(ctx, {
1913
+ code: ZodIssueCode.invalid_type,
1914
+ expected: ZodParsedType.null,
1915
+ received: ctx.parsedType
1916
+ });
1917
+ return INVALID;
1918
+ }
1919
+ return OK(input.data);
1920
+ }
1921
+ };
1922
+ ZodNull.create = (params) => {
1923
+ return new ZodNull({
1924
+ typeName: ZodFirstPartyTypeKind.ZodNull,
1925
+ ...processCreateParams(params)
1926
+ });
1927
+ };
1928
+ var ZodAny = class extends ZodType {
1929
+ constructor() {
1930
+ super(...arguments);
1931
+ this._any = true;
1932
+ }
1933
+ _parse(input) {
1934
+ return OK(input.data);
1935
+ }
1936
+ };
1937
+ ZodAny.create = (params) => {
1938
+ return new ZodAny({
1939
+ typeName: ZodFirstPartyTypeKind.ZodAny,
1940
+ ...processCreateParams(params)
1941
+ });
1942
+ };
1943
+ var ZodUnknown = class extends ZodType {
1944
+ constructor() {
1945
+ super(...arguments);
1946
+ this._unknown = true;
1947
+ }
1948
+ _parse(input) {
1949
+ return OK(input.data);
1950
+ }
1951
+ };
1952
+ ZodUnknown.create = (params) => {
1953
+ return new ZodUnknown({
1954
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
1955
+ ...processCreateParams(params)
1956
+ });
1957
+ };
1958
+ var ZodNever = class extends ZodType {
1959
+ _parse(input) {
1960
+ const ctx = this._getOrReturnCtx(input);
1961
+ addIssueToContext(ctx, {
1962
+ code: ZodIssueCode.invalid_type,
1963
+ expected: ZodParsedType.never,
1964
+ received: ctx.parsedType
1965
+ });
1966
+ return INVALID;
1967
+ }
1968
+ };
1969
+ ZodNever.create = (params) => {
1970
+ return new ZodNever({
1971
+ typeName: ZodFirstPartyTypeKind.ZodNever,
1972
+ ...processCreateParams(params)
1973
+ });
1974
+ };
1975
+ var ZodVoid = class extends ZodType {
1976
+ _parse(input) {
1977
+ const parsedType = this._getType(input);
1978
+ if (parsedType !== ZodParsedType.undefined) {
1979
+ const ctx = this._getOrReturnCtx(input);
1980
+ addIssueToContext(ctx, {
1981
+ code: ZodIssueCode.invalid_type,
1982
+ expected: ZodParsedType.void,
1983
+ received: ctx.parsedType
1984
+ });
1985
+ return INVALID;
1986
+ }
1987
+ return OK(input.data);
1988
+ }
1989
+ };
1990
+ ZodVoid.create = (params) => {
1991
+ return new ZodVoid({
1992
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
1993
+ ...processCreateParams(params)
1994
+ });
1995
+ };
1996
+ var ZodArray = class _ZodArray extends ZodType {
1997
+ _parse(input) {
1998
+ const { ctx, status } = this._processInputParams(input);
1999
+ const def = this._def;
2000
+ if (ctx.parsedType !== ZodParsedType.array) {
2001
+ addIssueToContext(ctx, {
2002
+ code: ZodIssueCode.invalid_type,
2003
+ expected: ZodParsedType.array,
2004
+ received: ctx.parsedType
2005
+ });
2006
+ return INVALID;
2007
+ }
2008
+ if (def.exactLength !== null) {
2009
+ const tooBig = ctx.data.length > def.exactLength.value;
2010
+ const tooSmall = ctx.data.length < def.exactLength.value;
2011
+ if (tooBig || tooSmall) {
2012
+ addIssueToContext(ctx, {
2013
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2014
+ minimum: tooSmall ? def.exactLength.value : void 0,
2015
+ maximum: tooBig ? def.exactLength.value : void 0,
2016
+ type: "array",
2017
+ inclusive: true,
2018
+ exact: true,
2019
+ message: def.exactLength.message
2020
+ });
2021
+ status.dirty();
2022
+ }
2023
+ }
2024
+ if (def.minLength !== null) {
2025
+ if (ctx.data.length < def.minLength.value) {
2026
+ addIssueToContext(ctx, {
2027
+ code: ZodIssueCode.too_small,
2028
+ minimum: def.minLength.value,
2029
+ type: "array",
2030
+ inclusive: true,
2031
+ exact: false,
2032
+ message: def.minLength.message
2033
+ });
2034
+ status.dirty();
2035
+ }
2036
+ }
2037
+ if (def.maxLength !== null) {
2038
+ if (ctx.data.length > def.maxLength.value) {
2039
+ addIssueToContext(ctx, {
2040
+ code: ZodIssueCode.too_big,
2041
+ maximum: def.maxLength.value,
2042
+ type: "array",
2043
+ inclusive: true,
2044
+ exact: false,
2045
+ message: def.maxLength.message
2046
+ });
2047
+ status.dirty();
2048
+ }
2049
+ }
2050
+ if (ctx.common.async) {
2051
+ return Promise.all([...ctx.data].map((item, i) => {
2052
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2053
+ })).then((result2) => {
2054
+ return ParseStatus.mergeArray(status, result2);
2055
+ });
2056
+ }
2057
+ const result = [...ctx.data].map((item, i) => {
2058
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2059
+ });
2060
+ return ParseStatus.mergeArray(status, result);
2061
+ }
2062
+ get element() {
2063
+ return this._def.type;
2064
+ }
2065
+ min(minLength, message) {
2066
+ return new _ZodArray({
2067
+ ...this._def,
2068
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2069
+ });
2070
+ }
2071
+ max(maxLength, message) {
2072
+ return new _ZodArray({
2073
+ ...this._def,
2074
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2075
+ });
2076
+ }
2077
+ length(len, message) {
2078
+ return new _ZodArray({
2079
+ ...this._def,
2080
+ exactLength: { value: len, message: errorUtil.toString(message) }
2081
+ });
2082
+ }
2083
+ nonempty(message) {
2084
+ return this.min(1, message);
2085
+ }
2086
+ };
2087
+ ZodArray.create = (schema, params) => {
2088
+ return new ZodArray({
2089
+ type: schema,
2090
+ minLength: null,
2091
+ maxLength: null,
2092
+ exactLength: null,
2093
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2094
+ ...processCreateParams(params)
2095
+ });
2096
+ };
2097
+ function deepPartialify(schema) {
2098
+ if (schema instanceof ZodObject) {
2099
+ const newShape = {};
2100
+ for (const key in schema.shape) {
2101
+ const fieldSchema = schema.shape[key];
2102
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2103
+ }
2104
+ return new ZodObject({
2105
+ ...schema._def,
2106
+ shape: () => newShape
2107
+ });
2108
+ } else if (schema instanceof ZodArray) {
2109
+ return new ZodArray({
2110
+ ...schema._def,
2111
+ type: deepPartialify(schema.element)
2112
+ });
2113
+ } else if (schema instanceof ZodOptional) {
2114
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2115
+ } else if (schema instanceof ZodNullable) {
2116
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2117
+ } else if (schema instanceof ZodTuple) {
2118
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2119
+ } else {
2120
+ return schema;
2121
+ }
2122
+ }
2123
+ var ZodObject = class _ZodObject extends ZodType {
2124
+ constructor() {
2125
+ super(...arguments);
2126
+ this._cached = null;
2127
+ this.nonstrict = this.passthrough;
2128
+ this.augment = this.extend;
2129
+ }
2130
+ _getCached() {
2131
+ if (this._cached !== null)
2132
+ return this._cached;
2133
+ const shape = this._def.shape();
2134
+ const keys = util.objectKeys(shape);
2135
+ return this._cached = { shape, keys };
2136
+ }
2137
+ _parse(input) {
2138
+ const parsedType = this._getType(input);
2139
+ if (parsedType !== ZodParsedType.object) {
2140
+ const ctx2 = this._getOrReturnCtx(input);
2141
+ addIssueToContext(ctx2, {
2142
+ code: ZodIssueCode.invalid_type,
2143
+ expected: ZodParsedType.object,
2144
+ received: ctx2.parsedType
2145
+ });
2146
+ return INVALID;
2147
+ }
2148
+ const { status, ctx } = this._processInputParams(input);
2149
+ const { shape, keys: shapeKeys } = this._getCached();
2150
+ const extraKeys = [];
2151
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2152
+ for (const key in ctx.data) {
2153
+ if (!shapeKeys.includes(key)) {
2154
+ extraKeys.push(key);
2155
+ }
2156
+ }
2157
+ }
2158
+ const pairs = [];
2159
+ for (const key of shapeKeys) {
2160
+ const keyValidator = shape[key];
2161
+ const value = ctx.data[key];
2162
+ pairs.push({
2163
+ key: { status: "valid", value: key },
2164
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2165
+ alwaysSet: key in ctx.data
2166
+ });
2167
+ }
2168
+ if (this._def.catchall instanceof ZodNever) {
2169
+ const unknownKeys = this._def.unknownKeys;
2170
+ if (unknownKeys === "passthrough") {
2171
+ for (const key of extraKeys) {
2172
+ pairs.push({
2173
+ key: { status: "valid", value: key },
2174
+ value: { status: "valid", value: ctx.data[key] }
2175
+ });
2176
+ }
2177
+ } else if (unknownKeys === "strict") {
2178
+ if (extraKeys.length > 0) {
2179
+ addIssueToContext(ctx, {
2180
+ code: ZodIssueCode.unrecognized_keys,
2181
+ keys: extraKeys
2182
+ });
2183
+ status.dirty();
2184
+ }
2185
+ } else if (unknownKeys === "strip") ;
2186
+ else {
2187
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2188
+ }
2189
+ } else {
2190
+ const catchall = this._def.catchall;
2191
+ for (const key of extraKeys) {
2192
+ const value = ctx.data[key];
2193
+ pairs.push({
2194
+ key: { status: "valid", value: key },
2195
+ value: catchall._parse(
2196
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2197
+ //, ctx.child(key), value, getParsedType(value)
2198
+ ),
2199
+ alwaysSet: key in ctx.data
2200
+ });
2201
+ }
2202
+ }
2203
+ if (ctx.common.async) {
2204
+ return Promise.resolve().then(async () => {
2205
+ const syncPairs = [];
2206
+ for (const pair of pairs) {
2207
+ const key = await pair.key;
2208
+ const value = await pair.value;
2209
+ syncPairs.push({
2210
+ key,
2211
+ value,
2212
+ alwaysSet: pair.alwaysSet
2213
+ });
2214
+ }
2215
+ return syncPairs;
2216
+ }).then((syncPairs) => {
2217
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2218
+ });
2219
+ } else {
2220
+ return ParseStatus.mergeObjectSync(status, pairs);
2221
+ }
2222
+ }
2223
+ get shape() {
2224
+ return this._def.shape();
2225
+ }
2226
+ strict(message) {
2227
+ errorUtil.errToObj;
2228
+ return new _ZodObject({
2229
+ ...this._def,
2230
+ unknownKeys: "strict",
2231
+ ...message !== void 0 ? {
2232
+ errorMap: (issue, ctx) => {
2233
+ var _a, _b, _c, _d;
2234
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
2235
+ if (issue.code === "unrecognized_keys")
2236
+ return {
2237
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
2238
+ };
2239
+ return {
2240
+ message: defaultError
2241
+ };
2242
+ }
2243
+ } : {}
2244
+ });
2245
+ }
2246
+ strip() {
2247
+ return new _ZodObject({
2248
+ ...this._def,
2249
+ unknownKeys: "strip"
2250
+ });
2251
+ }
2252
+ passthrough() {
2253
+ return new _ZodObject({
2254
+ ...this._def,
2255
+ unknownKeys: "passthrough"
2256
+ });
2257
+ }
2258
+ // const AugmentFactory =
2259
+ // <Def extends ZodObjectDef>(def: Def) =>
2260
+ // <Augmentation extends ZodRawShape>(
2261
+ // augmentation: Augmentation
2262
+ // ): ZodObject<
2263
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2264
+ // Def["unknownKeys"],
2265
+ // Def["catchall"]
2266
+ // > => {
2267
+ // return new ZodObject({
2268
+ // ...def,
2269
+ // shape: () => ({
2270
+ // ...def.shape(),
2271
+ // ...augmentation,
2272
+ // }),
2273
+ // }) as any;
2274
+ // };
2275
+ extend(augmentation) {
2276
+ return new _ZodObject({
2277
+ ...this._def,
2278
+ shape: () => ({
2279
+ ...this._def.shape(),
2280
+ ...augmentation
2281
+ })
2282
+ });
2283
+ }
2284
+ /**
2285
+ * Prior to zod@1.0.12 there was a bug in the
2286
+ * inferred type of merged objects. Please
2287
+ * upgrade if you are experiencing issues.
2288
+ */
2289
+ merge(merging) {
2290
+ const merged = new _ZodObject({
2291
+ unknownKeys: merging._def.unknownKeys,
2292
+ catchall: merging._def.catchall,
2293
+ shape: () => ({
2294
+ ...this._def.shape(),
2295
+ ...merging._def.shape()
2296
+ }),
2297
+ typeName: ZodFirstPartyTypeKind.ZodObject
2298
+ });
2299
+ return merged;
2300
+ }
2301
+ // merge<
2302
+ // Incoming extends AnyZodObject,
2303
+ // Augmentation extends Incoming["shape"],
2304
+ // NewOutput extends {
2305
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2306
+ // ? Augmentation[k]["_output"]
2307
+ // : k extends keyof Output
2308
+ // ? Output[k]
2309
+ // : never;
2310
+ // },
2311
+ // NewInput extends {
2312
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2313
+ // ? Augmentation[k]["_input"]
2314
+ // : k extends keyof Input
2315
+ // ? Input[k]
2316
+ // : never;
2317
+ // }
2318
+ // >(
2319
+ // merging: Incoming
2320
+ // ): ZodObject<
2321
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2322
+ // Incoming["_def"]["unknownKeys"],
2323
+ // Incoming["_def"]["catchall"],
2324
+ // NewOutput,
2325
+ // NewInput
2326
+ // > {
2327
+ // const merged: any = new ZodObject({
2328
+ // unknownKeys: merging._def.unknownKeys,
2329
+ // catchall: merging._def.catchall,
2330
+ // shape: () =>
2331
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2332
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2333
+ // }) as any;
2334
+ // return merged;
2335
+ // }
2336
+ setKey(key, schema) {
2337
+ return this.augment({ [key]: schema });
2338
+ }
2339
+ // merge<Incoming extends AnyZodObject>(
2340
+ // merging: Incoming
2341
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2342
+ // ZodObject<
2343
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2344
+ // Incoming["_def"]["unknownKeys"],
2345
+ // Incoming["_def"]["catchall"]
2346
+ // > {
2347
+ // // const mergedShape = objectUtil.mergeShapes(
2348
+ // // this._def.shape(),
2349
+ // // merging._def.shape()
2350
+ // // );
2351
+ // const merged: any = new ZodObject({
2352
+ // unknownKeys: merging._def.unknownKeys,
2353
+ // catchall: merging._def.catchall,
2354
+ // shape: () =>
2355
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2356
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2357
+ // }) as any;
2358
+ // return merged;
2359
+ // }
2360
+ catchall(index) {
2361
+ return new _ZodObject({
2362
+ ...this._def,
2363
+ catchall: index
2364
+ });
2365
+ }
2366
+ pick(mask) {
2367
+ const shape = {};
2368
+ util.objectKeys(mask).forEach((key) => {
2369
+ if (mask[key] && this.shape[key]) {
2370
+ shape[key] = this.shape[key];
2371
+ }
2372
+ });
2373
+ return new _ZodObject({
2374
+ ...this._def,
2375
+ shape: () => shape
2376
+ });
2377
+ }
2378
+ omit(mask) {
2379
+ const shape = {};
2380
+ util.objectKeys(this.shape).forEach((key) => {
2381
+ if (!mask[key]) {
2382
+ shape[key] = this.shape[key];
2383
+ }
2384
+ });
2385
+ return new _ZodObject({
2386
+ ...this._def,
2387
+ shape: () => shape
2388
+ });
2389
+ }
2390
+ /**
2391
+ * @deprecated
2392
+ */
2393
+ deepPartial() {
2394
+ return deepPartialify(this);
2395
+ }
2396
+ partial(mask) {
2397
+ const newShape = {};
2398
+ util.objectKeys(this.shape).forEach((key) => {
2399
+ const fieldSchema = this.shape[key];
2400
+ if (mask && !mask[key]) {
2401
+ newShape[key] = fieldSchema;
2402
+ } else {
2403
+ newShape[key] = fieldSchema.optional();
2404
+ }
2405
+ });
2406
+ return new _ZodObject({
2407
+ ...this._def,
2408
+ shape: () => newShape
2409
+ });
2410
+ }
2411
+ required(mask) {
2412
+ const newShape = {};
2413
+ util.objectKeys(this.shape).forEach((key) => {
2414
+ if (mask && !mask[key]) {
2415
+ newShape[key] = this.shape[key];
2416
+ } else {
2417
+ const fieldSchema = this.shape[key];
2418
+ let newField = fieldSchema;
2419
+ while (newField instanceof ZodOptional) {
2420
+ newField = newField._def.innerType;
2421
+ }
2422
+ newShape[key] = newField;
2423
+ }
2424
+ });
2425
+ return new _ZodObject({
2426
+ ...this._def,
2427
+ shape: () => newShape
2428
+ });
2429
+ }
2430
+ keyof() {
2431
+ return createZodEnum(util.objectKeys(this.shape));
2432
+ }
2433
+ };
2434
+ ZodObject.create = (shape, params) => {
2435
+ return new ZodObject({
2436
+ shape: () => shape,
2437
+ unknownKeys: "strip",
2438
+ catchall: ZodNever.create(),
2439
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2440
+ ...processCreateParams(params)
2441
+ });
2442
+ };
2443
+ ZodObject.strictCreate = (shape, params) => {
2444
+ return new ZodObject({
2445
+ shape: () => shape,
2446
+ unknownKeys: "strict",
2447
+ catchall: ZodNever.create(),
2448
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2449
+ ...processCreateParams(params)
2450
+ });
2451
+ };
2452
+ ZodObject.lazycreate = (shape, params) => {
2453
+ return new ZodObject({
2454
+ shape,
2455
+ unknownKeys: "strip",
2456
+ catchall: ZodNever.create(),
2457
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2458
+ ...processCreateParams(params)
2459
+ });
2460
+ };
2461
+ var ZodUnion = class extends ZodType {
2462
+ _parse(input) {
2463
+ const { ctx } = this._processInputParams(input);
2464
+ const options = this._def.options;
2465
+ function handleResults(results) {
2466
+ for (const result of results) {
2467
+ if (result.result.status === "valid") {
2468
+ return result.result;
2469
+ }
2470
+ }
2471
+ for (const result of results) {
2472
+ if (result.result.status === "dirty") {
2473
+ ctx.common.issues.push(...result.ctx.common.issues);
2474
+ return result.result;
2475
+ }
2476
+ }
2477
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2478
+ addIssueToContext(ctx, {
2479
+ code: ZodIssueCode.invalid_union,
2480
+ unionErrors
2481
+ });
2482
+ return INVALID;
2483
+ }
2484
+ if (ctx.common.async) {
2485
+ return Promise.all(options.map(async (option) => {
2486
+ const childCtx = {
2487
+ ...ctx,
2488
+ common: {
2489
+ ...ctx.common,
2490
+ issues: []
2491
+ },
2492
+ parent: null
2493
+ };
2494
+ return {
2495
+ result: await option._parseAsync({
2496
+ data: ctx.data,
2497
+ path: ctx.path,
2498
+ parent: childCtx
2499
+ }),
2500
+ ctx: childCtx
2501
+ };
2502
+ })).then(handleResults);
2503
+ } else {
2504
+ let dirty = void 0;
2505
+ const issues = [];
2506
+ for (const option of options) {
2507
+ const childCtx = {
2508
+ ...ctx,
2509
+ common: {
2510
+ ...ctx.common,
2511
+ issues: []
2512
+ },
2513
+ parent: null
2514
+ };
2515
+ const result = option._parseSync({
2516
+ data: ctx.data,
2517
+ path: ctx.path,
2518
+ parent: childCtx
2519
+ });
2520
+ if (result.status === "valid") {
2521
+ return result;
2522
+ } else if (result.status === "dirty" && !dirty) {
2523
+ dirty = { result, ctx: childCtx };
2524
+ }
2525
+ if (childCtx.common.issues.length) {
2526
+ issues.push(childCtx.common.issues);
2527
+ }
2528
+ }
2529
+ if (dirty) {
2530
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2531
+ return dirty.result;
2532
+ }
2533
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
2534
+ addIssueToContext(ctx, {
2535
+ code: ZodIssueCode.invalid_union,
2536
+ unionErrors
2537
+ });
2538
+ return INVALID;
2539
+ }
2540
+ }
2541
+ get options() {
2542
+ return this._def.options;
2543
+ }
2544
+ };
2545
+ ZodUnion.create = (types, params) => {
2546
+ return new ZodUnion({
2547
+ options: types,
2548
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2549
+ ...processCreateParams(params)
2550
+ });
2551
+ };
2552
+ var getDiscriminator = (type) => {
2553
+ if (type instanceof ZodLazy) {
2554
+ return getDiscriminator(type.schema);
2555
+ } else if (type instanceof ZodEffects) {
2556
+ return getDiscriminator(type.innerType());
2557
+ } else if (type instanceof ZodLiteral) {
2558
+ return [type.value];
2559
+ } else if (type instanceof ZodEnum) {
2560
+ return type.options;
2561
+ } else if (type instanceof ZodNativeEnum) {
2562
+ return util.objectValues(type.enum);
2563
+ } else if (type instanceof ZodDefault) {
2564
+ return getDiscriminator(type._def.innerType);
2565
+ } else if (type instanceof ZodUndefined) {
2566
+ return [void 0];
2567
+ } else if (type instanceof ZodNull) {
2568
+ return [null];
2569
+ } else if (type instanceof ZodOptional) {
2570
+ return [void 0, ...getDiscriminator(type.unwrap())];
2571
+ } else if (type instanceof ZodNullable) {
2572
+ return [null, ...getDiscriminator(type.unwrap())];
2573
+ } else if (type instanceof ZodBranded) {
2574
+ return getDiscriminator(type.unwrap());
2575
+ } else if (type instanceof ZodReadonly) {
2576
+ return getDiscriminator(type.unwrap());
2577
+ } else if (type instanceof ZodCatch) {
2578
+ return getDiscriminator(type._def.innerType);
2579
+ } else {
2580
+ return [];
2581
+ }
2582
+ };
2583
+ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
2584
+ _parse(input) {
2585
+ const { ctx } = this._processInputParams(input);
2586
+ if (ctx.parsedType !== ZodParsedType.object) {
2587
+ addIssueToContext(ctx, {
2588
+ code: ZodIssueCode.invalid_type,
2589
+ expected: ZodParsedType.object,
2590
+ received: ctx.parsedType
2591
+ });
2592
+ return INVALID;
2593
+ }
2594
+ const discriminator = this.discriminator;
2595
+ const discriminatorValue = ctx.data[discriminator];
2596
+ const option = this.optionsMap.get(discriminatorValue);
2597
+ if (!option) {
2598
+ addIssueToContext(ctx, {
2599
+ code: ZodIssueCode.invalid_union_discriminator,
2600
+ options: Array.from(this.optionsMap.keys()),
2601
+ path: [discriminator]
2602
+ });
2603
+ return INVALID;
2604
+ }
2605
+ if (ctx.common.async) {
2606
+ return option._parseAsync({
2607
+ data: ctx.data,
2608
+ path: ctx.path,
2609
+ parent: ctx
2610
+ });
2611
+ } else {
2612
+ return option._parseSync({
2613
+ data: ctx.data,
2614
+ path: ctx.path,
2615
+ parent: ctx
2616
+ });
2617
+ }
2618
+ }
2619
+ get discriminator() {
2620
+ return this._def.discriminator;
2621
+ }
2622
+ get options() {
2623
+ return this._def.options;
2624
+ }
2625
+ get optionsMap() {
2626
+ return this._def.optionsMap;
2627
+ }
2628
+ /**
2629
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2630
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2631
+ * have a different value for each object in the union.
2632
+ * @param discriminator the name of the discriminator property
2633
+ * @param types an array of object schemas
2634
+ * @param params
2635
+ */
2636
+ static create(discriminator, options, params) {
2637
+ const optionsMap = /* @__PURE__ */ new Map();
2638
+ for (const type of options) {
2639
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2640
+ if (!discriminatorValues.length) {
2641
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2642
+ }
2643
+ for (const value of discriminatorValues) {
2644
+ if (optionsMap.has(value)) {
2645
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2646
+ }
2647
+ optionsMap.set(value, type);
2648
+ }
2649
+ }
2650
+ return new _ZodDiscriminatedUnion({
2651
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2652
+ discriminator,
2653
+ options,
2654
+ optionsMap,
2655
+ ...processCreateParams(params)
2656
+ });
2657
+ }
2658
+ };
2659
+ function mergeValues(a, b) {
2660
+ const aType = getParsedType(a);
2661
+ const bType = getParsedType(b);
2662
+ if (a === b) {
2663
+ return { valid: true, data: a };
2664
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2665
+ const bKeys = util.objectKeys(b);
2666
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2667
+ const newObj = { ...a, ...b };
2668
+ for (const key of sharedKeys) {
2669
+ const sharedValue = mergeValues(a[key], b[key]);
2670
+ if (!sharedValue.valid) {
2671
+ return { valid: false };
2672
+ }
2673
+ newObj[key] = sharedValue.data;
2674
+ }
2675
+ return { valid: true, data: newObj };
2676
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2677
+ if (a.length !== b.length) {
2678
+ return { valid: false };
2679
+ }
2680
+ const newArray = [];
2681
+ for (let index = 0; index < a.length; index++) {
2682
+ const itemA = a[index];
2683
+ const itemB = b[index];
2684
+ const sharedValue = mergeValues(itemA, itemB);
2685
+ if (!sharedValue.valid) {
2686
+ return { valid: false };
2687
+ }
2688
+ newArray.push(sharedValue.data);
2689
+ }
2690
+ return { valid: true, data: newArray };
2691
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
2692
+ return { valid: true, data: a };
2693
+ } else {
2694
+ return { valid: false };
2695
+ }
2696
+ }
2697
+ var ZodIntersection = class extends ZodType {
2698
+ _parse(input) {
2699
+ const { status, ctx } = this._processInputParams(input);
2700
+ const handleParsed = (parsedLeft, parsedRight) => {
2701
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2702
+ return INVALID;
2703
+ }
2704
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2705
+ if (!merged.valid) {
2706
+ addIssueToContext(ctx, {
2707
+ code: ZodIssueCode.invalid_intersection_types
2708
+ });
2709
+ return INVALID;
2710
+ }
2711
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2712
+ status.dirty();
2713
+ }
2714
+ return { status: status.value, value: merged.data };
2715
+ };
2716
+ if (ctx.common.async) {
2717
+ return Promise.all([
2718
+ this._def.left._parseAsync({
2719
+ data: ctx.data,
2720
+ path: ctx.path,
2721
+ parent: ctx
2722
+ }),
2723
+ this._def.right._parseAsync({
2724
+ data: ctx.data,
2725
+ path: ctx.path,
2726
+ parent: ctx
2727
+ })
2728
+ ]).then(([left, right]) => handleParsed(left, right));
2729
+ } else {
2730
+ return handleParsed(this._def.left._parseSync({
2731
+ data: ctx.data,
2732
+ path: ctx.path,
2733
+ parent: ctx
2734
+ }), this._def.right._parseSync({
2735
+ data: ctx.data,
2736
+ path: ctx.path,
2737
+ parent: ctx
2738
+ }));
2739
+ }
2740
+ }
2741
+ };
2742
+ ZodIntersection.create = (left, right, params) => {
2743
+ return new ZodIntersection({
2744
+ left,
2745
+ right,
2746
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2747
+ ...processCreateParams(params)
2748
+ });
2749
+ };
2750
+ var ZodTuple = class _ZodTuple extends ZodType {
2751
+ _parse(input) {
2752
+ const { status, ctx } = this._processInputParams(input);
2753
+ if (ctx.parsedType !== ZodParsedType.array) {
2754
+ addIssueToContext(ctx, {
2755
+ code: ZodIssueCode.invalid_type,
2756
+ expected: ZodParsedType.array,
2757
+ received: ctx.parsedType
2758
+ });
2759
+ return INVALID;
2760
+ }
2761
+ if (ctx.data.length < this._def.items.length) {
2762
+ addIssueToContext(ctx, {
2763
+ code: ZodIssueCode.too_small,
2764
+ minimum: this._def.items.length,
2765
+ inclusive: true,
2766
+ exact: false,
2767
+ type: "array"
2768
+ });
2769
+ return INVALID;
2770
+ }
2771
+ const rest = this._def.rest;
2772
+ if (!rest && ctx.data.length > this._def.items.length) {
2773
+ addIssueToContext(ctx, {
2774
+ code: ZodIssueCode.too_big,
2775
+ maximum: this._def.items.length,
2776
+ inclusive: true,
2777
+ exact: false,
2778
+ type: "array"
2779
+ });
2780
+ status.dirty();
2781
+ }
2782
+ const items = [...ctx.data].map((item, itemIndex) => {
2783
+ const schema = this._def.items[itemIndex] || this._def.rest;
2784
+ if (!schema)
2785
+ return null;
2786
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2787
+ }).filter((x) => !!x);
2788
+ if (ctx.common.async) {
2789
+ return Promise.all(items).then((results) => {
2790
+ return ParseStatus.mergeArray(status, results);
2791
+ });
2792
+ } else {
2793
+ return ParseStatus.mergeArray(status, items);
2794
+ }
2795
+ }
2796
+ get items() {
2797
+ return this._def.items;
2798
+ }
2799
+ rest(rest) {
2800
+ return new _ZodTuple({
2801
+ ...this._def,
2802
+ rest
2803
+ });
2804
+ }
2805
+ };
2806
+ ZodTuple.create = (schemas, params) => {
2807
+ if (!Array.isArray(schemas)) {
2808
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2809
+ }
2810
+ return new ZodTuple({
2811
+ items: schemas,
2812
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2813
+ rest: null,
2814
+ ...processCreateParams(params)
2815
+ });
2816
+ };
2817
+ var ZodRecord = class _ZodRecord extends ZodType {
2818
+ get keySchema() {
2819
+ return this._def.keyType;
2820
+ }
2821
+ get valueSchema() {
2822
+ return this._def.valueType;
2823
+ }
2824
+ _parse(input) {
2825
+ const { status, ctx } = this._processInputParams(input);
2826
+ if (ctx.parsedType !== ZodParsedType.object) {
2827
+ addIssueToContext(ctx, {
2828
+ code: ZodIssueCode.invalid_type,
2829
+ expected: ZodParsedType.object,
2830
+ received: ctx.parsedType
2831
+ });
2832
+ return INVALID;
2833
+ }
2834
+ const pairs = [];
2835
+ const keyType = this._def.keyType;
2836
+ const valueType = this._def.valueType;
2837
+ for (const key in ctx.data) {
2838
+ pairs.push({
2839
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2840
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2841
+ alwaysSet: key in ctx.data
2842
+ });
2843
+ }
2844
+ if (ctx.common.async) {
2845
+ return ParseStatus.mergeObjectAsync(status, pairs);
2846
+ } else {
2847
+ return ParseStatus.mergeObjectSync(status, pairs);
2848
+ }
2849
+ }
2850
+ get element() {
2851
+ return this._def.valueType;
2852
+ }
2853
+ static create(first, second, third) {
2854
+ if (second instanceof ZodType) {
2855
+ return new _ZodRecord({
2856
+ keyType: first,
2857
+ valueType: second,
2858
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2859
+ ...processCreateParams(third)
2860
+ });
2861
+ }
2862
+ return new _ZodRecord({
2863
+ keyType: ZodString.create(),
2864
+ valueType: first,
2865
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2866
+ ...processCreateParams(second)
2867
+ });
2868
+ }
2869
+ };
2870
+ var ZodMap = class extends ZodType {
2871
+ get keySchema() {
2872
+ return this._def.keyType;
2873
+ }
2874
+ get valueSchema() {
2875
+ return this._def.valueType;
2876
+ }
2877
+ _parse(input) {
2878
+ const { status, ctx } = this._processInputParams(input);
2879
+ if (ctx.parsedType !== ZodParsedType.map) {
2880
+ addIssueToContext(ctx, {
2881
+ code: ZodIssueCode.invalid_type,
2882
+ expected: ZodParsedType.map,
2883
+ received: ctx.parsedType
2884
+ });
2885
+ return INVALID;
2886
+ }
2887
+ const keyType = this._def.keyType;
2888
+ const valueType = this._def.valueType;
2889
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2890
+ return {
2891
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2892
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
2893
+ };
2894
+ });
2895
+ if (ctx.common.async) {
2896
+ const finalMap = /* @__PURE__ */ new Map();
2897
+ return Promise.resolve().then(async () => {
2898
+ for (const pair of pairs) {
2899
+ const key = await pair.key;
2900
+ const value = await pair.value;
2901
+ if (key.status === "aborted" || value.status === "aborted") {
2902
+ return INVALID;
2903
+ }
2904
+ if (key.status === "dirty" || value.status === "dirty") {
2905
+ status.dirty();
2906
+ }
2907
+ finalMap.set(key.value, value.value);
2908
+ }
2909
+ return { status: status.value, value: finalMap };
2910
+ });
2911
+ } else {
2912
+ const finalMap = /* @__PURE__ */ new Map();
2913
+ for (const pair of pairs) {
2914
+ const key = pair.key;
2915
+ const value = pair.value;
2916
+ if (key.status === "aborted" || value.status === "aborted") {
2917
+ return INVALID;
2918
+ }
2919
+ if (key.status === "dirty" || value.status === "dirty") {
2920
+ status.dirty();
2921
+ }
2922
+ finalMap.set(key.value, value.value);
2923
+ }
2924
+ return { status: status.value, value: finalMap };
2925
+ }
2926
+ }
2927
+ };
2928
+ ZodMap.create = (keyType, valueType, params) => {
2929
+ return new ZodMap({
2930
+ valueType,
2931
+ keyType,
2932
+ typeName: ZodFirstPartyTypeKind.ZodMap,
2933
+ ...processCreateParams(params)
2934
+ });
2935
+ };
2936
+ var ZodSet = class _ZodSet extends ZodType {
2937
+ _parse(input) {
2938
+ const { status, ctx } = this._processInputParams(input);
2939
+ if (ctx.parsedType !== ZodParsedType.set) {
2940
+ addIssueToContext(ctx, {
2941
+ code: ZodIssueCode.invalid_type,
2942
+ expected: ZodParsedType.set,
2943
+ received: ctx.parsedType
2944
+ });
2945
+ return INVALID;
2946
+ }
2947
+ const def = this._def;
2948
+ if (def.minSize !== null) {
2949
+ if (ctx.data.size < def.minSize.value) {
2950
+ addIssueToContext(ctx, {
2951
+ code: ZodIssueCode.too_small,
2952
+ minimum: def.minSize.value,
2953
+ type: "set",
2954
+ inclusive: true,
2955
+ exact: false,
2956
+ message: def.minSize.message
2957
+ });
2958
+ status.dirty();
2959
+ }
2960
+ }
2961
+ if (def.maxSize !== null) {
2962
+ if (ctx.data.size > def.maxSize.value) {
2963
+ addIssueToContext(ctx, {
2964
+ code: ZodIssueCode.too_big,
2965
+ maximum: def.maxSize.value,
2966
+ type: "set",
2967
+ inclusive: true,
2968
+ exact: false,
2969
+ message: def.maxSize.message
2970
+ });
2971
+ status.dirty();
2972
+ }
2973
+ }
2974
+ const valueType = this._def.valueType;
2975
+ function finalizeSet(elements2) {
2976
+ const parsedSet = /* @__PURE__ */ new Set();
2977
+ for (const element of elements2) {
2978
+ if (element.status === "aborted")
2979
+ return INVALID;
2980
+ if (element.status === "dirty")
2981
+ status.dirty();
2982
+ parsedSet.add(element.value);
2983
+ }
2984
+ return { status: status.value, value: parsedSet };
2985
+ }
2986
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2987
+ if (ctx.common.async) {
2988
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
2989
+ } else {
2990
+ return finalizeSet(elements);
2991
+ }
2992
+ }
2993
+ min(minSize, message) {
2994
+ return new _ZodSet({
2995
+ ...this._def,
2996
+ minSize: { value: minSize, message: errorUtil.toString(message) }
2997
+ });
2998
+ }
2999
+ max(maxSize, message) {
3000
+ return new _ZodSet({
3001
+ ...this._def,
3002
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3003
+ });
3004
+ }
3005
+ size(size, message) {
3006
+ return this.min(size, message).max(size, message);
3007
+ }
3008
+ nonempty(message) {
3009
+ return this.min(1, message);
3010
+ }
3011
+ };
3012
+ ZodSet.create = (valueType, params) => {
3013
+ return new ZodSet({
3014
+ valueType,
3015
+ minSize: null,
3016
+ maxSize: null,
3017
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3018
+ ...processCreateParams(params)
3019
+ });
3020
+ };
3021
+ var ZodFunction = class _ZodFunction extends ZodType {
3022
+ constructor() {
3023
+ super(...arguments);
3024
+ this.validate = this.implement;
3025
+ }
3026
+ _parse(input) {
3027
+ const { ctx } = this._processInputParams(input);
3028
+ if (ctx.parsedType !== ZodParsedType.function) {
3029
+ addIssueToContext(ctx, {
3030
+ code: ZodIssueCode.invalid_type,
3031
+ expected: ZodParsedType.function,
3032
+ received: ctx.parsedType
3033
+ });
3034
+ return INVALID;
3035
+ }
3036
+ function makeArgsIssue(args, error) {
3037
+ return makeIssue({
3038
+ data: args,
3039
+ path: ctx.path,
3040
+ errorMaps: [
3041
+ ctx.common.contextualErrorMap,
3042
+ ctx.schemaErrorMap,
3043
+ getErrorMap(),
3044
+ errorMap
3045
+ ].filter((x) => !!x),
3046
+ issueData: {
3047
+ code: ZodIssueCode.invalid_arguments,
3048
+ argumentsError: error
3049
+ }
3050
+ });
3051
+ }
3052
+ function makeReturnsIssue(returns, error) {
3053
+ return makeIssue({
3054
+ data: returns,
3055
+ path: ctx.path,
3056
+ errorMaps: [
3057
+ ctx.common.contextualErrorMap,
3058
+ ctx.schemaErrorMap,
3059
+ getErrorMap(),
3060
+ errorMap
3061
+ ].filter((x) => !!x),
3062
+ issueData: {
3063
+ code: ZodIssueCode.invalid_return_type,
3064
+ returnTypeError: error
3065
+ }
3066
+ });
3067
+ }
3068
+ const params = { errorMap: ctx.common.contextualErrorMap };
3069
+ const fn = ctx.data;
3070
+ if (this._def.returns instanceof ZodPromise) {
3071
+ const me = this;
3072
+ return OK(async function(...args) {
3073
+ const error = new ZodError([]);
3074
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3075
+ error.addIssue(makeArgsIssue(args, e));
3076
+ throw error;
3077
+ });
3078
+ const result = await Reflect.apply(fn, this, parsedArgs);
3079
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3080
+ error.addIssue(makeReturnsIssue(result, e));
3081
+ throw error;
3082
+ });
3083
+ return parsedReturns;
3084
+ });
3085
+ } else {
3086
+ const me = this;
3087
+ return OK(function(...args) {
3088
+ const parsedArgs = me._def.args.safeParse(args, params);
3089
+ if (!parsedArgs.success) {
3090
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3091
+ }
3092
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3093
+ const parsedReturns = me._def.returns.safeParse(result, params);
3094
+ if (!parsedReturns.success) {
3095
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3096
+ }
3097
+ return parsedReturns.data;
3098
+ });
3099
+ }
3100
+ }
3101
+ parameters() {
3102
+ return this._def.args;
3103
+ }
3104
+ returnType() {
3105
+ return this._def.returns;
3106
+ }
3107
+ args(...items) {
3108
+ return new _ZodFunction({
3109
+ ...this._def,
3110
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3111
+ });
3112
+ }
3113
+ returns(returnType) {
3114
+ return new _ZodFunction({
3115
+ ...this._def,
3116
+ returns: returnType
3117
+ });
3118
+ }
3119
+ implement(func) {
3120
+ const validatedFunc = this.parse(func);
3121
+ return validatedFunc;
3122
+ }
3123
+ strictImplement(func) {
3124
+ const validatedFunc = this.parse(func);
3125
+ return validatedFunc;
3126
+ }
3127
+ static create(args, returns, params) {
3128
+ return new _ZodFunction({
3129
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3130
+ returns: returns || ZodUnknown.create(),
3131
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3132
+ ...processCreateParams(params)
3133
+ });
3134
+ }
3135
+ };
3136
+ var ZodLazy = class extends ZodType {
3137
+ get schema() {
3138
+ return this._def.getter();
3139
+ }
3140
+ _parse(input) {
3141
+ const { ctx } = this._processInputParams(input);
3142
+ const lazySchema = this._def.getter();
3143
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3144
+ }
3145
+ };
3146
+ ZodLazy.create = (getter, params) => {
3147
+ return new ZodLazy({
3148
+ getter,
3149
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3150
+ ...processCreateParams(params)
3151
+ });
3152
+ };
3153
+ var ZodLiteral = class extends ZodType {
3154
+ _parse(input) {
3155
+ if (input.data !== this._def.value) {
3156
+ const ctx = this._getOrReturnCtx(input);
3157
+ addIssueToContext(ctx, {
3158
+ received: ctx.data,
3159
+ code: ZodIssueCode.invalid_literal,
3160
+ expected: this._def.value
3161
+ });
3162
+ return INVALID;
3163
+ }
3164
+ return { status: "valid", value: input.data };
3165
+ }
3166
+ get value() {
3167
+ return this._def.value;
3168
+ }
3169
+ };
3170
+ ZodLiteral.create = (value, params) => {
3171
+ return new ZodLiteral({
3172
+ value,
3173
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3174
+ ...processCreateParams(params)
3175
+ });
3176
+ };
3177
+ function createZodEnum(values, params) {
3178
+ return new ZodEnum({
3179
+ values,
3180
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3181
+ ...processCreateParams(params)
3182
+ });
3183
+ }
3184
+ var ZodEnum = class _ZodEnum extends ZodType {
3185
+ constructor() {
3186
+ super(...arguments);
3187
+ _ZodEnum_cache.set(this, void 0);
3188
+ }
3189
+ _parse(input) {
3190
+ if (typeof input.data !== "string") {
3191
+ const ctx = this._getOrReturnCtx(input);
3192
+ const expectedValues = this._def.values;
3193
+ addIssueToContext(ctx, {
3194
+ expected: util.joinValues(expectedValues),
3195
+ received: ctx.parsedType,
3196
+ code: ZodIssueCode.invalid_type
3197
+ });
3198
+ return INVALID;
3199
+ }
3200
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
3201
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
3202
+ }
3203
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
3204
+ const ctx = this._getOrReturnCtx(input);
3205
+ const expectedValues = this._def.values;
3206
+ addIssueToContext(ctx, {
3207
+ received: ctx.data,
3208
+ code: ZodIssueCode.invalid_enum_value,
3209
+ options: expectedValues
3210
+ });
3211
+ return INVALID;
3212
+ }
3213
+ return OK(input.data);
3214
+ }
3215
+ get options() {
3216
+ return this._def.values;
3217
+ }
3218
+ get enum() {
3219
+ const enumValues = {};
3220
+ for (const val of this._def.values) {
3221
+ enumValues[val] = val;
3222
+ }
3223
+ return enumValues;
3224
+ }
3225
+ get Values() {
3226
+ const enumValues = {};
3227
+ for (const val of this._def.values) {
3228
+ enumValues[val] = val;
3229
+ }
3230
+ return enumValues;
3231
+ }
3232
+ get Enum() {
3233
+ const enumValues = {};
3234
+ for (const val of this._def.values) {
3235
+ enumValues[val] = val;
3236
+ }
3237
+ return enumValues;
3238
+ }
3239
+ extract(values, newDef = this._def) {
3240
+ return _ZodEnum.create(values, {
3241
+ ...this._def,
3242
+ ...newDef
3243
+ });
3244
+ }
3245
+ exclude(values, newDef = this._def) {
3246
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3247
+ ...this._def,
3248
+ ...newDef
3249
+ });
3250
+ }
3251
+ };
3252
+ _ZodEnum_cache = /* @__PURE__ */ new WeakMap();
3253
+ ZodEnum.create = createZodEnum;
3254
+ var ZodNativeEnum = class extends ZodType {
3255
+ constructor() {
3256
+ super(...arguments);
3257
+ _ZodNativeEnum_cache.set(this, void 0);
3258
+ }
3259
+ _parse(input) {
3260
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3261
+ const ctx = this._getOrReturnCtx(input);
3262
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3263
+ const expectedValues = util.objectValues(nativeEnumValues);
3264
+ addIssueToContext(ctx, {
3265
+ expected: util.joinValues(expectedValues),
3266
+ received: ctx.parsedType,
3267
+ code: ZodIssueCode.invalid_type
3268
+ });
3269
+ return INVALID;
3270
+ }
3271
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
3272
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
3273
+ }
3274
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
3275
+ const expectedValues = util.objectValues(nativeEnumValues);
3276
+ addIssueToContext(ctx, {
3277
+ received: ctx.data,
3278
+ code: ZodIssueCode.invalid_enum_value,
3279
+ options: expectedValues
3280
+ });
3281
+ return INVALID;
3282
+ }
3283
+ return OK(input.data);
3284
+ }
3285
+ get enum() {
3286
+ return this._def.values;
3287
+ }
3288
+ };
3289
+ _ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
3290
+ ZodNativeEnum.create = (values, params) => {
3291
+ return new ZodNativeEnum({
3292
+ values,
3293
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3294
+ ...processCreateParams(params)
3295
+ });
3296
+ };
3297
+ var ZodPromise = class extends ZodType {
3298
+ unwrap() {
3299
+ return this._def.type;
3300
+ }
3301
+ _parse(input) {
3302
+ const { ctx } = this._processInputParams(input);
3303
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3304
+ addIssueToContext(ctx, {
3305
+ code: ZodIssueCode.invalid_type,
3306
+ expected: ZodParsedType.promise,
3307
+ received: ctx.parsedType
3308
+ });
3309
+ return INVALID;
3310
+ }
3311
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3312
+ return OK(promisified.then((data) => {
3313
+ return this._def.type.parseAsync(data, {
3314
+ path: ctx.path,
3315
+ errorMap: ctx.common.contextualErrorMap
3316
+ });
3317
+ }));
3318
+ }
3319
+ };
3320
+ ZodPromise.create = (schema, params) => {
3321
+ return new ZodPromise({
3322
+ type: schema,
3323
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3324
+ ...processCreateParams(params)
3325
+ });
3326
+ };
3327
+ var ZodEffects = class extends ZodType {
3328
+ innerType() {
3329
+ return this._def.schema;
3330
+ }
3331
+ sourceType() {
3332
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3333
+ }
3334
+ _parse(input) {
3335
+ const { status, ctx } = this._processInputParams(input);
3336
+ const effect = this._def.effect || null;
3337
+ const checkCtx = {
3338
+ addIssue: (arg) => {
3339
+ addIssueToContext(ctx, arg);
3340
+ if (arg.fatal) {
3341
+ status.abort();
3342
+ } else {
3343
+ status.dirty();
3344
+ }
3345
+ },
3346
+ get path() {
3347
+ return ctx.path;
3348
+ }
3349
+ };
3350
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3351
+ if (effect.type === "preprocess") {
3352
+ const processed = effect.transform(ctx.data, checkCtx);
3353
+ if (ctx.common.async) {
3354
+ return Promise.resolve(processed).then(async (processed2) => {
3355
+ if (status.value === "aborted")
3356
+ return INVALID;
3357
+ const result = await this._def.schema._parseAsync({
3358
+ data: processed2,
3359
+ path: ctx.path,
3360
+ parent: ctx
3361
+ });
3362
+ if (result.status === "aborted")
3363
+ return INVALID;
3364
+ if (result.status === "dirty")
3365
+ return DIRTY(result.value);
3366
+ if (status.value === "dirty")
3367
+ return DIRTY(result.value);
3368
+ return result;
3369
+ });
3370
+ } else {
3371
+ if (status.value === "aborted")
3372
+ return INVALID;
3373
+ const result = this._def.schema._parseSync({
3374
+ data: processed,
3375
+ path: ctx.path,
3376
+ parent: ctx
3377
+ });
3378
+ if (result.status === "aborted")
3379
+ return INVALID;
3380
+ if (result.status === "dirty")
3381
+ return DIRTY(result.value);
3382
+ if (status.value === "dirty")
3383
+ return DIRTY(result.value);
3384
+ return result;
3385
+ }
3386
+ }
3387
+ if (effect.type === "refinement") {
3388
+ const executeRefinement = (acc) => {
3389
+ const result = effect.refinement(acc, checkCtx);
3390
+ if (ctx.common.async) {
3391
+ return Promise.resolve(result);
3392
+ }
3393
+ if (result instanceof Promise) {
3394
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3395
+ }
3396
+ return acc;
3397
+ };
3398
+ if (ctx.common.async === false) {
3399
+ const inner = this._def.schema._parseSync({
3400
+ data: ctx.data,
3401
+ path: ctx.path,
3402
+ parent: ctx
3403
+ });
3404
+ if (inner.status === "aborted")
3405
+ return INVALID;
3406
+ if (inner.status === "dirty")
3407
+ status.dirty();
3408
+ executeRefinement(inner.value);
3409
+ return { status: status.value, value: inner.value };
3410
+ } else {
3411
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3412
+ if (inner.status === "aborted")
3413
+ return INVALID;
3414
+ if (inner.status === "dirty")
3415
+ status.dirty();
3416
+ return executeRefinement(inner.value).then(() => {
3417
+ return { status: status.value, value: inner.value };
3418
+ });
3419
+ });
3420
+ }
3421
+ }
3422
+ if (effect.type === "transform") {
3423
+ if (ctx.common.async === false) {
3424
+ const base = this._def.schema._parseSync({
3425
+ data: ctx.data,
3426
+ path: ctx.path,
3427
+ parent: ctx
3428
+ });
3429
+ if (!isValid(base))
3430
+ return base;
3431
+ const result = effect.transform(base.value, checkCtx);
3432
+ if (result instanceof Promise) {
3433
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3434
+ }
3435
+ return { status: status.value, value: result };
3436
+ } else {
3437
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3438
+ if (!isValid(base))
3439
+ return base;
3440
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3441
+ });
3442
+ }
3443
+ }
3444
+ util.assertNever(effect);
3445
+ }
3446
+ };
3447
+ ZodEffects.create = (schema, effect, params) => {
3448
+ return new ZodEffects({
3449
+ schema,
3450
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3451
+ effect,
3452
+ ...processCreateParams(params)
3453
+ });
3454
+ };
3455
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3456
+ return new ZodEffects({
3457
+ schema,
3458
+ effect: { type: "preprocess", transform: preprocess },
3459
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3460
+ ...processCreateParams(params)
3461
+ });
3462
+ };
3463
+ var ZodOptional = class extends ZodType {
3464
+ _parse(input) {
3465
+ const parsedType = this._getType(input);
3466
+ if (parsedType === ZodParsedType.undefined) {
3467
+ return OK(void 0);
3468
+ }
3469
+ return this._def.innerType._parse(input);
3470
+ }
3471
+ unwrap() {
3472
+ return this._def.innerType;
3473
+ }
3474
+ };
3475
+ ZodOptional.create = (type, params) => {
3476
+ return new ZodOptional({
3477
+ innerType: type,
3478
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3479
+ ...processCreateParams(params)
3480
+ });
3481
+ };
3482
+ var ZodNullable = class extends ZodType {
3483
+ _parse(input) {
3484
+ const parsedType = this._getType(input);
3485
+ if (parsedType === ZodParsedType.null) {
3486
+ return OK(null);
3487
+ }
3488
+ return this._def.innerType._parse(input);
3489
+ }
3490
+ unwrap() {
3491
+ return this._def.innerType;
3492
+ }
3493
+ };
3494
+ ZodNullable.create = (type, params) => {
3495
+ return new ZodNullable({
3496
+ innerType: type,
3497
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3498
+ ...processCreateParams(params)
3499
+ });
3500
+ };
3501
+ var ZodDefault = class extends ZodType {
3502
+ _parse(input) {
3503
+ const { ctx } = this._processInputParams(input);
3504
+ let data = ctx.data;
3505
+ if (ctx.parsedType === ZodParsedType.undefined) {
3506
+ data = this._def.defaultValue();
3507
+ }
3508
+ return this._def.innerType._parse({
3509
+ data,
3510
+ path: ctx.path,
3511
+ parent: ctx
3512
+ });
3513
+ }
3514
+ removeDefault() {
3515
+ return this._def.innerType;
3516
+ }
3517
+ };
3518
+ ZodDefault.create = (type, params) => {
3519
+ return new ZodDefault({
3520
+ innerType: type,
3521
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3522
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3523
+ ...processCreateParams(params)
3524
+ });
3525
+ };
3526
+ var ZodCatch = class extends ZodType {
3527
+ _parse(input) {
3528
+ const { ctx } = this._processInputParams(input);
3529
+ const newCtx = {
3530
+ ...ctx,
3531
+ common: {
3532
+ ...ctx.common,
3533
+ issues: []
3534
+ }
3535
+ };
3536
+ const result = this._def.innerType._parse({
3537
+ data: newCtx.data,
3538
+ path: newCtx.path,
3539
+ parent: {
3540
+ ...newCtx
3541
+ }
3542
+ });
3543
+ if (isAsync(result)) {
3544
+ return result.then((result2) => {
3545
+ return {
3546
+ status: "valid",
3547
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
3548
+ get error() {
3549
+ return new ZodError(newCtx.common.issues);
3550
+ },
3551
+ input: newCtx.data
3552
+ })
3553
+ };
3554
+ });
3555
+ } else {
3556
+ return {
3557
+ status: "valid",
3558
+ value: result.status === "valid" ? result.value : this._def.catchValue({
3559
+ get error() {
3560
+ return new ZodError(newCtx.common.issues);
3561
+ },
3562
+ input: newCtx.data
3563
+ })
3564
+ };
3565
+ }
3566
+ }
3567
+ removeCatch() {
3568
+ return this._def.innerType;
3569
+ }
3570
+ };
3571
+ ZodCatch.create = (type, params) => {
3572
+ return new ZodCatch({
3573
+ innerType: type,
3574
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3575
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3576
+ ...processCreateParams(params)
3577
+ });
3578
+ };
3579
+ var ZodNaN = class extends ZodType {
3580
+ _parse(input) {
3581
+ const parsedType = this._getType(input);
3582
+ if (parsedType !== ZodParsedType.nan) {
3583
+ const ctx = this._getOrReturnCtx(input);
3584
+ addIssueToContext(ctx, {
3585
+ code: ZodIssueCode.invalid_type,
3586
+ expected: ZodParsedType.nan,
3587
+ received: ctx.parsedType
3588
+ });
3589
+ return INVALID;
3590
+ }
3591
+ return { status: "valid", value: input.data };
3592
+ }
3593
+ };
3594
+ ZodNaN.create = (params) => {
3595
+ return new ZodNaN({
3596
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3597
+ ...processCreateParams(params)
3598
+ });
3599
+ };
3600
+ var BRAND = Symbol("zod_brand");
3601
+ var ZodBranded = class extends ZodType {
3602
+ _parse(input) {
3603
+ const { ctx } = this._processInputParams(input);
3604
+ const data = ctx.data;
3605
+ return this._def.type._parse({
3606
+ data,
3607
+ path: ctx.path,
3608
+ parent: ctx
3609
+ });
3610
+ }
3611
+ unwrap() {
3612
+ return this._def.type;
3613
+ }
3614
+ };
3615
+ var ZodPipeline = class _ZodPipeline extends ZodType {
3616
+ _parse(input) {
3617
+ const { status, ctx } = this._processInputParams(input);
3618
+ if (ctx.common.async) {
3619
+ const handleAsync = async () => {
3620
+ const inResult = await this._def.in._parseAsync({
3621
+ data: ctx.data,
3622
+ path: ctx.path,
3623
+ parent: ctx
3624
+ });
3625
+ if (inResult.status === "aborted")
3626
+ return INVALID;
3627
+ if (inResult.status === "dirty") {
3628
+ status.dirty();
3629
+ return DIRTY(inResult.value);
3630
+ } else {
3631
+ return this._def.out._parseAsync({
3632
+ data: inResult.value,
3633
+ path: ctx.path,
3634
+ parent: ctx
3635
+ });
3636
+ }
3637
+ };
3638
+ return handleAsync();
3639
+ } else {
3640
+ const inResult = this._def.in._parseSync({
3641
+ data: ctx.data,
3642
+ path: ctx.path,
3643
+ parent: ctx
3644
+ });
3645
+ if (inResult.status === "aborted")
3646
+ return INVALID;
3647
+ if (inResult.status === "dirty") {
3648
+ status.dirty();
3649
+ return {
3650
+ status: "dirty",
3651
+ value: inResult.value
3652
+ };
3653
+ } else {
3654
+ return this._def.out._parseSync({
3655
+ data: inResult.value,
3656
+ path: ctx.path,
3657
+ parent: ctx
3658
+ });
3659
+ }
3660
+ }
3661
+ }
3662
+ static create(a, b) {
3663
+ return new _ZodPipeline({
3664
+ in: a,
3665
+ out: b,
3666
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
3667
+ });
3668
+ }
3669
+ };
3670
+ var ZodReadonly = class extends ZodType {
3671
+ _parse(input) {
3672
+ const result = this._def.innerType._parse(input);
3673
+ const freeze = (data) => {
3674
+ if (isValid(data)) {
3675
+ data.value = Object.freeze(data.value);
3676
+ }
3677
+ return data;
3678
+ };
3679
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3680
+ }
3681
+ unwrap() {
3682
+ return this._def.innerType;
3683
+ }
3684
+ };
3685
+ ZodReadonly.create = (type, params) => {
3686
+ return new ZodReadonly({
3687
+ innerType: type,
3688
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3689
+ ...processCreateParams(params)
3690
+ });
3691
+ };
3692
+ function custom(check, params = {}, fatal) {
3693
+ if (check)
3694
+ return ZodAny.create().superRefine((data, ctx) => {
3695
+ var _a, _b;
3696
+ if (!check(data)) {
3697
+ const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3698
+ const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
3699
+ const p2 = typeof p === "string" ? { message: p } : p;
3700
+ ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
3701
+ }
3702
+ });
3703
+ return ZodAny.create();
3704
+ }
3705
+ var late = {
3706
+ object: ZodObject.lazycreate
3707
+ };
3708
+ var ZodFirstPartyTypeKind;
3709
+ (function(ZodFirstPartyTypeKind2) {
3710
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3711
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3712
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3713
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3714
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3715
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3716
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3717
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3718
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3719
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3720
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3721
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3722
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3723
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3724
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3725
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3726
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3727
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3728
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3729
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3730
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3731
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3732
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3733
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3734
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3735
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3736
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3737
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3738
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3739
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
3740
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
3741
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
3742
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
3743
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
3744
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
3745
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
3746
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3747
+ var instanceOfType = (cls, params = {
3748
+ message: `Input not instance of ${cls.name}`
3749
+ }) => custom((data) => data instanceof cls, params);
3750
+ var stringType = ZodString.create;
3751
+ var numberType = ZodNumber.create;
3752
+ var nanType = ZodNaN.create;
3753
+ var bigIntType = ZodBigInt.create;
3754
+ var booleanType = ZodBoolean.create;
3755
+ var dateType = ZodDate.create;
3756
+ var symbolType = ZodSymbol.create;
3757
+ var undefinedType = ZodUndefined.create;
3758
+ var nullType = ZodNull.create;
3759
+ var anyType = ZodAny.create;
3760
+ var unknownType = ZodUnknown.create;
3761
+ var neverType = ZodNever.create;
3762
+ var voidType = ZodVoid.create;
3763
+ var arrayType = ZodArray.create;
3764
+ var objectType = ZodObject.create;
3765
+ var strictObjectType = ZodObject.strictCreate;
3766
+ var unionType = ZodUnion.create;
3767
+ var discriminatedUnionType = ZodDiscriminatedUnion.create;
3768
+ var intersectionType = ZodIntersection.create;
3769
+ var tupleType = ZodTuple.create;
3770
+ var recordType = ZodRecord.create;
3771
+ var mapType = ZodMap.create;
3772
+ var setType = ZodSet.create;
3773
+ var functionType = ZodFunction.create;
3774
+ var lazyType = ZodLazy.create;
3775
+ var literalType = ZodLiteral.create;
3776
+ var enumType = ZodEnum.create;
3777
+ var nativeEnumType = ZodNativeEnum.create;
3778
+ var promiseType = ZodPromise.create;
3779
+ var effectsType = ZodEffects.create;
3780
+ var optionalType = ZodOptional.create;
3781
+ var nullableType = ZodNullable.create;
3782
+ var preprocessType = ZodEffects.createWithPreprocess;
3783
+ var pipelineType = ZodPipeline.create;
3784
+ var ostring = () => stringType().optional();
3785
+ var onumber = () => numberType().optional();
3786
+ var oboolean = () => booleanType().optional();
3787
+ var coerce = {
3788
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
3789
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
3790
+ boolean: ((arg) => ZodBoolean.create({
3791
+ ...arg,
3792
+ coerce: true
3793
+ })),
3794
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
3795
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
3796
+ };
3797
+ var NEVER = INVALID;
3798
+ var z = /* @__PURE__ */ Object.freeze({
3799
+ __proto__: null,
3800
+ defaultErrorMap: errorMap,
3801
+ setErrorMap,
3802
+ getErrorMap,
3803
+ makeIssue,
3804
+ EMPTY_PATH,
3805
+ addIssueToContext,
3806
+ ParseStatus,
3807
+ INVALID,
3808
+ DIRTY,
3809
+ OK,
3810
+ isAborted,
3811
+ isDirty,
3812
+ isValid,
3813
+ isAsync,
3814
+ get util() {
3815
+ return util;
3816
+ },
3817
+ get objectUtil() {
3818
+ return objectUtil;
3819
+ },
3820
+ ZodParsedType,
3821
+ getParsedType,
3822
+ ZodType,
3823
+ datetimeRegex,
3824
+ ZodString,
3825
+ ZodNumber,
3826
+ ZodBigInt,
3827
+ ZodBoolean,
3828
+ ZodDate,
3829
+ ZodSymbol,
3830
+ ZodUndefined,
3831
+ ZodNull,
3832
+ ZodAny,
3833
+ ZodUnknown,
3834
+ ZodNever,
3835
+ ZodVoid,
3836
+ ZodArray,
3837
+ ZodObject,
3838
+ ZodUnion,
3839
+ ZodDiscriminatedUnion,
3840
+ ZodIntersection,
3841
+ ZodTuple,
3842
+ ZodRecord,
3843
+ ZodMap,
3844
+ ZodSet,
3845
+ ZodFunction,
3846
+ ZodLazy,
3847
+ ZodLiteral,
3848
+ ZodEnum,
3849
+ ZodNativeEnum,
3850
+ ZodPromise,
3851
+ ZodEffects,
3852
+ ZodTransformer: ZodEffects,
3853
+ ZodOptional,
3854
+ ZodNullable,
3855
+ ZodDefault,
3856
+ ZodCatch,
3857
+ ZodNaN,
3858
+ BRAND,
3859
+ ZodBranded,
3860
+ ZodPipeline,
3861
+ ZodReadonly,
3862
+ custom,
3863
+ Schema: ZodType,
3864
+ ZodSchema: ZodType,
3865
+ late,
3866
+ get ZodFirstPartyTypeKind() {
3867
+ return ZodFirstPartyTypeKind;
3868
+ },
3869
+ coerce,
3870
+ any: anyType,
3871
+ array: arrayType,
3872
+ bigint: bigIntType,
3873
+ boolean: booleanType,
3874
+ date: dateType,
3875
+ discriminatedUnion: discriminatedUnionType,
3876
+ effect: effectsType,
3877
+ "enum": enumType,
3878
+ "function": functionType,
3879
+ "instanceof": instanceOfType,
3880
+ intersection: intersectionType,
3881
+ lazy: lazyType,
3882
+ literal: literalType,
3883
+ map: mapType,
3884
+ nan: nanType,
3885
+ nativeEnum: nativeEnumType,
3886
+ never: neverType,
3887
+ "null": nullType,
3888
+ nullable: nullableType,
3889
+ number: numberType,
3890
+ object: objectType,
3891
+ oboolean,
3892
+ onumber,
3893
+ optional: optionalType,
3894
+ ostring,
3895
+ pipeline: pipelineType,
3896
+ preprocess: preprocessType,
3897
+ promise: promiseType,
3898
+ record: recordType,
3899
+ set: setType,
3900
+ strictObject: strictObjectType,
3901
+ string: stringType,
3902
+ symbol: symbolType,
3903
+ transformer: effectsType,
3904
+ tuple: tupleType,
3905
+ "undefined": undefinedType,
3906
+ union: unionType,
3907
+ unknown: unknownType,
3908
+ "void": voidType,
3909
+ NEVER,
3910
+ ZodIssueCode,
3911
+ quotelessJson,
3912
+ ZodError
3913
+ });
3914
+ export {
3915
+ BRAND,
3916
+ DIRTY,
3917
+ EMPTY_PATH,
3918
+ INVALID,
3919
+ NEVER,
3920
+ OK,
3921
+ ParseStatus,
3922
+ ZodType as Schema,
3923
+ ZodAny,
3924
+ ZodArray,
3925
+ ZodBigInt,
3926
+ ZodBoolean,
3927
+ ZodBranded,
3928
+ ZodCatch,
3929
+ ZodDate,
3930
+ ZodDefault,
3931
+ ZodDiscriminatedUnion,
3932
+ ZodEffects,
3933
+ ZodEnum,
3934
+ ZodError,
3935
+ ZodFirstPartyTypeKind,
3936
+ ZodFunction,
3937
+ ZodIntersection,
3938
+ ZodIssueCode,
3939
+ ZodLazy,
3940
+ ZodLiteral,
3941
+ ZodMap,
3942
+ ZodNaN,
3943
+ ZodNativeEnum,
3944
+ ZodNever,
3945
+ ZodNull,
3946
+ ZodNullable,
3947
+ ZodNumber,
3948
+ ZodObject,
3949
+ ZodOptional,
3950
+ ZodParsedType,
3951
+ ZodPipeline,
3952
+ ZodPromise,
3953
+ ZodReadonly,
3954
+ ZodRecord,
3955
+ ZodType as ZodSchema,
3956
+ ZodSet,
3957
+ ZodString,
3958
+ ZodSymbol,
3959
+ ZodEffects as ZodTransformer,
3960
+ ZodTuple,
3961
+ ZodType,
3962
+ ZodUndefined,
3963
+ ZodUnion,
3964
+ ZodUnknown,
3965
+ ZodVoid,
3966
+ addIssueToContext,
3967
+ anyType as any,
3968
+ arrayType as array,
3969
+ bigIntType as bigint,
3970
+ booleanType as boolean,
3971
+ coerce,
3972
+ custom,
3973
+ dateType as date,
3974
+ datetimeRegex,
3975
+ errorMap as defaultErrorMap,
3976
+ discriminatedUnionType as discriminatedUnion,
3977
+ effectsType as effect,
3978
+ enumType as enum,
3979
+ functionType as function,
3980
+ getErrorMap,
3981
+ getParsedType,
3982
+ instanceOfType as instanceof,
3983
+ intersectionType as intersection,
3984
+ isAborted,
3985
+ isAsync,
3986
+ isDirty,
3987
+ isValid,
3988
+ late,
3989
+ lazyType as lazy,
3990
+ literalType as literal,
3991
+ makeIssue,
3992
+ mapType as map,
3993
+ nanType as nan,
3994
+ nativeEnumType as nativeEnum,
3995
+ neverType as never,
3996
+ nullType as null,
3997
+ nullableType as nullable,
3998
+ numberType as number,
3999
+ objectType as object,
4000
+ objectUtil,
4001
+ oboolean,
4002
+ onumber,
4003
+ optionalType as optional,
4004
+ ostring,
4005
+ pipelineType as pipeline,
4006
+ preprocessType as preprocess,
4007
+ promiseType as promise,
4008
+ quotelessJson,
4009
+ recordType as record,
4010
+ setType as set,
4011
+ setErrorMap,
4012
+ strictObjectType as strictObject,
4013
+ stringType as string,
4014
+ symbolType as symbol,
4015
+ effectsType as transformer,
4016
+ tupleType as tuple,
4017
+ undefinedType as undefined,
4018
+ unionType as union,
4019
+ unknownType as unknown,
4020
+ util,
4021
+ voidType as void,
4022
+ z
4023
+ };