@wise/dynamic-flow-types 3.1.0 → 3.1.2

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