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