@nubase/frontend 0.1.29 → 0.1.32

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