drizzle-kit 0.21.2 → 0.21.4
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/bin.cjs +34625 -26761
- package/index.d.mts +9 -1
- package/index.d.ts +9 -1
- package/package.json +2 -1
- package/payload.d.mts +177 -177
- package/payload.d.ts +177 -177
- package/payload.js +533 -454
- package/payload.mjs +510 -431
- package/utils-studio.js +934 -246
- package/utils-studio.mjs +908 -220
- package/utils.js +842 -215
- package/utils.mjs +817 -190
package/utils.mjs
CHANGED
@@ -571,7 +571,7 @@ import {
|
|
571
571
|
writeFileSync
|
572
572
|
} from "fs";
|
573
573
|
|
574
|
-
// node_modules/.pnpm/chalk@5.
|
574
|
+
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js
|
575
575
|
var ANSI_BACKGROUND_OFFSET = 10;
|
576
576
|
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
577
577
|
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
@@ -757,7 +757,7 @@ function assembleStyles() {
|
|
757
757
|
var ansiStyles = assembleStyles();
|
758
758
|
var ansi_styles_default = ansiStyles;
|
759
759
|
|
760
|
-
// node_modules/.pnpm/chalk@5.
|
760
|
+
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js
|
761
761
|
import process2 from "node:process";
|
762
762
|
import os from "node:os";
|
763
763
|
import tty from "node:tty";
|
@@ -831,7 +831,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
831
831
|
return 1;
|
832
832
|
}
|
833
833
|
if ("CI" in env) {
|
834
|
-
if ("GITHUB_ACTIONS" in env) {
|
834
|
+
if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
|
835
835
|
return 3;
|
836
836
|
}
|
837
837
|
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
@@ -883,7 +883,7 @@ var supportsColor = {
|
|
883
883
|
};
|
884
884
|
var supports_color_default = supportsColor;
|
885
885
|
|
886
|
-
// node_modules/.pnpm/chalk@5.
|
886
|
+
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js
|
887
887
|
function stringReplaceAll(string, substring, replacer) {
|
888
888
|
let index4 = string.indexOf(substring);
|
889
889
|
if (index4 === -1) {
|
@@ -913,7 +913,7 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index4) {
|
|
913
913
|
return returnValue;
|
914
914
|
}
|
915
915
|
|
916
|
-
// node_modules/.pnpm/chalk@5.
|
916
|
+
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
|
917
917
|
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
918
918
|
var GENERATOR = Symbol("GENERATOR");
|
919
919
|
var STYLER = Symbol("STYLER");
|
@@ -1070,7 +1070,7 @@ var info = (msg, greyMsg = "") => {
|
|
1070
1070
|
var originUUID = "00000000-0000-0000-0000-000000000000";
|
1071
1071
|
var snapshotVersion = "6";
|
1072
1072
|
|
1073
|
-
// node_modules/.pnpm/zod@3.
|
1073
|
+
// node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.mjs
|
1074
1074
|
var util;
|
1075
1075
|
(function(util2) {
|
1076
1076
|
util2.assertEqual = (val) => val;
|
@@ -1129,6 +1129,16 @@ var util;
|
|
1129
1129
|
return value;
|
1130
1130
|
};
|
1131
1131
|
})(util || (util = {}));
|
1132
|
+
var objectUtil;
|
1133
|
+
(function(objectUtil2) {
|
1134
|
+
objectUtil2.mergeShapes = (first, second) => {
|
1135
|
+
return {
|
1136
|
+
...first,
|
1137
|
+
...second
|
1138
|
+
// second overwrites first
|
1139
|
+
};
|
1140
|
+
};
|
1141
|
+
})(objectUtil || (objectUtil = {}));
|
1132
1142
|
var ZodParsedType = util.arrayToEnum([
|
1133
1143
|
"string",
|
1134
1144
|
"nan",
|
@@ -1210,7 +1220,7 @@ var ZodIssueCode = util.arrayToEnum([
|
|
1210
1220
|
"not_multiple_of",
|
1211
1221
|
"not_finite"
|
1212
1222
|
]);
|
1213
|
-
var ZodError = class extends Error {
|
1223
|
+
var ZodError = class _ZodError extends Error {
|
1214
1224
|
constructor(issues) {
|
1215
1225
|
super();
|
1216
1226
|
this.issues = [];
|
@@ -1268,6 +1278,11 @@ var ZodError = class extends Error {
|
|
1268
1278
|
processError(this);
|
1269
1279
|
return fieldErrors;
|
1270
1280
|
}
|
1281
|
+
static assert(value) {
|
1282
|
+
if (!(value instanceof _ZodError)) {
|
1283
|
+
throw new Error(`Not a ZodError: ${value}`);
|
1284
|
+
}
|
1285
|
+
}
|
1271
1286
|
toString() {
|
1272
1287
|
return this.message;
|
1273
1288
|
}
|
@@ -1334,7 +1349,12 @@ var errorMap = (issue, _ctx) => {
|
|
1334
1349
|
break;
|
1335
1350
|
case ZodIssueCode.invalid_string:
|
1336
1351
|
if (typeof issue.validation === "object") {
|
1337
|
-
if ("
|
1352
|
+
if ("includes" in issue.validation) {
|
1353
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
1354
|
+
if (typeof issue.validation.position === "number") {
|
1355
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
1356
|
+
}
|
1357
|
+
} else if ("startsWith" in issue.validation) {
|
1338
1358
|
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
1339
1359
|
} else if ("endsWith" in issue.validation) {
|
1340
1360
|
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
@@ -1355,7 +1375,7 @@ var errorMap = (issue, _ctx) => {
|
|
1355
1375
|
else if (issue.type === "number")
|
1356
1376
|
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
1357
1377
|
else if (issue.type === "date")
|
1358
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(issue.minimum)}`;
|
1378
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
1359
1379
|
else
|
1360
1380
|
message = "Invalid input";
|
1361
1381
|
break;
|
@@ -1366,8 +1386,10 @@ var errorMap = (issue, _ctx) => {
|
|
1366
1386
|
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
1367
1387
|
else if (issue.type === "number")
|
1368
1388
|
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
1389
|
+
else if (issue.type === "bigint")
|
1390
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
1369
1391
|
else if (issue.type === "date")
|
1370
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(issue.maximum)}`;
|
1392
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
1371
1393
|
else
|
1372
1394
|
message = "Invalid input";
|
1373
1395
|
break;
|
@@ -1400,6 +1422,13 @@ var makeIssue = (params) => {
|
|
1400
1422
|
...issueData,
|
1401
1423
|
path: fullPath
|
1402
1424
|
};
|
1425
|
+
if (issueData.message !== void 0) {
|
1426
|
+
return {
|
1427
|
+
...issueData,
|
1428
|
+
path: fullPath,
|
1429
|
+
message: issueData.message
|
1430
|
+
};
|
1431
|
+
}
|
1403
1432
|
let errorMessage = "";
|
1404
1433
|
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
1405
1434
|
for (const map of maps) {
|
@@ -1408,10 +1437,11 @@ var makeIssue = (params) => {
|
|
1408
1437
|
return {
|
1409
1438
|
...issueData,
|
1410
1439
|
path: fullPath,
|
1411
|
-
message:
|
1440
|
+
message: errorMessage
|
1412
1441
|
};
|
1413
1442
|
};
|
1414
1443
|
function addIssueToContext(ctx, issueData) {
|
1444
|
+
const overrideMap = getErrorMap();
|
1415
1445
|
const issue = makeIssue({
|
1416
1446
|
issueData,
|
1417
1447
|
data: ctx.data,
|
@@ -1419,8 +1449,8 @@ function addIssueToContext(ctx, issueData) {
|
|
1419
1449
|
errorMaps: [
|
1420
1450
|
ctx.common.contextualErrorMap,
|
1421
1451
|
ctx.schemaErrorMap,
|
1422
|
-
|
1423
|
-
errorMap
|
1452
|
+
overrideMap,
|
1453
|
+
overrideMap === errorMap ? void 0 : errorMap
|
1424
1454
|
// then global default map
|
1425
1455
|
].filter((x) => !!x)
|
1426
1456
|
});
|
@@ -1452,9 +1482,11 @@ var ParseStatus = class _ParseStatus {
|
|
1452
1482
|
static async mergeObjectAsync(status, pairs) {
|
1453
1483
|
const syncPairs = [];
|
1454
1484
|
for (const pair of pairs) {
|
1485
|
+
const key = await pair.key;
|
1486
|
+
const value = await pair.value;
|
1455
1487
|
syncPairs.push({
|
1456
|
-
key
|
1457
|
-
value
|
1488
|
+
key,
|
1489
|
+
value
|
1458
1490
|
});
|
1459
1491
|
}
|
1460
1492
|
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
@@ -1471,7 +1503,7 @@ var ParseStatus = class _ParseStatus {
|
|
1471
1503
|
status.dirty();
|
1472
1504
|
if (value.status === "dirty")
|
1473
1505
|
status.dirty();
|
1474
|
-
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
1506
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
1475
1507
|
finalObject[key.value] = value.value;
|
1476
1508
|
}
|
1477
1509
|
}
|
@@ -1486,21 +1518,47 @@ var OK = (value) => ({ status: "valid", value });
|
|
1486
1518
|
var isAborted = (x) => x.status === "aborted";
|
1487
1519
|
var isDirty = (x) => x.status === "dirty";
|
1488
1520
|
var isValid = (x) => x.status === "valid";
|
1489
|
-
var isAsync = (x) => typeof Promise !==
|
1521
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
1522
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
1523
|
+
if (kind === "a" && !f)
|
1524
|
+
throw new TypeError("Private accessor was defined without a getter");
|
1525
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
1526
|
+
throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
1527
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
1528
|
+
}
|
1529
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
1530
|
+
if (kind === "m")
|
1531
|
+
throw new TypeError("Private method is not writable");
|
1532
|
+
if (kind === "a" && !f)
|
1533
|
+
throw new TypeError("Private accessor was defined without a setter");
|
1534
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
1535
|
+
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
1536
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
1537
|
+
}
|
1490
1538
|
var errorUtil;
|
1491
1539
|
(function(errorUtil2) {
|
1492
1540
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
1493
1541
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
1494
1542
|
})(errorUtil || (errorUtil = {}));
|
1543
|
+
var _ZodEnum_cache;
|
1544
|
+
var _ZodNativeEnum_cache;
|
1495
1545
|
var ParseInputLazyPath = class {
|
1496
1546
|
constructor(parent, value, path, key) {
|
1547
|
+
this._cachedPath = [];
|
1497
1548
|
this.parent = parent;
|
1498
1549
|
this.data = value;
|
1499
1550
|
this._path = path;
|
1500
1551
|
this._key = key;
|
1501
1552
|
}
|
1502
1553
|
get path() {
|
1503
|
-
|
1554
|
+
if (!this._cachedPath.length) {
|
1555
|
+
if (this._key instanceof Array) {
|
1556
|
+
this._cachedPath.push(...this._path, ...this._key);
|
1557
|
+
} else {
|
1558
|
+
this._cachedPath.push(...this._path, this._key);
|
1559
|
+
}
|
1560
|
+
}
|
1561
|
+
return this._cachedPath;
|
1504
1562
|
}
|
1505
1563
|
};
|
1506
1564
|
var handleResult = (ctx, result) => {
|
@@ -1510,8 +1568,16 @@ var handleResult = (ctx, result) => {
|
|
1510
1568
|
if (!ctx.common.issues.length) {
|
1511
1569
|
throw new Error("Validation failed but no issues detected.");
|
1512
1570
|
}
|
1513
|
-
|
1514
|
-
|
1571
|
+
return {
|
1572
|
+
success: false,
|
1573
|
+
get error() {
|
1574
|
+
if (this._error)
|
1575
|
+
return this._error;
|
1576
|
+
const error = new ZodError(ctx.common.issues);
|
1577
|
+
this._error = error;
|
1578
|
+
return this._error;
|
1579
|
+
}
|
1580
|
+
};
|
1515
1581
|
}
|
1516
1582
|
};
|
1517
1583
|
function processCreateParams(params) {
|
@@ -1524,12 +1590,17 @@ function processCreateParams(params) {
|
|
1524
1590
|
if (errorMap2)
|
1525
1591
|
return { errorMap: errorMap2, description };
|
1526
1592
|
const customMap = (iss, ctx) => {
|
1527
|
-
|
1528
|
-
|
1593
|
+
var _a, _b;
|
1594
|
+
const { message } = params;
|
1595
|
+
if (iss.code === "invalid_enum_value") {
|
1596
|
+
return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
|
1597
|
+
}
|
1529
1598
|
if (typeof ctx.data === "undefined") {
|
1530
|
-
return { message:
|
1599
|
+
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
1531
1600
|
}
|
1532
|
-
|
1601
|
+
if (iss.code !== "invalid_type")
|
1602
|
+
return { message: ctx.defaultError };
|
1603
|
+
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
1533
1604
|
};
|
1534
1605
|
return { errorMap: customMap, description };
|
1535
1606
|
}
|
@@ -1558,6 +1629,7 @@ var ZodType = class {
|
|
1558
1629
|
this.catch = this.catch.bind(this);
|
1559
1630
|
this.describe = this.describe.bind(this);
|
1560
1631
|
this.pipe = this.pipe.bind(this);
|
1632
|
+
this.readonly = this.readonly.bind(this);
|
1561
1633
|
this.isNullable = this.isNullable.bind(this);
|
1562
1634
|
this.isOptional = this.isOptional.bind(this);
|
1563
1635
|
}
|
@@ -1702,28 +1774,29 @@ var ZodType = class {
|
|
1702
1774
|
return this._refinement(refinement);
|
1703
1775
|
}
|
1704
1776
|
optional() {
|
1705
|
-
return ZodOptional.create(this);
|
1777
|
+
return ZodOptional.create(this, this._def);
|
1706
1778
|
}
|
1707
1779
|
nullable() {
|
1708
|
-
return ZodNullable.create(this);
|
1780
|
+
return ZodNullable.create(this, this._def);
|
1709
1781
|
}
|
1710
1782
|
nullish() {
|
1711
|
-
return this.
|
1783
|
+
return this.nullable().optional();
|
1712
1784
|
}
|
1713
1785
|
array() {
|
1714
|
-
return ZodArray.create(this);
|
1786
|
+
return ZodArray.create(this, this._def);
|
1715
1787
|
}
|
1716
1788
|
promise() {
|
1717
|
-
return ZodPromise.create(this);
|
1789
|
+
return ZodPromise.create(this, this._def);
|
1718
1790
|
}
|
1719
1791
|
or(option) {
|
1720
|
-
return ZodUnion.create([this, option]);
|
1792
|
+
return ZodUnion.create([this, option], this._def);
|
1721
1793
|
}
|
1722
1794
|
and(incoming) {
|
1723
|
-
return ZodIntersection.create(this, incoming);
|
1795
|
+
return ZodIntersection.create(this, incoming, this._def);
|
1724
1796
|
}
|
1725
1797
|
transform(transform) {
|
1726
1798
|
return new ZodEffects({
|
1799
|
+
...processCreateParams(this._def),
|
1727
1800
|
schema: this,
|
1728
1801
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
1729
1802
|
effect: { type: "transform", transform }
|
@@ -1732,6 +1805,7 @@ var ZodType = class {
|
|
1732
1805
|
default(def) {
|
1733
1806
|
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
1734
1807
|
return new ZodDefault({
|
1808
|
+
...processCreateParams(this._def),
|
1735
1809
|
innerType: this,
|
1736
1810
|
defaultValue: defaultValueFunc,
|
1737
1811
|
typeName: ZodFirstPartyTypeKind.ZodDefault
|
@@ -1741,14 +1815,15 @@ var ZodType = class {
|
|
1741
1815
|
return new ZodBranded({
|
1742
1816
|
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
1743
1817
|
type: this,
|
1744
|
-
...processCreateParams(
|
1818
|
+
...processCreateParams(this._def)
|
1745
1819
|
});
|
1746
1820
|
}
|
1747
1821
|
catch(def) {
|
1748
|
-
const
|
1822
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
1749
1823
|
return new ZodCatch({
|
1824
|
+
...processCreateParams(this._def),
|
1750
1825
|
innerType: this,
|
1751
|
-
|
1826
|
+
catchValue: catchValueFunc,
|
1752
1827
|
typeName: ZodFirstPartyTypeKind.ZodCatch
|
1753
1828
|
});
|
1754
1829
|
}
|
@@ -1762,6 +1837,9 @@ var ZodType = class {
|
|
1762
1837
|
pipe(target) {
|
1763
1838
|
return ZodPipeline.create(this, target);
|
1764
1839
|
}
|
1840
|
+
readonly() {
|
1841
|
+
return ZodReadonly.create(this);
|
1842
|
+
}
|
1765
1843
|
isOptional() {
|
1766
1844
|
return this.safeParse(void 0).success;
|
1767
1845
|
}
|
@@ -1770,43 +1848,50 @@ var ZodType = class {
|
|
1770
1848
|
}
|
1771
1849
|
};
|
1772
1850
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
1773
|
-
var
|
1774
|
-
var
|
1775
|
-
var
|
1851
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
1852
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
1853
|
+
var 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;
|
1854
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
1855
|
+
var 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)?)??$/;
|
1856
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
1857
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
1858
|
+
var emojiRegex;
|
1859
|
+
var 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])$/;
|
1860
|
+
var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
1861
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
1862
|
+
var 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])))`;
|
1863
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
1864
|
+
function timeRegexSource(args) {
|
1865
|
+
let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
|
1776
1866
|
if (args.precision) {
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
1781
|
-
}
|
1782
|
-
} else if (args.precision === 0) {
|
1783
|
-
if (args.offset) {
|
1784
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$`);
|
1785
|
-
} else {
|
1786
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
1787
|
-
}
|
1788
|
-
} else {
|
1789
|
-
if (args.offset) {
|
1790
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$`);
|
1791
|
-
} else {
|
1792
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
1793
|
-
}
|
1867
|
+
regex = `${regex}\\.\\d{${args.precision}}`;
|
1868
|
+
} else if (args.precision == null) {
|
1869
|
+
regex = `${regex}(\\.\\d+)?`;
|
1794
1870
|
}
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1871
|
+
return regex;
|
1872
|
+
}
|
1873
|
+
function timeRegex(args) {
|
1874
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
1875
|
+
}
|
1876
|
+
function datetimeRegex(args) {
|
1877
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
1878
|
+
const opts = [];
|
1879
|
+
opts.push(args.local ? `Z?` : `Z`);
|
1880
|
+
if (args.offset)
|
1881
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
1882
|
+
regex = `${regex}(${opts.join("|")})`;
|
1883
|
+
return new RegExp(`^${regex}$`);
|
1884
|
+
}
|
1885
|
+
function isValidIP(ip, version) {
|
1886
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
1887
|
+
return true;
|
1809
1888
|
}
|
1889
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
1890
|
+
return true;
|
1891
|
+
}
|
1892
|
+
return false;
|
1893
|
+
}
|
1894
|
+
var ZodString = class _ZodString extends ZodType {
|
1810
1895
|
_parse(input) {
|
1811
1896
|
if (this._def.coerce) {
|
1812
1897
|
input.data = String(input.data);
|
@@ -1814,15 +1899,11 @@ var ZodString = class _ZodString extends ZodType {
|
|
1814
1899
|
const parsedType = this._getType(input);
|
1815
1900
|
if (parsedType !== ZodParsedType.string) {
|
1816
1901
|
const ctx2 = this._getOrReturnCtx(input);
|
1817
|
-
addIssueToContext(
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
received: ctx2.parsedType
|
1823
|
-
}
|
1824
|
-
//
|
1825
|
-
);
|
1902
|
+
addIssueToContext(ctx2, {
|
1903
|
+
code: ZodIssueCode.invalid_type,
|
1904
|
+
expected: ZodParsedType.string,
|
1905
|
+
received: ctx2.parsedType
|
1906
|
+
});
|
1826
1907
|
return INVALID;
|
1827
1908
|
}
|
1828
1909
|
const status = new ParseStatus();
|
@@ -1890,6 +1971,19 @@ var ZodString = class _ZodString extends ZodType {
|
|
1890
1971
|
});
|
1891
1972
|
status.dirty();
|
1892
1973
|
}
|
1974
|
+
} else if (check.kind === "emoji") {
|
1975
|
+
if (!emojiRegex) {
|
1976
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
1977
|
+
}
|
1978
|
+
if (!emojiRegex.test(input.data)) {
|
1979
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
1980
|
+
addIssueToContext(ctx, {
|
1981
|
+
validation: "emoji",
|
1982
|
+
code: ZodIssueCode.invalid_string,
|
1983
|
+
message: check.message
|
1984
|
+
});
|
1985
|
+
status.dirty();
|
1986
|
+
}
|
1893
1987
|
} else if (check.kind === "uuid") {
|
1894
1988
|
if (!uuidRegex.test(input.data)) {
|
1895
1989
|
ctx = this._getOrReturnCtx(input, ctx);
|
@@ -1900,6 +1994,16 @@ var ZodString = class _ZodString extends ZodType {
|
|
1900
1994
|
});
|
1901
1995
|
status.dirty();
|
1902
1996
|
}
|
1997
|
+
} else if (check.kind === "nanoid") {
|
1998
|
+
if (!nanoidRegex.test(input.data)) {
|
1999
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2000
|
+
addIssueToContext(ctx, {
|
2001
|
+
validation: "nanoid",
|
2002
|
+
code: ZodIssueCode.invalid_string,
|
2003
|
+
message: check.message
|
2004
|
+
});
|
2005
|
+
status.dirty();
|
2006
|
+
}
|
1903
2007
|
} else if (check.kind === "cuid") {
|
1904
2008
|
if (!cuidRegex.test(input.data)) {
|
1905
2009
|
ctx = this._getOrReturnCtx(input, ctx);
|
@@ -1910,6 +2014,26 @@ var ZodString = class _ZodString extends ZodType {
|
|
1910
2014
|
});
|
1911
2015
|
status.dirty();
|
1912
2016
|
}
|
2017
|
+
} else if (check.kind === "cuid2") {
|
2018
|
+
if (!cuid2Regex.test(input.data)) {
|
2019
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2020
|
+
addIssueToContext(ctx, {
|
2021
|
+
validation: "cuid2",
|
2022
|
+
code: ZodIssueCode.invalid_string,
|
2023
|
+
message: check.message
|
2024
|
+
});
|
2025
|
+
status.dirty();
|
2026
|
+
}
|
2027
|
+
} else if (check.kind === "ulid") {
|
2028
|
+
if (!ulidRegex.test(input.data)) {
|
2029
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2030
|
+
addIssueToContext(ctx, {
|
2031
|
+
validation: "ulid",
|
2032
|
+
code: ZodIssueCode.invalid_string,
|
2033
|
+
message: check.message
|
2034
|
+
});
|
2035
|
+
status.dirty();
|
2036
|
+
}
|
1913
2037
|
} else if (check.kind === "url") {
|
1914
2038
|
try {
|
1915
2039
|
new URL(input.data);
|
@@ -1936,6 +2060,20 @@ var ZodString = class _ZodString extends ZodType {
|
|
1936
2060
|
}
|
1937
2061
|
} else if (check.kind === "trim") {
|
1938
2062
|
input.data = input.data.trim();
|
2063
|
+
} else if (check.kind === "includes") {
|
2064
|
+
if (!input.data.includes(check.value, check.position)) {
|
2065
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2066
|
+
addIssueToContext(ctx, {
|
2067
|
+
code: ZodIssueCode.invalid_string,
|
2068
|
+
validation: { includes: check.value, position: check.position },
|
2069
|
+
message: check.message
|
2070
|
+
});
|
2071
|
+
status.dirty();
|
2072
|
+
}
|
2073
|
+
} else if (check.kind === "toLowerCase") {
|
2074
|
+
input.data = input.data.toLowerCase();
|
2075
|
+
} else if (check.kind === "toUpperCase") {
|
2076
|
+
input.data = input.data.toUpperCase();
|
1939
2077
|
} else if (check.kind === "startsWith") {
|
1940
2078
|
if (!input.data.startsWith(check.value)) {
|
1941
2079
|
ctx = this._getOrReturnCtx(input, ctx);
|
@@ -1967,12 +2105,71 @@ var ZodString = class _ZodString extends ZodType {
|
|
1967
2105
|
});
|
1968
2106
|
status.dirty();
|
1969
2107
|
}
|
2108
|
+
} else if (check.kind === "date") {
|
2109
|
+
const regex = dateRegex;
|
2110
|
+
if (!regex.test(input.data)) {
|
2111
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2112
|
+
addIssueToContext(ctx, {
|
2113
|
+
code: ZodIssueCode.invalid_string,
|
2114
|
+
validation: "date",
|
2115
|
+
message: check.message
|
2116
|
+
});
|
2117
|
+
status.dirty();
|
2118
|
+
}
|
2119
|
+
} else if (check.kind === "time") {
|
2120
|
+
const regex = timeRegex(check);
|
2121
|
+
if (!regex.test(input.data)) {
|
2122
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2123
|
+
addIssueToContext(ctx, {
|
2124
|
+
code: ZodIssueCode.invalid_string,
|
2125
|
+
validation: "time",
|
2126
|
+
message: check.message
|
2127
|
+
});
|
2128
|
+
status.dirty();
|
2129
|
+
}
|
2130
|
+
} else if (check.kind === "duration") {
|
2131
|
+
if (!durationRegex.test(input.data)) {
|
2132
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2133
|
+
addIssueToContext(ctx, {
|
2134
|
+
validation: "duration",
|
2135
|
+
code: ZodIssueCode.invalid_string,
|
2136
|
+
message: check.message
|
2137
|
+
});
|
2138
|
+
status.dirty();
|
2139
|
+
}
|
2140
|
+
} else if (check.kind === "ip") {
|
2141
|
+
if (!isValidIP(input.data, check.version)) {
|
2142
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2143
|
+
addIssueToContext(ctx, {
|
2144
|
+
validation: "ip",
|
2145
|
+
code: ZodIssueCode.invalid_string,
|
2146
|
+
message: check.message
|
2147
|
+
});
|
2148
|
+
status.dirty();
|
2149
|
+
}
|
2150
|
+
} else if (check.kind === "base64") {
|
2151
|
+
if (!base64Regex.test(input.data)) {
|
2152
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2153
|
+
addIssueToContext(ctx, {
|
2154
|
+
validation: "base64",
|
2155
|
+
code: ZodIssueCode.invalid_string,
|
2156
|
+
message: check.message
|
2157
|
+
});
|
2158
|
+
status.dirty();
|
2159
|
+
}
|
1970
2160
|
} else {
|
1971
2161
|
util.assertNever(check);
|
1972
2162
|
}
|
1973
2163
|
}
|
1974
2164
|
return { status: status.value, value: input.data };
|
1975
2165
|
}
|
2166
|
+
_regex(regex, validation, message) {
|
2167
|
+
return this.refinement((data) => regex.test(data), {
|
2168
|
+
validation,
|
2169
|
+
code: ZodIssueCode.invalid_string,
|
2170
|
+
...errorUtil.errToObj(message)
|
2171
|
+
});
|
2172
|
+
}
|
1976
2173
|
_addCheck(check) {
|
1977
2174
|
return new _ZodString({
|
1978
2175
|
...this._def,
|
@@ -1985,19 +2182,38 @@ var ZodString = class _ZodString extends ZodType {
|
|
1985
2182
|
url(message) {
|
1986
2183
|
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
1987
2184
|
}
|
2185
|
+
emoji(message) {
|
2186
|
+
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
2187
|
+
}
|
1988
2188
|
uuid(message) {
|
1989
2189
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
1990
2190
|
}
|
2191
|
+
nanoid(message) {
|
2192
|
+
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
2193
|
+
}
|
1991
2194
|
cuid(message) {
|
1992
2195
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
1993
2196
|
}
|
2197
|
+
cuid2(message) {
|
2198
|
+
return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
|
2199
|
+
}
|
2200
|
+
ulid(message) {
|
2201
|
+
return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
|
2202
|
+
}
|
2203
|
+
base64(message) {
|
2204
|
+
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
2205
|
+
}
|
2206
|
+
ip(options) {
|
2207
|
+
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
2208
|
+
}
|
1994
2209
|
datetime(options) {
|
1995
|
-
var _a;
|
2210
|
+
var _a, _b;
|
1996
2211
|
if (typeof options === "string") {
|
1997
2212
|
return this._addCheck({
|
1998
2213
|
kind: "datetime",
|
1999
2214
|
precision: null,
|
2000
2215
|
offset: false,
|
2216
|
+
local: false,
|
2001
2217
|
message: options
|
2002
2218
|
});
|
2003
2219
|
}
|
@@ -2005,9 +2221,30 @@ var ZodString = class _ZodString extends ZodType {
|
|
2005
2221
|
kind: "datetime",
|
2006
2222
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
2007
2223
|
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
2224
|
+
local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
|
2225
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
2226
|
+
});
|
2227
|
+
}
|
2228
|
+
date(message) {
|
2229
|
+
return this._addCheck({ kind: "date", message });
|
2230
|
+
}
|
2231
|
+
time(options) {
|
2232
|
+
if (typeof options === "string") {
|
2233
|
+
return this._addCheck({
|
2234
|
+
kind: "time",
|
2235
|
+
precision: null,
|
2236
|
+
message: options
|
2237
|
+
});
|
2238
|
+
}
|
2239
|
+
return this._addCheck({
|
2240
|
+
kind: "time",
|
2241
|
+
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
2008
2242
|
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
2009
2243
|
});
|
2010
2244
|
}
|
2245
|
+
duration(message) {
|
2246
|
+
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
2247
|
+
}
|
2011
2248
|
regex(regex, message) {
|
2012
2249
|
return this._addCheck({
|
2013
2250
|
kind: "regex",
|
@@ -2015,6 +2252,14 @@ var ZodString = class _ZodString extends ZodType {
|
|
2015
2252
|
...errorUtil.errToObj(message)
|
2016
2253
|
});
|
2017
2254
|
}
|
2255
|
+
includes(value, options) {
|
2256
|
+
return this._addCheck({
|
2257
|
+
kind: "includes",
|
2258
|
+
value,
|
2259
|
+
position: options === null || options === void 0 ? void 0 : options.position,
|
2260
|
+
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
2261
|
+
});
|
2262
|
+
}
|
2018
2263
|
startsWith(value, message) {
|
2019
2264
|
return this._addCheck({
|
2020
2265
|
kind: "startsWith",
|
@@ -2050,21 +2295,73 @@ var ZodString = class _ZodString extends ZodType {
|
|
2050
2295
|
...errorUtil.errToObj(message)
|
2051
2296
|
});
|
2052
2297
|
}
|
2298
|
+
/**
|
2299
|
+
* @deprecated Use z.string().min(1) instead.
|
2300
|
+
* @see {@link ZodString.min}
|
2301
|
+
*/
|
2302
|
+
nonempty(message) {
|
2303
|
+
return this.min(1, errorUtil.errToObj(message));
|
2304
|
+
}
|
2305
|
+
trim() {
|
2306
|
+
return new _ZodString({
|
2307
|
+
...this._def,
|
2308
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
2309
|
+
});
|
2310
|
+
}
|
2311
|
+
toLowerCase() {
|
2312
|
+
return new _ZodString({
|
2313
|
+
...this._def,
|
2314
|
+
checks: [...this._def.checks, { kind: "toLowerCase" }]
|
2315
|
+
});
|
2316
|
+
}
|
2317
|
+
toUpperCase() {
|
2318
|
+
return new _ZodString({
|
2319
|
+
...this._def,
|
2320
|
+
checks: [...this._def.checks, { kind: "toUpperCase" }]
|
2321
|
+
});
|
2322
|
+
}
|
2053
2323
|
get isDatetime() {
|
2054
2324
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
2055
2325
|
}
|
2326
|
+
get isDate() {
|
2327
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
2328
|
+
}
|
2329
|
+
get isTime() {
|
2330
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
2331
|
+
}
|
2332
|
+
get isDuration() {
|
2333
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
2334
|
+
}
|
2056
2335
|
get isEmail() {
|
2057
2336
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
2058
2337
|
}
|
2059
2338
|
get isURL() {
|
2060
2339
|
return !!this._def.checks.find((ch) => ch.kind === "url");
|
2061
2340
|
}
|
2341
|
+
get isEmoji() {
|
2342
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
2343
|
+
}
|
2062
2344
|
get isUUID() {
|
2063
2345
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
2064
2346
|
}
|
2347
|
+
get isNANOID() {
|
2348
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
2349
|
+
}
|
2065
2350
|
get isCUID() {
|
2066
2351
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
2067
2352
|
}
|
2353
|
+
get isCUID2() {
|
2354
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
2355
|
+
}
|
2356
|
+
get isULID() {
|
2357
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
2358
|
+
}
|
2359
|
+
get isIP() {
|
2360
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
2361
|
+
}
|
2362
|
+
get isBase64() {
|
2363
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
2364
|
+
}
|
2068
2365
|
get minLength() {
|
2069
2366
|
let min = null;
|
2070
2367
|
for (const ch of this._def.checks) {
|
@@ -2274,6 +2571,19 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
2274
2571
|
message: errorUtil.toString(message)
|
2275
2572
|
});
|
2276
2573
|
}
|
2574
|
+
safe(message) {
|
2575
|
+
return this._addCheck({
|
2576
|
+
kind: "min",
|
2577
|
+
inclusive: true,
|
2578
|
+
value: Number.MIN_SAFE_INTEGER,
|
2579
|
+
message: errorUtil.toString(message)
|
2580
|
+
})._addCheck({
|
2581
|
+
kind: "max",
|
2582
|
+
inclusive: true,
|
2583
|
+
value: Number.MAX_SAFE_INTEGER,
|
2584
|
+
message: errorUtil.toString(message)
|
2585
|
+
});
|
2586
|
+
}
|
2277
2587
|
get minValue() {
|
2278
2588
|
let min = null;
|
2279
2589
|
for (const ch of this._def.checks) {
|
@@ -2295,7 +2605,22 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
2295
2605
|
return max;
|
2296
2606
|
}
|
2297
2607
|
get isInt() {
|
2298
|
-
return !!this._def.checks.find((ch) => ch.kind === "int");
|
2608
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
2609
|
+
}
|
2610
|
+
get isFinite() {
|
2611
|
+
let max = null, min = null;
|
2612
|
+
for (const ch of this._def.checks) {
|
2613
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
2614
|
+
return true;
|
2615
|
+
} else if (ch.kind === "min") {
|
2616
|
+
if (min === null || ch.value > min)
|
2617
|
+
min = ch.value;
|
2618
|
+
} else if (ch.kind === "max") {
|
2619
|
+
if (max === null || ch.value < max)
|
2620
|
+
max = ch.value;
|
2621
|
+
}
|
2622
|
+
}
|
2623
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
2299
2624
|
}
|
2300
2625
|
};
|
2301
2626
|
ZodNumber.create = (params) => {
|
@@ -2306,27 +2631,167 @@ ZodNumber.create = (params) => {
|
|
2306
2631
|
...processCreateParams(params)
|
2307
2632
|
});
|
2308
2633
|
};
|
2309
|
-
var ZodBigInt = class extends ZodType {
|
2634
|
+
var ZodBigInt = class _ZodBigInt extends ZodType {
|
2635
|
+
constructor() {
|
2636
|
+
super(...arguments);
|
2637
|
+
this.min = this.gte;
|
2638
|
+
this.max = this.lte;
|
2639
|
+
}
|
2310
2640
|
_parse(input) {
|
2311
2641
|
if (this._def.coerce) {
|
2312
2642
|
input.data = BigInt(input.data);
|
2313
2643
|
}
|
2314
2644
|
const parsedType = this._getType(input);
|
2315
2645
|
if (parsedType !== ZodParsedType.bigint) {
|
2316
|
-
const
|
2317
|
-
addIssueToContext(
|
2646
|
+
const ctx2 = this._getOrReturnCtx(input);
|
2647
|
+
addIssueToContext(ctx2, {
|
2318
2648
|
code: ZodIssueCode.invalid_type,
|
2319
2649
|
expected: ZodParsedType.bigint,
|
2320
|
-
received:
|
2650
|
+
received: ctx2.parsedType
|
2321
2651
|
});
|
2322
2652
|
return INVALID;
|
2323
2653
|
}
|
2324
|
-
|
2654
|
+
let ctx = void 0;
|
2655
|
+
const status = new ParseStatus();
|
2656
|
+
for (const check of this._def.checks) {
|
2657
|
+
if (check.kind === "min") {
|
2658
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
2659
|
+
if (tooSmall) {
|
2660
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2661
|
+
addIssueToContext(ctx, {
|
2662
|
+
code: ZodIssueCode.too_small,
|
2663
|
+
type: "bigint",
|
2664
|
+
minimum: check.value,
|
2665
|
+
inclusive: check.inclusive,
|
2666
|
+
message: check.message
|
2667
|
+
});
|
2668
|
+
status.dirty();
|
2669
|
+
}
|
2670
|
+
} else if (check.kind === "max") {
|
2671
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
2672
|
+
if (tooBig) {
|
2673
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2674
|
+
addIssueToContext(ctx, {
|
2675
|
+
code: ZodIssueCode.too_big,
|
2676
|
+
type: "bigint",
|
2677
|
+
maximum: check.value,
|
2678
|
+
inclusive: check.inclusive,
|
2679
|
+
message: check.message
|
2680
|
+
});
|
2681
|
+
status.dirty();
|
2682
|
+
}
|
2683
|
+
} else if (check.kind === "multipleOf") {
|
2684
|
+
if (input.data % check.value !== BigInt(0)) {
|
2685
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
2686
|
+
addIssueToContext(ctx, {
|
2687
|
+
code: ZodIssueCode.not_multiple_of,
|
2688
|
+
multipleOf: check.value,
|
2689
|
+
message: check.message
|
2690
|
+
});
|
2691
|
+
status.dirty();
|
2692
|
+
}
|
2693
|
+
} else {
|
2694
|
+
util.assertNever(check);
|
2695
|
+
}
|
2696
|
+
}
|
2697
|
+
return { status: status.value, value: input.data };
|
2698
|
+
}
|
2699
|
+
gte(value, message) {
|
2700
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
2701
|
+
}
|
2702
|
+
gt(value, message) {
|
2703
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
2704
|
+
}
|
2705
|
+
lte(value, message) {
|
2706
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
2707
|
+
}
|
2708
|
+
lt(value, message) {
|
2709
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
2710
|
+
}
|
2711
|
+
setLimit(kind, value, inclusive, message) {
|
2712
|
+
return new _ZodBigInt({
|
2713
|
+
...this._def,
|
2714
|
+
checks: [
|
2715
|
+
...this._def.checks,
|
2716
|
+
{
|
2717
|
+
kind,
|
2718
|
+
value,
|
2719
|
+
inclusive,
|
2720
|
+
message: errorUtil.toString(message)
|
2721
|
+
}
|
2722
|
+
]
|
2723
|
+
});
|
2724
|
+
}
|
2725
|
+
_addCheck(check) {
|
2726
|
+
return new _ZodBigInt({
|
2727
|
+
...this._def,
|
2728
|
+
checks: [...this._def.checks, check]
|
2729
|
+
});
|
2730
|
+
}
|
2731
|
+
positive(message) {
|
2732
|
+
return this._addCheck({
|
2733
|
+
kind: "min",
|
2734
|
+
value: BigInt(0),
|
2735
|
+
inclusive: false,
|
2736
|
+
message: errorUtil.toString(message)
|
2737
|
+
});
|
2738
|
+
}
|
2739
|
+
negative(message) {
|
2740
|
+
return this._addCheck({
|
2741
|
+
kind: "max",
|
2742
|
+
value: BigInt(0),
|
2743
|
+
inclusive: false,
|
2744
|
+
message: errorUtil.toString(message)
|
2745
|
+
});
|
2746
|
+
}
|
2747
|
+
nonpositive(message) {
|
2748
|
+
return this._addCheck({
|
2749
|
+
kind: "max",
|
2750
|
+
value: BigInt(0),
|
2751
|
+
inclusive: true,
|
2752
|
+
message: errorUtil.toString(message)
|
2753
|
+
});
|
2754
|
+
}
|
2755
|
+
nonnegative(message) {
|
2756
|
+
return this._addCheck({
|
2757
|
+
kind: "min",
|
2758
|
+
value: BigInt(0),
|
2759
|
+
inclusive: true,
|
2760
|
+
message: errorUtil.toString(message)
|
2761
|
+
});
|
2762
|
+
}
|
2763
|
+
multipleOf(value, message) {
|
2764
|
+
return this._addCheck({
|
2765
|
+
kind: "multipleOf",
|
2766
|
+
value,
|
2767
|
+
message: errorUtil.toString(message)
|
2768
|
+
});
|
2769
|
+
}
|
2770
|
+
get minValue() {
|
2771
|
+
let min = null;
|
2772
|
+
for (const ch of this._def.checks) {
|
2773
|
+
if (ch.kind === "min") {
|
2774
|
+
if (min === null || ch.value > min)
|
2775
|
+
min = ch.value;
|
2776
|
+
}
|
2777
|
+
}
|
2778
|
+
return min;
|
2779
|
+
}
|
2780
|
+
get maxValue() {
|
2781
|
+
let max = null;
|
2782
|
+
for (const ch of this._def.checks) {
|
2783
|
+
if (ch.kind === "max") {
|
2784
|
+
if (max === null || ch.value < max)
|
2785
|
+
max = ch.value;
|
2786
|
+
}
|
2787
|
+
}
|
2788
|
+
return max;
|
2325
2789
|
}
|
2326
2790
|
};
|
2327
2791
|
ZodBigInt.create = (params) => {
|
2328
2792
|
var _a;
|
2329
2793
|
return new ZodBigInt({
|
2794
|
+
checks: [],
|
2330
2795
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
2331
2796
|
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
2332
2797
|
...processCreateParams(params)
|
@@ -2652,13 +3117,13 @@ var ZodArray = class _ZodArray extends ZodType {
|
|
2652
3117
|
}
|
2653
3118
|
}
|
2654
3119
|
if (ctx.common.async) {
|
2655
|
-
return Promise.all(ctx.data.map((item, i) => {
|
3120
|
+
return Promise.all([...ctx.data].map((item, i) => {
|
2656
3121
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
2657
3122
|
})).then((result2) => {
|
2658
3123
|
return ParseStatus.mergeArray(status, result2);
|
2659
3124
|
});
|
2660
3125
|
}
|
2661
|
-
const result = ctx.data.map((item, i) => {
|
3126
|
+
const result = [...ctx.data].map((item, i) => {
|
2662
3127
|
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
2663
3128
|
});
|
2664
3129
|
return ParseStatus.mergeArray(status, result);
|
@@ -2698,25 +3163,6 @@ ZodArray.create = (schema3, params) => {
|
|
2698
3163
|
...processCreateParams(params)
|
2699
3164
|
});
|
2700
3165
|
};
|
2701
|
-
var objectUtil;
|
2702
|
-
(function(objectUtil2) {
|
2703
|
-
objectUtil2.mergeShapes = (first, second) => {
|
2704
|
-
return {
|
2705
|
-
...first,
|
2706
|
-
...second
|
2707
|
-
// second overwrites first
|
2708
|
-
};
|
2709
|
-
};
|
2710
|
-
})(objectUtil || (objectUtil = {}));
|
2711
|
-
var AugmentFactory = (def) => (augmentation) => {
|
2712
|
-
return new ZodObject({
|
2713
|
-
...def,
|
2714
|
-
shape: () => ({
|
2715
|
-
...def.shape(),
|
2716
|
-
...augmentation
|
2717
|
-
})
|
2718
|
-
});
|
2719
|
-
};
|
2720
3166
|
function deepPartialify(schema3) {
|
2721
3167
|
if (schema3 instanceof ZodObject) {
|
2722
3168
|
const newShape = {};
|
@@ -2729,7 +3175,10 @@ function deepPartialify(schema3) {
|
|
2729
3175
|
shape: () => newShape
|
2730
3176
|
});
|
2731
3177
|
} else if (schema3 instanceof ZodArray) {
|
2732
|
-
return ZodArray
|
3178
|
+
return new ZodArray({
|
3179
|
+
...schema3._def,
|
3180
|
+
type: deepPartialify(schema3.element)
|
3181
|
+
});
|
2733
3182
|
} else if (schema3 instanceof ZodOptional) {
|
2734
3183
|
return ZodOptional.create(deepPartialify(schema3.unwrap()));
|
2735
3184
|
} else if (schema3 instanceof ZodNullable) {
|
@@ -2745,8 +3194,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2745
3194
|
super(...arguments);
|
2746
3195
|
this._cached = null;
|
2747
3196
|
this.nonstrict = this.passthrough;
|
2748
|
-
this.augment =
|
2749
|
-
this.extend = AugmentFactory(this._def);
|
3197
|
+
this.augment = this.extend;
|
2750
3198
|
}
|
2751
3199
|
_getCached() {
|
2752
3200
|
if (this._cached !== null)
|
@@ -2827,9 +3275,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2827
3275
|
const syncPairs = [];
|
2828
3276
|
for (const pair of pairs) {
|
2829
3277
|
const key = await pair.key;
|
3278
|
+
const value = await pair.value;
|
2830
3279
|
syncPairs.push({
|
2831
3280
|
key,
|
2832
|
-
value
|
3281
|
+
value,
|
2833
3282
|
alwaysSet: pair.alwaysSet
|
2834
3283
|
});
|
2835
3284
|
}
|
@@ -2876,8 +3325,31 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2876
3325
|
unknownKeys: "passthrough"
|
2877
3326
|
});
|
2878
3327
|
}
|
2879
|
-
|
2880
|
-
|
3328
|
+
// const AugmentFactory =
|
3329
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
3330
|
+
// <Augmentation extends ZodRawShape>(
|
3331
|
+
// augmentation: Augmentation
|
3332
|
+
// ): ZodObject<
|
3333
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
3334
|
+
// Def["unknownKeys"],
|
3335
|
+
// Def["catchall"]
|
3336
|
+
// > => {
|
3337
|
+
// return new ZodObject({
|
3338
|
+
// ...def,
|
3339
|
+
// shape: () => ({
|
3340
|
+
// ...def.shape(),
|
3341
|
+
// ...augmentation,
|
3342
|
+
// }),
|
3343
|
+
// }) as any;
|
3344
|
+
// };
|
3345
|
+
extend(augmentation) {
|
3346
|
+
return new _ZodObject({
|
3347
|
+
...this._def,
|
3348
|
+
shape: () => ({
|
3349
|
+
...this._def.shape(),
|
3350
|
+
...augmentation
|
3351
|
+
})
|
3352
|
+
});
|
2881
3353
|
}
|
2882
3354
|
/**
|
2883
3355
|
* Prior to zod@1.0.12 there was a bug in the
|
@@ -2888,11 +3360,73 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2888
3360
|
const merged = new _ZodObject({
|
2889
3361
|
unknownKeys: merging._def.unknownKeys,
|
2890
3362
|
catchall: merging._def.catchall,
|
2891
|
-
shape: () =>
|
3363
|
+
shape: () => ({
|
3364
|
+
...this._def.shape(),
|
3365
|
+
...merging._def.shape()
|
3366
|
+
}),
|
2892
3367
|
typeName: ZodFirstPartyTypeKind.ZodObject
|
2893
3368
|
});
|
2894
3369
|
return merged;
|
2895
3370
|
}
|
3371
|
+
// merge<
|
3372
|
+
// Incoming extends AnyZodObject,
|
3373
|
+
// Augmentation extends Incoming["shape"],
|
3374
|
+
// NewOutput extends {
|
3375
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
3376
|
+
// ? Augmentation[k]["_output"]
|
3377
|
+
// : k extends keyof Output
|
3378
|
+
// ? Output[k]
|
3379
|
+
// : never;
|
3380
|
+
// },
|
3381
|
+
// NewInput extends {
|
3382
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
3383
|
+
// ? Augmentation[k]["_input"]
|
3384
|
+
// : k extends keyof Input
|
3385
|
+
// ? Input[k]
|
3386
|
+
// : never;
|
3387
|
+
// }
|
3388
|
+
// >(
|
3389
|
+
// merging: Incoming
|
3390
|
+
// ): ZodObject<
|
3391
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
3392
|
+
// Incoming["_def"]["unknownKeys"],
|
3393
|
+
// Incoming["_def"]["catchall"],
|
3394
|
+
// NewOutput,
|
3395
|
+
// NewInput
|
3396
|
+
// > {
|
3397
|
+
// const merged: any = new ZodObject({
|
3398
|
+
// unknownKeys: merging._def.unknownKeys,
|
3399
|
+
// catchall: merging._def.catchall,
|
3400
|
+
// shape: () =>
|
3401
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
3402
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
3403
|
+
// }) as any;
|
3404
|
+
// return merged;
|
3405
|
+
// }
|
3406
|
+
setKey(key, schema3) {
|
3407
|
+
return this.augment({ [key]: schema3 });
|
3408
|
+
}
|
3409
|
+
// merge<Incoming extends AnyZodObject>(
|
3410
|
+
// merging: Incoming
|
3411
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
3412
|
+
// ZodObject<
|
3413
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
3414
|
+
// Incoming["_def"]["unknownKeys"],
|
3415
|
+
// Incoming["_def"]["catchall"]
|
3416
|
+
// > {
|
3417
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
3418
|
+
// // this._def.shape(),
|
3419
|
+
// // merging._def.shape()
|
3420
|
+
// // );
|
3421
|
+
// const merged: any = new ZodObject({
|
3422
|
+
// unknownKeys: merging._def.unknownKeys,
|
3423
|
+
// catchall: merging._def.catchall,
|
3424
|
+
// shape: () =>
|
3425
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
3426
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
3427
|
+
// }) as any;
|
3428
|
+
// return merged;
|
3429
|
+
// }
|
2896
3430
|
catchall(index4) {
|
2897
3431
|
return new _ZodObject({
|
2898
3432
|
...this._def,
|
@@ -2901,9 +3435,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2901
3435
|
}
|
2902
3436
|
pick(mask) {
|
2903
3437
|
const shape = {};
|
2904
|
-
util.objectKeys(mask).
|
2905
|
-
if (this.shape[key])
|
3438
|
+
util.objectKeys(mask).forEach((key) => {
|
3439
|
+
if (mask[key] && this.shape[key]) {
|
2906
3440
|
shape[key] = this.shape[key];
|
3441
|
+
}
|
2907
3442
|
});
|
2908
3443
|
return new _ZodObject({
|
2909
3444
|
...this._def,
|
@@ -2912,8 +3447,8 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2912
3447
|
}
|
2913
3448
|
omit(mask) {
|
2914
3449
|
const shape = {};
|
2915
|
-
util.objectKeys(this.shape).
|
2916
|
-
if (
|
3450
|
+
util.objectKeys(this.shape).forEach((key) => {
|
3451
|
+
if (!mask[key]) {
|
2917
3452
|
shape[key] = this.shape[key];
|
2918
3453
|
}
|
2919
3454
|
});
|
@@ -2922,29 +3457,22 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2922
3457
|
shape: () => shape
|
2923
3458
|
});
|
2924
3459
|
}
|
3460
|
+
/**
|
3461
|
+
* @deprecated
|
3462
|
+
*/
|
2925
3463
|
deepPartial() {
|
2926
3464
|
return deepPartialify(this);
|
2927
3465
|
}
|
2928
3466
|
partial(mask) {
|
2929
3467
|
const newShape = {};
|
2930
|
-
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
newShape[key] = this.shape[key].optional();
|
2936
|
-
}
|
2937
|
-
});
|
2938
|
-
return new _ZodObject({
|
2939
|
-
...this._def,
|
2940
|
-
shape: () => newShape
|
2941
|
-
});
|
2942
|
-
} else {
|
2943
|
-
for (const key in this.shape) {
|
2944
|
-
const fieldSchema = this.shape[key];
|
3468
|
+
util.objectKeys(this.shape).forEach((key) => {
|
3469
|
+
const fieldSchema = this.shape[key];
|
3470
|
+
if (mask && !mask[key]) {
|
3471
|
+
newShape[key] = fieldSchema;
|
3472
|
+
} else {
|
2945
3473
|
newShape[key] = fieldSchema.optional();
|
2946
3474
|
}
|
2947
|
-
}
|
3475
|
+
});
|
2948
3476
|
return new _ZodObject({
|
2949
3477
|
...this._def,
|
2950
3478
|
shape: () => newShape
|
@@ -2952,21 +3480,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2952
3480
|
}
|
2953
3481
|
required(mask) {
|
2954
3482
|
const newShape = {};
|
2955
|
-
|
2956
|
-
|
2957
|
-
|
2958
|
-
|
2959
|
-
} else {
|
2960
|
-
const fieldSchema = this.shape[key];
|
2961
|
-
let newField = fieldSchema;
|
2962
|
-
while (newField instanceof ZodOptional) {
|
2963
|
-
newField = newField._def.innerType;
|
2964
|
-
}
|
2965
|
-
newShape[key] = newField;
|
2966
|
-
}
|
2967
|
-
});
|
2968
|
-
} else {
|
2969
|
-
for (const key in this.shape) {
|
3483
|
+
util.objectKeys(this.shape).forEach((key) => {
|
3484
|
+
if (mask && !mask[key]) {
|
3485
|
+
newShape[key] = this.shape[key];
|
3486
|
+
} else {
|
2970
3487
|
const fieldSchema = this.shape[key];
|
2971
3488
|
let newField = fieldSchema;
|
2972
3489
|
while (newField instanceof ZodOptional) {
|
@@ -2974,7 +3491,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
2974
3491
|
}
|
2975
3492
|
newShape[key] = newField;
|
2976
3493
|
}
|
2977
|
-
}
|
3494
|
+
});
|
2978
3495
|
return new _ZodObject({
|
2979
3496
|
...this._def,
|
2980
3497
|
shape: () => newShape
|
@@ -3112,15 +3629,25 @@ var getDiscriminator = (type) => {
|
|
3112
3629
|
} else if (type instanceof ZodEnum) {
|
3113
3630
|
return type.options;
|
3114
3631
|
} else if (type instanceof ZodNativeEnum) {
|
3115
|
-
return
|
3632
|
+
return util.objectValues(type.enum);
|
3116
3633
|
} else if (type instanceof ZodDefault) {
|
3117
3634
|
return getDiscriminator(type._def.innerType);
|
3118
3635
|
} else if (type instanceof ZodUndefined) {
|
3119
3636
|
return [void 0];
|
3120
3637
|
} else if (type instanceof ZodNull) {
|
3121
3638
|
return [null];
|
3639
|
+
} else if (type instanceof ZodOptional) {
|
3640
|
+
return [void 0, ...getDiscriminator(type.unwrap())];
|
3641
|
+
} else if (type instanceof ZodNullable) {
|
3642
|
+
return [null, ...getDiscriminator(type.unwrap())];
|
3643
|
+
} else if (type instanceof ZodBranded) {
|
3644
|
+
return getDiscriminator(type.unwrap());
|
3645
|
+
} else if (type instanceof ZodReadonly) {
|
3646
|
+
return getDiscriminator(type.unwrap());
|
3647
|
+
} else if (type instanceof ZodCatch) {
|
3648
|
+
return getDiscriminator(type._def.innerType);
|
3122
3649
|
} else {
|
3123
|
-
return
|
3650
|
+
return [];
|
3124
3651
|
}
|
3125
3652
|
};
|
3126
3653
|
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
@@ -3180,7 +3707,7 @@ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3180
3707
|
const optionsMap = /* @__PURE__ */ new Map();
|
3181
3708
|
for (const type of options) {
|
3182
3709
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
3183
|
-
if (!discriminatorValues) {
|
3710
|
+
if (!discriminatorValues.length) {
|
3184
3711
|
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
3185
3712
|
}
|
3186
3713
|
for (const value of discriminatorValues) {
|
@@ -3322,7 +3849,7 @@ var ZodTuple = class _ZodTuple extends ZodType {
|
|
3322
3849
|
});
|
3323
3850
|
status.dirty();
|
3324
3851
|
}
|
3325
|
-
const items = ctx.data.map((item, itemIndex) => {
|
3852
|
+
const items = [...ctx.data].map((item, itemIndex) => {
|
3326
3853
|
const schema3 = this._def.items[itemIndex] || this._def.rest;
|
3327
3854
|
if (!schema3)
|
3328
3855
|
return null;
|
@@ -3380,7 +3907,8 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
3380
3907
|
for (const key in ctx.data) {
|
3381
3908
|
pairs.push({
|
3382
3909
|
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
3383
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
3910
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
3911
|
+
alwaysSet: key in ctx.data
|
3384
3912
|
});
|
3385
3913
|
}
|
3386
3914
|
if (ctx.common.async) {
|
@@ -3410,6 +3938,12 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
3410
3938
|
}
|
3411
3939
|
};
|
3412
3940
|
var ZodMap = class extends ZodType {
|
3941
|
+
get keySchema() {
|
3942
|
+
return this._def.keyType;
|
3943
|
+
}
|
3944
|
+
get valueSchema() {
|
3945
|
+
return this._def.valueType;
|
3946
|
+
}
|
3413
3947
|
_parse(input) {
|
3414
3948
|
const { status, ctx } = this._processInputParams(input);
|
3415
3949
|
if (ctx.parsedType !== ZodParsedType.map) {
|
@@ -3604,27 +4138,29 @@ var ZodFunction = class _ZodFunction extends ZodType {
|
|
3604
4138
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
3605
4139
|
const fn = ctx.data;
|
3606
4140
|
if (this._def.returns instanceof ZodPromise) {
|
3607
|
-
|
4141
|
+
const me = this;
|
4142
|
+
return OK(async function(...args) {
|
3608
4143
|
const error = new ZodError([]);
|
3609
|
-
const parsedArgs = await
|
4144
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
3610
4145
|
error.addIssue(makeArgsIssue(args, e));
|
3611
4146
|
throw error;
|
3612
4147
|
});
|
3613
|
-
const result = await fn
|
3614
|
-
const parsedReturns = await
|
4148
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
4149
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
3615
4150
|
error.addIssue(makeReturnsIssue(result, e));
|
3616
4151
|
throw error;
|
3617
4152
|
});
|
3618
4153
|
return parsedReturns;
|
3619
4154
|
});
|
3620
4155
|
} else {
|
3621
|
-
|
3622
|
-
|
4156
|
+
const me = this;
|
4157
|
+
return OK(function(...args) {
|
4158
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
3623
4159
|
if (!parsedArgs.success) {
|
3624
4160
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
3625
4161
|
}
|
3626
|
-
const result = fn
|
3627
|
-
const parsedReturns =
|
4162
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
4163
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
3628
4164
|
if (!parsedReturns.success) {
|
3629
4165
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
3630
4166
|
}
|
@@ -3689,6 +4225,7 @@ var ZodLiteral = class extends ZodType {
|
|
3689
4225
|
if (input.data !== this._def.value) {
|
3690
4226
|
const ctx = this._getOrReturnCtx(input);
|
3691
4227
|
addIssueToContext(ctx, {
|
4228
|
+
received: ctx.data,
|
3692
4229
|
code: ZodIssueCode.invalid_literal,
|
3693
4230
|
expected: this._def.value
|
3694
4231
|
});
|
@@ -3714,7 +4251,11 @@ function createZodEnum(values, params) {
|
|
3714
4251
|
...processCreateParams(params)
|
3715
4252
|
});
|
3716
4253
|
}
|
3717
|
-
var ZodEnum = class extends ZodType {
|
4254
|
+
var ZodEnum = class _ZodEnum extends ZodType {
|
4255
|
+
constructor() {
|
4256
|
+
super(...arguments);
|
4257
|
+
_ZodEnum_cache.set(this, void 0);
|
4258
|
+
}
|
3718
4259
|
_parse(input) {
|
3719
4260
|
if (typeof input.data !== "string") {
|
3720
4261
|
const ctx = this._getOrReturnCtx(input);
|
@@ -3726,7 +4267,10 @@ var ZodEnum = class extends ZodType {
|
|
3726
4267
|
});
|
3727
4268
|
return INVALID;
|
3728
4269
|
}
|
3729
|
-
if (this
|
4270
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
|
4271
|
+
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
4272
|
+
}
|
4273
|
+
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
3730
4274
|
const ctx = this._getOrReturnCtx(input);
|
3731
4275
|
const expectedValues = this._def.values;
|
3732
4276
|
addIssueToContext(ctx, {
|
@@ -3762,9 +4306,26 @@ var ZodEnum = class extends ZodType {
|
|
3762
4306
|
}
|
3763
4307
|
return enumValues;
|
3764
4308
|
}
|
4309
|
+
extract(values, newDef = this._def) {
|
4310
|
+
return _ZodEnum.create(values, {
|
4311
|
+
...this._def,
|
4312
|
+
...newDef
|
4313
|
+
});
|
4314
|
+
}
|
4315
|
+
exclude(values, newDef = this._def) {
|
4316
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
4317
|
+
...this._def,
|
4318
|
+
...newDef
|
4319
|
+
});
|
4320
|
+
}
|
3765
4321
|
};
|
4322
|
+
_ZodEnum_cache = /* @__PURE__ */ new WeakMap();
|
3766
4323
|
ZodEnum.create = createZodEnum;
|
3767
4324
|
var ZodNativeEnum = class extends ZodType {
|
4325
|
+
constructor() {
|
4326
|
+
super(...arguments);
|
4327
|
+
_ZodNativeEnum_cache.set(this, void 0);
|
4328
|
+
}
|
3768
4329
|
_parse(input) {
|
3769
4330
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
3770
4331
|
const ctx = this._getOrReturnCtx(input);
|
@@ -3777,7 +4338,10 @@ var ZodNativeEnum = class extends ZodType {
|
|
3777
4338
|
});
|
3778
4339
|
return INVALID;
|
3779
4340
|
}
|
3780
|
-
if (
|
4341
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
|
4342
|
+
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
|
4343
|
+
}
|
4344
|
+
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
3781
4345
|
const expectedValues = util.objectValues(nativeEnumValues);
|
3782
4346
|
addIssueToContext(ctx, {
|
3783
4347
|
received: ctx.data,
|
@@ -3792,6 +4356,7 @@ var ZodNativeEnum = class extends ZodType {
|
|
3792
4356
|
return this._def.values;
|
3793
4357
|
}
|
3794
4358
|
};
|
4359
|
+
_ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
|
3795
4360
|
ZodNativeEnum.create = (values, params) => {
|
3796
4361
|
return new ZodNativeEnum({
|
3797
4362
|
values,
|
@@ -3800,6 +4365,9 @@ ZodNativeEnum.create = (values, params) => {
|
|
3800
4365
|
});
|
3801
4366
|
};
|
3802
4367
|
var ZodPromise = class extends ZodType {
|
4368
|
+
unwrap() {
|
4369
|
+
return this._def.type;
|
4370
|
+
}
|
3803
4371
|
_parse(input) {
|
3804
4372
|
const { ctx } = this._processInputParams(input);
|
3805
4373
|
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
@@ -3836,24 +4404,6 @@ var ZodEffects = class extends ZodType {
|
|
3836
4404
|
_parse(input) {
|
3837
4405
|
const { status, ctx } = this._processInputParams(input);
|
3838
4406
|
const effect = this._def.effect || null;
|
3839
|
-
if (effect.type === "preprocess") {
|
3840
|
-
const processed = effect.transform(ctx.data);
|
3841
|
-
if (ctx.common.async) {
|
3842
|
-
return Promise.resolve(processed).then((processed2) => {
|
3843
|
-
return this._def.schema._parseAsync({
|
3844
|
-
data: processed2,
|
3845
|
-
path: ctx.path,
|
3846
|
-
parent: ctx
|
3847
|
-
});
|
3848
|
-
});
|
3849
|
-
} else {
|
3850
|
-
return this._def.schema._parseSync({
|
3851
|
-
data: processed,
|
3852
|
-
path: ctx.path,
|
3853
|
-
parent: ctx
|
3854
|
-
});
|
3855
|
-
}
|
3856
|
-
}
|
3857
4407
|
const checkCtx = {
|
3858
4408
|
addIssue: (arg) => {
|
3859
4409
|
addIssueToContext(ctx, arg);
|
@@ -3868,6 +4418,42 @@ var ZodEffects = class extends ZodType {
|
|
3868
4418
|
}
|
3869
4419
|
};
|
3870
4420
|
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
4421
|
+
if (effect.type === "preprocess") {
|
4422
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
4423
|
+
if (ctx.common.async) {
|
4424
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
4425
|
+
if (status.value === "aborted")
|
4426
|
+
return INVALID;
|
4427
|
+
const result = await this._def.schema._parseAsync({
|
4428
|
+
data: processed2,
|
4429
|
+
path: ctx.path,
|
4430
|
+
parent: ctx
|
4431
|
+
});
|
4432
|
+
if (result.status === "aborted")
|
4433
|
+
return INVALID;
|
4434
|
+
if (result.status === "dirty")
|
4435
|
+
return DIRTY(result.value);
|
4436
|
+
if (status.value === "dirty")
|
4437
|
+
return DIRTY(result.value);
|
4438
|
+
return result;
|
4439
|
+
});
|
4440
|
+
} else {
|
4441
|
+
if (status.value === "aborted")
|
4442
|
+
return INVALID;
|
4443
|
+
const result = this._def.schema._parseSync({
|
4444
|
+
data: processed,
|
4445
|
+
path: ctx.path,
|
4446
|
+
parent: ctx
|
4447
|
+
});
|
4448
|
+
if (result.status === "aborted")
|
4449
|
+
return INVALID;
|
4450
|
+
if (result.status === "dirty")
|
4451
|
+
return DIRTY(result.value);
|
4452
|
+
if (status.value === "dirty")
|
4453
|
+
return DIRTY(result.value);
|
4454
|
+
return result;
|
4455
|
+
}
|
4456
|
+
}
|
3871
4457
|
if (effect.type === "refinement") {
|
3872
4458
|
const executeRefinement = (acc) => {
|
3873
4459
|
const result = effect.refinement(acc, checkCtx);
|
@@ -4010,26 +4596,45 @@ ZodDefault.create = (type, params) => {
|
|
4010
4596
|
var ZodCatch = class extends ZodType {
|
4011
4597
|
_parse(input) {
|
4012
4598
|
const { ctx } = this._processInputParams(input);
|
4599
|
+
const newCtx = {
|
4600
|
+
...ctx,
|
4601
|
+
common: {
|
4602
|
+
...ctx.common,
|
4603
|
+
issues: []
|
4604
|
+
}
|
4605
|
+
};
|
4013
4606
|
const result = this._def.innerType._parse({
|
4014
|
-
data:
|
4015
|
-
path:
|
4016
|
-
parent:
|
4607
|
+
data: newCtx.data,
|
4608
|
+
path: newCtx.path,
|
4609
|
+
parent: {
|
4610
|
+
...newCtx
|
4611
|
+
}
|
4017
4612
|
});
|
4018
4613
|
if (isAsync(result)) {
|
4019
4614
|
return result.then((result2) => {
|
4020
4615
|
return {
|
4021
4616
|
status: "valid",
|
4022
|
-
value: result2.status === "valid" ? result2.value : this._def.
|
4617
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
4618
|
+
get error() {
|
4619
|
+
return new ZodError(newCtx.common.issues);
|
4620
|
+
},
|
4621
|
+
input: newCtx.data
|
4622
|
+
})
|
4023
4623
|
};
|
4024
4624
|
});
|
4025
4625
|
} else {
|
4026
4626
|
return {
|
4027
4627
|
status: "valid",
|
4028
|
-
value: result.status === "valid" ? result.value : this._def.
|
4628
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
4629
|
+
get error() {
|
4630
|
+
return new ZodError(newCtx.common.issues);
|
4631
|
+
},
|
4632
|
+
input: newCtx.data
|
4633
|
+
})
|
4029
4634
|
};
|
4030
4635
|
}
|
4031
4636
|
}
|
4032
|
-
|
4637
|
+
removeCatch() {
|
4033
4638
|
return this._def.innerType;
|
4034
4639
|
}
|
4035
4640
|
};
|
@@ -4037,7 +4642,7 @@ ZodCatch.create = (type, params) => {
|
|
4037
4642
|
return new ZodCatch({
|
4038
4643
|
innerType: type,
|
4039
4644
|
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
4040
|
-
|
4645
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
4041
4646
|
...processCreateParams(params)
|
4042
4647
|
});
|
4043
4648
|
};
|
@@ -4132,6 +4737,28 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
4132
4737
|
});
|
4133
4738
|
}
|
4134
4739
|
};
|
4740
|
+
var ZodReadonly = class extends ZodType {
|
4741
|
+
_parse(input) {
|
4742
|
+
const result = this._def.innerType._parse(input);
|
4743
|
+
const freeze = (data) => {
|
4744
|
+
if (isValid(data)) {
|
4745
|
+
data.value = Object.freeze(data.value);
|
4746
|
+
}
|
4747
|
+
return data;
|
4748
|
+
};
|
4749
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
4750
|
+
}
|
4751
|
+
unwrap() {
|
4752
|
+
return this._def.innerType;
|
4753
|
+
}
|
4754
|
+
};
|
4755
|
+
ZodReadonly.create = (type, params) => {
|
4756
|
+
return new ZodReadonly({
|
4757
|
+
innerType: type,
|
4758
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
4759
|
+
...processCreateParams(params)
|
4760
|
+
});
|
4761
|
+
};
|
4135
4762
|
var late = {
|
4136
4763
|
object: ZodObject.lazycreate
|
4137
4764
|
};
|
@@ -4172,6 +4799,7 @@ var ZodFirstPartyTypeKind;
|
|
4172
4799
|
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
4173
4800
|
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
4174
4801
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
4802
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
4175
4803
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
4176
4804
|
var stringType = ZodString.create;
|
4177
4805
|
var numberType = ZodNumber.create;
|
@@ -4785,7 +5413,6 @@ var validateWithReport = (snapshots, dialect3) => {
|
|
4785
5413
|
}
|
4786
5414
|
const result2 = validator.safeParse(raw);
|
4787
5415
|
if (!result2.success) {
|
4788
|
-
console.error(result2.error);
|
4789
5416
|
accum.malformed.push(it);
|
4790
5417
|
return accum;
|
4791
5418
|
}
|