@nubase/frontend 0.1.28 → 0.1.31

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