@seed-ship/mcp-ui-solid 5.4.0 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/mcp-ui-spec/dist/schemas.cjs +493 -0
  3. package/dist/mcp-ui-spec/dist/schemas.cjs.map +1 -0
  4. package/dist/mcp-ui-spec/dist/schemas.js +493 -0
  5. package/dist/mcp-ui-spec/dist/schemas.js.map +1 -0
  6. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.cjs +118 -0
  7. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.cjs.map +1 -0
  8. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js +118 -0
  9. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js.map +1 -0
  10. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.cjs +10 -0
  11. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.cjs.map +1 -0
  12. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js +10 -0
  13. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js.map +1 -0
  14. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.cjs +8 -0
  15. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.cjs.map +1 -0
  16. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js +9 -0
  17. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js.map +1 -0
  18. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.cjs +122 -0
  19. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.cjs.map +1 -0
  20. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js +122 -0
  21. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js.map +1 -0
  22. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.cjs +137 -0
  23. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.cjs.map +1 -0
  24. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js +139 -0
  25. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js.map +1 -0
  26. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.cjs +105 -0
  27. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.cjs.map +1 -0
  28. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js +106 -0
  29. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js.map +1 -0
  30. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs +3229 -0
  31. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.cjs.map +1 -0
  32. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js +3230 -0
  33. package/dist/node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js.map +1 -0
  34. package/dist/services/validation.cjs +70 -152
  35. package/dist/services/validation.cjs.map +1 -1
  36. package/dist/services/validation.d.ts.map +1 -1
  37. package/dist/services/validation.js +70 -152
  38. package/dist/services/validation.js.map +1 -1
  39. package/package.json +3 -2
  40. package/src/services/validation.spec-migration.test.ts +207 -0
  41. package/src/services/validation.ts +132 -178
  42. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,3230 @@
