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