drizzle-kit 0.20.17-a2979a1 → 0.20.17-b08243d
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 +25462 -26322
- package/cli/commands/migrate.d.ts +41 -41
- package/cli/commands/mysqlIntrospect.d.ts +8 -8
- package/cli/commands/pgIntrospect.d.ts +8 -8
- package/cli/commands/sqliteIntrospect.d.ts +12 -12
- package/cli/commands/utils.d.ts +2 -2
- package/cli/validations/cli.d.ts +29 -29
- package/cli/validations/common.d.ts +35 -35
- package/cli/validations/mysql.d.ts +4 -4
- package/cli/validations/outputs.d.ts +1 -2
- package/cli/validations/pg.d.ts +4 -4
- package/index.d.mts +2 -48
- package/index.d.ts +2 -48
- package/package.json +1 -1
- package/payload.js +476 -1080
- package/payload.mjs +283 -887
- package/schemaValidator.d.ts +222 -222
- package/serializer/mysqlSchema.d.ts +890 -890
- package/serializer/pgSchema.d.ts +745 -745
- package/serializer/sqliteSchema.d.ts +457 -457
- package/serializer/studio.d.ts +1 -1
- package/snapshotsDiffer.d.ts +315 -316
- package/utils-studio.js +841 -947
- package/utils-studio.mjs +814 -920
- package/utils.js +219 -844
- package/utils.mjs +194 -819
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.2.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.2.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) {
|
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.2.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.2.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.20.2/node_modules/zod/lib/index.mjs
|
1074
1074
|
var util;
|
1075
1075
|
(function(util2) {
|
1076
1076
|
util2.assertEqual = (val) => val;
|
@@ -1129,16 +1129,6 @@ 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 = {}));
|
1142
1132
|
var ZodParsedType = util.arrayToEnum([
|
1143
1133
|
"string",
|
1144
1134
|
"nan",
|
@@ -1220,7 +1210,7 @@ var ZodIssueCode = util.arrayToEnum([
|
|
1220
1210
|
"not_multiple_of",
|
1221
1211
|
"not_finite"
|
1222
1212
|
]);
|
1223
|
-
var ZodError = class
|
1213
|
+
var ZodError = class extends Error {
|
1224
1214
|
constructor(issues) {
|
1225
1215
|
super();
|
1226
1216
|
this.issues = [];
|
@@ -1278,11 +1268,6 @@ var ZodError = class _ZodError extends Error {
|
|
1278
1268
|
processError(this);
|
1279
1269
|
return fieldErrors;
|
1280
1270
|
}
|
1281
|
-
static assert(value) {
|
1282
|
-
if (!(value instanceof _ZodError)) {
|
1283
|
-
throw new Error(`Not a ZodError: ${value}`);
|
1284
|
-
}
|
1285
|
-
}
|
1286
1271
|
toString() {
|
1287
1272
|
return this.message;
|
1288
1273
|
}
|
@@ -1349,12 +1334,7 @@ var errorMap = (issue, _ctx) => {
|
|
1349
1334
|
break;
|
1350
1335
|
case ZodIssueCode.invalid_string:
|
1351
1336
|
if (typeof issue.validation === "object") {
|
1352
|
-
if ("
|
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) {
|
1337
|
+
if ("startsWith" in issue.validation) {
|
1358
1338
|
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
1359
1339
|
} else if ("endsWith" in issue.validation) {
|
1360
1340
|
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
@@ -1375,7 +1355,7 @@ var errorMap = (issue, _ctx) => {
|
|
1375
1355
|
else if (issue.type === "number")
|
1376
1356
|
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
1377
1357
|
else if (issue.type === "date")
|
1378
|
-
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(
|
1358
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(issue.minimum)}`;
|
1379
1359
|
else
|
1380
1360
|
message = "Invalid input";
|
1381
1361
|
break;
|
@@ -1386,10 +1366,8 @@ var errorMap = (issue, _ctx) => {
|
|
1386
1366
|
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
1387
1367
|
else if (issue.type === "number")
|
1388
1368
|
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}`;
|
1391
1369
|
else if (issue.type === "date")
|
1392
|
-
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(
|
1370
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(issue.maximum)}`;
|
1393
1371
|
else
|
1394
1372
|
message = "Invalid input";
|
1395
1373
|
break;
|
@@ -1422,13 +1400,6 @@ var makeIssue = (params) => {
|
|
1422
1400
|
...issueData,
|
1423
1401
|
path: fullPath
|
1424
1402
|
};
|
1425
|
-
if (issueData.message !== void 0) {
|
1426
|
-
return {
|
1427
|
-
...issueData,
|
1428
|
-
path: fullPath,
|
1429
|
-
message: issueData.message
|
1430
|
-
};
|
1431
|
-
}
|
1432
1403
|
let errorMessage = "";
|
1433
1404
|
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
1434
1405
|
for (const map of maps) {
|
@@ -1437,11 +1408,10 @@ var makeIssue = (params) => {
|
|
1437
1408
|
return {
|
1438
1409
|
...issueData,
|
1439
1410
|
path: fullPath,
|
1440
|
-
message: errorMessage
|
1411
|
+
message: issueData.message || errorMessage
|
1441
1412
|
};
|
1442
1413
|
};
|
1443
1414
|
function addIssueToContext(ctx, issueData) {
|
1444
|
-
const overrideMap = getErrorMap();
|
1445
1415
|
const issue = makeIssue({
|
1446
1416
|
issueData,
|
1447
1417
|
data: ctx.data,
|
@@ -1449,8 +1419,8 @@ function addIssueToContext(ctx, issueData) {
|
|
1449
1419
|
errorMaps: [
|
1450
1420
|
ctx.common.contextualErrorMap,
|
1451
1421
|
ctx.schemaErrorMap,
|
1452
|
-
|
1453
|
-
|
1422
|
+
getErrorMap(),
|
1423
|
+
errorMap
|
1454
1424
|
// then global default map
|
1455
1425
|
].filter((x) => !!x)
|
1456
1426
|
});
|
@@ -1482,11 +1452,9 @@ var ParseStatus = class _ParseStatus {
|
|
1482
1452
|
static async mergeObjectAsync(status, pairs) {
|
1483
1453
|
const syncPairs = [];
|
1484
1454
|
for (const pair of pairs) {
|
1485
|
-
const key = await pair.key;
|
1486
|
-
const value = await pair.value;
|
1487
1455
|
syncPairs.push({
|
1488
|
-
key,
|
1489
|
-
value
|
1456
|
+
key: await pair.key,
|
1457
|
+
value: await pair.value
|
1490
1458
|
});
|
1491
1459
|
}
|
1492
1460
|
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
@@ -1503,7 +1471,7 @@ var ParseStatus = class _ParseStatus {
|
|
1503
1471
|
status.dirty();
|
1504
1472
|
if (value.status === "dirty")
|
1505
1473
|
status.dirty();
|
1506
|
-
if (
|
1474
|
+
if (typeof value.value !== "undefined" || pair.alwaysSet) {
|
1507
1475
|
finalObject[key.value] = value.value;
|
1508
1476
|
}
|
1509
1477
|
}
|
@@ -1518,47 +1486,21 @@ var OK = (value) => ({ status: "valid", value });
|
|
1518
1486
|
var isAborted = (x) => x.status === "aborted";
|
1519
1487
|
var isDirty = (x) => x.status === "dirty";
|
1520
1488
|
var isValid = (x) => x.status === "valid";
|
1521
|
-
var isAsync = (x) => typeof 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
|
-
}
|
1489
|
+
var isAsync = (x) => typeof Promise !== void 0 && x instanceof Promise;
|
1538
1490
|
var errorUtil;
|
1539
1491
|
(function(errorUtil2) {
|
1540
1492
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
1541
1493
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
1542
1494
|
})(errorUtil || (errorUtil = {}));
|
1543
|
-
var _ZodEnum_cache;
|
1544
|
-
var _ZodNativeEnum_cache;
|
1545
1495
|
var ParseInputLazyPath = class {
|
1546
1496
|
constructor(parent, value, path, key) {
|
1547
|
-
this._cachedPath = [];
|
1548
1497
|
this.parent = parent;
|
1549
1498
|
this.data = value;
|
1550
1499
|
this._path = path;
|
1551
1500
|
this._key = key;
|
1552
1501
|
}
|
1553
1502
|
get path() {
|
1554
|
-
|
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;
|
1503
|
+
return this._path.concat(this._key);
|
1562
1504
|
}
|
1563
1505
|
};
|
1564
1506
|
var handleResult = (ctx, result) => {
|
@@ -1568,16 +1510,8 @@ var handleResult = (ctx, result) => {
|
|
1568
1510
|
if (!ctx.common.issues.length) {
|
1569
1511
|
throw new Error("Validation failed but no issues detected.");
|
1570
1512
|
}
|
1571
|
-
|
1572
|
-
|
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
|
-
};
|
1513
|
+
const error = new ZodError(ctx.common.issues);
|
1514
|
+
return { success: false, error };
|
1581
1515
|
}
|
1582
1516
|
};
|
1583
1517
|
function processCreateParams(params) {
|
@@ -1590,17 +1524,12 @@ function processCreateParams(params) {
|
|
1590
1524
|
if (errorMap2)
|
1591
1525
|
return { errorMap: errorMap2, description };
|
1592
1526
|
const customMap = (iss, ctx) => {
|
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
|
-
}
|
1598
|
-
if (typeof ctx.data === "undefined") {
|
1599
|
-
return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
|
1600
|
-
}
|
1601
1527
|
if (iss.code !== "invalid_type")
|
1602
1528
|
return { message: ctx.defaultError };
|
1603
|
-
|
1529
|
+
if (typeof ctx.data === "undefined") {
|
1530
|
+
return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
|
1531
|
+
}
|
1532
|
+
return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
|
1604
1533
|
};
|
1605
1534
|
return { errorMap: customMap, description };
|
1606
1535
|
}
|
@@ -1629,7 +1558,6 @@ var ZodType = class {
|
|
1629
1558
|
this.catch = this.catch.bind(this);
|
1630
1559
|
this.describe = this.describe.bind(this);
|
1631
1560
|
this.pipe = this.pipe.bind(this);
|
1632
|
-
this.readonly = this.readonly.bind(this);
|
1633
1561
|
this.isNullable = this.isNullable.bind(this);
|
1634
1562
|
this.isOptional = this.isOptional.bind(this);
|
1635
1563
|
}
|
@@ -1774,29 +1702,28 @@ var ZodType = class {
|
|
1774
1702
|
return this._refinement(refinement);
|
1775
1703
|
}
|
1776
1704
|
optional() {
|
1777
|
-
return ZodOptional.create(this
|
1705
|
+
return ZodOptional.create(this);
|
1778
1706
|
}
|
1779
1707
|
nullable() {
|
1780
|
-
return ZodNullable.create(this
|
1708
|
+
return ZodNullable.create(this);
|
1781
1709
|
}
|
1782
1710
|
nullish() {
|
1783
|
-
return this.
|
1711
|
+
return this.optional().nullable();
|
1784
1712
|
}
|
1785
1713
|
array() {
|
1786
|
-
return ZodArray.create(this
|
1714
|
+
return ZodArray.create(this);
|
1787
1715
|
}
|
1788
1716
|
promise() {
|
1789
|
-
return ZodPromise.create(this
|
1717
|
+
return ZodPromise.create(this);
|
1790
1718
|
}
|
1791
1719
|
or(option) {
|
1792
|
-
return ZodUnion.create([this, option]
|
1720
|
+
return ZodUnion.create([this, option]);
|
1793
1721
|
}
|
1794
1722
|
and(incoming) {
|
1795
|
-
return ZodIntersection.create(this, incoming
|
1723
|
+
return ZodIntersection.create(this, incoming);
|
1796
1724
|
}
|
1797
1725
|
transform(transform) {
|
1798
1726
|
return new ZodEffects({
|
1799
|
-
...processCreateParams(this._def),
|
1800
1727
|
schema: this,
|
1801
1728
|
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
1802
1729
|
effect: { type: "transform", transform }
|
@@ -1805,7 +1732,6 @@ var ZodType = class {
|
|
1805
1732
|
default(def) {
|
1806
1733
|
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
1807
1734
|
return new ZodDefault({
|
1808
|
-
...processCreateParams(this._def),
|
1809
1735
|
innerType: this,
|
1810
1736
|
defaultValue: defaultValueFunc,
|
1811
1737
|
typeName: ZodFirstPartyTypeKind.ZodDefault
|
@@ -1815,15 +1741,14 @@ var ZodType = class {
|
|
1815
1741
|
return new ZodBranded({
|
1816
1742
|
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
1817
1743
|
type: this,
|
1818
|
-
...processCreateParams(
|
1744
|
+
...processCreateParams(void 0)
|
1819
1745
|
});
|
1820
1746
|
}
|
1821
1747
|
catch(def) {
|
1822
|
-
const
|
1748
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
1823
1749
|
return new ZodCatch({
|
1824
|
-
...processCreateParams(this._def),
|
1825
1750
|
innerType: this,
|
1826
|
-
|
1751
|
+
defaultValue: defaultValueFunc,
|
1827
1752
|
typeName: ZodFirstPartyTypeKind.ZodCatch
|
1828
1753
|
});
|
1829
1754
|
}
|
@@ -1837,9 +1762,6 @@ var ZodType = class {
|
|
1837
1762
|
pipe(target) {
|
1838
1763
|
return ZodPipeline.create(this, target);
|
1839
1764
|
}
|
1840
|
-
readonly() {
|
1841
|
-
return ZodReadonly.create(this);
|
1842
|
-
}
|
1843
1765
|
isOptional() {
|
1844
1766
|
return this.safeParse(void 0).success;
|
1845
1767
|
}
|
@@ -1848,50 +1770,43 @@ var ZodType = class {
|
|
1848
1770
|
}
|
1849
1771
|
};
|
1850
1772
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
1851
|
-
var
|
1852
|
-
var
|
1853
|
-
var
|
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`;
|
1773
|
+
var uuidRegex = /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
1774
|
+
var emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
|
1775
|
+
var datetimeRegex = (args) => {
|
1866
1776
|
if (args.precision) {
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
}
|
1873
|
-
|
1874
|
-
|
1875
|
-
}
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
}
|
1885
|
-
function isValidIP(ip, version) {
|
1886
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
1887
|
-
return true;
|
1888
|
-
}
|
1889
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
1890
|
-
return true;
|
1777
|
+
if (args.offset) {
|
1778
|
+
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}:\\d{2})|Z)$`);
|
1779
|
+
} else {
|
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
|
+
}
|
1891
1794
|
}
|
1892
|
-
|
1893
|
-
}
|
1795
|
+
};
|
1894
1796
|
var ZodString = class _ZodString extends ZodType {
|
1797
|
+
constructor() {
|
1798
|
+
super(...arguments);
|
1799
|
+
this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
|
1800
|
+
validation,
|
1801
|
+
code: ZodIssueCode.invalid_string,
|
1802
|
+
...errorUtil.errToObj(message)
|
1803
|
+
});
|
1804
|
+
this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
|
1805
|
+
this.trim = () => new _ZodString({
|
1806
|
+
...this._def,
|
1807
|
+
checks: [...this._def.checks, { kind: "trim" }]
|
1808
|
+
});
|
1809
|
+
}
|
1895
1810
|
_parse(input) {
|
1896
1811
|
if (this._def.coerce) {
|
1897
1812
|
input.data = String(input.data);
|
@@ -1899,11 +1814,15 @@ var ZodString = class _ZodString extends ZodType {
|
|
1899
1814
|
const parsedType = this._getType(input);
|
1900
1815
|
if (parsedType !== ZodParsedType.string) {
|
1901
1816
|
const ctx2 = this._getOrReturnCtx(input);
|
1902
|
-
addIssueToContext(
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1817
|
+
addIssueToContext(
|
1818
|
+
ctx2,
|
1819
|
+
{
|
1820
|
+
code: ZodIssueCode.invalid_type,
|
1821
|
+
expected: ZodParsedType.string,
|
1822
|
+
received: ctx2.parsedType
|
1823
|
+
}
|
1824
|
+
//
|
1825
|
+
);
|
1907
1826
|
return INVALID;
|
1908
1827
|
}
|
1909
1828
|
const status = new ParseStatus();
|
@@ -1971,19 +1890,6 @@ var ZodString = class _ZodString extends ZodType {
|
|
1971
1890
|
});
|
1972
1891
|
status.dirty();
|
1973
1892
|
}
|
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
|
-
}
|
1987
1893
|
} else if (check.kind === "uuid") {
|
1988
1894
|
if (!uuidRegex.test(input.data)) {
|
1989
1895
|
ctx = this._getOrReturnCtx(input, ctx);
|
@@ -1994,16 +1900,6 @@ var ZodString = class _ZodString extends ZodType {
|
|
1994
1900
|
});
|
1995
1901
|
status.dirty();
|
1996
1902
|
}
|
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
|
-
}
|
2007
1903
|
} else if (check.kind === "cuid") {
|
2008
1904
|
if (!cuidRegex.test(input.data)) {
|
2009
1905
|
ctx = this._getOrReturnCtx(input, ctx);
|
@@ -2014,26 +1910,6 @@ var ZodString = class _ZodString extends ZodType {
|
|
2014
1910
|
});
|
2015
1911
|
status.dirty();
|
2016
1912
|
}
|
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
|
-
}
|
2037
1913
|
} else if (check.kind === "url") {
|
2038
1914
|
try {
|
2039
1915
|
new URL(input.data);
|
@@ -2060,20 +1936,6 @@ var ZodString = class _ZodString extends ZodType {
|
|
2060
1936
|
}
|
2061
1937
|
} else if (check.kind === "trim") {
|
2062
1938
|
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();
|
2077
1939
|
} else if (check.kind === "startsWith") {
|
2078
1940
|
if (!input.data.startsWith(check.value)) {
|
2079
1941
|
ctx = this._getOrReturnCtx(input, ctx);
|
@@ -2105,71 +1967,12 @@ var ZodString = class _ZodString extends ZodType {
|
|
2105
1967
|
});
|
2106
1968
|
status.dirty();
|
2107
1969
|
}
|
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
|
-
}
|
2160
1970
|
} else {
|
2161
1971
|
util.assertNever(check);
|
2162
1972
|
}
|
2163
1973
|
}
|
2164
1974
|
return { status: status.value, value: input.data };
|
2165
1975
|
}
|
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
|
-
}
|
2173
1976
|
_addCheck(check) {
|
2174
1977
|
return new _ZodString({
|
2175
1978
|
...this._def,
|
@@ -2182,38 +1985,19 @@ var ZodString = class _ZodString extends ZodType {
|
|
2182
1985
|
url(message) {
|
2183
1986
|
return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
|
2184
1987
|
}
|
2185
|
-
emoji(message) {
|
2186
|
-
return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
|
2187
|
-
}
|
2188
1988
|
uuid(message) {
|
2189
1989
|
return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
|
2190
1990
|
}
|
2191
|
-
nanoid(message) {
|
2192
|
-
return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
|
2193
|
-
}
|
2194
1991
|
cuid(message) {
|
2195
1992
|
return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
|
2196
1993
|
}
|
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
|
-
}
|
2209
1994
|
datetime(options) {
|
2210
|
-
var _a
|
1995
|
+
var _a;
|
2211
1996
|
if (typeof options === "string") {
|
2212
1997
|
return this._addCheck({
|
2213
1998
|
kind: "datetime",
|
2214
1999
|
precision: null,
|
2215
2000
|
offset: false,
|
2216
|
-
local: false,
|
2217
2001
|
message: options
|
2218
2002
|
});
|
2219
2003
|
}
|
@@ -2221,30 +2005,9 @@ var ZodString = class _ZodString extends ZodType {
|
|
2221
2005
|
kind: "datetime",
|
2222
2006
|
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
2223
2007
|
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,
|
2242
2008
|
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
2243
2009
|
});
|
2244
2010
|
}
|
2245
|
-
duration(message) {
|
2246
|
-
return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
|
2247
|
-
}
|
2248
2011
|
regex(regex, message) {
|
2249
2012
|
return this._addCheck({
|
2250
2013
|
kind: "regex",
|
@@ -2252,14 +2015,6 @@ var ZodString = class _ZodString extends ZodType {
|
|
2252
2015
|
...errorUtil.errToObj(message)
|
2253
2016
|
});
|
2254
2017
|
}
|
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
|
-
}
|
2263
2018
|
startsWith(value, message) {
|
2264
2019
|
return this._addCheck({
|
2265
2020
|
kind: "startsWith",
|
@@ -2295,73 +2050,21 @@ var ZodString = class _ZodString extends ZodType {
|
|
2295
2050
|
...errorUtil.errToObj(message)
|
2296
2051
|
});
|
2297
2052
|
}
|
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
|
-
}
|
2323
2053
|
get isDatetime() {
|
2324
2054
|
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
2325
2055
|
}
|
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
|
-
}
|
2335
2056
|
get isEmail() {
|
2336
2057
|
return !!this._def.checks.find((ch) => ch.kind === "email");
|
2337
2058
|
}
|
2338
2059
|
get isURL() {
|
2339
2060
|
return !!this._def.checks.find((ch) => ch.kind === "url");
|
2340
2061
|
}
|
2341
|
-
get isEmoji() {
|
2342
|
-
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
2343
|
-
}
|
2344
2062
|
get isUUID() {
|
2345
2063
|
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
2346
2064
|
}
|
2347
|
-
get isNANOID() {
|
2348
|
-
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
2349
|
-
}
|
2350
2065
|
get isCUID() {
|
2351
2066
|
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
2352
2067
|
}
|
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
|
-
}
|
2365
2068
|
get minLength() {
|
2366
2069
|
let min = null;
|
2367
2070
|
for (const ch of this._def.checks) {
|
@@ -2571,19 +2274,6 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
2571
2274
|
message: errorUtil.toString(message)
|
2572
2275
|
});
|
2573
2276
|
}
|
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
|
-
}
|
2587
2277
|
get minValue() {
|
2588
2278
|
let min = null;
|
2589
2279
|
for (const ch of this._def.checks) {
|
@@ -2605,22 +2295,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
2605
2295
|
return max;
|
2606
2296
|
}
|
2607
2297
|
get isInt() {
|
2608
|
-
return !!this._def.checks.find((ch) => ch.kind === "int"
|
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);
|
2298
|
+
return !!this._def.checks.find((ch) => ch.kind === "int");
|
2624
2299
|
}
|
2625
2300
|
};
|
2626
2301
|
ZodNumber.create = (params) => {
|
@@ -2631,167 +2306,27 @@ ZodNumber.create = (params) => {
|
|
2631
2306
|
...processCreateParams(params)
|
2632
2307
|
});
|
2633
2308
|
};
|
2634
|
-
var ZodBigInt = class
|
2635
|
-
constructor() {
|
2636
|
-
super(...arguments);
|
2637
|
-
this.min = this.gte;
|
2638
|
-
this.max = this.lte;
|
2639
|
-
}
|
2309
|
+
var ZodBigInt = class extends ZodType {
|
2640
2310
|
_parse(input) {
|
2641
2311
|
if (this._def.coerce) {
|
2642
2312
|
input.data = BigInt(input.data);
|
2643
2313
|
}
|
2644
2314
|
const parsedType = this._getType(input);
|
2645
2315
|
if (parsedType !== ZodParsedType.bigint) {
|
2646
|
-
const
|
2647
|
-
addIssueToContext(
|
2316
|
+
const ctx = this._getOrReturnCtx(input);
|
2317
|
+
addIssueToContext(ctx, {
|
2648
2318
|
code: ZodIssueCode.invalid_type,
|
2649
2319
|
expected: ZodParsedType.bigint,
|
2650
|
-
received:
|
2320
|
+
received: ctx.parsedType
|
2651
2321
|
});
|
2652
2322
|
return INVALID;
|
2653
2323
|
}
|
2654
|
-
|
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;
|
2324
|
+
return OK(input.data);
|
2789
2325
|
}
|
2790
2326
|
};
|
2791
2327
|
ZodBigInt.create = (params) => {
|
2792
2328
|
var _a;
|
2793
2329
|
return new ZodBigInt({
|
2794
|
-
checks: [],
|
2795
2330
|
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
2796
2331
|
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
2797
2332
|
...processCreateParams(params)
|
@@ -3117,13 +2652,13 @@ var ZodArray = class _ZodArray extends ZodType {
|
|
3117
2652
|
}
|
3118
2653
|
}
|
3119
2654
|
if (ctx.common.async) {
|
3120
|
-
return Promise.all(
|
2655
|
+
return Promise.all(ctx.data.map((item, i) => {
|
3121
2656
|
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
3122
2657
|
})).then((result2) => {
|
3123
2658
|
return ParseStatus.mergeArray(status, result2);
|
3124
2659
|
});
|
3125
2660
|
}
|
3126
|
-
const result =
|
2661
|
+
const result = ctx.data.map((item, i) => {
|
3127
2662
|
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
3128
2663
|
});
|
3129
2664
|
return ParseStatus.mergeArray(status, result);
|
@@ -3163,6 +2698,25 @@ ZodArray.create = (schema3, params) => {
|
|
3163
2698
|
...processCreateParams(params)
|
3164
2699
|
});
|
3165
2700
|
};
|
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
|
+
};
|
3166
2720
|
function deepPartialify(schema3) {
|
3167
2721
|
if (schema3 instanceof ZodObject) {
|
3168
2722
|
const newShape = {};
|
@@ -3175,10 +2729,7 @@ function deepPartialify(schema3) {
|
|
3175
2729
|
shape: () => newShape
|
3176
2730
|
});
|
3177
2731
|
} else if (schema3 instanceof ZodArray) {
|
3178
|
-
return
|
3179
|
-
...schema3._def,
|
3180
|
-
type: deepPartialify(schema3.element)
|
3181
|
-
});
|
2732
|
+
return ZodArray.create(deepPartialify(schema3.element));
|
3182
2733
|
} else if (schema3 instanceof ZodOptional) {
|
3183
2734
|
return ZodOptional.create(deepPartialify(schema3.unwrap()));
|
3184
2735
|
} else if (schema3 instanceof ZodNullable) {
|
@@ -3194,7 +2745,8 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3194
2745
|
super(...arguments);
|
3195
2746
|
this._cached = null;
|
3196
2747
|
this.nonstrict = this.passthrough;
|
3197
|
-
this.augment = this.
|
2748
|
+
this.augment = AugmentFactory(this._def);
|
2749
|
+
this.extend = AugmentFactory(this._def);
|
3198
2750
|
}
|
3199
2751
|
_getCached() {
|
3200
2752
|
if (this._cached !== null)
|
@@ -3275,10 +2827,9 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3275
2827
|
const syncPairs = [];
|
3276
2828
|
for (const pair of pairs) {
|
3277
2829
|
const key = await pair.key;
|
3278
|
-
const value = await pair.value;
|
3279
2830
|
syncPairs.push({
|
3280
2831
|
key,
|
3281
|
-
value,
|
2832
|
+
value: await pair.value,
|
3282
2833
|
alwaysSet: pair.alwaysSet
|
3283
2834
|
});
|
3284
2835
|
}
|
@@ -3325,31 +2876,8 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3325
2876
|
unknownKeys: "passthrough"
|
3326
2877
|
});
|
3327
2878
|
}
|
3328
|
-
|
3329
|
-
|
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
|
-
});
|
2879
|
+
setKey(key, schema3) {
|
2880
|
+
return this.augment({ [key]: schema3 });
|
3353
2881
|
}
|
3354
2882
|
/**
|
3355
2883
|
* Prior to zod@1.0.12 there was a bug in the
|
@@ -3360,73 +2888,11 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3360
2888
|
const merged = new _ZodObject({
|
3361
2889
|
unknownKeys: merging._def.unknownKeys,
|
3362
2890
|
catchall: merging._def.catchall,
|
3363
|
-
shape: () => (
|
3364
|
-
...this._def.shape(),
|
3365
|
-
...merging._def.shape()
|
3366
|
-
}),
|
2891
|
+
shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
3367
2892
|
typeName: ZodFirstPartyTypeKind.ZodObject
|
3368
2893
|
});
|
3369
2894
|
return merged;
|
3370
2895
|
}
|
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
|
-
// }
|
3430
2896
|
catchall(index4) {
|
3431
2897
|
return new _ZodObject({
|
3432
2898
|
...this._def,
|
@@ -3435,10 +2901,9 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3435
2901
|
}
|
3436
2902
|
pick(mask) {
|
3437
2903
|
const shape = {};
|
3438
|
-
util.objectKeys(mask).
|
3439
|
-
if (
|
2904
|
+
util.objectKeys(mask).map((key) => {
|
2905
|
+
if (this.shape[key])
|
3440
2906
|
shape[key] = this.shape[key];
|
3441
|
-
}
|
3442
2907
|
});
|
3443
2908
|
return new _ZodObject({
|
3444
2909
|
...this._def,
|
@@ -3447,8 +2912,8 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3447
2912
|
}
|
3448
2913
|
omit(mask) {
|
3449
2914
|
const shape = {};
|
3450
|
-
util.objectKeys(this.shape).
|
3451
|
-
if (
|
2915
|
+
util.objectKeys(this.shape).map((key) => {
|
2916
|
+
if (util.objectKeys(mask).indexOf(key) === -1) {
|
3452
2917
|
shape[key] = this.shape[key];
|
3453
2918
|
}
|
3454
2919
|
});
|
@@ -3457,22 +2922,29 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3457
2922
|
shape: () => shape
|
3458
2923
|
});
|
3459
2924
|
}
|
3460
|
-
/**
|
3461
|
-
* @deprecated
|
3462
|
-
*/
|
3463
2925
|
deepPartial() {
|
3464
2926
|
return deepPartialify(this);
|
3465
2927
|
}
|
3466
2928
|
partial(mask) {
|
3467
2929
|
const newShape = {};
|
3468
|
-
|
3469
|
-
|
3470
|
-
|
3471
|
-
|
3472
|
-
|
2930
|
+
if (mask) {
|
2931
|
+
util.objectKeys(this.shape).map((key) => {
|
2932
|
+
if (util.objectKeys(mask).indexOf(key) === -1) {
|
2933
|
+
newShape[key] = this.shape[key];
|
2934
|
+
} else {
|
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];
|
3473
2945
|
newShape[key] = fieldSchema.optional();
|
3474
2946
|
}
|
3475
|
-
}
|
2947
|
+
}
|
3476
2948
|
return new _ZodObject({
|
3477
2949
|
...this._def,
|
3478
2950
|
shape: () => newShape
|
@@ -3480,10 +2952,21 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3480
2952
|
}
|
3481
2953
|
required(mask) {
|
3482
2954
|
const newShape = {};
|
3483
|
-
|
3484
|
-
|
3485
|
-
|
3486
|
-
|
2955
|
+
if (mask) {
|
2956
|
+
util.objectKeys(this.shape).map((key) => {
|
2957
|
+
if (util.objectKeys(mask).indexOf(key) === -1) {
|
2958
|
+
newShape[key] = this.shape[key];
|
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) {
|
3487
2970
|
const fieldSchema = this.shape[key];
|
3488
2971
|
let newField = fieldSchema;
|
3489
2972
|
while (newField instanceof ZodOptional) {
|
@@ -3491,7 +2974,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
3491
2974
|
}
|
3492
2975
|
newShape[key] = newField;
|
3493
2976
|
}
|
3494
|
-
}
|
2977
|
+
}
|
3495
2978
|
return new _ZodObject({
|
3496
2979
|
...this._def,
|
3497
2980
|
shape: () => newShape
|
@@ -3629,25 +3112,15 @@ var getDiscriminator = (type) => {
|
|
3629
3112
|
} else if (type instanceof ZodEnum) {
|
3630
3113
|
return type.options;
|
3631
3114
|
} else if (type instanceof ZodNativeEnum) {
|
3632
|
-
return
|
3115
|
+
return Object.keys(type.enum);
|
3633
3116
|
} else if (type instanceof ZodDefault) {
|
3634
3117
|
return getDiscriminator(type._def.innerType);
|
3635
3118
|
} else if (type instanceof ZodUndefined) {
|
3636
3119
|
return [void 0];
|
3637
3120
|
} else if (type instanceof ZodNull) {
|
3638
3121
|
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);
|
3649
3122
|
} else {
|
3650
|
-
return
|
3123
|
+
return null;
|
3651
3124
|
}
|
3652
3125
|
};
|
3653
3126
|
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
@@ -3707,7 +3180,7 @@ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3707
3180
|
const optionsMap = /* @__PURE__ */ new Map();
|
3708
3181
|
for (const type of options) {
|
3709
3182
|
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
3710
|
-
if (!discriminatorValues
|
3183
|
+
if (!discriminatorValues) {
|
3711
3184
|
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
3712
3185
|
}
|
3713
3186
|
for (const value of discriminatorValues) {
|
@@ -3849,7 +3322,7 @@ var ZodTuple = class _ZodTuple extends ZodType {
|
|
3849
3322
|
});
|
3850
3323
|
status.dirty();
|
3851
3324
|
}
|
3852
|
-
const items =
|
3325
|
+
const items = ctx.data.map((item, itemIndex) => {
|
3853
3326
|
const schema3 = this._def.items[itemIndex] || this._def.rest;
|
3854
3327
|
if (!schema3)
|
3855
3328
|
return null;
|
@@ -3907,8 +3380,7 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
3907
3380
|
for (const key in ctx.data) {
|
3908
3381
|
pairs.push({
|
3909
3382
|
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
3910
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
3911
|
-
alwaysSet: key in ctx.data
|
3383
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
3912
3384
|
});
|
3913
3385
|
}
|
3914
3386
|
if (ctx.common.async) {
|
@@ -3938,12 +3410,6 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
3938
3410
|
}
|
3939
3411
|
};
|
3940
3412
|
var ZodMap = class extends ZodType {
|
3941
|
-
get keySchema() {
|
3942
|
-
return this._def.keyType;
|
3943
|
-
}
|
3944
|
-
get valueSchema() {
|
3945
|
-
return this._def.valueType;
|
3946
|
-
}
|
3947
3413
|
_parse(input) {
|
3948
3414
|
const { status, ctx } = this._processInputParams(input);
|
3949
3415
|
if (ctx.parsedType !== ZodParsedType.map) {
|
@@ -4138,29 +3604,27 @@ var ZodFunction = class _ZodFunction extends ZodType {
|
|
4138
3604
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
4139
3605
|
const fn = ctx.data;
|
4140
3606
|
if (this._def.returns instanceof ZodPromise) {
|
4141
|
-
|
4142
|
-
return OK(async function(...args) {
|
3607
|
+
return OK(async (...args) => {
|
4143
3608
|
const error = new ZodError([]);
|
4144
|
-
const parsedArgs = await
|
3609
|
+
const parsedArgs = await this._def.args.parseAsync(args, params).catch((e) => {
|
4145
3610
|
error.addIssue(makeArgsIssue(args, e));
|
4146
3611
|
throw error;
|
4147
3612
|
});
|
4148
|
-
const result = await
|
4149
|
-
const parsedReturns = await
|
3613
|
+
const result = await fn(...parsedArgs);
|
3614
|
+
const parsedReturns = await this._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
4150
3615
|
error.addIssue(makeReturnsIssue(result, e));
|
4151
3616
|
throw error;
|
4152
3617
|
});
|
4153
3618
|
return parsedReturns;
|
4154
3619
|
});
|
4155
3620
|
} else {
|
4156
|
-
|
4157
|
-
|
4158
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
3621
|
+
return OK((...args) => {
|
3622
|
+
const parsedArgs = this._def.args.safeParse(args, params);
|
4159
3623
|
if (!parsedArgs.success) {
|
4160
3624
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
4161
3625
|
}
|
4162
|
-
const result =
|
4163
|
-
const parsedReturns =
|
3626
|
+
const result = fn(...parsedArgs.data);
|
3627
|
+
const parsedReturns = this._def.returns.safeParse(result, params);
|
4164
3628
|
if (!parsedReturns.success) {
|
4165
3629
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
4166
3630
|
}
|
@@ -4225,7 +3689,6 @@ var ZodLiteral = class extends ZodType {
|
|
4225
3689
|
if (input.data !== this._def.value) {
|
4226
3690
|
const ctx = this._getOrReturnCtx(input);
|
4227
3691
|
addIssueToContext(ctx, {
|
4228
|
-
received: ctx.data,
|
4229
3692
|
code: ZodIssueCode.invalid_literal,
|
4230
3693
|
expected: this._def.value
|
4231
3694
|
});
|
@@ -4251,11 +3714,7 @@ function createZodEnum(values, params) {
|
|
4251
3714
|
...processCreateParams(params)
|
4252
3715
|
});
|
4253
3716
|
}
|
4254
|
-
var ZodEnum = class
|
4255
|
-
constructor() {
|
4256
|
-
super(...arguments);
|
4257
|
-
_ZodEnum_cache.set(this, void 0);
|
4258
|
-
}
|
3717
|
+
var ZodEnum = class extends ZodType {
|
4259
3718
|
_parse(input) {
|
4260
3719
|
if (typeof input.data !== "string") {
|
4261
3720
|
const ctx = this._getOrReturnCtx(input);
|
@@ -4267,10 +3726,7 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
|
4267
3726
|
});
|
4268
3727
|
return INVALID;
|
4269
3728
|
}
|
4270
|
-
if (
|
4271
|
-
__classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
|
4272
|
-
}
|
4273
|
-
if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
|
3729
|
+
if (this._def.values.indexOf(input.data) === -1) {
|
4274
3730
|
const ctx = this._getOrReturnCtx(input);
|
4275
3731
|
const expectedValues = this._def.values;
|
4276
3732
|
addIssueToContext(ctx, {
|
@@ -4306,26 +3762,9 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
|
4306
3762
|
}
|
4307
3763
|
return enumValues;
|
4308
3764
|
}
|
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
|
-
}
|
4321
3765
|
};
|
4322
|
-
_ZodEnum_cache = /* @__PURE__ */ new WeakMap();
|
4323
3766
|
ZodEnum.create = createZodEnum;
|
4324
3767
|
var ZodNativeEnum = class extends ZodType {
|
4325
|
-
constructor() {
|
4326
|
-
super(...arguments);
|
4327
|
-
_ZodNativeEnum_cache.set(this, void 0);
|
4328
|
-
}
|
4329
3768
|
_parse(input) {
|
4330
3769
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
4331
3770
|
const ctx = this._getOrReturnCtx(input);
|
@@ -4338,10 +3777,7 @@ var ZodNativeEnum = class extends ZodType {
|
|
4338
3777
|
});
|
4339
3778
|
return INVALID;
|
4340
3779
|
}
|
4341
|
-
if (
|
4342
|
-
__classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
|
4343
|
-
}
|
4344
|
-
if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
|
3780
|
+
if (nativeEnumValues.indexOf(input.data) === -1) {
|
4345
3781
|
const expectedValues = util.objectValues(nativeEnumValues);
|
4346
3782
|
addIssueToContext(ctx, {
|
4347
3783
|
received: ctx.data,
|
@@ -4356,7 +3792,6 @@ var ZodNativeEnum = class extends ZodType {
|
|
4356
3792
|
return this._def.values;
|
4357
3793
|
}
|
4358
3794
|
};
|
4359
|
-
_ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
|
4360
3795
|
ZodNativeEnum.create = (values, params) => {
|
4361
3796
|
return new ZodNativeEnum({
|
4362
3797
|
values,
|
@@ -4365,9 +3800,6 @@ ZodNativeEnum.create = (values, params) => {
|
|
4365
3800
|
});
|
4366
3801
|
};
|
4367
3802
|
var ZodPromise = class extends ZodType {
|
4368
|
-
unwrap() {
|
4369
|
-
return this._def.type;
|
4370
|
-
}
|
4371
3803
|
_parse(input) {
|
4372
3804
|
const { ctx } = this._processInputParams(input);
|
4373
3805
|
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
@@ -4404,56 +3836,38 @@ var ZodEffects = class extends ZodType {
|
|
4404
3836
|
_parse(input) {
|
4405
3837
|
const { status, ctx } = this._processInputParams(input);
|
4406
3838
|
const effect = this._def.effect || null;
|
4407
|
-
const checkCtx = {
|
4408
|
-
addIssue: (arg) => {
|
4409
|
-
addIssueToContext(ctx, arg);
|
4410
|
-
if (arg.fatal) {
|
4411
|
-
status.abort();
|
4412
|
-
} else {
|
4413
|
-
status.dirty();
|
4414
|
-
}
|
4415
|
-
},
|
4416
|
-
get path() {
|
4417
|
-
return ctx.path;
|
4418
|
-
}
|
4419
|
-
};
|
4420
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
4421
3839
|
if (effect.type === "preprocess") {
|
4422
|
-
const processed = effect.transform(ctx.data
|
3840
|
+
const processed = effect.transform(ctx.data);
|
4423
3841
|
if (ctx.common.async) {
|
4424
|
-
return Promise.resolve(processed).then(
|
4425
|
-
|
4426
|
-
return INVALID;
|
4427
|
-
const result = await this._def.schema._parseAsync({
|
3842
|
+
return Promise.resolve(processed).then((processed2) => {
|
3843
|
+
return this._def.schema._parseAsync({
|
4428
3844
|
data: processed2,
|
4429
3845
|
path: ctx.path,
|
4430
3846
|
parent: ctx
|
4431
3847
|
});
|
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
3848
|
});
|
4440
3849
|
} else {
|
4441
|
-
|
4442
|
-
return INVALID;
|
4443
|
-
const result = this._def.schema._parseSync({
|
3850
|
+
return this._def.schema._parseSync({
|
4444
3851
|
data: processed,
|
4445
3852
|
path: ctx.path,
|
4446
3853
|
parent: ctx
|
4447
3854
|
});
|
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
3855
|
}
|
4456
3856
|
}
|
3857
|
+
const checkCtx = {
|
3858
|
+
addIssue: (arg) => {
|
3859
|
+
addIssueToContext(ctx, arg);
|
3860
|
+
if (arg.fatal) {
|
3861
|
+
status.abort();
|
3862
|
+
} else {
|
3863
|
+
status.dirty();
|
3864
|
+
}
|
3865
|
+
},
|
3866
|
+
get path() {
|
3867
|
+
return ctx.path;
|
3868
|
+
}
|
3869
|
+
};
|
3870
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
4457
3871
|
if (effect.type === "refinement") {
|
4458
3872
|
const executeRefinement = (acc) => {
|
4459
3873
|
const result = effect.refinement(acc, checkCtx);
|
@@ -4596,45 +4010,26 @@ ZodDefault.create = (type, params) => {
|
|
4596
4010
|
var ZodCatch = class extends ZodType {
|
4597
4011
|
_parse(input) {
|
4598
4012
|
const { ctx } = this._processInputParams(input);
|
4599
|
-
const newCtx = {
|
4600
|
-
...ctx,
|
4601
|
-
common: {
|
4602
|
-
...ctx.common,
|
4603
|
-
issues: []
|
4604
|
-
}
|
4605
|
-
};
|
4606
4013
|
const result = this._def.innerType._parse({
|
4607
|
-
data:
|
4608
|
-
path:
|
4609
|
-
parent:
|
4610
|
-
...newCtx
|
4611
|
-
}
|
4014
|
+
data: ctx.data,
|
4015
|
+
path: ctx.path,
|
4016
|
+
parent: ctx
|
4612
4017
|
});
|
4613
4018
|
if (isAsync(result)) {
|
4614
4019
|
return result.then((result2) => {
|
4615
4020
|
return {
|
4616
4021
|
status: "valid",
|
4617
|
-
value: result2.status === "valid" ? result2.value : this._def.
|
4618
|
-
get error() {
|
4619
|
-
return new ZodError(newCtx.common.issues);
|
4620
|
-
},
|
4621
|
-
input: newCtx.data
|
4622
|
-
})
|
4022
|
+
value: result2.status === "valid" ? result2.value : this._def.defaultValue()
|
4623
4023
|
};
|
4624
4024
|
});
|
4625
4025
|
} else {
|
4626
4026
|
return {
|
4627
4027
|
status: "valid",
|
4628
|
-
value: result.status === "valid" ? result.value : this._def.
|
4629
|
-
get error() {
|
4630
|
-
return new ZodError(newCtx.common.issues);
|
4631
|
-
},
|
4632
|
-
input: newCtx.data
|
4633
|
-
})
|
4028
|
+
value: result.status === "valid" ? result.value : this._def.defaultValue()
|
4634
4029
|
};
|
4635
4030
|
}
|
4636
4031
|
}
|
4637
|
-
|
4032
|
+
removeDefault() {
|
4638
4033
|
return this._def.innerType;
|
4639
4034
|
}
|
4640
4035
|
};
|
@@ -4642,7 +4037,7 @@ ZodCatch.create = (type, params) => {
|
|
4642
4037
|
return new ZodCatch({
|
4643
4038
|
innerType: type,
|
4644
4039
|
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
4645
|
-
|
4040
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
4646
4041
|
...processCreateParams(params)
|
4647
4042
|
});
|
4648
4043
|
};
|
@@ -4737,25 +4132,6 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
4737
4132
|
});
|
4738
4133
|
}
|
4739
4134
|
};
|
4740
|
-
var ZodReadonly = class extends ZodType {
|
4741
|
-
_parse(input) {
|
4742
|
-
const result = this._def.innerType._parse(input);
|
4743
|
-
if (isValid(result)) {
|
4744
|
-
result.value = Object.freeze(result.value);
|
4745
|
-
}
|
4746
|
-
return result;
|
4747
|
-
}
|
4748
|
-
unwrap() {
|
4749
|
-
return this._def.innerType;
|
4750
|
-
}
|
4751
|
-
};
|
4752
|
-
ZodReadonly.create = (type, params) => {
|
4753
|
-
return new ZodReadonly({
|
4754
|
-
innerType: type,
|
4755
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
4756
|
-
...processCreateParams(params)
|
4757
|
-
});
|
4758
|
-
};
|
4759
4135
|
var late = {
|
4760
4136
|
object: ZodObject.lazycreate
|
4761
4137
|
};
|
@@ -4796,7 +4172,6 @@ var ZodFirstPartyTypeKind;
|
|
4796
4172
|
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
4797
4173
|
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
4798
4174
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
4799
|
-
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
4800
4175
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
4801
4176
|
var stringType = ZodString.create;
|
4802
4177
|
var numberType = ZodNumber.create;
|
@@ -5164,7 +4539,7 @@ var pgSchemaExternal = objectType({
|
|
5164
4539
|
}).strict();
|
5165
4540
|
var pgSchemaInternal = objectType({
|
5166
4541
|
version: literalType("6"),
|
5167
|
-
dialect: literalType("
|
4542
|
+
dialect: literalType("postgresql"),
|
5168
4543
|
tables: recordType(stringType(), table2),
|
5169
4544
|
enums: recordType(stringType(), enumSchema),
|
5170
4545
|
schemas: recordType(stringType(), stringType()),
|
@@ -5193,14 +4568,14 @@ var tableSquashedV42 = objectType({
|
|
5193
4568
|
}).strict();
|
5194
4569
|
var pgSchemaSquashedV4 = objectType({
|
5195
4570
|
version: literalType("4"),
|
5196
|
-
dialect:
|
4571
|
+
dialect: literalType("pg"),
|
5197
4572
|
tables: recordType(stringType(), tableSquashedV42),
|
5198
4573
|
enums: recordType(stringType(), enumSchemaV1),
|
5199
4574
|
schemas: recordType(stringType(), stringType())
|
5200
4575
|
}).strict();
|
5201
4576
|
var pgSchemaSquashed = objectType({
|
5202
4577
|
version: literalType("6"),
|
5203
|
-
dialect:
|
4578
|
+
dialect: literalType("postgresql"),
|
5204
4579
|
tables: recordType(stringType(), tableSquashed2),
|
5205
4580
|
enums: recordType(stringType(), enumSchema),
|
5206
4581
|
schemas: recordType(stringType(), stringType())
|
@@ -5212,7 +4587,7 @@ var pgSchema = pgSchemaInternal.merge(schemaHash2);
|
|
5212
4587
|
var backwardCompatiblePgSchema = unionType([pgSchemaV5, pgSchema]);
|
5213
4588
|
var dryPg = pgSchema.parse({
|
5214
4589
|
version: snapshotVersion,
|
5215
|
-
dialect: "
|
4590
|
+
dialect: "postgresql",
|
5216
4591
|
id: originUUID,
|
5217
4592
|
prevId: "",
|
5218
4593
|
tables: {},
|
@@ -5374,7 +4749,7 @@ var prepareOutFolder = (out, dialect3) => {
|
|
5374
4749
|
};
|
5375
4750
|
var validatorForDialect = (dialect3) => {
|
5376
4751
|
switch (dialect3) {
|
5377
|
-
case "
|
4752
|
+
case "postgresql":
|
5378
4753
|
return { validator: backwardCompatiblePgSchema, version: 6 };
|
5379
4754
|
case "sqlite":
|
5380
4755
|
return { validator: backwardCompatibleSqliteSchema, version: 5 };
|