@plyaz/types 1.13.17 → 1.14.0

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