@playcademy/sdk 0.0.1-beta.24 → 0.0.1-beta.25
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/core/client.d.ts +36 -16
- package/dist/core/namespaces/admin.d.ts +16 -12
- package/dist/core/namespaces/dev.d.ts +184 -13
- package/dist/core/namespaces/users.d.ts +16 -16
- package/dist/index.js +4695 -27
- package/dist/types.d.ts +1 -1
- package/dist/types.js +4646 -8
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -263,15 +263,17 @@ function createUsersNamespace(client) {
|
|
|
263
263
|
const resolveItemId = async (identifier) => {
|
|
264
264
|
if (UUID_REGEX.test(identifier))
|
|
265
265
|
return identifier;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (!item) {
|
|
271
|
-
throw new Error(`Item with internal name '${identifier}' not found in inventory`);
|
|
266
|
+
const gameId = client["gameId"];
|
|
267
|
+
const cacheKey = gameId ? `${identifier}:${gameId}` : identifier;
|
|
268
|
+
if (itemIdCache.has(cacheKey)) {
|
|
269
|
+
return itemIdCache.get(cacheKey);
|
|
272
270
|
}
|
|
273
|
-
|
|
274
|
-
|
|
271
|
+
const queryParams = new URLSearchParams({ slug: identifier });
|
|
272
|
+
if (gameId)
|
|
273
|
+
queryParams.append("gameId", gameId);
|
|
274
|
+
const item = await client["request"](`/items/resolve?${queryParams.toString()}`, "GET");
|
|
275
|
+
itemIdCache.set(cacheKey, item.id);
|
|
276
|
+
return item.id;
|
|
275
277
|
};
|
|
276
278
|
return {
|
|
277
279
|
me: async () => {
|
|
@@ -300,12 +302,9 @@ function createUsersNamespace(client) {
|
|
|
300
302
|
return res;
|
|
301
303
|
},
|
|
302
304
|
quantity: async (identifier) => {
|
|
305
|
+
const itemId = await resolveItemId(identifier);
|
|
303
306
|
const inventory = await client.users.inventory.get();
|
|
304
|
-
|
|
305
|
-
const item2 = inventory.find((inv) => inv.item?.id === identifier);
|
|
306
|
-
return item2?.quantity ?? 0;
|
|
307
|
-
}
|
|
308
|
-
const item = inventory.find((inv) => inv.item?.internalName === identifier);
|
|
307
|
+
const item = inventory.find((inv) => inv.item?.id === itemId);
|
|
309
308
|
return item?.quantity ?? 0;
|
|
310
309
|
},
|
|
311
310
|
has: async (identifier, minQuantity = 1) => {
|
|
@@ -337,9 +336,39 @@ function createDevNamespace(client) {
|
|
|
337
336
|
delete: (gameId) => client["request"](`/games/${gameId}`, "DELETE")
|
|
338
337
|
},
|
|
339
338
|
keys: {
|
|
340
|
-
createKey: (
|
|
341
|
-
listKeys: (
|
|
339
|
+
createKey: (label) => client["request"](`/dev/keys`, "POST", { label }),
|
|
340
|
+
listKeys: () => client["request"](`/dev/keys`, "GET"),
|
|
342
341
|
revokeKey: (keyId) => client["request"](`/dev/keys/${keyId}`, "DELETE")
|
|
342
|
+
},
|
|
343
|
+
items: {
|
|
344
|
+
create: (gameId, slug, itemData) => client["request"](`/games/${gameId}/items`, "POST", {
|
|
345
|
+
slug,
|
|
346
|
+
...itemData
|
|
347
|
+
}),
|
|
348
|
+
update: (gameId, itemId, updates) => client["request"](`/games/${gameId}/items/${itemId}`, "PATCH", updates),
|
|
349
|
+
list: (gameId) => client["request"](`/games/${gameId}/items`, "GET"),
|
|
350
|
+
get: (gameId, slug) => {
|
|
351
|
+
const queryParams = new URLSearchParams({ slug, gameId });
|
|
352
|
+
return client["request"](`/items/resolve?${queryParams.toString()}`, "GET");
|
|
353
|
+
},
|
|
354
|
+
delete: (gameId, itemId) => client["request"](`/games/${gameId}/items/${itemId}`, "DELETE"),
|
|
355
|
+
shop: {
|
|
356
|
+
create: (gameId, itemId, listingData) => {
|
|
357
|
+
return client["request"](`/games/${gameId}/items/${itemId}/shop-listing`, "POST", listingData);
|
|
358
|
+
},
|
|
359
|
+
get: (gameId, itemId) => {
|
|
360
|
+
return client["request"](`/games/${gameId}/items/${itemId}/shop-listing`, "GET");
|
|
361
|
+
},
|
|
362
|
+
update: (gameId, itemId, updates) => {
|
|
363
|
+
return client["request"](`/games/${gameId}/items/${itemId}/shop-listing`, "PATCH", updates);
|
|
364
|
+
},
|
|
365
|
+
delete: (gameId, itemId) => {
|
|
366
|
+
return client["request"](`/games/${gameId}/items/${itemId}/shop-listing`, "DELETE");
|
|
367
|
+
},
|
|
368
|
+
list: (gameId) => {
|
|
369
|
+
return client["request"](`/games/${gameId}/shop-listings`, "GET");
|
|
370
|
+
}
|
|
371
|
+
}
|
|
343
372
|
}
|
|
344
373
|
};
|
|
345
374
|
}
|
|
@@ -437,10 +466,4648 @@ function createLevelsNamespace(client) {
|
|
|
437
466
|
};
|
|
438
467
|
}
|
|
439
468
|
|
|
469
|
+
// ../../node_modules/zod/dist/esm/v3/helpers/util.js
|
|
470
|
+
var util, objectUtil, ZodParsedType, getParsedType = (data) => {
|
|
471
|
+
const t = typeof data;
|
|
472
|
+
switch (t) {
|
|
473
|
+
case "undefined":
|
|
474
|
+
return ZodParsedType.undefined;
|
|
475
|
+
case "string":
|
|
476
|
+
return ZodParsedType.string;
|
|
477
|
+
case "number":
|
|
478
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
479
|
+
case "boolean":
|
|
480
|
+
return ZodParsedType.boolean;
|
|
481
|
+
case "function":
|
|
482
|
+
return ZodParsedType.function;
|
|
483
|
+
case "bigint":
|
|
484
|
+
return ZodParsedType.bigint;
|
|
485
|
+
case "symbol":
|
|
486
|
+
return ZodParsedType.symbol;
|
|
487
|
+
case "object":
|
|
488
|
+
if (Array.isArray(data)) {
|
|
489
|
+
return ZodParsedType.array;
|
|
490
|
+
}
|
|
491
|
+
if (data === null) {
|
|
492
|
+
return ZodParsedType.null;
|
|
493
|
+
}
|
|
494
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
495
|
+
return ZodParsedType.promise;
|
|
496
|
+
}
|
|
497
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
498
|
+
return ZodParsedType.map;
|
|
499
|
+
}
|
|
500
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
501
|
+
return ZodParsedType.set;
|
|
502
|
+
}
|
|
503
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
504
|
+
return ZodParsedType.date;
|
|
505
|
+
}
|
|
506
|
+
return ZodParsedType.object;
|
|
507
|
+
default:
|
|
508
|
+
return ZodParsedType.unknown;
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
var init_util = __esm(() => {
|
|
512
|
+
(function(util2) {
|
|
513
|
+
util2.assertEqual = (_) => {};
|
|
514
|
+
function assertIs(_arg) {}
|
|
515
|
+
util2.assertIs = assertIs;
|
|
516
|
+
function assertNever(_x) {
|
|
517
|
+
throw new Error;
|
|
518
|
+
}
|
|
519
|
+
util2.assertNever = assertNever;
|
|
520
|
+
util2.arrayToEnum = (items) => {
|
|
521
|
+
const obj = {};
|
|
522
|
+
for (const item of items) {
|
|
523
|
+
obj[item] = item;
|
|
524
|
+
}
|
|
525
|
+
return obj;
|
|
526
|
+
};
|
|
527
|
+
util2.getValidEnumValues = (obj) => {
|
|
528
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
529
|
+
const filtered = {};
|
|
530
|
+
for (const k of validKeys) {
|
|
531
|
+
filtered[k] = obj[k];
|
|
532
|
+
}
|
|
533
|
+
return util2.objectValues(filtered);
|
|
534
|
+
};
|
|
535
|
+
util2.objectValues = (obj) => {
|
|
536
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
537
|
+
return obj[e];
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
541
|
+
const keys = [];
|
|
542
|
+
for (const key in object) {
|
|
543
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
544
|
+
keys.push(key);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return keys;
|
|
548
|
+
};
|
|
549
|
+
util2.find = (arr, checker) => {
|
|
550
|
+
for (const item of arr) {
|
|
551
|
+
if (checker(item))
|
|
552
|
+
return item;
|
|
553
|
+
}
|
|
554
|
+
return;
|
|
555
|
+
};
|
|
556
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
557
|
+
function joinValues(array, separator = " | ") {
|
|
558
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
559
|
+
}
|
|
560
|
+
util2.joinValues = joinValues;
|
|
561
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
562
|
+
if (typeof value === "bigint") {
|
|
563
|
+
return value.toString();
|
|
564
|
+
}
|
|
565
|
+
return value;
|
|
566
|
+
};
|
|
567
|
+
})(util || (util = {}));
|
|
568
|
+
(function(objectUtil2) {
|
|
569
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
570
|
+
return {
|
|
571
|
+
...first,
|
|
572
|
+
...second
|
|
573
|
+
};
|
|
574
|
+
};
|
|
575
|
+
})(objectUtil || (objectUtil = {}));
|
|
576
|
+
ZodParsedType = util.arrayToEnum([
|
|
577
|
+
"string",
|
|
578
|
+
"nan",
|
|
579
|
+
"number",
|
|
580
|
+
"integer",
|
|
581
|
+
"float",
|
|
582
|
+
"boolean",
|
|
583
|
+
"date",
|
|
584
|
+
"bigint",
|
|
585
|
+
"symbol",
|
|
586
|
+
"function",
|
|
587
|
+
"undefined",
|
|
588
|
+
"null",
|
|
589
|
+
"array",
|
|
590
|
+
"object",
|
|
591
|
+
"unknown",
|
|
592
|
+
"promise",
|
|
593
|
+
"void",
|
|
594
|
+
"never",
|
|
595
|
+
"map",
|
|
596
|
+
"set"
|
|
597
|
+
]);
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
// ../../node_modules/zod/dist/esm/v3/ZodError.js
|
|
601
|
+
var ZodIssueCode, quotelessJson = (obj) => {
|
|
602
|
+
const json = JSON.stringify(obj, null, 2);
|
|
603
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
604
|
+
}, ZodError;
|
|
605
|
+
var init_ZodError = __esm(() => {
|
|
606
|
+
init_util();
|
|
607
|
+
ZodIssueCode = util.arrayToEnum([
|
|
608
|
+
"invalid_type",
|
|
609
|
+
"invalid_literal",
|
|
610
|
+
"custom",
|
|
611
|
+
"invalid_union",
|
|
612
|
+
"invalid_union_discriminator",
|
|
613
|
+
"invalid_enum_value",
|
|
614
|
+
"unrecognized_keys",
|
|
615
|
+
"invalid_arguments",
|
|
616
|
+
"invalid_return_type",
|
|
617
|
+
"invalid_date",
|
|
618
|
+
"invalid_string",
|
|
619
|
+
"too_small",
|
|
620
|
+
"too_big",
|
|
621
|
+
"invalid_intersection_types",
|
|
622
|
+
"not_multiple_of",
|
|
623
|
+
"not_finite"
|
|
624
|
+
]);
|
|
625
|
+
ZodError = class ZodError extends Error {
|
|
626
|
+
get errors() {
|
|
627
|
+
return this.issues;
|
|
628
|
+
}
|
|
629
|
+
constructor(issues) {
|
|
630
|
+
super();
|
|
631
|
+
this.issues = [];
|
|
632
|
+
this.addIssue = (sub) => {
|
|
633
|
+
this.issues = [...this.issues, sub];
|
|
634
|
+
};
|
|
635
|
+
this.addIssues = (subs = []) => {
|
|
636
|
+
this.issues = [...this.issues, ...subs];
|
|
637
|
+
};
|
|
638
|
+
const actualProto = new.target.prototype;
|
|
639
|
+
if (Object.setPrototypeOf) {
|
|
640
|
+
Object.setPrototypeOf(this, actualProto);
|
|
641
|
+
} else {
|
|
642
|
+
this.__proto__ = actualProto;
|
|
643
|
+
}
|
|
644
|
+
this.name = "ZodError";
|
|
645
|
+
this.issues = issues;
|
|
646
|
+
}
|
|
647
|
+
format(_mapper) {
|
|
648
|
+
const mapper = _mapper || function(issue) {
|
|
649
|
+
return issue.message;
|
|
650
|
+
};
|
|
651
|
+
const fieldErrors = { _errors: [] };
|
|
652
|
+
const processError = (error) => {
|
|
653
|
+
for (const issue of error.issues) {
|
|
654
|
+
if (issue.code === "invalid_union") {
|
|
655
|
+
issue.unionErrors.map(processError);
|
|
656
|
+
} else if (issue.code === "invalid_return_type") {
|
|
657
|
+
processError(issue.returnTypeError);
|
|
658
|
+
} else if (issue.code === "invalid_arguments") {
|
|
659
|
+
processError(issue.argumentsError);
|
|
660
|
+
} else if (issue.path.length === 0) {
|
|
661
|
+
fieldErrors._errors.push(mapper(issue));
|
|
662
|
+
} else {
|
|
663
|
+
let curr = fieldErrors;
|
|
664
|
+
let i = 0;
|
|
665
|
+
while (i < issue.path.length) {
|
|
666
|
+
const el = issue.path[i];
|
|
667
|
+
const terminal = i === issue.path.length - 1;
|
|
668
|
+
if (!terminal) {
|
|
669
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
670
|
+
} else {
|
|
671
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
672
|
+
curr[el]._errors.push(mapper(issue));
|
|
673
|
+
}
|
|
674
|
+
curr = curr[el];
|
|
675
|
+
i++;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
processError(this);
|
|
681
|
+
return fieldErrors;
|
|
682
|
+
}
|
|
683
|
+
static assert(value) {
|
|
684
|
+
if (!(value instanceof ZodError)) {
|
|
685
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
toString() {
|
|
689
|
+
return this.message;
|
|
690
|
+
}
|
|
691
|
+
get message() {
|
|
692
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
693
|
+
}
|
|
694
|
+
get isEmpty() {
|
|
695
|
+
return this.issues.length === 0;
|
|
696
|
+
}
|
|
697
|
+
flatten(mapper = (issue) => issue.message) {
|
|
698
|
+
const fieldErrors = {};
|
|
699
|
+
const formErrors = [];
|
|
700
|
+
for (const sub of this.issues) {
|
|
701
|
+
if (sub.path.length > 0) {
|
|
702
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
703
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
704
|
+
} else {
|
|
705
|
+
formErrors.push(mapper(sub));
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return { formErrors, fieldErrors };
|
|
709
|
+
}
|
|
710
|
+
get formErrors() {
|
|
711
|
+
return this.flatten();
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
ZodError.create = (issues) => {
|
|
715
|
+
const error = new ZodError(issues);
|
|
716
|
+
return error;
|
|
717
|
+
};
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
// ../../node_modules/zod/dist/esm/v3/locales/en.js
|
|
721
|
+
var errorMap = (issue, _ctx) => {
|
|
722
|
+
let message;
|
|
723
|
+
switch (issue.code) {
|
|
724
|
+
case ZodIssueCode.invalid_type:
|
|
725
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
726
|
+
message = "Required";
|
|
727
|
+
} else {
|
|
728
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
729
|
+
}
|
|
730
|
+
break;
|
|
731
|
+
case ZodIssueCode.invalid_literal:
|
|
732
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
733
|
+
break;
|
|
734
|
+
case ZodIssueCode.unrecognized_keys:
|
|
735
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
736
|
+
break;
|
|
737
|
+
case ZodIssueCode.invalid_union:
|
|
738
|
+
message = `Invalid input`;
|
|
739
|
+
break;
|
|
740
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
741
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
742
|
+
break;
|
|
743
|
+
case ZodIssueCode.invalid_enum_value:
|
|
744
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
745
|
+
break;
|
|
746
|
+
case ZodIssueCode.invalid_arguments:
|
|
747
|
+
message = `Invalid function arguments`;
|
|
748
|
+
break;
|
|
749
|
+
case ZodIssueCode.invalid_return_type:
|
|
750
|
+
message = `Invalid function return type`;
|
|
751
|
+
break;
|
|
752
|
+
case ZodIssueCode.invalid_date:
|
|
753
|
+
message = `Invalid date`;
|
|
754
|
+
break;
|
|
755
|
+
case ZodIssueCode.invalid_string:
|
|
756
|
+
if (typeof issue.validation === "object") {
|
|
757
|
+
if ("includes" in issue.validation) {
|
|
758
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
759
|
+
if (typeof issue.validation.position === "number") {
|
|
760
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
761
|
+
}
|
|
762
|
+
} else if ("startsWith" in issue.validation) {
|
|
763
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
764
|
+
} else if ("endsWith" in issue.validation) {
|
|
765
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
766
|
+
} else {
|
|
767
|
+
util.assertNever(issue.validation);
|
|
768
|
+
}
|
|
769
|
+
} else if (issue.validation !== "regex") {
|
|
770
|
+
message = `Invalid ${issue.validation}`;
|
|
771
|
+
} else {
|
|
772
|
+
message = "Invalid";
|
|
773
|
+
}
|
|
774
|
+
break;
|
|
775
|
+
case ZodIssueCode.too_small:
|
|
776
|
+
if (issue.type === "array")
|
|
777
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
778
|
+
else if (issue.type === "string")
|
|
779
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
780
|
+
else if (issue.type === "number")
|
|
781
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
782
|
+
else if (issue.type === "date")
|
|
783
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
784
|
+
else
|
|
785
|
+
message = "Invalid input";
|
|
786
|
+
break;
|
|
787
|
+
case ZodIssueCode.too_big:
|
|
788
|
+
if (issue.type === "array")
|
|
789
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
790
|
+
else if (issue.type === "string")
|
|
791
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
792
|
+
else if (issue.type === "number")
|
|
793
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
794
|
+
else if (issue.type === "bigint")
|
|
795
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
796
|
+
else if (issue.type === "date")
|
|
797
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
798
|
+
else
|
|
799
|
+
message = "Invalid input";
|
|
800
|
+
break;
|
|
801
|
+
case ZodIssueCode.custom:
|
|
802
|
+
message = `Invalid input`;
|
|
803
|
+
break;
|
|
804
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
805
|
+
message = `Intersection results could not be merged`;
|
|
806
|
+
break;
|
|
807
|
+
case ZodIssueCode.not_multiple_of:
|
|
808
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
809
|
+
break;
|
|
810
|
+
case ZodIssueCode.not_finite:
|
|
811
|
+
message = "Number must be finite";
|
|
812
|
+
break;
|
|
813
|
+
default:
|
|
814
|
+
message = _ctx.defaultError;
|
|
815
|
+
util.assertNever(issue);
|
|
816
|
+
}
|
|
817
|
+
return { message };
|
|
818
|
+
}, en_default;
|
|
819
|
+
var init_en = __esm(() => {
|
|
820
|
+
init_ZodError();
|
|
821
|
+
init_util();
|
|
822
|
+
en_default = errorMap;
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// ../../node_modules/zod/dist/esm/v3/errors.js
|
|
826
|
+
function setErrorMap(map) {
|
|
827
|
+
overrideErrorMap = map;
|
|
828
|
+
}
|
|
829
|
+
function getErrorMap() {
|
|
830
|
+
return overrideErrorMap;
|
|
831
|
+
}
|
|
832
|
+
var overrideErrorMap;
|
|
833
|
+
var init_errors2 = __esm(() => {
|
|
834
|
+
init_en();
|
|
835
|
+
overrideErrorMap = en_default;
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
// ../../node_modules/zod/dist/esm/v3/helpers/parseUtil.js
|
|
839
|
+
function addIssueToContext(ctx, issueData) {
|
|
840
|
+
const overrideMap = getErrorMap();
|
|
841
|
+
const issue = makeIssue({
|
|
842
|
+
issueData,
|
|
843
|
+
data: ctx.data,
|
|
844
|
+
path: ctx.path,
|
|
845
|
+
errorMaps: [
|
|
846
|
+
ctx.common.contextualErrorMap,
|
|
847
|
+
ctx.schemaErrorMap,
|
|
848
|
+
overrideMap,
|
|
849
|
+
overrideMap === en_default ? undefined : en_default
|
|
850
|
+
].filter((x) => !!x)
|
|
851
|
+
});
|
|
852
|
+
ctx.common.issues.push(issue);
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
class ParseStatus {
|
|
856
|
+
constructor() {
|
|
857
|
+
this.value = "valid";
|
|
858
|
+
}
|
|
859
|
+
dirty() {
|
|
860
|
+
if (this.value === "valid")
|
|
861
|
+
this.value = "dirty";
|
|
862
|
+
}
|
|
863
|
+
abort() {
|
|
864
|
+
if (this.value !== "aborted")
|
|
865
|
+
this.value = "aborted";
|
|
866
|
+
}
|
|
867
|
+
static mergeArray(status, results) {
|
|
868
|
+
const arrayValue = [];
|
|
869
|
+
for (const s of results) {
|
|
870
|
+
if (s.status === "aborted")
|
|
871
|
+
return INVALID;
|
|
872
|
+
if (s.status === "dirty")
|
|
873
|
+
status.dirty();
|
|
874
|
+
arrayValue.push(s.value);
|
|
875
|
+
}
|
|
876
|
+
return { status: status.value, value: arrayValue };
|
|
877
|
+
}
|
|
878
|
+
static async mergeObjectAsync(status, pairs) {
|
|
879
|
+
const syncPairs = [];
|
|
880
|
+
for (const pair of pairs) {
|
|
881
|
+
const key = await pair.key;
|
|
882
|
+
const value = await pair.value;
|
|
883
|
+
syncPairs.push({
|
|
884
|
+
key,
|
|
885
|
+
value
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
889
|
+
}
|
|
890
|
+
static mergeObjectSync(status, pairs) {
|
|
891
|
+
const finalObject = {};
|
|
892
|
+
for (const pair of pairs) {
|
|
893
|
+
const { key, value } = pair;
|
|
894
|
+
if (key.status === "aborted")
|
|
895
|
+
return INVALID;
|
|
896
|
+
if (value.status === "aborted")
|
|
897
|
+
return INVALID;
|
|
898
|
+
if (key.status === "dirty")
|
|
899
|
+
status.dirty();
|
|
900
|
+
if (value.status === "dirty")
|
|
901
|
+
status.dirty();
|
|
902
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
903
|
+
finalObject[key.value] = value.value;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return { status: status.value, value: finalObject };
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
var makeIssue = (params) => {
|
|
910
|
+
const { data, path, errorMaps, issueData } = params;
|
|
911
|
+
const fullPath = [...path, ...issueData.path || []];
|
|
912
|
+
const fullIssue = {
|
|
913
|
+
...issueData,
|
|
914
|
+
path: fullPath
|
|
915
|
+
};
|
|
916
|
+
if (issueData.message !== undefined) {
|
|
917
|
+
return {
|
|
918
|
+
...issueData,
|
|
919
|
+
path: fullPath,
|
|
920
|
+
message: issueData.message
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
let errorMessage = "";
|
|
924
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
925
|
+
for (const map of maps) {
|
|
926
|
+
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
927
|
+
}
|
|
928
|
+
return {
|
|
929
|
+
...issueData,
|
|
930
|
+
path: fullPath,
|
|
931
|
+
message: errorMessage
|
|
932
|
+
};
|
|
933
|
+
}, EMPTY_PATH, INVALID, DIRTY = (value) => ({ status: "dirty", value }), OK = (value) => ({ status: "valid", value }), isAborted = (x) => x.status === "aborted", isDirty = (x) => x.status === "dirty", isValid = (x) => x.status === "valid", isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
934
|
+
var init_parseUtil = __esm(() => {
|
|
935
|
+
init_errors2();
|
|
936
|
+
init_en();
|
|
937
|
+
EMPTY_PATH = [];
|
|
938
|
+
INVALID = Object.freeze({
|
|
939
|
+
status: "aborted"
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
// ../../node_modules/zod/dist/esm/v3/helpers/typeAliases.js
|
|
944
|
+
var init_typeAliases = () => {};
|
|
945
|
+
|
|
946
|
+
// ../../node_modules/zod/dist/esm/v3/helpers/errorUtil.js
|
|
947
|
+
var errorUtil;
|
|
948
|
+
var init_errorUtil = __esm(() => {
|
|
949
|
+
(function(errorUtil2) {
|
|
950
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
951
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
952
|
+
})(errorUtil || (errorUtil = {}));
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
// ../../node_modules/zod/dist/esm/v3/types.js
|
|
956
|
+
class ParseInputLazyPath {
|
|
957
|
+
constructor(parent, value, path, key) {
|
|
958
|
+
this._cachedPath = [];
|
|
959
|
+
this.parent = parent;
|
|
960
|
+
this.data = value;
|
|
961
|
+
this._path = path;
|
|
962
|
+
this._key = key;
|
|
963
|
+
}
|
|
964
|
+
get path() {
|
|
965
|
+
if (!this._cachedPath.length) {
|
|
966
|
+
if (Array.isArray(this._key)) {
|
|
967
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
968
|
+
} else {
|
|
969
|
+
this._cachedPath.push(...this._path, this._key);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return this._cachedPath;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
function processCreateParams(params) {
|
|
976
|
+
if (!params)
|
|
977
|
+
return {};
|
|
978
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
979
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
980
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
981
|
+
}
|
|
982
|
+
if (errorMap2)
|
|
983
|
+
return { errorMap: errorMap2, description };
|
|
984
|
+
const customMap = (iss, ctx) => {
|
|
985
|
+
const { message } = params;
|
|
986
|
+
if (iss.code === "invalid_enum_value") {
|
|
987
|
+
return { message: message ?? ctx.defaultError };
|
|
988
|
+
}
|
|
989
|
+
if (typeof ctx.data === "undefined") {
|
|
990
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
991
|
+
}
|
|
992
|
+
if (iss.code !== "invalid_type")
|
|
993
|
+
return { message: ctx.defaultError };
|
|
994
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
995
|
+
};
|
|
996
|
+
return { errorMap: customMap, description };
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
class ZodType {
|
|
1000
|
+
get description() {
|
|
1001
|
+
return this._def.description;
|
|
1002
|
+
}
|
|
1003
|
+
_getType(input) {
|
|
1004
|
+
return getParsedType(input.data);
|
|
1005
|
+
}
|
|
1006
|
+
_getOrReturnCtx(input, ctx) {
|
|
1007
|
+
return ctx || {
|
|
1008
|
+
common: input.parent.common,
|
|
1009
|
+
data: input.data,
|
|
1010
|
+
parsedType: getParsedType(input.data),
|
|
1011
|
+
schemaErrorMap: this._def.errorMap,
|
|
1012
|
+
path: input.path,
|
|
1013
|
+
parent: input.parent
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
_processInputParams(input) {
|
|
1017
|
+
return {
|
|
1018
|
+
status: new ParseStatus,
|
|
1019
|
+
ctx: {
|
|
1020
|
+
common: input.parent.common,
|
|
1021
|
+
data: input.data,
|
|
1022
|
+
parsedType: getParsedType(input.data),
|
|
1023
|
+
schemaErrorMap: this._def.errorMap,
|
|
1024
|
+
path: input.path,
|
|
1025
|
+
parent: input.parent
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
_parseSync(input) {
|
|
1030
|
+
const result = this._parse(input);
|
|
1031
|
+
if (isAsync(result)) {
|
|
1032
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
1033
|
+
}
|
|
1034
|
+
return result;
|
|
1035
|
+
}
|
|
1036
|
+
_parseAsync(input) {
|
|
1037
|
+
const result = this._parse(input);
|
|
1038
|
+
return Promise.resolve(result);
|
|
1039
|
+
}
|
|
1040
|
+
parse(data, params) {
|
|
1041
|
+
const result = this.safeParse(data, params);
|
|
1042
|
+
if (result.success)
|
|
1043
|
+
return result.data;
|
|
1044
|
+
throw result.error;
|
|
1045
|
+
}
|
|
1046
|
+
safeParse(data, params) {
|
|
1047
|
+
const ctx = {
|
|
1048
|
+
common: {
|
|
1049
|
+
issues: [],
|
|
1050
|
+
async: params?.async ?? false,
|
|
1051
|
+
contextualErrorMap: params?.errorMap
|
|
1052
|
+
},
|
|
1053
|
+
path: params?.path || [],
|
|
1054
|
+
schemaErrorMap: this._def.errorMap,
|
|
1055
|
+
parent: null,
|
|
1056
|
+
data,
|
|
1057
|
+
parsedType: getParsedType(data)
|
|
1058
|
+
};
|
|
1059
|
+
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
1060
|
+
return handleResult(ctx, result);
|
|
1061
|
+
}
|
|
1062
|
+
"~validate"(data) {
|
|
1063
|
+
const ctx = {
|
|
1064
|
+
common: {
|
|
1065
|
+
issues: [],
|
|
1066
|
+
async: !!this["~standard"].async
|
|
1067
|
+
},
|
|
1068
|
+
path: [],
|
|
1069
|
+
schemaErrorMap: this._def.errorMap,
|
|
1070
|
+
parent: null,
|
|
1071
|
+
data,
|
|
1072
|
+
parsedType: getParsedType(data)
|
|
1073
|
+
};
|
|
1074
|
+
if (!this["~standard"].async) {
|
|
1075
|
+
try {
|
|
1076
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
1077
|
+
return isValid(result) ? {
|
|
1078
|
+
value: result.value
|
|
1079
|
+
} : {
|
|
1080
|
+
issues: ctx.common.issues
|
|
1081
|
+
};
|
|
1082
|
+
} catch (err) {
|
|
1083
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
1084
|
+
this["~standard"].async = true;
|
|
1085
|
+
}
|
|
1086
|
+
ctx.common = {
|
|
1087
|
+
issues: [],
|
|
1088
|
+
async: true
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
1093
|
+
value: result.value
|
|
1094
|
+
} : {
|
|
1095
|
+
issues: ctx.common.issues
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
async parseAsync(data, params) {
|
|
1099
|
+
const result = await this.safeParseAsync(data, params);
|
|
1100
|
+
if (result.success)
|
|
1101
|
+
return result.data;
|
|
1102
|
+
throw result.error;
|
|
1103
|
+
}
|
|
1104
|
+
async safeParseAsync(data, params) {
|
|
1105
|
+
const ctx = {
|
|
1106
|
+
common: {
|
|
1107
|
+
issues: [],
|
|
1108
|
+
contextualErrorMap: params?.errorMap,
|
|
1109
|
+
async: true
|
|
1110
|
+
},
|
|
1111
|
+
path: params?.path || [],
|
|
1112
|
+
schemaErrorMap: this._def.errorMap,
|
|
1113
|
+
parent: null,
|
|
1114
|
+
data,
|
|
1115
|
+
parsedType: getParsedType(data)
|
|
1116
|
+
};
|
|
1117
|
+
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
1118
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
1119
|
+
return handleResult(ctx, result);
|
|
1120
|
+
}
|
|
1121
|
+
refine(check, message) {
|
|
1122
|
+
const getIssueProperties = (val) => {
|
|
1123
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
1124
|
+
return { message };
|
|
1125
|
+
} else if (typeof message === "function") {
|
|
1126
|
+
return message(val);
|
|
1127
|
+
} else {
|
|
1128
|
+
return message;
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
return this._refinement((val, ctx) => {
|
|
1132
|
+
const result = check(val);
|
|
1133
|
+
const setError = () => ctx.addIssue({
|
|
1134
|
+
code: ZodIssueCode.custom,
|
|
1135
|
+
...getIssueProperties(val)
|
|
1136
|
+
});
|
|
1137
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
1138
|
+
return result.then((data) => {
|
|
1139
|
+
if (!data) {
|
|
1140
|
+
setError();
|
|
1141
|
+
return false;
|
|
1142
|
+
} else {
|
|
1143
|
+
return true;
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
if (!result) {
|
|
1148
|
+
setError();
|
|
1149
|
+
return false;
|
|
1150
|
+
} else {
|
|
1151
|
+
return true;
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
}
|
|
1155
|
+
refinement(check, refinementData) {
|
|
1156
|
+
return this._refinement((val, ctx) => {
|
|
1157
|
+
if (!check(val)) {
|
|
1158
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
1159
|
+
return false;
|
|
1160
|
+
} else {
|
|
1161
|
+
return true;
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
_refinement(refinement) {
|
|
1166
|
+
return new ZodEffects({
|
|
1167
|
+
schema: this,
|
|
1168
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1169
|
+
effect: { type: "refinement", refinement }
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
superRefine(refinement) {
|
|
1173
|
+
return this._refinement(refinement);
|
|
1174
|
+
}
|
|
1175
|
+
constructor(def) {
|
|
1176
|
+
this.spa = this.safeParseAsync;
|
|
1177
|
+
this._def = def;
|
|
1178
|
+
this.parse = this.parse.bind(this);
|
|
1179
|
+
this.safeParse = this.safeParse.bind(this);
|
|
1180
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
1181
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
1182
|
+
this.spa = this.spa.bind(this);
|
|
1183
|
+
this.refine = this.refine.bind(this);
|
|
1184
|
+
this.refinement = this.refinement.bind(this);
|
|
1185
|
+
this.superRefine = this.superRefine.bind(this);
|
|
1186
|
+
this.optional = this.optional.bind(this);
|
|
1187
|
+
this.nullable = this.nullable.bind(this);
|
|
1188
|
+
this.nullish = this.nullish.bind(this);
|
|
1189
|
+
this.array = this.array.bind(this);
|
|
1190
|
+
this.promise = this.promise.bind(this);
|
|
1191
|
+
this.or = this.or.bind(this);
|
|
1192
|
+
this.and = this.and.bind(this);
|
|
1193
|
+
this.transform = this.transform.bind(this);
|
|
1194
|
+
this.brand = this.brand.bind(this);
|
|
1195
|
+
this.default = this.default.bind(this);
|
|
1196
|
+
this.catch = this.catch.bind(this);
|
|
1197
|
+
this.describe = this.describe.bind(this);
|
|
1198
|
+
this.pipe = this.pipe.bind(this);
|
|
1199
|
+
this.readonly = this.readonly.bind(this);
|
|
1200
|
+
this.isNullable = this.isNullable.bind(this);
|
|
1201
|
+
this.isOptional = this.isOptional.bind(this);
|
|
1202
|
+
this["~standard"] = {
|
|
1203
|
+
version: 1,
|
|
1204
|
+
vendor: "zod",
|
|
1205
|
+
validate: (data) => this["~validate"](data)
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
optional() {
|
|
1209
|
+
return ZodOptional.create(this, this._def);
|
|
1210
|
+
}
|
|
1211
|
+
nullable() {
|
|
1212
|
+
return ZodNullable.create(this, this._def);
|
|
1213
|
+
}
|
|
1214
|
+
nullish() {
|
|
1215
|
+
return this.nullable().optional();
|
|
1216
|
+
}
|
|
1217
|
+
array() {
|
|
1218
|
+
return ZodArray.create(this);
|
|
1219
|
+
}
|
|
1220
|
+
promise() {
|
|
1221
|
+
return ZodPromise.create(this, this._def);
|
|
1222
|
+
}
|
|
1223
|
+
or(option) {
|
|
1224
|
+
return ZodUnion.create([this, option], this._def);
|
|
1225
|
+
}
|
|
1226
|
+
and(incoming) {
|
|
1227
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
1228
|
+
}
|
|
1229
|
+
transform(transform) {
|
|
1230
|
+
return new ZodEffects({
|
|
1231
|
+
...processCreateParams(this._def),
|
|
1232
|
+
schema: this,
|
|
1233
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1234
|
+
effect: { type: "transform", transform }
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
default(def) {
|
|
1238
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1239
|
+
return new ZodDefault({
|
|
1240
|
+
...processCreateParams(this._def),
|
|
1241
|
+
innerType: this,
|
|
1242
|
+
defaultValue: defaultValueFunc,
|
|
1243
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
brand() {
|
|
1247
|
+
return new ZodBranded({
|
|
1248
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1249
|
+
type: this,
|
|
1250
|
+
...processCreateParams(this._def)
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
catch(def) {
|
|
1254
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1255
|
+
return new ZodCatch({
|
|
1256
|
+
...processCreateParams(this._def),
|
|
1257
|
+
innerType: this,
|
|
1258
|
+
catchValue: catchValueFunc,
|
|
1259
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
describe(description) {
|
|
1263
|
+
const This = this.constructor;
|
|
1264
|
+
return new This({
|
|
1265
|
+
...this._def,
|
|
1266
|
+
description
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
pipe(target) {
|
|
1270
|
+
return ZodPipeline.create(this, target);
|
|
1271
|
+
}
|
|
1272
|
+
readonly() {
|
|
1273
|
+
return ZodReadonly.create(this);
|
|
1274
|
+
}
|
|
1275
|
+
isOptional() {
|
|
1276
|
+
return this.safeParse(undefined).success;
|
|
1277
|
+
}
|
|
1278
|
+
isNullable() {
|
|
1279
|
+
return this.safeParse(null).success;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
function timeRegexSource(args) {
|
|
1283
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1284
|
+
if (args.precision) {
|
|
1285
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1286
|
+
} else if (args.precision == null) {
|
|
1287
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1288
|
+
}
|
|
1289
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1290
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1291
|
+
}
|
|
1292
|
+
function timeRegex(args) {
|
|
1293
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1294
|
+
}
|
|
1295
|
+
function datetimeRegex(args) {
|
|
1296
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1297
|
+
const opts = [];
|
|
1298
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1299
|
+
if (args.offset)
|
|
1300
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1301
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1302
|
+
return new RegExp(`^${regex}$`);
|
|
1303
|
+
}
|
|
1304
|
+
function isValidIP(ip, version) {
|
|
1305
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1309
|
+
return true;
|
|
1310
|
+
}
|
|
1311
|
+
return false;
|
|
1312
|
+
}
|
|
1313
|
+
function isValidJWT(jwt, alg) {
|
|
1314
|
+
if (!jwtRegex.test(jwt))
|
|
1315
|
+
return false;
|
|
1316
|
+
try {
|
|
1317
|
+
const [header] = jwt.split(".");
|
|
1318
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1319
|
+
const decoded = JSON.parse(atob(base64));
|
|
1320
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1321
|
+
return false;
|
|
1322
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1323
|
+
return false;
|
|
1324
|
+
if (!decoded.alg)
|
|
1325
|
+
return false;
|
|
1326
|
+
if (alg && decoded.alg !== alg)
|
|
1327
|
+
return false;
|
|
1328
|
+
return true;
|
|
1329
|
+
} catch {
|
|
1330
|
+
return false;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
function isValidCidr(ip, version) {
|
|
1334
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1335
|
+
return true;
|
|
1336
|
+
}
|
|
1337
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
return false;
|
|
1341
|
+
}
|
|
1342
|
+
function floatSafeRemainder(val, step) {
|
|
1343
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1344
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1345
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1346
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1347
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1348
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1349
|
+
}
|
|
1350
|
+
function deepPartialify(schema) {
|
|
1351
|
+
if (schema instanceof ZodObject) {
|
|
1352
|
+
const newShape = {};
|
|
1353
|
+
for (const key in schema.shape) {
|
|
1354
|
+
const fieldSchema = schema.shape[key];
|
|
1355
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
1356
|
+
}
|
|
1357
|
+
return new ZodObject({
|
|
1358
|
+
...schema._def,
|
|
1359
|
+
shape: () => newShape
|
|
1360
|
+
});
|
|
1361
|
+
} else if (schema instanceof ZodArray) {
|
|
1362
|
+
return new ZodArray({
|
|
1363
|
+
...schema._def,
|
|
1364
|
+
type: deepPartialify(schema.element)
|
|
1365
|
+
});
|
|
1366
|
+
} else if (schema instanceof ZodOptional) {
|
|
1367
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
1368
|
+
} else if (schema instanceof ZodNullable) {
|
|
1369
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
1370
|
+
} else if (schema instanceof ZodTuple) {
|
|
1371
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
1372
|
+
} else {
|
|
1373
|
+
return schema;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
function mergeValues(a, b) {
|
|
1377
|
+
const aType = getParsedType(a);
|
|
1378
|
+
const bType = getParsedType(b);
|
|
1379
|
+
if (a === b) {
|
|
1380
|
+
return { valid: true, data: a };
|
|
1381
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
1382
|
+
const bKeys = util.objectKeys(b);
|
|
1383
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
1384
|
+
const newObj = { ...a, ...b };
|
|
1385
|
+
for (const key of sharedKeys) {
|
|
1386
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
1387
|
+
if (!sharedValue.valid) {
|
|
1388
|
+
return { valid: false };
|
|
1389
|
+
}
|
|
1390
|
+
newObj[key] = sharedValue.data;
|
|
1391
|
+
}
|
|
1392
|
+
return { valid: true, data: newObj };
|
|
1393
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
1394
|
+
if (a.length !== b.length) {
|
|
1395
|
+
return { valid: false };
|
|
1396
|
+
}
|
|
1397
|
+
const newArray = [];
|
|
1398
|
+
for (let index = 0;index < a.length; index++) {
|
|
1399
|
+
const itemA = a[index];
|
|
1400
|
+
const itemB = b[index];
|
|
1401
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
1402
|
+
if (!sharedValue.valid) {
|
|
1403
|
+
return { valid: false };
|
|
1404
|
+
}
|
|
1405
|
+
newArray.push(sharedValue.data);
|
|
1406
|
+
}
|
|
1407
|
+
return { valid: true, data: newArray };
|
|
1408
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
1409
|
+
return { valid: true, data: a };
|
|
1410
|
+
} else {
|
|
1411
|
+
return { valid: false };
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
function createZodEnum(values, params) {
|
|
1415
|
+
return new ZodEnum({
|
|
1416
|
+
values,
|
|
1417
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
1418
|
+
...processCreateParams(params)
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
function cleanParams(params, data) {
|
|
1422
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
1423
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
1424
|
+
return p2;
|
|
1425
|
+
}
|
|
1426
|
+
function custom(check, _params = {}, fatal) {
|
|
1427
|
+
if (check)
|
|
1428
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
1429
|
+
const r = check(data);
|
|
1430
|
+
if (r instanceof Promise) {
|
|
1431
|
+
return r.then((r2) => {
|
|
1432
|
+
if (!r2) {
|
|
1433
|
+
const params = cleanParams(_params, data);
|
|
1434
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
1435
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
if (!r) {
|
|
1440
|
+
const params = cleanParams(_params, data);
|
|
1441
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
1442
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
1443
|
+
}
|
|
1444
|
+
return;
|
|
1445
|
+
});
|
|
1446
|
+
return ZodAny.create();
|
|
1447
|
+
}
|
|
1448
|
+
var __classPrivateFieldGet = function(receiver, state, kind, f) {
|
|
1449
|
+
if (kind === "a" && !f)
|
|
1450
|
+
throw new TypeError("Private accessor was defined without a getter");
|
|
1451
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1452
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1453
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1454
|
+
}, __classPrivateFieldSet = function(receiver, state, value, kind, f) {
|
|
1455
|
+
if (kind === "m")
|
|
1456
|
+
throw new TypeError("Private method is not writable");
|
|
1457
|
+
if (kind === "a" && !f)
|
|
1458
|
+
throw new TypeError("Private accessor was defined without a setter");
|
|
1459
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
|
1460
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1461
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1462
|
+
}, _ZodEnum_cache, _ZodNativeEnum_cache, handleResult = (ctx, result) => {
|
|
1463
|
+
if (isValid(result)) {
|
|
1464
|
+
return { success: true, data: result.value };
|
|
1465
|
+
} else {
|
|
1466
|
+
if (!ctx.common.issues.length) {
|
|
1467
|
+
throw new Error("Validation failed but no issues detected.");
|
|
1468
|
+
}
|
|
1469
|
+
return {
|
|
1470
|
+
success: false,
|
|
1471
|
+
get error() {
|
|
1472
|
+
if (this._error)
|
|
1473
|
+
return this._error;
|
|
1474
|
+
const error = new ZodError(ctx.common.issues);
|
|
1475
|
+
this._error = error;
|
|
1476
|
+
return this._error;
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
}
|
|
1480
|
+
}, cuidRegex, cuid2Regex, ulidRegex, uuidRegex, nanoidRegex, jwtRegex, durationRegex, emailRegex, _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`, emojiRegex, ipv4Regex, ipv4CidrRegex, ipv6Regex, ipv6CidrRegex, base64Regex, base64urlRegex, 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])))`, dateRegex, ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodSymbol, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodVoid, ZodArray, ZodObject, ZodUnion, getDiscriminator = (type) => {
|
|
1481
|
+
if (type instanceof ZodLazy) {
|
|
1482
|
+
return getDiscriminator(type.schema);
|
|
1483
|
+
} else if (type instanceof ZodEffects) {
|
|
1484
|
+
return getDiscriminator(type.innerType());
|
|
1485
|
+
} else if (type instanceof ZodLiteral) {
|
|
1486
|
+
return [type.value];
|
|
1487
|
+
} else if (type instanceof ZodEnum) {
|
|
1488
|
+
return type.options;
|
|
1489
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
1490
|
+
return util.objectValues(type.enum);
|
|
1491
|
+
} else if (type instanceof ZodDefault) {
|
|
1492
|
+
return getDiscriminator(type._def.innerType);
|
|
1493
|
+
} else if (type instanceof ZodUndefined) {
|
|
1494
|
+
return [undefined];
|
|
1495
|
+
} else if (type instanceof ZodNull) {
|
|
1496
|
+
return [null];
|
|
1497
|
+
} else if (type instanceof ZodOptional) {
|
|
1498
|
+
return [undefined, ...getDiscriminator(type.unwrap())];
|
|
1499
|
+
} else if (type instanceof ZodNullable) {
|
|
1500
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
|
1501
|
+
} else if (type instanceof ZodBranded) {
|
|
1502
|
+
return getDiscriminator(type.unwrap());
|
|
1503
|
+
} else if (type instanceof ZodReadonly) {
|
|
1504
|
+
return getDiscriminator(type.unwrap());
|
|
1505
|
+
} else if (type instanceof ZodCatch) {
|
|
1506
|
+
return getDiscriminator(type._def.innerType);
|
|
1507
|
+
} else {
|
|
1508
|
+
return [];
|
|
1509
|
+
}
|
|
1510
|
+
}, 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 = (cls, params = {
|
|
1511
|
+
message: `Input not instance of ${cls.name}`
|
|
1512
|
+
}) => custom((data) => data instanceof cls, params), 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 = () => stringType().optional(), onumber = () => numberType().optional(), oboolean = () => booleanType().optional(), coerce, NEVER;
|
|
1513
|
+
var init_types = __esm(() => {
|
|
1514
|
+
init_ZodError();
|
|
1515
|
+
init_errors2();
|
|
1516
|
+
init_errorUtil();
|
|
1517
|
+
init_parseUtil();
|
|
1518
|
+
init_util();
|
|
1519
|
+
cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1520
|
+
cuid2Regex = /^[0-9a-z]+$/;
|
|
1521
|
+
ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1522
|
+
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;
|
|
1523
|
+
nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1524
|
+
jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1525
|
+
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)?)??$/;
|
|
1526
|
+
emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1527
|
+
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])$/;
|
|
1528
|
+
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])$/;
|
|
1529
|
+
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]))$/;
|
|
1530
|
+
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])$/;
|
|
1531
|
+
base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1532
|
+
base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1533
|
+
dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1534
|
+
ZodString = class ZodString extends ZodType {
|
|
1535
|
+
_parse(input) {
|
|
1536
|
+
if (this._def.coerce) {
|
|
1537
|
+
input.data = String(input.data);
|
|
1538
|
+
}
|
|
1539
|
+
const parsedType = this._getType(input);
|
|
1540
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1541
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1542
|
+
addIssueToContext(ctx2, {
|
|
1543
|
+
code: ZodIssueCode.invalid_type,
|
|
1544
|
+
expected: ZodParsedType.string,
|
|
1545
|
+
received: ctx2.parsedType
|
|
1546
|
+
});
|
|
1547
|
+
return INVALID;
|
|
1548
|
+
}
|
|
1549
|
+
const status = new ParseStatus;
|
|
1550
|
+
let ctx = undefined;
|
|
1551
|
+
for (const check of this._def.checks) {
|
|
1552
|
+
if (check.kind === "min") {
|
|
1553
|
+
if (input.data.length < check.value) {
|
|
1554
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1555
|
+
addIssueToContext(ctx, {
|
|
1556
|
+
code: ZodIssueCode.too_small,
|
|
1557
|
+
minimum: check.value,
|
|
1558
|
+
type: "string",
|
|
1559
|
+
inclusive: true,
|
|
1560
|
+
exact: false,
|
|
1561
|
+
message: check.message
|
|
1562
|
+
});
|
|
1563
|
+
status.dirty();
|
|
1564
|
+
}
|
|
1565
|
+
} else if (check.kind === "max") {
|
|
1566
|
+
if (input.data.length > check.value) {
|
|
1567
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1568
|
+
addIssueToContext(ctx, {
|
|
1569
|
+
code: ZodIssueCode.too_big,
|
|
1570
|
+
maximum: check.value,
|
|
1571
|
+
type: "string",
|
|
1572
|
+
inclusive: true,
|
|
1573
|
+
exact: false,
|
|
1574
|
+
message: check.message
|
|
1575
|
+
});
|
|
1576
|
+
status.dirty();
|
|
1577
|
+
}
|
|
1578
|
+
} else if (check.kind === "length") {
|
|
1579
|
+
const tooBig = input.data.length > check.value;
|
|
1580
|
+
const tooSmall = input.data.length < check.value;
|
|
1581
|
+
if (tooBig || tooSmall) {
|
|
1582
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1583
|
+
if (tooBig) {
|
|
1584
|
+
addIssueToContext(ctx, {
|
|
1585
|
+
code: ZodIssueCode.too_big,
|
|
1586
|
+
maximum: check.value,
|
|
1587
|
+
type: "string",
|
|
1588
|
+
inclusive: true,
|
|
1589
|
+
exact: true,
|
|
1590
|
+
message: check.message
|
|
1591
|
+
});
|
|
1592
|
+
} else if (tooSmall) {
|
|
1593
|
+
addIssueToContext(ctx, {
|
|
1594
|
+
code: ZodIssueCode.too_small,
|
|
1595
|
+
minimum: check.value,
|
|
1596
|
+
type: "string",
|
|
1597
|
+
inclusive: true,
|
|
1598
|
+
exact: true,
|
|
1599
|
+
message: check.message
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
status.dirty();
|
|
1603
|
+
}
|
|
1604
|
+
} else if (check.kind === "email") {
|
|
1605
|
+
if (!emailRegex.test(input.data)) {
|
|
1606
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1607
|
+
addIssueToContext(ctx, {
|
|
1608
|
+
validation: "email",
|
|
1609
|
+
code: ZodIssueCode.invalid_string,
|
|
1610
|
+
message: check.message
|
|
1611
|
+
});
|
|
1612
|
+
status.dirty();
|
|
1613
|
+
}
|
|
1614
|
+
} else if (check.kind === "emoji") {
|
|
1615
|
+
if (!emojiRegex) {
|
|
1616
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1617
|
+
}
|
|
1618
|
+
if (!emojiRegex.test(input.data)) {
|
|
1619
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1620
|
+
addIssueToContext(ctx, {
|
|
1621
|
+
validation: "emoji",
|
|
1622
|
+
code: ZodIssueCode.invalid_string,
|
|
1623
|
+
message: check.message
|
|
1624
|
+
});
|
|
1625
|
+
status.dirty();
|
|
1626
|
+
}
|
|
1627
|
+
} else if (check.kind === "uuid") {
|
|
1628
|
+
if (!uuidRegex.test(input.data)) {
|
|
1629
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1630
|
+
addIssueToContext(ctx, {
|
|
1631
|
+
validation: "uuid",
|
|
1632
|
+
code: ZodIssueCode.invalid_string,
|
|
1633
|
+
message: check.message
|
|
1634
|
+
});
|
|
1635
|
+
status.dirty();
|
|
1636
|
+
}
|
|
1637
|
+
} else if (check.kind === "nanoid") {
|
|
1638
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1639
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1640
|
+
addIssueToContext(ctx, {
|
|
1641
|
+
validation: "nanoid",
|
|
1642
|
+
code: ZodIssueCode.invalid_string,
|
|
1643
|
+
message: check.message
|
|
1644
|
+
});
|
|
1645
|
+
status.dirty();
|
|
1646
|
+
}
|
|
1647
|
+
} else if (check.kind === "cuid") {
|
|
1648
|
+
if (!cuidRegex.test(input.data)) {
|
|
1649
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1650
|
+
addIssueToContext(ctx, {
|
|
1651
|
+
validation: "cuid",
|
|
1652
|
+
code: ZodIssueCode.invalid_string,
|
|
1653
|
+
message: check.message
|
|
1654
|
+
});
|
|
1655
|
+
status.dirty();
|
|
1656
|
+
}
|
|
1657
|
+
} else if (check.kind === "cuid2") {
|
|
1658
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1659
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1660
|
+
addIssueToContext(ctx, {
|
|
1661
|
+
validation: "cuid2",
|
|
1662
|
+
code: ZodIssueCode.invalid_string,
|
|
1663
|
+
message: check.message
|
|
1664
|
+
});
|
|
1665
|
+
status.dirty();
|
|
1666
|
+
}
|
|
1667
|
+
} else if (check.kind === "ulid") {
|
|
1668
|
+
if (!ulidRegex.test(input.data)) {
|
|
1669
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1670
|
+
addIssueToContext(ctx, {
|
|
1671
|
+
validation: "ulid",
|
|
1672
|
+
code: ZodIssueCode.invalid_string,
|
|
1673
|
+
message: check.message
|
|
1674
|
+
});
|
|
1675
|
+
status.dirty();
|
|
1676
|
+
}
|
|
1677
|
+
} else if (check.kind === "url") {
|
|
1678
|
+
try {
|
|
1679
|
+
new URL(input.data);
|
|
1680
|
+
} catch {
|
|
1681
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1682
|
+
addIssueToContext(ctx, {
|
|
1683
|
+
validation: "url",
|
|
1684
|
+
code: ZodIssueCode.invalid_string,
|
|
1685
|
+
message: check.message
|
|
1686
|
+
});
|
|
1687
|
+
status.dirty();
|
|
1688
|
+
}
|
|
1689
|
+
} else if (check.kind === "regex") {
|
|
1690
|
+
check.regex.lastIndex = 0;
|
|
1691
|
+
const testResult = check.regex.test(input.data);
|
|
1692
|
+
if (!testResult) {
|
|
1693
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1694
|
+
addIssueToContext(ctx, {
|
|
1695
|
+
validation: "regex",
|
|
1696
|
+
code: ZodIssueCode.invalid_string,
|
|
1697
|
+
message: check.message
|
|
1698
|
+
});
|
|
1699
|
+
status.dirty();
|
|
1700
|
+
}
|
|
1701
|
+
} else if (check.kind === "trim") {
|
|
1702
|
+
input.data = input.data.trim();
|
|
1703
|
+
} else if (check.kind === "includes") {
|
|
1704
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1705
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1706
|
+
addIssueToContext(ctx, {
|
|
1707
|
+
code: ZodIssueCode.invalid_string,
|
|
1708
|
+
validation: { includes: check.value, position: check.position },
|
|
1709
|
+
message: check.message
|
|
1710
|
+
});
|
|
1711
|
+
status.dirty();
|
|
1712
|
+
}
|
|
1713
|
+
} else if (check.kind === "toLowerCase") {
|
|
1714
|
+
input.data = input.data.toLowerCase();
|
|
1715
|
+
} else if (check.kind === "toUpperCase") {
|
|
1716
|
+
input.data = input.data.toUpperCase();
|
|
1717
|
+
} else if (check.kind === "startsWith") {
|
|
1718
|
+
if (!input.data.startsWith(check.value)) {
|
|
1719
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1720
|
+
addIssueToContext(ctx, {
|
|
1721
|
+
code: ZodIssueCode.invalid_string,
|
|
1722
|
+
validation: { startsWith: check.value },
|
|
1723
|
+
message: check.message
|
|
1724
|
+
});
|
|
1725
|
+
status.dirty();
|
|
1726
|
+
}
|
|
1727
|
+
} else if (check.kind === "endsWith") {
|
|
1728
|
+
if (!input.data.endsWith(check.value)) {
|
|
1729
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1730
|
+
addIssueToContext(ctx, {
|
|
1731
|
+
code: ZodIssueCode.invalid_string,
|
|
1732
|
+
validation: { endsWith: check.value },
|
|
1733
|
+
message: check.message
|
|
1734
|
+
});
|
|
1735
|
+
status.dirty();
|
|
1736
|
+
}
|
|
1737
|
+
} else if (check.kind === "datetime") {
|
|
1738
|
+
const regex = datetimeRegex(check);
|
|
1739
|
+
if (!regex.test(input.data)) {
|
|
1740
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1741
|
+
addIssueToContext(ctx, {
|
|
1742
|
+
code: ZodIssueCode.invalid_string,
|
|
1743
|
+
validation: "datetime",
|
|
1744
|
+
message: check.message
|
|
1745
|
+
});
|
|
1746
|
+
status.dirty();
|
|
1747
|
+
}
|
|
1748
|
+
} else if (check.kind === "date") {
|
|
1749
|
+
const regex = dateRegex;
|
|
1750
|
+
if (!regex.test(input.data)) {
|
|
1751
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1752
|
+
addIssueToContext(ctx, {
|
|
1753
|
+
code: ZodIssueCode.invalid_string,
|
|
1754
|
+
validation: "date",
|
|
1755
|
+
message: check.message
|
|
1756
|
+
});
|
|
1757
|
+
status.dirty();
|
|
1758
|
+
}
|
|
1759
|
+
} else if (check.kind === "time") {
|
|
1760
|
+
const regex = timeRegex(check);
|
|
1761
|
+
if (!regex.test(input.data)) {
|
|
1762
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1763
|
+
addIssueToContext(ctx, {
|
|
1764
|
+
code: ZodIssueCode.invalid_string,
|
|
1765
|
+
validation: "time",
|
|
1766
|
+
message: check.message
|
|
1767
|
+
});
|
|
1768
|
+
status.dirty();
|
|
1769
|
+
}
|
|
1770
|
+
} else if (check.kind === "duration") {
|
|
1771
|
+
if (!durationRegex.test(input.data)) {
|
|
1772
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1773
|
+
addIssueToContext(ctx, {
|
|
1774
|
+
validation: "duration",
|
|
1775
|
+
code: ZodIssueCode.invalid_string,
|
|
1776
|
+
message: check.message
|
|
1777
|
+
});
|
|
1778
|
+
status.dirty();
|
|
1779
|
+
}
|
|
1780
|
+
} else if (check.kind === "ip") {
|
|
1781
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1782
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1783
|
+
addIssueToContext(ctx, {
|
|
1784
|
+
validation: "ip",
|
|
1785
|
+
code: ZodIssueCode.invalid_string,
|
|
1786
|
+
message: check.message
|
|
1787
|
+
});
|
|
1788
|
+
status.dirty();
|
|
1789
|
+
}
|
|
1790
|
+
} else if (check.kind === "jwt") {
|
|
1791
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1792
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1793
|
+
addIssueToContext(ctx, {
|
|
1794
|
+
validation: "jwt",
|
|
1795
|
+
code: ZodIssueCode.invalid_string,
|
|
1796
|
+
message: check.message
|
|
1797
|
+
});
|
|
1798
|
+
status.dirty();
|
|
1799
|
+
}
|
|
1800
|
+
} else if (check.kind === "cidr") {
|
|
1801
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1802
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1803
|
+
addIssueToContext(ctx, {
|
|
1804
|
+
validation: "cidr",
|
|
1805
|
+
code: ZodIssueCode.invalid_string,
|
|
1806
|
+
message: check.message
|
|
1807
|
+
});
|
|
1808
|
+
status.dirty();
|
|
1809
|
+
}
|
|
1810
|
+
} else if (check.kind === "base64") {
|
|
1811
|
+
if (!base64Regex.test(input.data)) {
|
|
1812
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1813
|
+
addIssueToContext(ctx, {
|
|
1814
|
+
validation: "base64",
|
|
1815
|
+
code: ZodIssueCode.invalid_string,
|
|
1816
|
+
message: check.message
|
|
1817
|
+
});
|
|
1818
|
+
status.dirty();
|
|
1819
|
+
}
|
|
1820
|
+
} else if (check.kind === "base64url") {
|
|
1821
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1822
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1823
|
+
addIssueToContext(ctx, {
|
|
1824
|
+
validation: "base64url",
|
|
1825
|
+
code: ZodIssueCode.invalid_string,
|
|
1826
|
+
message: check.message
|
|
1827
|
+
});
|
|
1828
|
+
status.dirty();
|
|
1829
|
+
}
|
|
1830
|
+
} else {
|
|
1831
|
+
util.assertNever(check);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
return { status: status.value, value: input.data };
|
|
1835
|
+
}
|
|
1836
|
+
_regex(regex, validation, message) {
|
|
1837
|
+
return this.refinement((data) => regex.test(data), {
|
|
1838
|
+
validation,
|
|
1839
|
+
code: ZodIssueCode.invalid_string,
|
|
1840
|
+
...errorUtil.errToObj(message)
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
_addCheck(check) {
|
|
1844
|
+
return new ZodString({
|
|
1845
|
+
...this._def,
|
|
1846
|
+
checks: [...this._def.checks, check]
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
email(message) {
|
|
1850
|
+
return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
|
|
1851
|
+
}
|
|
1852
|
+
url(message) {
|
|
1853
|
+
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
|
1854
|
+
}
|
|
1855
|
+
emoji(message) {
|
|
1856
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
|
1857
|
+
}
|
|
1858
|
+
uuid(message) {
|
|
1859
|
+
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
|
1860
|
+
}
|
|
1861
|
+
nanoid(message) {
|
|
1862
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
|
1863
|
+
}
|
|
1864
|
+
cuid(message) {
|
|
1865
|
+
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
|
1866
|
+
}
|
|
1867
|
+
cuid2(message) {
|
|
1868
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
|
1869
|
+
}
|
|
1870
|
+
ulid(message) {
|
|
1871
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
|
1872
|
+
}
|
|
1873
|
+
base64(message) {
|
|
1874
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1875
|
+
}
|
|
1876
|
+
base64url(message) {
|
|
1877
|
+
return this._addCheck({
|
|
1878
|
+
kind: "base64url",
|
|
1879
|
+
...errorUtil.errToObj(message)
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
jwt(options) {
|
|
1883
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1884
|
+
}
|
|
1885
|
+
ip(options) {
|
|
1886
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1887
|
+
}
|
|
1888
|
+
cidr(options) {
|
|
1889
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1890
|
+
}
|
|
1891
|
+
datetime(options) {
|
|
1892
|
+
if (typeof options === "string") {
|
|
1893
|
+
return this._addCheck({
|
|
1894
|
+
kind: "datetime",
|
|
1895
|
+
precision: null,
|
|
1896
|
+
offset: false,
|
|
1897
|
+
local: false,
|
|
1898
|
+
message: options
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
return this._addCheck({
|
|
1902
|
+
kind: "datetime",
|
|
1903
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1904
|
+
offset: options?.offset ?? false,
|
|
1905
|
+
local: options?.local ?? false,
|
|
1906
|
+
...errorUtil.errToObj(options?.message)
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
date(message) {
|
|
1910
|
+
return this._addCheck({ kind: "date", message });
|
|
1911
|
+
}
|
|
1912
|
+
time(options) {
|
|
1913
|
+
if (typeof options === "string") {
|
|
1914
|
+
return this._addCheck({
|
|
1915
|
+
kind: "time",
|
|
1916
|
+
precision: null,
|
|
1917
|
+
message: options
|
|
1918
|
+
});
|
|
1919
|
+
}
|
|
1920
|
+
return this._addCheck({
|
|
1921
|
+
kind: "time",
|
|
1922
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1923
|
+
...errorUtil.errToObj(options?.message)
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
duration(message) {
|
|
1927
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
|
1928
|
+
}
|
|
1929
|
+
regex(regex, message) {
|
|
1930
|
+
return this._addCheck({
|
|
1931
|
+
kind: "regex",
|
|
1932
|
+
regex,
|
|
1933
|
+
...errorUtil.errToObj(message)
|
|
1934
|
+
});
|
|
1935
|
+
}
|
|
1936
|
+
includes(value, options) {
|
|
1937
|
+
return this._addCheck({
|
|
1938
|
+
kind: "includes",
|
|
1939
|
+
value,
|
|
1940
|
+
position: options?.position,
|
|
1941
|
+
...errorUtil.errToObj(options?.message)
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
startsWith(value, message) {
|
|
1945
|
+
return this._addCheck({
|
|
1946
|
+
kind: "startsWith",
|
|
1947
|
+
value,
|
|
1948
|
+
...errorUtil.errToObj(message)
|
|
1949
|
+
});
|
|
1950
|
+
}
|
|
1951
|
+
endsWith(value, message) {
|
|
1952
|
+
return this._addCheck({
|
|
1953
|
+
kind: "endsWith",
|
|
1954
|
+
value,
|
|
1955
|
+
...errorUtil.errToObj(message)
|
|
1956
|
+
});
|
|
1957
|
+
}
|
|
1958
|
+
min(minLength, message) {
|
|
1959
|
+
return this._addCheck({
|
|
1960
|
+
kind: "min",
|
|
1961
|
+
value: minLength,
|
|
1962
|
+
...errorUtil.errToObj(message)
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
max(maxLength, message) {
|
|
1966
|
+
return this._addCheck({
|
|
1967
|
+
kind: "max",
|
|
1968
|
+
value: maxLength,
|
|
1969
|
+
...errorUtil.errToObj(message)
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
length(len, message) {
|
|
1973
|
+
return this._addCheck({
|
|
1974
|
+
kind: "length",
|
|
1975
|
+
value: len,
|
|
1976
|
+
...errorUtil.errToObj(message)
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
nonempty(message) {
|
|
1980
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1981
|
+
}
|
|
1982
|
+
trim() {
|
|
1983
|
+
return new ZodString({
|
|
1984
|
+
...this._def,
|
|
1985
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
toLowerCase() {
|
|
1989
|
+
return new ZodString({
|
|
1990
|
+
...this._def,
|
|
1991
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
toUpperCase() {
|
|
1995
|
+
return new ZodString({
|
|
1996
|
+
...this._def,
|
|
1997
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
get isDatetime() {
|
|
2001
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
2002
|
+
}
|
|
2003
|
+
get isDate() {
|
|
2004
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
2005
|
+
}
|
|
2006
|
+
get isTime() {
|
|
2007
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
2008
|
+
}
|
|
2009
|
+
get isDuration() {
|
|
2010
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
2011
|
+
}
|
|
2012
|
+
get isEmail() {
|
|
2013
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
2014
|
+
}
|
|
2015
|
+
get isURL() {
|
|
2016
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
2017
|
+
}
|
|
2018
|
+
get isEmoji() {
|
|
2019
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
2020
|
+
}
|
|
2021
|
+
get isUUID() {
|
|
2022
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
2023
|
+
}
|
|
2024
|
+
get isNANOID() {
|
|
2025
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
2026
|
+
}
|
|
2027
|
+
get isCUID() {
|
|
2028
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
2029
|
+
}
|
|
2030
|
+
get isCUID2() {
|
|
2031
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
2032
|
+
}
|
|
2033
|
+
get isULID() {
|
|
2034
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
2035
|
+
}
|
|
2036
|
+
get isIP() {
|
|
2037
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
2038
|
+
}
|
|
2039
|
+
get isCIDR() {
|
|
2040
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
2041
|
+
}
|
|
2042
|
+
get isBase64() {
|
|
2043
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
2044
|
+
}
|
|
2045
|
+
get isBase64url() {
|
|
2046
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
2047
|
+
}
|
|
2048
|
+
get minLength() {
|
|
2049
|
+
let min = null;
|
|
2050
|
+
for (const ch of this._def.checks) {
|
|
2051
|
+
if (ch.kind === "min") {
|
|
2052
|
+
if (min === null || ch.value > min)
|
|
2053
|
+
min = ch.value;
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
return min;
|
|
2057
|
+
}
|
|
2058
|
+
get maxLength() {
|
|
2059
|
+
let max = null;
|
|
2060
|
+
for (const ch of this._def.checks) {
|
|
2061
|
+
if (ch.kind === "max") {
|
|
2062
|
+
if (max === null || ch.value < max)
|
|
2063
|
+
max = ch.value;
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return max;
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
ZodString.create = (params) => {
|
|
2070
|
+
return new ZodString({
|
|
2071
|
+
checks: [],
|
|
2072
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
2073
|
+
coerce: params?.coerce ?? false,
|
|
2074
|
+
...processCreateParams(params)
|
|
2075
|
+
});
|
|
2076
|
+
};
|
|
2077
|
+
ZodNumber = class ZodNumber extends ZodType {
|
|
2078
|
+
constructor() {
|
|
2079
|
+
super(...arguments);
|
|
2080
|
+
this.min = this.gte;
|
|
2081
|
+
this.max = this.lte;
|
|
2082
|
+
this.step = this.multipleOf;
|
|
2083
|
+
}
|
|
2084
|
+
_parse(input) {
|
|
2085
|
+
if (this._def.coerce) {
|
|
2086
|
+
input.data = Number(input.data);
|
|
2087
|
+
}
|
|
2088
|
+
const parsedType = this._getType(input);
|
|
2089
|
+
if (parsedType !== ZodParsedType.number) {
|
|
2090
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2091
|
+
addIssueToContext(ctx2, {
|
|
2092
|
+
code: ZodIssueCode.invalid_type,
|
|
2093
|
+
expected: ZodParsedType.number,
|
|
2094
|
+
received: ctx2.parsedType
|
|
2095
|
+
});
|
|
2096
|
+
return INVALID;
|
|
2097
|
+
}
|
|
2098
|
+
let ctx = undefined;
|
|
2099
|
+
const status = new ParseStatus;
|
|
2100
|
+
for (const check of this._def.checks) {
|
|
2101
|
+
if (check.kind === "int") {
|
|
2102
|
+
if (!util.isInteger(input.data)) {
|
|
2103
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2104
|
+
addIssueToContext(ctx, {
|
|
2105
|
+
code: ZodIssueCode.invalid_type,
|
|
2106
|
+
expected: "integer",
|
|
2107
|
+
received: "float",
|
|
2108
|
+
message: check.message
|
|
2109
|
+
});
|
|
2110
|
+
status.dirty();
|
|
2111
|
+
}
|
|
2112
|
+
} else if (check.kind === "min") {
|
|
2113
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2114
|
+
if (tooSmall) {
|
|
2115
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2116
|
+
addIssueToContext(ctx, {
|
|
2117
|
+
code: ZodIssueCode.too_small,
|
|
2118
|
+
minimum: check.value,
|
|
2119
|
+
type: "number",
|
|
2120
|
+
inclusive: check.inclusive,
|
|
2121
|
+
exact: false,
|
|
2122
|
+
message: check.message
|
|
2123
|
+
});
|
|
2124
|
+
status.dirty();
|
|
2125
|
+
}
|
|
2126
|
+
} else if (check.kind === "max") {
|
|
2127
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2128
|
+
if (tooBig) {
|
|
2129
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2130
|
+
addIssueToContext(ctx, {
|
|
2131
|
+
code: ZodIssueCode.too_big,
|
|
2132
|
+
maximum: check.value,
|
|
2133
|
+
type: "number",
|
|
2134
|
+
inclusive: check.inclusive,
|
|
2135
|
+
exact: false,
|
|
2136
|
+
message: check.message
|
|
2137
|
+
});
|
|
2138
|
+
status.dirty();
|
|
2139
|
+
}
|
|
2140
|
+
} else if (check.kind === "multipleOf") {
|
|
2141
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
2142
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2143
|
+
addIssueToContext(ctx, {
|
|
2144
|
+
code: ZodIssueCode.not_multiple_of,
|
|
2145
|
+
multipleOf: check.value,
|
|
2146
|
+
message: check.message
|
|
2147
|
+
});
|
|
2148
|
+
status.dirty();
|
|
2149
|
+
}
|
|
2150
|
+
} else if (check.kind === "finite") {
|
|
2151
|
+
if (!Number.isFinite(input.data)) {
|
|
2152
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2153
|
+
addIssueToContext(ctx, {
|
|
2154
|
+
code: ZodIssueCode.not_finite,
|
|
2155
|
+
message: check.message
|
|
2156
|
+
});
|
|
2157
|
+
status.dirty();
|
|
2158
|
+
}
|
|
2159
|
+
} else {
|
|
2160
|
+
util.assertNever(check);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
return { status: status.value, value: input.data };
|
|
2164
|
+
}
|
|
2165
|
+
gte(value, message) {
|
|
2166
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2167
|
+
}
|
|
2168
|
+
gt(value, message) {
|
|
2169
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2170
|
+
}
|
|
2171
|
+
lte(value, message) {
|
|
2172
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2173
|
+
}
|
|
2174
|
+
lt(value, message) {
|
|
2175
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2176
|
+
}
|
|
2177
|
+
setLimit(kind, value, inclusive, message) {
|
|
2178
|
+
return new ZodNumber({
|
|
2179
|
+
...this._def,
|
|
2180
|
+
checks: [
|
|
2181
|
+
...this._def.checks,
|
|
2182
|
+
{
|
|
2183
|
+
kind,
|
|
2184
|
+
value,
|
|
2185
|
+
inclusive,
|
|
2186
|
+
message: errorUtil.toString(message)
|
|
2187
|
+
}
|
|
2188
|
+
]
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
_addCheck(check) {
|
|
2192
|
+
return new ZodNumber({
|
|
2193
|
+
...this._def,
|
|
2194
|
+
checks: [...this._def.checks, check]
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
int(message) {
|
|
2198
|
+
return this._addCheck({
|
|
2199
|
+
kind: "int",
|
|
2200
|
+
message: errorUtil.toString(message)
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
positive(message) {
|
|
2204
|
+
return this._addCheck({
|
|
2205
|
+
kind: "min",
|
|
2206
|
+
value: 0,
|
|
2207
|
+
inclusive: false,
|
|
2208
|
+
message: errorUtil.toString(message)
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
negative(message) {
|
|
2212
|
+
return this._addCheck({
|
|
2213
|
+
kind: "max",
|
|
2214
|
+
value: 0,
|
|
2215
|
+
inclusive: false,
|
|
2216
|
+
message: errorUtil.toString(message)
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
nonpositive(message) {
|
|
2220
|
+
return this._addCheck({
|
|
2221
|
+
kind: "max",
|
|
2222
|
+
value: 0,
|
|
2223
|
+
inclusive: true,
|
|
2224
|
+
message: errorUtil.toString(message)
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
nonnegative(message) {
|
|
2228
|
+
return this._addCheck({
|
|
2229
|
+
kind: "min",
|
|
2230
|
+
value: 0,
|
|
2231
|
+
inclusive: true,
|
|
2232
|
+
message: errorUtil.toString(message)
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
multipleOf(value, message) {
|
|
2236
|
+
return this._addCheck({
|
|
2237
|
+
kind: "multipleOf",
|
|
2238
|
+
value,
|
|
2239
|
+
message: errorUtil.toString(message)
|
|
2240
|
+
});
|
|
2241
|
+
}
|
|
2242
|
+
finite(message) {
|
|
2243
|
+
return this._addCheck({
|
|
2244
|
+
kind: "finite",
|
|
2245
|
+
message: errorUtil.toString(message)
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
safe(message) {
|
|
2249
|
+
return this._addCheck({
|
|
2250
|
+
kind: "min",
|
|
2251
|
+
inclusive: true,
|
|
2252
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
2253
|
+
message: errorUtil.toString(message)
|
|
2254
|
+
})._addCheck({
|
|
2255
|
+
kind: "max",
|
|
2256
|
+
inclusive: true,
|
|
2257
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
2258
|
+
message: errorUtil.toString(message)
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
get minValue() {
|
|
2262
|
+
let min = null;
|
|
2263
|
+
for (const ch of this._def.checks) {
|
|
2264
|
+
if (ch.kind === "min") {
|
|
2265
|
+
if (min === null || ch.value > min)
|
|
2266
|
+
min = ch.value;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
return min;
|
|
2270
|
+
}
|
|
2271
|
+
get maxValue() {
|
|
2272
|
+
let max = null;
|
|
2273
|
+
for (const ch of this._def.checks) {
|
|
2274
|
+
if (ch.kind === "max") {
|
|
2275
|
+
if (max === null || ch.value < max)
|
|
2276
|
+
max = ch.value;
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
return max;
|
|
2280
|
+
}
|
|
2281
|
+
get isInt() {
|
|
2282
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
2283
|
+
}
|
|
2284
|
+
get isFinite() {
|
|
2285
|
+
let max = null;
|
|
2286
|
+
let min = null;
|
|
2287
|
+
for (const ch of this._def.checks) {
|
|
2288
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
2289
|
+
return true;
|
|
2290
|
+
} else if (ch.kind === "min") {
|
|
2291
|
+
if (min === null || ch.value > min)
|
|
2292
|
+
min = ch.value;
|
|
2293
|
+
} else if (ch.kind === "max") {
|
|
2294
|
+
if (max === null || ch.value < max)
|
|
2295
|
+
max = ch.value;
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
2299
|
+
}
|
|
2300
|
+
};
|
|
2301
|
+
ZodNumber.create = (params) => {
|
|
2302
|
+
return new ZodNumber({
|
|
2303
|
+
checks: [],
|
|
2304
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
2305
|
+
coerce: params?.coerce || false,
|
|
2306
|
+
...processCreateParams(params)
|
|
2307
|
+
});
|
|
2308
|
+
};
|
|
2309
|
+
ZodBigInt = class ZodBigInt extends ZodType {
|
|
2310
|
+
constructor() {
|
|
2311
|
+
super(...arguments);
|
|
2312
|
+
this.min = this.gte;
|
|
2313
|
+
this.max = this.lte;
|
|
2314
|
+
}
|
|
2315
|
+
_parse(input) {
|
|
2316
|
+
if (this._def.coerce) {
|
|
2317
|
+
try {
|
|
2318
|
+
input.data = BigInt(input.data);
|
|
2319
|
+
} catch {
|
|
2320
|
+
return this._getInvalidInput(input);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
const parsedType = this._getType(input);
|
|
2324
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
2325
|
+
return this._getInvalidInput(input);
|
|
2326
|
+
}
|
|
2327
|
+
let ctx = undefined;
|
|
2328
|
+
const status = new ParseStatus;
|
|
2329
|
+
for (const check of this._def.checks) {
|
|
2330
|
+
if (check.kind === "min") {
|
|
2331
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2332
|
+
if (tooSmall) {
|
|
2333
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2334
|
+
addIssueToContext(ctx, {
|
|
2335
|
+
code: ZodIssueCode.too_small,
|
|
2336
|
+
type: "bigint",
|
|
2337
|
+
minimum: check.value,
|
|
2338
|
+
inclusive: check.inclusive,
|
|
2339
|
+
message: check.message
|
|
2340
|
+
});
|
|
2341
|
+
status.dirty();
|
|
2342
|
+
}
|
|
2343
|
+
} else if (check.kind === "max") {
|
|
2344
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2345
|
+
if (tooBig) {
|
|
2346
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2347
|
+
addIssueToContext(ctx, {
|
|
2348
|
+
code: ZodIssueCode.too_big,
|
|
2349
|
+
type: "bigint",
|
|
2350
|
+
maximum: check.value,
|
|
2351
|
+
inclusive: check.inclusive,
|
|
2352
|
+
message: check.message
|
|
2353
|
+
});
|
|
2354
|
+
status.dirty();
|
|
2355
|
+
}
|
|
2356
|
+
} else if (check.kind === "multipleOf") {
|
|
2357
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
2358
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2359
|
+
addIssueToContext(ctx, {
|
|
2360
|
+
code: ZodIssueCode.not_multiple_of,
|
|
2361
|
+
multipleOf: check.value,
|
|
2362
|
+
message: check.message
|
|
2363
|
+
});
|
|
2364
|
+
status.dirty();
|
|
2365
|
+
}
|
|
2366
|
+
} else {
|
|
2367
|
+
util.assertNever(check);
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
return { status: status.value, value: input.data };
|
|
2371
|
+
}
|
|
2372
|
+
_getInvalidInput(input) {
|
|
2373
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2374
|
+
addIssueToContext(ctx, {
|
|
2375
|
+
code: ZodIssueCode.invalid_type,
|
|
2376
|
+
expected: ZodParsedType.bigint,
|
|
2377
|
+
received: ctx.parsedType
|
|
2378
|
+
});
|
|
2379
|
+
return INVALID;
|
|
2380
|
+
}
|
|
2381
|
+
gte(value, message) {
|
|
2382
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2383
|
+
}
|
|
2384
|
+
gt(value, message) {
|
|
2385
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2386
|
+
}
|
|
2387
|
+
lte(value, message) {
|
|
2388
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2389
|
+
}
|
|
2390
|
+
lt(value, message) {
|
|
2391
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2392
|
+
}
|
|
2393
|
+
setLimit(kind, value, inclusive, message) {
|
|
2394
|
+
return new ZodBigInt({
|
|
2395
|
+
...this._def,
|
|
2396
|
+
checks: [
|
|
2397
|
+
...this._def.checks,
|
|
2398
|
+
{
|
|
2399
|
+
kind,
|
|
2400
|
+
value,
|
|
2401
|
+
inclusive,
|
|
2402
|
+
message: errorUtil.toString(message)
|
|
2403
|
+
}
|
|
2404
|
+
]
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2407
|
+
_addCheck(check) {
|
|
2408
|
+
return new ZodBigInt({
|
|
2409
|
+
...this._def,
|
|
2410
|
+
checks: [...this._def.checks, check]
|
|
2411
|
+
});
|
|
2412
|
+
}
|
|
2413
|
+
positive(message) {
|
|
2414
|
+
return this._addCheck({
|
|
2415
|
+
kind: "min",
|
|
2416
|
+
value: BigInt(0),
|
|
2417
|
+
inclusive: false,
|
|
2418
|
+
message: errorUtil.toString(message)
|
|
2419
|
+
});
|
|
2420
|
+
}
|
|
2421
|
+
negative(message) {
|
|
2422
|
+
return this._addCheck({
|
|
2423
|
+
kind: "max",
|
|
2424
|
+
value: BigInt(0),
|
|
2425
|
+
inclusive: false,
|
|
2426
|
+
message: errorUtil.toString(message)
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
nonpositive(message) {
|
|
2430
|
+
return this._addCheck({
|
|
2431
|
+
kind: "max",
|
|
2432
|
+
value: BigInt(0),
|
|
2433
|
+
inclusive: true,
|
|
2434
|
+
message: errorUtil.toString(message)
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
nonnegative(message) {
|
|
2438
|
+
return this._addCheck({
|
|
2439
|
+
kind: "min",
|
|
2440
|
+
value: BigInt(0),
|
|
2441
|
+
inclusive: true,
|
|
2442
|
+
message: errorUtil.toString(message)
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
multipleOf(value, message) {
|
|
2446
|
+
return this._addCheck({
|
|
2447
|
+
kind: "multipleOf",
|
|
2448
|
+
value,
|
|
2449
|
+
message: errorUtil.toString(message)
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
get minValue() {
|
|
2453
|
+
let min = null;
|
|
2454
|
+
for (const ch of this._def.checks) {
|
|
2455
|
+
if (ch.kind === "min") {
|
|
2456
|
+
if (min === null || ch.value > min)
|
|
2457
|
+
min = ch.value;
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
return min;
|
|
2461
|
+
}
|
|
2462
|
+
get maxValue() {
|
|
2463
|
+
let max = null;
|
|
2464
|
+
for (const ch of this._def.checks) {
|
|
2465
|
+
if (ch.kind === "max") {
|
|
2466
|
+
if (max === null || ch.value < max)
|
|
2467
|
+
max = ch.value;
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
return max;
|
|
2471
|
+
}
|
|
2472
|
+
};
|
|
2473
|
+
ZodBigInt.create = (params) => {
|
|
2474
|
+
return new ZodBigInt({
|
|
2475
|
+
checks: [],
|
|
2476
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2477
|
+
coerce: params?.coerce ?? false,
|
|
2478
|
+
...processCreateParams(params)
|
|
2479
|
+
});
|
|
2480
|
+
};
|
|
2481
|
+
ZodBoolean = class ZodBoolean extends ZodType {
|
|
2482
|
+
_parse(input) {
|
|
2483
|
+
if (this._def.coerce) {
|
|
2484
|
+
input.data = Boolean(input.data);
|
|
2485
|
+
}
|
|
2486
|
+
const parsedType = this._getType(input);
|
|
2487
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
2488
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2489
|
+
addIssueToContext(ctx, {
|
|
2490
|
+
code: ZodIssueCode.invalid_type,
|
|
2491
|
+
expected: ZodParsedType.boolean,
|
|
2492
|
+
received: ctx.parsedType
|
|
2493
|
+
});
|
|
2494
|
+
return INVALID;
|
|
2495
|
+
}
|
|
2496
|
+
return OK(input.data);
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
ZodBoolean.create = (params) => {
|
|
2500
|
+
return new ZodBoolean({
|
|
2501
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2502
|
+
coerce: params?.coerce || false,
|
|
2503
|
+
...processCreateParams(params)
|
|
2504
|
+
});
|
|
2505
|
+
};
|
|
2506
|
+
ZodDate = class ZodDate extends ZodType {
|
|
2507
|
+
_parse(input) {
|
|
2508
|
+
if (this._def.coerce) {
|
|
2509
|
+
input.data = new Date(input.data);
|
|
2510
|
+
}
|
|
2511
|
+
const parsedType = this._getType(input);
|
|
2512
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2513
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2514
|
+
addIssueToContext(ctx2, {
|
|
2515
|
+
code: ZodIssueCode.invalid_type,
|
|
2516
|
+
expected: ZodParsedType.date,
|
|
2517
|
+
received: ctx2.parsedType
|
|
2518
|
+
});
|
|
2519
|
+
return INVALID;
|
|
2520
|
+
}
|
|
2521
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2522
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2523
|
+
addIssueToContext(ctx2, {
|
|
2524
|
+
code: ZodIssueCode.invalid_date
|
|
2525
|
+
});
|
|
2526
|
+
return INVALID;
|
|
2527
|
+
}
|
|
2528
|
+
const status = new ParseStatus;
|
|
2529
|
+
let ctx = undefined;
|
|
2530
|
+
for (const check of this._def.checks) {
|
|
2531
|
+
if (check.kind === "min") {
|
|
2532
|
+
if (input.data.getTime() < check.value) {
|
|
2533
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2534
|
+
addIssueToContext(ctx, {
|
|
2535
|
+
code: ZodIssueCode.too_small,
|
|
2536
|
+
message: check.message,
|
|
2537
|
+
inclusive: true,
|
|
2538
|
+
exact: false,
|
|
2539
|
+
minimum: check.value,
|
|
2540
|
+
type: "date"
|
|
2541
|
+
});
|
|
2542
|
+
status.dirty();
|
|
2543
|
+
}
|
|
2544
|
+
} else if (check.kind === "max") {
|
|
2545
|
+
if (input.data.getTime() > check.value) {
|
|
2546
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2547
|
+
addIssueToContext(ctx, {
|
|
2548
|
+
code: ZodIssueCode.too_big,
|
|
2549
|
+
message: check.message,
|
|
2550
|
+
inclusive: true,
|
|
2551
|
+
exact: false,
|
|
2552
|
+
maximum: check.value,
|
|
2553
|
+
type: "date"
|
|
2554
|
+
});
|
|
2555
|
+
status.dirty();
|
|
2556
|
+
}
|
|
2557
|
+
} else {
|
|
2558
|
+
util.assertNever(check);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
return {
|
|
2562
|
+
status: status.value,
|
|
2563
|
+
value: new Date(input.data.getTime())
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
_addCheck(check) {
|
|
2567
|
+
return new ZodDate({
|
|
2568
|
+
...this._def,
|
|
2569
|
+
checks: [...this._def.checks, check]
|
|
2570
|
+
});
|
|
2571
|
+
}
|
|
2572
|
+
min(minDate, message) {
|
|
2573
|
+
return this._addCheck({
|
|
2574
|
+
kind: "min",
|
|
2575
|
+
value: minDate.getTime(),
|
|
2576
|
+
message: errorUtil.toString(message)
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
max(maxDate, message) {
|
|
2580
|
+
return this._addCheck({
|
|
2581
|
+
kind: "max",
|
|
2582
|
+
value: maxDate.getTime(),
|
|
2583
|
+
message: errorUtil.toString(message)
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
get minDate() {
|
|
2587
|
+
let min = null;
|
|
2588
|
+
for (const ch of this._def.checks) {
|
|
2589
|
+
if (ch.kind === "min") {
|
|
2590
|
+
if (min === null || ch.value > min)
|
|
2591
|
+
min = ch.value;
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
return min != null ? new Date(min) : null;
|
|
2595
|
+
}
|
|
2596
|
+
get maxDate() {
|
|
2597
|
+
let max = null;
|
|
2598
|
+
for (const ch of this._def.checks) {
|
|
2599
|
+
if (ch.kind === "max") {
|
|
2600
|
+
if (max === null || ch.value < max)
|
|
2601
|
+
max = ch.value;
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
return max != null ? new Date(max) : null;
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
ZodDate.create = (params) => {
|
|
2608
|
+
return new ZodDate({
|
|
2609
|
+
checks: [],
|
|
2610
|
+
coerce: params?.coerce || false,
|
|
2611
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2612
|
+
...processCreateParams(params)
|
|
2613
|
+
});
|
|
2614
|
+
};
|
|
2615
|
+
ZodSymbol = class ZodSymbol extends ZodType {
|
|
2616
|
+
_parse(input) {
|
|
2617
|
+
const parsedType = this._getType(input);
|
|
2618
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2619
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2620
|
+
addIssueToContext(ctx, {
|
|
2621
|
+
code: ZodIssueCode.invalid_type,
|
|
2622
|
+
expected: ZodParsedType.symbol,
|
|
2623
|
+
received: ctx.parsedType
|
|
2624
|
+
});
|
|
2625
|
+
return INVALID;
|
|
2626
|
+
}
|
|
2627
|
+
return OK(input.data);
|
|
2628
|
+
}
|
|
2629
|
+
};
|
|
2630
|
+
ZodSymbol.create = (params) => {
|
|
2631
|
+
return new ZodSymbol({
|
|
2632
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2633
|
+
...processCreateParams(params)
|
|
2634
|
+
});
|
|
2635
|
+
};
|
|
2636
|
+
ZodUndefined = class ZodUndefined extends ZodType {
|
|
2637
|
+
_parse(input) {
|
|
2638
|
+
const parsedType = this._getType(input);
|
|
2639
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2640
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2641
|
+
addIssueToContext(ctx, {
|
|
2642
|
+
code: ZodIssueCode.invalid_type,
|
|
2643
|
+
expected: ZodParsedType.undefined,
|
|
2644
|
+
received: ctx.parsedType
|
|
2645
|
+
});
|
|
2646
|
+
return INVALID;
|
|
2647
|
+
}
|
|
2648
|
+
return OK(input.data);
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
ZodUndefined.create = (params) => {
|
|
2652
|
+
return new ZodUndefined({
|
|
2653
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2654
|
+
...processCreateParams(params)
|
|
2655
|
+
});
|
|
2656
|
+
};
|
|
2657
|
+
ZodNull = class ZodNull extends ZodType {
|
|
2658
|
+
_parse(input) {
|
|
2659
|
+
const parsedType = this._getType(input);
|
|
2660
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2661
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2662
|
+
addIssueToContext(ctx, {
|
|
2663
|
+
code: ZodIssueCode.invalid_type,
|
|
2664
|
+
expected: ZodParsedType.null,
|
|
2665
|
+
received: ctx.parsedType
|
|
2666
|
+
});
|
|
2667
|
+
return INVALID;
|
|
2668
|
+
}
|
|
2669
|
+
return OK(input.data);
|
|
2670
|
+
}
|
|
2671
|
+
};
|
|
2672
|
+
ZodNull.create = (params) => {
|
|
2673
|
+
return new ZodNull({
|
|
2674
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2675
|
+
...processCreateParams(params)
|
|
2676
|
+
});
|
|
2677
|
+
};
|
|
2678
|
+
ZodAny = class ZodAny extends ZodType {
|
|
2679
|
+
constructor() {
|
|
2680
|
+
super(...arguments);
|
|
2681
|
+
this._any = true;
|
|
2682
|
+
}
|
|
2683
|
+
_parse(input) {
|
|
2684
|
+
return OK(input.data);
|
|
2685
|
+
}
|
|
2686
|
+
};
|
|
2687
|
+
ZodAny.create = (params) => {
|
|
2688
|
+
return new ZodAny({
|
|
2689
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2690
|
+
...processCreateParams(params)
|
|
2691
|
+
});
|
|
2692
|
+
};
|
|
2693
|
+
ZodUnknown = class ZodUnknown extends ZodType {
|
|
2694
|
+
constructor() {
|
|
2695
|
+
super(...arguments);
|
|
2696
|
+
this._unknown = true;
|
|
2697
|
+
}
|
|
2698
|
+
_parse(input) {
|
|
2699
|
+
return OK(input.data);
|
|
2700
|
+
}
|
|
2701
|
+
};
|
|
2702
|
+
ZodUnknown.create = (params) => {
|
|
2703
|
+
return new ZodUnknown({
|
|
2704
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2705
|
+
...processCreateParams(params)
|
|
2706
|
+
});
|
|
2707
|
+
};
|
|
2708
|
+
ZodNever = class ZodNever extends ZodType {
|
|
2709
|
+
_parse(input) {
|
|
2710
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2711
|
+
addIssueToContext(ctx, {
|
|
2712
|
+
code: ZodIssueCode.invalid_type,
|
|
2713
|
+
expected: ZodParsedType.never,
|
|
2714
|
+
received: ctx.parsedType
|
|
2715
|
+
});
|
|
2716
|
+
return INVALID;
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
ZodNever.create = (params) => {
|
|
2720
|
+
return new ZodNever({
|
|
2721
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2722
|
+
...processCreateParams(params)
|
|
2723
|
+
});
|
|
2724
|
+
};
|
|
2725
|
+
ZodVoid = class ZodVoid extends ZodType {
|
|
2726
|
+
_parse(input) {
|
|
2727
|
+
const parsedType = this._getType(input);
|
|
2728
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2729
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2730
|
+
addIssueToContext(ctx, {
|
|
2731
|
+
code: ZodIssueCode.invalid_type,
|
|
2732
|
+
expected: ZodParsedType.void,
|
|
2733
|
+
received: ctx.parsedType
|
|
2734
|
+
});
|
|
2735
|
+
return INVALID;
|
|
2736
|
+
}
|
|
2737
|
+
return OK(input.data);
|
|
2738
|
+
}
|
|
2739
|
+
};
|
|
2740
|
+
ZodVoid.create = (params) => {
|
|
2741
|
+
return new ZodVoid({
|
|
2742
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2743
|
+
...processCreateParams(params)
|
|
2744
|
+
});
|
|
2745
|
+
};
|
|
2746
|
+
ZodArray = class ZodArray extends ZodType {
|
|
2747
|
+
_parse(input) {
|
|
2748
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2749
|
+
const def = this._def;
|
|
2750
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2751
|
+
addIssueToContext(ctx, {
|
|
2752
|
+
code: ZodIssueCode.invalid_type,
|
|
2753
|
+
expected: ZodParsedType.array,
|
|
2754
|
+
received: ctx.parsedType
|
|
2755
|
+
});
|
|
2756
|
+
return INVALID;
|
|
2757
|
+
}
|
|
2758
|
+
if (def.exactLength !== null) {
|
|
2759
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2760
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2761
|
+
if (tooBig || tooSmall) {
|
|
2762
|
+
addIssueToContext(ctx, {
|
|
2763
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2764
|
+
minimum: tooSmall ? def.exactLength.value : undefined,
|
|
2765
|
+
maximum: tooBig ? def.exactLength.value : undefined,
|
|
2766
|
+
type: "array",
|
|
2767
|
+
inclusive: true,
|
|
2768
|
+
exact: true,
|
|
2769
|
+
message: def.exactLength.message
|
|
2770
|
+
});
|
|
2771
|
+
status.dirty();
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
if (def.minLength !== null) {
|
|
2775
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2776
|
+
addIssueToContext(ctx, {
|
|
2777
|
+
code: ZodIssueCode.too_small,
|
|
2778
|
+
minimum: def.minLength.value,
|
|
2779
|
+
type: "array",
|
|
2780
|
+
inclusive: true,
|
|
2781
|
+
exact: false,
|
|
2782
|
+
message: def.minLength.message
|
|
2783
|
+
});
|
|
2784
|
+
status.dirty();
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
if (def.maxLength !== null) {
|
|
2788
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2789
|
+
addIssueToContext(ctx, {
|
|
2790
|
+
code: ZodIssueCode.too_big,
|
|
2791
|
+
maximum: def.maxLength.value,
|
|
2792
|
+
type: "array",
|
|
2793
|
+
inclusive: true,
|
|
2794
|
+
exact: false,
|
|
2795
|
+
message: def.maxLength.message
|
|
2796
|
+
});
|
|
2797
|
+
status.dirty();
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
if (ctx.common.async) {
|
|
2801
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
|
2802
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2803
|
+
})).then((result2) => {
|
|
2804
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
const result = [...ctx.data].map((item, i) => {
|
|
2808
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2809
|
+
});
|
|
2810
|
+
return ParseStatus.mergeArray(status, result);
|
|
2811
|
+
}
|
|
2812
|
+
get element() {
|
|
2813
|
+
return this._def.type;
|
|
2814
|
+
}
|
|
2815
|
+
min(minLength, message) {
|
|
2816
|
+
return new ZodArray({
|
|
2817
|
+
...this._def,
|
|
2818
|
+
minLength: { value: minLength, message: errorUtil.toString(message) }
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
max(maxLength, message) {
|
|
2822
|
+
return new ZodArray({
|
|
2823
|
+
...this._def,
|
|
2824
|
+
maxLength: { value: maxLength, message: errorUtil.toString(message) }
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
length(len, message) {
|
|
2828
|
+
return new ZodArray({
|
|
2829
|
+
...this._def,
|
|
2830
|
+
exactLength: { value: len, message: errorUtil.toString(message) }
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
nonempty(message) {
|
|
2834
|
+
return this.min(1, message);
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
ZodArray.create = (schema, params) => {
|
|
2838
|
+
return new ZodArray({
|
|
2839
|
+
type: schema,
|
|
2840
|
+
minLength: null,
|
|
2841
|
+
maxLength: null,
|
|
2842
|
+
exactLength: null,
|
|
2843
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2844
|
+
...processCreateParams(params)
|
|
2845
|
+
});
|
|
2846
|
+
};
|
|
2847
|
+
ZodObject = class ZodObject extends ZodType {
|
|
2848
|
+
constructor() {
|
|
2849
|
+
super(...arguments);
|
|
2850
|
+
this._cached = null;
|
|
2851
|
+
this.nonstrict = this.passthrough;
|
|
2852
|
+
this.augment = this.extend;
|
|
2853
|
+
}
|
|
2854
|
+
_getCached() {
|
|
2855
|
+
if (this._cached !== null)
|
|
2856
|
+
return this._cached;
|
|
2857
|
+
const shape = this._def.shape();
|
|
2858
|
+
const keys = util.objectKeys(shape);
|
|
2859
|
+
this._cached = { shape, keys };
|
|
2860
|
+
return this._cached;
|
|
2861
|
+
}
|
|
2862
|
+
_parse(input) {
|
|
2863
|
+
const parsedType = this._getType(input);
|
|
2864
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2865
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2866
|
+
addIssueToContext(ctx2, {
|
|
2867
|
+
code: ZodIssueCode.invalid_type,
|
|
2868
|
+
expected: ZodParsedType.object,
|
|
2869
|
+
received: ctx2.parsedType
|
|
2870
|
+
});
|
|
2871
|
+
return INVALID;
|
|
2872
|
+
}
|
|
2873
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2874
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2875
|
+
const extraKeys = [];
|
|
2876
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2877
|
+
for (const key in ctx.data) {
|
|
2878
|
+
if (!shapeKeys.includes(key)) {
|
|
2879
|
+
extraKeys.push(key);
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
const pairs = [];
|
|
2884
|
+
for (const key of shapeKeys) {
|
|
2885
|
+
const keyValidator = shape[key];
|
|
2886
|
+
const value = ctx.data[key];
|
|
2887
|
+
pairs.push({
|
|
2888
|
+
key: { status: "valid", value: key },
|
|
2889
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2890
|
+
alwaysSet: key in ctx.data
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2894
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2895
|
+
if (unknownKeys === "passthrough") {
|
|
2896
|
+
for (const key of extraKeys) {
|
|
2897
|
+
pairs.push({
|
|
2898
|
+
key: { status: "valid", value: key },
|
|
2899
|
+
value: { status: "valid", value: ctx.data[key] }
|
|
2900
|
+
});
|
|
2901
|
+
}
|
|
2902
|
+
} else if (unknownKeys === "strict") {
|
|
2903
|
+
if (extraKeys.length > 0) {
|
|
2904
|
+
addIssueToContext(ctx, {
|
|
2905
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2906
|
+
keys: extraKeys
|
|
2907
|
+
});
|
|
2908
|
+
status.dirty();
|
|
2909
|
+
}
|
|
2910
|
+
} else if (unknownKeys === "strip") {} else {
|
|
2911
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2912
|
+
}
|
|
2913
|
+
} else {
|
|
2914
|
+
const catchall = this._def.catchall;
|
|
2915
|
+
for (const key of extraKeys) {
|
|
2916
|
+
const value = ctx.data[key];
|
|
2917
|
+
pairs.push({
|
|
2918
|
+
key: { status: "valid", value: key },
|
|
2919
|
+
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2920
|
+
alwaysSet: key in ctx.data
|
|
2921
|
+
});
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
if (ctx.common.async) {
|
|
2925
|
+
return Promise.resolve().then(async () => {
|
|
2926
|
+
const syncPairs = [];
|
|
2927
|
+
for (const pair of pairs) {
|
|
2928
|
+
const key = await pair.key;
|
|
2929
|
+
const value = await pair.value;
|
|
2930
|
+
syncPairs.push({
|
|
2931
|
+
key,
|
|
2932
|
+
value,
|
|
2933
|
+
alwaysSet: pair.alwaysSet
|
|
2934
|
+
});
|
|
2935
|
+
}
|
|
2936
|
+
return syncPairs;
|
|
2937
|
+
}).then((syncPairs) => {
|
|
2938
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2939
|
+
});
|
|
2940
|
+
} else {
|
|
2941
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
get shape() {
|
|
2945
|
+
return this._def.shape();
|
|
2946
|
+
}
|
|
2947
|
+
strict(message) {
|
|
2948
|
+
errorUtil.errToObj;
|
|
2949
|
+
return new ZodObject({
|
|
2950
|
+
...this._def,
|
|
2951
|
+
unknownKeys: "strict",
|
|
2952
|
+
...message !== undefined ? {
|
|
2953
|
+
errorMap: (issue, ctx) => {
|
|
2954
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2955
|
+
if (issue.code === "unrecognized_keys")
|
|
2956
|
+
return {
|
|
2957
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2958
|
+
};
|
|
2959
|
+
return {
|
|
2960
|
+
message: defaultError
|
|
2961
|
+
};
|
|
2962
|
+
}
|
|
2963
|
+
} : {}
|
|
2964
|
+
});
|
|
2965
|
+
}
|
|
2966
|
+
strip() {
|
|
2967
|
+
return new ZodObject({
|
|
2968
|
+
...this._def,
|
|
2969
|
+
unknownKeys: "strip"
|
|
2970
|
+
});
|
|
2971
|
+
}
|
|
2972
|
+
passthrough() {
|
|
2973
|
+
return new ZodObject({
|
|
2974
|
+
...this._def,
|
|
2975
|
+
unknownKeys: "passthrough"
|
|
2976
|
+
});
|
|
2977
|
+
}
|
|
2978
|
+
extend(augmentation) {
|
|
2979
|
+
return new ZodObject({
|
|
2980
|
+
...this._def,
|
|
2981
|
+
shape: () => ({
|
|
2982
|
+
...this._def.shape(),
|
|
2983
|
+
...augmentation
|
|
2984
|
+
})
|
|
2985
|
+
});
|
|
2986
|
+
}
|
|
2987
|
+
merge(merging) {
|
|
2988
|
+
const merged = new ZodObject({
|
|
2989
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2990
|
+
catchall: merging._def.catchall,
|
|
2991
|
+
shape: () => ({
|
|
2992
|
+
...this._def.shape(),
|
|
2993
|
+
...merging._def.shape()
|
|
2994
|
+
}),
|
|
2995
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2996
|
+
});
|
|
2997
|
+
return merged;
|
|
2998
|
+
}
|
|
2999
|
+
setKey(key, schema) {
|
|
3000
|
+
return this.augment({ [key]: schema });
|
|
3001
|
+
}
|
|
3002
|
+
catchall(index) {
|
|
3003
|
+
return new ZodObject({
|
|
3004
|
+
...this._def,
|
|
3005
|
+
catchall: index
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
pick(mask) {
|
|
3009
|
+
const shape = {};
|
|
3010
|
+
for (const key of util.objectKeys(mask)) {
|
|
3011
|
+
if (mask[key] && this.shape[key]) {
|
|
3012
|
+
shape[key] = this.shape[key];
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
return new ZodObject({
|
|
3016
|
+
...this._def,
|
|
3017
|
+
shape: () => shape
|
|
3018
|
+
});
|
|
3019
|
+
}
|
|
3020
|
+
omit(mask) {
|
|
3021
|
+
const shape = {};
|
|
3022
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
3023
|
+
if (!mask[key]) {
|
|
3024
|
+
shape[key] = this.shape[key];
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
return new ZodObject({
|
|
3028
|
+
...this._def,
|
|
3029
|
+
shape: () => shape
|
|
3030
|
+
});
|
|
3031
|
+
}
|
|
3032
|
+
deepPartial() {
|
|
3033
|
+
return deepPartialify(this);
|
|
3034
|
+
}
|
|
3035
|
+
partial(mask) {
|
|
3036
|
+
const newShape = {};
|
|
3037
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
3038
|
+
const fieldSchema = this.shape[key];
|
|
3039
|
+
if (mask && !mask[key]) {
|
|
3040
|
+
newShape[key] = fieldSchema;
|
|
3041
|
+
} else {
|
|
3042
|
+
newShape[key] = fieldSchema.optional();
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
return new ZodObject({
|
|
3046
|
+
...this._def,
|
|
3047
|
+
shape: () => newShape
|
|
3048
|
+
});
|
|
3049
|
+
}
|
|
3050
|
+
required(mask) {
|
|
3051
|
+
const newShape = {};
|
|
3052
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
3053
|
+
if (mask && !mask[key]) {
|
|
3054
|
+
newShape[key] = this.shape[key];
|
|
3055
|
+
} else {
|
|
3056
|
+
const fieldSchema = this.shape[key];
|
|
3057
|
+
let newField = fieldSchema;
|
|
3058
|
+
while (newField instanceof ZodOptional) {
|
|
3059
|
+
newField = newField._def.innerType;
|
|
3060
|
+
}
|
|
3061
|
+
newShape[key] = newField;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
return new ZodObject({
|
|
3065
|
+
...this._def,
|
|
3066
|
+
shape: () => newShape
|
|
3067
|
+
});
|
|
3068
|
+
}
|
|
3069
|
+
keyof() {
|
|
3070
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
3071
|
+
}
|
|
3072
|
+
};
|
|
3073
|
+
ZodObject.create = (shape, params) => {
|
|
3074
|
+
return new ZodObject({
|
|
3075
|
+
shape: () => shape,
|
|
3076
|
+
unknownKeys: "strip",
|
|
3077
|
+
catchall: ZodNever.create(),
|
|
3078
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3079
|
+
...processCreateParams(params)
|
|
3080
|
+
});
|
|
3081
|
+
};
|
|
3082
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
3083
|
+
return new ZodObject({
|
|
3084
|
+
shape: () => shape,
|
|
3085
|
+
unknownKeys: "strict",
|
|
3086
|
+
catchall: ZodNever.create(),
|
|
3087
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3088
|
+
...processCreateParams(params)
|
|
3089
|
+
});
|
|
3090
|
+
};
|
|
3091
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
3092
|
+
return new ZodObject({
|
|
3093
|
+
shape,
|
|
3094
|
+
unknownKeys: "strip",
|
|
3095
|
+
catchall: ZodNever.create(),
|
|
3096
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
3097
|
+
...processCreateParams(params)
|
|
3098
|
+
});
|
|
3099
|
+
};
|
|
3100
|
+
ZodUnion = class ZodUnion extends ZodType {
|
|
3101
|
+
_parse(input) {
|
|
3102
|
+
const { ctx } = this._processInputParams(input);
|
|
3103
|
+
const options = this._def.options;
|
|
3104
|
+
function handleResults(results) {
|
|
3105
|
+
for (const result of results) {
|
|
3106
|
+
if (result.result.status === "valid") {
|
|
3107
|
+
return result.result;
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
for (const result of results) {
|
|
3111
|
+
if (result.result.status === "dirty") {
|
|
3112
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
3113
|
+
return result.result;
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
3117
|
+
addIssueToContext(ctx, {
|
|
3118
|
+
code: ZodIssueCode.invalid_union,
|
|
3119
|
+
unionErrors
|
|
3120
|
+
});
|
|
3121
|
+
return INVALID;
|
|
3122
|
+
}
|
|
3123
|
+
if (ctx.common.async) {
|
|
3124
|
+
return Promise.all(options.map(async (option) => {
|
|
3125
|
+
const childCtx = {
|
|
3126
|
+
...ctx,
|
|
3127
|
+
common: {
|
|
3128
|
+
...ctx.common,
|
|
3129
|
+
issues: []
|
|
3130
|
+
},
|
|
3131
|
+
parent: null
|
|
3132
|
+
};
|
|
3133
|
+
return {
|
|
3134
|
+
result: await option._parseAsync({
|
|
3135
|
+
data: ctx.data,
|
|
3136
|
+
path: ctx.path,
|
|
3137
|
+
parent: childCtx
|
|
3138
|
+
}),
|
|
3139
|
+
ctx: childCtx
|
|
3140
|
+
};
|
|
3141
|
+
})).then(handleResults);
|
|
3142
|
+
} else {
|
|
3143
|
+
let dirty = undefined;
|
|
3144
|
+
const issues = [];
|
|
3145
|
+
for (const option of options) {
|
|
3146
|
+
const childCtx = {
|
|
3147
|
+
...ctx,
|
|
3148
|
+
common: {
|
|
3149
|
+
...ctx.common,
|
|
3150
|
+
issues: []
|
|
3151
|
+
},
|
|
3152
|
+
parent: null
|
|
3153
|
+
};
|
|
3154
|
+
const result = option._parseSync({
|
|
3155
|
+
data: ctx.data,
|
|
3156
|
+
path: ctx.path,
|
|
3157
|
+
parent: childCtx
|
|
3158
|
+
});
|
|
3159
|
+
if (result.status === "valid") {
|
|
3160
|
+
return result;
|
|
3161
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
3162
|
+
dirty = { result, ctx: childCtx };
|
|
3163
|
+
}
|
|
3164
|
+
if (childCtx.common.issues.length) {
|
|
3165
|
+
issues.push(childCtx.common.issues);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
if (dirty) {
|
|
3169
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
3170
|
+
return dirty.result;
|
|
3171
|
+
}
|
|
3172
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
3173
|
+
addIssueToContext(ctx, {
|
|
3174
|
+
code: ZodIssueCode.invalid_union,
|
|
3175
|
+
unionErrors
|
|
3176
|
+
});
|
|
3177
|
+
return INVALID;
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
get options() {
|
|
3181
|
+
return this._def.options;
|
|
3182
|
+
}
|
|
3183
|
+
};
|
|
3184
|
+
ZodUnion.create = (types, params) => {
|
|
3185
|
+
return new ZodUnion({
|
|
3186
|
+
options: types,
|
|
3187
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
3188
|
+
...processCreateParams(params)
|
|
3189
|
+
});
|
|
3190
|
+
};
|
|
3191
|
+
ZodDiscriminatedUnion = class ZodDiscriminatedUnion extends ZodType {
|
|
3192
|
+
_parse(input) {
|
|
3193
|
+
const { ctx } = this._processInputParams(input);
|
|
3194
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3195
|
+
addIssueToContext(ctx, {
|
|
3196
|
+
code: ZodIssueCode.invalid_type,
|
|
3197
|
+
expected: ZodParsedType.object,
|
|
3198
|
+
received: ctx.parsedType
|
|
3199
|
+
});
|
|
3200
|
+
return INVALID;
|
|
3201
|
+
}
|
|
3202
|
+
const discriminator = this.discriminator;
|
|
3203
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
3204
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
3205
|
+
if (!option) {
|
|
3206
|
+
addIssueToContext(ctx, {
|
|
3207
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
3208
|
+
options: Array.from(this.optionsMap.keys()),
|
|
3209
|
+
path: [discriminator]
|
|
3210
|
+
});
|
|
3211
|
+
return INVALID;
|
|
3212
|
+
}
|
|
3213
|
+
if (ctx.common.async) {
|
|
3214
|
+
return option._parseAsync({
|
|
3215
|
+
data: ctx.data,
|
|
3216
|
+
path: ctx.path,
|
|
3217
|
+
parent: ctx
|
|
3218
|
+
});
|
|
3219
|
+
} else {
|
|
3220
|
+
return option._parseSync({
|
|
3221
|
+
data: ctx.data,
|
|
3222
|
+
path: ctx.path,
|
|
3223
|
+
parent: ctx
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
get discriminator() {
|
|
3228
|
+
return this._def.discriminator;
|
|
3229
|
+
}
|
|
3230
|
+
get options() {
|
|
3231
|
+
return this._def.options;
|
|
3232
|
+
}
|
|
3233
|
+
get optionsMap() {
|
|
3234
|
+
return this._def.optionsMap;
|
|
3235
|
+
}
|
|
3236
|
+
static create(discriminator, options, params) {
|
|
3237
|
+
const optionsMap = new Map;
|
|
3238
|
+
for (const type of options) {
|
|
3239
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3240
|
+
if (!discriminatorValues.length) {
|
|
3241
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3242
|
+
}
|
|
3243
|
+
for (const value of discriminatorValues) {
|
|
3244
|
+
if (optionsMap.has(value)) {
|
|
3245
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3246
|
+
}
|
|
3247
|
+
optionsMap.set(value, type);
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
return new ZodDiscriminatedUnion({
|
|
3251
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3252
|
+
discriminator,
|
|
3253
|
+
options,
|
|
3254
|
+
optionsMap,
|
|
3255
|
+
...processCreateParams(params)
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
};
|
|
3259
|
+
ZodIntersection = class ZodIntersection extends ZodType {
|
|
3260
|
+
_parse(input) {
|
|
3261
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3262
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3263
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3264
|
+
return INVALID;
|
|
3265
|
+
}
|
|
3266
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3267
|
+
if (!merged.valid) {
|
|
3268
|
+
addIssueToContext(ctx, {
|
|
3269
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
3270
|
+
});
|
|
3271
|
+
return INVALID;
|
|
3272
|
+
}
|
|
3273
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3274
|
+
status.dirty();
|
|
3275
|
+
}
|
|
3276
|
+
return { status: status.value, value: merged.data };
|
|
3277
|
+
};
|
|
3278
|
+
if (ctx.common.async) {
|
|
3279
|
+
return Promise.all([
|
|
3280
|
+
this._def.left._parseAsync({
|
|
3281
|
+
data: ctx.data,
|
|
3282
|
+
path: ctx.path,
|
|
3283
|
+
parent: ctx
|
|
3284
|
+
}),
|
|
3285
|
+
this._def.right._parseAsync({
|
|
3286
|
+
data: ctx.data,
|
|
3287
|
+
path: ctx.path,
|
|
3288
|
+
parent: ctx
|
|
3289
|
+
})
|
|
3290
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
3291
|
+
} else {
|
|
3292
|
+
return handleParsed(this._def.left._parseSync({
|
|
3293
|
+
data: ctx.data,
|
|
3294
|
+
path: ctx.path,
|
|
3295
|
+
parent: ctx
|
|
3296
|
+
}), this._def.right._parseSync({
|
|
3297
|
+
data: ctx.data,
|
|
3298
|
+
path: ctx.path,
|
|
3299
|
+
parent: ctx
|
|
3300
|
+
}));
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
};
|
|
3304
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3305
|
+
return new ZodIntersection({
|
|
3306
|
+
left,
|
|
3307
|
+
right,
|
|
3308
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3309
|
+
...processCreateParams(params)
|
|
3310
|
+
});
|
|
3311
|
+
};
|
|
3312
|
+
ZodTuple = class ZodTuple extends ZodType {
|
|
3313
|
+
_parse(input) {
|
|
3314
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3315
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3316
|
+
addIssueToContext(ctx, {
|
|
3317
|
+
code: ZodIssueCode.invalid_type,
|
|
3318
|
+
expected: ZodParsedType.array,
|
|
3319
|
+
received: ctx.parsedType
|
|
3320
|
+
});
|
|
3321
|
+
return INVALID;
|
|
3322
|
+
}
|
|
3323
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3324
|
+
addIssueToContext(ctx, {
|
|
3325
|
+
code: ZodIssueCode.too_small,
|
|
3326
|
+
minimum: this._def.items.length,
|
|
3327
|
+
inclusive: true,
|
|
3328
|
+
exact: false,
|
|
3329
|
+
type: "array"
|
|
3330
|
+
});
|
|
3331
|
+
return INVALID;
|
|
3332
|
+
}
|
|
3333
|
+
const rest = this._def.rest;
|
|
3334
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3335
|
+
addIssueToContext(ctx, {
|
|
3336
|
+
code: ZodIssueCode.too_big,
|
|
3337
|
+
maximum: this._def.items.length,
|
|
3338
|
+
inclusive: true,
|
|
3339
|
+
exact: false,
|
|
3340
|
+
type: "array"
|
|
3341
|
+
});
|
|
3342
|
+
status.dirty();
|
|
3343
|
+
}
|
|
3344
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
|
3345
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3346
|
+
if (!schema)
|
|
3347
|
+
return null;
|
|
3348
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3349
|
+
}).filter((x) => !!x);
|
|
3350
|
+
if (ctx.common.async) {
|
|
3351
|
+
return Promise.all(items).then((results) => {
|
|
3352
|
+
return ParseStatus.mergeArray(status, results);
|
|
3353
|
+
});
|
|
3354
|
+
} else {
|
|
3355
|
+
return ParseStatus.mergeArray(status, items);
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
get items() {
|
|
3359
|
+
return this._def.items;
|
|
3360
|
+
}
|
|
3361
|
+
rest(rest) {
|
|
3362
|
+
return new ZodTuple({
|
|
3363
|
+
...this._def,
|
|
3364
|
+
rest
|
|
3365
|
+
});
|
|
3366
|
+
}
|
|
3367
|
+
};
|
|
3368
|
+
ZodTuple.create = (schemas, params) => {
|
|
3369
|
+
if (!Array.isArray(schemas)) {
|
|
3370
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3371
|
+
}
|
|
3372
|
+
return new ZodTuple({
|
|
3373
|
+
items: schemas,
|
|
3374
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3375
|
+
rest: null,
|
|
3376
|
+
...processCreateParams(params)
|
|
3377
|
+
});
|
|
3378
|
+
};
|
|
3379
|
+
ZodRecord = class ZodRecord extends ZodType {
|
|
3380
|
+
get keySchema() {
|
|
3381
|
+
return this._def.keyType;
|
|
3382
|
+
}
|
|
3383
|
+
get valueSchema() {
|
|
3384
|
+
return this._def.valueType;
|
|
3385
|
+
}
|
|
3386
|
+
_parse(input) {
|
|
3387
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3388
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3389
|
+
addIssueToContext(ctx, {
|
|
3390
|
+
code: ZodIssueCode.invalid_type,
|
|
3391
|
+
expected: ZodParsedType.object,
|
|
3392
|
+
received: ctx.parsedType
|
|
3393
|
+
});
|
|
3394
|
+
return INVALID;
|
|
3395
|
+
}
|
|
3396
|
+
const pairs = [];
|
|
3397
|
+
const keyType = this._def.keyType;
|
|
3398
|
+
const valueType = this._def.valueType;
|
|
3399
|
+
for (const key in ctx.data) {
|
|
3400
|
+
pairs.push({
|
|
3401
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3402
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3403
|
+
alwaysSet: key in ctx.data
|
|
3404
|
+
});
|
|
3405
|
+
}
|
|
3406
|
+
if (ctx.common.async) {
|
|
3407
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3408
|
+
} else {
|
|
3409
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
get element() {
|
|
3413
|
+
return this._def.valueType;
|
|
3414
|
+
}
|
|
3415
|
+
static create(first, second, third) {
|
|
3416
|
+
if (second instanceof ZodType) {
|
|
3417
|
+
return new ZodRecord({
|
|
3418
|
+
keyType: first,
|
|
3419
|
+
valueType: second,
|
|
3420
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3421
|
+
...processCreateParams(third)
|
|
3422
|
+
});
|
|
3423
|
+
}
|
|
3424
|
+
return new ZodRecord({
|
|
3425
|
+
keyType: ZodString.create(),
|
|
3426
|
+
valueType: first,
|
|
3427
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3428
|
+
...processCreateParams(second)
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
};
|
|
3432
|
+
ZodMap = class ZodMap extends ZodType {
|
|
3433
|
+
get keySchema() {
|
|
3434
|
+
return this._def.keyType;
|
|
3435
|
+
}
|
|
3436
|
+
get valueSchema() {
|
|
3437
|
+
return this._def.valueType;
|
|
3438
|
+
}
|
|
3439
|
+
_parse(input) {
|
|
3440
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3441
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3442
|
+
addIssueToContext(ctx, {
|
|
3443
|
+
code: ZodIssueCode.invalid_type,
|
|
3444
|
+
expected: ZodParsedType.map,
|
|
3445
|
+
received: ctx.parsedType
|
|
3446
|
+
});
|
|
3447
|
+
return INVALID;
|
|
3448
|
+
}
|
|
3449
|
+
const keyType = this._def.keyType;
|
|
3450
|
+
const valueType = this._def.valueType;
|
|
3451
|
+
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3452
|
+
return {
|
|
3453
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3454
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3455
|
+
};
|
|
3456
|
+
});
|
|
3457
|
+
if (ctx.common.async) {
|
|
3458
|
+
const finalMap = new Map;
|
|
3459
|
+
return Promise.resolve().then(async () => {
|
|
3460
|
+
for (const pair of pairs) {
|
|
3461
|
+
const key = await pair.key;
|
|
3462
|
+
const value = await pair.value;
|
|
3463
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3464
|
+
return INVALID;
|
|
3465
|
+
}
|
|
3466
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3467
|
+
status.dirty();
|
|
3468
|
+
}
|
|
3469
|
+
finalMap.set(key.value, value.value);
|
|
3470
|
+
}
|
|
3471
|
+
return { status: status.value, value: finalMap };
|
|
3472
|
+
});
|
|
3473
|
+
} else {
|
|
3474
|
+
const finalMap = new Map;
|
|
3475
|
+
for (const pair of pairs) {
|
|
3476
|
+
const key = pair.key;
|
|
3477
|
+
const value = pair.value;
|
|
3478
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3479
|
+
return INVALID;
|
|
3480
|
+
}
|
|
3481
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3482
|
+
status.dirty();
|
|
3483
|
+
}
|
|
3484
|
+
finalMap.set(key.value, value.value);
|
|
3485
|
+
}
|
|
3486
|
+
return { status: status.value, value: finalMap };
|
|
3487
|
+
}
|
|
3488
|
+
}
|
|
3489
|
+
};
|
|
3490
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3491
|
+
return new ZodMap({
|
|
3492
|
+
valueType,
|
|
3493
|
+
keyType,
|
|
3494
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3495
|
+
...processCreateParams(params)
|
|
3496
|
+
});
|
|
3497
|
+
};
|
|
3498
|
+
ZodSet = class ZodSet extends ZodType {
|
|
3499
|
+
_parse(input) {
|
|
3500
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3501
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3502
|
+
addIssueToContext(ctx, {
|
|
3503
|
+
code: ZodIssueCode.invalid_type,
|
|
3504
|
+
expected: ZodParsedType.set,
|
|
3505
|
+
received: ctx.parsedType
|
|
3506
|
+
});
|
|
3507
|
+
return INVALID;
|
|
3508
|
+
}
|
|
3509
|
+
const def = this._def;
|
|
3510
|
+
if (def.minSize !== null) {
|
|
3511
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3512
|
+
addIssueToContext(ctx, {
|
|
3513
|
+
code: ZodIssueCode.too_small,
|
|
3514
|
+
minimum: def.minSize.value,
|
|
3515
|
+
type: "set",
|
|
3516
|
+
inclusive: true,
|
|
3517
|
+
exact: false,
|
|
3518
|
+
message: def.minSize.message
|
|
3519
|
+
});
|
|
3520
|
+
status.dirty();
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
if (def.maxSize !== null) {
|
|
3524
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3525
|
+
addIssueToContext(ctx, {
|
|
3526
|
+
code: ZodIssueCode.too_big,
|
|
3527
|
+
maximum: def.maxSize.value,
|
|
3528
|
+
type: "set",
|
|
3529
|
+
inclusive: true,
|
|
3530
|
+
exact: false,
|
|
3531
|
+
message: def.maxSize.message
|
|
3532
|
+
});
|
|
3533
|
+
status.dirty();
|
|
3534
|
+
}
|
|
3535
|
+
}
|
|
3536
|
+
const valueType = this._def.valueType;
|
|
3537
|
+
function finalizeSet(elements2) {
|
|
3538
|
+
const parsedSet = new Set;
|
|
3539
|
+
for (const element of elements2) {
|
|
3540
|
+
if (element.status === "aborted")
|
|
3541
|
+
return INVALID;
|
|
3542
|
+
if (element.status === "dirty")
|
|
3543
|
+
status.dirty();
|
|
3544
|
+
parsedSet.add(element.value);
|
|
3545
|
+
}
|
|
3546
|
+
return { status: status.value, value: parsedSet };
|
|
3547
|
+
}
|
|
3548
|
+
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3549
|
+
if (ctx.common.async) {
|
|
3550
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3551
|
+
} else {
|
|
3552
|
+
return finalizeSet(elements);
|
|
3553
|
+
}
|
|
3554
|
+
}
|
|
3555
|
+
min(minSize, message) {
|
|
3556
|
+
return new ZodSet({
|
|
3557
|
+
...this._def,
|
|
3558
|
+
minSize: { value: minSize, message: errorUtil.toString(message) }
|
|
3559
|
+
});
|
|
3560
|
+
}
|
|
3561
|
+
max(maxSize, message) {
|
|
3562
|
+
return new ZodSet({
|
|
3563
|
+
...this._def,
|
|
3564
|
+
maxSize: { value: maxSize, message: errorUtil.toString(message) }
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
size(size, message) {
|
|
3568
|
+
return this.min(size, message).max(size, message);
|
|
3569
|
+
}
|
|
3570
|
+
nonempty(message) {
|
|
3571
|
+
return this.min(1, message);
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
ZodSet.create = (valueType, params) => {
|
|
3575
|
+
return new ZodSet({
|
|
3576
|
+
valueType,
|
|
3577
|
+
minSize: null,
|
|
3578
|
+
maxSize: null,
|
|
3579
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3580
|
+
...processCreateParams(params)
|
|
3581
|
+
});
|
|
3582
|
+
};
|
|
3583
|
+
ZodFunction = class ZodFunction extends ZodType {
|
|
3584
|
+
constructor() {
|
|
3585
|
+
super(...arguments);
|
|
3586
|
+
this.validate = this.implement;
|
|
3587
|
+
}
|
|
3588
|
+
_parse(input) {
|
|
3589
|
+
const { ctx } = this._processInputParams(input);
|
|
3590
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3591
|
+
addIssueToContext(ctx, {
|
|
3592
|
+
code: ZodIssueCode.invalid_type,
|
|
3593
|
+
expected: ZodParsedType.function,
|
|
3594
|
+
received: ctx.parsedType
|
|
3595
|
+
});
|
|
3596
|
+
return INVALID;
|
|
3597
|
+
}
|
|
3598
|
+
function makeArgsIssue(args, error) {
|
|
3599
|
+
return makeIssue({
|
|
3600
|
+
data: args,
|
|
3601
|
+
path: ctx.path,
|
|
3602
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3603
|
+
issueData: {
|
|
3604
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3605
|
+
argumentsError: error
|
|
3606
|
+
}
|
|
3607
|
+
});
|
|
3608
|
+
}
|
|
3609
|
+
function makeReturnsIssue(returns, error) {
|
|
3610
|
+
return makeIssue({
|
|
3611
|
+
data: returns,
|
|
3612
|
+
path: ctx.path,
|
|
3613
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x) => !!x),
|
|
3614
|
+
issueData: {
|
|
3615
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3616
|
+
returnTypeError: error
|
|
3617
|
+
}
|
|
3618
|
+
});
|
|
3619
|
+
}
|
|
3620
|
+
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3621
|
+
const fn = ctx.data;
|
|
3622
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3623
|
+
const me = this;
|
|
3624
|
+
return OK(async function(...args) {
|
|
3625
|
+
const error = new ZodError([]);
|
|
3626
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3627
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
3628
|
+
throw error;
|
|
3629
|
+
});
|
|
3630
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3631
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3632
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
3633
|
+
throw error;
|
|
3634
|
+
});
|
|
3635
|
+
return parsedReturns;
|
|
3636
|
+
});
|
|
3637
|
+
} else {
|
|
3638
|
+
const me = this;
|
|
3639
|
+
return OK(function(...args) {
|
|
3640
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3641
|
+
if (!parsedArgs.success) {
|
|
3642
|
+
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3643
|
+
}
|
|
3644
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3645
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3646
|
+
if (!parsedReturns.success) {
|
|
3647
|
+
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3648
|
+
}
|
|
3649
|
+
return parsedReturns.data;
|
|
3650
|
+
});
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
parameters() {
|
|
3654
|
+
return this._def.args;
|
|
3655
|
+
}
|
|
3656
|
+
returnType() {
|
|
3657
|
+
return this._def.returns;
|
|
3658
|
+
}
|
|
3659
|
+
args(...items) {
|
|
3660
|
+
return new ZodFunction({
|
|
3661
|
+
...this._def,
|
|
3662
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3663
|
+
});
|
|
3664
|
+
}
|
|
3665
|
+
returns(returnType) {
|
|
3666
|
+
return new ZodFunction({
|
|
3667
|
+
...this._def,
|
|
3668
|
+
returns: returnType
|
|
3669
|
+
});
|
|
3670
|
+
}
|
|
3671
|
+
implement(func) {
|
|
3672
|
+
const validatedFunc = this.parse(func);
|
|
3673
|
+
return validatedFunc;
|
|
3674
|
+
}
|
|
3675
|
+
strictImplement(func) {
|
|
3676
|
+
const validatedFunc = this.parse(func);
|
|
3677
|
+
return validatedFunc;
|
|
3678
|
+
}
|
|
3679
|
+
static create(args, returns, params) {
|
|
3680
|
+
return new ZodFunction({
|
|
3681
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3682
|
+
returns: returns || ZodUnknown.create(),
|
|
3683
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3684
|
+
...processCreateParams(params)
|
|
3685
|
+
});
|
|
3686
|
+
}
|
|
3687
|
+
};
|
|
3688
|
+
ZodLazy = class ZodLazy extends ZodType {
|
|
3689
|
+
get schema() {
|
|
3690
|
+
return this._def.getter();
|
|
3691
|
+
}
|
|
3692
|
+
_parse(input) {
|
|
3693
|
+
const { ctx } = this._processInputParams(input);
|
|
3694
|
+
const lazySchema = this._def.getter();
|
|
3695
|
+
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3696
|
+
}
|
|
3697
|
+
};
|
|
3698
|
+
ZodLazy.create = (getter, params) => {
|
|
3699
|
+
return new ZodLazy({
|
|
3700
|
+
getter,
|
|
3701
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3702
|
+
...processCreateParams(params)
|
|
3703
|
+
});
|
|
3704
|
+
};
|
|
3705
|
+
ZodLiteral = class ZodLiteral extends ZodType {
|
|
3706
|
+
_parse(input) {
|
|
3707
|
+
if (input.data !== this._def.value) {
|
|
3708
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3709
|
+
addIssueToContext(ctx, {
|
|
3710
|
+
received: ctx.data,
|
|
3711
|
+
code: ZodIssueCode.invalid_literal,
|
|
3712
|
+
expected: this._def.value
|
|
3713
|
+
});
|
|
3714
|
+
return INVALID;
|
|
3715
|
+
}
|
|
3716
|
+
return { status: "valid", value: input.data };
|
|
3717
|
+
}
|
|
3718
|
+
get value() {
|
|
3719
|
+
return this._def.value;
|
|
3720
|
+
}
|
|
3721
|
+
};
|
|
3722
|
+
ZodLiteral.create = (value, params) => {
|
|
3723
|
+
return new ZodLiteral({
|
|
3724
|
+
value,
|
|
3725
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3726
|
+
...processCreateParams(params)
|
|
3727
|
+
});
|
|
3728
|
+
};
|
|
3729
|
+
ZodEnum = class ZodEnum extends ZodType {
|
|
3730
|
+
constructor() {
|
|
3731
|
+
super(...arguments);
|
|
3732
|
+
_ZodEnum_cache.set(this, undefined);
|
|
3733
|
+
}
|
|
3734
|
+
_parse(input) {
|
|
3735
|
+
if (typeof input.data !== "string") {
|
|
3736
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3737
|
+
const expectedValues = this._def.values;
|
|
3738
|
+
addIssueToContext(ctx, {
|
|
3739
|
+
expected: util.joinValues(expectedValues),
|
|
3740
|
+
received: ctx.parsedType,
|
|
3741
|
+
code: ZodIssueCode.invalid_type
|
|
3742
|
+
});
|
|
3743
|
+
return INVALID;
|
|
3744
|
+
}
|
|
3745
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
|
3746
|
+
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
|
3747
|
+
}
|
|
3748
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
|
3749
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3750
|
+
const expectedValues = this._def.values;
|
|
3751
|
+
addIssueToContext(ctx, {
|
|
3752
|
+
received: ctx.data,
|
|
3753
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3754
|
+
options: expectedValues
|
|
3755
|
+
});
|
|
3756
|
+
return INVALID;
|
|
3757
|
+
}
|
|
3758
|
+
return OK(input.data);
|
|
3759
|
+
}
|
|
3760
|
+
get options() {
|
|
3761
|
+
return this._def.values;
|
|
3762
|
+
}
|
|
3763
|
+
get enum() {
|
|
3764
|
+
const enumValues = {};
|
|
3765
|
+
for (const val of this._def.values) {
|
|
3766
|
+
enumValues[val] = val;
|
|
3767
|
+
}
|
|
3768
|
+
return enumValues;
|
|
3769
|
+
}
|
|
3770
|
+
get Values() {
|
|
3771
|
+
const enumValues = {};
|
|
3772
|
+
for (const val of this._def.values) {
|
|
3773
|
+
enumValues[val] = val;
|
|
3774
|
+
}
|
|
3775
|
+
return enumValues;
|
|
3776
|
+
}
|
|
3777
|
+
get Enum() {
|
|
3778
|
+
const enumValues = {};
|
|
3779
|
+
for (const val of this._def.values) {
|
|
3780
|
+
enumValues[val] = val;
|
|
3781
|
+
}
|
|
3782
|
+
return enumValues;
|
|
3783
|
+
}
|
|
3784
|
+
extract(values, newDef = this._def) {
|
|
3785
|
+
return ZodEnum.create(values, {
|
|
3786
|
+
...this._def,
|
|
3787
|
+
...newDef
|
|
3788
|
+
});
|
|
3789
|
+
}
|
|
3790
|
+
exclude(values, newDef = this._def) {
|
|
3791
|
+
return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3792
|
+
...this._def,
|
|
3793
|
+
...newDef
|
|
3794
|
+
});
|
|
3795
|
+
}
|
|
3796
|
+
};
|
|
3797
|
+
_ZodEnum_cache = new WeakMap;
|
|
3798
|
+
ZodEnum.create = createZodEnum;
|
|
3799
|
+
ZodNativeEnum = class ZodNativeEnum extends ZodType {
|
|
3800
|
+
constructor() {
|
|
3801
|
+
super(...arguments);
|
|
3802
|
+
_ZodNativeEnum_cache.set(this, undefined);
|
|
3803
|
+
}
|
|
3804
|
+
_parse(input) {
|
|
3805
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3806
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3807
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3808
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3809
|
+
addIssueToContext(ctx, {
|
|
3810
|
+
expected: util.joinValues(expectedValues),
|
|
3811
|
+
received: ctx.parsedType,
|
|
3812
|
+
code: ZodIssueCode.invalid_type
|
|
3813
|
+
});
|
|
3814
|
+
return INVALID;
|
|
3815
|
+
}
|
|
3816
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
|
3817
|
+
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
|
|
3818
|
+
}
|
|
3819
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
|
3820
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3821
|
+
addIssueToContext(ctx, {
|
|
3822
|
+
received: ctx.data,
|
|
3823
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3824
|
+
options: expectedValues
|
|
3825
|
+
});
|
|
3826
|
+
return INVALID;
|
|
3827
|
+
}
|
|
3828
|
+
return OK(input.data);
|
|
3829
|
+
}
|
|
3830
|
+
get enum() {
|
|
3831
|
+
return this._def.values;
|
|
3832
|
+
}
|
|
3833
|
+
};
|
|
3834
|
+
_ZodNativeEnum_cache = new WeakMap;
|
|
3835
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3836
|
+
return new ZodNativeEnum({
|
|
3837
|
+
values,
|
|
3838
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3839
|
+
...processCreateParams(params)
|
|
3840
|
+
});
|
|
3841
|
+
};
|
|
3842
|
+
ZodPromise = class ZodPromise extends ZodType {
|
|
3843
|
+
unwrap() {
|
|
3844
|
+
return this._def.type;
|
|
3845
|
+
}
|
|
3846
|
+
_parse(input) {
|
|
3847
|
+
const { ctx } = this._processInputParams(input);
|
|
3848
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3849
|
+
addIssueToContext(ctx, {
|
|
3850
|
+
code: ZodIssueCode.invalid_type,
|
|
3851
|
+
expected: ZodParsedType.promise,
|
|
3852
|
+
received: ctx.parsedType
|
|
3853
|
+
});
|
|
3854
|
+
return INVALID;
|
|
3855
|
+
}
|
|
3856
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3857
|
+
return OK(promisified.then((data) => {
|
|
3858
|
+
return this._def.type.parseAsync(data, {
|
|
3859
|
+
path: ctx.path,
|
|
3860
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3861
|
+
});
|
|
3862
|
+
}));
|
|
3863
|
+
}
|
|
3864
|
+
};
|
|
3865
|
+
ZodPromise.create = (schema, params) => {
|
|
3866
|
+
return new ZodPromise({
|
|
3867
|
+
type: schema,
|
|
3868
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3869
|
+
...processCreateParams(params)
|
|
3870
|
+
});
|
|
3871
|
+
};
|
|
3872
|
+
ZodEffects = class ZodEffects extends ZodType {
|
|
3873
|
+
innerType() {
|
|
3874
|
+
return this._def.schema;
|
|
3875
|
+
}
|
|
3876
|
+
sourceType() {
|
|
3877
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3878
|
+
}
|
|
3879
|
+
_parse(input) {
|
|
3880
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3881
|
+
const effect = this._def.effect || null;
|
|
3882
|
+
const checkCtx = {
|
|
3883
|
+
addIssue: (arg) => {
|
|
3884
|
+
addIssueToContext(ctx, arg);
|
|
3885
|
+
if (arg.fatal) {
|
|
3886
|
+
status.abort();
|
|
3887
|
+
} else {
|
|
3888
|
+
status.dirty();
|
|
3889
|
+
}
|
|
3890
|
+
},
|
|
3891
|
+
get path() {
|
|
3892
|
+
return ctx.path;
|
|
3893
|
+
}
|
|
3894
|
+
};
|
|
3895
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3896
|
+
if (effect.type === "preprocess") {
|
|
3897
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3898
|
+
if (ctx.common.async) {
|
|
3899
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3900
|
+
if (status.value === "aborted")
|
|
3901
|
+
return INVALID;
|
|
3902
|
+
const result = await this._def.schema._parseAsync({
|
|
3903
|
+
data: processed2,
|
|
3904
|
+
path: ctx.path,
|
|
3905
|
+
parent: ctx
|
|
3906
|
+
});
|
|
3907
|
+
if (result.status === "aborted")
|
|
3908
|
+
return INVALID;
|
|
3909
|
+
if (result.status === "dirty")
|
|
3910
|
+
return DIRTY(result.value);
|
|
3911
|
+
if (status.value === "dirty")
|
|
3912
|
+
return DIRTY(result.value);
|
|
3913
|
+
return result;
|
|
3914
|
+
});
|
|
3915
|
+
} else {
|
|
3916
|
+
if (status.value === "aborted")
|
|
3917
|
+
return INVALID;
|
|
3918
|
+
const result = this._def.schema._parseSync({
|
|
3919
|
+
data: processed,
|
|
3920
|
+
path: ctx.path,
|
|
3921
|
+
parent: ctx
|
|
3922
|
+
});
|
|
3923
|
+
if (result.status === "aborted")
|
|
3924
|
+
return INVALID;
|
|
3925
|
+
if (result.status === "dirty")
|
|
3926
|
+
return DIRTY(result.value);
|
|
3927
|
+
if (status.value === "dirty")
|
|
3928
|
+
return DIRTY(result.value);
|
|
3929
|
+
return result;
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
if (effect.type === "refinement") {
|
|
3933
|
+
const executeRefinement = (acc) => {
|
|
3934
|
+
const result = effect.refinement(acc, checkCtx);
|
|
3935
|
+
if (ctx.common.async) {
|
|
3936
|
+
return Promise.resolve(result);
|
|
3937
|
+
}
|
|
3938
|
+
if (result instanceof Promise) {
|
|
3939
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3940
|
+
}
|
|
3941
|
+
return acc;
|
|
3942
|
+
};
|
|
3943
|
+
if (ctx.common.async === false) {
|
|
3944
|
+
const inner = this._def.schema._parseSync({
|
|
3945
|
+
data: ctx.data,
|
|
3946
|
+
path: ctx.path,
|
|
3947
|
+
parent: ctx
|
|
3948
|
+
});
|
|
3949
|
+
if (inner.status === "aborted")
|
|
3950
|
+
return INVALID;
|
|
3951
|
+
if (inner.status === "dirty")
|
|
3952
|
+
status.dirty();
|
|
3953
|
+
executeRefinement(inner.value);
|
|
3954
|
+
return { status: status.value, value: inner.value };
|
|
3955
|
+
} else {
|
|
3956
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
3957
|
+
if (inner.status === "aborted")
|
|
3958
|
+
return INVALID;
|
|
3959
|
+
if (inner.status === "dirty")
|
|
3960
|
+
status.dirty();
|
|
3961
|
+
return executeRefinement(inner.value).then(() => {
|
|
3962
|
+
return { status: status.value, value: inner.value };
|
|
3963
|
+
});
|
|
3964
|
+
});
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
if (effect.type === "transform") {
|
|
3968
|
+
if (ctx.common.async === false) {
|
|
3969
|
+
const base = this._def.schema._parseSync({
|
|
3970
|
+
data: ctx.data,
|
|
3971
|
+
path: ctx.path,
|
|
3972
|
+
parent: ctx
|
|
3973
|
+
});
|
|
3974
|
+
if (!isValid(base))
|
|
3975
|
+
return base;
|
|
3976
|
+
const result = effect.transform(base.value, checkCtx);
|
|
3977
|
+
if (result instanceof Promise) {
|
|
3978
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3979
|
+
}
|
|
3980
|
+
return { status: status.value, value: result };
|
|
3981
|
+
} else {
|
|
3982
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
3983
|
+
if (!isValid(base))
|
|
3984
|
+
return base;
|
|
3985
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3986
|
+
status: status.value,
|
|
3987
|
+
value: result
|
|
3988
|
+
}));
|
|
3989
|
+
});
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
util.assertNever(effect);
|
|
3993
|
+
}
|
|
3994
|
+
};
|
|
3995
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
3996
|
+
return new ZodEffects({
|
|
3997
|
+
schema,
|
|
3998
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3999
|
+
effect,
|
|
4000
|
+
...processCreateParams(params)
|
|
4001
|
+
});
|
|
4002
|
+
};
|
|
4003
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
4004
|
+
return new ZodEffects({
|
|
4005
|
+
schema,
|
|
4006
|
+
effect: { type: "preprocess", transform: preprocess },
|
|
4007
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4008
|
+
...processCreateParams(params)
|
|
4009
|
+
});
|
|
4010
|
+
};
|
|
4011
|
+
ZodOptional = class ZodOptional extends ZodType {
|
|
4012
|
+
_parse(input) {
|
|
4013
|
+
const parsedType = this._getType(input);
|
|
4014
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
4015
|
+
return OK(undefined);
|
|
4016
|
+
}
|
|
4017
|
+
return this._def.innerType._parse(input);
|
|
4018
|
+
}
|
|
4019
|
+
unwrap() {
|
|
4020
|
+
return this._def.innerType;
|
|
4021
|
+
}
|
|
4022
|
+
};
|
|
4023
|
+
ZodOptional.create = (type, params) => {
|
|
4024
|
+
return new ZodOptional({
|
|
4025
|
+
innerType: type,
|
|
4026
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
4027
|
+
...processCreateParams(params)
|
|
4028
|
+
});
|
|
4029
|
+
};
|
|
4030
|
+
ZodNullable = class ZodNullable extends ZodType {
|
|
4031
|
+
_parse(input) {
|
|
4032
|
+
const parsedType = this._getType(input);
|
|
4033
|
+
if (parsedType === ZodParsedType.null) {
|
|
4034
|
+
return OK(null);
|
|
4035
|
+
}
|
|
4036
|
+
return this._def.innerType._parse(input);
|
|
4037
|
+
}
|
|
4038
|
+
unwrap() {
|
|
4039
|
+
return this._def.innerType;
|
|
4040
|
+
}
|
|
4041
|
+
};
|
|
4042
|
+
ZodNullable.create = (type, params) => {
|
|
4043
|
+
return new ZodNullable({
|
|
4044
|
+
innerType: type,
|
|
4045
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
4046
|
+
...processCreateParams(params)
|
|
4047
|
+
});
|
|
4048
|
+
};
|
|
4049
|
+
ZodDefault = class ZodDefault extends ZodType {
|
|
4050
|
+
_parse(input) {
|
|
4051
|
+
const { ctx } = this._processInputParams(input);
|
|
4052
|
+
let data = ctx.data;
|
|
4053
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
4054
|
+
data = this._def.defaultValue();
|
|
4055
|
+
}
|
|
4056
|
+
return this._def.innerType._parse({
|
|
4057
|
+
data,
|
|
4058
|
+
path: ctx.path,
|
|
4059
|
+
parent: ctx
|
|
4060
|
+
});
|
|
4061
|
+
}
|
|
4062
|
+
removeDefault() {
|
|
4063
|
+
return this._def.innerType;
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
ZodDefault.create = (type, params) => {
|
|
4067
|
+
return new ZodDefault({
|
|
4068
|
+
innerType: type,
|
|
4069
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
4070
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
4071
|
+
...processCreateParams(params)
|
|
4072
|
+
});
|
|
4073
|
+
};
|
|
4074
|
+
ZodCatch = class ZodCatch extends ZodType {
|
|
4075
|
+
_parse(input) {
|
|
4076
|
+
const { ctx } = this._processInputParams(input);
|
|
4077
|
+
const newCtx = {
|
|
4078
|
+
...ctx,
|
|
4079
|
+
common: {
|
|
4080
|
+
...ctx.common,
|
|
4081
|
+
issues: []
|
|
4082
|
+
}
|
|
4083
|
+
};
|
|
4084
|
+
const result = this._def.innerType._parse({
|
|
4085
|
+
data: newCtx.data,
|
|
4086
|
+
path: newCtx.path,
|
|
4087
|
+
parent: {
|
|
4088
|
+
...newCtx
|
|
4089
|
+
}
|
|
4090
|
+
});
|
|
4091
|
+
if (isAsync(result)) {
|
|
4092
|
+
return result.then((result2) => {
|
|
4093
|
+
return {
|
|
4094
|
+
status: "valid",
|
|
4095
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
4096
|
+
get error() {
|
|
4097
|
+
return new ZodError(newCtx.common.issues);
|
|
4098
|
+
},
|
|
4099
|
+
input: newCtx.data
|
|
4100
|
+
})
|
|
4101
|
+
};
|
|
4102
|
+
});
|
|
4103
|
+
} else {
|
|
4104
|
+
return {
|
|
4105
|
+
status: "valid",
|
|
4106
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
4107
|
+
get error() {
|
|
4108
|
+
return new ZodError(newCtx.common.issues);
|
|
4109
|
+
},
|
|
4110
|
+
input: newCtx.data
|
|
4111
|
+
})
|
|
4112
|
+
};
|
|
4113
|
+
}
|
|
4114
|
+
}
|
|
4115
|
+
removeCatch() {
|
|
4116
|
+
return this._def.innerType;
|
|
4117
|
+
}
|
|
4118
|
+
};
|
|
4119
|
+
ZodCatch.create = (type, params) => {
|
|
4120
|
+
return new ZodCatch({
|
|
4121
|
+
innerType: type,
|
|
4122
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
4123
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
4124
|
+
...processCreateParams(params)
|
|
4125
|
+
});
|
|
4126
|
+
};
|
|
4127
|
+
ZodNaN = class ZodNaN extends ZodType {
|
|
4128
|
+
_parse(input) {
|
|
4129
|
+
const parsedType = this._getType(input);
|
|
4130
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
4131
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4132
|
+
addIssueToContext(ctx, {
|
|
4133
|
+
code: ZodIssueCode.invalid_type,
|
|
4134
|
+
expected: ZodParsedType.nan,
|
|
4135
|
+
received: ctx.parsedType
|
|
4136
|
+
});
|
|
4137
|
+
return INVALID;
|
|
4138
|
+
}
|
|
4139
|
+
return { status: "valid", value: input.data };
|
|
4140
|
+
}
|
|
4141
|
+
};
|
|
4142
|
+
ZodNaN.create = (params) => {
|
|
4143
|
+
return new ZodNaN({
|
|
4144
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
4145
|
+
...processCreateParams(params)
|
|
4146
|
+
});
|
|
4147
|
+
};
|
|
4148
|
+
BRAND = Symbol("zod_brand");
|
|
4149
|
+
ZodBranded = class ZodBranded extends ZodType {
|
|
4150
|
+
_parse(input) {
|
|
4151
|
+
const { ctx } = this._processInputParams(input);
|
|
4152
|
+
const data = ctx.data;
|
|
4153
|
+
return this._def.type._parse({
|
|
4154
|
+
data,
|
|
4155
|
+
path: ctx.path,
|
|
4156
|
+
parent: ctx
|
|
4157
|
+
});
|
|
4158
|
+
}
|
|
4159
|
+
unwrap() {
|
|
4160
|
+
return this._def.type;
|
|
4161
|
+
}
|
|
4162
|
+
};
|
|
4163
|
+
ZodPipeline = class ZodPipeline extends ZodType {
|
|
4164
|
+
_parse(input) {
|
|
4165
|
+
const { status, ctx } = this._processInputParams(input);
|
|
4166
|
+
if (ctx.common.async) {
|
|
4167
|
+
const handleAsync = async () => {
|
|
4168
|
+
const inResult = await this._def.in._parseAsync({
|
|
4169
|
+
data: ctx.data,
|
|
4170
|
+
path: ctx.path,
|
|
4171
|
+
parent: ctx
|
|
4172
|
+
});
|
|
4173
|
+
if (inResult.status === "aborted")
|
|
4174
|
+
return INVALID;
|
|
4175
|
+
if (inResult.status === "dirty") {
|
|
4176
|
+
status.dirty();
|
|
4177
|
+
return DIRTY(inResult.value);
|
|
4178
|
+
} else {
|
|
4179
|
+
return this._def.out._parseAsync({
|
|
4180
|
+
data: inResult.value,
|
|
4181
|
+
path: ctx.path,
|
|
4182
|
+
parent: ctx
|
|
4183
|
+
});
|
|
4184
|
+
}
|
|
4185
|
+
};
|
|
4186
|
+
return handleAsync();
|
|
4187
|
+
} else {
|
|
4188
|
+
const inResult = this._def.in._parseSync({
|
|
4189
|
+
data: ctx.data,
|
|
4190
|
+
path: ctx.path,
|
|
4191
|
+
parent: ctx
|
|
4192
|
+
});
|
|
4193
|
+
if (inResult.status === "aborted")
|
|
4194
|
+
return INVALID;
|
|
4195
|
+
if (inResult.status === "dirty") {
|
|
4196
|
+
status.dirty();
|
|
4197
|
+
return {
|
|
4198
|
+
status: "dirty",
|
|
4199
|
+
value: inResult.value
|
|
4200
|
+
};
|
|
4201
|
+
} else {
|
|
4202
|
+
return this._def.out._parseSync({
|
|
4203
|
+
data: inResult.value,
|
|
4204
|
+
path: ctx.path,
|
|
4205
|
+
parent: ctx
|
|
4206
|
+
});
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
static create(a, b) {
|
|
4211
|
+
return new ZodPipeline({
|
|
4212
|
+
in: a,
|
|
4213
|
+
out: b,
|
|
4214
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
4215
|
+
});
|
|
4216
|
+
}
|
|
4217
|
+
};
|
|
4218
|
+
ZodReadonly = class ZodReadonly extends ZodType {
|
|
4219
|
+
_parse(input) {
|
|
4220
|
+
const result = this._def.innerType._parse(input);
|
|
4221
|
+
const freeze = (data) => {
|
|
4222
|
+
if (isValid(data)) {
|
|
4223
|
+
data.value = Object.freeze(data.value);
|
|
4224
|
+
}
|
|
4225
|
+
return data;
|
|
4226
|
+
};
|
|
4227
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
4228
|
+
}
|
|
4229
|
+
unwrap() {
|
|
4230
|
+
return this._def.innerType;
|
|
4231
|
+
}
|
|
4232
|
+
};
|
|
4233
|
+
ZodReadonly.create = (type, params) => {
|
|
4234
|
+
return new ZodReadonly({
|
|
4235
|
+
innerType: type,
|
|
4236
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
4237
|
+
...processCreateParams(params)
|
|
4238
|
+
});
|
|
4239
|
+
};
|
|
4240
|
+
late = {
|
|
4241
|
+
object: ZodObject.lazycreate
|
|
4242
|
+
};
|
|
4243
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
4244
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
4245
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
4246
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
4247
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
4248
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
4249
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
4250
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
4251
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
4252
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
4253
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
4254
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
4255
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
4256
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
4257
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
4258
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
4259
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
4260
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
4261
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4262
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4263
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4264
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4265
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4266
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4267
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4268
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4269
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4270
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4271
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4272
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4273
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4274
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4275
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4276
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4277
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4278
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4279
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4280
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4281
|
+
stringType = ZodString.create;
|
|
4282
|
+
numberType = ZodNumber.create;
|
|
4283
|
+
nanType = ZodNaN.create;
|
|
4284
|
+
bigIntType = ZodBigInt.create;
|
|
4285
|
+
booleanType = ZodBoolean.create;
|
|
4286
|
+
dateType = ZodDate.create;
|
|
4287
|
+
symbolType = ZodSymbol.create;
|
|
4288
|
+
undefinedType = ZodUndefined.create;
|
|
4289
|
+
nullType = ZodNull.create;
|
|
4290
|
+
anyType = ZodAny.create;
|
|
4291
|
+
unknownType = ZodUnknown.create;
|
|
4292
|
+
neverType = ZodNever.create;
|
|
4293
|
+
voidType = ZodVoid.create;
|
|
4294
|
+
arrayType = ZodArray.create;
|
|
4295
|
+
objectType = ZodObject.create;
|
|
4296
|
+
strictObjectType = ZodObject.strictCreate;
|
|
4297
|
+
unionType = ZodUnion.create;
|
|
4298
|
+
discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4299
|
+
intersectionType = ZodIntersection.create;
|
|
4300
|
+
tupleType = ZodTuple.create;
|
|
4301
|
+
recordType = ZodRecord.create;
|
|
4302
|
+
mapType = ZodMap.create;
|
|
4303
|
+
setType = ZodSet.create;
|
|
4304
|
+
functionType = ZodFunction.create;
|
|
4305
|
+
lazyType = ZodLazy.create;
|
|
4306
|
+
literalType = ZodLiteral.create;
|
|
4307
|
+
enumType = ZodEnum.create;
|
|
4308
|
+
nativeEnumType = ZodNativeEnum.create;
|
|
4309
|
+
promiseType = ZodPromise.create;
|
|
4310
|
+
effectsType = ZodEffects.create;
|
|
4311
|
+
optionalType = ZodOptional.create;
|
|
4312
|
+
nullableType = ZodNullable.create;
|
|
4313
|
+
preprocessType = ZodEffects.createWithPreprocess;
|
|
4314
|
+
pipelineType = ZodPipeline.create;
|
|
4315
|
+
coerce = {
|
|
4316
|
+
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
4317
|
+
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
4318
|
+
boolean: (arg) => ZodBoolean.create({
|
|
4319
|
+
...arg,
|
|
4320
|
+
coerce: true
|
|
4321
|
+
}),
|
|
4322
|
+
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
4323
|
+
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
4324
|
+
};
|
|
4325
|
+
NEVER = INVALID;
|
|
4326
|
+
});
|
|
4327
|
+
|
|
4328
|
+
// ../../node_modules/zod/dist/esm/v3/external.js
|
|
4329
|
+
var exports_external = {};
|
|
4330
|
+
__export(exports_external, {
|
|
4331
|
+
void: () => voidType,
|
|
4332
|
+
util: () => util,
|
|
4333
|
+
unknown: () => unknownType,
|
|
4334
|
+
union: () => unionType,
|
|
4335
|
+
undefined: () => undefinedType,
|
|
4336
|
+
tuple: () => tupleType,
|
|
4337
|
+
transformer: () => effectsType,
|
|
4338
|
+
symbol: () => symbolType,
|
|
4339
|
+
string: () => stringType,
|
|
4340
|
+
strictObject: () => strictObjectType,
|
|
4341
|
+
setErrorMap: () => setErrorMap,
|
|
4342
|
+
set: () => setType,
|
|
4343
|
+
record: () => recordType,
|
|
4344
|
+
quotelessJson: () => quotelessJson,
|
|
4345
|
+
promise: () => promiseType,
|
|
4346
|
+
preprocess: () => preprocessType,
|
|
4347
|
+
pipeline: () => pipelineType,
|
|
4348
|
+
ostring: () => ostring,
|
|
4349
|
+
optional: () => optionalType,
|
|
4350
|
+
onumber: () => onumber,
|
|
4351
|
+
oboolean: () => oboolean,
|
|
4352
|
+
objectUtil: () => objectUtil,
|
|
4353
|
+
object: () => objectType,
|
|
4354
|
+
number: () => numberType,
|
|
4355
|
+
nullable: () => nullableType,
|
|
4356
|
+
null: () => nullType,
|
|
4357
|
+
never: () => neverType,
|
|
4358
|
+
nativeEnum: () => nativeEnumType,
|
|
4359
|
+
nan: () => nanType,
|
|
4360
|
+
map: () => mapType,
|
|
4361
|
+
makeIssue: () => makeIssue,
|
|
4362
|
+
literal: () => literalType,
|
|
4363
|
+
lazy: () => lazyType,
|
|
4364
|
+
late: () => late,
|
|
4365
|
+
isValid: () => isValid,
|
|
4366
|
+
isDirty: () => isDirty,
|
|
4367
|
+
isAsync: () => isAsync,
|
|
4368
|
+
isAborted: () => isAborted,
|
|
4369
|
+
intersection: () => intersectionType,
|
|
4370
|
+
instanceof: () => instanceOfType,
|
|
4371
|
+
getParsedType: () => getParsedType,
|
|
4372
|
+
getErrorMap: () => getErrorMap,
|
|
4373
|
+
function: () => functionType,
|
|
4374
|
+
enum: () => enumType,
|
|
4375
|
+
effect: () => effectsType,
|
|
4376
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
4377
|
+
defaultErrorMap: () => en_default,
|
|
4378
|
+
datetimeRegex: () => datetimeRegex,
|
|
4379
|
+
date: () => dateType,
|
|
4380
|
+
custom: () => custom,
|
|
4381
|
+
coerce: () => coerce,
|
|
4382
|
+
boolean: () => booleanType,
|
|
4383
|
+
bigint: () => bigIntType,
|
|
4384
|
+
array: () => arrayType,
|
|
4385
|
+
any: () => anyType,
|
|
4386
|
+
addIssueToContext: () => addIssueToContext,
|
|
4387
|
+
ZodVoid: () => ZodVoid,
|
|
4388
|
+
ZodUnknown: () => ZodUnknown,
|
|
4389
|
+
ZodUnion: () => ZodUnion,
|
|
4390
|
+
ZodUndefined: () => ZodUndefined,
|
|
4391
|
+
ZodType: () => ZodType,
|
|
4392
|
+
ZodTuple: () => ZodTuple,
|
|
4393
|
+
ZodTransformer: () => ZodEffects,
|
|
4394
|
+
ZodSymbol: () => ZodSymbol,
|
|
4395
|
+
ZodString: () => ZodString,
|
|
4396
|
+
ZodSet: () => ZodSet,
|
|
4397
|
+
ZodSchema: () => ZodType,
|
|
4398
|
+
ZodRecord: () => ZodRecord,
|
|
4399
|
+
ZodReadonly: () => ZodReadonly,
|
|
4400
|
+
ZodPromise: () => ZodPromise,
|
|
4401
|
+
ZodPipeline: () => ZodPipeline,
|
|
4402
|
+
ZodParsedType: () => ZodParsedType,
|
|
4403
|
+
ZodOptional: () => ZodOptional,
|
|
4404
|
+
ZodObject: () => ZodObject,
|
|
4405
|
+
ZodNumber: () => ZodNumber,
|
|
4406
|
+
ZodNullable: () => ZodNullable,
|
|
4407
|
+
ZodNull: () => ZodNull,
|
|
4408
|
+
ZodNever: () => ZodNever,
|
|
4409
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
4410
|
+
ZodNaN: () => ZodNaN,
|
|
4411
|
+
ZodMap: () => ZodMap,
|
|
4412
|
+
ZodLiteral: () => ZodLiteral,
|
|
4413
|
+
ZodLazy: () => ZodLazy,
|
|
4414
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
4415
|
+
ZodIntersection: () => ZodIntersection,
|
|
4416
|
+
ZodFunction: () => ZodFunction,
|
|
4417
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
4418
|
+
ZodError: () => ZodError,
|
|
4419
|
+
ZodEnum: () => ZodEnum,
|
|
4420
|
+
ZodEffects: () => ZodEffects,
|
|
4421
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
4422
|
+
ZodDefault: () => ZodDefault,
|
|
4423
|
+
ZodDate: () => ZodDate,
|
|
4424
|
+
ZodCatch: () => ZodCatch,
|
|
4425
|
+
ZodBranded: () => ZodBranded,
|
|
4426
|
+
ZodBoolean: () => ZodBoolean,
|
|
4427
|
+
ZodBigInt: () => ZodBigInt,
|
|
4428
|
+
ZodArray: () => ZodArray,
|
|
4429
|
+
ZodAny: () => ZodAny,
|
|
4430
|
+
Schema: () => ZodType,
|
|
4431
|
+
ParseStatus: () => ParseStatus,
|
|
4432
|
+
OK: () => OK,
|
|
4433
|
+
NEVER: () => NEVER,
|
|
4434
|
+
INVALID: () => INVALID,
|
|
4435
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
4436
|
+
DIRTY: () => DIRTY,
|
|
4437
|
+
BRAND: () => BRAND
|
|
4438
|
+
});
|
|
4439
|
+
var init_external = __esm(() => {
|
|
4440
|
+
init_errors2();
|
|
4441
|
+
init_parseUtil();
|
|
4442
|
+
init_typeAliases();
|
|
4443
|
+
init_util();
|
|
4444
|
+
init_types();
|
|
4445
|
+
init_ZodError();
|
|
4446
|
+
});
|
|
4447
|
+
|
|
4448
|
+
// ../../node_modules/zod/dist/esm/v3/index.js
|
|
4449
|
+
var init_v3 = __esm(() => {
|
|
4450
|
+
init_external();
|
|
4451
|
+
init_external();
|
|
4452
|
+
});
|
|
4453
|
+
|
|
4454
|
+
// ../../node_modules/zod/dist/esm/index.js
|
|
4455
|
+
var init_esm = __esm(() => {
|
|
4456
|
+
init_v3();
|
|
4457
|
+
});
|
|
4458
|
+
|
|
4459
|
+
// ../../node_modules/drizzle-zod/index.mjs
|
|
4460
|
+
import { isTable, getTableColumns, getViewSelectedFields, is, Column, SQL, isView } from "drizzle-orm";
|
|
4461
|
+
function isColumnType(column, columnTypes) {
|
|
4462
|
+
return columnTypes.includes(column.columnType);
|
|
4463
|
+
}
|
|
4464
|
+
function isWithEnum(column) {
|
|
4465
|
+
return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
|
|
4466
|
+
}
|
|
4467
|
+
function columnToSchema(column, factory) {
|
|
4468
|
+
const z$1 = factory?.zodInstance ?? exports_external;
|
|
4469
|
+
const coerce2 = factory?.coerce ?? {};
|
|
4470
|
+
let schema;
|
|
4471
|
+
if (isWithEnum(column)) {
|
|
4472
|
+
schema = column.enumValues.length ? z$1.enum(column.enumValues) : z$1.string();
|
|
4473
|
+
}
|
|
4474
|
+
if (!schema) {
|
|
4475
|
+
if (isColumnType(column, ["PgGeometry", "PgPointTuple"])) {
|
|
4476
|
+
schema = z$1.tuple([z$1.number(), z$1.number()]);
|
|
4477
|
+
} else if (isColumnType(column, ["PgGeometryObject", "PgPointObject"])) {
|
|
4478
|
+
schema = z$1.object({ x: z$1.number(), y: z$1.number() });
|
|
4479
|
+
} else if (isColumnType(column, ["PgHalfVector", "PgVector"])) {
|
|
4480
|
+
schema = z$1.array(z$1.number());
|
|
4481
|
+
schema = column.dimensions ? schema.length(column.dimensions) : schema;
|
|
4482
|
+
} else if (isColumnType(column, ["PgLine"])) {
|
|
4483
|
+
schema = z$1.tuple([z$1.number(), z$1.number(), z$1.number()]);
|
|
4484
|
+
} else if (isColumnType(column, ["PgLineABC"])) {
|
|
4485
|
+
schema = z$1.object({
|
|
4486
|
+
a: z$1.number(),
|
|
4487
|
+
b: z$1.number(),
|
|
4488
|
+
c: z$1.number()
|
|
4489
|
+
});
|
|
4490
|
+
} else if (isColumnType(column, ["PgArray"])) {
|
|
4491
|
+
schema = z$1.array(columnToSchema(column.baseColumn, z$1));
|
|
4492
|
+
schema = column.size ? schema.length(column.size) : schema;
|
|
4493
|
+
} else if (column.dataType === "array") {
|
|
4494
|
+
schema = z$1.array(z$1.any());
|
|
4495
|
+
} else if (column.dataType === "number") {
|
|
4496
|
+
schema = numberColumnToSchema(column, z$1, coerce2);
|
|
4497
|
+
} else if (column.dataType === "bigint") {
|
|
4498
|
+
schema = bigintColumnToSchema(column, z$1, coerce2);
|
|
4499
|
+
} else if (column.dataType === "boolean") {
|
|
4500
|
+
schema = coerce2 === true || coerce2.boolean ? z$1.coerce.boolean() : z$1.boolean();
|
|
4501
|
+
} else if (column.dataType === "date") {
|
|
4502
|
+
schema = coerce2 === true || coerce2.date ? z$1.coerce.date() : z$1.date();
|
|
4503
|
+
} else if (column.dataType === "string") {
|
|
4504
|
+
schema = stringColumnToSchema(column, z$1, coerce2);
|
|
4505
|
+
} else if (column.dataType === "json") {
|
|
4506
|
+
schema = jsonSchema;
|
|
4507
|
+
} else if (column.dataType === "custom") {
|
|
4508
|
+
schema = z$1.any();
|
|
4509
|
+
} else if (column.dataType === "buffer") {
|
|
4510
|
+
schema = bufferSchema;
|
|
4511
|
+
}
|
|
4512
|
+
}
|
|
4513
|
+
if (!schema) {
|
|
4514
|
+
schema = z$1.any();
|
|
4515
|
+
}
|
|
4516
|
+
return schema;
|
|
4517
|
+
}
|
|
4518
|
+
function numberColumnToSchema(column, z, coerce2) {
|
|
4519
|
+
let unsigned = column.getSQLType().includes("unsigned");
|
|
4520
|
+
let min;
|
|
4521
|
+
let max;
|
|
4522
|
+
let integer = false;
|
|
4523
|
+
if (isColumnType(column, ["MySqlTinyInt", "SingleStoreTinyInt"])) {
|
|
4524
|
+
min = unsigned ? 0 : CONSTANTS.INT8_MIN;
|
|
4525
|
+
max = unsigned ? CONSTANTS.INT8_UNSIGNED_MAX : CONSTANTS.INT8_MAX;
|
|
4526
|
+
integer = true;
|
|
4527
|
+
} else if (isColumnType(column, [
|
|
4528
|
+
"PgSmallInt",
|
|
4529
|
+
"PgSmallSerial",
|
|
4530
|
+
"MySqlSmallInt",
|
|
4531
|
+
"SingleStoreSmallInt"
|
|
4532
|
+
])) {
|
|
4533
|
+
min = unsigned ? 0 : CONSTANTS.INT16_MIN;
|
|
4534
|
+
max = unsigned ? CONSTANTS.INT16_UNSIGNED_MAX : CONSTANTS.INT16_MAX;
|
|
4535
|
+
integer = true;
|
|
4536
|
+
} else if (isColumnType(column, [
|
|
4537
|
+
"PgReal",
|
|
4538
|
+
"MySqlFloat",
|
|
4539
|
+
"MySqlMediumInt",
|
|
4540
|
+
"SingleStoreMediumInt",
|
|
4541
|
+
"SingleStoreFloat"
|
|
4542
|
+
])) {
|
|
4543
|
+
min = unsigned ? 0 : CONSTANTS.INT24_MIN;
|
|
4544
|
+
max = unsigned ? CONSTANTS.INT24_UNSIGNED_MAX : CONSTANTS.INT24_MAX;
|
|
4545
|
+
integer = isColumnType(column, ["MySqlMediumInt", "SingleStoreMediumInt"]);
|
|
4546
|
+
} else if (isColumnType(column, [
|
|
4547
|
+
"PgInteger",
|
|
4548
|
+
"PgSerial",
|
|
4549
|
+
"MySqlInt",
|
|
4550
|
+
"SingleStoreInt"
|
|
4551
|
+
])) {
|
|
4552
|
+
min = unsigned ? 0 : CONSTANTS.INT32_MIN;
|
|
4553
|
+
max = unsigned ? CONSTANTS.INT32_UNSIGNED_MAX : CONSTANTS.INT32_MAX;
|
|
4554
|
+
integer = true;
|
|
4555
|
+
} else if (isColumnType(column, [
|
|
4556
|
+
"PgDoublePrecision",
|
|
4557
|
+
"MySqlReal",
|
|
4558
|
+
"MySqlDouble",
|
|
4559
|
+
"SingleStoreReal",
|
|
4560
|
+
"SingleStoreDouble",
|
|
4561
|
+
"SQLiteReal"
|
|
4562
|
+
])) {
|
|
4563
|
+
min = unsigned ? 0 : CONSTANTS.INT48_MIN;
|
|
4564
|
+
max = unsigned ? CONSTANTS.INT48_UNSIGNED_MAX : CONSTANTS.INT48_MAX;
|
|
4565
|
+
} else if (isColumnType(column, [
|
|
4566
|
+
"PgBigInt53",
|
|
4567
|
+
"PgBigSerial53",
|
|
4568
|
+
"MySqlBigInt53",
|
|
4569
|
+
"MySqlSerial",
|
|
4570
|
+
"SingleStoreBigInt53",
|
|
4571
|
+
"SingleStoreSerial",
|
|
4572
|
+
"SQLiteInteger"
|
|
4573
|
+
])) {
|
|
4574
|
+
unsigned = unsigned || isColumnType(column, ["MySqlSerial", "SingleStoreSerial"]);
|
|
4575
|
+
min = unsigned ? 0 : Number.MIN_SAFE_INTEGER;
|
|
4576
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
4577
|
+
integer = true;
|
|
4578
|
+
} else if (isColumnType(column, ["MySqlYear", "SingleStoreYear"])) {
|
|
4579
|
+
min = 1901;
|
|
4580
|
+
max = 2155;
|
|
4581
|
+
integer = true;
|
|
4582
|
+
} else {
|
|
4583
|
+
min = Number.MIN_SAFE_INTEGER;
|
|
4584
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
4585
|
+
}
|
|
4586
|
+
let schema = coerce2 === true || coerce2?.number ? z.coerce.number() : z.number();
|
|
4587
|
+
schema = schema.min(min).max(max);
|
|
4588
|
+
return integer ? schema.int() : schema;
|
|
4589
|
+
}
|
|
4590
|
+
function bigintColumnToSchema(column, z, coerce2) {
|
|
4591
|
+
const unsigned = column.getSQLType().includes("unsigned");
|
|
4592
|
+
const min = unsigned ? 0n : CONSTANTS.INT64_MIN;
|
|
4593
|
+
const max = unsigned ? CONSTANTS.INT64_UNSIGNED_MAX : CONSTANTS.INT64_MAX;
|
|
4594
|
+
const schema = coerce2 === true || coerce2?.bigint ? z.coerce.bigint() : z.bigint();
|
|
4595
|
+
return schema.min(min).max(max);
|
|
4596
|
+
}
|
|
4597
|
+
function stringColumnToSchema(column, z, coerce2) {
|
|
4598
|
+
if (isColumnType(column, ["PgUUID"])) {
|
|
4599
|
+
return z.string().uuid();
|
|
4600
|
+
}
|
|
4601
|
+
let max;
|
|
4602
|
+
let regex;
|
|
4603
|
+
let fixed = false;
|
|
4604
|
+
if (isColumnType(column, ["PgVarchar", "SQLiteText"])) {
|
|
4605
|
+
max = column.length;
|
|
4606
|
+
} else if (isColumnType(column, ["MySqlVarChar", "SingleStoreVarChar"])) {
|
|
4607
|
+
max = column.length ?? CONSTANTS.INT16_UNSIGNED_MAX;
|
|
4608
|
+
} else if (isColumnType(column, ["MySqlText", "SingleStoreText"])) {
|
|
4609
|
+
if (column.textType === "longtext") {
|
|
4610
|
+
max = CONSTANTS.INT32_UNSIGNED_MAX;
|
|
4611
|
+
} else if (column.textType === "mediumtext") {
|
|
4612
|
+
max = CONSTANTS.INT24_UNSIGNED_MAX;
|
|
4613
|
+
} else if (column.textType === "text") {
|
|
4614
|
+
max = CONSTANTS.INT16_UNSIGNED_MAX;
|
|
4615
|
+
} else {
|
|
4616
|
+
max = CONSTANTS.INT8_UNSIGNED_MAX;
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
if (isColumnType(column, [
|
|
4620
|
+
"PgChar",
|
|
4621
|
+
"MySqlChar",
|
|
4622
|
+
"SingleStoreChar"
|
|
4623
|
+
])) {
|
|
4624
|
+
max = column.length;
|
|
4625
|
+
fixed = true;
|
|
4626
|
+
}
|
|
4627
|
+
if (isColumnType(column, ["PgBinaryVector"])) {
|
|
4628
|
+
regex = /^[01]+$/;
|
|
4629
|
+
max = column.dimensions;
|
|
4630
|
+
}
|
|
4631
|
+
let schema = coerce2 === true || coerce2?.string ? z.coerce.string() : z.string();
|
|
4632
|
+
schema = regex ? schema.regex(regex) : schema;
|
|
4633
|
+
return max && fixed ? schema.length(max) : max ? schema.max(max) : schema;
|
|
4634
|
+
}
|
|
4635
|
+
function getColumns(tableLike) {
|
|
4636
|
+
return isTable(tableLike) ? getTableColumns(tableLike) : getViewSelectedFields(tableLike);
|
|
4637
|
+
}
|
|
4638
|
+
function handleColumns(columns, refinements, conditions, factory) {
|
|
4639
|
+
const columnSchemas = {};
|
|
4640
|
+
for (const [key, selected] of Object.entries(columns)) {
|
|
4641
|
+
if (!is(selected, Column) && !is(selected, SQL) && !is(selected, SQL.Aliased) && typeof selected === "object") {
|
|
4642
|
+
const columns2 = isTable(selected) || isView(selected) ? getColumns(selected) : selected;
|
|
4643
|
+
columnSchemas[key] = handleColumns(columns2, refinements[key] ?? {}, conditions, factory);
|
|
4644
|
+
continue;
|
|
4645
|
+
}
|
|
4646
|
+
const refinement = refinements[key];
|
|
4647
|
+
if (refinement !== undefined && typeof refinement !== "function") {
|
|
4648
|
+
columnSchemas[key] = refinement;
|
|
4649
|
+
continue;
|
|
4650
|
+
}
|
|
4651
|
+
const column = is(selected, Column) ? selected : undefined;
|
|
4652
|
+
const schema = column ? columnToSchema(column, factory) : exports_external.any();
|
|
4653
|
+
const refined = typeof refinement === "function" ? refinement(schema) : schema;
|
|
4654
|
+
if (conditions.never(column)) {
|
|
4655
|
+
continue;
|
|
4656
|
+
} else {
|
|
4657
|
+
columnSchemas[key] = refined;
|
|
4658
|
+
}
|
|
4659
|
+
if (column) {
|
|
4660
|
+
if (conditions.nullable(column)) {
|
|
4661
|
+
columnSchemas[key] = columnSchemas[key].nullable();
|
|
4662
|
+
}
|
|
4663
|
+
if (conditions.optional(column)) {
|
|
4664
|
+
columnSchemas[key] = columnSchemas[key].optional();
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4668
|
+
return exports_external.object(columnSchemas);
|
|
4669
|
+
}
|
|
4670
|
+
function handleEnum(enum_, factory) {
|
|
4671
|
+
const zod = factory?.zodInstance ?? exports_external;
|
|
4672
|
+
return zod.enum(enum_.enumValues);
|
|
4673
|
+
}
|
|
4674
|
+
var CONSTANTS, isPgEnum, literalSchema, jsonSchema, bufferSchema, selectConditions, insertConditions, updateConditions, createSelectSchema = (entity, refine) => {
|
|
4675
|
+
if (isPgEnum(entity)) {
|
|
4676
|
+
return handleEnum(entity);
|
|
4677
|
+
}
|
|
4678
|
+
const columns = getColumns(entity);
|
|
4679
|
+
return handleColumns(columns, refine ?? {}, selectConditions);
|
|
4680
|
+
}, createInsertSchema = (entity, refine) => {
|
|
4681
|
+
const columns = getColumns(entity);
|
|
4682
|
+
return handleColumns(columns, refine ?? {}, insertConditions);
|
|
4683
|
+
}, createUpdateSchema = (entity, refine) => {
|
|
4684
|
+
const columns = getColumns(entity);
|
|
4685
|
+
return handleColumns(columns, refine ?? {}, updateConditions);
|
|
4686
|
+
};
|
|
4687
|
+
var init_drizzle_zod = __esm(() => {
|
|
4688
|
+
init_esm();
|
|
4689
|
+
CONSTANTS = {
|
|
4690
|
+
INT8_MIN: -128,
|
|
4691
|
+
INT8_MAX: 127,
|
|
4692
|
+
INT8_UNSIGNED_MAX: 255,
|
|
4693
|
+
INT16_MIN: -32768,
|
|
4694
|
+
INT16_MAX: 32767,
|
|
4695
|
+
INT16_UNSIGNED_MAX: 65535,
|
|
4696
|
+
INT24_MIN: -8388608,
|
|
4697
|
+
INT24_MAX: 8388607,
|
|
4698
|
+
INT24_UNSIGNED_MAX: 16777215,
|
|
4699
|
+
INT32_MIN: -2147483648,
|
|
4700
|
+
INT32_MAX: 2147483647,
|
|
4701
|
+
INT32_UNSIGNED_MAX: 4294967295,
|
|
4702
|
+
INT48_MIN: -140737488355328,
|
|
4703
|
+
INT48_MAX: 140737488355327,
|
|
4704
|
+
INT48_UNSIGNED_MAX: 281474976710655,
|
|
4705
|
+
INT64_MIN: -9223372036854775808n,
|
|
4706
|
+
INT64_MAX: 9223372036854775807n,
|
|
4707
|
+
INT64_UNSIGNED_MAX: 18446744073709551615n
|
|
4708
|
+
};
|
|
4709
|
+
isPgEnum = isWithEnum;
|
|
4710
|
+
literalSchema = exports_external.union([exports_external.string(), exports_external.number(), exports_external.boolean(), exports_external.null()]);
|
|
4711
|
+
jsonSchema = exports_external.union([literalSchema, exports_external.record(exports_external.any()), exports_external.array(exports_external.any())]);
|
|
4712
|
+
bufferSchema = exports_external.custom((v) => v instanceof Buffer);
|
|
4713
|
+
selectConditions = {
|
|
4714
|
+
never: () => false,
|
|
4715
|
+
optional: () => false,
|
|
4716
|
+
nullable: (column) => !column.notNull
|
|
4717
|
+
};
|
|
4718
|
+
insertConditions = {
|
|
4719
|
+
never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always",
|
|
4720
|
+
optional: (column) => !column.notNull || column.notNull && column.hasDefault,
|
|
4721
|
+
nullable: (column) => !column.notNull
|
|
4722
|
+
};
|
|
4723
|
+
updateConditions = {
|
|
4724
|
+
never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always",
|
|
4725
|
+
optional: () => true,
|
|
4726
|
+
nullable: (column) => !column.notNull
|
|
4727
|
+
};
|
|
4728
|
+
});
|
|
4729
|
+
|
|
4730
|
+
// ../data/src/schemas/auth.ts
|
|
4731
|
+
import {
|
|
4732
|
+
pgTable,
|
|
4733
|
+
text,
|
|
4734
|
+
timestamp,
|
|
4735
|
+
pgEnum,
|
|
4736
|
+
boolean,
|
|
4737
|
+
uniqueIndex
|
|
4738
|
+
} from "drizzle-orm/pg-core";
|
|
4739
|
+
var userRoleEnum, developerStatusEnum, users, accounts, sessions, verification, InsertUserSchema, SelectUserSchema, UpdateUserSchema, InsertAccountSchema, SelectAccountSchema, InsertSessionSchema, SelectSessionSchema, InsertVerificationSchema, SelectVerificationSchema, developerStatusValues, DeveloperStatusResponseSchema;
|
|
4740
|
+
var init_auth = __esm(() => {
|
|
4741
|
+
init_drizzle_zod();
|
|
4742
|
+
init_esm();
|
|
4743
|
+
userRoleEnum = pgEnum("user_role", [
|
|
4744
|
+
"admin",
|
|
4745
|
+
"player",
|
|
4746
|
+
"developer"
|
|
4747
|
+
]);
|
|
4748
|
+
developerStatusEnum = pgEnum("developer_status", [
|
|
4749
|
+
"none",
|
|
4750
|
+
"pending",
|
|
4751
|
+
"approved"
|
|
4752
|
+
]);
|
|
4753
|
+
users = pgTable("user", {
|
|
4754
|
+
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
4755
|
+
name: text("name").notNull(),
|
|
4756
|
+
username: text("username").unique(),
|
|
4757
|
+
email: text("email").notNull().unique(),
|
|
4758
|
+
emailVerified: boolean("email_verified").notNull().default(false),
|
|
4759
|
+
image: text("image"),
|
|
4760
|
+
role: userRoleEnum("role").notNull().default("player"),
|
|
4761
|
+
developerStatus: developerStatusEnum("developer_status").notNull().default("none"),
|
|
4762
|
+
createdAt: timestamp("created_at", {
|
|
4763
|
+
mode: "date",
|
|
4764
|
+
withTimezone: true
|
|
4765
|
+
}).notNull(),
|
|
4766
|
+
updatedAt: timestamp("updated_at", {
|
|
4767
|
+
mode: "date",
|
|
4768
|
+
withTimezone: true
|
|
4769
|
+
}).notNull()
|
|
4770
|
+
});
|
|
4771
|
+
accounts = pgTable("account", {
|
|
4772
|
+
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
4773
|
+
userId: text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
4774
|
+
accountId: text("account_id").notNull(),
|
|
4775
|
+
providerId: text("provider_id").notNull(),
|
|
4776
|
+
accessToken: text("access_token"),
|
|
4777
|
+
refreshToken: text("refresh_token"),
|
|
4778
|
+
idToken: text("id_token"),
|
|
4779
|
+
accessTokenExpiresAt: timestamp("access_token_expires_at", {
|
|
4780
|
+
mode: "date",
|
|
4781
|
+
withTimezone: true
|
|
4782
|
+
}),
|
|
4783
|
+
refreshTokenExpiresAt: timestamp("refresh_token_expires_at", {
|
|
4784
|
+
mode: "date",
|
|
4785
|
+
withTimezone: true
|
|
4786
|
+
}),
|
|
4787
|
+
scope: text("scope"),
|
|
4788
|
+
password: text("password"),
|
|
4789
|
+
createdAt: timestamp("created_at", {
|
|
4790
|
+
mode: "date",
|
|
4791
|
+
withTimezone: true
|
|
4792
|
+
}).notNull(),
|
|
4793
|
+
updatedAt: timestamp("updated_at", {
|
|
4794
|
+
mode: "date",
|
|
4795
|
+
withTimezone: true
|
|
4796
|
+
}).notNull()
|
|
4797
|
+
}, (table) => [
|
|
4798
|
+
uniqueIndex("account_provider_providerId_idx").on(table.accountId, table.providerId)
|
|
4799
|
+
]);
|
|
4800
|
+
sessions = pgTable("session", {
|
|
4801
|
+
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
4802
|
+
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
4803
|
+
expiresAt: timestamp("expires_at", {
|
|
4804
|
+
mode: "date",
|
|
4805
|
+
withTimezone: true
|
|
4806
|
+
}).notNull(),
|
|
4807
|
+
token: text("token").notNull().unique(),
|
|
4808
|
+
ipAddress: text("ip_address"),
|
|
4809
|
+
userAgent: text("user_agent"),
|
|
4810
|
+
createdAt: timestamp("created_at", {
|
|
4811
|
+
mode: "date",
|
|
4812
|
+
withTimezone: true
|
|
4813
|
+
}).notNull(),
|
|
4814
|
+
updatedAt: timestamp("updated_at", {
|
|
4815
|
+
mode: "date",
|
|
4816
|
+
withTimezone: true
|
|
4817
|
+
}).notNull()
|
|
4818
|
+
});
|
|
4819
|
+
verification = pgTable("verification", {
|
|
4820
|
+
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
4821
|
+
identifier: text("identifier").notNull(),
|
|
4822
|
+
value: text("value").notNull(),
|
|
4823
|
+
expiresAt: timestamp("expires_at", {
|
|
4824
|
+
mode: "date",
|
|
4825
|
+
withTimezone: true
|
|
4826
|
+
}).notNull(),
|
|
4827
|
+
createdAt: timestamp("created_at", {
|
|
4828
|
+
mode: "date",
|
|
4829
|
+
withTimezone: true
|
|
4830
|
+
}).notNull(),
|
|
4831
|
+
updatedAt: timestamp("updated_at", {
|
|
4832
|
+
mode: "date",
|
|
4833
|
+
withTimezone: true
|
|
4834
|
+
}).notNull()
|
|
4835
|
+
});
|
|
4836
|
+
InsertUserSchema = createInsertSchema(users, {
|
|
4837
|
+
email: exports_external.string().email(),
|
|
4838
|
+
name: exports_external.string().optional()
|
|
4839
|
+
}).omit({ id: true });
|
|
4840
|
+
SelectUserSchema = createSelectSchema(users);
|
|
4841
|
+
UpdateUserSchema = createUpdateSchema(users);
|
|
4842
|
+
InsertAccountSchema = createInsertSchema(accounts);
|
|
4843
|
+
SelectAccountSchema = createSelectSchema(accounts);
|
|
4844
|
+
InsertSessionSchema = createInsertSchema(sessions);
|
|
4845
|
+
SelectSessionSchema = createSelectSchema(sessions);
|
|
4846
|
+
InsertVerificationSchema = createInsertSchema(verification);
|
|
4847
|
+
SelectVerificationSchema = createSelectSchema(verification);
|
|
4848
|
+
developerStatusValues = developerStatusEnum.enumValues;
|
|
4849
|
+
DeveloperStatusResponseSchema = exports_external.object({
|
|
4850
|
+
status: exports_external.enum(developerStatusValues)
|
|
4851
|
+
});
|
|
4852
|
+
});
|
|
4853
|
+
|
|
4854
|
+
// ../data/src/schemas/game.ts
|
|
4855
|
+
import {
|
|
4856
|
+
pgTable as pgTable2,
|
|
4857
|
+
text as text2,
|
|
4858
|
+
timestamp as timestamp2,
|
|
4859
|
+
jsonb,
|
|
4860
|
+
varchar,
|
|
4861
|
+
uuid,
|
|
4862
|
+
pgEnum as pgEnum2,
|
|
4863
|
+
uniqueIndex as uniqueIndex2
|
|
4864
|
+
} from "drizzle-orm/pg-core";
|
|
4865
|
+
var gamePlatformEnum, gameBootModeEnum, games, gameSessions, gameStates, safeRelativePathRegex, invalidPathMessage = "Path must be relative, contain only alphanumeric, -, _, ., / characters, and not contain .. segments.", validateRelativePath = (path, fieldName) => {
|
|
4866
|
+
if (path == null)
|
|
4867
|
+
return true;
|
|
4868
|
+
if (typeof path !== "string" || !safeRelativePathRegex.test(path)) {
|
|
4869
|
+
throw new exports_external.ZodError([
|
|
4870
|
+
{
|
|
4871
|
+
code: exports_external.ZodIssueCode.custom,
|
|
4872
|
+
path: [fieldName],
|
|
4873
|
+
message: invalidPathMessage
|
|
4874
|
+
}
|
|
4875
|
+
]);
|
|
4876
|
+
}
|
|
4877
|
+
return true;
|
|
4878
|
+
}, validateStylesArray = (styles, fieldName) => {
|
|
4879
|
+
if (styles == null)
|
|
4880
|
+
return true;
|
|
4881
|
+
if (!Array.isArray(styles)) {
|
|
4882
|
+
throw new exports_external.ZodError([
|
|
4883
|
+
{
|
|
4884
|
+
code: exports_external.ZodIssueCode.custom,
|
|
4885
|
+
path: [fieldName],
|
|
4886
|
+
message: "Styles must be an array of strings."
|
|
4887
|
+
}
|
|
4888
|
+
]);
|
|
4889
|
+
}
|
|
4890
|
+
styles.forEach((style, index) => {
|
|
4891
|
+
if (typeof style !== "string") {
|
|
4892
|
+
throw new exports_external.ZodError([
|
|
4893
|
+
{
|
|
4894
|
+
code: exports_external.ZodIssueCode.custom,
|
|
4895
|
+
path: [`${fieldName}[${index}]`],
|
|
4896
|
+
message: "Each style must be a string."
|
|
4897
|
+
}
|
|
4898
|
+
]);
|
|
4899
|
+
}
|
|
4900
|
+
validateRelativePath(style, `${fieldName}[${index}]`);
|
|
4901
|
+
});
|
|
4902
|
+
return true;
|
|
4903
|
+
}, VersionSchema, InsertGameSchema, SelectGameSchema, UpdateGameSchema, InsertGameSessionSchema, SelectGameSessionSchema, UpdateGameSessionSchema, InsertGameStateSchema, SelectGameStateSchema, UpdateGameStateSchema, UpsertGameMetadataSchema, InitiateUploadSchema, ProcessZipSchema, StartSessionInputSchema, ManifestV1Schema;
|
|
4904
|
+
var init_game = __esm(() => {
|
|
4905
|
+
init_drizzle_zod();
|
|
4906
|
+
init_esm();
|
|
4907
|
+
init_auth();
|
|
4908
|
+
init_map();
|
|
4909
|
+
gamePlatformEnum = pgEnum2("game_platform", [
|
|
4910
|
+
"web",
|
|
4911
|
+
"godot",
|
|
4912
|
+
"unity"
|
|
4913
|
+
]);
|
|
4914
|
+
gameBootModeEnum = pgEnum2("game_boot_mode", ["iframe", "module"]);
|
|
4915
|
+
games = pgTable2("games", {
|
|
4916
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
4917
|
+
developerId: text2("developer_id").references(() => users.id, {
|
|
4918
|
+
onDelete: "set null"
|
|
4919
|
+
}),
|
|
4920
|
+
slug: varchar("slug", { length: 255 }).notNull().unique(),
|
|
4921
|
+
displayName: varchar("display_name", { length: 255 }).notNull(),
|
|
4922
|
+
version: varchar("version", { length: 50 }).notNull(),
|
|
4923
|
+
assetBundleBase: text2("asset_bundle_base").notNull(),
|
|
4924
|
+
platform: gamePlatformEnum("platform").notNull().default("web"),
|
|
4925
|
+
mapElementId: uuid("map_element_id").references(() => mapElements.id, {
|
|
4926
|
+
onDelete: "set null"
|
|
4927
|
+
}),
|
|
4928
|
+
metadata: jsonb("metadata").default("{}"),
|
|
4929
|
+
createdAt: timestamp2("created_at", { withTimezone: true }).defaultNow(),
|
|
4930
|
+
updatedAt: timestamp2("updated_at", { withTimezone: true }).defaultNow()
|
|
4931
|
+
});
|
|
4932
|
+
gameSessions = pgTable2("game_sessions", {
|
|
4933
|
+
id: uuid("id").primaryKey().defaultRandom(),
|
|
4934
|
+
userId: text2("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
4935
|
+
gameId: uuid("game_id").notNull().references(() => games.id, { onDelete: "cascade" }),
|
|
4936
|
+
startedAt: timestamp2("started_at", { withTimezone: true }).notNull().defaultNow(),
|
|
4937
|
+
endedAt: timestamp2("ended_at", { withTimezone: true })
|
|
4938
|
+
});
|
|
4939
|
+
gameStates = pgTable2("game_states", {
|
|
4940
|
+
userId: text2("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
|
|
4941
|
+
gameId: uuid("game_id").notNull().references(() => games.id, { onDelete: "cascade" }),
|
|
4942
|
+
data: jsonb("data").default("{}"),
|
|
4943
|
+
updatedAt: timestamp2("updated_at", { withTimezone: true }).defaultNow()
|
|
4944
|
+
}, (table) => [
|
|
4945
|
+
uniqueIndex2("unique_user_game_idx").on(table.userId, table.gameId)
|
|
4946
|
+
]);
|
|
4947
|
+
safeRelativePathRegex = /^(?!.*\.\.)(?!\/)[\w\-./]+$/;
|
|
4948
|
+
VersionSchema = exports_external.string().min(1).max(50);
|
|
4949
|
+
InsertGameSchema = createInsertSchema(games, {
|
|
4950
|
+
metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional().default({}),
|
|
4951
|
+
mapElementId: exports_external.string().uuid().optional().nullable()
|
|
4952
|
+
}).omit({
|
|
4953
|
+
id: true,
|
|
4954
|
+
slug: true,
|
|
4955
|
+
createdAt: true,
|
|
4956
|
+
updatedAt: true,
|
|
4957
|
+
version: true
|
|
4958
|
+
});
|
|
4959
|
+
SelectGameSchema = createSelectSchema(games);
|
|
4960
|
+
UpdateGameSchema = createUpdateSchema(games, {
|
|
4961
|
+
metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional(),
|
|
4962
|
+
displayName: exports_external.string().optional(),
|
|
4963
|
+
mapElementId: exports_external.string().uuid().optional().nullable(),
|
|
4964
|
+
platform: exports_external.enum(gamePlatformEnum.enumValues).optional()
|
|
4965
|
+
}).omit({
|
|
4966
|
+
id: true,
|
|
4967
|
+
slug: true,
|
|
4968
|
+
createdAt: true,
|
|
4969
|
+
developerId: true,
|
|
4970
|
+
version: true
|
|
4971
|
+
});
|
|
4972
|
+
InsertGameSessionSchema = createInsertSchema(gameSessions).omit({
|
|
4973
|
+
id: true,
|
|
4974
|
+
startedAt: true
|
|
4975
|
+
});
|
|
4976
|
+
SelectGameSessionSchema = createSelectSchema(gameSessions);
|
|
4977
|
+
UpdateGameSessionSchema = createUpdateSchema(gameSessions).omit({
|
|
4978
|
+
id: true,
|
|
4979
|
+
userId: true,
|
|
4980
|
+
gameId: true,
|
|
4981
|
+
startedAt: true
|
|
4982
|
+
});
|
|
4983
|
+
InsertGameStateSchema = createInsertSchema(gameStates, {
|
|
4984
|
+
data: exports_external.record(exports_external.string(), exports_external.unknown()).optional().default({})
|
|
4985
|
+
}).omit({ updatedAt: true });
|
|
4986
|
+
SelectGameStateSchema = createSelectSchema(gameStates);
|
|
4987
|
+
UpdateGameStateSchema = createUpdateSchema(gameStates, {
|
|
4988
|
+
data: exports_external.record(exports_external.string(), exports_external.unknown()).optional()
|
|
4989
|
+
}).omit({ userId: true, gameId: true });
|
|
4990
|
+
UpsertGameMetadataSchema = exports_external.object({
|
|
4991
|
+
displayName: exports_external.string().min(1),
|
|
4992
|
+
mapElementId: exports_external.string().uuid().optional().nullable(),
|
|
4993
|
+
platform: exports_external.enum(gamePlatformEnum.enumValues),
|
|
4994
|
+
metadata: exports_external.record(exports_external.string(), exports_external.unknown()).optional().default({})
|
|
4995
|
+
});
|
|
4996
|
+
InitiateUploadSchema = exports_external.object({
|
|
4997
|
+
fileName: exports_external.string().min(1).refine((name) => name.endsWith(".zip"), {
|
|
4998
|
+
message: "File must be a .zip file"
|
|
4999
|
+
}),
|
|
5000
|
+
gameId: exports_external.string().uuid()
|
|
5001
|
+
});
|
|
5002
|
+
ProcessZipSchema = exports_external.object({
|
|
5003
|
+
tempS3Key: exports_external.string().min(1),
|
|
5004
|
+
gameId: exports_external.string().uuid(),
|
|
5005
|
+
version: exports_external.string().min(1),
|
|
5006
|
+
slug: exports_external.string().min(1),
|
|
5007
|
+
metadata: UpsertGameMetadataSchema,
|
|
5008
|
+
originalFileName: exports_external.string().min(1).endsWith(".zip")
|
|
5009
|
+
});
|
|
5010
|
+
StartSessionInputSchema = exports_external.object({
|
|
5011
|
+
gameId: exports_external.string().uuid()
|
|
5012
|
+
});
|
|
5013
|
+
ManifestV1Schema = exports_external.object({
|
|
5014
|
+
version: exports_external.string().min(1),
|
|
5015
|
+
bootMode: exports_external.enum(gameBootModeEnum.enumValues),
|
|
5016
|
+
entryPoint: exports_external.string().refine((val) => validateRelativePath(val, "entryPoint")),
|
|
5017
|
+
styles: exports_external.array(exports_external.string()).optional().refine((val) => validateStylesArray(val, "styles")),
|
|
5018
|
+
platform: exports_external.enum(gamePlatformEnum.enumValues),
|
|
5019
|
+
createdAt: exports_external.string().datetime()
|
|
5020
|
+
});
|
|
5021
|
+
});
|
|
5022
|
+
|
|
5023
|
+
// ../data/src/schemas/map.ts
|
|
5024
|
+
import {
|
|
5025
|
+
pgTable as pgTable3,
|
|
5026
|
+
jsonb as jsonb2,
|
|
5027
|
+
varchar as varchar2,
|
|
5028
|
+
uuid as uuid2,
|
|
5029
|
+
pgEnum as pgEnum3,
|
|
5030
|
+
uniqueIndex as uniqueIndex3,
|
|
5031
|
+
text as text3,
|
|
5032
|
+
doublePrecision
|
|
5033
|
+
} from "drizzle-orm/pg-core";
|
|
5034
|
+
import { relations } from "drizzle-orm";
|
|
5035
|
+
var interactionTypeEnum, maps, mapElements, mapElementsRelations, mapsRelations, MapElementMetadataZodSchema, SelectMapSchema, InsertMapElementSchema, SelectMapElementSchema, UpdateMapElementSchema;
|
|
5036
|
+
var init_map = __esm(() => {
|
|
5037
|
+
init_drizzle_zod();
|
|
5038
|
+
init_esm();
|
|
5039
|
+
init_game();
|
|
5040
|
+
interactionTypeEnum = pgEnum3("interaction_type", [
|
|
5041
|
+
"game_entry",
|
|
5042
|
+
"game_registry",
|
|
5043
|
+
"info",
|
|
5044
|
+
"teleport",
|
|
5045
|
+
"door_in",
|
|
5046
|
+
"door_out",
|
|
5047
|
+
"npc_interaction",
|
|
5048
|
+
"quest_trigger"
|
|
5049
|
+
]);
|
|
5050
|
+
maps = pgTable3("maps", {
|
|
5051
|
+
id: uuid2("id").primaryKey().defaultRandom(),
|
|
5052
|
+
identifier: varchar2("identifier", { length: 255 }).notNull().unique(),
|
|
5053
|
+
displayName: varchar2("display_name", { length: 255 }).notNull(),
|
|
5054
|
+
filePath: varchar2("file_path", { length: 255 }).notNull(),
|
|
5055
|
+
tilesetBasePath: varchar2("tileset_base_path", { length: 255 }).notNull().default("/tilesets"),
|
|
5056
|
+
defaultSpawnTileX: doublePrecision("default_spawn_tile_x").notNull().default(0),
|
|
5057
|
+
defaultSpawnTileY: doublePrecision("default_spawn_tile_y").notNull().default(0),
|
|
5058
|
+
description: text3("description")
|
|
5059
|
+
});
|
|
5060
|
+
mapElements = pgTable3("map_elements", {
|
|
5061
|
+
id: uuid2("id").primaryKey().defaultRandom(),
|
|
5062
|
+
mapId: uuid2("map_id").references(() => maps.id, {
|
|
5063
|
+
onDelete: "cascade"
|
|
5064
|
+
}),
|
|
5065
|
+
elementSlug: varchar2("element_slug", { length: 255 }).notNull(),
|
|
5066
|
+
interactionType: interactionTypeEnum("interaction_type").notNull(),
|
|
5067
|
+
gameId: uuid2("game_id").references(() => games.id, {
|
|
5068
|
+
onDelete: "set null"
|
|
5069
|
+
}),
|
|
5070
|
+
metadata: jsonb2("metadata").$type().default({})
|
|
5071
|
+
}, (table) => [
|
|
5072
|
+
uniqueIndex3("map_id_element_slug_unique_idx").on(table.mapId, table.elementSlug)
|
|
5073
|
+
]);
|
|
5074
|
+
mapElementsRelations = relations(mapElements, ({ one }) => ({
|
|
5075
|
+
game: one(games, {
|
|
5076
|
+
fields: [mapElements.gameId],
|
|
5077
|
+
references: [games.id]
|
|
5078
|
+
}),
|
|
5079
|
+
map: one(maps, {
|
|
5080
|
+
fields: [mapElements.mapId],
|
|
5081
|
+
references: [maps.id]
|
|
5082
|
+
})
|
|
5083
|
+
}));
|
|
5084
|
+
mapsRelations = relations(maps, ({ many }) => ({
|
|
5085
|
+
elements: many(mapElements)
|
|
5086
|
+
}));
|
|
5087
|
+
MapElementMetadataZodSchema = exports_external.object({
|
|
5088
|
+
description: exports_external.string().optional(),
|
|
5089
|
+
sourceTiledObjects: exports_external.array(exports_external.record(exports_external.string(), exports_external.unknown())).optional()
|
|
5090
|
+
}).catchall(exports_external.unknown());
|
|
5091
|
+
SelectMapSchema = createSelectSchema(maps);
|
|
5092
|
+
InsertMapElementSchema = createInsertSchema(mapElements, {
|
|
5093
|
+
metadata: MapElementMetadataZodSchema.optional().default({}),
|
|
5094
|
+
interactionType: exports_external.enum(interactionTypeEnum.enumValues)
|
|
5095
|
+
}).omit({ id: true });
|
|
5096
|
+
SelectMapElementSchema = createSelectSchema(mapElements, {
|
|
5097
|
+
metadata: MapElementMetadataZodSchema.optional().default({}),
|
|
5098
|
+
interactionType: exports_external.enum(interactionTypeEnum.enumValues)
|
|
5099
|
+
});
|
|
5100
|
+
UpdateMapElementSchema = createUpdateSchema(mapElements, {
|
|
5101
|
+
metadata: MapElementMetadataZodSchema.optional(),
|
|
5102
|
+
interactionType: exports_external.enum(interactionTypeEnum.enumValues).optional()
|
|
5103
|
+
}).omit({ id: true });
|
|
5104
|
+
});
|
|
5105
|
+
|
|
440
5106
|
// ../data/src/constants.ts
|
|
441
|
-
var
|
|
5107
|
+
var ITEM_SLUGS, CURRENCIES, BADGES, INTERACTION_TYPE;
|
|
442
5108
|
var init_constants = __esm(() => {
|
|
443
|
-
|
|
5109
|
+
init_map();
|
|
5110
|
+
ITEM_SLUGS = {
|
|
444
5111
|
PLAYCADEMY_CREDITS: "PLAYCADEMY_CREDITS",
|
|
445
5112
|
PLAYCADEMY_XP: "PLAYCADEMY_XP",
|
|
446
5113
|
FOUNDING_MEMBER_BADGE: "FOUNDING_MEMBER_BADGE",
|
|
@@ -451,14 +5118,15 @@ var init_constants = __esm(() => {
|
|
|
451
5118
|
SMALL_BACKPACK: "SMALL_BACKPACK"
|
|
452
5119
|
};
|
|
453
5120
|
CURRENCIES = {
|
|
454
|
-
PRIMARY:
|
|
455
|
-
XP:
|
|
5121
|
+
PRIMARY: ITEM_SLUGS.PLAYCADEMY_CREDITS,
|
|
5122
|
+
XP: ITEM_SLUGS.PLAYCADEMY_XP
|
|
456
5123
|
};
|
|
457
5124
|
BADGES = {
|
|
458
|
-
FOUNDING_MEMBER:
|
|
459
|
-
EARLY_ADOPTER:
|
|
460
|
-
FIRST_GAME:
|
|
5125
|
+
FOUNDING_MEMBER: ITEM_SLUGS.FOUNDING_MEMBER_BADGE,
|
|
5126
|
+
EARLY_ADOPTER: ITEM_SLUGS.EARLY_ADOPTER_BADGE,
|
|
5127
|
+
FIRST_GAME: ITEM_SLUGS.FIRST_GAME_BADGE
|
|
461
5128
|
};
|
|
5129
|
+
INTERACTION_TYPE = Object.fromEntries(interactionTypeEnum.enumValues.map((value) => [value, value]));
|
|
462
5130
|
});
|
|
463
5131
|
|
|
464
5132
|
// src/core/namespaces/credits.ts
|
|
@@ -468,9 +5136,9 @@ function createCreditsNamespace(client) {
|
|
|
468
5136
|
if (cachedCreditsItemId) {
|
|
469
5137
|
return cachedCreditsItemId;
|
|
470
5138
|
}
|
|
471
|
-
const
|
|
472
|
-
const creditsItem = items.
|
|
473
|
-
if (!creditsItem) {
|
|
5139
|
+
const queryParams = new URLSearchParams({ slug: CURRENCIES.PRIMARY });
|
|
5140
|
+
const creditsItem = await client["request"](`/items/resolve?${queryParams.toString()}`, "GET");
|
|
5141
|
+
if (!creditsItem || !creditsItem.id) {
|
|
474
5142
|
throw new Error("Playcademy Credits item not found in catalog");
|
|
475
5143
|
}
|
|
476
5144
|
cachedCreditsItemId = creditsItem.id;
|
|
@@ -479,8 +5147,8 @@ function createCreditsNamespace(client) {
|
|
|
479
5147
|
return {
|
|
480
5148
|
balance: async () => {
|
|
481
5149
|
const inventory = await client.users.inventory.get();
|
|
482
|
-
const
|
|
483
|
-
return
|
|
5150
|
+
const primaryCurrencyInventoryItem = inventory.find((item) => item.item?.slug === CURRENCIES.PRIMARY);
|
|
5151
|
+
return primaryCurrencyInventoryItem?.quantity ?? 0;
|
|
484
5152
|
},
|
|
485
5153
|
add: async (amount) => {
|
|
486
5154
|
if (amount <= 0) {
|