@nine-lab/nine-mu 0.1.200 → 0.1.201

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/dist/nine-mu.js CHANGED
@@ -18,3577 +18,6 @@ class Trace extends trace$1.constructor {
18
18
  }
19
19
  }
20
20
  const trace = new Trace();
21
- var util$1;
22
- (function(util2) {
23
- util2.assertEqual = (_) => {
24
- };
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 = (items2) => {
33
- const obj = {};
34
- for (const item of items2) {
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) : (object2) => {
53
- const keys = [];
54
- for (const key in object2) {
55
- if (Object.prototype.hasOwnProperty.call(object2, 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" && Number.isFinite(val) && Math.floor(val) === val;
69
- function joinValues(array2, separator = " | ") {
70
- return array2.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$1 || (util$1 = {}));
80
- var objectUtil;
81
- (function(objectUtil2) {
82
- objectUtil2.mergeShapes = (first, second) => {
83
- return {
84
- ...first,
85
- ...second
86
- // second overwrites first
87
- };
88
- };
89
- })(objectUtil || (objectUtil = {}));
90
- const ZodParsedType = util$1.arrayToEnum([
91
- "string",
92
- "nan",
93
- "number",
94
- "integer",
95
- "float",
96
- "boolean",
97
- "date",
98
- "bigint",
99
- "symbol",
100
- "function",
101
- "undefined",
102
- "null",
103
- "array",
104
- "object",
105
- "unknown",
106
- "promise",
107
- "void",
108
- "never",
109
- "map",
110
- "set"
111
- ]);
112
- const getParsedType = (data) => {
113
- const t2 = typeof data;
114
- switch (t2) {
115
- case "undefined":
116
- return ZodParsedType.undefined;
117
- case "string":
118
- return ZodParsedType.string;
119
- case "number":
120
- return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
121
- case "boolean":
122
- return ZodParsedType.boolean;
123
- case "function":
124
- return ZodParsedType.function;
125
- case "bigint":
126
- return ZodParsedType.bigint;
127
- case "symbol":
128
- return ZodParsedType.symbol;
129
- case "object":
130
- if (Array.isArray(data)) {
131
- return ZodParsedType.array;
132
- }
133
- if (data === null) {
134
- return ZodParsedType.null;
135
- }
136
- if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
137
- return ZodParsedType.promise;
138
- }
139
- if (typeof Map !== "undefined" && data instanceof Map) {
140
- return ZodParsedType.map;
141
- }
142
- if (typeof Set !== "undefined" && data instanceof Set) {
143
- return ZodParsedType.set;
144
- }
145
- if (typeof Date !== "undefined" && data instanceof Date) {
146
- return ZodParsedType.date;
147
- }
148
- return ZodParsedType.object;
149
- default:
150
- return ZodParsedType.unknown;
151
- }
152
- };
153
- const ZodIssueCode = util$1.arrayToEnum([
154
- "invalid_type",
155
- "invalid_literal",
156
- "custom",
157
- "invalid_union",
158
- "invalid_union_discriminator",
159
- "invalid_enum_value",
160
- "unrecognized_keys",
161
- "invalid_arguments",
162
- "invalid_return_type",
163
- "invalid_date",
164
- "invalid_string",
165
- "too_small",
166
- "too_big",
167
- "invalid_intersection_types",
168
- "not_multiple_of",
169
- "not_finite"
170
- ]);
171
- 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(issue2) {
195
- return issue2.message;
196
- };
197
- const fieldErrors = { _errors: [] };
198
- const processError = (error) => {
199
- for (const issue2 of error.issues) {
200
- if (issue2.code === "invalid_union") {
201
- issue2.unionErrors.map(processError);
202
- } else if (issue2.code === "invalid_return_type") {
203
- processError(issue2.returnTypeError);
204
- } else if (issue2.code === "invalid_arguments") {
205
- processError(issue2.argumentsError);
206
- } else if (issue2.path.length === 0) {
207
- fieldErrors._errors.push(mapper(issue2));
208
- } else {
209
- let curr = fieldErrors;
210
- let i = 0;
211
- while (i < issue2.path.length) {
212
- const el = issue2.path[i];
213
- const terminal = i === issue2.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(issue2));
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$1.jsonStringifyReplacer, 2);
239
- }
240
- get isEmpty() {
241
- return this.issues.length === 0;
242
- }
243
- flatten(mapper = (issue2) => issue2.message) {
244
- const fieldErrors = {};
245
- const formErrors = [];
246
- for (const sub of this.issues) {
247
- if (sub.path.length > 0) {
248
- const firstEl = sub.path[0];
249
- fieldErrors[firstEl] = fieldErrors[firstEl] || [];
250
- fieldErrors[firstEl].push(mapper(sub));
251
- } else {
252
- formErrors.push(mapper(sub));
253
- }
254
- }
255
- return { formErrors, fieldErrors };
256
- }
257
- get formErrors() {
258
- return this.flatten();
259
- }
260
- }
261
- ZodError.create = (issues) => {
262
- const error = new ZodError(issues);
263
- return error;
264
- };
265
- const errorMap = (issue2, _ctx) => {
266
- let message;
267
- switch (issue2.code) {
268
- case ZodIssueCode.invalid_type:
269
- if (issue2.received === ZodParsedType.undefined) {
270
- message = "Required";
271
- } else {
272
- message = `Expected ${issue2.expected}, received ${issue2.received}`;
273
- }
274
- break;
275
- case ZodIssueCode.invalid_literal:
276
- message = `Invalid literal value, expected ${JSON.stringify(issue2.expected, util$1.jsonStringifyReplacer)}`;
277
- break;
278
- case ZodIssueCode.unrecognized_keys:
279
- message = `Unrecognized key(s) in object: ${util$1.joinValues(issue2.keys, ", ")}`;
280
- break;
281
- case ZodIssueCode.invalid_union:
282
- message = `Invalid input`;
283
- break;
284
- case ZodIssueCode.invalid_union_discriminator:
285
- message = `Invalid discriminator value. Expected ${util$1.joinValues(issue2.options)}`;
286
- break;
287
- case ZodIssueCode.invalid_enum_value:
288
- message = `Invalid enum value. Expected ${util$1.joinValues(issue2.options)}, received '${issue2.received}'`;
289
- break;
290
- case ZodIssueCode.invalid_arguments:
291
- message = `Invalid function arguments`;
292
- break;
293
- case ZodIssueCode.invalid_return_type:
294
- message = `Invalid function return type`;
295
- break;
296
- case ZodIssueCode.invalid_date:
297
- message = `Invalid date`;
298
- break;
299
- case ZodIssueCode.invalid_string:
300
- if (typeof issue2.validation === "object") {
301
- if ("includes" in issue2.validation) {
302
- message = `Invalid input: must include "${issue2.validation.includes}"`;
303
- if (typeof issue2.validation.position === "number") {
304
- message = `${message} at one or more positions greater than or equal to ${issue2.validation.position}`;
305
- }
306
- } else if ("startsWith" in issue2.validation) {
307
- message = `Invalid input: must start with "${issue2.validation.startsWith}"`;
308
- } else if ("endsWith" in issue2.validation) {
309
- message = `Invalid input: must end with "${issue2.validation.endsWith}"`;
310
- } else {
311
- util$1.assertNever(issue2.validation);
312
- }
313
- } else if (issue2.validation !== "regex") {
314
- message = `Invalid ${issue2.validation}`;
315
- } else {
316
- message = "Invalid";
317
- }
318
- break;
319
- case ZodIssueCode.too_small:
320
- if (issue2.type === "array")
321
- message = `Array must contain ${issue2.exact ? "exactly" : issue2.inclusive ? `at least` : `more than`} ${issue2.minimum} element(s)`;
322
- else if (issue2.type === "string")
323
- message = `String must contain ${issue2.exact ? "exactly" : issue2.inclusive ? `at least` : `over`} ${issue2.minimum} character(s)`;
324
- else if (issue2.type === "number")
325
- message = `Number must be ${issue2.exact ? `exactly equal to ` : issue2.inclusive ? `greater than or equal to ` : `greater than `}${issue2.minimum}`;
326
- else if (issue2.type === "bigint")
327
- message = `Number must be ${issue2.exact ? `exactly equal to ` : issue2.inclusive ? `greater than or equal to ` : `greater than `}${issue2.minimum}`;
328
- else if (issue2.type === "date")
329
- message = `Date must be ${issue2.exact ? `exactly equal to ` : issue2.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue2.minimum))}`;
330
- else
331
- message = "Invalid input";
332
- break;
333
- case ZodIssueCode.too_big:
334
- if (issue2.type === "array")
335
- message = `Array must contain ${issue2.exact ? `exactly` : issue2.inclusive ? `at most` : `less than`} ${issue2.maximum} element(s)`;
336
- else if (issue2.type === "string")
337
- message = `String must contain ${issue2.exact ? `exactly` : issue2.inclusive ? `at most` : `under`} ${issue2.maximum} character(s)`;
338
- else if (issue2.type === "number")
339
- message = `Number must be ${issue2.exact ? `exactly` : issue2.inclusive ? `less than or equal to` : `less than`} ${issue2.maximum}`;
340
- else if (issue2.type === "bigint")
341
- message = `BigInt must be ${issue2.exact ? `exactly` : issue2.inclusive ? `less than or equal to` : `less than`} ${issue2.maximum}`;
342
- else if (issue2.type === "date")
343
- message = `Date must be ${issue2.exact ? `exactly` : issue2.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue2.maximum))}`;
344
- else
345
- message = "Invalid input";
346
- break;
347
- case ZodIssueCode.custom:
348
- message = `Invalid input`;
349
- break;
350
- case ZodIssueCode.invalid_intersection_types:
351
- message = `Intersection results could not be merged`;
352
- break;
353
- case ZodIssueCode.not_multiple_of:
354
- message = `Number must be a multiple of ${issue2.multipleOf}`;
355
- break;
356
- case ZodIssueCode.not_finite:
357
- message = "Number must be finite";
358
- break;
359
- default:
360
- message = _ctx.defaultError;
361
- util$1.assertNever(issue2);
362
- }
363
- return { message };
364
- };
365
- let overrideErrorMap = errorMap;
366
- function getErrorMap() {
367
- return overrideErrorMap;
368
- }
369
- const makeIssue = (params) => {
370
- const { data, path, errorMaps, issueData } = params;
371
- const fullPath = [...path, ...issueData.path || []];
372
- const fullIssue = {
373
- ...issueData,
374
- path: fullPath
375
- };
376
- if (issueData.message !== void 0) {
377
- return {
378
- ...issueData,
379
- path: fullPath,
380
- message: issueData.message
381
- };
382
- }
383
- let errorMessage = "";
384
- const maps = errorMaps.filter((m) => !!m).slice().reverse();
385
- for (const map of maps) {
386
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
387
- }
388
- return {
389
- ...issueData,
390
- path: fullPath,
391
- message: errorMessage
392
- };
393
- };
394
- function addIssueToContext(ctx, issueData) {
395
- const overrideMap = getErrorMap();
396
- const issue2 = makeIssue({
397
- issueData,
398
- data: ctx.data,
399
- path: ctx.path,
400
- errorMaps: [
401
- ctx.common.contextualErrorMap,
402
- // contextual error map is first priority
403
- ctx.schemaErrorMap,
404
- // then schema-bound map if available
405
- overrideMap,
406
- // then global override map
407
- overrideMap === errorMap ? void 0 : errorMap
408
- // then global default map
409
- ].filter((x) => !!x)
410
- });
411
- ctx.common.issues.push(issue2);
412
- }
413
- class ParseStatus {
414
- constructor() {
415
- this.value = "valid";
416
- }
417
- dirty() {
418
- if (this.value === "valid")
419
- this.value = "dirty";
420
- }
421
- abort() {
422
- if (this.value !== "aborted")
423
- this.value = "aborted";
424
- }
425
- static mergeArray(status, results) {
426
- const arrayValue = [];
427
- for (const s of results) {
428
- if (s.status === "aborted")
429
- return INVALID;
430
- if (s.status === "dirty")
431
- status.dirty();
432
- arrayValue.push(s.value);
433
- }
434
- return { status: status.value, value: arrayValue };
435
- }
436
- static async mergeObjectAsync(status, pairs) {
437
- const syncPairs = [];
438
- for (const pair2 of pairs) {
439
- const key = await pair2.key;
440
- const value = await pair2.value;
441
- syncPairs.push({
442
- key,
443
- value
444
- });
445
- }
446
- return ParseStatus.mergeObjectSync(status, syncPairs);
447
- }
448
- static mergeObjectSync(status, pairs) {
449
- const finalObject = {};
450
- for (const pair2 of pairs) {
451
- const { key, value } = pair2;
452
- if (key.status === "aborted")
453
- return INVALID;
454
- if (value.status === "aborted")
455
- return INVALID;
456
- if (key.status === "dirty")
457
- status.dirty();
458
- if (value.status === "dirty")
459
- status.dirty();
460
- if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair2.alwaysSet)) {
461
- finalObject[key.value] = value.value;
462
- }
463
- }
464
- return { status: status.value, value: finalObject };
465
- }
466
- }
467
- const INVALID = Object.freeze({
468
- status: "aborted"
469
- });
470
- const DIRTY = (value) => ({ status: "dirty", value });
471
- const OK = (value) => ({ status: "valid", value });
472
- const isAborted = (x) => x.status === "aborted";
473
- const isDirty = (x) => x.status === "dirty";
474
- const isValid = (x) => x.status === "valid";
475
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
476
- var errorUtil;
477
- (function(errorUtil2) {
478
- errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
479
- errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
480
- })(errorUtil || (errorUtil = {}));
481
- class ParseInputLazyPath {
482
- constructor(parent, value, path, key) {
483
- this._cachedPath = [];
484
- this.parent = parent;
485
- this.data = value;
486
- this._path = path;
487
- this._key = key;
488
- }
489
- get path() {
490
- if (!this._cachedPath.length) {
491
- if (Array.isArray(this._key)) {
492
- this._cachedPath.push(...this._path, ...this._key);
493
- } else {
494
- this._cachedPath.push(...this._path, this._key);
495
- }
496
- }
497
- return this._cachedPath;
498
- }
499
- }
500
- const handleResult = (ctx, result) => {
501
- if (isValid(result)) {
502
- return { success: true, data: result.value };
503
- } else {
504
- if (!ctx.common.issues.length) {
505
- throw new Error("Validation failed but no issues detected.");
506
- }
507
- return {
508
- success: false,
509
- get error() {
510
- if (this._error)
511
- return this._error;
512
- const error = new ZodError(ctx.common.issues);
513
- this._error = error;
514
- return this._error;
515
- }
516
- };
517
- }
518
- };
519
- function processCreateParams(params) {
520
- if (!params)
521
- return {};
522
- const { errorMap: errorMap2, invalid_type_error, required_error, description: description2 } = params;
523
- if (errorMap2 && (invalid_type_error || required_error)) {
524
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
525
- }
526
- if (errorMap2)
527
- return { errorMap: errorMap2, description: description2 };
528
- const customMap = (iss, ctx) => {
529
- const { message } = params;
530
- if (iss.code === "invalid_enum_value") {
531
- return { message: message ?? ctx.defaultError };
532
- }
533
- if (typeof ctx.data === "undefined") {
534
- return { message: message ?? required_error ?? ctx.defaultError };
535
- }
536
- if (iss.code !== "invalid_type")
537
- return { message: ctx.defaultError };
538
- return { message: message ?? invalid_type_error ?? ctx.defaultError };
539
- };
540
- return { errorMap: customMap, description: description2 };
541
- }
542
- let ZodType$1 = class ZodType {
543
- get description() {
544
- return this._def.description;
545
- }
546
- _getType(input) {
547
- return getParsedType(input.data);
548
- }
549
- _getOrReturnCtx(input, ctx) {
550
- return ctx || {
551
- common: input.parent.common,
552
- data: input.data,
553
- parsedType: getParsedType(input.data),
554
- schemaErrorMap: this._def.errorMap,
555
- path: input.path,
556
- parent: input.parent
557
- };
558
- }
559
- _processInputParams(input) {
560
- return {
561
- status: new ParseStatus(),
562
- 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
- }
572
- _parseSync(input) {
573
- const result = this._parse(input);
574
- if (isAsync(result)) {
575
- throw new Error("Synchronous parse encountered promise.");
576
- }
577
- return result;
578
- }
579
- _parseAsync(input) {
580
- const result = this._parse(input);
581
- return Promise.resolve(result);
582
- }
583
- parse(data, params) {
584
- const result = this.safeParse(data, params);
585
- if (result.success)
586
- return result.data;
587
- throw result.error;
588
- }
589
- safeParse(data, params) {
590
- const ctx = {
591
- common: {
592
- issues: [],
593
- async: (params == null ? void 0 : params.async) ?? false,
594
- contextualErrorMap: params == null ? void 0 : params.errorMap
595
- },
596
- path: (params == null ? void 0 : params.path) || [],
597
- schemaErrorMap: this._def.errorMap,
598
- parent: null,
599
- data,
600
- parsedType: getParsedType(data)
601
- };
602
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
603
- return handleResult(ctx, result);
604
- }
605
- "~validate"(data) {
606
- var _a2, _b;
607
- const ctx = {
608
- common: {
609
- issues: [],
610
- async: !!this["~standard"].async
611
- },
612
- path: [],
613
- schemaErrorMap: this._def.errorMap,
614
- parent: null,
615
- data,
616
- parsedType: getParsedType(data)
617
- };
618
- if (!this["~standard"].async) {
619
- try {
620
- const result = this._parseSync({ data, path: [], parent: ctx });
621
- return isValid(result) ? {
622
- value: result.value
623
- } : {
624
- issues: ctx.common.issues
625
- };
626
- } catch (err) {
627
- if ((_b = (_a2 = err == null ? void 0 : err.message) == null ? void 0 : _a2.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
628
- this["~standard"].async = true;
629
- }
630
- ctx.common = {
631
- issues: [],
632
- async: true
633
- };
634
- }
635
- }
636
- return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
637
- value: result.value
638
- } : {
639
- issues: ctx.common.issues
640
- });
641
- }
642
- async parseAsync(data, params) {
643
- const result = await this.safeParseAsync(data, params);
644
- if (result.success)
645
- return result.data;
646
- throw result.error;
647
- }
648
- async safeParseAsync(data, params) {
649
- const ctx = {
650
- common: {
651
- issues: [],
652
- contextualErrorMap: params == null ? void 0 : params.errorMap,
653
- async: true
654
- },
655
- path: (params == null ? void 0 : params.path) || [],
656
- schemaErrorMap: this._def.errorMap,
657
- parent: null,
658
- data,
659
- parsedType: getParsedType(data)
660
- };
661
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
662
- const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
663
- return handleResult(ctx, result);
664
- }
665
- refine(check2, message) {
666
- const getIssueProperties = (val) => {
667
- if (typeof message === "string" || typeof message === "undefined") {
668
- return { message };
669
- } else if (typeof message === "function") {
670
- return message(val);
671
- } else {
672
- return message;
673
- }
674
- };
675
- return this._refinement((val, ctx) => {
676
- const result = check2(val);
677
- const setError = () => ctx.addIssue({
678
- code: ZodIssueCode.custom,
679
- ...getIssueProperties(val)
680
- });
681
- if (typeof Promise !== "undefined" && result instanceof Promise) {
682
- return result.then((data) => {
683
- if (!data) {
684
- setError();
685
- return false;
686
- } else {
687
- return true;
688
- }
689
- });
690
- }
691
- if (!result) {
692
- setError();
693
- return false;
694
- } else {
695
- return true;
696
- }
697
- });
698
- }
699
- refinement(check2, refinementData) {
700
- return this._refinement((val, ctx) => {
701
- if (!check2(val)) {
702
- ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
703
- return false;
704
- } else {
705
- return true;
706
- }
707
- });
708
- }
709
- _refinement(refinement) {
710
- return new ZodEffects({
711
- schema: this,
712
- typeName: ZodFirstPartyTypeKind.ZodEffects,
713
- effect: { type: "refinement", refinement }
714
- });
715
- }
716
- superRefine(refinement) {
717
- return this._refinement(refinement);
718
- }
719
- constructor(def) {
720
- this.spa = this.safeParseAsync;
721
- this._def = def;
722
- this.parse = this.parse.bind(this);
723
- this.safeParse = this.safeParse.bind(this);
724
- this.parseAsync = this.parseAsync.bind(this);
725
- this.safeParseAsync = this.safeParseAsync.bind(this);
726
- this.spa = this.spa.bind(this);
727
- this.refine = this.refine.bind(this);
728
- this.refinement = this.refinement.bind(this);
729
- this.superRefine = this.superRefine.bind(this);
730
- this.optional = this.optional.bind(this);
731
- this.nullable = this.nullable.bind(this);
732
- this.nullish = this.nullish.bind(this);
733
- this.array = this.array.bind(this);
734
- this.promise = this.promise.bind(this);
735
- this.or = this.or.bind(this);
736
- this.and = this.and.bind(this);
737
- this.transform = this.transform.bind(this);
738
- this.brand = this.brand.bind(this);
739
- this.default = this.default.bind(this);
740
- this.catch = this.catch.bind(this);
741
- this.describe = this.describe.bind(this);
742
- this.pipe = this.pipe.bind(this);
743
- this.readonly = this.readonly.bind(this);
744
- this.isNullable = this.isNullable.bind(this);
745
- this.isOptional = this.isOptional.bind(this);
746
- this["~standard"] = {
747
- version: 1,
748
- vendor: "zod",
749
- validate: (data) => this["~validate"](data)
750
- };
751
- }
752
- optional() {
753
- return ZodOptional$1.create(this, this._def);
754
- }
755
- nullable() {
756
- return ZodNullable$1.create(this, this._def);
757
- }
758
- nullish() {
759
- return this.nullable().optional();
760
- }
761
- array() {
762
- return ZodArray$1.create(this);
763
- }
764
- promise() {
765
- return ZodPromise.create(this, this._def);
766
- }
767
- or(option) {
768
- return ZodUnion$1.create([this, option], this._def);
769
- }
770
- and(incoming) {
771
- return ZodIntersection$1.create(this, incoming, this._def);
772
- }
773
- transform(transform2) {
774
- return new ZodEffects({
775
- ...processCreateParams(this._def),
776
- schema: this,
777
- typeName: ZodFirstPartyTypeKind.ZodEffects,
778
- effect: { type: "transform", transform: transform2 }
779
- });
780
- }
781
- default(def) {
782
- const defaultValueFunc = typeof def === "function" ? def : () => def;
783
- return new ZodDefault$1({
784
- ...processCreateParams(this._def),
785
- innerType: this,
786
- defaultValue: defaultValueFunc,
787
- typeName: ZodFirstPartyTypeKind.ZodDefault
788
- });
789
- }
790
- brand() {
791
- return new ZodBranded({
792
- typeName: ZodFirstPartyTypeKind.ZodBranded,
793
- type: this,
794
- ...processCreateParams(this._def)
795
- });
796
- }
797
- catch(def) {
798
- const catchValueFunc = typeof def === "function" ? def : () => def;
799
- return new ZodCatch$1({
800
- ...processCreateParams(this._def),
801
- innerType: this,
802
- catchValue: catchValueFunc,
803
- typeName: ZodFirstPartyTypeKind.ZodCatch
804
- });
805
- }
806
- describe(description2) {
807
- const This = this.constructor;
808
- return new This({
809
- ...this._def,
810
- description: description2
811
- });
812
- }
813
- pipe(target) {
814
- return ZodPipeline.create(this, target);
815
- }
816
- readonly() {
817
- return ZodReadonly$1.create(this);
818
- }
819
- isOptional() {
820
- return this.safeParse(void 0).success;
821
- }
822
- isNullable() {
823
- return this.safeParse(null).success;
824
- }
825
- };
826
- const cuidRegex = /^c[^\s-]{8,}$/i;
827
- const cuid2Regex = /^[0-9a-z]+$/;
828
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
829
- const 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;
830
- const nanoidRegex = /^[a-z0-9_-]{21}$/i;
831
- const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
832
- const 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)?)??$/;
833
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
834
- const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
835
- let emojiRegex;
836
- const 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])$/;
837
- const 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])$/;
838
- const 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]))$/;
839
- const 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])$/;
840
- const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
841
- const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
842
- const 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])))`;
843
- const dateRegex = new RegExp(`^${dateRegexSource}$`);
844
- function timeRegexSource(args) {
845
- let secondsRegexSource = `[0-5]\\d`;
846
- if (args.precision) {
847
- secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
848
- } else if (args.precision == null) {
849
- secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
850
- }
851
- const secondsQuantifier = args.precision ? "+" : "?";
852
- return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
853
- }
854
- function timeRegex(args) {
855
- return new RegExp(`^${timeRegexSource(args)}$`);
856
- }
857
- function datetimeRegex(args) {
858
- let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
859
- const opts = [];
860
- opts.push(args.local ? `Z?` : `Z`);
861
- if (args.offset)
862
- opts.push(`([+-]\\d{2}:?\\d{2})`);
863
- regex = `${regex}(${opts.join("|")})`;
864
- return new RegExp(`^${regex}$`);
865
- }
866
- function isValidIP(ip, version2) {
867
- if ((version2 === "v4" || !version2) && ipv4Regex.test(ip)) {
868
- return true;
869
- }
870
- if ((version2 === "v6" || !version2) && ipv6Regex.test(ip)) {
871
- return true;
872
- }
873
- return false;
874
- }
875
- function isValidJWT$1(jwt, alg) {
876
- if (!jwtRegex.test(jwt))
877
- return false;
878
- try {
879
- const [header] = jwt.split(".");
880
- if (!header)
881
- return false;
882
- const base642 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
883
- const decoded = JSON.parse(atob(base642));
884
- if (typeof decoded !== "object" || decoded === null)
885
- return false;
886
- if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
887
- return false;
888
- if (!decoded.alg)
889
- return false;
890
- if (alg && decoded.alg !== alg)
891
- return false;
892
- return true;
893
- } catch {
894
- return false;
895
- }
896
- }
897
- function isValidCidr(ip, version2) {
898
- if ((version2 === "v4" || !version2) && ipv4CidrRegex.test(ip)) {
899
- return true;
900
- }
901
- if ((version2 === "v6" || !version2) && ipv6CidrRegex.test(ip)) {
902
- return true;
903
- }
904
- return false;
905
- }
906
- let ZodString$1 = class ZodString extends ZodType$1 {
907
- _parse(input) {
908
- if (this._def.coerce) {
909
- input.data = String(input.data);
910
- }
911
- const parsedType = this._getType(input);
912
- if (parsedType !== ZodParsedType.string) {
913
- const ctx2 = this._getOrReturnCtx(input);
914
- addIssueToContext(ctx2, {
915
- code: ZodIssueCode.invalid_type,
916
- expected: ZodParsedType.string,
917
- received: ctx2.parsedType
918
- });
919
- return INVALID;
920
- }
921
- const status = new ParseStatus();
922
- let ctx = void 0;
923
- for (const check2 of this._def.checks) {
924
- if (check2.kind === "min") {
925
- if (input.data.length < check2.value) {
926
- ctx = this._getOrReturnCtx(input, ctx);
927
- addIssueToContext(ctx, {
928
- code: ZodIssueCode.too_small,
929
- minimum: check2.value,
930
- type: "string",
931
- inclusive: true,
932
- exact: false,
933
- message: check2.message
934
- });
935
- status.dirty();
936
- }
937
- } else if (check2.kind === "max") {
938
- if (input.data.length > check2.value) {
939
- ctx = this._getOrReturnCtx(input, ctx);
940
- addIssueToContext(ctx, {
941
- code: ZodIssueCode.too_big,
942
- maximum: check2.value,
943
- type: "string",
944
- inclusive: true,
945
- exact: false,
946
- message: check2.message
947
- });
948
- status.dirty();
949
- }
950
- } else if (check2.kind === "length") {
951
- const tooBig = input.data.length > check2.value;
952
- const tooSmall = input.data.length < check2.value;
953
- if (tooBig || tooSmall) {
954
- ctx = this._getOrReturnCtx(input, ctx);
955
- if (tooBig) {
956
- addIssueToContext(ctx, {
957
- code: ZodIssueCode.too_big,
958
- maximum: check2.value,
959
- type: "string",
960
- inclusive: true,
961
- exact: true,
962
- message: check2.message
963
- });
964
- } else if (tooSmall) {
965
- addIssueToContext(ctx, {
966
- code: ZodIssueCode.too_small,
967
- minimum: check2.value,
968
- type: "string",
969
- inclusive: true,
970
- exact: true,
971
- message: check2.message
972
- });
973
- }
974
- status.dirty();
975
- }
976
- } else if (check2.kind === "email") {
977
- if (!emailRegex.test(input.data)) {
978
- ctx = this._getOrReturnCtx(input, ctx);
979
- addIssueToContext(ctx, {
980
- validation: "email",
981
- code: ZodIssueCode.invalid_string,
982
- message: check2.message
983
- });
984
- status.dirty();
985
- }
986
- } else if (check2.kind === "emoji") {
987
- if (!emojiRegex) {
988
- emojiRegex = new RegExp(_emojiRegex, "u");
989
- }
990
- if (!emojiRegex.test(input.data)) {
991
- ctx = this._getOrReturnCtx(input, ctx);
992
- addIssueToContext(ctx, {
993
- validation: "emoji",
994
- code: ZodIssueCode.invalid_string,
995
- message: check2.message
996
- });
997
- status.dirty();
998
- }
999
- } else if (check2.kind === "uuid") {
1000
- if (!uuidRegex.test(input.data)) {
1001
- ctx = this._getOrReturnCtx(input, ctx);
1002
- addIssueToContext(ctx, {
1003
- validation: "uuid",
1004
- code: ZodIssueCode.invalid_string,
1005
- message: check2.message
1006
- });
1007
- status.dirty();
1008
- }
1009
- } else if (check2.kind === "nanoid") {
1010
- if (!nanoidRegex.test(input.data)) {
1011
- ctx = this._getOrReturnCtx(input, ctx);
1012
- addIssueToContext(ctx, {
1013
- validation: "nanoid",
1014
- code: ZodIssueCode.invalid_string,
1015
- message: check2.message
1016
- });
1017
- status.dirty();
1018
- }
1019
- } else if (check2.kind === "cuid") {
1020
- if (!cuidRegex.test(input.data)) {
1021
- ctx = this._getOrReturnCtx(input, ctx);
1022
- addIssueToContext(ctx, {
1023
- validation: "cuid",
1024
- code: ZodIssueCode.invalid_string,
1025
- message: check2.message
1026
- });
1027
- status.dirty();
1028
- }
1029
- } else if (check2.kind === "cuid2") {
1030
- if (!cuid2Regex.test(input.data)) {
1031
- ctx = this._getOrReturnCtx(input, ctx);
1032
- addIssueToContext(ctx, {
1033
- validation: "cuid2",
1034
- code: ZodIssueCode.invalid_string,
1035
- message: check2.message
1036
- });
1037
- status.dirty();
1038
- }
1039
- } else if (check2.kind === "ulid") {
1040
- if (!ulidRegex.test(input.data)) {
1041
- ctx = this._getOrReturnCtx(input, ctx);
1042
- addIssueToContext(ctx, {
1043
- validation: "ulid",
1044
- code: ZodIssueCode.invalid_string,
1045
- message: check2.message
1046
- });
1047
- status.dirty();
1048
- }
1049
- } else if (check2.kind === "url") {
1050
- try {
1051
- new URL(input.data);
1052
- } catch {
1053
- ctx = this._getOrReturnCtx(input, ctx);
1054
- addIssueToContext(ctx, {
1055
- validation: "url",
1056
- code: ZodIssueCode.invalid_string,
1057
- message: check2.message
1058
- });
1059
- status.dirty();
1060
- }
1061
- } else if (check2.kind === "regex") {
1062
- check2.regex.lastIndex = 0;
1063
- const testResult = check2.regex.test(input.data);
1064
- if (!testResult) {
1065
- ctx = this._getOrReturnCtx(input, ctx);
1066
- addIssueToContext(ctx, {
1067
- validation: "regex",
1068
- code: ZodIssueCode.invalid_string,
1069
- message: check2.message
1070
- });
1071
- status.dirty();
1072
- }
1073
- } else if (check2.kind === "trim") {
1074
- input.data = input.data.trim();
1075
- } else if (check2.kind === "includes") {
1076
- if (!input.data.includes(check2.value, check2.position)) {
1077
- ctx = this._getOrReturnCtx(input, ctx);
1078
- addIssueToContext(ctx, {
1079
- code: ZodIssueCode.invalid_string,
1080
- validation: { includes: check2.value, position: check2.position },
1081
- message: check2.message
1082
- });
1083
- status.dirty();
1084
- }
1085
- } else if (check2.kind === "toLowerCase") {
1086
- input.data = input.data.toLowerCase();
1087
- } else if (check2.kind === "toUpperCase") {
1088
- input.data = input.data.toUpperCase();
1089
- } else if (check2.kind === "startsWith") {
1090
- if (!input.data.startsWith(check2.value)) {
1091
- ctx = this._getOrReturnCtx(input, ctx);
1092
- addIssueToContext(ctx, {
1093
- code: ZodIssueCode.invalid_string,
1094
- validation: { startsWith: check2.value },
1095
- message: check2.message
1096
- });
1097
- status.dirty();
1098
- }
1099
- } else if (check2.kind === "endsWith") {
1100
- if (!input.data.endsWith(check2.value)) {
1101
- ctx = this._getOrReturnCtx(input, ctx);
1102
- addIssueToContext(ctx, {
1103
- code: ZodIssueCode.invalid_string,
1104
- validation: { endsWith: check2.value },
1105
- message: check2.message
1106
- });
1107
- status.dirty();
1108
- }
1109
- } else if (check2.kind === "datetime") {
1110
- const regex = datetimeRegex(check2);
1111
- if (!regex.test(input.data)) {
1112
- ctx = this._getOrReturnCtx(input, ctx);
1113
- addIssueToContext(ctx, {
1114
- code: ZodIssueCode.invalid_string,
1115
- validation: "datetime",
1116
- message: check2.message
1117
- });
1118
- status.dirty();
1119
- }
1120
- } else if (check2.kind === "date") {
1121
- const regex = dateRegex;
1122
- if (!regex.test(input.data)) {
1123
- ctx = this._getOrReturnCtx(input, ctx);
1124
- addIssueToContext(ctx, {
1125
- code: ZodIssueCode.invalid_string,
1126
- validation: "date",
1127
- message: check2.message
1128
- });
1129
- status.dirty();
1130
- }
1131
- } else if (check2.kind === "time") {
1132
- const regex = timeRegex(check2);
1133
- if (!regex.test(input.data)) {
1134
- ctx = this._getOrReturnCtx(input, ctx);
1135
- addIssueToContext(ctx, {
1136
- code: ZodIssueCode.invalid_string,
1137
- validation: "time",
1138
- message: check2.message
1139
- });
1140
- status.dirty();
1141
- }
1142
- } else if (check2.kind === "duration") {
1143
- if (!durationRegex.test(input.data)) {
1144
- ctx = this._getOrReturnCtx(input, ctx);
1145
- addIssueToContext(ctx, {
1146
- validation: "duration",
1147
- code: ZodIssueCode.invalid_string,
1148
- message: check2.message
1149
- });
1150
- status.dirty();
1151
- }
1152
- } else if (check2.kind === "ip") {
1153
- if (!isValidIP(input.data, check2.version)) {
1154
- ctx = this._getOrReturnCtx(input, ctx);
1155
- addIssueToContext(ctx, {
1156
- validation: "ip",
1157
- code: ZodIssueCode.invalid_string,
1158
- message: check2.message
1159
- });
1160
- status.dirty();
1161
- }
1162
- } else if (check2.kind === "jwt") {
1163
- if (!isValidJWT$1(input.data, check2.alg)) {
1164
- ctx = this._getOrReturnCtx(input, ctx);
1165
- addIssueToContext(ctx, {
1166
- validation: "jwt",
1167
- code: ZodIssueCode.invalid_string,
1168
- message: check2.message
1169
- });
1170
- status.dirty();
1171
- }
1172
- } else if (check2.kind === "cidr") {
1173
- if (!isValidCidr(input.data, check2.version)) {
1174
- ctx = this._getOrReturnCtx(input, ctx);
1175
- addIssueToContext(ctx, {
1176
- validation: "cidr",
1177
- code: ZodIssueCode.invalid_string,
1178
- message: check2.message
1179
- });
1180
- status.dirty();
1181
- }
1182
- } else if (check2.kind === "base64") {
1183
- if (!base64Regex.test(input.data)) {
1184
- ctx = this._getOrReturnCtx(input, ctx);
1185
- addIssueToContext(ctx, {
1186
- validation: "base64",
1187
- code: ZodIssueCode.invalid_string,
1188
- message: check2.message
1189
- });
1190
- status.dirty();
1191
- }
1192
- } else if (check2.kind === "base64url") {
1193
- if (!base64urlRegex.test(input.data)) {
1194
- ctx = this._getOrReturnCtx(input, ctx);
1195
- addIssueToContext(ctx, {
1196
- validation: "base64url",
1197
- code: ZodIssueCode.invalid_string,
1198
- message: check2.message
1199
- });
1200
- status.dirty();
1201
- }
1202
- } else {
1203
- util$1.assertNever(check2);
1204
- }
1205
- }
1206
- return { status: status.value, value: input.data };
1207
- }
1208
- _regex(regex, validation2, message) {
1209
- return this.refinement((data) => regex.test(data), {
1210
- validation: validation2,
1211
- code: ZodIssueCode.invalid_string,
1212
- ...errorUtil.errToObj(message)
1213
- });
1214
- }
1215
- _addCheck(check2) {
1216
- return new ZodString({
1217
- ...this._def,
1218
- checks: [...this._def.checks, check2]
1219
- });
1220
- }
1221
- email(message) {
1222
- return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1223
- }
1224
- url(message) {
1225
- return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1226
- }
1227
- emoji(message) {
1228
- return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1229
- }
1230
- uuid(message) {
1231
- return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1232
- }
1233
- nanoid(message) {
1234
- return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1235
- }
1236
- cuid(message) {
1237
- return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1238
- }
1239
- cuid2(message) {
1240
- return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1241
- }
1242
- ulid(message) {
1243
- return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1244
- }
1245
- base64(message) {
1246
- return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1247
- }
1248
- base64url(message) {
1249
- return this._addCheck({
1250
- kind: "base64url",
1251
- ...errorUtil.errToObj(message)
1252
- });
1253
- }
1254
- jwt(options) {
1255
- return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1256
- }
1257
- ip(options) {
1258
- return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1259
- }
1260
- cidr(options) {
1261
- return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1262
- }
1263
- datetime(options) {
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({
1274
- kind: "datetime",
1275
- precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
1276
- offset: (options == null ? void 0 : options.offset) ?? false,
1277
- local: (options == null ? void 0 : options.local) ?? false,
1278
- ...errorUtil.errToObj(options == null ? void 0 : options.message)
1279
- });
1280
- }
1281
- date(message) {
1282
- return this._addCheck({ kind: "date", message });
1283
- }
1284
- time(options) {
1285
- if (typeof options === "string") {
1286
- return this._addCheck({
1287
- kind: "time",
1288
- precision: null,
1289
- message: options
1290
- });
1291
- }
1292
- return this._addCheck({
1293
- kind: "time",
1294
- precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
1295
- ...errorUtil.errToObj(options == null ? void 0 : options.message)
1296
- });
1297
- }
1298
- duration(message) {
1299
- return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1300
- }
1301
- regex(regex, message) {
1302
- return this._addCheck({
1303
- kind: "regex",
1304
- regex,
1305
- ...errorUtil.errToObj(message)
1306
- });
1307
- }
1308
- includes(value, options) {
1309
- return this._addCheck({
1310
- kind: "includes",
1311
- value,
1312
- position: options == null ? void 0 : options.position,
1313
- ...errorUtil.errToObj(options == null ? void 0 : options.message)
1314
- });
1315
- }
1316
- startsWith(value, message) {
1317
- return this._addCheck({
1318
- kind: "startsWith",
1319
- value,
1320
- ...errorUtil.errToObj(message)
1321
- });
1322
- }
1323
- endsWith(value, message) {
1324
- return this._addCheck({
1325
- kind: "endsWith",
1326
- value,
1327
- ...errorUtil.errToObj(message)
1328
- });
1329
- }
1330
- min(minLength, message) {
1331
- return this._addCheck({
1332
- kind: "min",
1333
- value: minLength,
1334
- ...errorUtil.errToObj(message)
1335
- });
1336
- }
1337
- max(maxLength, message) {
1338
- return this._addCheck({
1339
- kind: "max",
1340
- value: maxLength,
1341
- ...errorUtil.errToObj(message)
1342
- });
1343
- }
1344
- length(len, message) {
1345
- return this._addCheck({
1346
- kind: "length",
1347
- value: len,
1348
- ...errorUtil.errToObj(message)
1349
- });
1350
- }
1351
- /**
1352
- * Equivalent to `.min(1)`
1353
- */
1354
- nonempty(message) {
1355
- return this.min(1, errorUtil.errToObj(message));
1356
- }
1357
- trim() {
1358
- return new ZodString({
1359
- ...this._def,
1360
- checks: [...this._def.checks, { kind: "trim" }]
1361
- });
1362
- }
1363
- toLowerCase() {
1364
- return new ZodString({
1365
- ...this._def,
1366
- checks: [...this._def.checks, { kind: "toLowerCase" }]
1367
- });
1368
- }
1369
- toUpperCase() {
1370
- return new ZodString({
1371
- ...this._def,
1372
- checks: [...this._def.checks, { kind: "toUpperCase" }]
1373
- });
1374
- }
1375
- get isDatetime() {
1376
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
1377
- }
1378
- get isDate() {
1379
- return !!this._def.checks.find((ch) => ch.kind === "date");
1380
- }
1381
- get isTime() {
1382
- return !!this._def.checks.find((ch) => ch.kind === "time");
1383
- }
1384
- get isDuration() {
1385
- return !!this._def.checks.find((ch) => ch.kind === "duration");
1386
- }
1387
- get isEmail() {
1388
- return !!this._def.checks.find((ch) => ch.kind === "email");
1389
- }
1390
- get isURL() {
1391
- return !!this._def.checks.find((ch) => ch.kind === "url");
1392
- }
1393
- get isEmoji() {
1394
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
1395
- }
1396
- get isUUID() {
1397
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
1398
- }
1399
- get isNANOID() {
1400
- return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1401
- }
1402
- get isCUID() {
1403
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
1404
- }
1405
- get isCUID2() {
1406
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1407
- }
1408
- get isULID() {
1409
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
1410
- }
1411
- get isIP() {
1412
- return !!this._def.checks.find((ch) => ch.kind === "ip");
1413
- }
1414
- get isCIDR() {
1415
- return !!this._def.checks.find((ch) => ch.kind === "cidr");
1416
- }
1417
- get isBase64() {
1418
- return !!this._def.checks.find((ch) => ch.kind === "base64");
1419
- }
1420
- get isBase64url() {
1421
- return !!this._def.checks.find((ch) => ch.kind === "base64url");
1422
- }
1423
- get minLength() {
1424
- let min = null;
1425
- for (const ch of this._def.checks) {
1426
- if (ch.kind === "min") {
1427
- if (min === null || ch.value > min)
1428
- min = ch.value;
1429
- }
1430
- }
1431
- return min;
1432
- }
1433
- get maxLength() {
1434
- let max = null;
1435
- for (const ch of this._def.checks) {
1436
- if (ch.kind === "max") {
1437
- if (max === null || ch.value < max)
1438
- max = ch.value;
1439
- }
1440
- }
1441
- return max;
1442
- }
1443
- };
1444
- ZodString$1.create = (params) => {
1445
- return new ZodString$1({
1446
- checks: [],
1447
- typeName: ZodFirstPartyTypeKind.ZodString,
1448
- coerce: (params == null ? void 0 : params.coerce) ?? false,
1449
- ...processCreateParams(params)
1450
- });
1451
- };
1452
- function floatSafeRemainder$1(val, step) {
1453
- const valDecCount = (val.toString().split(".")[1] || "").length;
1454
- const stepDecCount = (step.toString().split(".")[1] || "").length;
1455
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1456
- const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1457
- const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1458
- return valInt % stepInt / 10 ** decCount;
1459
- }
1460
- let ZodNumber$1 = class ZodNumber extends ZodType$1 {
1461
- constructor() {
1462
- super(...arguments);
1463
- this.min = this.gte;
1464
- this.max = this.lte;
1465
- this.step = this.multipleOf;
1466
- }
1467
- _parse(input) {
1468
- if (this._def.coerce) {
1469
- input.data = Number(input.data);
1470
- }
1471
- const parsedType = this._getType(input);
1472
- if (parsedType !== ZodParsedType.number) {
1473
- const ctx2 = this._getOrReturnCtx(input);
1474
- addIssueToContext(ctx2, {
1475
- code: ZodIssueCode.invalid_type,
1476
- expected: ZodParsedType.number,
1477
- received: ctx2.parsedType
1478
- });
1479
- return INVALID;
1480
- }
1481
- let ctx = void 0;
1482
- const status = new ParseStatus();
1483
- for (const check2 of this._def.checks) {
1484
- if (check2.kind === "int") {
1485
- if (!util$1.isInteger(input.data)) {
1486
- ctx = this._getOrReturnCtx(input, ctx);
1487
- addIssueToContext(ctx, {
1488
- code: ZodIssueCode.invalid_type,
1489
- expected: "integer",
1490
- received: "float",
1491
- message: check2.message
1492
- });
1493
- status.dirty();
1494
- }
1495
- } else if (check2.kind === "min") {
1496
- const tooSmall = check2.inclusive ? input.data < check2.value : input.data <= check2.value;
1497
- if (tooSmall) {
1498
- ctx = this._getOrReturnCtx(input, ctx);
1499
- addIssueToContext(ctx, {
1500
- code: ZodIssueCode.too_small,
1501
- minimum: check2.value,
1502
- type: "number",
1503
- inclusive: check2.inclusive,
1504
- exact: false,
1505
- message: check2.message
1506
- });
1507
- status.dirty();
1508
- }
1509
- } else if (check2.kind === "max") {
1510
- const tooBig = check2.inclusive ? input.data > check2.value : input.data >= check2.value;
1511
- if (tooBig) {
1512
- ctx = this._getOrReturnCtx(input, ctx);
1513
- addIssueToContext(ctx, {
1514
- code: ZodIssueCode.too_big,
1515
- maximum: check2.value,
1516
- type: "number",
1517
- inclusive: check2.inclusive,
1518
- exact: false,
1519
- message: check2.message
1520
- });
1521
- status.dirty();
1522
- }
1523
- } else if (check2.kind === "multipleOf") {
1524
- if (floatSafeRemainder$1(input.data, check2.value) !== 0) {
1525
- ctx = this._getOrReturnCtx(input, ctx);
1526
- addIssueToContext(ctx, {
1527
- code: ZodIssueCode.not_multiple_of,
1528
- multipleOf: check2.value,
1529
- message: check2.message
1530
- });
1531
- status.dirty();
1532
- }
1533
- } else if (check2.kind === "finite") {
1534
- if (!Number.isFinite(input.data)) {
1535
- ctx = this._getOrReturnCtx(input, ctx);
1536
- addIssueToContext(ctx, {
1537
- code: ZodIssueCode.not_finite,
1538
- message: check2.message
1539
- });
1540
- status.dirty();
1541
- }
1542
- } else {
1543
- util$1.assertNever(check2);
1544
- }
1545
- }
1546
- return { status: status.value, value: input.data };
1547
- }
1548
- gte(value, message) {
1549
- return this.setLimit("min", value, true, errorUtil.toString(message));
1550
- }
1551
- gt(value, message) {
1552
- return this.setLimit("min", value, false, errorUtil.toString(message));
1553
- }
1554
- lte(value, message) {
1555
- return this.setLimit("max", value, true, errorUtil.toString(message));
1556
- }
1557
- lt(value, message) {
1558
- return this.setLimit("max", value, false, errorUtil.toString(message));
1559
- }
1560
- setLimit(kind, value, inclusive, message) {
1561
- return new ZodNumber({
1562
- ...this._def,
1563
- checks: [
1564
- ...this._def.checks,
1565
- {
1566
- kind,
1567
- value,
1568
- inclusive,
1569
- message: errorUtil.toString(message)
1570
- }
1571
- ]
1572
- });
1573
- }
1574
- _addCheck(check2) {
1575
- return new ZodNumber({
1576
- ...this._def,
1577
- checks: [...this._def.checks, check2]
1578
- });
1579
- }
1580
- int(message) {
1581
- return this._addCheck({
1582
- kind: "int",
1583
- message: errorUtil.toString(message)
1584
- });
1585
- }
1586
- positive(message) {
1587
- return this._addCheck({
1588
- kind: "min",
1589
- value: 0,
1590
- inclusive: false,
1591
- message: errorUtil.toString(message)
1592
- });
1593
- }
1594
- negative(message) {
1595
- return this._addCheck({
1596
- kind: "max",
1597
- value: 0,
1598
- inclusive: false,
1599
- message: errorUtil.toString(message)
1600
- });
1601
- }
1602
- nonpositive(message) {
1603
- return this._addCheck({
1604
- kind: "max",
1605
- value: 0,
1606
- inclusive: true,
1607
- message: errorUtil.toString(message)
1608
- });
1609
- }
1610
- nonnegative(message) {
1611
- return this._addCheck({
1612
- kind: "min",
1613
- value: 0,
1614
- inclusive: true,
1615
- message: errorUtil.toString(message)
1616
- });
1617
- }
1618
- multipleOf(value, message) {
1619
- return this._addCheck({
1620
- kind: "multipleOf",
1621
- value,
1622
- message: errorUtil.toString(message)
1623
- });
1624
- }
1625
- finite(message) {
1626
- return this._addCheck({
1627
- kind: "finite",
1628
- message: errorUtil.toString(message)
1629
- });
1630
- }
1631
- safe(message) {
1632
- return this._addCheck({
1633
- kind: "min",
1634
- inclusive: true,
1635
- value: Number.MIN_SAFE_INTEGER,
1636
- message: errorUtil.toString(message)
1637
- })._addCheck({
1638
- kind: "max",
1639
- inclusive: true,
1640
- value: Number.MAX_SAFE_INTEGER,
1641
- message: errorUtil.toString(message)
1642
- });
1643
- }
1644
- get minValue() {
1645
- let min = null;
1646
- for (const ch of this._def.checks) {
1647
- if (ch.kind === "min") {
1648
- if (min === null || ch.value > min)
1649
- min = ch.value;
1650
- }
1651
- }
1652
- return min;
1653
- }
1654
- get maxValue() {
1655
- let max = null;
1656
- for (const ch of this._def.checks) {
1657
- if (ch.kind === "max") {
1658
- if (max === null || ch.value < max)
1659
- max = ch.value;
1660
- }
1661
- }
1662
- return max;
1663
- }
1664
- get isInt() {
1665
- return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util$1.isInteger(ch.value));
1666
- }
1667
- get isFinite() {
1668
- let max = null;
1669
- let min = null;
1670
- for (const ch of this._def.checks) {
1671
- if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1672
- return true;
1673
- } else if (ch.kind === "min") {
1674
- if (min === null || ch.value > min)
1675
- min = ch.value;
1676
- } else if (ch.kind === "max") {
1677
- if (max === null || ch.value < max)
1678
- max = ch.value;
1679
- }
1680
- }
1681
- return Number.isFinite(min) && Number.isFinite(max);
1682
- }
1683
- };
1684
- ZodNumber$1.create = (params) => {
1685
- return new ZodNumber$1({
1686
- checks: [],
1687
- typeName: ZodFirstPartyTypeKind.ZodNumber,
1688
- coerce: (params == null ? void 0 : params.coerce) || false,
1689
- ...processCreateParams(params)
1690
- });
1691
- };
1692
- class ZodBigInt extends ZodType$1 {
1693
- constructor() {
1694
- super(...arguments);
1695
- this.min = this.gte;
1696
- this.max = this.lte;
1697
- }
1698
- _parse(input) {
1699
- if (this._def.coerce) {
1700
- try {
1701
- input.data = BigInt(input.data);
1702
- } catch {
1703
- return this._getInvalidInput(input);
1704
- }
1705
- }
1706
- const parsedType = this._getType(input);
1707
- if (parsedType !== ZodParsedType.bigint) {
1708
- return this._getInvalidInput(input);
1709
- }
1710
- let ctx = void 0;
1711
- const status = new ParseStatus();
1712
- for (const check2 of this._def.checks) {
1713
- if (check2.kind === "min") {
1714
- const tooSmall = check2.inclusive ? input.data < check2.value : input.data <= check2.value;
1715
- if (tooSmall) {
1716
- ctx = this._getOrReturnCtx(input, ctx);
1717
- addIssueToContext(ctx, {
1718
- code: ZodIssueCode.too_small,
1719
- type: "bigint",
1720
- minimum: check2.value,
1721
- inclusive: check2.inclusive,
1722
- message: check2.message
1723
- });
1724
- status.dirty();
1725
- }
1726
- } else if (check2.kind === "max") {
1727
- const tooBig = check2.inclusive ? input.data > check2.value : input.data >= check2.value;
1728
- if (tooBig) {
1729
- ctx = this._getOrReturnCtx(input, ctx);
1730
- addIssueToContext(ctx, {
1731
- code: ZodIssueCode.too_big,
1732
- type: "bigint",
1733
- maximum: check2.value,
1734
- inclusive: check2.inclusive,
1735
- message: check2.message
1736
- });
1737
- status.dirty();
1738
- }
1739
- } else if (check2.kind === "multipleOf") {
1740
- if (input.data % check2.value !== BigInt(0)) {
1741
- ctx = this._getOrReturnCtx(input, ctx);
1742
- addIssueToContext(ctx, {
1743
- code: ZodIssueCode.not_multiple_of,
1744
- multipleOf: check2.value,
1745
- message: check2.message
1746
- });
1747
- status.dirty();
1748
- }
1749
- } else {
1750
- util$1.assertNever(check2);
1751
- }
1752
- }
1753
- return { status: status.value, value: input.data };
1754
- }
1755
- _getInvalidInput(input) {
1756
- const ctx = this._getOrReturnCtx(input);
1757
- addIssueToContext(ctx, {
1758
- code: ZodIssueCode.invalid_type,
1759
- expected: ZodParsedType.bigint,
1760
- received: ctx.parsedType
1761
- });
1762
- return INVALID;
1763
- }
1764
- gte(value, message) {
1765
- return this.setLimit("min", value, true, errorUtil.toString(message));
1766
- }
1767
- gt(value, message) {
1768
- return this.setLimit("min", value, false, errorUtil.toString(message));
1769
- }
1770
- lte(value, message) {
1771
- return this.setLimit("max", value, true, errorUtil.toString(message));
1772
- }
1773
- lt(value, message) {
1774
- return this.setLimit("max", value, false, errorUtil.toString(message));
1775
- }
1776
- setLimit(kind, value, inclusive, message) {
1777
- return new ZodBigInt({
1778
- ...this._def,
1779
- checks: [
1780
- ...this._def.checks,
1781
- {
1782
- kind,
1783
- value,
1784
- inclusive,
1785
- message: errorUtil.toString(message)
1786
- }
1787
- ]
1788
- });
1789
- }
1790
- _addCheck(check2) {
1791
- return new ZodBigInt({
1792
- ...this._def,
1793
- checks: [...this._def.checks, check2]
1794
- });
1795
- }
1796
- positive(message) {
1797
- return this._addCheck({
1798
- kind: "min",
1799
- value: BigInt(0),
1800
- inclusive: false,
1801
- message: errorUtil.toString(message)
1802
- });
1803
- }
1804
- negative(message) {
1805
- return this._addCheck({
1806
- kind: "max",
1807
- value: BigInt(0),
1808
- inclusive: false,
1809
- message: errorUtil.toString(message)
1810
- });
1811
- }
1812
- nonpositive(message) {
1813
- return this._addCheck({
1814
- kind: "max",
1815
- value: BigInt(0),
1816
- inclusive: true,
1817
- message: errorUtil.toString(message)
1818
- });
1819
- }
1820
- nonnegative(message) {
1821
- return this._addCheck({
1822
- kind: "min",
1823
- value: BigInt(0),
1824
- inclusive: true,
1825
- message: errorUtil.toString(message)
1826
- });
1827
- }
1828
- multipleOf(value, message) {
1829
- return this._addCheck({
1830
- kind: "multipleOf",
1831
- value,
1832
- message: errorUtil.toString(message)
1833
- });
1834
- }
1835
- get minValue() {
1836
- let min = null;
1837
- for (const ch of this._def.checks) {
1838
- if (ch.kind === "min") {
1839
- if (min === null || ch.value > min)
1840
- min = ch.value;
1841
- }
1842
- }
1843
- return min;
1844
- }
1845
- get maxValue() {
1846
- let max = null;
1847
- for (const ch of this._def.checks) {
1848
- if (ch.kind === "max") {
1849
- if (max === null || ch.value < max)
1850
- max = ch.value;
1851
- }
1852
- }
1853
- return max;
1854
- }
1855
- }
1856
- ZodBigInt.create = (params) => {
1857
- return new ZodBigInt({
1858
- checks: [],
1859
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
1860
- coerce: (params == null ? void 0 : params.coerce) ?? false,
1861
- ...processCreateParams(params)
1862
- });
1863
- };
1864
- let ZodBoolean$1 = class ZodBoolean extends ZodType$1 {
1865
- _parse(input) {
1866
- if (this._def.coerce) {
1867
- input.data = Boolean(input.data);
1868
- }
1869
- const parsedType = this._getType(input);
1870
- if (parsedType !== ZodParsedType.boolean) {
1871
- const ctx = this._getOrReturnCtx(input);
1872
- addIssueToContext(ctx, {
1873
- code: ZodIssueCode.invalid_type,
1874
- expected: ZodParsedType.boolean,
1875
- received: ctx.parsedType
1876
- });
1877
- return INVALID;
1878
- }
1879
- return OK(input.data);
1880
- }
1881
- };
1882
- ZodBoolean$1.create = (params) => {
1883
- return new ZodBoolean$1({
1884
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
1885
- coerce: (params == null ? void 0 : params.coerce) || false,
1886
- ...processCreateParams(params)
1887
- });
1888
- };
1889
- class ZodDate extends ZodType$1 {
1890
- _parse(input) {
1891
- if (this._def.coerce) {
1892
- input.data = new Date(input.data);
1893
- }
1894
- const parsedType = this._getType(input);
1895
- if (parsedType !== ZodParsedType.date) {
1896
- const ctx2 = this._getOrReturnCtx(input);
1897
- addIssueToContext(ctx2, {
1898
- code: ZodIssueCode.invalid_type,
1899
- expected: ZodParsedType.date,
1900
- received: ctx2.parsedType
1901
- });
1902
- return INVALID;
1903
- }
1904
- if (Number.isNaN(input.data.getTime())) {
1905
- const ctx2 = this._getOrReturnCtx(input);
1906
- addIssueToContext(ctx2, {
1907
- code: ZodIssueCode.invalid_date
1908
- });
1909
- return INVALID;
1910
- }
1911
- const status = new ParseStatus();
1912
- let ctx = void 0;
1913
- for (const check2 of this._def.checks) {
1914
- if (check2.kind === "min") {
1915
- if (input.data.getTime() < check2.value) {
1916
- ctx = this._getOrReturnCtx(input, ctx);
1917
- addIssueToContext(ctx, {
1918
- code: ZodIssueCode.too_small,
1919
- message: check2.message,
1920
- inclusive: true,
1921
- exact: false,
1922
- minimum: check2.value,
1923
- type: "date"
1924
- });
1925
- status.dirty();
1926
- }
1927
- } else if (check2.kind === "max") {
1928
- if (input.data.getTime() > check2.value) {
1929
- ctx = this._getOrReturnCtx(input, ctx);
1930
- addIssueToContext(ctx, {
1931
- code: ZodIssueCode.too_big,
1932
- message: check2.message,
1933
- inclusive: true,
1934
- exact: false,
1935
- maximum: check2.value,
1936
- type: "date"
1937
- });
1938
- status.dirty();
1939
- }
1940
- } else {
1941
- util$1.assertNever(check2);
1942
- }
1943
- }
1944
- return {
1945
- status: status.value,
1946
- value: new Date(input.data.getTime())
1947
- };
1948
- }
1949
- _addCheck(check2) {
1950
- return new ZodDate({
1951
- ...this._def,
1952
- checks: [...this._def.checks, check2]
1953
- });
1954
- }
1955
- min(minDate, message) {
1956
- return this._addCheck({
1957
- kind: "min",
1958
- value: minDate.getTime(),
1959
- message: errorUtil.toString(message)
1960
- });
1961
- }
1962
- max(maxDate, message) {
1963
- return this._addCheck({
1964
- kind: "max",
1965
- value: maxDate.getTime(),
1966
- message: errorUtil.toString(message)
1967
- });
1968
- }
1969
- get minDate() {
1970
- let min = null;
1971
- for (const ch of this._def.checks) {
1972
- if (ch.kind === "min") {
1973
- if (min === null || ch.value > min)
1974
- min = ch.value;
1975
- }
1976
- }
1977
- return min != null ? new Date(min) : null;
1978
- }
1979
- get maxDate() {
1980
- let max = null;
1981
- for (const ch of this._def.checks) {
1982
- if (ch.kind === "max") {
1983
- if (max === null || ch.value < max)
1984
- max = ch.value;
1985
- }
1986
- }
1987
- return max != null ? new Date(max) : null;
1988
- }
1989
- }
1990
- ZodDate.create = (params) => {
1991
- return new ZodDate({
1992
- checks: [],
1993
- coerce: (params == null ? void 0 : params.coerce) || false,
1994
- typeName: ZodFirstPartyTypeKind.ZodDate,
1995
- ...processCreateParams(params)
1996
- });
1997
- };
1998
- class ZodSymbol extends ZodType$1 {
1999
- _parse(input) {
2000
- const parsedType = this._getType(input);
2001
- if (parsedType !== ZodParsedType.symbol) {
2002
- const ctx = this._getOrReturnCtx(input);
2003
- addIssueToContext(ctx, {
2004
- code: ZodIssueCode.invalid_type,
2005
- expected: ZodParsedType.symbol,
2006
- received: ctx.parsedType
2007
- });
2008
- return INVALID;
2009
- }
2010
- return OK(input.data);
2011
- }
2012
- }
2013
- ZodSymbol.create = (params) => {
2014
- return new ZodSymbol({
2015
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
2016
- ...processCreateParams(params)
2017
- });
2018
- };
2019
- class ZodUndefined extends ZodType$1 {
2020
- _parse(input) {
2021
- const parsedType = this._getType(input);
2022
- if (parsedType !== ZodParsedType.undefined) {
2023
- const ctx = this._getOrReturnCtx(input);
2024
- addIssueToContext(ctx, {
2025
- code: ZodIssueCode.invalid_type,
2026
- expected: ZodParsedType.undefined,
2027
- received: ctx.parsedType
2028
- });
2029
- return INVALID;
2030
- }
2031
- return OK(input.data);
2032
- }
2033
- }
2034
- ZodUndefined.create = (params) => {
2035
- return new ZodUndefined({
2036
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
2037
- ...processCreateParams(params)
2038
- });
2039
- };
2040
- let ZodNull$1 = class ZodNull extends ZodType$1 {
2041
- _parse(input) {
2042
- const parsedType = this._getType(input);
2043
- if (parsedType !== ZodParsedType.null) {
2044
- const ctx = this._getOrReturnCtx(input);
2045
- addIssueToContext(ctx, {
2046
- code: ZodIssueCode.invalid_type,
2047
- expected: ZodParsedType.null,
2048
- received: ctx.parsedType
2049
- });
2050
- return INVALID;
2051
- }
2052
- return OK(input.data);
2053
- }
2054
- };
2055
- ZodNull$1.create = (params) => {
2056
- return new ZodNull$1({
2057
- typeName: ZodFirstPartyTypeKind.ZodNull,
2058
- ...processCreateParams(params)
2059
- });
2060
- };
2061
- class ZodAny extends ZodType$1 {
2062
- constructor() {
2063
- super(...arguments);
2064
- this._any = true;
2065
- }
2066
- _parse(input) {
2067
- return OK(input.data);
2068
- }
2069
- }
2070
- ZodAny.create = (params) => {
2071
- return new ZodAny({
2072
- typeName: ZodFirstPartyTypeKind.ZodAny,
2073
- ...processCreateParams(params)
2074
- });
2075
- };
2076
- let ZodUnknown$1 = class ZodUnknown extends ZodType$1 {
2077
- constructor() {
2078
- super(...arguments);
2079
- this._unknown = true;
2080
- }
2081
- _parse(input) {
2082
- return OK(input.data);
2083
- }
2084
- };
2085
- ZodUnknown$1.create = (params) => {
2086
- return new ZodUnknown$1({
2087
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
2088
- ...processCreateParams(params)
2089
- });
2090
- };
2091
- let ZodNever$1 = class ZodNever extends ZodType$1 {
2092
- _parse(input) {
2093
- const ctx = this._getOrReturnCtx(input);
2094
- addIssueToContext(ctx, {
2095
- code: ZodIssueCode.invalid_type,
2096
- expected: ZodParsedType.never,
2097
- received: ctx.parsedType
2098
- });
2099
- return INVALID;
2100
- }
2101
- };
2102
- ZodNever$1.create = (params) => {
2103
- return new ZodNever$1({
2104
- typeName: ZodFirstPartyTypeKind.ZodNever,
2105
- ...processCreateParams(params)
2106
- });
2107
- };
2108
- class ZodVoid extends ZodType$1 {
2109
- _parse(input) {
2110
- const parsedType = this._getType(input);
2111
- if (parsedType !== ZodParsedType.undefined) {
2112
- const ctx = this._getOrReturnCtx(input);
2113
- addIssueToContext(ctx, {
2114
- code: ZodIssueCode.invalid_type,
2115
- expected: ZodParsedType.void,
2116
- received: ctx.parsedType
2117
- });
2118
- return INVALID;
2119
- }
2120
- return OK(input.data);
2121
- }
2122
- }
2123
- ZodVoid.create = (params) => {
2124
- return new ZodVoid({
2125
- typeName: ZodFirstPartyTypeKind.ZodVoid,
2126
- ...processCreateParams(params)
2127
- });
2128
- };
2129
- let ZodArray$1 = class ZodArray extends ZodType$1 {
2130
- _parse(input) {
2131
- const { ctx, status } = this._processInputParams(input);
2132
- const def = this._def;
2133
- if (ctx.parsedType !== ZodParsedType.array) {
2134
- addIssueToContext(ctx, {
2135
- code: ZodIssueCode.invalid_type,
2136
- expected: ZodParsedType.array,
2137
- received: ctx.parsedType
2138
- });
2139
- return INVALID;
2140
- }
2141
- if (def.exactLength !== null) {
2142
- const tooBig = ctx.data.length > def.exactLength.value;
2143
- const tooSmall = ctx.data.length < def.exactLength.value;
2144
- if (tooBig || tooSmall) {
2145
- addIssueToContext(ctx, {
2146
- code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2147
- minimum: tooSmall ? def.exactLength.value : void 0,
2148
- maximum: tooBig ? def.exactLength.value : void 0,
2149
- type: "array",
2150
- inclusive: true,
2151
- exact: true,
2152
- message: def.exactLength.message
2153
- });
2154
- status.dirty();
2155
- }
2156
- }
2157
- if (def.minLength !== null) {
2158
- if (ctx.data.length < def.minLength.value) {
2159
- addIssueToContext(ctx, {
2160
- code: ZodIssueCode.too_small,
2161
- minimum: def.minLength.value,
2162
- type: "array",
2163
- inclusive: true,
2164
- exact: false,
2165
- message: def.minLength.message
2166
- });
2167
- status.dirty();
2168
- }
2169
- }
2170
- if (def.maxLength !== null) {
2171
- if (ctx.data.length > def.maxLength.value) {
2172
- addIssueToContext(ctx, {
2173
- code: ZodIssueCode.too_big,
2174
- maximum: def.maxLength.value,
2175
- type: "array",
2176
- inclusive: true,
2177
- exact: false,
2178
- message: def.maxLength.message
2179
- });
2180
- status.dirty();
2181
- }
2182
- }
2183
- if (ctx.common.async) {
2184
- return Promise.all([...ctx.data].map((item, i) => {
2185
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2186
- })).then((result2) => {
2187
- return ParseStatus.mergeArray(status, result2);
2188
- });
2189
- }
2190
- const result = [...ctx.data].map((item, i) => {
2191
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2192
- });
2193
- return ParseStatus.mergeArray(status, result);
2194
- }
2195
- get element() {
2196
- return this._def.type;
2197
- }
2198
- min(minLength, message) {
2199
- return new ZodArray({
2200
- ...this._def,
2201
- minLength: { value: minLength, message: errorUtil.toString(message) }
2202
- });
2203
- }
2204
- max(maxLength, message) {
2205
- return new ZodArray({
2206
- ...this._def,
2207
- maxLength: { value: maxLength, message: errorUtil.toString(message) }
2208
- });
2209
- }
2210
- length(len, message) {
2211
- return new ZodArray({
2212
- ...this._def,
2213
- exactLength: { value: len, message: errorUtil.toString(message) }
2214
- });
2215
- }
2216
- nonempty(message) {
2217
- return this.min(1, message);
2218
- }
2219
- };
2220
- ZodArray$1.create = (schema, params) => {
2221
- return new ZodArray$1({
2222
- type: schema,
2223
- minLength: null,
2224
- maxLength: null,
2225
- exactLength: null,
2226
- typeName: ZodFirstPartyTypeKind.ZodArray,
2227
- ...processCreateParams(params)
2228
- });
2229
- };
2230
- function deepPartialify(schema) {
2231
- if (schema instanceof ZodObject$1) {
2232
- const newShape = {};
2233
- for (const key in schema.shape) {
2234
- const fieldSchema = schema.shape[key];
2235
- newShape[key] = ZodOptional$1.create(deepPartialify(fieldSchema));
2236
- }
2237
- return new ZodObject$1({
2238
- ...schema._def,
2239
- shape: () => newShape
2240
- });
2241
- } else if (schema instanceof ZodArray$1) {
2242
- return new ZodArray$1({
2243
- ...schema._def,
2244
- type: deepPartialify(schema.element)
2245
- });
2246
- } else if (schema instanceof ZodOptional$1) {
2247
- return ZodOptional$1.create(deepPartialify(schema.unwrap()));
2248
- } else if (schema instanceof ZodNullable$1) {
2249
- return ZodNullable$1.create(deepPartialify(schema.unwrap()));
2250
- } else if (schema instanceof ZodTuple) {
2251
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2252
- } else {
2253
- return schema;
2254
- }
2255
- }
2256
- let ZodObject$1 = class ZodObject extends ZodType$1 {
2257
- constructor() {
2258
- super(...arguments);
2259
- this._cached = null;
2260
- this.nonstrict = this.passthrough;
2261
- this.augment = this.extend;
2262
- }
2263
- _getCached() {
2264
- if (this._cached !== null)
2265
- return this._cached;
2266
- const shape = this._def.shape();
2267
- const keys = util$1.objectKeys(shape);
2268
- this._cached = { shape, keys };
2269
- return this._cached;
2270
- }
2271
- _parse(input) {
2272
- const parsedType = this._getType(input);
2273
- if (parsedType !== ZodParsedType.object) {
2274
- const ctx2 = this._getOrReturnCtx(input);
2275
- addIssueToContext(ctx2, {
2276
- code: ZodIssueCode.invalid_type,
2277
- expected: ZodParsedType.object,
2278
- received: ctx2.parsedType
2279
- });
2280
- return INVALID;
2281
- }
2282
- const { status, ctx } = this._processInputParams(input);
2283
- const { shape, keys: shapeKeys } = this._getCached();
2284
- const extraKeys = [];
2285
- if (!(this._def.catchall instanceof ZodNever$1 && this._def.unknownKeys === "strip")) {
2286
- for (const key in ctx.data) {
2287
- if (!shapeKeys.includes(key)) {
2288
- extraKeys.push(key);
2289
- }
2290
- }
2291
- }
2292
- const pairs = [];
2293
- for (const key of shapeKeys) {
2294
- const keyValidator = shape[key];
2295
- const value = ctx.data[key];
2296
- pairs.push({
2297
- key: { status: "valid", value: key },
2298
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2299
- alwaysSet: key in ctx.data
2300
- });
2301
- }
2302
- if (this._def.catchall instanceof ZodNever$1) {
2303
- const unknownKeys = this._def.unknownKeys;
2304
- if (unknownKeys === "passthrough") {
2305
- for (const key of extraKeys) {
2306
- pairs.push({
2307
- key: { status: "valid", value: key },
2308
- value: { status: "valid", value: ctx.data[key] }
2309
- });
2310
- }
2311
- } else if (unknownKeys === "strict") {
2312
- if (extraKeys.length > 0) {
2313
- addIssueToContext(ctx, {
2314
- code: ZodIssueCode.unrecognized_keys,
2315
- keys: extraKeys
2316
- });
2317
- status.dirty();
2318
- }
2319
- } else if (unknownKeys === "strip") ;
2320
- else {
2321
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2322
- }
2323
- } else {
2324
- const catchall = this._def.catchall;
2325
- for (const key of extraKeys) {
2326
- const value = ctx.data[key];
2327
- pairs.push({
2328
- key: { status: "valid", value: key },
2329
- value: catchall._parse(
2330
- new ParseInputLazyPath(ctx, value, ctx.path, key)
2331
- //, ctx.child(key), value, getParsedType(value)
2332
- ),
2333
- alwaysSet: key in ctx.data
2334
- });
2335
- }
2336
- }
2337
- if (ctx.common.async) {
2338
- return Promise.resolve().then(async () => {
2339
- const syncPairs = [];
2340
- for (const pair2 of pairs) {
2341
- const key = await pair2.key;
2342
- const value = await pair2.value;
2343
- syncPairs.push({
2344
- key,
2345
- value,
2346
- alwaysSet: pair2.alwaysSet
2347
- });
2348
- }
2349
- return syncPairs;
2350
- }).then((syncPairs) => {
2351
- return ParseStatus.mergeObjectSync(status, syncPairs);
2352
- });
2353
- } else {
2354
- return ParseStatus.mergeObjectSync(status, pairs);
2355
- }
2356
- }
2357
- get shape() {
2358
- return this._def.shape();
2359
- }
2360
- strict(message) {
2361
- errorUtil.errToObj;
2362
- return new ZodObject({
2363
- ...this._def,
2364
- unknownKeys: "strict",
2365
- ...message !== void 0 ? {
2366
- errorMap: (issue2, ctx) => {
2367
- var _a2, _b;
2368
- const defaultError = ((_b = (_a2 = this._def).errorMap) == null ? void 0 : _b.call(_a2, issue2, ctx).message) ?? ctx.defaultError;
2369
- if (issue2.code === "unrecognized_keys")
2370
- return {
2371
- message: errorUtil.errToObj(message).message ?? defaultError
2372
- };
2373
- return {
2374
- message: defaultError
2375
- };
2376
- }
2377
- } : {}
2378
- });
2379
- }
2380
- strip() {
2381
- return new ZodObject({
2382
- ...this._def,
2383
- unknownKeys: "strip"
2384
- });
2385
- }
2386
- passthrough() {
2387
- return new ZodObject({
2388
- ...this._def,
2389
- unknownKeys: "passthrough"
2390
- });
2391
- }
2392
- // const AugmentFactory =
2393
- // <Def extends ZodObjectDef>(def: Def) =>
2394
- // <Augmentation extends ZodRawShape>(
2395
- // augmentation: Augmentation
2396
- // ): ZodObject<
2397
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2398
- // Def["unknownKeys"],
2399
- // Def["catchall"]
2400
- // > => {
2401
- // return new ZodObject({
2402
- // ...def,
2403
- // shape: () => ({
2404
- // ...def.shape(),
2405
- // ...augmentation,
2406
- // }),
2407
- // }) as any;
2408
- // };
2409
- extend(augmentation) {
2410
- return new ZodObject({
2411
- ...this._def,
2412
- shape: () => ({
2413
- ...this._def.shape(),
2414
- ...augmentation
2415
- })
2416
- });
2417
- }
2418
- /**
2419
- * Prior to zod@1.0.12 there was a bug in the
2420
- * inferred type of merged objects. Please
2421
- * upgrade if you are experiencing issues.
2422
- */
2423
- merge(merging) {
2424
- const merged = new ZodObject({
2425
- unknownKeys: merging._def.unknownKeys,
2426
- catchall: merging._def.catchall,
2427
- shape: () => ({
2428
- ...this._def.shape(),
2429
- ...merging._def.shape()
2430
- }),
2431
- typeName: ZodFirstPartyTypeKind.ZodObject
2432
- });
2433
- return merged;
2434
- }
2435
- // merge<
2436
- // Incoming extends AnyZodObject,
2437
- // Augmentation extends Incoming["shape"],
2438
- // NewOutput extends {
2439
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2440
- // ? Augmentation[k]["_output"]
2441
- // : k extends keyof Output
2442
- // ? Output[k]
2443
- // : never;
2444
- // },
2445
- // NewInput extends {
2446
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2447
- // ? Augmentation[k]["_input"]
2448
- // : k extends keyof Input
2449
- // ? Input[k]
2450
- // : never;
2451
- // }
2452
- // >(
2453
- // merging: Incoming
2454
- // ): ZodObject<
2455
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2456
- // Incoming["_def"]["unknownKeys"],
2457
- // Incoming["_def"]["catchall"],
2458
- // NewOutput,
2459
- // NewInput
2460
- // > {
2461
- // const merged: any = new ZodObject({
2462
- // unknownKeys: merging._def.unknownKeys,
2463
- // catchall: merging._def.catchall,
2464
- // shape: () =>
2465
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2466
- // typeName: ZodFirstPartyTypeKind.ZodObject,
2467
- // }) as any;
2468
- // return merged;
2469
- // }
2470
- setKey(key, schema) {
2471
- return this.augment({ [key]: schema });
2472
- }
2473
- // merge<Incoming extends AnyZodObject>(
2474
- // merging: Incoming
2475
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2476
- // ZodObject<
2477
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2478
- // Incoming["_def"]["unknownKeys"],
2479
- // Incoming["_def"]["catchall"]
2480
- // > {
2481
- // // const mergedShape = objectUtil.mergeShapes(
2482
- // // this._def.shape(),
2483
- // // merging._def.shape()
2484
- // // );
2485
- // const merged: any = new ZodObject({
2486
- // unknownKeys: merging._def.unknownKeys,
2487
- // catchall: merging._def.catchall,
2488
- // shape: () =>
2489
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2490
- // typeName: ZodFirstPartyTypeKind.ZodObject,
2491
- // }) as any;
2492
- // return merged;
2493
- // }
2494
- catchall(index) {
2495
- return new ZodObject({
2496
- ...this._def,
2497
- catchall: index
2498
- });
2499
- }
2500
- pick(mask) {
2501
- const shape = {};
2502
- for (const key of util$1.objectKeys(mask)) {
2503
- if (mask[key] && this.shape[key]) {
2504
- shape[key] = this.shape[key];
2505
- }
2506
- }
2507
- return new ZodObject({
2508
- ...this._def,
2509
- shape: () => shape
2510
- });
2511
- }
2512
- omit(mask) {
2513
- const shape = {};
2514
- for (const key of util$1.objectKeys(this.shape)) {
2515
- if (!mask[key]) {
2516
- shape[key] = this.shape[key];
2517
- }
2518
- }
2519
- return new ZodObject({
2520
- ...this._def,
2521
- shape: () => shape
2522
- });
2523
- }
2524
- /**
2525
- * @deprecated
2526
- */
2527
- deepPartial() {
2528
- return deepPartialify(this);
2529
- }
2530
- partial(mask) {
2531
- const newShape = {};
2532
- for (const key of util$1.objectKeys(this.shape)) {
2533
- const fieldSchema = this.shape[key];
2534
- if (mask && !mask[key]) {
2535
- newShape[key] = fieldSchema;
2536
- } else {
2537
- newShape[key] = fieldSchema.optional();
2538
- }
2539
- }
2540
- return new ZodObject({
2541
- ...this._def,
2542
- shape: () => newShape
2543
- });
2544
- }
2545
- required(mask) {
2546
- const newShape = {};
2547
- for (const key of util$1.objectKeys(this.shape)) {
2548
- if (mask && !mask[key]) {
2549
- newShape[key] = this.shape[key];
2550
- } else {
2551
- const fieldSchema = this.shape[key];
2552
- let newField = fieldSchema;
2553
- while (newField instanceof ZodOptional$1) {
2554
- newField = newField._def.innerType;
2555
- }
2556
- newShape[key] = newField;
2557
- }
2558
- }
2559
- return new ZodObject({
2560
- ...this._def,
2561
- shape: () => newShape
2562
- });
2563
- }
2564
- keyof() {
2565
- return createZodEnum(util$1.objectKeys(this.shape));
2566
- }
2567
- };
2568
- ZodObject$1.create = (shape, params) => {
2569
- return new ZodObject$1({
2570
- shape: () => shape,
2571
- unknownKeys: "strip",
2572
- catchall: ZodNever$1.create(),
2573
- typeName: ZodFirstPartyTypeKind.ZodObject,
2574
- ...processCreateParams(params)
2575
- });
2576
- };
2577
- ZodObject$1.strictCreate = (shape, params) => {
2578
- return new ZodObject$1({
2579
- shape: () => shape,
2580
- unknownKeys: "strict",
2581
- catchall: ZodNever$1.create(),
2582
- typeName: ZodFirstPartyTypeKind.ZodObject,
2583
- ...processCreateParams(params)
2584
- });
2585
- };
2586
- ZodObject$1.lazycreate = (shape, params) => {
2587
- return new ZodObject$1({
2588
- shape,
2589
- unknownKeys: "strip",
2590
- catchall: ZodNever$1.create(),
2591
- typeName: ZodFirstPartyTypeKind.ZodObject,
2592
- ...processCreateParams(params)
2593
- });
2594
- };
2595
- let ZodUnion$1 = class ZodUnion extends ZodType$1 {
2596
- _parse(input) {
2597
- const { ctx } = this._processInputParams(input);
2598
- const options = this._def.options;
2599
- function handleResults(results) {
2600
- for (const result of results) {
2601
- if (result.result.status === "valid") {
2602
- return result.result;
2603
- }
2604
- }
2605
- for (const result of results) {
2606
- if (result.result.status === "dirty") {
2607
- ctx.common.issues.push(...result.ctx.common.issues);
2608
- return result.result;
2609
- }
2610
- }
2611
- const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2612
- addIssueToContext(ctx, {
2613
- code: ZodIssueCode.invalid_union,
2614
- unionErrors
2615
- });
2616
- return INVALID;
2617
- }
2618
- if (ctx.common.async) {
2619
- return Promise.all(options.map(async (option) => {
2620
- const childCtx = {
2621
- ...ctx,
2622
- common: {
2623
- ...ctx.common,
2624
- issues: []
2625
- },
2626
- parent: null
2627
- };
2628
- return {
2629
- result: await option._parseAsync({
2630
- data: ctx.data,
2631
- path: ctx.path,
2632
- parent: childCtx
2633
- }),
2634
- ctx: childCtx
2635
- };
2636
- })).then(handleResults);
2637
- } else {
2638
- let dirty = void 0;
2639
- const issues = [];
2640
- for (const option of options) {
2641
- const childCtx = {
2642
- ...ctx,
2643
- common: {
2644
- ...ctx.common,
2645
- issues: []
2646
- },
2647
- parent: null
2648
- };
2649
- const result = option._parseSync({
2650
- data: ctx.data,
2651
- path: ctx.path,
2652
- parent: childCtx
2653
- });
2654
- if (result.status === "valid") {
2655
- return result;
2656
- } else if (result.status === "dirty" && !dirty) {
2657
- dirty = { result, ctx: childCtx };
2658
- }
2659
- if (childCtx.common.issues.length) {
2660
- issues.push(childCtx.common.issues);
2661
- }
2662
- }
2663
- if (dirty) {
2664
- ctx.common.issues.push(...dirty.ctx.common.issues);
2665
- return dirty.result;
2666
- }
2667
- const unionErrors = issues.map((issues2) => new ZodError(issues2));
2668
- addIssueToContext(ctx, {
2669
- code: ZodIssueCode.invalid_union,
2670
- unionErrors
2671
- });
2672
- return INVALID;
2673
- }
2674
- }
2675
- get options() {
2676
- return this._def.options;
2677
- }
2678
- };
2679
- ZodUnion$1.create = (types2, params) => {
2680
- return new ZodUnion$1({
2681
- options: types2,
2682
- typeName: ZodFirstPartyTypeKind.ZodUnion,
2683
- ...processCreateParams(params)
2684
- });
2685
- };
2686
- function mergeValues$1(a, b) {
2687
- const aType = getParsedType(a);
2688
- const bType = getParsedType(b);
2689
- if (a === b) {
2690
- return { valid: true, data: a };
2691
- } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2692
- const bKeys = util$1.objectKeys(b);
2693
- const sharedKeys = util$1.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2694
- const newObj = { ...a, ...b };
2695
- for (const key of sharedKeys) {
2696
- const sharedValue = mergeValues$1(a[key], b[key]);
2697
- if (!sharedValue.valid) {
2698
- return { valid: false };
2699
- }
2700
- newObj[key] = sharedValue.data;
2701
- }
2702
- return { valid: true, data: newObj };
2703
- } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2704
- if (a.length !== b.length) {
2705
- return { valid: false };
2706
- }
2707
- const newArray = [];
2708
- for (let index = 0; index < a.length; index++) {
2709
- const itemA = a[index];
2710
- const itemB = b[index];
2711
- const sharedValue = mergeValues$1(itemA, itemB);
2712
- if (!sharedValue.valid) {
2713
- return { valid: false };
2714
- }
2715
- newArray.push(sharedValue.data);
2716
- }
2717
- return { valid: true, data: newArray };
2718
- } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
2719
- return { valid: true, data: a };
2720
- } else {
2721
- return { valid: false };
2722
- }
2723
- }
2724
- let ZodIntersection$1 = class ZodIntersection extends ZodType$1 {
2725
- _parse(input) {
2726
- const { status, ctx } = this._processInputParams(input);
2727
- const handleParsed = (parsedLeft, parsedRight) => {
2728
- if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2729
- return INVALID;
2730
- }
2731
- const merged = mergeValues$1(parsedLeft.value, parsedRight.value);
2732
- if (!merged.valid) {
2733
- addIssueToContext(ctx, {
2734
- code: ZodIssueCode.invalid_intersection_types
2735
- });
2736
- return INVALID;
2737
- }
2738
- if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2739
- status.dirty();
2740
- }
2741
- return { status: status.value, value: merged.data };
2742
- };
2743
- if (ctx.common.async) {
2744
- return Promise.all([
2745
- this._def.left._parseAsync({
2746
- data: ctx.data,
2747
- path: ctx.path,
2748
- parent: ctx
2749
- }),
2750
- this._def.right._parseAsync({
2751
- data: ctx.data,
2752
- path: ctx.path,
2753
- parent: ctx
2754
- })
2755
- ]).then(([left, right]) => handleParsed(left, right));
2756
- } else {
2757
- return handleParsed(this._def.left._parseSync({
2758
- data: ctx.data,
2759
- path: ctx.path,
2760
- parent: ctx
2761
- }), this._def.right._parseSync({
2762
- data: ctx.data,
2763
- path: ctx.path,
2764
- parent: ctx
2765
- }));
2766
- }
2767
- }
2768
- };
2769
- ZodIntersection$1.create = (left, right, params) => {
2770
- return new ZodIntersection$1({
2771
- left,
2772
- right,
2773
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
2774
- ...processCreateParams(params)
2775
- });
2776
- };
2777
- class ZodTuple extends ZodType$1 {
2778
- _parse(input) {
2779
- const { status, ctx } = this._processInputParams(input);
2780
- if (ctx.parsedType !== ZodParsedType.array) {
2781
- addIssueToContext(ctx, {
2782
- code: ZodIssueCode.invalid_type,
2783
- expected: ZodParsedType.array,
2784
- received: ctx.parsedType
2785
- });
2786
- return INVALID;
2787
- }
2788
- if (ctx.data.length < this._def.items.length) {
2789
- addIssueToContext(ctx, {
2790
- code: ZodIssueCode.too_small,
2791
- minimum: this._def.items.length,
2792
- inclusive: true,
2793
- exact: false,
2794
- type: "array"
2795
- });
2796
- return INVALID;
2797
- }
2798
- const rest = this._def.rest;
2799
- if (!rest && ctx.data.length > this._def.items.length) {
2800
- addIssueToContext(ctx, {
2801
- code: ZodIssueCode.too_big,
2802
- maximum: this._def.items.length,
2803
- inclusive: true,
2804
- exact: false,
2805
- type: "array"
2806
- });
2807
- status.dirty();
2808
- }
2809
- const items2 = [...ctx.data].map((item, itemIndex) => {
2810
- const schema = this._def.items[itemIndex] || this._def.rest;
2811
- if (!schema)
2812
- return null;
2813
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2814
- }).filter((x) => !!x);
2815
- if (ctx.common.async) {
2816
- return Promise.all(items2).then((results) => {
2817
- return ParseStatus.mergeArray(status, results);
2818
- });
2819
- } else {
2820
- return ParseStatus.mergeArray(status, items2);
2821
- }
2822
- }
2823
- get items() {
2824
- return this._def.items;
2825
- }
2826
- rest(rest) {
2827
- return new ZodTuple({
2828
- ...this._def,
2829
- rest
2830
- });
2831
- }
2832
- }
2833
- ZodTuple.create = (schemas, params) => {
2834
- if (!Array.isArray(schemas)) {
2835
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2836
- }
2837
- return new ZodTuple({
2838
- items: schemas,
2839
- typeName: ZodFirstPartyTypeKind.ZodTuple,
2840
- rest: null,
2841
- ...processCreateParams(params)
2842
- });
2843
- };
2844
- class ZodMap extends ZodType$1 {
2845
- get keySchema() {
2846
- return this._def.keyType;
2847
- }
2848
- get valueSchema() {
2849
- return this._def.valueType;
2850
- }
2851
- _parse(input) {
2852
- const { status, ctx } = this._processInputParams(input);
2853
- if (ctx.parsedType !== ZodParsedType.map) {
2854
- addIssueToContext(ctx, {
2855
- code: ZodIssueCode.invalid_type,
2856
- expected: ZodParsedType.map,
2857
- received: ctx.parsedType
2858
- });
2859
- return INVALID;
2860
- }
2861
- const keyType = this._def.keyType;
2862
- const valueType = this._def.valueType;
2863
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
2864
- return {
2865
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
2866
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
2867
- };
2868
- });
2869
- if (ctx.common.async) {
2870
- const finalMap = /* @__PURE__ */ new Map();
2871
- return Promise.resolve().then(async () => {
2872
- for (const pair2 of pairs) {
2873
- const key = await pair2.key;
2874
- const value = await pair2.value;
2875
- if (key.status === "aborted" || value.status === "aborted") {
2876
- return INVALID;
2877
- }
2878
- if (key.status === "dirty" || value.status === "dirty") {
2879
- status.dirty();
2880
- }
2881
- finalMap.set(key.value, value.value);
2882
- }
2883
- return { status: status.value, value: finalMap };
2884
- });
2885
- } else {
2886
- const finalMap = /* @__PURE__ */ new Map();
2887
- for (const pair2 of pairs) {
2888
- const key = pair2.key;
2889
- const value = pair2.value;
2890
- if (key.status === "aborted" || value.status === "aborted") {
2891
- return INVALID;
2892
- }
2893
- if (key.status === "dirty" || value.status === "dirty") {
2894
- status.dirty();
2895
- }
2896
- finalMap.set(key.value, value.value);
2897
- }
2898
- return { status: status.value, value: finalMap };
2899
- }
2900
- }
2901
- }
2902
- ZodMap.create = (keyType, valueType, params) => {
2903
- return new ZodMap({
2904
- valueType,
2905
- keyType,
2906
- typeName: ZodFirstPartyTypeKind.ZodMap,
2907
- ...processCreateParams(params)
2908
- });
2909
- };
2910
- class ZodSet extends ZodType$1 {
2911
- _parse(input) {
2912
- const { status, ctx } = this._processInputParams(input);
2913
- if (ctx.parsedType !== ZodParsedType.set) {
2914
- addIssueToContext(ctx, {
2915
- code: ZodIssueCode.invalid_type,
2916
- expected: ZodParsedType.set,
2917
- received: ctx.parsedType
2918
- });
2919
- return INVALID;
2920
- }
2921
- const def = this._def;
2922
- if (def.minSize !== null) {
2923
- if (ctx.data.size < def.minSize.value) {
2924
- addIssueToContext(ctx, {
2925
- code: ZodIssueCode.too_small,
2926
- minimum: def.minSize.value,
2927
- type: "set",
2928
- inclusive: true,
2929
- exact: false,
2930
- message: def.minSize.message
2931
- });
2932
- status.dirty();
2933
- }
2934
- }
2935
- if (def.maxSize !== null) {
2936
- if (ctx.data.size > def.maxSize.value) {
2937
- addIssueToContext(ctx, {
2938
- code: ZodIssueCode.too_big,
2939
- maximum: def.maxSize.value,
2940
- type: "set",
2941
- inclusive: true,
2942
- exact: false,
2943
- message: def.maxSize.message
2944
- });
2945
- status.dirty();
2946
- }
2947
- }
2948
- const valueType = this._def.valueType;
2949
- function finalizeSet(elements2) {
2950
- const parsedSet = /* @__PURE__ */ new Set();
2951
- for (const element of elements2) {
2952
- if (element.status === "aborted")
2953
- return INVALID;
2954
- if (element.status === "dirty")
2955
- status.dirty();
2956
- parsedSet.add(element.value);
2957
- }
2958
- return { status: status.value, value: parsedSet };
2959
- }
2960
- const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
2961
- if (ctx.common.async) {
2962
- return Promise.all(elements).then((elements2) => finalizeSet(elements2));
2963
- } else {
2964
- return finalizeSet(elements);
2965
- }
2966
- }
2967
- min(minSize, message) {
2968
- return new ZodSet({
2969
- ...this._def,
2970
- minSize: { value: minSize, message: errorUtil.toString(message) }
2971
- });
2972
- }
2973
- max(maxSize, message) {
2974
- return new ZodSet({
2975
- ...this._def,
2976
- maxSize: { value: maxSize, message: errorUtil.toString(message) }
2977
- });
2978
- }
2979
- size(size, message) {
2980
- return this.min(size, message).max(size, message);
2981
- }
2982
- nonempty(message) {
2983
- return this.min(1, message);
2984
- }
2985
- }
2986
- ZodSet.create = (valueType, params) => {
2987
- return new ZodSet({
2988
- valueType,
2989
- minSize: null,
2990
- maxSize: null,
2991
- typeName: ZodFirstPartyTypeKind.ZodSet,
2992
- ...processCreateParams(params)
2993
- });
2994
- };
2995
- class ZodLazy extends ZodType$1 {
2996
- get schema() {
2997
- return this._def.getter();
2998
- }
2999
- _parse(input) {
3000
- const { ctx } = this._processInputParams(input);
3001
- const lazySchema = this._def.getter();
3002
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3003
- }
3004
- }
3005
- ZodLazy.create = (getter, params) => {
3006
- return new ZodLazy({
3007
- getter,
3008
- typeName: ZodFirstPartyTypeKind.ZodLazy,
3009
- ...processCreateParams(params)
3010
- });
3011
- };
3012
- let ZodLiteral$1 = class ZodLiteral extends ZodType$1 {
3013
- _parse(input) {
3014
- if (input.data !== this._def.value) {
3015
- const ctx = this._getOrReturnCtx(input);
3016
- addIssueToContext(ctx, {
3017
- received: ctx.data,
3018
- code: ZodIssueCode.invalid_literal,
3019
- expected: this._def.value
3020
- });
3021
- return INVALID;
3022
- }
3023
- return { status: "valid", value: input.data };
3024
- }
3025
- get value() {
3026
- return this._def.value;
3027
- }
3028
- };
3029
- ZodLiteral$1.create = (value, params) => {
3030
- return new ZodLiteral$1({
3031
- value,
3032
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
3033
- ...processCreateParams(params)
3034
- });
3035
- };
3036
- function createZodEnum(values, params) {
3037
- return new ZodEnum$1({
3038
- values,
3039
- typeName: ZodFirstPartyTypeKind.ZodEnum,
3040
- ...processCreateParams(params)
3041
- });
3042
- }
3043
- let ZodEnum$1 = class ZodEnum extends ZodType$1 {
3044
- _parse(input) {
3045
- if (typeof input.data !== "string") {
3046
- const ctx = this._getOrReturnCtx(input);
3047
- const expectedValues = this._def.values;
3048
- addIssueToContext(ctx, {
3049
- expected: util$1.joinValues(expectedValues),
3050
- received: ctx.parsedType,
3051
- code: ZodIssueCode.invalid_type
3052
- });
3053
- return INVALID;
3054
- }
3055
- if (!this._cache) {
3056
- this._cache = new Set(this._def.values);
3057
- }
3058
- if (!this._cache.has(input.data)) {
3059
- const ctx = this._getOrReturnCtx(input);
3060
- const expectedValues = this._def.values;
3061
- addIssueToContext(ctx, {
3062
- received: ctx.data,
3063
- code: ZodIssueCode.invalid_enum_value,
3064
- options: expectedValues
3065
- });
3066
- return INVALID;
3067
- }
3068
- return OK(input.data);
3069
- }
3070
- get options() {
3071
- return this._def.values;
3072
- }
3073
- get enum() {
3074
- const enumValues = {};
3075
- for (const val of this._def.values) {
3076
- enumValues[val] = val;
3077
- }
3078
- return enumValues;
3079
- }
3080
- get Values() {
3081
- const enumValues = {};
3082
- for (const val of this._def.values) {
3083
- enumValues[val] = val;
3084
- }
3085
- return enumValues;
3086
- }
3087
- get Enum() {
3088
- const enumValues = {};
3089
- for (const val of this._def.values) {
3090
- enumValues[val] = val;
3091
- }
3092
- return enumValues;
3093
- }
3094
- extract(values, newDef = this._def) {
3095
- return ZodEnum.create(values, {
3096
- ...this._def,
3097
- ...newDef
3098
- });
3099
- }
3100
- exclude(values, newDef = this._def) {
3101
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3102
- ...this._def,
3103
- ...newDef
3104
- });
3105
- }
3106
- };
3107
- ZodEnum$1.create = createZodEnum;
3108
- class ZodNativeEnum extends ZodType$1 {
3109
- _parse(input) {
3110
- const nativeEnumValues = util$1.getValidEnumValues(this._def.values);
3111
- const ctx = this._getOrReturnCtx(input);
3112
- if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3113
- const expectedValues = util$1.objectValues(nativeEnumValues);
3114
- addIssueToContext(ctx, {
3115
- expected: util$1.joinValues(expectedValues),
3116
- received: ctx.parsedType,
3117
- code: ZodIssueCode.invalid_type
3118
- });
3119
- return INVALID;
3120
- }
3121
- if (!this._cache) {
3122
- this._cache = new Set(util$1.getValidEnumValues(this._def.values));
3123
- }
3124
- if (!this._cache.has(input.data)) {
3125
- const expectedValues = util$1.objectValues(nativeEnumValues);
3126
- addIssueToContext(ctx, {
3127
- received: ctx.data,
3128
- code: ZodIssueCode.invalid_enum_value,
3129
- options: expectedValues
3130
- });
3131
- return INVALID;
3132
- }
3133
- return OK(input.data);
3134
- }
3135
- get enum() {
3136
- return this._def.values;
3137
- }
3138
- }
3139
- ZodNativeEnum.create = (values, params) => {
3140
- return new ZodNativeEnum({
3141
- values,
3142
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3143
- ...processCreateParams(params)
3144
- });
3145
- };
3146
- class ZodPromise extends ZodType$1 {
3147
- unwrap() {
3148
- return this._def.type;
3149
- }
3150
- _parse(input) {
3151
- const { ctx } = this._processInputParams(input);
3152
- if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3153
- addIssueToContext(ctx, {
3154
- code: ZodIssueCode.invalid_type,
3155
- expected: ZodParsedType.promise,
3156
- received: ctx.parsedType
3157
- });
3158
- return INVALID;
3159
- }
3160
- const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3161
- return OK(promisified.then((data) => {
3162
- return this._def.type.parseAsync(data, {
3163
- path: ctx.path,
3164
- errorMap: ctx.common.contextualErrorMap
3165
- });
3166
- }));
3167
- }
3168
- }
3169
- ZodPromise.create = (schema, params) => {
3170
- return new ZodPromise({
3171
- type: schema,
3172
- typeName: ZodFirstPartyTypeKind.ZodPromise,
3173
- ...processCreateParams(params)
3174
- });
3175
- };
3176
- class ZodEffects extends ZodType$1 {
3177
- innerType() {
3178
- return this._def.schema;
3179
- }
3180
- sourceType() {
3181
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3182
- }
3183
- _parse(input) {
3184
- const { status, ctx } = this._processInputParams(input);
3185
- const effect = this._def.effect || null;
3186
- const checkCtx = {
3187
- addIssue: (arg) => {
3188
- addIssueToContext(ctx, arg);
3189
- if (arg.fatal) {
3190
- status.abort();
3191
- } else {
3192
- status.dirty();
3193
- }
3194
- },
3195
- get path() {
3196
- return ctx.path;
3197
- }
3198
- };
3199
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3200
- if (effect.type === "preprocess") {
3201
- const processed = effect.transform(ctx.data, checkCtx);
3202
- if (ctx.common.async) {
3203
- return Promise.resolve(processed).then(async (processed2) => {
3204
- if (status.value === "aborted")
3205
- return INVALID;
3206
- const result = await this._def.schema._parseAsync({
3207
- data: processed2,
3208
- path: ctx.path,
3209
- parent: ctx
3210
- });
3211
- if (result.status === "aborted")
3212
- return INVALID;
3213
- if (result.status === "dirty")
3214
- return DIRTY(result.value);
3215
- if (status.value === "dirty")
3216
- return DIRTY(result.value);
3217
- return result;
3218
- });
3219
- } else {
3220
- if (status.value === "aborted")
3221
- return INVALID;
3222
- const result = this._def.schema._parseSync({
3223
- data: processed,
3224
- path: ctx.path,
3225
- parent: ctx
3226
- });
3227
- if (result.status === "aborted")
3228
- return INVALID;
3229
- if (result.status === "dirty")
3230
- return DIRTY(result.value);
3231
- if (status.value === "dirty")
3232
- return DIRTY(result.value);
3233
- return result;
3234
- }
3235
- }
3236
- if (effect.type === "refinement") {
3237
- const executeRefinement = (acc) => {
3238
- const result = effect.refinement(acc, checkCtx);
3239
- if (ctx.common.async) {
3240
- return Promise.resolve(result);
3241
- }
3242
- if (result instanceof Promise) {
3243
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3244
- }
3245
- return acc;
3246
- };
3247
- if (ctx.common.async === false) {
3248
- const inner = this._def.schema._parseSync({
3249
- data: ctx.data,
3250
- path: ctx.path,
3251
- parent: ctx
3252
- });
3253
- if (inner.status === "aborted")
3254
- return INVALID;
3255
- if (inner.status === "dirty")
3256
- status.dirty();
3257
- executeRefinement(inner.value);
3258
- return { status: status.value, value: inner.value };
3259
- } else {
3260
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3261
- if (inner.status === "aborted")
3262
- return INVALID;
3263
- if (inner.status === "dirty")
3264
- status.dirty();
3265
- return executeRefinement(inner.value).then(() => {
3266
- return { status: status.value, value: inner.value };
3267
- });
3268
- });
3269
- }
3270
- }
3271
- if (effect.type === "transform") {
3272
- if (ctx.common.async === false) {
3273
- const base2 = this._def.schema._parseSync({
3274
- data: ctx.data,
3275
- path: ctx.path,
3276
- parent: ctx
3277
- });
3278
- if (!isValid(base2))
3279
- return INVALID;
3280
- const result = effect.transform(base2.value, checkCtx);
3281
- if (result instanceof Promise) {
3282
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3283
- }
3284
- return { status: status.value, value: result };
3285
- } else {
3286
- return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base2) => {
3287
- if (!isValid(base2))
3288
- return INVALID;
3289
- return Promise.resolve(effect.transform(base2.value, checkCtx)).then((result) => ({
3290
- status: status.value,
3291
- value: result
3292
- }));
3293
- });
3294
- }
3295
- }
3296
- util$1.assertNever(effect);
3297
- }
3298
- }
3299
- ZodEffects.create = (schema, effect, params) => {
3300
- return new ZodEffects({
3301
- schema,
3302
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3303
- effect,
3304
- ...processCreateParams(params)
3305
- });
3306
- };
3307
- ZodEffects.createWithPreprocess = (preprocess2, schema, params) => {
3308
- return new ZodEffects({
3309
- schema,
3310
- effect: { type: "preprocess", transform: preprocess2 },
3311
- typeName: ZodFirstPartyTypeKind.ZodEffects,
3312
- ...processCreateParams(params)
3313
- });
3314
- };
3315
- let ZodOptional$1 = class ZodOptional extends ZodType$1 {
3316
- _parse(input) {
3317
- const parsedType = this._getType(input);
3318
- if (parsedType === ZodParsedType.undefined) {
3319
- return OK(void 0);
3320
- }
3321
- return this._def.innerType._parse(input);
3322
- }
3323
- unwrap() {
3324
- return this._def.innerType;
3325
- }
3326
- };
3327
- ZodOptional$1.create = (type2, params) => {
3328
- return new ZodOptional$1({
3329
- innerType: type2,
3330
- typeName: ZodFirstPartyTypeKind.ZodOptional,
3331
- ...processCreateParams(params)
3332
- });
3333
- };
3334
- let ZodNullable$1 = class ZodNullable extends ZodType$1 {
3335
- _parse(input) {
3336
- const parsedType = this._getType(input);
3337
- if (parsedType === ZodParsedType.null) {
3338
- return OK(null);
3339
- }
3340
- return this._def.innerType._parse(input);
3341
- }
3342
- unwrap() {
3343
- return this._def.innerType;
3344
- }
3345
- };
3346
- ZodNullable$1.create = (type2, params) => {
3347
- return new ZodNullable$1({
3348
- innerType: type2,
3349
- typeName: ZodFirstPartyTypeKind.ZodNullable,
3350
- ...processCreateParams(params)
3351
- });
3352
- };
3353
- let ZodDefault$1 = class ZodDefault extends ZodType$1 {
3354
- _parse(input) {
3355
- const { ctx } = this._processInputParams(input);
3356
- let data = ctx.data;
3357
- if (ctx.parsedType === ZodParsedType.undefined) {
3358
- data = this._def.defaultValue();
3359
- }
3360
- return this._def.innerType._parse({
3361
- data,
3362
- path: ctx.path,
3363
- parent: ctx
3364
- });
3365
- }
3366
- removeDefault() {
3367
- return this._def.innerType;
3368
- }
3369
- };
3370
- ZodDefault$1.create = (type2, params) => {
3371
- return new ZodDefault$1({
3372
- innerType: type2,
3373
- typeName: ZodFirstPartyTypeKind.ZodDefault,
3374
- defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3375
- ...processCreateParams(params)
3376
- });
3377
- };
3378
- let ZodCatch$1 = class ZodCatch extends ZodType$1 {
3379
- _parse(input) {
3380
- const { ctx } = this._processInputParams(input);
3381
- const newCtx = {
3382
- ...ctx,
3383
- common: {
3384
- ...ctx.common,
3385
- issues: []
3386
- }
3387
- };
3388
- const result = this._def.innerType._parse({
3389
- data: newCtx.data,
3390
- path: newCtx.path,
3391
- parent: {
3392
- ...newCtx
3393
- }
3394
- });
3395
- if (isAsync(result)) {
3396
- return result.then((result2) => {
3397
- return {
3398
- status: "valid",
3399
- value: result2.status === "valid" ? result2.value : this._def.catchValue({
3400
- get error() {
3401
- return new ZodError(newCtx.common.issues);
3402
- },
3403
- input: newCtx.data
3404
- })
3405
- };
3406
- });
3407
- } else {
3408
- return {
3409
- status: "valid",
3410
- value: result.status === "valid" ? result.value : this._def.catchValue({
3411
- get error() {
3412
- return new ZodError(newCtx.common.issues);
3413
- },
3414
- input: newCtx.data
3415
- })
3416
- };
3417
- }
3418
- }
3419
- removeCatch() {
3420
- return this._def.innerType;
3421
- }
3422
- };
3423
- ZodCatch$1.create = (type2, params) => {
3424
- return new ZodCatch$1({
3425
- innerType: type2,
3426
- typeName: ZodFirstPartyTypeKind.ZodCatch,
3427
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3428
- ...processCreateParams(params)
3429
- });
3430
- };
3431
- class ZodNaN extends ZodType$1 {
3432
- _parse(input) {
3433
- const parsedType = this._getType(input);
3434
- if (parsedType !== ZodParsedType.nan) {
3435
- const ctx = this._getOrReturnCtx(input);
3436
- addIssueToContext(ctx, {
3437
- code: ZodIssueCode.invalid_type,
3438
- expected: ZodParsedType.nan,
3439
- received: ctx.parsedType
3440
- });
3441
- return INVALID;
3442
- }
3443
- return { status: "valid", value: input.data };
3444
- }
3445
- }
3446
- ZodNaN.create = (params) => {
3447
- return new ZodNaN({
3448
- typeName: ZodFirstPartyTypeKind.ZodNaN,
3449
- ...processCreateParams(params)
3450
- });
3451
- };
3452
- class ZodBranded extends ZodType$1 {
3453
- _parse(input) {
3454
- const { ctx } = this._processInputParams(input);
3455
- const data = ctx.data;
3456
- return this._def.type._parse({
3457
- data,
3458
- path: ctx.path,
3459
- parent: ctx
3460
- });
3461
- }
3462
- unwrap() {
3463
- return this._def.type;
3464
- }
3465
- }
3466
- class ZodPipeline extends ZodType$1 {
3467
- _parse(input) {
3468
- const { status, ctx } = this._processInputParams(input);
3469
- if (ctx.common.async) {
3470
- const handleAsync = async () => {
3471
- const inResult = await this._def.in._parseAsync({
3472
- data: ctx.data,
3473
- path: ctx.path,
3474
- parent: ctx
3475
- });
3476
- if (inResult.status === "aborted")
3477
- return INVALID;
3478
- if (inResult.status === "dirty") {
3479
- status.dirty();
3480
- return DIRTY(inResult.value);
3481
- } else {
3482
- return this._def.out._parseAsync({
3483
- data: inResult.value,
3484
- path: ctx.path,
3485
- parent: ctx
3486
- });
3487
- }
3488
- };
3489
- return handleAsync();
3490
- } else {
3491
- const inResult = this._def.in._parseSync({
3492
- data: ctx.data,
3493
- path: ctx.path,
3494
- parent: ctx
3495
- });
3496
- if (inResult.status === "aborted")
3497
- return INVALID;
3498
- if (inResult.status === "dirty") {
3499
- status.dirty();
3500
- return {
3501
- status: "dirty",
3502
- value: inResult.value
3503
- };
3504
- } else {
3505
- return this._def.out._parseSync({
3506
- data: inResult.value,
3507
- path: ctx.path,
3508
- parent: ctx
3509
- });
3510
- }
3511
- }
3512
- }
3513
- static create(a, b) {
3514
- return new ZodPipeline({
3515
- in: a,
3516
- out: b,
3517
- typeName: ZodFirstPartyTypeKind.ZodPipeline
3518
- });
3519
- }
3520
- }
3521
- let ZodReadonly$1 = class ZodReadonly extends ZodType$1 {
3522
- _parse(input) {
3523
- const result = this._def.innerType._parse(input);
3524
- const freeze = (data) => {
3525
- if (isValid(data)) {
3526
- data.value = Object.freeze(data.value);
3527
- }
3528
- return data;
3529
- };
3530
- return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3531
- }
3532
- unwrap() {
3533
- return this._def.innerType;
3534
- }
3535
- };
3536
- ZodReadonly$1.create = (type2, params) => {
3537
- return new ZodReadonly$1({
3538
- innerType: type2,
3539
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
3540
- ...processCreateParams(params)
3541
- });
3542
- };
3543
- var ZodFirstPartyTypeKind;
3544
- (function(ZodFirstPartyTypeKind2) {
3545
- ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3546
- ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3547
- ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3548
- ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3549
- ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3550
- ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3551
- ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3552
- ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3553
- ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3554
- ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3555
- ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3556
- ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3557
- ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3558
- ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3559
- ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3560
- ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3561
- ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3562
- ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3563
- ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3564
- ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3565
- ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3566
- ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3567
- ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3568
- ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3569
- ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3570
- ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3571
- ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3572
- ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3573
- ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3574
- ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
3575
- ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
3576
- ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
3577
- ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
3578
- ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
3579
- ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
3580
- ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
3581
- })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3582
- ZodNever$1.create;
3583
- ZodArray$1.create;
3584
- const objectType = ZodObject$1.create;
3585
- ZodUnion$1.create;
3586
- ZodIntersection$1.create;
3587
- ZodTuple.create;
3588
- ZodEnum$1.create;
3589
- ZodPromise.create;
3590
- ZodOptional$1.create;
3591
- ZodNullable$1.create;
3592
21
  function $constructor(name2, initializer2, params) {
3593
22
  function init(inst, def) {
3594
23
  var _a2;
@@ -4115,8 +544,8 @@ function datetime$1(args) {
4115
544
  opts.push("");
4116
545
  if (args.offset)
4117
546
  opts.push(`([+-]\\d{2}:\\d{2})`);
4118
- const timeRegex2 = `${time2}(?:${opts.join("|")})`;
4119
- return new RegExp(`^${dateSource}T(?:${timeRegex2})$`);
547
+ const timeRegex = `${time2}(?:${opts.join("|")})`;
548
+ return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
4120
549
  }
4121
550
  const string$2 = (params) => {
4122
551
  const regex = params ? `[\\s\\S]{${(params == null ? void 0 : params.minimum) ?? 0},${(params == null ? void 0 : params.maximum) ?? ""}}` : `[\\s\\S]*`;
@@ -4574,14 +1003,14 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
4574
1003
  });
4575
1004
  } else {
4576
1005
  const runChecks = (payload, checks2, ctx) => {
4577
- let isAborted2 = aborted(payload);
1006
+ let isAborted = aborted(payload);
4578
1007
  let asyncResult;
4579
1008
  for (const ch of checks2) {
4580
1009
  if (ch._zod.def.when) {
4581
1010
  const shouldRun = ch._zod.def.when(payload);
4582
1011
  if (!shouldRun)
4583
1012
  continue;
4584
- } else if (isAborted2) {
1013
+ } else if (isAborted) {
4585
1014
  continue;
4586
1015
  }
4587
1016
  const currLen = payload.issues.length;
@@ -4595,15 +1024,15 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
4595
1024
  const nextLen = payload.issues.length;
4596
1025
  if (nextLen === currLen)
4597
1026
  return;
4598
- if (!isAborted2)
4599
- isAborted2 = aborted(payload, currLen);
1027
+ if (!isAborted)
1028
+ isAborted = aborted(payload, currLen);
4600
1029
  });
4601
1030
  } else {
4602
1031
  const nextLen = payload.issues.length;
4603
1032
  if (nextLen === currLen)
4604
1033
  continue;
4605
- if (!isAborted2)
4606
- isAborted2 = aborted(payload, currLen);
1034
+ if (!isAborted)
1035
+ isAborted = aborted(payload, currLen);
4607
1036
  }
4608
1037
  }
4609
1038
  if (asyncResult) {
@@ -6402,7 +2831,7 @@ const parse = /* @__PURE__ */ _parse(ZodRealError);
6402
2831
  const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
6403
2832
  const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
6404
2833
  const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
6405
- const ZodType2 = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
2834
+ const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
6406
2835
  $ZodType.init(inst, def);
6407
2836
  inst.def = def;
6408
2837
  Object.defineProperty(inst, "_def", { value: def });
@@ -6471,7 +2900,7 @@ const ZodType2 = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
6471
2900
  });
6472
2901
  const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
6473
2902
  $ZodString.init(inst, def);
6474
- ZodType2.init(inst, def);
2903
+ ZodType.init(inst, def);
6475
2904
  const bag = inst._zod.bag;
6476
2905
  inst.format = bag.format ?? null;
6477
2906
  inst.minLength = bag.minimum ?? null;
@@ -6491,7 +2920,7 @@ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
6491
2920
  inst.toLowerCase = () => inst.check(_toLowerCase());
6492
2921
  inst.toUpperCase = () => inst.check(_toUpperCase());
6493
2922
  });
6494
- const ZodString2 = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
2923
+ const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
6495
2924
  $ZodString.init(inst, def);
6496
2925
  _ZodString.init(inst, def);
6497
2926
  inst.email = (params) => inst.check(_email(ZodEmail, params));
@@ -6523,7 +2952,7 @@ const ZodString2 = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
6523
2952
  inst.duration = (params) => inst.check(duration(params));
6524
2953
  });
6525
2954
  function string$1(params) {
6526
- return _string(ZodString2, params);
2955
+ return _string(ZodString, params);
6527
2956
  }
6528
2957
  const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, def) => {
6529
2958
  $ZodStringFormat.init(inst, def);
@@ -6605,9 +3034,9 @@ const ZodJWT = /* @__PURE__ */ $constructor("ZodJWT", (inst, def) => {
6605
3034
  $ZodJWT.init(inst, def);
6606
3035
  ZodStringFormat.init(inst, def);
6607
3036
  });
6608
- const ZodNumber2 = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
3037
+ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
6609
3038
  $ZodNumber.init(inst, def);
6610
- ZodType2.init(inst, def);
3039
+ ZodType.init(inst, def);
6611
3040
  inst.gt = (value, params) => inst.check(_gt(value, params));
6612
3041
  inst.gte = (value, params) => inst.check(_gte(value, params));
6613
3042
  inst.min = (value, params) => inst.check(_gte(value, params));
@@ -6631,46 +3060,46 @@ const ZodNumber2 = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
6631
3060
  inst.format = bag.format ?? null;
6632
3061
  });
6633
3062
  function number$1(params) {
6634
- return _number(ZodNumber2, params);
3063
+ return _number(ZodNumber, params);
6635
3064
  }
6636
3065
  const ZodNumberFormat = /* @__PURE__ */ $constructor("ZodNumberFormat", (inst, def) => {
6637
3066
  $ZodNumberFormat.init(inst, def);
6638
- ZodNumber2.init(inst, def);
3067
+ ZodNumber.init(inst, def);
6639
3068
  });
6640
3069
  function int(params) {
6641
3070
  return _int(ZodNumberFormat, params);
6642
3071
  }
6643
- const ZodBoolean2 = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
3072
+ const ZodBoolean = /* @__PURE__ */ $constructor("ZodBoolean", (inst, def) => {
6644
3073
  $ZodBoolean.init(inst, def);
6645
- ZodType2.init(inst, def);
3074
+ ZodType.init(inst, def);
6646
3075
  });
6647
3076
  function boolean(params) {
6648
- return _boolean(ZodBoolean2, params);
3077
+ return _boolean(ZodBoolean, params);
6649
3078
  }
6650
- const ZodNull2 = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
3079
+ const ZodNull = /* @__PURE__ */ $constructor("ZodNull", (inst, def) => {
6651
3080
  $ZodNull.init(inst, def);
6652
- ZodType2.init(inst, def);
3081
+ ZodType.init(inst, def);
6653
3082
  });
6654
3083
  function _null(params) {
6655
- return _null$1(ZodNull2, params);
3084
+ return _null$1(ZodNull, params);
6656
3085
  }
6657
- const ZodUnknown2 = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
3086
+ const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
6658
3087
  $ZodUnknown.init(inst, def);
6659
- ZodType2.init(inst, def);
3088
+ ZodType.init(inst, def);
6660
3089
  });
6661
3090
  function unknown() {
6662
- return _unknown(ZodUnknown2);
3091
+ return _unknown(ZodUnknown);
6663
3092
  }
6664
- const ZodNever2 = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
3093
+ const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
6665
3094
  $ZodNever.init(inst, def);
6666
- ZodType2.init(inst, def);
3095
+ ZodType.init(inst, def);
6667
3096
  });
6668
3097
  function never(params) {
6669
- return _never(ZodNever2, params);
3098
+ return _never(ZodNever, params);
6670
3099
  }
6671
- const ZodArray2 = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
3100
+ const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
6672
3101
  $ZodArray.init(inst, def);
6673
- ZodType2.init(inst, def);
3102
+ ZodType.init(inst, def);
6674
3103
  inst.element = def.element;
6675
3104
  inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
6676
3105
  inst.nonempty = (params) => inst.check(_minLength(1, params));
@@ -6679,11 +3108,11 @@ const ZodArray2 = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
6679
3108
  inst.unwrap = () => inst.element;
6680
3109
  });
6681
3110
  function array(element, params) {
6682
- return _array(ZodArray2, element, params);
3111
+ return _array(ZodArray, element, params);
6683
3112
  }
6684
- const ZodObject2 = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
3113
+ const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
6685
3114
  $ZodObject.init(inst, def);
6686
- ZodType2.init(inst, def);
3115
+ ZodType.init(inst, def);
6687
3116
  defineLazy(inst, "shape", () => def.shape);
6688
3117
  inst.keyof = () => _enum$1(Object.keys(inst._zod.def.shape));
6689
3118
  inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
@@ -6697,7 +3126,7 @@ const ZodObject2 = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
6697
3126
  inst.merge = (other) => merge(inst, other);
6698
3127
  inst.pick = (mask) => pick(inst, mask);
6699
3128
  inst.omit = (mask) => omit(inst, mask);
6700
- inst.partial = (...args) => partial(ZodOptional2, inst, args[0]);
3129
+ inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
6701
3130
  inst.required = (...args) => required$2(ZodNonOptional, inst, args[0]);
6702
3131
  });
6703
3132
  function object(shape, params) {
@@ -6709,10 +3138,10 @@ function object(shape, params) {
6709
3138
  },
6710
3139
  ...normalizeParams(params)
6711
3140
  };
6712
- return new ZodObject2(def);
3141
+ return new ZodObject(def);
6713
3142
  }
6714
3143
  function looseObject(shape, params) {
6715
- return new ZodObject2({
3144
+ return new ZodObject({
6716
3145
  type: "object",
6717
3146
  get shape() {
6718
3147
  assignProp(this, "shape", { ...shape });
@@ -6722,20 +3151,20 @@ function looseObject(shape, params) {
6722
3151
  ...normalizeParams(params)
6723
3152
  });
6724
3153
  }
6725
- const ZodUnion2 = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
3154
+ const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
6726
3155
  $ZodUnion.init(inst, def);
6727
- ZodType2.init(inst, def);
3156
+ ZodType.init(inst, def);
6728
3157
  inst.options = def.options;
6729
3158
  });
6730
3159
  function union(options, params) {
6731
- return new ZodUnion2({
3160
+ return new ZodUnion({
6732
3161
  type: "union",
6733
3162
  options,
6734
3163
  ...normalizeParams(params)
6735
3164
  });
6736
3165
  }
6737
3166
  const ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("ZodDiscriminatedUnion", (inst, def) => {
6738
- ZodUnion2.init(inst, def);
3167
+ ZodUnion.init(inst, def);
6739
3168
  $ZodDiscriminatedUnion.init(inst, def);
6740
3169
  });
6741
3170
  function discriminatedUnion(discriminator2, options, params) {
@@ -6746,12 +3175,12 @@ function discriminatedUnion(discriminator2, options, params) {
6746
3175
  ...normalizeParams(params)
6747
3176
  });
6748
3177
  }
6749
- const ZodIntersection2 = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
3178
+ const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
6750
3179
  $ZodIntersection.init(inst, def);
6751
- ZodType2.init(inst, def);
3180
+ ZodType.init(inst, def);
6752
3181
  });
6753
3182
  function intersection(left, right) {
6754
- return new ZodIntersection2({
3183
+ return new ZodIntersection({
6755
3184
  type: "intersection",
6756
3185
  left,
6757
3186
  right
@@ -6759,7 +3188,7 @@ function intersection(left, right) {
6759
3188
  }
6760
3189
  const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
6761
3190
  $ZodRecord.init(inst, def);
6762
- ZodType2.init(inst, def);
3191
+ ZodType.init(inst, def);
6763
3192
  inst.keyType = def.keyType;
6764
3193
  inst.valueType = def.valueType;
6765
3194
  });
@@ -6771,9 +3200,9 @@ function record(keyType, valueType, params) {
6771
3200
  ...normalizeParams(params)
6772
3201
  });
6773
3202
  }
6774
- const ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
3203
+ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
6775
3204
  $ZodEnum.init(inst, def);
6776
- ZodType2.init(inst, def);
3205
+ ZodType.init(inst, def);
6777
3206
  inst.enum = def.entries;
6778
3207
  inst.options = Object.values(def.entries);
6779
3208
  const keys = new Set(Object.keys(def.entries));
@@ -6785,7 +3214,7 @@ const ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
6785
3214
  } else
6786
3215
  throw new Error(`Key ${value} not found in enum`);
6787
3216
  }
6788
- return new ZodEnum2({
3217
+ return new ZodEnum({
6789
3218
  ...def,
6790
3219
  checks: [],
6791
3220
  ...normalizeParams(params),
@@ -6800,7 +3229,7 @@ const ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
6800
3229
  } else
6801
3230
  throw new Error(`Key ${value} not found in enum`);
6802
3231
  }
6803
- return new ZodEnum2({
3232
+ return new ZodEnum({
6804
3233
  ...def,
6805
3234
  checks: [],
6806
3235
  ...normalizeParams(params),
@@ -6810,15 +3239,15 @@ const ZodEnum2 = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
6810
3239
  });
6811
3240
  function _enum$1(values, params) {
6812
3241
  const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
6813
- return new ZodEnum2({
3242
+ return new ZodEnum({
6814
3243
  type: "enum",
6815
3244
  entries,
6816
3245
  ...normalizeParams(params)
6817
3246
  });
6818
3247
  }
6819
- const ZodLiteral2 = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
3248
+ const ZodLiteral = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
6820
3249
  $ZodLiteral.init(inst, def);
6821
- ZodType2.init(inst, def);
3250
+ ZodType.init(inst, def);
6822
3251
  inst.values = new Set(def.values);
6823
3252
  Object.defineProperty(inst, "value", {
6824
3253
  get() {
@@ -6830,7 +3259,7 @@ const ZodLiteral2 = /* @__PURE__ */ $constructor("ZodLiteral", (inst, def) => {
6830
3259
  });
6831
3260
  });
6832
3261
  function literal$1(value, params) {
6833
- return new ZodLiteral2({
3262
+ return new ZodLiteral({
6834
3263
  type: "literal",
6835
3264
  values: Array.isArray(value) ? value : [value],
6836
3265
  ...normalizeParams(params)
@@ -6838,7 +3267,7 @@ function literal$1(value, params) {
6838
3267
  }
6839
3268
  const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
6840
3269
  $ZodTransform.init(inst, def);
6841
- ZodType2.init(inst, def);
3270
+ ZodType.init(inst, def);
6842
3271
  inst._zod.parse = (payload, _ctx) => {
6843
3272
  payload.addIssue = (issue$1) => {
6844
3273
  if (typeof issue$1 === "string") {
@@ -6871,36 +3300,36 @@ function transform(fn) {
6871
3300
  transform: fn
6872
3301
  });
6873
3302
  }
6874
- const ZodOptional2 = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
3303
+ const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
6875
3304
  $ZodOptional.init(inst, def);
6876
- ZodType2.init(inst, def);
3305
+ ZodType.init(inst, def);
6877
3306
  inst.unwrap = () => inst._zod.def.innerType;
6878
3307
  });
6879
3308
  function optional(innerType) {
6880
- return new ZodOptional2({
3309
+ return new ZodOptional({
6881
3310
  type: "optional",
6882
3311
  innerType
6883
3312
  });
6884
3313
  }
6885
- const ZodNullable2 = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
3314
+ const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
6886
3315
  $ZodNullable.init(inst, def);
6887
- ZodType2.init(inst, def);
3316
+ ZodType.init(inst, def);
6888
3317
  inst.unwrap = () => inst._zod.def.innerType;
6889
3318
  });
6890
3319
  function nullable(innerType) {
6891
- return new ZodNullable2({
3320
+ return new ZodNullable({
6892
3321
  type: "nullable",
6893
3322
  innerType
6894
3323
  });
6895
3324
  }
6896
- const ZodDefault2 = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
3325
+ const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
6897
3326
  $ZodDefault.init(inst, def);
6898
- ZodType2.init(inst, def);
3327
+ ZodType.init(inst, def);
6899
3328
  inst.unwrap = () => inst._zod.def.innerType;
6900
3329
  inst.removeDefault = inst.unwrap;
6901
3330
  });
6902
3331
  function _default(innerType, defaultValue) {
6903
- return new ZodDefault2({
3332
+ return new ZodDefault({
6904
3333
  type: "default",
6905
3334
  innerType,
6906
3335
  get defaultValue() {
@@ -6910,7 +3339,7 @@ function _default(innerType, defaultValue) {
6910
3339
  }
6911
3340
  const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
6912
3341
  $ZodPrefault.init(inst, def);
6913
- ZodType2.init(inst, def);
3342
+ ZodType.init(inst, def);
6914
3343
  inst.unwrap = () => inst._zod.def.innerType;
6915
3344
  });
6916
3345
  function prefault(innerType, defaultValue) {
@@ -6924,7 +3353,7 @@ function prefault(innerType, defaultValue) {
6924
3353
  }
6925
3354
  const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
6926
3355
  $ZodNonOptional.init(inst, def);
6927
- ZodType2.init(inst, def);
3356
+ ZodType.init(inst, def);
6928
3357
  inst.unwrap = () => inst._zod.def.innerType;
6929
3358
  });
6930
3359
  function nonoptional(innerType, params) {
@@ -6934,14 +3363,14 @@ function nonoptional(innerType, params) {
6934
3363
  ...normalizeParams(params)
6935
3364
  });
6936
3365
  }
6937
- const ZodCatch2 = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
3366
+ const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
6938
3367
  $ZodCatch.init(inst, def);
6939
- ZodType2.init(inst, def);
3368
+ ZodType.init(inst, def);
6940
3369
  inst.unwrap = () => inst._zod.def.innerType;
6941
3370
  inst.removeCatch = inst.unwrap;
6942
3371
  });
6943
3372
  function _catch(innerType, catchValue) {
6944
- return new ZodCatch2({
3373
+ return new ZodCatch({
6945
3374
  type: "catch",
6946
3375
  innerType,
6947
3376
  catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
@@ -6949,7 +3378,7 @@ function _catch(innerType, catchValue) {
6949
3378
  }
6950
3379
  const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
6951
3380
  $ZodPipe.init(inst, def);
6952
- ZodType2.init(inst, def);
3381
+ ZodType.init(inst, def);
6953
3382
  inst.in = def.in;
6954
3383
  inst.out = def.out;
6955
3384
  });
@@ -6961,19 +3390,19 @@ function pipe(in_, out) {
6961
3390
  // ...util.normalizeParams(params),
6962
3391
  });
6963
3392
  }
6964
- const ZodReadonly2 = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
3393
+ const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
6965
3394
  $ZodReadonly.init(inst, def);
6966
- ZodType2.init(inst, def);
3395
+ ZodType.init(inst, def);
6967
3396
  });
6968
3397
  function readonly(innerType) {
6969
- return new ZodReadonly2({
3398
+ return new ZodReadonly({
6970
3399
  type: "readonly",
6971
3400
  innerType
6972
3401
  });
6973
3402
  }
6974
3403
  const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
6975
3404
  $ZodCustom.init(inst, def);
6976
- ZodType2.init(inst, def);
3405
+ ZodType.init(inst, def);
6977
3406
  });
6978
3407
  function check(fn) {
6979
3408
  const ch = new $ZodCheck({
@@ -17146,21 +13575,10 @@ connect_fn = async function() {
17146
13575
  trace.log(__privateGet(this, _mcpClient));
17147
13576
  __privateGet(this, _mcpClient).connect(transport).then(async () => {
17148
13577
  __privateMethod(this, _NineChatManager_instances, updateStatus_fn).call(this, "✅ MCP Connected");
17149
- try {
17150
- await __privateGet(this, _mcpClient).request(
17151
- { method: "logging/setLevel", params: { level: "info" } },
17152
- objectType({})
17153
- // 빈 응답 스키마 객체 검증
17154
- );
17155
- trace.log("🚀 MCP 로깅 세션 활성화 완료 (Level: info)");
17156
- } catch (linkErr) {
17157
- trace.error("❌ 로깅 세션 활성화 실패:", linkErr);
17158
- }
17159
13578
  __privateGet(this, _mcpClient).onnotification = (notification) => {
17160
13579
  trace.log("🔔 실시간 알림 도착:", notification);
17161
13580
  if ((notification == null ? void 0 : notification.method) === "notifications/logging/message") {
17162
13581
  try {
17163
- trace.log("🔔 실시간 알림 도착:", notification);
17164
13582
  const logData = JSON.parse(notification.params.message);
17165
13583
  if (logData.type === "BRAIN_DECISION") {
17166
13584
  }
@@ -17393,7 +13811,7 @@ render_fn = function() {
17393
13811
  const customImport = this.getAttribute("css-path") ? `@import "${this.getAttribute("css-path")}";` : "";
17394
13812
  this.shadowRoot.innerHTML = `
