drizzle-kit 0.21.2 → 0.21.4-b5744a6

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