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