@thirstie/thirstievalidators 1.5.0 → 1.5.1
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/CHANGELOG.md +20 -0
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/agegate.js.html +1 -1
- package/coverage/lcov-report/block-navigation.js +1 -1
- package/coverage/lcov-report/emailLists.js.html +1 -1
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/index.js.html +1 -1
- package/coverage/lcov-report/iso3166codes.js.html +1 -1
- package/coverage/lcov-report/passwordcheck.js.html +1 -1
- package/coverage/lcov-report/sorter.js +21 -7
- package/dist/bundle.cjs +118 -726
- package/dist/bundle.iife.js +1 -1
- package/dist/bundle.mjs +118 -726
- package/package.json +2 -2
package/dist/bundle.mjs
CHANGED
|
@@ -172,7 +172,7 @@ const trustedEmailDomains = [
|
|
|
172
172
|
|
|
173
173
|
var util;
|
|
174
174
|
(function (util) {
|
|
175
|
-
util.assertEqual = (
|
|
175
|
+
util.assertEqual = (_) => { };
|
|
176
176
|
function assertIs(_arg) { }
|
|
177
177
|
util.assertIs = assertIs;
|
|
178
178
|
function assertNever(_x) {
|
|
@@ -219,11 +219,9 @@ var util;
|
|
|
219
219
|
};
|
|
220
220
|
util.isInteger = typeof Number.isInteger === "function"
|
|
221
221
|
? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
|
|
222
|
-
: (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
222
|
+
: (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
223
223
|
function joinValues(array, separator = " | ") {
|
|
224
|
-
return array
|
|
225
|
-
.map((val) => (typeof val === "string" ? `'${val}'` : val))
|
|
226
|
-
.join(separator);
|
|
224
|
+
return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
|
|
227
225
|
}
|
|
228
226
|
util.joinValues = joinValues;
|
|
229
227
|
util.jsonStringifyReplacer = (_, value) => {
|
|
@@ -272,7 +270,7 @@ const getParsedType = (data) => {
|
|
|
272
270
|
case "string":
|
|
273
271
|
return ZodParsedType.string;
|
|
274
272
|
case "number":
|
|
275
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
273
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
276
274
|
case "boolean":
|
|
277
275
|
return ZodParsedType.boolean;
|
|
278
276
|
case "function":
|
|
@@ -288,10 +286,7 @@ const getParsedType = (data) => {
|
|
|
288
286
|
if (data === null) {
|
|
289
287
|
return ZodParsedType.null;
|
|
290
288
|
}
|
|
291
|
-
if (data.then &&
|
|
292
|
-
typeof data.then === "function" &&
|
|
293
|
-
data.catch &&
|
|
294
|
-
typeof data.catch === "function") {
|
|
289
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
295
290
|
return ZodParsedType.promise;
|
|
296
291
|
}
|
|
297
292
|
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
@@ -327,10 +322,6 @@ const ZodIssueCode = util.arrayToEnum([
|
|
|
327
322
|
"not_multiple_of",
|
|
328
323
|
"not_finite",
|
|
329
324
|
]);
|
|
330
|
-
const quotelessJson = (obj) => {
|
|
331
|
-
const json = JSON.stringify(obj, null, 2);
|
|
332
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
333
|
-
};
|
|
334
325
|
class ZodError extends Error {
|
|
335
326
|
get errors() {
|
|
336
327
|
return this.issues;
|
|
@@ -423,8 +414,9 @@ class ZodError extends Error {
|
|
|
423
414
|
const formErrors = [];
|
|
424
415
|
for (const sub of this.issues) {
|
|
425
416
|
if (sub.path.length > 0) {
|
|
426
|
-
|
|
427
|
-
fieldErrors[
|
|
417
|
+
const firstEl = sub.path[0];
|
|
418
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
419
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
428
420
|
}
|
|
429
421
|
else {
|
|
430
422
|
formErrors.push(mapper(sub));
|
|
@@ -507,17 +499,11 @@ const errorMap = (issue, _ctx) => {
|
|
|
507
499
|
else if (issue.type === "string")
|
|
508
500
|
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
509
501
|
else if (issue.type === "number")
|
|
510
|
-
message = `Number must be ${issue.exact
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
? `greater than or equal to `
|
|
514
|
-
: `greater than `}${issue.minimum}`;
|
|
502
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
503
|
+
else if (issue.type === "bigint")
|
|
504
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
515
505
|
else if (issue.type === "date")
|
|
516
|
-
message = `Date must be ${issue.exact
|
|
517
|
-
? `exactly equal to `
|
|
518
|
-
: issue.inclusive
|
|
519
|
-
? `greater than or equal to `
|
|
520
|
-
: `greater than `}${new Date(Number(issue.minimum))}`;
|
|
506
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
521
507
|
else
|
|
522
508
|
message = "Invalid input";
|
|
523
509
|
break;
|
|
@@ -527,23 +513,11 @@ const errorMap = (issue, _ctx) => {
|
|
|
527
513
|
else if (issue.type === "string")
|
|
528
514
|
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
529
515
|
else if (issue.type === "number")
|
|
530
|
-
message = `Number must be ${issue.exact
|
|
531
|
-
? `exactly`
|
|
532
|
-
: issue.inclusive
|
|
533
|
-
? `less than or equal to`
|
|
534
|
-
: `less than`} ${issue.maximum}`;
|
|
516
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
535
517
|
else if (issue.type === "bigint")
|
|
536
|
-
message = `BigInt must be ${issue.exact
|
|
537
|
-
? `exactly`
|
|
538
|
-
: issue.inclusive
|
|
539
|
-
? `less than or equal to`
|
|
540
|
-
: `less than`} ${issue.maximum}`;
|
|
518
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
541
519
|
else if (issue.type === "date")
|
|
542
|
-
message = `Date must be ${issue.exact
|
|
543
|
-
? `exactly`
|
|
544
|
-
: issue.inclusive
|
|
545
|
-
? `smaller than or equal to`
|
|
546
|
-
: `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
520
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
547
521
|
else
|
|
548
522
|
message = "Invalid input";
|
|
549
523
|
break;
|
|
@@ -567,9 +541,6 @@ const errorMap = (issue, _ctx) => {
|
|
|
567
541
|
};
|
|
568
542
|
|
|
569
543
|
let overrideErrorMap = errorMap;
|
|
570
|
-
function setErrorMap(map) {
|
|
571
|
-
overrideErrorMap = map;
|
|
572
|
-
}
|
|
573
544
|
function getErrorMap() {
|
|
574
545
|
return overrideErrorMap;
|
|
575
546
|
}
|
|
@@ -602,7 +573,6 @@ const makeIssue = (params) => {
|
|
|
602
573
|
message: errorMessage,
|
|
603
574
|
};
|
|
604
575
|
};
|
|
605
|
-
const EMPTY_PATH = [];
|
|
606
576
|
function addIssueToContext(ctx, issueData) {
|
|
607
577
|
const overrideMap = getErrorMap();
|
|
608
578
|
const issue = makeIssue({
|
|
@@ -665,8 +635,7 @@ class ParseStatus {
|
|
|
665
635
|
status.dirty();
|
|
666
636
|
if (value.status === "dirty")
|
|
667
637
|
status.dirty();
|
|
668
|
-
if (key.value !== "__proto__" &&
|
|
669
|
-
(typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
638
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
670
639
|
finalObject[key.value] = value.value;
|
|
671
640
|
}
|
|
672
641
|
}
|
|
@@ -683,43 +652,13 @@ const isDirty = (x) => x.status === "dirty";
|
|
|
683
652
|
const isValid = (x) => x.status === "valid";
|
|
684
653
|
const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
685
654
|
|
|
686
|
-
/******************************************************************************
|
|
687
|
-
Copyright (c) Microsoft Corporation.
|
|
688
|
-
|
|
689
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
690
|
-
purpose with or without fee is hereby granted.
|
|
691
|
-
|
|
692
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
693
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
694
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
695
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
696
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
697
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
698
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
699
|
-
***************************************************************************** */
|
|
700
|
-
|
|
701
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
702
|
-
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
703
|
-
return state.get(receiver);
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
707
|
-
if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
708
|
-
return (state.set(receiver, value)), value;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
712
|
-
var e = new Error(message);
|
|
713
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
714
|
-
};
|
|
715
|
-
|
|
716
655
|
var errorUtil;
|
|
717
656
|
(function (errorUtil) {
|
|
718
657
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
719
|
-
|
|
658
|
+
// biome-ignore lint:
|
|
659
|
+
errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
720
660
|
})(errorUtil || (errorUtil = {}));
|
|
721
661
|
|
|
722
|
-
var _ZodEnum_cache, _ZodNativeEnum_cache;
|
|
723
662
|
class ParseInputLazyPath {
|
|
724
663
|
constructor(parent, value, path, key) {
|
|
725
664
|
this._cachedPath = [];
|
|
@@ -730,7 +669,7 @@ class ParseInputLazyPath {
|
|
|
730
669
|
}
|
|
731
670
|
get path() {
|
|
732
671
|
if (!this._cachedPath.length) {
|
|
733
|
-
if (this._key
|
|
672
|
+
if (Array.isArray(this._key)) {
|
|
734
673
|
this._cachedPath.push(...this._path, ...this._key);
|
|
735
674
|
}
|
|
736
675
|
else {
|
|
@@ -770,17 +709,16 @@ function processCreateParams(params) {
|
|
|
770
709
|
if (errorMap)
|
|
771
710
|
return { errorMap: errorMap, description };
|
|
772
711
|
const customMap = (iss, ctx) => {
|
|
773
|
-
var _a, _b;
|
|
774
712
|
const { message } = params;
|
|
775
713
|
if (iss.code === "invalid_enum_value") {
|
|
776
|
-
return { message: message
|
|
714
|
+
return { message: message ?? ctx.defaultError };
|
|
777
715
|
}
|
|
778
716
|
if (typeof ctx.data === "undefined") {
|
|
779
|
-
return { message:
|
|
717
|
+
return { message: message ?? required_error ?? ctx.defaultError };
|
|
780
718
|
}
|
|
781
719
|
if (iss.code !== "invalid_type")
|
|
782
720
|
return { message: ctx.defaultError };
|
|
783
|
-
return { message:
|
|
721
|
+
return { message: message ?? invalid_type_error ?? ctx.defaultError };
|
|
784
722
|
};
|
|
785
723
|
return { errorMap: customMap, description };
|
|
786
724
|
}
|
|
@@ -832,14 +770,13 @@ class ZodType {
|
|
|
832
770
|
throw result.error;
|
|
833
771
|
}
|
|
834
772
|
safeParse(data, params) {
|
|
835
|
-
var _a;
|
|
836
773
|
const ctx = {
|
|
837
774
|
common: {
|
|
838
775
|
issues: [],
|
|
839
|
-
async:
|
|
840
|
-
contextualErrorMap: params
|
|
776
|
+
async: params?.async ?? false,
|
|
777
|
+
contextualErrorMap: params?.errorMap,
|
|
841
778
|
},
|
|
842
|
-
path:
|
|
779
|
+
path: params?.path || [],
|
|
843
780
|
schemaErrorMap: this._def.errorMap,
|
|
844
781
|
parent: null,
|
|
845
782
|
data,
|
|
@@ -849,7 +786,6 @@ class ZodType {
|
|
|
849
786
|
return handleResult(ctx, result);
|
|
850
787
|
}
|
|
851
788
|
"~validate"(data) {
|
|
852
|
-
var _a, _b;
|
|
853
789
|
const ctx = {
|
|
854
790
|
common: {
|
|
855
791
|
issues: [],
|
|
@@ -873,7 +809,7 @@ class ZodType {
|
|
|
873
809
|
};
|
|
874
810
|
}
|
|
875
811
|
catch (err) {
|
|
876
|
-
if (
|
|
812
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
877
813
|
this["~standard"].async = true;
|
|
878
814
|
}
|
|
879
815
|
ctx.common = {
|
|
@@ -900,19 +836,17 @@ class ZodType {
|
|
|
900
836
|
const ctx = {
|
|
901
837
|
common: {
|
|
902
838
|
issues: [],
|
|
903
|
-
contextualErrorMap: params
|
|
839
|
+
contextualErrorMap: params?.errorMap,
|
|
904
840
|
async: true,
|
|
905
841
|
},
|
|
906
|
-
path:
|
|
842
|
+
path: params?.path || [],
|
|
907
843
|
schemaErrorMap: this._def.errorMap,
|
|
908
844
|
parent: null,
|
|
909
845
|
data,
|
|
910
846
|
parsedType: getParsedType(data),
|
|
911
847
|
};
|
|
912
848
|
const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
|
|
913
|
-
const result = await (isAsync(maybeAsyncResult)
|
|
914
|
-
? maybeAsyncResult
|
|
915
|
-
: Promise.resolve(maybeAsyncResult));
|
|
849
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
916
850
|
return handleResult(ctx, result);
|
|
917
851
|
}
|
|
918
852
|
refine(check, message) {
|
|
@@ -956,9 +890,7 @@ class ZodType {
|
|
|
956
890
|
refinement(check, refinementData) {
|
|
957
891
|
return this._refinement((val, ctx) => {
|
|
958
892
|
if (!check(val)) {
|
|
959
|
-
ctx.addIssue(typeof refinementData === "function"
|
|
960
|
-
? refinementData(val, ctx)
|
|
961
|
-
: refinementData);
|
|
893
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
962
894
|
return false;
|
|
963
895
|
}
|
|
964
896
|
else {
|
|
@@ -1130,15 +1062,15 @@ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z
|
|
|
1130
1062
|
const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
1131
1063
|
const dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1132
1064
|
function timeRegexSource(args) {
|
|
1133
|
-
|
|
1134
|
-
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
|
1065
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1135
1066
|
if (args.precision) {
|
|
1136
|
-
|
|
1067
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1137
1068
|
}
|
|
1138
1069
|
else if (args.precision == null) {
|
|
1139
|
-
|
|
1070
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1140
1071
|
}
|
|
1141
|
-
|
|
1072
|
+
const secondsQuantifier = args.precision ? "+" : "?"; // require seconds if precision is nonzero
|
|
1073
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1142
1074
|
}
|
|
1143
1075
|
function timeRegex(args) {
|
|
1144
1076
|
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
@@ -1167,6 +1099,8 @@ function isValidJWT(jwt, alg) {
|
|
|
1167
1099
|
return false;
|
|
1168
1100
|
try {
|
|
1169
1101
|
const [header] = jwt.split(".");
|
|
1102
|
+
if (!header)
|
|
1103
|
+
return false;
|
|
1170
1104
|
// Convert base64url to base64
|
|
1171
1105
|
const base64 = header
|
|
1172
1106
|
.replace(/-/g, "+")
|
|
@@ -1175,13 +1109,15 @@ function isValidJWT(jwt, alg) {
|
|
|
1175
1109
|
const decoded = JSON.parse(atob(base64));
|
|
1176
1110
|
if (typeof decoded !== "object" || decoded === null)
|
|
1177
1111
|
return false;
|
|
1178
|
-
if (
|
|
1112
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1113
|
+
return false;
|
|
1114
|
+
if (!decoded.alg)
|
|
1179
1115
|
return false;
|
|
1180
1116
|
if (alg && decoded.alg !== alg)
|
|
1181
1117
|
return false;
|
|
1182
1118
|
return true;
|
|
1183
1119
|
}
|
|
1184
|
-
catch
|
|
1120
|
+
catch {
|
|
1185
1121
|
return false;
|
|
1186
1122
|
}
|
|
1187
1123
|
}
|
|
@@ -1352,7 +1288,7 @@ class ZodString extends ZodType {
|
|
|
1352
1288
|
try {
|
|
1353
1289
|
new URL(input.data);
|
|
1354
1290
|
}
|
|
1355
|
-
catch
|
|
1291
|
+
catch {
|
|
1356
1292
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1357
1293
|
addIssueToContext(ctx, {
|
|
1358
1294
|
validation: "url",
|
|
@@ -1582,7 +1518,6 @@ class ZodString extends ZodType {
|
|
|
1582
1518
|
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1583
1519
|
}
|
|
1584
1520
|
datetime(options) {
|
|
1585
|
-
var _a, _b;
|
|
1586
1521
|
if (typeof options === "string") {
|
|
1587
1522
|
return this._addCheck({
|
|
1588
1523
|
kind: "datetime",
|
|
@@ -1594,10 +1529,10 @@ class ZodString extends ZodType {
|
|
|
1594
1529
|
}
|
|
1595
1530
|
return this._addCheck({
|
|
1596
1531
|
kind: "datetime",
|
|
1597
|
-
precision: typeof
|
|
1598
|
-
offset:
|
|
1599
|
-
local:
|
|
1600
|
-
...errorUtil.errToObj(options
|
|
1532
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1533
|
+
offset: options?.offset ?? false,
|
|
1534
|
+
local: options?.local ?? false,
|
|
1535
|
+
...errorUtil.errToObj(options?.message),
|
|
1601
1536
|
});
|
|
1602
1537
|
}
|
|
1603
1538
|
date(message) {
|
|
@@ -1613,8 +1548,8 @@ class ZodString extends ZodType {
|
|
|
1613
1548
|
}
|
|
1614
1549
|
return this._addCheck({
|
|
1615
1550
|
kind: "time",
|
|
1616
|
-
precision: typeof
|
|
1617
|
-
...errorUtil.errToObj(options
|
|
1551
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1552
|
+
...errorUtil.errToObj(options?.message),
|
|
1618
1553
|
});
|
|
1619
1554
|
}
|
|
1620
1555
|
duration(message) {
|
|
@@ -1631,8 +1566,8 @@ class ZodString extends ZodType {
|
|
|
1631
1566
|
return this._addCheck({
|
|
1632
1567
|
kind: "includes",
|
|
1633
1568
|
value: value,
|
|
1634
|
-
position: options
|
|
1635
|
-
...errorUtil.errToObj(options
|
|
1569
|
+
position: options?.position,
|
|
1570
|
+
...errorUtil.errToObj(options?.message),
|
|
1636
1571
|
});
|
|
1637
1572
|
}
|
|
1638
1573
|
startsWith(value, message) {
|
|
@@ -1765,11 +1700,10 @@ class ZodString extends ZodType {
|
|
|
1765
1700
|
}
|
|
1766
1701
|
}
|
|
1767
1702
|
ZodString.create = (params) => {
|
|
1768
|
-
var _a;
|
|
1769
1703
|
return new ZodString({
|
|
1770
1704
|
checks: [],
|
|
1771
1705
|
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1772
|
-
coerce:
|
|
1706
|
+
coerce: params?.coerce ?? false,
|
|
1773
1707
|
...processCreateParams(params),
|
|
1774
1708
|
});
|
|
1775
1709
|
};
|
|
@@ -1778,9 +1712,9 @@ function floatSafeRemainder(val, step) {
|
|
|
1778
1712
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1779
1713
|
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1780
1714
|
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1781
|
-
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1782
|
-
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1783
|
-
return (valInt % stepInt) /
|
|
1715
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1716
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1717
|
+
return (valInt % stepInt) / 10 ** decCount;
|
|
1784
1718
|
}
|
|
1785
1719
|
class ZodNumber extends ZodType {
|
|
1786
1720
|
constructor() {
|
|
@@ -1819,9 +1753,7 @@ class ZodNumber extends ZodType {
|
|
|
1819
1753
|
}
|
|
1820
1754
|
}
|
|
1821
1755
|
else if (check.kind === "min") {
|
|
1822
|
-
const tooSmall = check.inclusive
|
|
1823
|
-
? input.data < check.value
|
|
1824
|
-
: input.data <= check.value;
|
|
1756
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1825
1757
|
if (tooSmall) {
|
|
1826
1758
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1827
1759
|
addIssueToContext(ctx, {
|
|
@@ -1836,9 +1768,7 @@ class ZodNumber extends ZodType {
|
|
|
1836
1768
|
}
|
|
1837
1769
|
}
|
|
1838
1770
|
else if (check.kind === "max") {
|
|
1839
|
-
const tooBig = check.inclusive
|
|
1840
|
-
? input.data > check.value
|
|
1841
|
-
: input.data >= check.value;
|
|
1771
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1842
1772
|
if (tooBig) {
|
|
1843
1773
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
1844
1774
|
addIssueToContext(ctx, {
|
|
@@ -1996,15 +1926,13 @@ class ZodNumber extends ZodType {
|
|
|
1996
1926
|
return max;
|
|
1997
1927
|
}
|
|
1998
1928
|
get isInt() {
|
|
1999
|
-
return !!this._def.checks.find((ch) => ch.kind === "int" ||
|
|
2000
|
-
(ch.kind === "multipleOf" && util.isInteger(ch.value)));
|
|
1929
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || (ch.kind === "multipleOf" && util.isInteger(ch.value)));
|
|
2001
1930
|
}
|
|
2002
1931
|
get isFinite() {
|
|
2003
|
-
let max = null
|
|
1932
|
+
let max = null;
|
|
1933
|
+
let min = null;
|
|
2004
1934
|
for (const ch of this._def.checks) {
|
|
2005
|
-
if (ch.kind === "finite" ||
|
|
2006
|
-
ch.kind === "int" ||
|
|
2007
|
-
ch.kind === "multipleOf") {
|
|
1935
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
2008
1936
|
return true;
|
|
2009
1937
|
}
|
|
2010
1938
|
else if (ch.kind === "min") {
|
|
@@ -2023,7 +1951,7 @@ ZodNumber.create = (params) => {
|
|
|
2023
1951
|
return new ZodNumber({
|
|
2024
1952
|
checks: [],
|
|
2025
1953
|
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
2026
|
-
coerce:
|
|
1954
|
+
coerce: params?.coerce || false,
|
|
2027
1955
|
...processCreateParams(params),
|
|
2028
1956
|
});
|
|
2029
1957
|
};
|
|
@@ -2038,7 +1966,7 @@ class ZodBigInt extends ZodType {
|
|
|
2038
1966
|
try {
|
|
2039
1967
|
input.data = BigInt(input.data);
|
|
2040
1968
|
}
|
|
2041
|
-
catch
|
|
1969
|
+
catch {
|
|
2042
1970
|
return this._getInvalidInput(input);
|
|
2043
1971
|
}
|
|
2044
1972
|
}
|
|
@@ -2050,9 +1978,7 @@ class ZodBigInt extends ZodType {
|
|
|
2050
1978
|
const status = new ParseStatus();
|
|
2051
1979
|
for (const check of this._def.checks) {
|
|
2052
1980
|
if (check.kind === "min") {
|
|
2053
|
-
const tooSmall = check.inclusive
|
|
2054
|
-
? input.data < check.value
|
|
2055
|
-
: input.data <= check.value;
|
|
1981
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2056
1982
|
if (tooSmall) {
|
|
2057
1983
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
2058
1984
|
addIssueToContext(ctx, {
|
|
@@ -2066,9 +1992,7 @@ class ZodBigInt extends ZodType {
|
|
|
2066
1992
|
}
|
|
2067
1993
|
}
|
|
2068
1994
|
else if (check.kind === "max") {
|
|
2069
|
-
const tooBig = check.inclusive
|
|
2070
|
-
? input.data > check.value
|
|
2071
|
-
: input.data >= check.value;
|
|
1995
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2072
1996
|
if (tooBig) {
|
|
2073
1997
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
2074
1998
|
addIssueToContext(ctx, {
|
|
@@ -2200,11 +2124,10 @@ class ZodBigInt extends ZodType {
|
|
|
2200
2124
|
}
|
|
2201
2125
|
}
|
|
2202
2126
|
ZodBigInt.create = (params) => {
|
|
2203
|
-
var _a;
|
|
2204
2127
|
return new ZodBigInt({
|
|
2205
2128
|
checks: [],
|
|
2206
2129
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2207
|
-
coerce:
|
|
2130
|
+
coerce: params?.coerce ?? false,
|
|
2208
2131
|
...processCreateParams(params),
|
|
2209
2132
|
});
|
|
2210
2133
|
};
|
|
@@ -2229,7 +2152,7 @@ class ZodBoolean extends ZodType {
|
|
|
2229
2152
|
ZodBoolean.create = (params) => {
|
|
2230
2153
|
return new ZodBoolean({
|
|
2231
2154
|
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2232
|
-
coerce:
|
|
2155
|
+
coerce: params?.coerce || false,
|
|
2233
2156
|
...processCreateParams(params),
|
|
2234
2157
|
});
|
|
2235
2158
|
};
|
|
@@ -2248,7 +2171,7 @@ class ZodDate extends ZodType {
|
|
|
2248
2171
|
});
|
|
2249
2172
|
return INVALID;
|
|
2250
2173
|
}
|
|
2251
|
-
if (isNaN(input.data.getTime())) {
|
|
2174
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2252
2175
|
const ctx = this._getOrReturnCtx(input);
|
|
2253
2176
|
addIssueToContext(ctx, {
|
|
2254
2177
|
code: ZodIssueCode.invalid_date,
|
|
@@ -2339,7 +2262,7 @@ class ZodDate extends ZodType {
|
|
|
2339
2262
|
ZodDate.create = (params) => {
|
|
2340
2263
|
return new ZodDate({
|
|
2341
2264
|
checks: [],
|
|
2342
|
-
coerce:
|
|
2265
|
+
coerce: params?.coerce || false,
|
|
2343
2266
|
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2344
2267
|
...processCreateParams(params),
|
|
2345
2268
|
});
|
|
@@ -2661,7 +2584,8 @@ class ZodObject extends ZodType {
|
|
|
2661
2584
|
return this._cached;
|
|
2662
2585
|
const shape = this._def.shape();
|
|
2663
2586
|
const keys = util.objectKeys(shape);
|
|
2664
|
-
|
|
2587
|
+
this._cached = { shape, keys };
|
|
2588
|
+
return this._cached;
|
|
2665
2589
|
}
|
|
2666
2590
|
_parse(input) {
|
|
2667
2591
|
const parsedType = this._getType(input);
|
|
@@ -2677,8 +2601,7 @@ class ZodObject extends ZodType {
|
|
|
2677
2601
|
const { status, ctx } = this._processInputParams(input);
|
|
2678
2602
|
const { shape, keys: shapeKeys } = this._getCached();
|
|
2679
2603
|
const extraKeys = [];
|
|
2680
|
-
if (!(this._def.catchall instanceof ZodNever &&
|
|
2681
|
-
this._def.unknownKeys === "strip")) {
|
|
2604
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2682
2605
|
for (const key in ctx.data) {
|
|
2683
2606
|
if (!shapeKeys.includes(key)) {
|
|
2684
2607
|
extraKeys.push(key);
|
|
@@ -2766,11 +2689,10 @@ class ZodObject extends ZodType {
|
|
|
2766
2689
|
...(message !== undefined
|
|
2767
2690
|
? {
|
|
2768
2691
|
errorMap: (issue, ctx) => {
|
|
2769
|
-
|
|
2770
|
-
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
2692
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2771
2693
|
if (issue.code === "unrecognized_keys")
|
|
2772
2694
|
return {
|
|
2773
|
-
message:
|
|
2695
|
+
message: errorUtil.errToObj(message).message ?? defaultError,
|
|
2774
2696
|
};
|
|
2775
2697
|
return {
|
|
2776
2698
|
message: defaultError,
|
|
@@ -2902,11 +2824,11 @@ class ZodObject extends ZodType {
|
|
|
2902
2824
|
}
|
|
2903
2825
|
pick(mask) {
|
|
2904
2826
|
const shape = {};
|
|
2905
|
-
util.objectKeys(mask)
|
|
2827
|
+
for (const key of util.objectKeys(mask)) {
|
|
2906
2828
|
if (mask[key] && this.shape[key]) {
|
|
2907
2829
|
shape[key] = this.shape[key];
|
|
2908
2830
|
}
|
|
2909
|
-
}
|
|
2831
|
+
}
|
|
2910
2832
|
return new ZodObject({
|
|
2911
2833
|
...this._def,
|
|
2912
2834
|
shape: () => shape,
|
|
@@ -2914,11 +2836,11 @@ class ZodObject extends ZodType {
|
|
|
2914
2836
|
}
|
|
2915
2837
|
omit(mask) {
|
|
2916
2838
|
const shape = {};
|
|
2917
|
-
util.objectKeys(this.shape)
|
|
2839
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2918
2840
|
if (!mask[key]) {
|
|
2919
2841
|
shape[key] = this.shape[key];
|
|
2920
2842
|
}
|
|
2921
|
-
}
|
|
2843
|
+
}
|
|
2922
2844
|
return new ZodObject({
|
|
2923
2845
|
...this._def,
|
|
2924
2846
|
shape: () => shape,
|
|
@@ -2932,7 +2854,7 @@ class ZodObject extends ZodType {
|
|
|
2932
2854
|
}
|
|
2933
2855
|
partial(mask) {
|
|
2934
2856
|
const newShape = {};
|
|
2935
|
-
util.objectKeys(this.shape)
|
|
2857
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2936
2858
|
const fieldSchema = this.shape[key];
|
|
2937
2859
|
if (mask && !mask[key]) {
|
|
2938
2860
|
newShape[key] = fieldSchema;
|
|
@@ -2940,7 +2862,7 @@ class ZodObject extends ZodType {
|
|
|
2940
2862
|
else {
|
|
2941
2863
|
newShape[key] = fieldSchema.optional();
|
|
2942
2864
|
}
|
|
2943
|
-
}
|
|
2865
|
+
}
|
|
2944
2866
|
return new ZodObject({
|
|
2945
2867
|
...this._def,
|
|
2946
2868
|
shape: () => newShape,
|
|
@@ -2948,7 +2870,7 @@ class ZodObject extends ZodType {
|
|
|
2948
2870
|
}
|
|
2949
2871
|
required(mask) {
|
|
2950
2872
|
const newShape = {};
|
|
2951
|
-
util.objectKeys(this.shape)
|
|
2873
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2952
2874
|
if (mask && !mask[key]) {
|
|
2953
2875
|
newShape[key] = this.shape[key];
|
|
2954
2876
|
}
|
|
@@ -2960,7 +2882,7 @@ class ZodObject extends ZodType {
|
|
|
2960
2882
|
}
|
|
2961
2883
|
newShape[key] = newField;
|
|
2962
2884
|
}
|
|
2963
|
-
}
|
|
2885
|
+
}
|
|
2964
2886
|
return new ZodObject({
|
|
2965
2887
|
...this._def,
|
|
2966
2888
|
shape: () => newShape,
|
|
@@ -3093,137 +3015,6 @@ ZodUnion.create = (types, params) => {
|
|
|
3093
3015
|
...processCreateParams(params),
|
|
3094
3016
|
});
|
|
3095
3017
|
};
|
|
3096
|
-
/////////////////////////////////////////////////////
|
|
3097
|
-
/////////////////////////////////////////////////////
|
|
3098
|
-
////////// //////////
|
|
3099
|
-
////////// ZodDiscriminatedUnion //////////
|
|
3100
|
-
////////// //////////
|
|
3101
|
-
/////////////////////////////////////////////////////
|
|
3102
|
-
/////////////////////////////////////////////////////
|
|
3103
|
-
const getDiscriminator = (type) => {
|
|
3104
|
-
if (type instanceof ZodLazy) {
|
|
3105
|
-
return getDiscriminator(type.schema);
|
|
3106
|
-
}
|
|
3107
|
-
else if (type instanceof ZodEffects) {
|
|
3108
|
-
return getDiscriminator(type.innerType());
|
|
3109
|
-
}
|
|
3110
|
-
else if (type instanceof ZodLiteral) {
|
|
3111
|
-
return [type.value];
|
|
3112
|
-
}
|
|
3113
|
-
else if (type instanceof ZodEnum) {
|
|
3114
|
-
return type.options;
|
|
3115
|
-
}
|
|
3116
|
-
else if (type instanceof ZodNativeEnum) {
|
|
3117
|
-
// eslint-disable-next-line ban/ban
|
|
3118
|
-
return util.objectValues(type.enum);
|
|
3119
|
-
}
|
|
3120
|
-
else if (type instanceof ZodDefault) {
|
|
3121
|
-
return getDiscriminator(type._def.innerType);
|
|
3122
|
-
}
|
|
3123
|
-
else if (type instanceof ZodUndefined) {
|
|
3124
|
-
return [undefined];
|
|
3125
|
-
}
|
|
3126
|
-
else if (type instanceof ZodNull) {
|
|
3127
|
-
return [null];
|
|
3128
|
-
}
|
|
3129
|
-
else if (type instanceof ZodOptional) {
|
|
3130
|
-
return [undefined, ...getDiscriminator(type.unwrap())];
|
|
3131
|
-
}
|
|
3132
|
-
else if (type instanceof ZodNullable) {
|
|
3133
|
-
return [null, ...getDiscriminator(type.unwrap())];
|
|
3134
|
-
}
|
|
3135
|
-
else if (type instanceof ZodBranded) {
|
|
3136
|
-
return getDiscriminator(type.unwrap());
|
|
3137
|
-
}
|
|
3138
|
-
else if (type instanceof ZodReadonly) {
|
|
3139
|
-
return getDiscriminator(type.unwrap());
|
|
3140
|
-
}
|
|
3141
|
-
else if (type instanceof ZodCatch) {
|
|
3142
|
-
return getDiscriminator(type._def.innerType);
|
|
3143
|
-
}
|
|
3144
|
-
else {
|
|
3145
|
-
return [];
|
|
3146
|
-
}
|
|
3147
|
-
};
|
|
3148
|
-
class ZodDiscriminatedUnion extends ZodType {
|
|
3149
|
-
_parse(input) {
|
|
3150
|
-
const { ctx } = this._processInputParams(input);
|
|
3151
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3152
|
-
addIssueToContext(ctx, {
|
|
3153
|
-
code: ZodIssueCode.invalid_type,
|
|
3154
|
-
expected: ZodParsedType.object,
|
|
3155
|
-
received: ctx.parsedType,
|
|
3156
|
-
});
|
|
3157
|
-
return INVALID;
|
|
3158
|
-
}
|
|
3159
|
-
const discriminator = this.discriminator;
|
|
3160
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
3161
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
3162
|
-
if (!option) {
|
|
3163
|
-
addIssueToContext(ctx, {
|
|
3164
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
3165
|
-
options: Array.from(this.optionsMap.keys()),
|
|
3166
|
-
path: [discriminator],
|
|
3167
|
-
});
|
|
3168
|
-
return INVALID;
|
|
3169
|
-
}
|
|
3170
|
-
if (ctx.common.async) {
|
|
3171
|
-
return option._parseAsync({
|
|
3172
|
-
data: ctx.data,
|
|
3173
|
-
path: ctx.path,
|
|
3174
|
-
parent: ctx,
|
|
3175
|
-
});
|
|
3176
|
-
}
|
|
3177
|
-
else {
|
|
3178
|
-
return option._parseSync({
|
|
3179
|
-
data: ctx.data,
|
|
3180
|
-
path: ctx.path,
|
|
3181
|
-
parent: ctx,
|
|
3182
|
-
});
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
get discriminator() {
|
|
3186
|
-
return this._def.discriminator;
|
|
3187
|
-
}
|
|
3188
|
-
get options() {
|
|
3189
|
-
return this._def.options;
|
|
3190
|
-
}
|
|
3191
|
-
get optionsMap() {
|
|
3192
|
-
return this._def.optionsMap;
|
|
3193
|
-
}
|
|
3194
|
-
/**
|
|
3195
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3196
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3197
|
-
* have a different value for each object in the union.
|
|
3198
|
-
* @param discriminator the name of the discriminator property
|
|
3199
|
-
* @param types an array of object schemas
|
|
3200
|
-
* @param params
|
|
3201
|
-
*/
|
|
3202
|
-
static create(discriminator, options, params) {
|
|
3203
|
-
// Get all the valid discriminator values
|
|
3204
|
-
const optionsMap = new Map();
|
|
3205
|
-
// try {
|
|
3206
|
-
for (const type of options) {
|
|
3207
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3208
|
-
if (!discriminatorValues.length) {
|
|
3209
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3210
|
-
}
|
|
3211
|
-
for (const value of discriminatorValues) {
|
|
3212
|
-
if (optionsMap.has(value)) {
|
|
3213
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3214
|
-
}
|
|
3215
|
-
optionsMap.set(value, type);
|
|
3216
|
-
}
|
|
3217
|
-
}
|
|
3218
|
-
return new ZodDiscriminatedUnion({
|
|
3219
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3220
|
-
discriminator,
|
|
3221
|
-
options,
|
|
3222
|
-
optionsMap,
|
|
3223
|
-
...processCreateParams(params),
|
|
3224
|
-
});
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
3018
|
function mergeValues(a, b) {
|
|
3228
3019
|
const aType = getParsedType(a);
|
|
3229
3020
|
const bType = getParsedType(b);
|
|
@@ -3232,9 +3023,7 @@ function mergeValues(a, b) {
|
|
|
3232
3023
|
}
|
|
3233
3024
|
else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
3234
3025
|
const bKeys = util.objectKeys(b);
|
|
3235
|
-
const sharedKeys = util
|
|
3236
|
-
.objectKeys(a)
|
|
3237
|
-
.filter((key) => bKeys.indexOf(key) !== -1);
|
|
3026
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3238
3027
|
const newObj = { ...a, ...b };
|
|
3239
3028
|
for (const key of sharedKeys) {
|
|
3240
3029
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
@@ -3261,9 +3050,7 @@ function mergeValues(a, b) {
|
|
|
3261
3050
|
}
|
|
3262
3051
|
return { valid: true, data: newArray };
|
|
3263
3052
|
}
|
|
3264
|
-
else if (aType === ZodParsedType.date &&
|
|
3265
|
-
bType === ZodParsedType.date &&
|
|
3266
|
-
+a === +b) {
|
|
3053
|
+
else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
3267
3054
|
return { valid: true, data: a };
|
|
3268
3055
|
}
|
|
3269
3056
|
else {
|
|
@@ -3324,6 +3111,7 @@ ZodIntersection.create = (left, right, params) => {
|
|
|
3324
3111
|
...processCreateParams(params),
|
|
3325
3112
|
});
|
|
3326
3113
|
};
|
|
3114
|
+
// type ZodTupleItems = [ZodTypeAny, ...ZodTypeAny[]];
|
|
3327
3115
|
class ZodTuple extends ZodType {
|
|
3328
3116
|
_parse(input) {
|
|
3329
3117
|
const { status, ctx } = this._processInputParams(input);
|
|
@@ -3394,60 +3182,6 @@ ZodTuple.create = (schemas, params) => {
|
|
|
3394
3182
|
...processCreateParams(params),
|
|
3395
3183
|
});
|
|
3396
3184
|
};
|
|
3397
|
-
class ZodRecord extends ZodType {
|
|
3398
|
-
get keySchema() {
|
|
3399
|
-
return this._def.keyType;
|
|
3400
|
-
}
|
|
3401
|
-
get valueSchema() {
|
|
3402
|
-
return this._def.valueType;
|
|
3403
|
-
}
|
|
3404
|
-
_parse(input) {
|
|
3405
|
-
const { status, ctx } = this._processInputParams(input);
|
|
3406
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3407
|
-
addIssueToContext(ctx, {
|
|
3408
|
-
code: ZodIssueCode.invalid_type,
|
|
3409
|
-
expected: ZodParsedType.object,
|
|
3410
|
-
received: ctx.parsedType,
|
|
3411
|
-
});
|
|
3412
|
-
return INVALID;
|
|
3413
|
-
}
|
|
3414
|
-
const pairs = [];
|
|
3415
|
-
const keyType = this._def.keyType;
|
|
3416
|
-
const valueType = this._def.valueType;
|
|
3417
|
-
for (const key in ctx.data) {
|
|
3418
|
-
pairs.push({
|
|
3419
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3420
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3421
|
-
alwaysSet: key in ctx.data,
|
|
3422
|
-
});
|
|
3423
|
-
}
|
|
3424
|
-
if (ctx.common.async) {
|
|
3425
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3426
|
-
}
|
|
3427
|
-
else {
|
|
3428
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3429
|
-
}
|
|
3430
|
-
}
|
|
3431
|
-
get element() {
|
|
3432
|
-
return this._def.valueType;
|
|
3433
|
-
}
|
|
3434
|
-
static create(first, second, third) {
|
|
3435
|
-
if (second instanceof ZodType) {
|
|
3436
|
-
return new ZodRecord({
|
|
3437
|
-
keyType: first,
|
|
3438
|
-
valueType: second,
|
|
3439
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3440
|
-
...processCreateParams(third),
|
|
3441
|
-
});
|
|
3442
|
-
}
|
|
3443
|
-
return new ZodRecord({
|
|
3444
|
-
keyType: ZodString.create(),
|
|
3445
|
-
valueType: first,
|
|
3446
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3447
|
-
...processCreateParams(second),
|
|
3448
|
-
});
|
|
3449
|
-
}
|
|
3450
|
-
}
|
|
3451
3185
|
class ZodMap extends ZodType {
|
|
3452
3186
|
get keySchema() {
|
|
3453
3187
|
return this._def.keyType;
|
|
@@ -3601,134 +3335,6 @@ ZodSet.create = (valueType, params) => {
|
|
|
3601
3335
|
...processCreateParams(params),
|
|
3602
3336
|
});
|
|
3603
3337
|
};
|
|
3604
|
-
class ZodFunction extends ZodType {
|
|
3605
|
-
constructor() {
|
|
3606
|
-
super(...arguments);
|
|
3607
|
-
this.validate = this.implement;
|
|
3608
|
-
}
|
|
3609
|
-
_parse(input) {
|
|
3610
|
-
const { ctx } = this._processInputParams(input);
|
|
3611
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3612
|
-
addIssueToContext(ctx, {
|
|
3613
|
-
code: ZodIssueCode.invalid_type,
|
|
3614
|
-
expected: ZodParsedType.function,
|
|
3615
|
-
received: ctx.parsedType,
|
|
3616
|
-
});
|
|
3617
|
-
return INVALID;
|
|
3618
|
-
}
|
|
3619
|
-
function makeArgsIssue(args, error) {
|
|
3620
|
-
return makeIssue({
|
|
3621
|
-
data: args,
|
|
3622
|
-
path: ctx.path,
|
|
3623
|
-
errorMaps: [
|
|
3624
|
-
ctx.common.contextualErrorMap,
|
|
3625
|
-
ctx.schemaErrorMap,
|
|
3626
|
-
getErrorMap(),
|
|
3627
|
-
errorMap,
|
|
3628
|
-
].filter((x) => !!x),
|
|
3629
|
-
issueData: {
|
|
3630
|
-
code: ZodIssueCode.invalid_arguments,
|
|
3631
|
-
argumentsError: error,
|
|
3632
|
-
},
|
|
3633
|
-
});
|
|
3634
|
-
}
|
|
3635
|
-
function makeReturnsIssue(returns, error) {
|
|
3636
|
-
return makeIssue({
|
|
3637
|
-
data: returns,
|
|
3638
|
-
path: ctx.path,
|
|
3639
|
-
errorMaps: [
|
|
3640
|
-
ctx.common.contextualErrorMap,
|
|
3641
|
-
ctx.schemaErrorMap,
|
|
3642
|
-
getErrorMap(),
|
|
3643
|
-
errorMap,
|
|
3644
|
-
].filter((x) => !!x),
|
|
3645
|
-
issueData: {
|
|
3646
|
-
code: ZodIssueCode.invalid_return_type,
|
|
3647
|
-
returnTypeError: error,
|
|
3648
|
-
},
|
|
3649
|
-
});
|
|
3650
|
-
}
|
|
3651
|
-
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3652
|
-
const fn = ctx.data;
|
|
3653
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
3654
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3655
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3656
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3657
|
-
const me = this;
|
|
3658
|
-
return OK(async function (...args) {
|
|
3659
|
-
const error = new ZodError([]);
|
|
3660
|
-
const parsedArgs = await me._def.args
|
|
3661
|
-
.parseAsync(args, params)
|
|
3662
|
-
.catch((e) => {
|
|
3663
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
3664
|
-
throw error;
|
|
3665
|
-
});
|
|
3666
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3667
|
-
const parsedReturns = await me._def.returns._def.type
|
|
3668
|
-
.parseAsync(result, params)
|
|
3669
|
-
.catch((e) => {
|
|
3670
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
3671
|
-
throw error;
|
|
3672
|
-
});
|
|
3673
|
-
return parsedReturns;
|
|
3674
|
-
});
|
|
3675
|
-
}
|
|
3676
|
-
else {
|
|
3677
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3678
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3679
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3680
|
-
const me = this;
|
|
3681
|
-
return OK(function (...args) {
|
|
3682
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3683
|
-
if (!parsedArgs.success) {
|
|
3684
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3685
|
-
}
|
|
3686
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3687
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3688
|
-
if (!parsedReturns.success) {
|
|
3689
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3690
|
-
}
|
|
3691
|
-
return parsedReturns.data;
|
|
3692
|
-
});
|
|
3693
|
-
}
|
|
3694
|
-
}
|
|
3695
|
-
parameters() {
|
|
3696
|
-
return this._def.args;
|
|
3697
|
-
}
|
|
3698
|
-
returnType() {
|
|
3699
|
-
return this._def.returns;
|
|
3700
|
-
}
|
|
3701
|
-
args(...items) {
|
|
3702
|
-
return new ZodFunction({
|
|
3703
|
-
...this._def,
|
|
3704
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create()),
|
|
3705
|
-
});
|
|
3706
|
-
}
|
|
3707
|
-
returns(returnType) {
|
|
3708
|
-
return new ZodFunction({
|
|
3709
|
-
...this._def,
|
|
3710
|
-
returns: returnType,
|
|
3711
|
-
});
|
|
3712
|
-
}
|
|
3713
|
-
implement(func) {
|
|
3714
|
-
const validatedFunc = this.parse(func);
|
|
3715
|
-
return validatedFunc;
|
|
3716
|
-
}
|
|
3717
|
-
strictImplement(func) {
|
|
3718
|
-
const validatedFunc = this.parse(func);
|
|
3719
|
-
return validatedFunc;
|
|
3720
|
-
}
|
|
3721
|
-
static create(args, returns, params) {
|
|
3722
|
-
return new ZodFunction({
|
|
3723
|
-
args: (args
|
|
3724
|
-
? args
|
|
3725
|
-
: ZodTuple.create([]).rest(ZodUnknown.create())),
|
|
3726
|
-
returns: returns || ZodUnknown.create(),
|
|
3727
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3728
|
-
...processCreateParams(params),
|
|
3729
|
-
});
|
|
3730
|
-
}
|
|
3731
|
-
}
|
|
3732
3338
|
class ZodLazy extends ZodType {
|
|
3733
3339
|
get schema() {
|
|
3734
3340
|
return this._def.getter();
|
|
@@ -3778,10 +3384,6 @@ function createZodEnum(values, params) {
|
|
|
3778
3384
|
});
|
|
3779
3385
|
}
|
|
3780
3386
|
class ZodEnum extends ZodType {
|
|
3781
|
-
constructor() {
|
|
3782
|
-
super(...arguments);
|
|
3783
|
-
_ZodEnum_cache.set(this, void 0);
|
|
3784
|
-
}
|
|
3785
3387
|
_parse(input) {
|
|
3786
3388
|
if (typeof input.data !== "string") {
|
|
3787
3389
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3793,10 +3395,10 @@ class ZodEnum extends ZodType {
|
|
|
3793
3395
|
});
|
|
3794
3396
|
return INVALID;
|
|
3795
3397
|
}
|
|
3796
|
-
if (!
|
|
3797
|
-
|
|
3398
|
+
if (!this._cache) {
|
|
3399
|
+
this._cache = new Set(this._def.values);
|
|
3798
3400
|
}
|
|
3799
|
-
if (!
|
|
3401
|
+
if (!this._cache.has(input.data)) {
|
|
3800
3402
|
const ctx = this._getOrReturnCtx(input);
|
|
3801
3403
|
const expectedValues = this._def.values;
|
|
3802
3404
|
addIssueToContext(ctx, {
|
|
@@ -3845,18 +3447,12 @@ class ZodEnum extends ZodType {
|
|
|
3845
3447
|
});
|
|
3846
3448
|
}
|
|
3847
3449
|
}
|
|
3848
|
-
_ZodEnum_cache = new WeakMap();
|
|
3849
3450
|
ZodEnum.create = createZodEnum;
|
|
3850
3451
|
class ZodNativeEnum extends ZodType {
|
|
3851
|
-
constructor() {
|
|
3852
|
-
super(...arguments);
|
|
3853
|
-
_ZodNativeEnum_cache.set(this, void 0);
|
|
3854
|
-
}
|
|
3855
3452
|
_parse(input) {
|
|
3856
3453
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3857
3454
|
const ctx = this._getOrReturnCtx(input);
|
|
3858
|
-
if (ctx.parsedType !== ZodParsedType.string &&
|
|
3859
|
-
ctx.parsedType !== ZodParsedType.number) {
|
|
3455
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3860
3456
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3861
3457
|
addIssueToContext(ctx, {
|
|
3862
3458
|
expected: util.joinValues(expectedValues),
|
|
@@ -3865,10 +3461,10 @@ class ZodNativeEnum extends ZodType {
|
|
|
3865
3461
|
});
|
|
3866
3462
|
return INVALID;
|
|
3867
3463
|
}
|
|
3868
|
-
if (!
|
|
3869
|
-
|
|
3464
|
+
if (!this._cache) {
|
|
3465
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3870
3466
|
}
|
|
3871
|
-
if (!
|
|
3467
|
+
if (!this._cache.has(input.data)) {
|
|
3872
3468
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3873
3469
|
addIssueToContext(ctx, {
|
|
3874
3470
|
received: ctx.data,
|
|
@@ -3883,7 +3479,6 @@ class ZodNativeEnum extends ZodType {
|
|
|
3883
3479
|
return this._def.values;
|
|
3884
3480
|
}
|
|
3885
3481
|
}
|
|
3886
|
-
_ZodNativeEnum_cache = new WeakMap();
|
|
3887
3482
|
ZodNativeEnum.create = (values, params) => {
|
|
3888
3483
|
return new ZodNativeEnum({
|
|
3889
3484
|
values: values,
|
|
@@ -3897,8 +3492,7 @@ class ZodPromise extends ZodType {
|
|
|
3897
3492
|
}
|
|
3898
3493
|
_parse(input) {
|
|
3899
3494
|
const { ctx } = this._processInputParams(input);
|
|
3900
|
-
if (ctx.parsedType !== ZodParsedType.promise &&
|
|
3901
|
-
ctx.common.async === false) {
|
|
3495
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3902
3496
|
addIssueToContext(ctx, {
|
|
3903
3497
|
code: ZodIssueCode.invalid_type,
|
|
3904
3498
|
expected: ZodParsedType.promise,
|
|
@@ -3906,9 +3500,7 @@ class ZodPromise extends ZodType {
|
|
|
3906
3500
|
});
|
|
3907
3501
|
return INVALID;
|
|
3908
3502
|
}
|
|
3909
|
-
const promisified = ctx.parsedType === ZodParsedType.promise
|
|
3910
|
-
? ctx.data
|
|
3911
|
-
: Promise.resolve(ctx.data);
|
|
3503
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3912
3504
|
return OK(promisified.then((data) => {
|
|
3913
3505
|
return this._def.type.parseAsync(data, {
|
|
3914
3506
|
path: ctx.path,
|
|
@@ -4014,9 +3606,7 @@ class ZodEffects extends ZodType {
|
|
|
4014
3606
|
return { status: status.value, value: inner.value };
|
|
4015
3607
|
}
|
|
4016
3608
|
else {
|
|
4017
|
-
return this._def.schema
|
|
4018
|
-
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
4019
|
-
.then((inner) => {
|
|
3609
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
|
|
4020
3610
|
if (inner.status === "aborted")
|
|
4021
3611
|
return INVALID;
|
|
4022
3612
|
if (inner.status === "dirty")
|
|
@@ -4035,7 +3625,7 @@ class ZodEffects extends ZodType {
|
|
|
4035
3625
|
parent: ctx,
|
|
4036
3626
|
});
|
|
4037
3627
|
if (!isValid(base))
|
|
4038
|
-
return
|
|
3628
|
+
return INVALID;
|
|
4039
3629
|
const result = effect.transform(base.value, checkCtx);
|
|
4040
3630
|
if (result instanceof Promise) {
|
|
4041
3631
|
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
@@ -4043,12 +3633,13 @@ class ZodEffects extends ZodType {
|
|
|
4043
3633
|
return { status: status.value, value: result };
|
|
4044
3634
|
}
|
|
4045
3635
|
else {
|
|
4046
|
-
return this._def.schema
|
|
4047
|
-
._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
|
|
4048
|
-
.then((base) => {
|
|
3636
|
+
return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
|
|
4049
3637
|
if (!isValid(base))
|
|
4050
|
-
return
|
|
4051
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3638
|
+
return INVALID;
|
|
3639
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
3640
|
+
status: status.value,
|
|
3641
|
+
value: result,
|
|
3642
|
+
}));
|
|
4052
3643
|
});
|
|
4053
3644
|
}
|
|
4054
3645
|
}
|
|
@@ -4130,9 +3721,7 @@ ZodDefault.create = (type, params) => {
|
|
|
4130
3721
|
return new ZodDefault({
|
|
4131
3722
|
innerType: type,
|
|
4132
3723
|
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
4133
|
-
defaultValue: typeof params.default === "function"
|
|
4134
|
-
? params.default
|
|
4135
|
-
: () => params.default,
|
|
3724
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
4136
3725
|
...processCreateParams(params),
|
|
4137
3726
|
});
|
|
4138
3727
|
};
|
|
@@ -4216,7 +3805,6 @@ ZodNaN.create = (params) => {
|
|
|
4216
3805
|
...processCreateParams(params),
|
|
4217
3806
|
});
|
|
4218
3807
|
};
|
|
4219
|
-
const BRAND = Symbol("zod_brand");
|
|
4220
3808
|
class ZodBranded extends ZodType {
|
|
4221
3809
|
_parse(input) {
|
|
4222
3810
|
const { ctx } = this._processInputParams(input);
|
|
@@ -4298,9 +3886,7 @@ class ZodReadonly extends ZodType {
|
|
|
4298
3886
|
}
|
|
4299
3887
|
return data;
|
|
4300
3888
|
};
|
|
4301
|
-
return isAsync(result)
|
|
4302
|
-
? result.then((data) => freeze(data))
|
|
4303
|
-
: freeze(result);
|
|
3889
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
4304
3890
|
}
|
|
4305
3891
|
unwrap() {
|
|
4306
3892
|
return this._def.innerType;
|
|
@@ -4313,60 +3899,6 @@ ZodReadonly.create = (type, params) => {
|
|
|
4313
3899
|
...processCreateParams(params),
|
|
4314
3900
|
});
|
|
4315
3901
|
};
|
|
4316
|
-
////////////////////////////////////////
|
|
4317
|
-
////////////////////////////////////////
|
|
4318
|
-
////////// //////////
|
|
4319
|
-
////////// z.custom //////////
|
|
4320
|
-
////////// //////////
|
|
4321
|
-
////////////////////////////////////////
|
|
4322
|
-
////////////////////////////////////////
|
|
4323
|
-
function cleanParams(params, data) {
|
|
4324
|
-
const p = typeof params === "function"
|
|
4325
|
-
? params(data)
|
|
4326
|
-
: typeof params === "string"
|
|
4327
|
-
? { message: params }
|
|
4328
|
-
: params;
|
|
4329
|
-
const p2 = typeof p === "string" ? { message: p } : p;
|
|
4330
|
-
return p2;
|
|
4331
|
-
}
|
|
4332
|
-
function custom(check, _params = {},
|
|
4333
|
-
/**
|
|
4334
|
-
* @deprecated
|
|
4335
|
-
*
|
|
4336
|
-
* Pass `fatal` into the params object instead:
|
|
4337
|
-
*
|
|
4338
|
-
* ```ts
|
|
4339
|
-
* z.string().custom((val) => val.length > 5, { fatal: false })
|
|
4340
|
-
* ```
|
|
4341
|
-
*
|
|
4342
|
-
*/
|
|
4343
|
-
fatal) {
|
|
4344
|
-
if (check)
|
|
4345
|
-
return ZodAny.create().superRefine((data, ctx) => {
|
|
4346
|
-
var _a, _b;
|
|
4347
|
-
const r = check(data);
|
|
4348
|
-
if (r instanceof Promise) {
|
|
4349
|
-
return r.then((r) => {
|
|
4350
|
-
var _a, _b;
|
|
4351
|
-
if (!r) {
|
|
4352
|
-
const params = cleanParams(_params, data);
|
|
4353
|
-
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4354
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4355
|
-
}
|
|
4356
|
-
});
|
|
4357
|
-
}
|
|
4358
|
-
if (!r) {
|
|
4359
|
-
const params = cleanParams(_params, data);
|
|
4360
|
-
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
4361
|
-
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
4362
|
-
}
|
|
4363
|
-
return;
|
|
4364
|
-
});
|
|
4365
|
-
return ZodAny.create();
|
|
4366
|
-
}
|
|
4367
|
-
const late = {
|
|
4368
|
-
object: ZodObject.lazycreate,
|
|
4369
|
-
};
|
|
4370
3902
|
var ZodFirstPartyTypeKind;
|
|
4371
3903
|
(function (ZodFirstPartyTypeKind) {
|
|
4372
3904
|
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
@@ -4406,48 +3938,20 @@ var ZodFirstPartyTypeKind;
|
|
|
4406
3938
|
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
4407
3939
|
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
4408
3940
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
const dateType = ZodDate.create;
|
|
4420
|
-
const symbolType = ZodSymbol.create;
|
|
4421
|
-
const undefinedType = ZodUndefined.create;
|
|
4422
|
-
const nullType = ZodNull.create;
|
|
4423
|
-
const anyType = ZodAny.create;
|
|
4424
|
-
const unknownType = ZodUnknown.create;
|
|
4425
|
-
const neverType = ZodNever.create;
|
|
4426
|
-
const voidType = ZodVoid.create;
|
|
4427
|
-
const arrayType = ZodArray.create;
|
|
4428
|
-
const objectType = ZodObject.create;
|
|
4429
|
-
const strictObjectType = ZodObject.strictCreate;
|
|
4430
|
-
const unionType = ZodUnion.create;
|
|
4431
|
-
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4432
|
-
const intersectionType = ZodIntersection.create;
|
|
4433
|
-
const tupleType = ZodTuple.create;
|
|
4434
|
-
const recordType = ZodRecord.create;
|
|
4435
|
-
const mapType = ZodMap.create;
|
|
4436
|
-
const setType = ZodSet.create;
|
|
4437
|
-
const functionType = ZodFunction.create;
|
|
4438
|
-
const lazyType = ZodLazy.create;
|
|
4439
|
-
const literalType = ZodLiteral.create;
|
|
3941
|
+
ZodString.create;
|
|
3942
|
+
ZodNumber.create;
|
|
3943
|
+
ZodBigInt.create;
|
|
3944
|
+
ZodBoolean.create;
|
|
3945
|
+
ZodDate.create;
|
|
3946
|
+
ZodNever.create;
|
|
3947
|
+
ZodArray.create;
|
|
3948
|
+
ZodUnion.create;
|
|
3949
|
+
ZodIntersection.create;
|
|
3950
|
+
ZodTuple.create;
|
|
4440
3951
|
const enumType = ZodEnum.create;
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
const optionalType = ZodOptional.create;
|
|
4445
|
-
const nullableType = ZodNullable.create;
|
|
4446
|
-
const preprocessType = ZodEffects.createWithPreprocess;
|
|
4447
|
-
const pipelineType = ZodPipeline.create;
|
|
4448
|
-
const ostring = () => stringType().optional();
|
|
4449
|
-
const onumber = () => numberType().optional();
|
|
4450
|
-
const oboolean = () => booleanType().optional();
|
|
3952
|
+
ZodPromise.create;
|
|
3953
|
+
ZodOptional.create;
|
|
3954
|
+
ZodNullable.create;
|
|
4451
3955
|
const coerce = {
|
|
4452
3956
|
string: ((arg) => ZodString.create({ ...arg, coerce: true })),
|
|
4453
3957
|
number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
|
|
@@ -4458,122 +3962,10 @@ const coerce = {
|
|
|
4458
3962
|
bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
|
|
4459
3963
|
date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
|
|
4460
3964
|
};
|
|
4461
|
-
const NEVER = INVALID;
|
|
4462
|
-
|
|
4463
|
-
var z = /*#__PURE__*/Object.freeze({
|
|
4464
|
-
__proto__: null,
|
|
4465
|
-
defaultErrorMap: errorMap,
|
|
4466
|
-
setErrorMap: setErrorMap,
|
|
4467
|
-
getErrorMap: getErrorMap,
|
|
4468
|
-
makeIssue: makeIssue,
|
|
4469
|
-
EMPTY_PATH: EMPTY_PATH,
|
|
4470
|
-
addIssueToContext: addIssueToContext,
|
|
4471
|
-
ParseStatus: ParseStatus,
|
|
4472
|
-
INVALID: INVALID,
|
|
4473
|
-
DIRTY: DIRTY,
|
|
4474
|
-
OK: OK,
|
|
4475
|
-
isAborted: isAborted,
|
|
4476
|
-
isDirty: isDirty,
|
|
4477
|
-
isValid: isValid,
|
|
4478
|
-
isAsync: isAsync,
|
|
4479
|
-
get util () { return util; },
|
|
4480
|
-
get objectUtil () { return objectUtil; },
|
|
4481
|
-
ZodParsedType: ZodParsedType,
|
|
4482
|
-
getParsedType: getParsedType,
|
|
4483
|
-
ZodType: ZodType,
|
|
4484
|
-
datetimeRegex: datetimeRegex,
|
|
4485
|
-
ZodString: ZodString,
|
|
4486
|
-
ZodNumber: ZodNumber,
|
|
4487
|
-
ZodBigInt: ZodBigInt,
|
|
4488
|
-
ZodBoolean: ZodBoolean,
|
|
4489
|
-
ZodDate: ZodDate,
|
|
4490
|
-
ZodSymbol: ZodSymbol,
|
|
4491
|
-
ZodUndefined: ZodUndefined,
|
|
4492
|
-
ZodNull: ZodNull,
|
|
4493
|
-
ZodAny: ZodAny,
|
|
4494
|
-
ZodUnknown: ZodUnknown,
|
|
4495
|
-
ZodNever: ZodNever,
|
|
4496
|
-
ZodVoid: ZodVoid,
|
|
4497
|
-
ZodArray: ZodArray,
|
|
4498
|
-
ZodObject: ZodObject,
|
|
4499
|
-
ZodUnion: ZodUnion,
|
|
4500
|
-
ZodDiscriminatedUnion: ZodDiscriminatedUnion,
|
|
4501
|
-
ZodIntersection: ZodIntersection,
|
|
4502
|
-
ZodTuple: ZodTuple,
|
|
4503
|
-
ZodRecord: ZodRecord,
|
|
4504
|
-
ZodMap: ZodMap,
|
|
4505
|
-
ZodSet: ZodSet,
|
|
4506
|
-
ZodFunction: ZodFunction,
|
|
4507
|
-
ZodLazy: ZodLazy,
|
|
4508
|
-
ZodLiteral: ZodLiteral,
|
|
4509
|
-
ZodEnum: ZodEnum,
|
|
4510
|
-
ZodNativeEnum: ZodNativeEnum,
|
|
4511
|
-
ZodPromise: ZodPromise,
|
|
4512
|
-
ZodEffects: ZodEffects,
|
|
4513
|
-
ZodTransformer: ZodEffects,
|
|
4514
|
-
ZodOptional: ZodOptional,
|
|
4515
|
-
ZodNullable: ZodNullable,
|
|
4516
|
-
ZodDefault: ZodDefault,
|
|
4517
|
-
ZodCatch: ZodCatch,
|
|
4518
|
-
ZodNaN: ZodNaN,
|
|
4519
|
-
BRAND: BRAND,
|
|
4520
|
-
ZodBranded: ZodBranded,
|
|
4521
|
-
ZodPipeline: ZodPipeline,
|
|
4522
|
-
ZodReadonly: ZodReadonly,
|
|
4523
|
-
custom: custom,
|
|
4524
|
-
Schema: ZodType,
|
|
4525
|
-
ZodSchema: ZodType,
|
|
4526
|
-
late: late,
|
|
4527
|
-
get ZodFirstPartyTypeKind () { return ZodFirstPartyTypeKind; },
|
|
4528
|
-
coerce: coerce,
|
|
4529
|
-
any: anyType,
|
|
4530
|
-
array: arrayType,
|
|
4531
|
-
bigint: bigIntType,
|
|
4532
|
-
boolean: booleanType,
|
|
4533
|
-
date: dateType,
|
|
4534
|
-
discriminatedUnion: discriminatedUnionType,
|
|
4535
|
-
effect: effectsType,
|
|
4536
|
-
'enum': enumType,
|
|
4537
|
-
'function': functionType,
|
|
4538
|
-
'instanceof': instanceOfType,
|
|
4539
|
-
intersection: intersectionType,
|
|
4540
|
-
lazy: lazyType,
|
|
4541
|
-
literal: literalType,
|
|
4542
|
-
map: mapType,
|
|
4543
|
-
nan: nanType,
|
|
4544
|
-
nativeEnum: nativeEnumType,
|
|
4545
|
-
never: neverType,
|
|
4546
|
-
'null': nullType,
|
|
4547
|
-
nullable: nullableType,
|
|
4548
|
-
number: numberType,
|
|
4549
|
-
object: objectType,
|
|
4550
|
-
oboolean: oboolean,
|
|
4551
|
-
onumber: onumber,
|
|
4552
|
-
optional: optionalType,
|
|
4553
|
-
ostring: ostring,
|
|
4554
|
-
pipeline: pipelineType,
|
|
4555
|
-
preprocess: preprocessType,
|
|
4556
|
-
promise: promiseType,
|
|
4557
|
-
record: recordType,
|
|
4558
|
-
set: setType,
|
|
4559
|
-
strictObject: strictObjectType,
|
|
4560
|
-
string: stringType,
|
|
4561
|
-
symbol: symbolType,
|
|
4562
|
-
transformer: effectsType,
|
|
4563
|
-
tuple: tupleType,
|
|
4564
|
-
'undefined': undefinedType,
|
|
4565
|
-
union: unionType,
|
|
4566
|
-
unknown: unknownType,
|
|
4567
|
-
'void': voidType,
|
|
4568
|
-
NEVER: NEVER,
|
|
4569
|
-
ZodIssueCode: ZodIssueCode,
|
|
4570
|
-
quotelessJson: quotelessJson,
|
|
4571
|
-
ZodError: ZodError
|
|
4572
|
-
});
|
|
4573
3965
|
|
|
4574
3966
|
const ageGate = (ageGateType, ageGateValue, legalAge = null) => {
|
|
4575
|
-
const ageGateTypeValidation =
|
|
4576
|
-
const ageDateValidation =
|
|
3967
|
+
const ageGateTypeValidation = enumType([ 'yesno', 'dob' ]);
|
|
3968
|
+
const ageDateValidation = coerce.date();
|
|
4577
3969
|
legalAge = legalAge || 21;
|
|
4578
3970
|
|
|
4579
3971
|
let _type = null;
|