@apps-in-toss/web-framework 0.0.0-dev.1741344445455 → 0.0.0-dev.1741598175595

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