17395
13813
  <style>
17396
- @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.199"}/dist/css/nine-mu.css";
13814
+ @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.200"}/dist/css/nine-mu.css";
17397
13815
  ${customImport}
17398
13816
  </style>
17399
13817
  <div class="wrapper">
@@ -43612,7 +40030,7 @@ class NineDiff extends HTMLElement {
43612
40030
  const customImport = this.getAttribute("css-path") ? `@import "${this.getAttribute("css-path")}";` : "";
43613
40031
  this.shadowRoot.innerHTML = `
43614
40032
  <style>
43615
- @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.199"}/dist/css/nine-mu.css";
40033
+ @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.200"}/dist/css/nine-mu.css";
43616
40034
  ${customImport}
43617
40035
  </style>
43618
40036
 
@@ -43722,7 +40140,7 @@ render_fn2 = function() {
43722
40140
  const customImport = this.getAttribute("css-path") ? `@import "${this.getAttribute("css-path")}";` : "";
43723
40141
  this.shadowRoot.innerHTML = `
43724
40142
  <style>
43725
- @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.199"}/dist/css/nine-mu.css";
40143
+ @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.200"}/dist/css/nine-mu.css";
43726
40144
  ${customImport}
43727
40145
  </style>
43728
40146
 
@@ -44049,7 +40467,7 @@ class ChatMessageBody extends HTMLElement {
44049
40467
  const customImport = this.getAttribute("css-path") ? `@import "${this.getAttribute("css-path")}";` : "";
44050
40468
  this.shadowRoot.innerHTML = `
44051
40469
  <style>
44052
- @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.199"}/dist/css/nine-mu.css";
40470
+ @import "https://cdn.jsdelivr.net/npm/@nine-lab/nine-mu@${"0.1.200"}/dist/css/nine-mu.css";
44053
40471
  ${customImport}
44054
40472
  </style>
44055
40473
 
@@ -44143,7 +40561,7 @@ if (!customElements.get("nine-chat-progress")) {
44143
40561
  customElements.define("nine-chat-progress", ProgressMessage);
44144
40562
  }
44145
40563
  const NineMu = {
44146
- version: "0.1.199",
40564
+ version: "0.1.200",
44147
40565
  init: (config2) => {
44148
40566
  trace$1.log("🛠️ Nine-Mu Engine initialized", config2);
44149
40567
  }