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