1
+ import { ZodIssueCode, ZodError } from "./ZodError.js";
2
+ import { errorUtil } from "./helpers/errorUtil.js";
3
+ import { addIssueToContext, INVALID, ParseStatus, OK, isAsync, isValid, DIRTY, isAborted, isDirty } from "./helpers/parseUtil.js";
4
+ import { util, ZodParsedType, getParsedType } from "./helpers/util.js";
5
+ class ParseInputLazyPath {
6
+ constructor(parent, value, path, key) {
7
+ this._cachedPath = [];
8
+ this.parent = parent;
9
+ this.data = value;
10
+ this._path = path;
11
+ this._key = key;
12
+ }
13
+ get path() {
14
+ if (!this._cachedPath.length) {
15
+ if (Array.isArray(this._key)) {
16
+ this._cachedPath.push(...this._path, ...this._key);
17
+ } else {
18
+ this._cachedPath.push(...this._path, this._key);
19
+ }
20
+ }
21
+ return this._cachedPath;
22
+ }
23
+ }
24
+ const handleResult = (ctx, result) => {
25
+ if (isValid(result)) {
26
+ return { success: true, data: result.value };
27
+ } else {
28
+ if (!ctx.common.issues.length) {
29
+ throw new Error("Validation failed but no issues detected.");
30
+ }
31
+ return {
32
+ success: false,
33
+ get error() {
34
+ if (this._error)
35
+ return this._error;
36
+ const error = new ZodError(ctx.common.issues);
37
+ this._error = error;
38
+ return this._error;
39
+ }
40
+ };
41
+ }
42
+ };
43
+ function processCreateParams(params) {
44
+ if (!params)
45
+ return {};
46
+ const { errorMap, invalid_type_error, required_error, description } = params;
47
+ if (errorMap && (invalid_type_error || required_error)) {
48
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
49
+ }
50
+ if (errorMap)
51
+ return { errorMap, description };
52
+ const customMap = (iss, ctx) => {
53
+ const { message } = params;
54
+ if (iss.code === "invalid_enum_value") {
55
+ return { message: message ?? ctx.defaultError };
56
+ }
57
+ if (typeof ctx.data === "undefined") {
58
+ return { message: message ?? required_error ?? ctx.defaultError };
59
+ }
60
+ if (iss.code !== "invalid_type")
61
+ return { message: ctx.defaultError };
62
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
63
+ };
64
+ return { errorMap: customMap, description };
65
+ }
66
+ class ZodType {
67
+ get description() {
68
+ return this._def.description;
69
+ }
70
+ _getType(input) {
71
+ return getParsedType(input.data);
72
+ }
73
+ _getOrReturnCtx(input, ctx) {
74
+ return ctx || {
75
+ common: input.parent.common,
76
+ data: input.data,
77
+ parsedType: getParsedType(input.data),
78
+ schemaErrorMap: this._def.errorMap,
79
+ path: input.path,
80
+ parent: input.parent
81
+ };
82
+ }
83
+ _processInputParams(input) {
84
+ return {
85
+ status: new ParseStatus(),
86
+ ctx: {
87
+ common: input.parent.common,
88
+ data: input.data,
89
+ parsedType: getParsedType(input.data),
90
+ schemaErrorMap: this._def.errorMap,
91
+ path: input.path,
92
+ parent: input.parent
93
+ }
94
+ };
95
+ }
96
+ _parseSync(input) {
97
+ const result = this._parse(input);
98
+ if (isAsync(result)) {
99
+ throw new Error("Synchronous parse encountered promise.");
100
+ }
101
+ return result;
102
+ }
103
+ _parseAsync(input) {
104
+ const result = this._parse(input);
105
+ return Promise.resolve(result);
106
+ }
107
+ parse(data, params) {
108
+ const result = this.safeParse(data, params);
109
+ if (result.success)
110
+ return result.data;
111
+ throw result.error;
112
+ }
113
+ safeParse(data, params) {
114
+ const ctx = {
115
+ common: {
116
+ issues: [],
117
+ async: (params == null ? void 0 : params.async) ?? false,
118
+ contextualErrorMap: params == null ? void 0 : params.errorMap
119
+ },
120
+ path: (params == null ? void 0 : params.path) || [],
121
+ schemaErrorMap: this._def.errorMap,
122
+ parent: null,
123
+ data,
124
+ parsedType: getParsedType(data)
125
+ };
126
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
127
+ return handleResult(ctx, result);
128
+ }
129
+ "~validate"(data) {
130
+ var _a, _b;
131
+ const ctx = {
132
+ common: {
133
+ issues: [],
134
+ async: !!this["~standard"].async
135
+ },
136
+ path: [],
137
+ schemaErrorMap: this._def.errorMap,
138
+ parent: null,
139
+ data,
140
+ parsedType: getParsedType(data)
141
+ };
142
+ if (!this["~standard"].async) {
143
+ try {
144
+ const result = this._parseSync({ data, path: [], parent: ctx });
145
+ return isValid(result) ? {
146
+ value: result.value
147
+ } : {
148
+ issues: ctx.common.issues
149
+ };
150
+ } catch (err) {
151
+ if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
152
+ this["~standard"].async = true;
153
+ }
154
+ ctx.common = {
155
+ issues: [],
156
+ async: true
157
+ };
158
+ }
159
+ }
160
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
161
+ value: result.value
162
+ } : {
163
+ issues: ctx.common.issues
164
+ });
165
+ }
166
+ async parseAsync(data, params) {
167
+ const result = await this.safeParseAsync(data, params);
168
+ if (result.success)
169
+ return result.data;
170
+ throw result.error;
171
+ }
172
+ async safeParseAsync(data, params) {
173
+ const ctx = {
174
+ common: {
175
+ issues: [],
176
+ contextualErrorMap: params == null ? void 0 : params.errorMap,
177
+ async: true
178
+ },
179
+ path: (params == null ? void 0 : params.path) || [],
180
+ schemaErrorMap: this._def.errorMap,
181
+ parent: null,
182
+ data,
183
+ parsedType: getParsedType(data)
184
+ };
185
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
186
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
187
+ return handleResult(ctx, result);
188
+ }
189
+ refine(check, message) {
190
+ const getIssueProperties = (val) => {
191
+ if (typeof message === "string" || typeof message === "undefined") {
192
+ return { message };
193
+ } else if (typeof message === "function") {
194
+ return message(val);
195
+ } else {
196
+ return message;
197
+ }
198
+ };
199
+ return this._refinement((val, ctx) => {
200
+ const result = check(val);
201
+ const setError = () => ctx.addIssue({
202
+ code: ZodIssueCode.custom,
203
+ ...getIssueProperties(val)
204
+ });
205
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
206
+ return result.then((data) => {
207
+ if (!data) {
208
+ setError();
209
+ return false;
210
+ } else {
211
+ return true;
212
+ }
213
+ });
214
+ }
215
+ if (!result) {
216
+ setError();
217
+ return false;
218
+ } else {
219
+ return true;
220
+ }
221
+ });
222
+ }
223
+ refinement(check, refinementData) {
224
+ return this._refinement((val, ctx) => {
225
+ if (!check(val)) {
226
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
227
+ return false;
228
+ } else {
229
+ return true;
230
+ }
231
+ });
232
+ }
233
+ _refinement(refinement) {
234
+ return new ZodEffects({
235
+ schema: this,
236
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
237
+ effect: { type: "refinement", refinement }
238
+ });
239
+ }
240
+ superRefine(refinement) {
241
+ return this._refinement(refinement);
242
+ }
243
+ constructor(def) {
244
+ this.spa = this.safeParseAsync;
245
+ this._def = def;
246
+ this.parse = this.parse.bind(this);
247
+ this.safeParse = this.safeParse.bind(this);
248
+ this.parseAsync = this.parseAsync.bind(this);
249
+ this.safeParseAsync = this.safeParseAsync.bind(this);
250
+ this.spa = this.spa.bind(this);
251
+ this.refine = this.refine.bind(this);
252
+ this.refinement = this.refinement.bind(this);
253
+ this.superRefine = this.superRefine.bind(this);
254
+ this.optional = this.optional.bind(this);
255
+ this.nullable = this.nullable.bind(this);
256
+ this.nullish = this.nullish.bind(this);
257
+ this.array = this.array.bind(this);
258
+ this.promise = this.promise.bind(this);
259
+ this.or = this.or.bind(this);
260
+ this.and = this.and.bind(this);
261
+ this.transform = this.transform.bind(this);
262
+ this.brand = this.brand.bind(this);
263
+ this.default = this.default.bind(this);
264
+ this.catch = this.catch.bind(this);
265
+ this.describe = this.describe.bind(this);
266
+ this.pipe = this.pipe.bind(this);
267
+ this.readonly = this.readonly.bind(this);
268
+ this.isNullable = this.isNullable.bind(this);
269
+ this.isOptional = this.isOptional.bind(this);
270
+ this["~standard"] = {
271
+ version: 1,
272
+ vendor: "zod",
273
+ validate: (data) => this["~validate"](data)
274
+ };
275
+ }
276
+ optional() {
277
+ return ZodOptional.create(this, this._def);
278
+ }
279
+ nullable() {
280
+ return ZodNullable.create(this, this._def);
281
+ }
282
+ nullish() {
283
+ return this.nullable().optional();
284
+ }
285
+ array() {
286
+ return ZodArray.create(this);
287
+ }
288
+ promise() {
289
+ return ZodPromise.create(this, this._def);
290
+ }
291
+ or(option) {
292
+ return ZodUnion.create([this, option], this._def);
293
+ }
294
+ and(incoming) {
295
+ return ZodIntersection.create(this, incoming, this._def);
296
+ }
297
+ transform(transform) {
298
+ return new ZodEffects({
299
+ ...processCreateParams(this._def),
300
+ schema: this,
301
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
302
+ effect: { type: "transform", transform }
303
+ });
304
+ }
305
+ default(def) {
306
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
307
+ return new ZodDefault({
308
+ ...processCreateParams(this._def),
309
+ innerType: this,
310
+ defaultValue: defaultValueFunc,
311
+ typeName: ZodFirstPartyTypeKind.ZodDefault
312
+ });
313
+ }
314
+ brand() {
315
+ return new ZodBranded({
316
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
317
+ type: this,
318
+ ...processCreateParams(this._def)
319
+ });
320
+ }
321
+ catch(def) {
322
+ const catchValueFunc = typeof def === "function" ? def : () => def;
323
+ return new ZodCatch({
324
+ ...processCreateParams(this._def),
325
+ innerType: this,
326
+ catchValue: catchValueFunc,
327
+ typeName: ZodFirstPartyTypeKind.ZodCatch
328
+ });
329
+ }
330
+ describe(description) {
331
+ const This = this.constructor;
332
+ return new This({
333
+ ...this._def,
334
+ description
335
+ });
336
+ }
337
+ pipe(target) {
338
+ return ZodPipeline.create(this, target);
339
+ }
340
+ readonly() {
341
+ return ZodReadonly.create(this);
342
+ }
343
+ isOptional() {
344
+ return this.safeParse(void 0).success;
345
+ }
346
+ isNullable() {
347
+ return this.safeParse(null).success;
348
+ }
349
+ }
350
+ const cuidRegex = /^c[^\s-]{8,}$/i;
351
+ const cuid2Regex = /^[0-9a-z]+$/;
352
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
353
+ const 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;
354
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
355
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
356
+ const 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)?)??$/;
357
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
358
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
359
+ let emojiRegex;
360
+ const 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])$/;
361
+ const ipv4CidrRegex = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/;
362
+ const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
363
+ const ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
364
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
365
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
366
+ const 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])))`;
367
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
368
+ function timeRegexSource(args) {
369
+ let secondsRegexSource = `[0-5]\\d`;
370
+ if (args.precision) {
371
+ secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
372
+ } else if (args.precision == null) {
373
+ secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
374
+ }
375
+ const secondsQuantifier = args.precision ? "+" : "?";
376
+ return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
377
+ }
378
+ function timeRegex(args) {
379
+ return new RegExp(`^${timeRegexSource(args)}$`);
380
+ }
381
+ function datetimeRegex(args) {
382
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
383
+ const opts = [];
384
+ opts.push(args.local ? `Z?` : `Z`);
385
+ if (args.offset)
386
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
387
+ regex = `${regex}(${opts.join("|")})`;
388
+ return new RegExp(`^${regex}$`);
389
+ }
390
+ function isValidIP(ip, version) {
391
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
392
+ return true;
393
+ }
394
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
395
+ return true;
396
+ }
397
+ return false;
398
+ }
399
+ function isValidJWT(jwt, alg) {
400
+ if (!jwtRegex.test(jwt))
401
+ return false;
402
+ try {
403
+ const [header] = jwt.split(".");
404
+ if (!header)
405
+ return false;
406
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
407
+ const decoded = JSON.parse(atob(base64));
408
+ if (typeof decoded !== "object" || decoded === null)
409
+ return false;
410
+ if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
411
+ return false;
412
+ if (!decoded.alg)
413
+ return false;
414
+ if (alg && decoded.alg !== alg)
415
+ return false;
416
+ return true;
417
+ } catch {
418
+ return false;
419
+ }
420
+ }
421
+ function isValidCidr(ip, version) {
422
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
423
+ return true;
424
+ }
425
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
426
+ return true;
427
+ }
428
+ return false;
429
+ }
430
+ class ZodString extends ZodType {
431
+ _parse(input) {
432
+ if (this._def.coerce) {
433
+ input.data = String(input.data);
434
+ }
435
+ const parsedType = this._getType(input);
436
+ if (parsedType !== ZodParsedType.string) {
437
+ const ctx2 = this._getOrReturnCtx(input);
438
+ addIssueToContext(ctx2, {
439
+ code: ZodIssueCode.invalid_type,
440
+ expected: ZodParsedType.string,
441
+ received: ctx2.parsedType
442
+ });
443
+ return INVALID;
444
+ }
445
+ const status = new ParseStatus();
446
+ let ctx = void 0;
447
+ for (const check of this._def.checks) {
448
+ if (check.kind === "min") {
449
+ if (input.data.length < check.value) {
450
+ ctx = this._getOrReturnCtx(input, ctx);
451
+ addIssueToContext(ctx, {
452
+ code: ZodIssueCode.too_small,
453
+ minimum: check.value,
454
+ type: "string",
455
+ inclusive: true,
456
+ exact: false,
457
+ message: check.message
458
+ });
459
+ status.dirty();
460
+ }
461
+ } else if (check.kind === "max") {
462
+ if (input.data.length > check.value) {
463
+ ctx = this._getOrReturnCtx(input, ctx);
464
+ addIssueToContext(ctx, {
465
+ code: ZodIssueCode.too_big,
466
+ maximum: check.value,
467
+ type: "string",
468
+ inclusive: true,
469
+ exact: false,
470
+ message: check.message
471
+ });
472
+ status.dirty();
473
+ }
474
+ } else if (check.kind === "length") {
475
+ const tooBig = input.data.length > check.value;
476
+ const tooSmall = input.data.length < check.value;
477
+ if (tooBig || tooSmall) {
478
+ ctx = this._getOrReturnCtx(input, ctx);
479
+ if (tooBig) {
480
+ addIssueToContext(ctx, {
481
+ code: ZodIssueCode.too_big,
482
+ maximum: check.value,
483
+ type: "string",
484
+ inclusive: true,
485
+ exact: true,
486
+ message: check.message
487
+ });
488
+ } else if (tooSmall) {
489
+ addIssueToContext(ctx, {
490
+ code: ZodIssueCode.too_small,
491
+ minimum: check.value,
492
+ type: "string",
493
+ inclusive: true,
494
+ exact: true,
495
+ message: check.message
496
+ });
497
+ }
498
+ status.dirty();
499
+ }
500
+ } else if (check.kind === "email") {
501
+ if (!emailRegex.test(input.data)) {
502
+ ctx = this._getOrReturnCtx(input, ctx);
503
+ addIssueToContext(ctx, {
504
+ validation: "email",
505
+ code: ZodIssueCode.invalid_string,
506
+ message: check.message
507
+ });
508
+ status.dirty();
509
+ }
510
+ } else if (check.kind === "emoji") {
511
+ if (!emojiRegex) {
512
+ emojiRegex = new RegExp(_emojiRegex, "u");
513
+ }
514
+ if (!emojiRegex.test(input.data)) {
515
+ ctx = this._getOrReturnCtx(input, ctx);
516
+ addIssueToContext(ctx, {
517
+ validation: "emoji",
518
+ code: ZodIssueCode.invalid_string,
519
+ message: check.message
520
+ });
521
+ status.dirty();
522
+ }
523
+ } else if (check.kind === "uuid") {
524
+ if (!uuidRegex.test(input.data)) {
525
+ ctx = this._getOrReturnCtx(input, ctx);
526
+ addIssueToContext(ctx, {
527
+ validation: "uuid",
528
+ code: ZodIssueCode.invalid_string,
529
+ message: check.message
530
+ });
531
+ status.dirty();
532
+ }
533
+ } else if (check.kind === "nanoid") {
534
+ if (!nanoidRegex.test(input.data)) {
535
+ ctx = this._getOrReturnCtx(input, ctx);
536
+ addIssueToContext(ctx, {
537
+ validation: "nanoid",
538
+ code: ZodIssueCode.invalid_string,
539
+ message: check.message
540
+ });
541
+ status.dirty();
542
+ }
543
+ } else if (check.kind === "cuid") {
544
+ if (!cuidRegex.test(input.data)) {
545
+ ctx = this._getOrReturnCtx(input, ctx);
546
+ addIssueToContext(ctx, {
547
+ validation: "cuid",
548
+ code: ZodIssueCode.invalid_string,
549
+ message: check.message
550
+ });
551
+ status.dirty();
552
+ }
553
+ } else if (check.kind === "cuid2") {
554
+ if (!cuid2Regex.test(input.data)) {
555
+ ctx = this._getOrReturnCtx(input, ctx);
556
+ addIssueToContext(ctx, {
557
+ validation: "cuid2",
558
+ code: ZodIssueCode.invalid_string,
559
+ message: check.message
560
+ });
561
+ status.dirty();
562
+ }
563
+ } else if (check.kind === "ulid") {
564
+ if (!ulidRegex.test(input.data)) {
565
+ ctx = this._getOrReturnCtx(input, ctx);
566
+ addIssueToContext(ctx, {
567
+ validation: "ulid",
568
+ code: ZodIssueCode.invalid_string,
569
+ message: check.message
570
+ });
571
+ status.dirty();
572
+ }
573
+ } else if (check.kind === "url") {
574
+ try {
575
+ new URL(input.data);
576
+ } catch {
577
+ ctx = this._getOrReturnCtx(input, ctx);
578
+ addIssueToContext(ctx, {
579
+ validation: "url",
580
+ code: ZodIssueCode.invalid_string,
581
+ message: check.message
582
+ });
583
+ status.dirty();
584
+ }
585
+ } else if (check.kind === "regex") {
586
+ check.regex.lastIndex = 0;
587
+ const testResult = check.regex.test(input.data);
588
+ if (!testResult) {
589
+ ctx = this._getOrReturnCtx(input, ctx);
590
+ addIssueToContext(ctx, {
591
+ validation: "regex",
592
+ code: ZodIssueCode.invalid_string,
593
+ message: check.message
594
+ });
595
+ status.dirty();
596
+ }
597
+ } else if (check.kind === "trim") {
598
+ input.data = input.data.trim();
599
+ } else if (check.kind === "includes") {
600
+ if (!input.data.includes(check.value, check.position)) {
601
+ ctx = this._getOrReturnCtx(input, ctx);
602
+ addIssueToContext(ctx, {
603
+ code: ZodIssueCode.invalid_string,
604
+ validation: { includes: check.value, position: check.position },
605
+ message: check.message
606
+ });
607
+ status.dirty();
608
+ }
609
+ } else if (check.kind === "toLowerCase") {
610
+ input.data = input.data.toLowerCase();
611
+ } else if (check.kind === "toUpperCase") {
612
+ input.data = input.data.toUpperCase();
613
+ } else if (check.kind === "startsWith") {
614
+ if (!input.data.startsWith(check.value)) {
615
+ ctx = this._getOrReturnCtx(input, ctx);
616
+ addIssueToContext(ctx, {
617
+ code: ZodIssueCode.invalid_string,
618
+ validation: { startsWith: check.value },
619
+ message: check.message
620
+ });
621
+ status.dirty();
622
+ }
623
+ } else if (check.kind === "endsWith") {
624
+ if (!input.data.endsWith(check.value)) {
625
+ ctx = this._getOrReturnCtx(input, ctx);
626
+ addIssueToContext(ctx, {
627
+ code: ZodIssueCode.invalid_string,
628
+ validation: { endsWith: check.value },
629
+ message: check.message
630
+ });
631
+ status.dirty();
632
+ }
633
+ } else if (check.kind === "datetime") {
634
+ const regex = datetimeRegex(check);
635
+ if (!regex.test(input.data)) {
636
+ ctx = this._getOrReturnCtx(input, ctx);
637
+ addIssueToContext(ctx, {
638
+ code: ZodIssueCode.invalid_string,
639
+ validation: "datetime",
640
+ message: check.message
641
+ });
642
+ status.dirty();
643
+ }
644
+ } else if (check.kind === "date") {
645
+ const regex = dateRegex;
646
+ if (!regex.test(input.data)) {
647
+ ctx = this._getOrReturnCtx(input, ctx);
648
+ addIssueToContext(ctx, {
649
+ code: ZodIssueCode.invalid_string,
650
+ validation: "date",
651
+ message: check.message
652
+ });
653
+ status.dirty();
654
+ }
655
+ } else if (check.kind === "time") {
656
+ const regex = timeRegex(check);
657
+ if (!regex.test(input.data)) {
658
+ ctx = this._getOrReturnCtx(input, ctx);
659
+ addIssueToContext(ctx, {
660
+ code: ZodIssueCode.invalid_string,
661
+ validation: "time",
662
+ message: check.message
663
+ });
664
+ status.dirty();
665
+ }
666
+ } else if (check.kind === "duration") {
667
+ if (!durationRegex.test(input.data)) {
668
+ ctx = this._getOrReturnCtx(input, ctx);
669
+ addIssueToContext(ctx, {
670
+ validation: "duration",
671
+ code: ZodIssueCode.invalid_string,
672
+ message: check.message
673
+ });
674
+ status.dirty();
675
+ }
676
+ } else if (check.kind === "ip") {
677
+ if (!isValidIP(input.data, check.version)) {
678
+ ctx = this._getOrReturnCtx(input, ctx);
679
+ addIssueToContext(ctx, {
680
+ validation: "ip",
681
+ code: ZodIssueCode.invalid_string,
682
+ message: check.message
683
+ });
684
+ status.dirty();
685
+ }
686
+ } else if (check.kind === "jwt") {
687
+ if (!isValidJWT(input.data, check.alg)) {
688
+ ctx = this._getOrReturnCtx(input, ctx);
689
+ addIssueToContext(ctx, {
690
+ validation: "jwt",
691
+ code: ZodIssueCode.invalid_string,
692
+ message: check.message
693
+ });
694
+ status.dirty();
695
+ }
696
+ } else if (check.kind === "cidr") {
697
+ if (!isValidCidr(input.data, check.version)) {
698
+ ctx = this._getOrReturnCtx(input, ctx);
699
+ addIssueToContext(ctx, {
700
+ validation: "cidr",
701
+ code: ZodIssueCode.invalid_string,
702
+ message: check.message
703
+ });
704
+ status.dirty();
705
+ }
706
+ } else if (check.kind === "base64") {
707
+ if (!base64Regex.test(input.data)) {
708
+ ctx = this._getOrReturnCtx(input, ctx);
709
+ addIssueToContext(ctx, {
710
+ validation: "base64",
711
+ code: ZodIssueCode.invalid_string,
712
+ message: check.message
713
+ });
714
+ status.dirty();
715
+ }
716
+ } else if (check.kind === "base64url") {
717
+ if (!base64urlRegex.test(input.data)) {
718
+ ctx = this._getOrReturnCtx(input, ctx);
719
+ addIssueToContext(ctx, {
720
+ validation: "base64url",
721
+ code: ZodIssueCode.invalid_string,
722
+ message: check.message
723
+ });
724
+ status.dirty();
725
+ }
726
+ } else {
727
+ util.assertNever(check);
728
+ }
729
+ }
730
+ return { status: status.value, value: input.data };
731
+ }
732
+ _regex(regex, validation, message) {
733
+ return this.refinement((data) => regex.test(data), {
734
+ validation,
735
+ code: ZodIssueCode.invalid_string,
736
+ ...errorUtil.errToObj(message)
737
+ });
738
+ }
739
+ _addCheck(check) {
740
+ return new ZodString({
741
+ ...this._def,
742
+ checks: [...this._def.checks, check]
743
+ });
744
+ }
745
+ email(message) {
746
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
747
+ }
748
+ url(message) {
749
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
750
+ }
751
+ emoji(message) {
752
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
753
+ }
754
+ uuid(message) {
755
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
756
+ }
757
+ nanoid(message) {
758
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
759
+ }
760
+ cuid(message) {
761
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
762
+ }
763
+ cuid2(message) {
764
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
765
+ }
766
+ ulid(message) {
767
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
768
+ }
769
+ base64(message) {
770
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
771
+ }
772
+ base64url(message) {
773
+ return this._addCheck({
774
+ kind: "base64url",
775
+ ...errorUtil.errToObj(message)
776
+ });
777
+ }
778
+ jwt(options) {
779
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
780
+ }
781
+ ip(options) {
782
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
783
+ }
784
+ cidr(options) {
785
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
786
+ }
787
+ datetime(options) {
788
+ if (typeof options === "string") {
789
+ return this._addCheck({
790
+ kind: "datetime",
791
+ precision: null,
792
+ offset: false,
793
+ local: false,
794
+ message: options
795
+ });
796
+ }
797
+ return this._addCheck({
798
+ kind: "datetime",
799
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
800
+ offset: (options == null ? void 0 : options.offset) ?? false,
801
+ local: (options == null ? void 0 : options.local) ?? false,
802
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
803
+ });
804
+ }
805
+ date(message) {
806
+ return this._addCheck({ kind: "date", message });
807
+ }
808
+ time(options) {
809
+ if (typeof options === "string") {
810
+ return this._addCheck({
811
+ kind: "time",
812
+ precision: null,
813
+ message: options
814
+ });
815
+ }
816
+ return this._addCheck({
817
+ kind: "time",
818
+ precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
819
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
820
+ });
821
+ }
822
+ duration(message) {
823
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
824
+ }
825
+ regex(regex, message) {
826
+ return this._addCheck({
827
+ kind: "regex",
828
+ regex,
829
+ ...errorUtil.errToObj(message)
830
+ });
831
+ }
832
+ includes(value, options) {
833
+ return this._addCheck({
834
+ kind: "includes",
835
+ value,
836
+ position: options == null ? void 0 : options.position,
837
+ ...errorUtil.errToObj(options == null ? void 0 : options.message)
838
+ });
839
+ }
840
+ startsWith(value, message) {
841
+ return this._addCheck({
842
+ kind: "startsWith",
843
+ value,
844
+ ...errorUtil.errToObj(message)
845
+ });
846
+ }
847
+ endsWith(value, message) {
848
+ return this._addCheck({
849
+ kind: "endsWith",
850
+ value,
851
+ ...errorUtil.errToObj(message)
852
+ });
853
+ }
854
+ min(minLength, message) {
855
+ return this._addCheck({
856
+ kind: "min",
857
+ value: minLength,
858
+ ...errorUtil.errToObj(message)
859
+ });
860
+ }
861
+ max(maxLength, message) {
862
+ return this._addCheck({
863
+ kind: "max",
864
+ value: maxLength,
865
+ ...errorUtil.errToObj(message)
866
+ });
867
+ }
868
+ length(len, message) {
869
+ return this._addCheck({
870
+ kind: "length",
871
+ value: len,
872
+ ...errorUtil.errToObj(message)
873
+ });
874
+ }
875
+ /**
876
+ * Equivalent to `.min(1)`
877
+ */
878
+ nonempty(message) {
879
+ return this.min(1, errorUtil.errToObj(message));
880
+ }
881
+ trim() {
882
+ return new ZodString({
883
+ ...this._def,
884
+ checks: [...this._def.checks, { kind: "trim" }]
885
+ });
886
+ }
887
+ toLowerCase() {
888
+ return new ZodString({
889
+ ...this._def,
890
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
891
+ });
892
+ }
893
+ toUpperCase() {
894
+ return new ZodString({
895
+ ...this._def,
896
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
897
+ });
898
+ }
899
+ get isDatetime() {
900
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
901
+ }
902
+ get isDate() {
903
+ return !!this._def.checks.find((ch) => ch.kind === "date");
904
+ }
905
+ get isTime() {
906
+ return !!this._def.checks.find((ch) => ch.kind === "time");
907
+ }
908
+ get isDuration() {
909
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
910
+ }
911
+ get isEmail() {
912
+ return !!this._def.checks.find((ch) => ch.kind === "email");
913
+ }
914
+ get isURL() {
915
+ return !!this._def.checks.find((ch) => ch.kind === "url");
916
+ }
917
+ get isEmoji() {
918
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
919
+ }
920
+ get isUUID() {
921
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
922
+ }
923
+ get isNANOID() {
924
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
925
+ }
926
+ get isCUID() {
927
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
928
+ }
929
+ get isCUID2() {
930
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
931
+ }
932
+ get isULID() {
933
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
934
+ }
935
+ get isIP() {
936
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
937
+ }
938
+ get isCIDR() {
939
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
940
+ }
941
+ get isBase64() {
942
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
943
+ }
944
+ get isBase64url() {
945
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
946
+ }
947
+ get minLength() {
948
+ let min = null;
949
+ for (const ch of this._def.checks) {
950
+ if (ch.kind === "min") {
951
+ if (min === null || ch.value > min)
952
+ min = ch.value;
953
+ }
954
+ }
955
+ return min;
956
+ }
957
+ get maxLength() {
958
+ let max = null;
959
+ for (const ch of this._def.checks) {
960
+ if (ch.kind === "max") {
961
+ if (max === null || ch.value < max)
962
+ max = ch.value;
963
+ }
964
+ }
965
+ return max;
966
+ }
967
+ }
968
+ ZodString.create = (params) => {
969
+ return new ZodString({
970
+ checks: [],
971
+ typeName: ZodFirstPartyTypeKind.ZodString,
972
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
973
+ ...processCreateParams(params)
974
+ });
975
+ };
976
+ function floatSafeRemainder(val, step) {
977
+ const valDecCount = (val.toString().split(".")[1] || "").length;
978
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
979
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
980
+ const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
981
+ const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
982
+ return valInt % stepInt / 10 ** decCount;
983
+ }
984
+ class ZodNumber extends ZodType {
985
+ constructor() {
986
+ super(...arguments);
987
+ this.min = this.gte;
988
+ this.max = this.lte;
989
+ this.step = this.multipleOf;
990
+ }
991
+ _parse(input) {
992
+ if (this._def.coerce) {
993
+ input.data = Number(input.data);
994
+ }
995
+ const parsedType = this._getType(input);
996
+ if (parsedType !== ZodParsedType.number) {
997
+ const ctx2 = this._getOrReturnCtx(input);
998
+ addIssueToContext(ctx2, {
999
+ code: ZodIssueCode.invalid_type,
1000
+ expected: ZodParsedType.number,
1001
+ received: ctx2.parsedType
1002
+ });
1003
+ return INVALID;
1004
+ }
1005
+ let ctx = void 0;
1006
+ const status = new ParseStatus();
1007
+ for (const check of this._def.checks) {
1008
+ if (check.kind === "int") {
1009
+ if (!util.isInteger(input.data)) {
1010
+ ctx = this._getOrReturnCtx(input, ctx);
1011
+ addIssueToContext(ctx, {
1012
+ code: ZodIssueCode.invalid_type,
1013
+ expected: "integer",
1014
+ received: "float",
1015
+ message: check.message
1016
+ });
1017
+ status.dirty();
1018
+ }
1019
+ } else if (check.kind === "min") {
1020
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1021
+ if (tooSmall) {
1022
+ ctx = this._getOrReturnCtx(input, ctx);
1023
+ addIssueToContext(ctx, {
1024
+ code: ZodIssueCode.too_small,
1025
+ minimum: check.value,
1026
+ type: "number",
1027
+ inclusive: check.inclusive,
1028
+ exact: false,
1029
+ message: check.message
1030
+ });
1031
+ status.dirty();
1032
+ }
1033
+ } else if (check.kind === "max") {
1034
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1035
+ if (tooBig) {
1036
+ ctx = this._getOrReturnCtx(input, ctx);
1037
+ addIssueToContext(ctx, {
1038
+ code: ZodIssueCode.too_big,
1039
+ maximum: check.value,
1040
+ type: "number",
1041
+ inclusive: check.inclusive,
1042
+ exact: false,
1043
+ message: check.message
1044
+ });
1045
+ status.dirty();
1046
+ }
1047
+ } else if (check.kind === "multipleOf") {
1048
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1049
+ ctx = this._getOrReturnCtx(input, ctx);
1050
+ addIssueToContext(ctx, {
1051
+ code: ZodIssueCode.not_multiple_of,
1052
+ multipleOf: check.value,
1053
+ message: check.message
1054
+ });
1055
+ status.dirty();
1056
+ }
1057
+ } else if (check.kind === "finite") {
1058
+ if (!Number.isFinite(input.data)) {
1059
+ ctx = this._getOrReturnCtx(input, ctx);
1060
+ addIssueToContext(ctx, {
1061
+ code: ZodIssueCode.not_finite,
1062
+ message: check.message
1063
+ });
1064
+ status.dirty();
1065
+ }
1066
+ } else {
1067
+ util.assertNever(check);
1068
+ }
1069
+ }
1070
+ return { status: status.value, value: input.data };
1071
+ }
1072
+ gte(value, message) {
1073
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1074
+ }
1075
+ gt(value, message) {
1076
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1077
+ }
1078
+ lte(value, message) {
1079
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1080
+ }
1081
+ lt(value, message) {
1082
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1083
+ }
1084
+ setLimit(kind, value, inclusive, message) {
1085
+ return new ZodNumber({
1086
+ ...this._def,
1087
+ checks: [
1088
+ ...this._def.checks,
1089
+ {
1090
+ kind,
1091
+ value,
1092
+ inclusive,
1093
+ message: errorUtil.toString(message)
1094
+ }
1095
+ ]
1096
+ });
1097
+ }
1098
+ _addCheck(check) {
1099
+ return new ZodNumber({
1100
+ ...this._def,
1101
+ checks: [...this._def.checks, check]
1102
+ });
1103
+ }
1104
+ int(message) {
1105
+ return this._addCheck({
1106
+ kind: "int",
1107
+ message: errorUtil.toString(message)
1108
+ });
1109
+ }
1110
+ positive(message) {
1111
+ return this._addCheck({
1112
+ kind: "min",
1113
+ value: 0,
1114
+ inclusive: false,
1115
+ message: errorUtil.toString(message)
1116
+ });
1117
+ }
1118
+ negative(message) {
1119
+ return this._addCheck({
1120
+ kind: "max",
1121
+ value: 0,
1122
+ inclusive: false,
1123
+ message: errorUtil.toString(message)
1124
+ });
1125
+ }
1126
+ nonpositive(message) {
1127
+ return this._addCheck({
1128
+ kind: "max",
1129
+ value: 0,
1130
+ inclusive: true,
1131
+ message: errorUtil.toString(message)
1132
+ });
1133
+ }
1134
+ nonnegative(message) {
1135
+ return this._addCheck({
1136
+ kind: "min",
1137
+ value: 0,
1138
+ inclusive: true,
1139
+ message: errorUtil.toString(message)
1140
+ });
1141
+ }
1142
+ multipleOf(value, message) {
1143
+ return this._addCheck({
1144
+ kind: "multipleOf",
1145
+ value,
1146
+ message: errorUtil.toString(message)
1147
+ });
1148
+ }
1149
+ finite(message) {
1150
+ return this._addCheck({
1151
+ kind: "finite",
1152
+ message: errorUtil.toString(message)
1153
+ });
1154
+ }
1155
+ safe(message) {
1156
+ return this._addCheck({
1157
+ kind: "min",
1158
+ inclusive: true,
1159
+ value: Number.MIN_SAFE_INTEGER,
1160
+ message: errorUtil.toString(message)
1161
+ })._addCheck({
1162
+ kind: "max",
1163
+ inclusive: true,
1164
+ value: Number.MAX_SAFE_INTEGER,
1165
+ message: errorUtil.toString(message)
1166
+ });
1167
+ }
1168
+ get minValue() {
1169
+ let min = null;
1170
+ for (const ch of this._def.checks) {
1171
+ if (ch.kind === "min") {
1172
+ if (min === null || ch.value > min)
1173
+ min = ch.value;
1174
+ }
1175
+ }
1176
+ return min;
1177
+ }
1178
+ get maxValue() {
1179
+ let max = null;
1180
+ for (const ch of this._def.checks) {
1181
+ if (ch.kind === "max") {
1182
+ if (max === null || ch.value < max)
1183
+ max = ch.value;
1184
+ }
1185
+ }
1186
+ return max;
1187
+ }
1188
+ get isInt() {
1189
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1190
+ }
1191
+ get isFinite() {
1192
+ let max = null;
1193
+ let min = null;
1194
+ for (const ch of this._def.checks) {
1195
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1196
+ return true;
1197
+ } else if (ch.kind === "min") {
1198
+ if (min === null || ch.value > min)
1199
+ min = ch.value;
1200
+ } else if (ch.kind === "max") {
1201
+ if (max === null || ch.value < max)
1202
+ max = ch.value;
1203
+ }
1204
+ }
1205
+ return Number.isFinite(min) && Number.isFinite(max);
1206
+ }
1207
+ }
1208
+ ZodNumber.create = (params) => {
1209
+ return new ZodNumber({
1210
+ checks: [],
1211
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1212
+ coerce: (params == null ? void 0 : params.coerce) || false,
1213
+ ...processCreateParams(params)
1214
+ });
1215
+ };
1216
+ class ZodBigInt extends ZodType {
1217
+ constructor() {
1218
+ super(...arguments);
1219
+ this.min = this.gte;
1220
+ this.max = this.lte;
1221
+ }
1222
+ _parse(input) {
1223
+ if (this._def.coerce) {
1224
+ try {
1225
+ input.data = BigInt(input.data);
1226
+ } catch {
1227
+ return this._getInvalidInput(input);
1228
+ }
1229
+ }
1230
+ const parsedType = this._getType(input);
1231
+ if (parsedType !== ZodParsedType.bigint) {
1232
+ return this._getInvalidInput(input);
1233
+ }
1234
+ let ctx = void 0;
1235
+ const status = new ParseStatus();
1236
+ for (const check of this._def.checks) {
1237
+ if (check.kind === "min") {
1238
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1239
+ if (tooSmall) {
1240
+ ctx = this._getOrReturnCtx(input, ctx);
1241
+ addIssueToContext(ctx, {
1242
+ code: ZodIssueCode.too_small,
1243
+ type: "bigint",
1244
+ minimum: check.value,
1245
+ inclusive: check.inclusive,
1246
+ message: check.message
1247
+ });
1248
+ status.dirty();
1249
+ }
1250
+ } else if (check.kind === "max") {
1251
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1252
+ if (tooBig) {
1253
+ ctx = this._getOrReturnCtx(input, ctx);
1254
+ addIssueToContext(ctx, {
1255
+ code: ZodIssueCode.too_big,
1256
+ type: "bigint",
1257
+ maximum: check.value,
1258
+ inclusive: check.inclusive,
1259
+ message: check.message
1260
+ });
1261
+ status.dirty();
1262
+ }
1263
+ } else if (check.kind === "multipleOf") {
1264
+ if (input.data % check.value !== BigInt(0)) {
1265
+ ctx = this._getOrReturnCtx(input, ctx);
1266
+ addIssueToContext(ctx, {
1267
+ code: ZodIssueCode.not_multiple_of,
1268
+ multipleOf: check.value,
1269
+ message: check.message
1270
+ });
1271
+ status.dirty();
1272
+ }
1273
+ } else {
1274
+ util.assertNever(check);
1275
+ }
1276
+ }
1277
+ return { status: status.value, value: input.data };
1278
+ }
1279
+ _getInvalidInput(input) {
1280
+ const ctx = this._getOrReturnCtx(input);
1281
+ addIssueToContext(ctx, {
1282
+ code: ZodIssueCode.invalid_type,
1283
+ expected: ZodParsedType.bigint,
1284
+ received: ctx.parsedType
1285
+ });
1286
+ return INVALID;
1287
+ }
1288
+ gte(value, message) {
1289
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1290
+ }
1291
+ gt(value, message) {
1292
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1293
+ }
1294
+ lte(value, message) {
1295
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1296
+ }
1297
+ lt(value, message) {
1298
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1299
+ }
1300
+ setLimit(kind, value, inclusive, message) {
1301
+ return new ZodBigInt({
1302
+ ...this._def,
1303
+ checks: [
1304
+ ...this._def.checks,
1305
+ {
1306
+ kind,
1307
+ value,
1308
+ inclusive,
1309
+ message: errorUtil.toString(message)
1310
+ }
1311
+ ]
1312
+ });
1313
+ }
1314
+ _addCheck(check) {
1315
+ return new ZodBigInt({
1316
+ ...this._def,
1317
+ checks: [...this._def.checks, check]
1318
+ });
1319
+ }
1320
+ positive(message) {
1321
+ return this._addCheck({
1322
+ kind: "min",
1323
+ value: BigInt(0),
1324
+ inclusive: false,
1325
+ message: errorUtil.toString(message)
1326
+ });
1327
+ }
1328
+ negative(message) {
1329
+ return this._addCheck({
1330
+ kind: "max",
1331
+ value: BigInt(0),
1332
+ inclusive: false,
1333
+ message: errorUtil.toString(message)
1334
+ });
1335
+ }
1336
+ nonpositive(message) {
1337
+ return this._addCheck({
1338
+ kind: "max",
1339
+ value: BigInt(0),
1340
+ inclusive: true,
1341
+ message: errorUtil.toString(message)
1342
+ });
1343
+ }
1344
+ nonnegative(message) {
1345
+ return this._addCheck({
1346
+ kind: "min",
1347
+ value: BigInt(0),
1348
+ inclusive: true,
1349
+ message: errorUtil.toString(message)
1350
+ });
1351
+ }
1352
+ multipleOf(value, message) {
1353
+ return this._addCheck({
1354
+ kind: "multipleOf",
1355
+ value,
1356
+ message: errorUtil.toString(message)
1357
+ });
1358
+ }
1359
+ get minValue() {
1360
+ let min = null;
1361
+ for (const ch of this._def.checks) {
1362
+ if (ch.kind === "min") {
1363
+ if (min === null || ch.value > min)
1364
+ min = ch.value;
1365
+ }
1366
+ }
1367
+ return min;
1368
+ }
1369
+ get maxValue() {
1370
+ let max = null;
1371
+ for (const ch of this._def.checks) {
1372
+ if (ch.kind === "max") {
1373
+ if (max === null || ch.value < max)
1374
+ max = ch.value;
1375
+ }
1376
+ }
1377
+ return max;
1378
+ }
1379
+ }
1380
+ ZodBigInt.create = (params) => {
1381
+ return new ZodBigInt({
1382
+ checks: [],
1383
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1384
+ coerce: (params == null ? void 0 : params.coerce) ?? false,
1385
+ ...processCreateParams(params)
1386
+ });
1387
+ };
1388
+ class ZodBoolean extends ZodType {
1389
+ _parse(input) {
1390
+ if (this._def.coerce) {
1391
+ input.data = Boolean(input.data);
1392
+ }
1393
+ const parsedType = this._getType(input);
1394
+ if (parsedType !== ZodParsedType.boolean) {
1395
+ const ctx = this._getOrReturnCtx(input);
1396
+ addIssueToContext(ctx, {
1397
+ code: ZodIssueCode.invalid_type,
1398
+ expected: ZodParsedType.boolean,
1399
+ received: ctx.parsedType
1400
+ });
1401
+ return INVALID;
1402
+ }
1403
+ return OK(input.data);
1404
+ }
1405
+ }
1406
+ ZodBoolean.create = (params) => {
1407
+ return new ZodBoolean({
1408
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1409
+ coerce: (params == null ? void 0 : params.coerce) || false,
1410
+ ...processCreateParams(params)
1411
+ });
1412
+ };
1413
+ class ZodDate extends ZodType {
1414
+ _parse(input) {
1415
+ if (this._def.coerce) {
1416
+ input.data = new Date(input.data);
1417
+ }
1418
+ const parsedType = this._getType(input);
1419
+ if (parsedType !== ZodParsedType.date) {
1420
+ const ctx2 = this._getOrReturnCtx(input);
1421
+ addIssueToContext(ctx2, {
1422
+ code: ZodIssueCode.invalid_type,
1423
+ expected: ZodParsedType.date,
1424
+ received: ctx2.parsedType
1425
+ });
1426
+ return INVALID;
1427
+ }
1428
+ if (Number.isNaN(input.data.getTime())) {
1429
+ const ctx2 = this._getOrReturnCtx(input);
1430
+ addIssueToContext(ctx2, {
1431
+ code: ZodIssueCode.invalid_date
1432
+ });
1433
+ return INVALID;
1434
+ }
1435
+ const status = new ParseStatus();
1436
+ let ctx = void 0;
1437
+ for (const check of this._def.checks) {
1438
+ if (check.kind === "min") {
1439
+ if (input.data.getTime() < check.value) {
1440
+ ctx = this._getOrReturnCtx(input, ctx);
1441
+ addIssueToContext(ctx, {
1442
+ code: ZodIssueCode.too_small,
1443
+ message: check.message,
1444
+ inclusive: true,
1445
+ exact: false,
1446
+ minimum: check.value,
1447
+ type: "date"
1448
+ });
1449
+ status.dirty();
1450
+ }
1451
+ } else if (check.kind === "max") {
1452
+ if (input.data.getTime() > check.value) {
1453
+ ctx = this._getOrReturnCtx(input, ctx);
1454
+ addIssueToContext(ctx, {
1455
+ code: ZodIssueCode.too_big,
1456
+ message: check.message,
1457
+ inclusive: true,
1458
+ exact: false,
1459
+ maximum: check.value,
1460
+ type: "date"
1461
+ });
1462
+ status.dirty();
1463
+ }
1464
+ } else {
1465
+ util.assertNever(check);
1466
+ }
1467
+ }
1468
+ return {
1469
+ status: status.value,
1470
+ value: new Date(input.data.getTime())
1471
+ };
1472
+ }
1473
+ _addCheck(check) {
1474
+ return new ZodDate({
1475
+ ...this._def,
1476
+ checks: [...this._def.checks, check]
1477
+ });
1478
+ }
1479
+ min(minDate, message) {
1480
+ return this._addCheck({
1481
+ kind: "min",
1482
+ value: minDate.getTime(),
1483
+ message: errorUtil.toString(message)
1484
+ });
1485
+ }
1486
+ max(maxDate, message) {
1487
+ return this._addCheck({
1488
+ kind: "max",
1489
+ value: maxDate.getTime(),
1490
+ message: errorUtil.toString(message)
1491
+ });
1492
+ }
1493
+ get minDate() {
1494
+ let min = null;
1495
+ for (const ch of this._def.checks) {
1496
+ if (ch.kind === "min") {
1497
+ if (min === null || ch.value > min)
1498
+ min = ch.value;
1499
+ }
1500
+ }
1501
+ return min != null ? new Date(min) : null;
1502
+ }
1503
+ get maxDate() {
1504
+ let max = null;
1505
+ for (const ch of this._def.checks) {
1506
+ if (ch.kind === "max") {
1507
+ if (max === null || ch.value < max)
1508
+ max = ch.value;
1509
+ }
1510
+ }
1511
+ return max != null ? new Date(max) : null;
1512
+ }
1513
+ }
1514
+ ZodDate.create = (params) => {
1515
+ return new ZodDate({
1516
+ checks: [],
1517
+ coerce: (params == null ? void 0 : params.coerce) || false,
1518
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1519
+ ...processCreateParams(params)
1520
+ });
1521
+ };
1522
+ class ZodSymbol extends ZodType {
1523
+ _parse(input) {
1524
+ const parsedType = this._getType(input);
1525
+ if (parsedType !== ZodParsedType.symbol) {
1526
+ const ctx = this._getOrReturnCtx(input);
1527
+ addIssueToContext(ctx, {
1528
+ code: ZodIssueCode.invalid_type,
1529
+ expected: ZodParsedType.symbol,
1530
+ received: ctx.parsedType
1531
+ });
1532
+ return INVALID;
1533
+ }
1534
+ return OK(input.data);
1535
+ }
1536
+ }
1537
+ ZodSymbol.create = (params) => {
1538
+ return new ZodSymbol({
1539
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
1540
+ ...processCreateParams(params)
1541
+ });
1542
+ };
1543
+ class ZodUndefined extends ZodType {
1544
+ _parse(input) {
1545
+ const parsedType = this._getType(input);
1546
+ if (parsedType !== ZodParsedType.undefined) {
1547
+ const ctx = this._getOrReturnCtx(input);
1548
+ addIssueToContext(ctx, {
1549
+ code: ZodIssueCode.invalid_type,
1550
+ expected: ZodParsedType.undefined,
1551
+ received: ctx.parsedType
1552
+ });
1553
+ return INVALID;
1554
+ }
1555
+ return OK(input.data);
1556
+ }
1557
+ }
1558
+ ZodUndefined.create = (params) => {
1559
+ return new ZodUndefined({
1560
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
1561
+ ...processCreateParams(params)
1562
+ });
1563
+ };
1564
+ class ZodNull extends ZodType {
1565
+ _parse(input) {
1566
+ const parsedType = this._getType(input);
1567
+ if (parsedType !== ZodParsedType.null) {
1568
+ const ctx = this._getOrReturnCtx(input);
1569
+ addIssueToContext(ctx, {
1570
+ code: ZodIssueCode.invalid_type,
1571
+ expected: ZodParsedType.null,
1572
+ received: ctx.parsedType
1573
+ });
1574
+ return INVALID;
1575
+ }
1576
+ return OK(input.data);
1577
+ }
1578
+ }
1579
+ ZodNull.create = (params) => {
1580
+ return new ZodNull({
1581
+ typeName: ZodFirstPartyTypeKind.ZodNull,
1582
+ ...processCreateParams(params)
1583
+ });
1584
+ };
1585
+ class ZodAny extends ZodType {
1586
+ constructor() {
1587
+ super(...arguments);
1588
+ this._any = true;
1589
+ }
1590
+ _parse(input) {
1591
+ return OK(input.data);
1592
+ }
1593
+ }
1594
+ ZodAny.create = (params) => {
1595
+ return new ZodAny({
1596
+ typeName: ZodFirstPartyTypeKind.ZodAny,
1597
+ ...processCreateParams(params)
1598
+ });
1599
+ };
1600
+ class ZodUnknown extends ZodType {
1601
+ constructor() {
1602
+ super(...arguments);
1603
+ this._unknown = true;
1604
+ }
1605
+ _parse(input) {
1606
+ return OK(input.data);
1607
+ }
1608
+ }
1609
+ ZodUnknown.create = (params) => {
1610
+ return new ZodUnknown({
1611
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
1612
+ ...processCreateParams(params)
1613
+ });
1614
+ };
1615
+ class ZodNever extends ZodType {
1616
+ _parse(input) {
1617
+ const ctx = this._getOrReturnCtx(input);
1618
+ addIssueToContext(ctx, {
1619
+ code: ZodIssueCode.invalid_type,
1620
+ expected: ZodParsedType.never,
1621
+ received: ctx.parsedType
1622
+ });
1623
+ return INVALID;
1624
+ }
1625
+ }
1626
+ ZodNever.create = (params) => {
1627
+ return new ZodNever({
1628
+ typeName: ZodFirstPartyTypeKind.ZodNever,
1629
+ ...processCreateParams(params)
1630
+ });
1631
+ };
1632
+ class ZodVoid extends ZodType {
1633
+ _parse(input) {
1634
+ const parsedType = this._getType(input);
1635
+ if (parsedType !== ZodParsedType.undefined) {
1636
+ const ctx = this._getOrReturnCtx(input);
1637
+ addIssueToContext(ctx, {
1638
+ code: ZodIssueCode.invalid_type,
1639
+ expected: ZodParsedType.void,
1640
+ received: ctx.parsedType
1641
+ });
1642
+ return INVALID;
1643
+ }
1644
+ return OK(input.data);
1645
+ }
1646
+ }
1647
+ ZodVoid.create = (params) => {
1648
+ return new ZodVoid({
1649
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
1650
+ ...processCreateParams(params)
1651
+ });
1652
+ };
1653
+ class ZodArray extends ZodType {
1654
+ _parse(input) {
1655
+ const { ctx, status } = this._processInputParams(input);
1656
+ const def = this._def;
1657
+ if (ctx.parsedType !== ZodParsedType.array) {
1658
+ addIssueToContext(ctx, {
1659
+ code: ZodIssueCode.invalid_type,
1660
+ expected: ZodParsedType.array,
1661
+ received: ctx.parsedType
1662
+ });
1663
+ return INVALID;
1664
+ }
1665
+ if (def.exactLength !== null) {
1666
+ const tooBig = ctx.data.length > def.exactLength.value;
1667
+ const tooSmall = ctx.data.length < def.exactLength.value;
1668
+ if (tooBig || tooSmall) {
1669
+ addIssueToContext(ctx, {
1670
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
1671
+ minimum: tooSmall ? def.exactLength.value : void 0,
1672
+ maximum: tooBig ? def.exactLength.value : void 0,
1673
+ type: "array",
1674
+ inclusive: true,
1675
+ exact: true,
1676
+ message: def.exactLength.message
1677
+ });
1678
+ status.dirty();
1679
+ }
1680
+ }
1681
+ if (def.minLength !== null) {
1682
+ if (ctx.data.length < def.minLength.value) {
1683
+ addIssueToContext(ctx, {
1684
+ code: ZodIssueCode.too_small,
1685
+ minimum: def.minLength.value,
1686
+ type: "array",
1687
+ inclusive: true,
1688
+ exact: false,
1689
+ message: def.minLength.message
1690
+ });
1691
+ status.dirty();
1692
+ }
1693
+ }
1694
+ if (def.maxLength !== null) {
1695
+ if (ctx.data.length > def.maxLength.value) {
1696
+ addIssueToContext(ctx, {
1697
+ code: ZodIssueCode.too_big,
1698
+ maximum: def.maxLength.value,
1699
+ type: "array",
1700
+ inclusive: true,
1701
+ exact: false,
1702
+ message: def.maxLength.message
1703
+ });
1704
+ status.dirty();
1705
+ }
1706
+ }
1707
+ if (ctx.common.async) {
1708
+ return Promise.all([...ctx.data].map((item, i) => {
1709
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
1710
+ })).then((result2) => {
1711
+ return ParseStatus.mergeArray(status, result2);
1712
+ });
1713
+ }
1714
+ const result = [...ctx.data].map((item, i) => {
1715
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
1716
+ });
1717
+ return ParseStatus.mergeArray(status, result);
1718
+ }
1719
+ get element() {
1720
+ return this._def.type;
1721
+ }
1722
+ min(minLength, message) {
1723
+ return new ZodArray({
1724
+ ...this._def,
1725
+ minLength: { value: minLength, message: errorUtil.toString(message) }
1726
+ });
1727
+ }
1728
+ max(maxLength, message) {
1729
+ return new ZodArray({
1730
+ ...this._def,
1731
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
1732
+ });
1733
+ }
1734
+ length(len, message) {
1735
+ return new ZodArray({
1736
+ ...this._def,
1737
+ exactLength: { value: len, message: errorUtil.toString(message) }
1738
+ });
1739
+ }
1740
+ nonempty(message) {
1741
+ return this.min(1, message);
1742
+ }
1743
+ }
1744
+ ZodArray.create = (schema, params) => {
1745
+ return new ZodArray({
1746
+ type: schema,
1747
+ minLength: null,
1748
+ maxLength: null,
1749
+ exactLength: null,
1750
+ typeName: ZodFirstPartyTypeKind.ZodArray,
1751
+ ...processCreateParams(params)
1752
+ });
1753
+ };
1754
+ function deepPartialify(schema) {
1755
+ if (schema instanceof ZodObject) {
1756
+ const newShape = {};
1757
+ for (const key in schema.shape) {
1758
+ const fieldSchema = schema.shape[key];
1759
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
1760
+ }
1761
+ return new ZodObject({
1762
+ ...schema._def,
1763
+ shape: () => newShape
1764
+ });
1765
+ } else if (schema instanceof ZodArray) {
1766
+ return new ZodArray({
1767
+ ...schema._def,
1768
+ type: deepPartialify(schema.element)
1769
+ });
1770
+ } else if (schema instanceof ZodOptional) {
1771
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
1772
+ } else if (schema instanceof ZodNullable) {
1773
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
1774
+ } else if (schema instanceof ZodTuple) {
1775
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
1776
+ } else {
1777
+ return schema;
1778
+ }
1779
+ }
1780
+ class ZodObject extends ZodType {
1781
+ constructor() {
1782
+ super(...arguments);
1783
+ this._cached = null;
1784
+ this.nonstrict = this.passthrough;
1785
+ this.augment = this.extend;
1786
+ }
1787
+ _getCached() {
1788
+ if (this._cached !== null)
1789
+ return this._cached;
1790
+ const shape = this._def.shape();
1791
+ const keys = util.objectKeys(shape);
1792
+ this._cached = { shape, keys };
1793
+ return this._cached;
1794
+ }
1795
+ _parse(input) {
1796
+ const parsedType = this._getType(input);
1797
+ if (parsedType !== ZodParsedType.object) {
1798
+ const ctx2 = this._getOrReturnCtx(input);
1799
+ addIssueToContext(ctx2, {
1800
+ code: ZodIssueCode.invalid_type,
1801
+ expected: ZodParsedType.object,
1802
+ received: ctx2.parsedType
1803
+ });
1804
+ return INVALID;
1805
+ }
1806
+ const { status, ctx } = this._processInputParams(input);
1807
+ const { shape, keys: shapeKeys } = this._getCached();
1808
+ const extraKeys = [];
1809
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
1810
+ for (const key in ctx.data) {
1811
+ if (!shapeKeys.includes(key)) {
1812
+ extraKeys.push(key);
1813
+ }
1814
+ }
1815
+ }
1816
+ const pairs = [];
1817
+ for (const key of shapeKeys) {
1818
+ const keyValidator = shape[key];
1819
+ const value = ctx.data[key];
1820
+ pairs.push({
1821
+ key: { status: "valid", value: key },
1822
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
1823
+ alwaysSet: key in ctx.data
1824
+ });
1825
+ }
1826
+ if (this._def.catchall instanceof ZodNever) {
1827
+ const unknownKeys = this._def.unknownKeys;
1828
+ if (unknownKeys === "passthrough") {
1829
+ for (const key of extraKeys) {
1830
+ pairs.push({
1831
+ key: { status: "valid", value: key },
1832
+ value: { status: "valid", value: ctx.data[key] }
1833
+ });
1834
+ }
1835
+ } else if (unknownKeys === "strict") {
1836
+ if (extraKeys.length > 0) {
1837
+ addIssueToContext(ctx, {
1838
+ code: ZodIssueCode.unrecognized_keys,
1839
+ keys: extraKeys
1840
+ });
1841
+ status.dirty();
1842
+ }
1843
+ } else if (unknownKeys === "strip") ;
1844
+ else {
1845
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
1846
+ }
1847
+ } else {
1848
+ const catchall = this._def.catchall;
1849
+ for (const key of extraKeys) {
1850
+ const value = ctx.data[key];
1851
+ pairs.push({
1852
+ key: { status: "valid", value: key },
1853
+ value: catchall._parse(
1854
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
1855
+ //, ctx.child(key), value, getParsedType(value)
1856
+ ),
1857
+ alwaysSet: key in ctx.data
1858
+ });
1859
+ }
1860
+ }
1861
+ if (ctx.common.async) {
1862
+ return Promise.resolve().then(async () => {
1863
+ const syncPairs = [];
1864
+ for (const pair of pairs) {
1865
+ const key = await pair.key;
1866
+ const value = await pair.value;
1867
+ syncPairs.push({
1868
+ key,
1869
+ value,
1870
+ alwaysSet: pair.alwaysSet
1871
+ });
1872
+ }
1873
+ return syncPairs;
1874
+ }).then((syncPairs) => {
1875
+ return ParseStatus.mergeObjectSync(status, syncPairs);
1876
+ });
1877
+ } else {
1878
+ return ParseStatus.mergeObjectSync(status, pairs);
1879
+ }
1880
+ }
1881
+ get shape() {
1882
+ return this._def.shape();
1883
+ }
1884
+ strict(message) {
1885
+ errorUtil.errToObj;
1886
+ return new ZodObject({
1887
+ ...this._def,
1888
+ unknownKeys: "strict",
1889
+ ...message !== void 0 ? {
1890
+ errorMap: (issue, ctx) => {
1891
+ var _a, _b;
1892
+ const defaultError = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) ?? ctx.defaultError;
1893
+ if (issue.code === "unrecognized_keys")
1894
+ return {
1895
+ message: errorUtil.errToObj(message).message ?? defaultError
1896
+ };
1897
+ return {
1898
+ message: defaultError
1899
+ };
1900
+ }
1901
+ } : {}
1902
+ });
1903
+ }
1904
+ strip() {
1905
+ return new ZodObject({
1906
+ ...this._def,
1907
+ unknownKeys: "strip"
1908
+ });
1909
+ }
1910
+ passthrough() {
1911
+ return new ZodObject({
1912
+ ...this._def,
1913
+ unknownKeys: "passthrough"
1914
+ });
1915
+ }
1916
+ // const AugmentFactory =
1917
+ // <Def extends ZodObjectDef>(def: Def) =>
1918
+ // <Augmentation extends ZodRawShape>(
1919
+ // augmentation: Augmentation
1920
+ // ): ZodObject<
1921
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
1922
+ // Def["unknownKeys"],
1923
+ // Def["catchall"]
1924
+ // > => {
1925
+ // return new ZodObject({
1926
+ // ...def,
1927
+ // shape: () => ({
1928
+ // ...def.shape(),
1929
+ // ...augmentation,
1930
+ // }),
1931
+ // }) as any;
1932
+ // };
1933
+ extend(augmentation) {
1934
+ return new ZodObject({
1935
+ ...this._def,
1936
+ shape: () => ({
1937
+ ...this._def.shape(),
1938
+ ...augmentation
1939
+ })
1940
+ });
1941
+ }
1942
+ /**
1943
+ * Prior to zod@1.0.12 there was a bug in the
1944
+ * inferred type of merged objects. Please
1945
+ * upgrade if you are experiencing issues.
1946
+ */
1947
+ merge(merging) {
1948
+ const merged = new ZodObject({
1949
+ unknownKeys: merging._def.unknownKeys,
1950
+ catchall: merging._def.catchall,
1951
+ shape: () => ({
1952
+ ...this._def.shape(),
1953
+ ...merging._def.shape()
1954
+ }),
1955
+ typeName: ZodFirstPartyTypeKind.ZodObject
1956
+ });
1957
+ return merged;
1958
+ }
1959
+ // merge<
1960
+ // Incoming extends AnyZodObject,
1961
+ // Augmentation extends Incoming["shape"],
1962
+ // NewOutput extends {
1963
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1964
+ // ? Augmentation[k]["_output"]
1965
+ // : k extends keyof Output
1966
+ // ? Output[k]
1967
+ // : never;
1968
+ // },
1969
+ // NewInput extends {
1970
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1971
+ // ? Augmentation[k]["_input"]
1972
+ // : k extends keyof Input
1973
+ // ? Input[k]
1974
+ // : never;
1975
+ // }
1976
+ // >(
1977
+ // merging: Incoming
1978
+ // ): ZodObject<
1979
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1980
+ // Incoming["_def"]["unknownKeys"],
1981
+ // Incoming["_def"]["catchall"],
1982
+ // NewOutput,
1983
+ // NewInput
1984
+ // > {
1985
+ // const merged: any = new ZodObject({
1986
+ // unknownKeys: merging._def.unknownKeys,
1987
+ // catchall: merging._def.catchall,
1988
+ // shape: () =>
1989
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1990
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
1991
+ // }) as any;
1992
+ // return merged;
1993
+ // }
1994
+ setKey(key, schema) {
1995
+ return this.augment({ [key]: schema });
1996
+ }
1997
+ // merge<Incoming extends AnyZodObject>(
1998
+ // merging: Incoming
1999
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2000
+ // ZodObject<
2001
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2002
+ // Incoming["_def"]["unknownKeys"],
2003
+ // Incoming["_def"]["catchall"]
2004
+ // > {
2005
+ // // const mergedShape = objectUtil.mergeShapes(
2006
+ // // this._def.shape(),
2007
+ // // merging._def.shape()
2008
+ // // );
2009
+ // const merged: any = new ZodObject({
2010
+ // unknownKeys: merging._def.unknownKeys,
2011
+ // catchall: merging._def.catchall,
2012
+ // shape: () =>
2013
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2014
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2015
+ // }) as any;
2016
+ // return merged;
2017
+ // }
2018
+ catchall(index) {
2019
+ return new ZodObject({
2020
+ ...this._def,
2021
+ catchall: index
2022
+ });
2023
+ }
2024
+ pick(mask) {
2025
+ const shape = {};
2026
+ for (const key of util.objectKeys(mask)) {
2027
+ if (mask[key] && this.shape[key]) {
2028
+ shape[key] = this.shape[key];
2029
+ }
2030
+ }
2031
+ return new ZodObject({
2032
+ ...this._def,
2033
+ shape: () => shape
2034
+ });
2035
+ }
2036
+ omit(mask) {
2037
+ const shape = {};
2038
+ for (const key of util.objectKeys(this.shape)) {
2039
+ if (!mask[key]) {
2040
+ shape[key] = this.shape[key];
2041
+ }
2042
+ }
2043
+ return new ZodObject({
2044
+ ...this._def,
2045
+ shape: () => shape
2046
+ });
2047
+ }
2048
+ /**
2049
+ * @deprecated
2050
+ */
2051
+ deepPartial() {
2052
+ return deepPartialify(this);
2053
+ }
2054
+ partial(mask) {
2055
+ const newShape = {};
2056
+ for (const key of util.objectKeys(this.shape)) {
2057
+ const fieldSchema = this.shape[key];
2058
+ if (mask && !mask[key]) {
2059
+ newShape[key] = fieldSchema;
2060
+ } else {
2061
+ newShape[key] = fieldSchema.optional();
2062
+ }
2063
+ }
2064
+ return new ZodObject({
2065
+ ...this._def,
2066
+ shape: () => newShape
2067
+ });
2068
+ }
2069
+ required(mask) {
2070
+ const newShape = {};
2071
+ for (const key of util.objectKeys(this.shape)) {
2072
+ if (mask && !mask[key]) {
2073
+ newShape[key] = this.shape[key];
2074
+ } else {
2075
+ const fieldSchema = this.shape[key];
2076
+ let newField = fieldSchema;
2077
+ while (newField instanceof ZodOptional) {
2078
+ newField = newField._def.innerType;
2079
+ }
2080
+ newShape[key] = newField;
2081
+ }
2082
+ }
2083
+ return new ZodObject({
2084
+ ...this._def,
2085
+ shape: () => newShape
2086
+ });
2087
+ }
2088
+ keyof() {
2089
+ return createZodEnum(util.objectKeys(this.shape));
2090
+ }
2091
+ }
2092
+ ZodObject.create = (shape, params) => {
2093
+ return new ZodObject({
2094
+ shape: () => shape,
2095
+ unknownKeys: "strip",
2096
+ catchall: ZodNever.create(),
2097
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2098
+ ...processCreateParams(params)
2099
+ });
2100
+ };
2101
+ ZodObject.strictCreate = (shape, params) => {
2102
+ return new ZodObject({
2103
+ shape: () => shape,
2104
+ unknownKeys: "strict",
2105
+ catchall: ZodNever.create(),
2106
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2107
+ ...processCreateParams(params)
2108
+ });
2109
+ };
2110
+ ZodObject.lazycreate = (shape, params) => {
2111
+ return new ZodObject({
2112
+ shape,
2113
+ unknownKeys: "strip",
2114
+ catchall: ZodNever.create(),
2115
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2116
+ ...processCreateParams(params)
2117
+ });
2118
+ };
2119
+ class ZodUnion extends ZodType {
2120
+ _parse(input) {
2121
+ const { ctx } = this._processInputParams(input);
2122
+ const options = this._def.options;
2123
+ function handleResults(results) {
2124
+ for (const result of results) {
2125
+ if (result.result.status === "valid") {
2126
+ return result.result;
2127
+ }
2128
+ }
2129
+ for (const result of results) {
2130
+ if (result.result.status === "dirty") {
2131
+ ctx.common.issues.push(...result.ctx.common.issues);
2132
+ return result.result;
2133
+ }
2134
+ }
2135
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2136
+ addIssueToContext(ctx, {
2137
+ code: ZodIssueCode.invalid_union,
2138
+ unionErrors
2139
+ });
2140
+ return INVALID;
2141
+ }
2142
+ if (ctx.common.async) {
2143
+ return Promise.all(options.map(async (option) => {
2144
+ const childCtx = {
2145
+ ...ctx,
2146
+ common: {
2147
+ ...ctx.common,
2148
+ issues: []
2149
+ },
2150
+ parent: null
2151
+ };
2152
+ return {
2153
+ result: await option._parseAsync({
2154
+ data: ctx.data,
2155
+ path: ctx.path,
2156
+ parent: childCtx
2157
+ }),
2158
+ ctx: childCtx
2159
+ };
2160
+ })).then(handleResults);
2161
+ } else {
2162
+ let dirty = void 0;
2163
+ const issues = [];
2164
+ for (const option of options) {
2165
+ const childCtx = {
2166
+ ...ctx,
2167
+ common: {
2168
+ ...ctx.common,
2169
+ issues: []
2170
+ },
2171
+ parent: null
2172
+ };
2173
+ const result = option._parseSync({
2174
+ data: ctx.data,
2175
+ path: ctx.path,
2176
+ parent: childCtx
2177
+ });
2178
+ if (result.status === "valid") {
2179
+ return result;
2180
+ } else if (result.status === "dirty" && !dirty) {
2181
+ dirty = { result, ctx: childCtx };
2182
+ }
2183
+ if (childCtx.common.issues.length) {
2184
+ issues.push(childCtx.common.issues);
2185
+ }
2186
+ }
2187
+ if (dirty) {
2188
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2189
+ return dirty.result;
2190
+ }
2191
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
2192
+ addIssueToContext(ctx, {
2193
+ code: ZodIssueCode.invalid_union,
2194
+ unionErrors
2195
+ });
2196
+ return INVALID;
2197
+ }
2198
+ }
2199
+ get options() {
2200
+ return this._def.options;
2201
+ }
2202
+ }
2203
+ ZodUnion.create = (types, params) => {
2204
+ return new ZodUnion({
2205
+ options: types,
2206
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2207
+ ...processCreateParams(params)
2208
+ });
2209
+ };
2210
+ function mergeValues(a, b) {
2211
+ const aType = getParsedType(a);
2212
+ const bType = getParsedType(b);
2213
+ if (a === b) {
2214
+ return { valid: true, data: a };
2215
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2216
+ const bKeys = util.objectKeys(b);
2217
+ const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2218
+ const newObj = { ...a, ...b };
2219
+ for (const key of sharedKeys) {
2220
+ const sharedValue = mergeValues(a[key], b[key]);
2221
+ if (!sharedValue.valid) {
2222
+ return { valid: false };
2223
+ }
2224
+ newObj[key] = sharedValue.data;
2225
+ }
2226
+ return { valid: true, data: newObj };
2227
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2228
+ if (a.length !== b.length) {
2229
+ return { valid: false };
2230
+ }
2231
+ const newArray = [];
2232
+ for (let index = 0; index < a.length; index++) {
2233
+ const itemA = a[index];
2234
+ const itemB = b[index];
2235
+ const sharedValue = mergeValues(itemA, itemB);
2236
+ if (!sharedValue.valid) {
2237
+ return { valid: false };
2238
+ }
2239
+ newArray.push(sharedValue.data);
2240
+ }
2241
+ return { valid: true, data: newArray };
2242
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
2243
+ return { valid: true, data: a };
2244
+ } else {
2245
+ return { valid: false };
2246
+ }
2247
+ }
2248
+ class ZodIntersection extends ZodType {
2249
+ _parse(input) {
2250
+ const { status, ctx } = this._processInputParams(input);
2251
+ const handleParsed = (parsedLeft, parsedRight) => {
2252
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2253
+ return INVALID;
2254
+ }
2255
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2256
+ if (!merged.valid) {
2257
+ addIssueToContext(ctx, {
2258
+ code: ZodIssueCode.invalid_intersection_types
2259
+ });
2260
+ return INVALID;
2261
+ }
2262
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2263
+ status.dirty();
2264
+ }
2265
+ return { status: status.value, value: merged.data };
2266
+ };
2267
+ if (ctx.common.async) {
2268
+ return Promise.all([
2269
+ this._def.left._parseAsync({
2270
+ data: ctx.data,
2271
+ path: ctx.path,
2272
+ parent: ctx
2273
+ }),
2274
+ this._def.right._parseAsync({
2275
+ data: ctx.data,
2276
+ path: ctx.path,
2277
+ parent: ctx
2278
+ })
2279
+ ]).then(([left, right]) => handleParsed(left, right));
2280
+ } else {
2281
+ return handleParsed(this._def.left._parseSync({
2282
+ data: ctx.data,
2283
+ path: ctx.path,
2284
+ parent: ctx
2285
+ }), this._def.right._parseSync({
2286
+ data: ctx.data,
2287
+ path: ctx.path,
2288
+ parent: ctx
2289
+ }));
2290
+ }
2291
+ }
2292
+ }
2293
+ ZodIntersection.create = (left, right, params) => {
2294
+ return new ZodIntersection({
2295
+ left,
2296
+ right,
2297
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2298
+ ...processCreateParams(params)
2299
+ });
2300
+ };
2301
+ class ZodTuple extends ZodType {
2302
+ _parse(input) {
2303
+ const { status, ctx } = this._processInputParams(input);
2304
+ if (ctx.parsedType !== ZodParsedType.array) {
2305
+ addIssueToContext(ctx, {
2306
+ code: ZodIssueCode.invalid_type,
2307
+ expected: ZodParsedType.array,
2308
+ received: ctx.parsedType
2309
+ });
2310
+ return INVALID;
2311
+ }
2312
+ if (ctx.data.length < this._def.items.length) {
2313
+ addIssueToContext(ctx, {
2314
+ code: ZodIssueCode.too_small,
2315
+ minimum: this._def.items.length,
2316
+ inclusive: true,
2317
+ exact: false,
2318
+ type: "array"
2319
+ });
2320
+ return INVALID;
2321
+ }
2322
+ const rest = this._def.rest;
2323
+ if (!rest && ctx.data.length > this._def.items.length) {
2324
+ addIssueToContext(ctx, {
2325
+ code: ZodIssueCode.too_big,
2326
+ maximum: this._def.items.length,
2327
+ inclusive: true,
2328
+ exact: false,
2329
+ type: "array"
2330
+ });
2331
+ status.dirty();
2332
+ }
2333
+ const items = [...ctx.data].map((item, itemIndex) => {
2334
+ const schema = this._def.items[itemIndex] || this._def.rest;
2335
+ if (!schema)
2336
+ return null;
2337
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2338
+ }).filter((x) => !!x);
2339
+ if (ctx.common.async) {
2340
+ return Promise.all(items).then((results) => {
2341
+ return ParseStatus.mergeArray(status, results);
2342
+ });
2343
+ } else {
2344
+ return ParseStatus.mergeArray(status, items);
2345
+ }
2346
+ }
2347
+ get items() {
2348
+ return this._def.items;
2349
+ }
2350
+ rest(rest) {
2351
+ return new ZodTuple({
2352
+ ...this._def,
2353
+ rest
2354
+ });
2355
+ }
2356
+ }
2357
+ ZodTuple.create = (schemas, params) => {
2358
+ if (!Array.isArray(schemas)) {
2359
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2360
+ }
2361
+ return new ZodTuple({
2362
+ items: schemas,
2363
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2364
+ rest: null,
2365
+ ...processCreateParams(params)
2366
+ });
2367
+ };
2368
+ class ZodRecord extends ZodType {
2369
+ get keySchema() {
2370
+ return this._def.keyType;
2371
+ }
2372
+ get valueSchema() {
2373
+ return this._def.valueType;
2374
+ }
2375
+ _parse(input) {
2376
+ const { status, ctx } = this._processInputParams(input);
2377
+ if (ctx.parsedType !== ZodParsedType.object) {
2378
+ addIssueToContext(ctx, {
2379
+ code: ZodIssueCode.invalid_type,
2380
+ expected: ZodParsedType.object,
2381
+ received: ctx.parsedType
2382
+ });
2383
+ return INVALID;
2384
+ }
2385
+ const pairs = [];
2386
+ const keyType = this._def.keyType;
2387
+ const valueType = this._def.valueType;
2388
+ for (const key in ctx.data) {
2389
+ pairs.push({
2390
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2391
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2392
+ alwaysSet: key in ctx.data
2393
+ });
2394
+ }
2395
+ if (ctx.common.async) {
2396
+ return ParseStatus.mergeObjectAsync(status, pairs);
2397
+ } else {
2398
+ return ParseStatus.mergeObjectSync(status, pairs);
2399
+ }
2400
+ }
2401
+ get element() {
2402
+ return this._def.valueType;
2403
+ }
2404
+ static create(first, second, third) {
2405
+ if (second instanceof ZodType) {
2406
+ return new ZodRecord({
2407
+ keyType: first,
2408
+ valueType: second,
2409
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2410
+ ...processCreateParams(third)
2411
+ });
2412
+ }
2413
+ return new ZodRecord({
2414
+ keyType: ZodString.create(),
2415
+ valueType: first,
2416
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2417
+ ...processCreateParams(second)
2418
+ });
2419
+ }
2420
+ }
2421
+ class ZodMap extends ZodType {
2422
+ get keySchema() {
2423
+ return this._def.keyType;
2424
+ }
2425
+ get valueSchema() {
2426
+ return this._def.valueType;
2427
+ }
2428
+ _parse(input) {
2429
+ const { status, ctx } = this._processInputParams(input);
2430
+ if (ctx.parsedType !== ZodParsedType.map) {
2431
+ addIssueToContext(ctx, {
2432
+ code: ZodIssueCode.invalid_type,
2433
+ expected: ZodParsedType.map,
2434
+ received: ctx.parsedType
2435
+ });
2436
+ return INVALID;
2437
+ }
2438
+ const keyType = this._def.keyType;
2439
+ const valueType = this._def.valueType;
2440
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2441
+ return {
2442
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2443
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
2444
+ };
2445
+ });
2446
+ if (ctx.common.async) {
2447
+ const finalMap = /* @__PURE__ */ new Map();
2448
+ return Promise.resolve().then(async () => {
2449
+ for (const pair of pairs) {
2450
+ const key = await pair.key;
2451
+ const value = await pair.value;
2452
+ if (key.status === "aborted" || value.status === "aborted") {
2453
+ return INVALID;
2454
+ }
2455
+ if (key.status === "dirty" || value.status === "dirty") {
2456
+ status.dirty();
2457
+ }
2458
+ finalMap.set(key.value, value.value);
2459
+ }
2460
+ return { status: status.value, value: finalMap };
2461
+ });
2462
+ } else {
2463
+ const finalMap = /* @__PURE__ */ new Map();
2464
+ for (const pair of pairs) {
2465
+ const key = pair.key;
2466
+ const value = pair.value;
2467
+ if (key.status === "aborted" || value.status === "aborted") {
2468
+ return INVALID;
2469
+ }
2470
+ if (key.status === "dirty" || value.status === "dirty") {
2471
+ status.dirty();
2472
+ }
2473
+ finalMap.set(key.value, value.value);
2474
+ }
2475
+ return { status: status.value, value: finalMap };
2476
+ }
2477
+ }
2478
+ }
2479
+ ZodMap.create = (keyType, valueType, params) => {
2480
+ return new ZodMap({
2481
+ valueType,
2482
+ keyType,
2483
+ typeName: ZodFirstPartyTypeKind.ZodMap,
2484
+ ...processCreateParams(params)
2485
+ });
2486
+ };
2487
+ class ZodSet extends ZodType {
2488
+ _parse(input) {
2489
+ const { status, ctx } = this._processInputParams(input);
2490
+ if (ctx.parsedType !== ZodParsedType.set) {
2491
+ addIssueToContext(ctx, {
2492
+ code: ZodIssueCode.invalid_type,
2493
+ expected: ZodParsedType.set,
2494
+ received: ctx.parsedType
2495
+ });
2496
+ return INVALID;
2497
+ }
2498
+ const def = this._def;
2499
+ if (def.minSize !== null) {
2500
+ if (ctx.data.size < def.minSize.value) {
2501
+ addIssueToContext(ctx, {
2502
+ code: ZodIssueCode.too_small,
2503
+ minimum: def.minSize.value,
2504
+ type: "set",
2505
+ inclusive: true,
2506
+ exact: false,
2507
+ message: def.minSize.message
2508
+ });
2509
+ status.dirty();
2510
+ }
2511
+ }
2512
+ if (def.maxSize !== null) {
2513
+ if (ctx.data.size > def.maxSize.value) {
2514
+ addIssueToContext(ctx, {
2515
+ code: ZodIssueCode.too_big,
2516
+ maximum: def.maxSize.value,
2517
+ type: "set",
2518
+ inclusive: true,
2519
+ exact: false,
2520
+ message: def.maxSize.message
2521
+ });
2522
+ status.dirty();
2523
+ }
2524
+ }
2525
+ const valueType = this._def.valueType;
2526
+ function finalizeSet(elements2) {
2527
+ const parsedSet = /* @__PURE__ */ new Set();
2528
+ for (const element of elements2) {
2529
+ if (element.status === "aborted")
2530
+ return INVALID;
2531
+ if (element.status === "dirty")
2532
+ status.dirty();
2533
+ parsedSet.add(element.value);
2534
+ }
2535
+ return { status: status.value, value: parsedSet };
2536
+ }
2537
+ const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2538
+ if (ctx.common.async) {
2539
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
2540
+ } else {
2541
+ return finalizeSet(elements);
2542
+ }
2543
+ }
2544
+ min(minSize, message) {
2545
+ return new ZodSet({
2546
+ ...this._def,
2547
+ minSize: { value: minSize, message: errorUtil.toString(message) }
2548
+ });
2549
+ }
2550
+ max(maxSize, message) {
2551
+ return new ZodSet({
2552
+ ...this._def,
2553
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
2554
+ });
2555
+ }
2556
+ size(size, message) {
2557
+ return this.min(size, message).max(size, message);
2558
+ }
2559
+ nonempty(message) {
2560
+ return this.min(1, message);
2561
+ }
2562
+ }
2563
+ ZodSet.create = (valueType, params) => {
2564
+ return new ZodSet({
2565
+ valueType,
2566
+ minSize: null,
2567
+ maxSize: null,
2568
+ typeName: ZodFirstPartyTypeKind.ZodSet,
2569
+ ...processCreateParams(params)
2570
+ });
2571
+ };
2572
+ class ZodLazy extends ZodType {
2573
+ get schema() {
2574
+ return this._def.getter();
2575
+ }
2576
+ _parse(input) {
2577
+ const { ctx } = this._processInputParams(input);
2578
+ const lazySchema = this._def.getter();
2579
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
2580
+ }
2581
+ }
2582
+ ZodLazy.create = (getter, params) => {
2583
+ return new ZodLazy({
2584
+ getter,
2585
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
2586
+ ...processCreateParams(params)
2587
+ });
2588
+ };
2589
+ class ZodLiteral extends ZodType {
2590
+ _parse(input) {
2591
+ if (input.data !== this._def.value) {
2592
+ const ctx = this._getOrReturnCtx(input);
2593
+ addIssueToContext(ctx, {
2594
+ received: ctx.data,
2595
+ code: ZodIssueCode.invalid_literal,
2596
+ expected: this._def.value
2597
+ });
2598
+ return INVALID;
2599
+ }
2600
+ return { status: "valid", value: input.data };
2601
+ }
2602
+ get value() {
2603
+ return this._def.value;
2604
+ }
2605
+ }
2606
+ ZodLiteral.create = (value, params) => {
2607
+ return new ZodLiteral({
2608
+ value,
2609
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
2610
+ ...processCreateParams(params)
2611
+ });
2612
+ };
2613
+ function createZodEnum(values, params) {
2614
+ return new ZodEnum({
2615
+ values,
2616
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
2617
+ ...processCreateParams(params)
2618
+ });
2619
+ }
2620
+ class ZodEnum extends ZodType {
2621
+ _parse(input) {
2622
+ if (typeof input.data !== "string") {
2623
+ const ctx = this._getOrReturnCtx(input);
2624
+ const expectedValues = this._def.values;
2625
+ addIssueToContext(ctx, {
2626
+ expected: util.joinValues(expectedValues),
2627
+ received: ctx.parsedType,
2628
+ code: ZodIssueCode.invalid_type
2629
+ });
2630
+ return INVALID;
2631
+ }
2632
+ if (!this._cache) {
2633
+ this._cache = new Set(this._def.values);
2634
+ }
2635
+ if (!this._cache.has(input.data)) {
2636
+ const ctx = this._getOrReturnCtx(input);
2637
+ const expectedValues = this._def.values;
2638
+ addIssueToContext(ctx, {
2639
+ received: ctx.data,
2640
+ code: ZodIssueCode.invalid_enum_value,
2641
+ options: expectedValues
2642
+ });
2643
+ return INVALID;
2644
+ }
2645
+ return OK(input.data);
2646
+ }
2647
+ get options() {
2648
+ return this._def.values;
2649
+ }
2650
+ get enum() {
2651
+ const enumValues = {};
2652
+ for (const val of this._def.values) {
2653
+ enumValues[val] = val;
2654
+ }
2655
+ return enumValues;
2656
+ }
2657
+ get Values() {
2658
+ const enumValues = {};
2659
+ for (const val of this._def.values) {
2660
+ enumValues[val] = val;
2661
+ }
2662
+ return enumValues;
2663
+ }
2664
+ get Enum() {
2665
+ const enumValues = {};
2666
+ for (const val of this._def.values) {
2667
+ enumValues[val] = val;
2668
+ }
2669
+ return enumValues;
2670
+ }
2671
+ extract(values, newDef = this._def) {
2672
+ return ZodEnum.create(values, {
2673
+ ...this._def,
2674
+ ...newDef
2675
+ });
2676
+ }
2677
+ exclude(values, newDef = this._def) {
2678
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
2679
+ ...this._def,
2680
+ ...newDef
2681
+ });
2682
+ }
2683
+ }
2684
+ ZodEnum.create = createZodEnum;
2685
+ class ZodNativeEnum extends ZodType {
2686
+ _parse(input) {
2687
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
2688
+ const ctx = this._getOrReturnCtx(input);
2689
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
2690
+ const expectedValues = util.objectValues(nativeEnumValues);
2691
+ addIssueToContext(ctx, {
2692
+ expected: util.joinValues(expectedValues),
2693
+ received: ctx.parsedType,
2694
+ code: ZodIssueCode.invalid_type
2695
+ });
2696
+ return INVALID;
2697
+ }
2698
+ if (!this._cache) {
2699
+ this._cache = new Set(util.getValidEnumValues(this._def.values));
2700
+ }
2701
+ if (!this._cache.has(input.data)) {
2702
+ const expectedValues = util.objectValues(nativeEnumValues);
2703
+ addIssueToContext(ctx, {
2704
+ received: ctx.data,
2705
+ code: ZodIssueCode.invalid_enum_value,
2706
+ options: expectedValues
2707
+ });
2708
+ return INVALID;
2709
+ }
2710
+ return OK(input.data);
2711
+ }
2712
+ get enum() {
2713
+ return this._def.values;
2714
+ }
2715
+ }
2716
+ ZodNativeEnum.create = (values, params) => {
2717
+ return new ZodNativeEnum({
2718
+ values,
2719
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
2720
+ ...processCreateParams(params)
2721
+ });
2722
+ };
2723
+ class ZodPromise extends ZodType {
2724
+ unwrap() {
2725
+ return this._def.type;
2726
+ }
2727
+ _parse(input) {
2728
+ const { ctx } = this._processInputParams(input);
2729
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
2730
+ addIssueToContext(ctx, {
2731
+ code: ZodIssueCode.invalid_type,
2732
+ expected: ZodParsedType.promise,
2733
+ received: ctx.parsedType
2734
+ });
2735
+ return INVALID;
2736
+ }
2737
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
2738
+ return OK(promisified.then((data) => {
2739
+ return this._def.type.parseAsync(data, {
2740
+ path: ctx.path,
2741
+ errorMap: ctx.common.contextualErrorMap
2742
+ });
2743
+ }));
2744
+ }
2745
+ }
2746
+ ZodPromise.create = (schema, params) => {
2747
+ return new ZodPromise({
2748
+ type: schema,
2749
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
2750
+ ...processCreateParams(params)
2751
+ });
2752
+ };
2753
+ class ZodEffects extends ZodType {
2754
+ innerType() {
2755
+ return this._def.schema;
2756
+ }
2757
+ sourceType() {
2758
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
2759
+ }
2760
+ _parse(input) {
2761
+ const { status, ctx } = this._processInputParams(input);
2762
+ const effect = this._def.effect || null;
2763
+ const checkCtx = {
2764
+ addIssue: (arg) => {
2765
+ addIssueToContext(ctx, arg);
2766
+ if (arg.fatal) {
2767
+ status.abort();
2768
+ } else {
2769
+ status.dirty();
2770
+ }
2771
+ },
2772
+ get path() {
2773
+ return ctx.path;
2774
+ }
2775
+ };
2776
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
2777
+ if (effect.type === "preprocess") {
2778
+ const processed = effect.transform(ctx.data, checkCtx);
2779
+ if (ctx.common.async) {
2780
+ return Promise.resolve(processed).then(async (processed2) => {
2781
+ if (status.value === "aborted")
2782
+ return INVALID;
2783
+ const result = await this._def.schema._parseAsync({
2784
+ data: processed2,
2785
+ path: ctx.path,
2786
+ parent: ctx
2787
+ });
2788
+ if (result.status === "aborted")
2789
+ return INVALID;
2790
+ if (result.status === "dirty")
2791
+ return DIRTY(result.value);
2792
+ if (status.value === "dirty")
2793
+ return DIRTY(result.value);
2794
+ return result;
2795
+ });
2796
+ } else {
2797
+ if (status.value === "aborted")
2798
+ return INVALID;
2799
+ const result = this._def.schema._parseSync({
2800
+ data: processed,
2801
+ path: ctx.path,
2802
+ parent: ctx
2803
+ });
2804
+ if (result.status === "aborted")
2805
+ return INVALID;
2806
+ if (result.status === "dirty")
2807
+ return DIRTY(result.value);
2808
+ if (status.value === "dirty")
2809
+ return DIRTY(result.value);
2810
+ return result;
2811
+ }
2812
+ }
2813
+ if (effect.type === "refinement") {
2814
+ const executeRefinement = (acc) => {
2815
+ const result = effect.refinement(acc, checkCtx);
2816
+ if (ctx.common.async) {
2817
+ return Promise.resolve(result);
2818
+ }
2819
+ if (result instanceof Promise) {
2820
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
2821
+ }
2822
+ return acc;
2823
+ };
2824
+ if (ctx.common.async === false) {
2825
+ const inner = this._def.schema._parseSync({
2826
+ data: ctx.data,
2827
+ path: ctx.path,
2828
+ parent: ctx
2829
+ });
2830
+ if (inner.status === "aborted")
2831
+ return INVALID;
2832
+ if (inner.status === "dirty")
2833
+ status.dirty();
2834
+ executeRefinement(inner.value);
2835
+ return { status: status.value, value: inner.value };
2836
+ } else {
2837
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
2838
+ if (inner.status === "aborted")
2839
+ return INVALID;
2840
+ if (inner.status === "dirty")
2841
+ status.dirty();
2842
+ return executeRefinement(inner.value).then(() => {
2843
+ return { status: status.value, value: inner.value };
2844
+ });
2845
+ });
2846
+ }
2847
+ }
2848
+ if (effect.type === "transform") {
2849
+ if (ctx.common.async === false) {
2850
+ const base = this._def.schema._parseSync({
2851
+ data: ctx.data,
2852
+ path: ctx.path,
2853
+ parent: ctx
2854
+ });
2855
+ if (!isValid(base))
2856
+ return INVALID;
2857
+ const result = effect.transform(base.value, checkCtx);
2858
+ if (result instanceof Promise) {
2859
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
2860
+ }
2861
+ return { status: status.value, value: result };
2862
+ } else {
2863
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
2864
+ if (!isValid(base))
2865
+ return INVALID;
2866
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
2867
+ status: status.value,
2868
+ value: result
2869
+ }));
2870
+ });
2871
+ }
2872
+ }
2873
+ util.assertNever(effect);
2874
+ }
2875
+ }
2876
+ ZodEffects.create = (schema, effect, params) => {
2877
+ return new ZodEffects({
2878
+ schema,
2879
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2880
+ effect,
2881
+ ...processCreateParams(params)
2882
+ });
2883
+ };
2884
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
2885
+ return new ZodEffects({
2886
+ schema,
2887
+ effect: { type: "preprocess", transform: preprocess },
2888
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
2889
+ ...processCreateParams(params)
2890
+ });
2891
+ };
2892
+ class ZodOptional extends ZodType {
2893
+ _parse(input) {
2894
+ const parsedType = this._getType(input);
2895
+ if (parsedType === ZodParsedType.undefined) {
2896
+ return OK(void 0);
2897
+ }
2898
+ return this._def.innerType._parse(input);
2899
+ }
2900
+ unwrap() {
2901
+ return this._def.innerType;
2902
+ }
2903
+ }
2904
+ ZodOptional.create = (type, params) => {
2905
+ return new ZodOptional({
2906
+ innerType: type,
2907
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
2908
+ ...processCreateParams(params)
2909
+ });
2910
+ };
2911
+ class ZodNullable extends ZodType {
2912
+ _parse(input) {
2913
+ const parsedType = this._getType(input);
2914
+ if (parsedType === ZodParsedType.null) {
2915
+ return OK(null);
2916
+ }
2917
+ return this._def.innerType._parse(input);
2918
+ }
2919
+ unwrap() {
2920
+ return this._def.innerType;
2921
+ }
2922
+ }
2923
+ ZodNullable.create = (type, params) => {
2924
+ return new ZodNullable({
2925
+ innerType: type,
2926
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
2927
+ ...processCreateParams(params)
2928
+ });
2929
+ };
2930
+ class ZodDefault extends ZodType {
2931
+ _parse(input) {
2932
+ const { ctx } = this._processInputParams(input);
2933
+ let data = ctx.data;
2934
+ if (ctx.parsedType === ZodParsedType.undefined) {
2935
+ data = this._def.defaultValue();
2936
+ }
2937
+ return this._def.innerType._parse({
2938
+ data,
2939
+ path: ctx.path,
2940
+ parent: ctx
2941
+ });
2942
+ }
2943
+ removeDefault() {
2944
+ return this._def.innerType;
2945
+ }
2946
+ }
2947
+ ZodDefault.create = (type, params) => {
2948
+ return new ZodDefault({
2949
+ innerType: type,
2950
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
2951
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
2952
+ ...processCreateParams(params)
2953
+ });
2954
+ };
2955
+ class ZodCatch extends ZodType {
2956
+ _parse(input) {
2957
+ const { ctx } = this._processInputParams(input);
2958
+ const newCtx = {
2959
+ ...ctx,
2960
+ common: {
2961
+ ...ctx.common,
2962
+ issues: []
2963
+ }
2964
+ };
2965
+ const result = this._def.innerType._parse({
2966
+ data: newCtx.data,
2967
+ path: newCtx.path,
2968
+ parent: {
2969
+ ...newCtx
2970
+ }
2971
+ });
2972
+ if (isAsync(result)) {
2973
+ return result.then((result2) => {
2974
+ return {
2975
+ status: "valid",
2976
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
2977
+ get error() {
2978
+ return new ZodError(newCtx.common.issues);
2979
+ },
2980
+ input: newCtx.data
2981
+ })
2982
+ };
2983
+ });
2984
+ } else {
2985
+ return {
2986
+ status: "valid",
2987
+ value: result.status === "valid" ? result.value : this._def.catchValue({
2988
+ get error() {
2989
+ return new ZodError(newCtx.common.issues);
2990
+ },
2991
+ input: newCtx.data
2992
+ })
2993
+ };
2994
+ }
2995
+ }
2996
+ removeCatch() {
2997
+ return this._def.innerType;
2998
+ }
2999
+ }
3000
+ ZodCatch.create = (type, params) => {
3001
+ return new ZodCatch({
3002
+ innerType: type,
3003
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3004
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3005
+ ...processCreateParams(params)
3006
+ });
3007
+ };
3008
+ class ZodNaN extends ZodType {
3009
+ _parse(input) {
3010
+ const parsedType = this._getType(input);
3011
+ if (parsedType !== ZodParsedType.nan) {
3012
+ const ctx = this._getOrReturnCtx(input);
3013
+ addIssueToContext(ctx, {
3014
+ code: ZodIssueCode.invalid_type,
3015
+ expected: ZodParsedType.nan,
3016
+ received: ctx.parsedType
3017
+ });
3018
+ return INVALID;
3019
+ }
3020
+ return { status: "valid", value: input.data };
3021
+ }
3022
+ }
3023
+ ZodNaN.create = (params) => {
3024
+ return new ZodNaN({
3025
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3026
+ ...processCreateParams(params)
3027
+ });
3028
+ };
3029
+ class ZodBranded extends ZodType {
3030
+ _parse(input) {
3031
+ const { ctx } = this._processInputParams(input);
3032
+ const data = ctx.data;
3033
+ return this._def.type._parse({
3034
+ data,
3035
+ path: ctx.path,
3036
+ parent: ctx
3037
+ });
3038
+ }
3039
+ unwrap() {
3040
+ return this._def.type;
3041
+ }
3042
+ }
3043
+ class ZodPipeline extends ZodType {
3044
+ _parse(input) {
3045
+ const { status, ctx } = this._processInputParams(input);
3046
+ if (ctx.common.async) {
3047
+ const handleAsync = async () => {
3048
+ const inResult = await this._def.in._parseAsync({
3049
+ data: ctx.data,
3050
+ path: ctx.path,
3051
+ parent: ctx
3052
+ });
3053
+ if (inResult.status === "aborted")
3054
+ return INVALID;
3055
+ if (inResult.status === "dirty") {
3056
+ status.dirty();
3057
+ return DIRTY(inResult.value);
3058
+ } else {
3059
+ return this._def.out._parseAsync({
3060
+ data: inResult.value,
3061
+ path: ctx.path,
3062
+ parent: ctx
3063
+ });
3064
+ }
3065
+ };
3066
+ return handleAsync();
3067
+ } else {
3068
+ const inResult = this._def.in._parseSync({
3069
+ data: ctx.data,
3070
+ path: ctx.path,
3071
+ parent: ctx
3072
+ });
3073
+ if (inResult.status === "aborted")
3074
+ return INVALID;
3075
+ if (inResult.status === "dirty") {
3076
+ status.dirty();
3077
+ return {
3078
+ status: "dirty",
3079
+ value: inResult.value
3080
+ };
3081
+ } else {
3082
+ return this._def.out._parseSync({
3083
+ data: inResult.value,
3084
+ path: ctx.path,
3085
+ parent: ctx
3086
+ });
3087
+ }
3088
+ }
3089
+ }
3090
+ static create(a, b) {
3091
+ return new ZodPipeline({
3092
+ in: a,
3093
+ out: b,
3094
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
3095
+ });
3096
+ }
3097
+ }
3098
+ class ZodReadonly extends ZodType {
3099
+ _parse(input) {
3100
+ const result = this._def.innerType._parse(input);
3101
+ const freeze = (data) => {
3102
+ if (isValid(data)) {
3103
+ data.value = Object.freeze(data.value);
3104
+ }
3105
+ return data;
3106
+ };
3107
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3108
+ }
3109
+ unwrap() {
3110
+ return this._def.innerType;
3111
+ }
3112
+ }
3113
+ ZodReadonly.create = (type, params) => {
3114
+ return new ZodReadonly({
3115
+ innerType: type,
3116
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3117
+ ...processCreateParams(params)
3118
+ });
3119
+ };
3120
+ var ZodFirstPartyTypeKind;
3121
+ (function(ZodFirstPartyTypeKind2) {
3122
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3123
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3124
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3125
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3126
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3127
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3128
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3129
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3130
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3131
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3132
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3133
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3134
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3135
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3136
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3137
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3138
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3139
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3140
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3141
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3142
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3143
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3144
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3145
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3146
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3147
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3148
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3149
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3150
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3151
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
3152
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
3153
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
3154
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
3155
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
3156
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
3157
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
3158
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3159
+ const stringType = ZodString.create;
3160
+ const numberType = ZodNumber.create;
3161
+ const booleanType = ZodBoolean.create;
3162
+ const anyType = ZodAny.create;
3163
+ const unknownType = ZodUnknown.create;
3164
+ ZodNever.create;
3165
+ const arrayType = ZodArray.create;
3166
+ const objectType = ZodObject.create;
3167
+ const unionType = ZodUnion.create;
3168
+ ZodIntersection.create;
3169
+ const tupleType = ZodTuple.create;
3170
+ const recordType = ZodRecord.create;
3171
+ const literalType = ZodLiteral.create;
3172
+ const enumType = ZodEnum.create;
3173
+ ZodPromise.create;
3174
+ ZodOptional.create;
3175
+ ZodNullable.create;
3176
+ export {
3177
+ ZodType as Schema,
3178
+ ZodAny,
3179
+ ZodArray,
3180
+ ZodBigInt,
3181
+ ZodBoolean,
3182
+ ZodBranded,
3183
+ ZodCatch,
3184
+ ZodDate,
3185
+ ZodDefault,
3186
+ ZodEffects,
3187
+ ZodEnum,
3188
+ ZodFirstPartyTypeKind,
3189
+ ZodIntersection,
3190
+ ZodLazy,
3191
+ ZodLiteral,
3192
+ ZodMap,
3193
+ ZodNaN,
3194
+ ZodNativeEnum,
3195
+ ZodNever,
3196
+ ZodNull,
3197
+ ZodNullable,
3198
+ ZodNumber,
3199
+ ZodObject,
3200
+ ZodOptional,
3201
+ ZodPipeline,
3202
+ ZodPromise,
3203
+ ZodReadonly,
3204
+ ZodRecord,
3205
+ ZodType as ZodSchema,
3206
+ ZodSet,
3207
+ ZodString,
3208
+ ZodSymbol,
3209
+ ZodEffects as ZodTransformer,
3210
+ ZodTuple,
3211
+ ZodType,
3212
+ ZodUndefined,
3213
+ ZodUnion,
3214
+ ZodUnknown,
3215
+ ZodVoid,
3216
+ anyType as any,
3217
+ arrayType as array,
3218
+ booleanType as boolean,
3219
+ datetimeRegex,
3220
+ enumType as enum,
3221
+ literalType as literal,
3222
+ numberType as number,
3223
+ objectType as object,
3224
+ recordType as record,
3225
+ stringType as string,
3226
+ tupleType as tuple,
3227
+ unionType as union,
3228
+ unknownType as unknown
3229
+ };
3230
+ //# sourceMappingURL=types.js.map