@squadbase/server 0.2.0 → 0.2.1

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