drizzle-kit 0.20.17-b2e8c7f → 0.20.17-b4f119e

Sign up to get free protection for your applications and to get access to all the features.
package/utils.js CHANGED
@@ -33,10 +33,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
 
34
34
  // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js
35
35
  var require_readline = __commonJS({
36
- "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports) {
36
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/readline.js"(exports2) {
37
37
  "use strict";
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.prepareReadLine = void 0;
38
+ Object.defineProperty(exports2, "__esModule", { value: true });
39
+ exports2.prepareReadLine = void 0;
40
40
  var prepareReadLine = () => {
41
41
  const stdin = process.stdin;
42
42
  const stdout = process.stdout;
@@ -52,13 +52,13 @@ var require_readline = __commonJS({
52
52
  closable: rl
53
53
  };
54
54
  };
55
- exports.prepareReadLine = prepareReadLine;
55
+ exports2.prepareReadLine = prepareReadLine;
56
56
  }
57
57
  });
58
58
 
59
59
  // node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
60
60
  var require_src = __commonJS({
61
- "node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports, module2) {
61
+ "node_modules/.pnpm/sisteransi@1.0.5/node_modules/sisteransi/src/index.js"(exports2, module2) {
62
62
  "use strict";
63
63
  var ESC = "\x1B";
64
64
  var CSI = `${ESC}[`;
@@ -119,10 +119,10 @@ var require_src = __commonJS({
119
119
 
120
120
  // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js
121
121
  var require_utils = __commonJS({
122
- "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports) {
122
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/utils.js"(exports2) {
123
123
  "use strict";
124
- Object.defineProperty(exports, "__esModule", { value: true });
125
- exports.clear = void 0;
124
+ Object.defineProperty(exports2, "__esModule", { value: true });
125
+ exports2.clear = void 0;
126
126
  var sisteransi_1 = require_src();
127
127
  var strip = (str) => {
128
128
  const pattern = [
@@ -143,13 +143,13 @@ var require_utils = __commonJS({
143
143
  }
144
144
  return sisteransi_1.erase.lines(rows);
145
145
  };
146
- exports.clear = clear;
146
+ exports2.clear = clear;
147
147
  }
148
148
  });
149
149
 
150
150
  // node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js
151
151
  var require_lodash = __commonJS({
152
- "node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports, module2) {
152
+ "node_modules/.pnpm/lodash.throttle@4.1.1/node_modules/lodash.throttle/index.js"(exports2, module2) {
153
153
  var FUNC_ERROR_TEXT = "Expected a function";
154
154
  var NAN = 0 / 0;
155
155
  var symbolTag = "[object Symbol]";
@@ -297,9 +297,9 @@ var require_lodash = __commonJS({
297
297
 
298
298
  // node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js
299
299
  var require_hanji = __commonJS({
300
- "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports) {
300
+ "node_modules/.pnpm/hanji@0.0.5/node_modules/hanji/index.js"(exports2) {
301
301
  "use strict";
302
- var __awaiter = exports && exports.__awaiter || function(thisArg, _arguments, P, generator) {
302
+ var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
303
303
  function adopt(value) {
304
304
  return value instanceof P ? value : new P(function(resolve) {
305
305
  resolve(value);
@@ -326,11 +326,11 @@ var require_hanji = __commonJS({
326
326
  step((generator = generator.apply(thisArg, _arguments || [])).next());
327
327
  });
328
328
  };
329
- var __importDefault = exports && exports.__importDefault || function(mod) {
329
+ var __importDefault = exports2 && exports2.__importDefault || function(mod) {
330
330
  return mod && mod.__esModule ? mod : { "default": mod };
331
331
  };
332
- Object.defineProperty(exports, "__esModule", { value: true });
333
- exports.onTerminate = exports.renderWithTask = exports.render = exports.TaskTerminal = exports.TaskView = exports.Terminal = exports.deferred = exports.SelectState = exports.Prompt = void 0;
332
+ Object.defineProperty(exports2, "__esModule", { value: true });
333
+ exports2.onTerminate = exports2.renderWithTask = exports2.render = exports2.TaskTerminal = exports2.TaskView = exports2.Terminal = exports2.deferred = exports2.SelectState = exports2.Prompt = void 0;
334
334
  var readline_1 = require_readline();
335
335
  var sisteransi_1 = require_src();
336
336
  var utils_1 = require_utils();
@@ -365,7 +365,7 @@ var require_hanji = __commonJS({
365
365
  this.inputCallbacks.forEach((it) => it(str, key));
366
366
  }
367
367
  };
368
- exports.Prompt = Prompt2;
368
+ exports2.Prompt = Prompt2;
369
369
  var SelectState2 = class {
370
370
  constructor(items) {
371
371
  this.items = items;
@@ -393,7 +393,7 @@ var require_hanji = __commonJS({
393
393
  return false;
394
394
  }
395
395
  };
396
- exports.SelectState = SelectState2;
396
+ exports2.SelectState = SelectState2;
397
397
  var deferred = () => {
398
398
  let resolve;
399
399
  let reject;
@@ -407,7 +407,7 @@ var require_hanji = __commonJS({
407
407
  promise
408
408
  };
409
409
  };
410
- exports.deferred = deferred;
410
+ exports2.deferred = deferred;
411
411
  var Terminal = class {
412
412
  constructor(view, stdin, stdout, closable) {
413
413
  this.view = view;
@@ -452,7 +452,7 @@ var require_hanji = __commonJS({
452
452
  };
453
453
  this.stdin.on("keypress", keypress);
454
454
  this.view.attach(this);
455
- const { resolve, promise } = (0, exports.deferred)();
455
+ const { resolve, promise } = (0, exports2.deferred)();
456
456
  this.resolve = resolve;
457
457
  this.promise = promise;
458
458
  this.renderFunc = (0, lodash_throttle_1.default)((str) => {
@@ -483,7 +483,7 @@ var require_hanji = __commonJS({
483
483
  this.renderFunc(`${clearPrefix}${string}`);
484
484
  }
485
485
  };
486
- exports.Terminal = Terminal;
486
+ exports2.Terminal = Terminal;
487
487
  var TaskView2 = class {
488
488
  constructor() {
489
489
  this.attachCallbacks = [];
@@ -508,7 +508,7 @@ var require_hanji = __commonJS({
508
508
  }
509
509
  }
510
510
  };
511
- exports.TaskView = TaskView2;
511
+ exports2.TaskView = TaskView2;
512
512
  var TaskTerminal = class {
513
513
  constructor(view, stdout) {
514
514
  this.view = view;
@@ -529,7 +529,7 @@ var require_hanji = __commonJS({
529
529
  this.stdout.write(`${clearPrefix}${string}`);
530
530
  }
531
531
  };
532
- exports.TaskTerminal = TaskTerminal;
532
+ exports2.TaskTerminal = TaskTerminal;
533
533
  function render2(view) {
534
534
  const { stdin, stdout, closable } = (0, readline_1.prepareReadLine)();
535
535
  if (view instanceof Prompt2) {
@@ -542,7 +542,7 @@ var require_hanji = __commonJS({
542
542
  closable.close();
543
543
  return;
544
544
  }
545
- exports.render = render2;
545
+ exports2.render = render2;
546
546
  function renderWithTask(view, task) {
547
547
  return __awaiter(this, void 0, void 0, function* () {
548
548
  const terminal = new TaskTerminal(view, process.stdout);
@@ -552,12 +552,12 @@ var require_hanji = __commonJS({
552
552
  return result;
553
553
  });
554
554
  }
555
- exports.renderWithTask = renderWithTask;
555
+ exports2.renderWithTask = renderWithTask;
556
556
  var terminateHandler;
557
557
  function onTerminate(callback) {
558
558
  terminateHandler = callback;
559
559
  }
560
- exports.onTerminate = onTerminate;
560
+ exports2.onTerminate = onTerminate;
561
561
  }
562
562
  });
563
563
 
@@ -580,7 +580,7 @@ __export(utils_exports, {
580
580
  module.exports = __toCommonJS(utils_exports);
581
581
  var import_fs = require("fs");
582
582
 
583
- // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/ansi-styles/index.js
583
+ // node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js
584
584
  var ANSI_BACKGROUND_OFFSET = 10;
585
585
  var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
586
586
  var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
@@ -766,7 +766,7 @@ function assembleStyles() {
766
766
  var ansiStyles = assembleStyles();
767
767
  var ansi_styles_default = ansiStyles;
768
768
 
769
- // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/vendor/supports-color/index.js
769
+ // node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js
770
770
  var import_node_process = __toESM(require("node:process"), 1);
771
771
  var import_node_os = __toESM(require("node:os"), 1);
772
772
  var import_node_tty = __toESM(require("node:tty"), 1);
@@ -840,7 +840,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
840
840
  return 1;
841
841
  }
842
842
  if ("CI" in env) {
843
- if ("GITHUB_ACTIONS" in env) {
843
+ if ("GITHUB_ACTIONS" in env || "GITEA_ACTIONS" in env) {
844
844
  return 3;
845
845
  }
846
846
  if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
@@ -892,7 +892,7 @@ var supportsColor = {
892
892
  };
893
893
  var supports_color_default = supportsColor;
894
894
 
895
- // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/utilities.js
895
+ // node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js
896
896
  function stringReplaceAll(string, substring, replacer) {
897
897
  let index4 = string.indexOf(substring);
898
898
  if (index4 === -1) {
@@ -922,7 +922,7 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index4) {
922
922
  return returnValue;
923
923
  }
924
924
 
925
- // node_modules/.pnpm/chalk@5.2.0/node_modules/chalk/source/index.js
925
+ // node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js
926
926
  var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
927
927
  var GENERATOR = Symbol("GENERATOR");
928
928
  var STYLER = Symbol("STYLER");
@@ -1079,7 +1079,7 @@ var info = (msg, greyMsg = "") => {
1079
1079
  var originUUID = "00000000-0000-0000-0000-000000000000";
1080
1080
  var snapshotVersion = "6";
1081
1081
 
1082
- // node_modules/.pnpm/zod@3.20.2/node_modules/zod/lib/index.mjs
1082
+ // node_modules/.pnpm/zod@3.23.4/node_modules/zod/lib/index.mjs
1083
1083
  var util;
1084
1084
  (function(util2) {
1085
1085
  util2.assertEqual = (val) => val;
@@ -1138,6 +1138,16 @@ var util;
1138
1138
  return value;
1139
1139
  };
1140
1140
  })(util || (util = {}));
1141
+ var objectUtil;
1142
+ (function(objectUtil2) {
1143
+ objectUtil2.mergeShapes = (first, second) => {
1144
+ return {
1145
+ ...first,
1146
+ ...second
1147
+ // second overwrites first
1148
+ };
1149
+ };
1150
+ })(objectUtil || (objectUtil = {}));
1141
1151
  var ZodParsedType = util.arrayToEnum([
1142
1152
  "string",
1143
1153
  "nan",
@@ -1219,7 +1229,7 @@ var ZodIssueCode = util.arrayToEnum([
1219
1229
  "not_multiple_of",
1220
1230
  "not_finite"
1221
1231
  ]);
1222
- var ZodError = class extends Error {
1232
+ var ZodError = class _ZodError extends Error {
1223
1233
  constructor(issues) {
1224
1234
  super();
1225
1235
  this.issues = [];
@@ -1277,6 +1287,11 @@ var ZodError = class extends Error {
1277
1287
  processError(this);
1278
1288
  return fieldErrors;
1279
1289
  }
1290
+ static assert(value) {
1291
+ if (!(value instanceof _ZodError)) {
1292
+ throw new Error(`Not a ZodError: ${value}`);
1293
+ }
1294
+ }
1280
1295
  toString() {
1281
1296
  return this.message;
1282
1297
  }
@@ -1343,7 +1358,12 @@ var errorMap = (issue, _ctx) => {
1343
1358
  break;
1344
1359
  case ZodIssueCode.invalid_string:
1345
1360
  if (typeof issue.validation === "object") {
1346
- if ("startsWith" in issue.validation) {
1361
+ if ("includes" in issue.validation) {
1362
+ message = `Invalid input: must include "${issue.validation.includes}"`;
1363
+ if (typeof issue.validation.position === "number") {
1364
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
1365
+ }
1366
+ } else if ("startsWith" in issue.validation) {
1347
1367
  message = `Invalid input: must start with "${issue.validation.startsWith}"`;
1348
1368
  } else if ("endsWith" in issue.validation) {
1349
1369
  message = `Invalid input: must end with "${issue.validation.endsWith}"`;
@@ -1364,7 +1384,7 @@ var errorMap = (issue, _ctx) => {
1364
1384
  else if (issue.type === "number")
1365
1385
  message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
1366
1386
  else if (issue.type === "date")
1367
- message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(issue.minimum)}`;
1387
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
1368
1388
  else
1369
1389
  message = "Invalid input";
1370
1390
  break;
@@ -1375,8 +1395,10 @@ var errorMap = (issue, _ctx) => {
1375
1395
  message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
1376
1396
  else if (issue.type === "number")
1377
1397
  message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1398
+ else if (issue.type === "bigint")
1399
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
1378
1400
  else if (issue.type === "date")
1379
- message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(issue.maximum)}`;
1401
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
1380
1402
  else
1381
1403
  message = "Invalid input";
1382
1404
  break;
@@ -1409,6 +1431,13 @@ var makeIssue = (params) => {
1409
1431
  ...issueData,
1410
1432
  path: fullPath
1411
1433
  };
1434
+ if (issueData.message !== void 0) {
1435
+ return {
1436
+ ...issueData,
1437
+ path: fullPath,
1438
+ message: issueData.message
1439
+ };
1440
+ }
1412
1441
  let errorMessage = "";
1413
1442
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
1414
1443
  for (const map of maps) {
@@ -1417,10 +1446,11 @@ var makeIssue = (params) => {
1417
1446
  return {
1418
1447
  ...issueData,
1419
1448
  path: fullPath,
1420
- message: issueData.message || errorMessage
1449
+ message: errorMessage
1421
1450
  };
1422
1451
  };
1423
1452
  function addIssueToContext(ctx, issueData) {
1453
+ const overrideMap = getErrorMap();
1424
1454
  const issue = makeIssue({
1425
1455
  issueData,
1426
1456
  data: ctx.data,
@@ -1428,8 +1458,8 @@ function addIssueToContext(ctx, issueData) {
1428
1458
  errorMaps: [
1429
1459
  ctx.common.contextualErrorMap,
1430
1460
  ctx.schemaErrorMap,
1431
- getErrorMap(),
1432
- errorMap
1461
+ overrideMap,
1462
+ overrideMap === errorMap ? void 0 : errorMap
1433
1463
  // then global default map
1434
1464
  ].filter((x) => !!x)
1435
1465
  });
@@ -1461,9 +1491,11 @@ var ParseStatus = class _ParseStatus {
1461
1491
  static async mergeObjectAsync(status, pairs) {
1462
1492
  const syncPairs = [];
1463
1493
  for (const pair of pairs) {
1494
+ const key = await pair.key;
1495
+ const value = await pair.value;
1464
1496
  syncPairs.push({
1465
- key: await pair.key,
1466
- value: await pair.value
1497
+ key,
1498
+ value
1467
1499
  });
1468
1500
  }
1469
1501
  return _ParseStatus.mergeObjectSync(status, syncPairs);
@@ -1480,7 +1512,7 @@ var ParseStatus = class _ParseStatus {
1480
1512
  status.dirty();
1481
1513
  if (value.status === "dirty")
1482
1514
  status.dirty();
1483
- if (typeof value.value !== "undefined" || pair.alwaysSet) {
1515
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
1484
1516
  finalObject[key.value] = value.value;
1485
1517
  }
1486
1518
  }
@@ -1495,21 +1527,47 @@ var OK = (value) => ({ status: "valid", value });
1495
1527
  var isAborted = (x) => x.status === "aborted";
1496
1528
  var isDirty = (x) => x.status === "dirty";
1497
1529
  var isValid = (x) => x.status === "valid";
1498
- var isAsync = (x) => typeof Promise !== void 0 && x instanceof Promise;
1530
+ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1531
+ function __classPrivateFieldGet(receiver, state, kind, f) {
1532
+ if (kind === "a" && !f)
1533
+ throw new TypeError("Private accessor was defined without a getter");
1534
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
1535
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
1536
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1537
+ }
1538
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
1539
+ if (kind === "m")
1540
+ throw new TypeError("Private method is not writable");
1541
+ if (kind === "a" && !f)
1542
+ throw new TypeError("Private accessor was defined without a setter");
1543
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
1544
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
1545
+ return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
1546
+ }
1499
1547
  var errorUtil;
1500
1548
  (function(errorUtil2) {
1501
1549
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1502
1550
  errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
1503
1551
  })(errorUtil || (errorUtil = {}));
1552
+ var _ZodEnum_cache;
1553
+ var _ZodNativeEnum_cache;
1504
1554
  var ParseInputLazyPath = class {
1505
1555
  constructor(parent, value, path, key) {
1556
+ this._cachedPath = [];
1506
1557
  this.parent = parent;
1507
1558
  this.data = value;
1508
1559
  this._path = path;
1509
1560
  this._key = key;
1510
1561
  }
1511
1562
  get path() {
1512
- return this._path.concat(this._key);
1563
+ if (!this._cachedPath.length) {
1564
+ if (this._key instanceof Array) {
1565
+ this._cachedPath.push(...this._path, ...this._key);
1566
+ } else {
1567
+ this._cachedPath.push(...this._path, this._key);
1568
+ }
1569
+ }
1570
+ return this._cachedPath;
1513
1571
  }
1514
1572
  };
1515
1573
  var handleResult = (ctx, result) => {
@@ -1519,8 +1577,16 @@ var handleResult = (ctx, result) => {
1519
1577
  if (!ctx.common.issues.length) {
1520
1578
  throw new Error("Validation failed but no issues detected.");
1521
1579
  }
1522
- const error = new ZodError(ctx.common.issues);
1523
- return { success: false, error };
1580
+ return {
1581
+ success: false,
1582
+ get error() {
1583
+ if (this._error)
1584
+ return this._error;
1585
+ const error = new ZodError(ctx.common.issues);
1586
+ this._error = error;
1587
+ return this._error;
1588
+ }
1589
+ };
1524
1590
  }
1525
1591
  };
1526
1592
  function processCreateParams(params) {
@@ -1533,12 +1599,17 @@ function processCreateParams(params) {
1533
1599
  if (errorMap2)
1534
1600
  return { errorMap: errorMap2, description };
1535
1601
  const customMap = (iss, ctx) => {
1536
- if (iss.code !== "invalid_type")
1537
- return { message: ctx.defaultError };
1602
+ var _a, _b;
1603
+ const { message } = params;
1604
+ if (iss.code === "invalid_enum_value") {
1605
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
1606
+ }
1538
1607
  if (typeof ctx.data === "undefined") {
1539
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
1608
+ return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
1540
1609
  }
1541
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
1610
+ if (iss.code !== "invalid_type")
1611
+ return { message: ctx.defaultError };
1612
+ return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
1542
1613
  };
1543
1614
  return { errorMap: customMap, description };
1544
1615
  }
@@ -1567,6 +1638,7 @@ var ZodType = class {
1567
1638
  this.catch = this.catch.bind(this);
1568
1639
  this.describe = this.describe.bind(this);
1569
1640
  this.pipe = this.pipe.bind(this);
1641
+ this.readonly = this.readonly.bind(this);
1570
1642
  this.isNullable = this.isNullable.bind(this);
1571
1643
  this.isOptional = this.isOptional.bind(this);
1572
1644
  }
@@ -1711,28 +1783,29 @@ var ZodType = class {
1711
1783
  return this._refinement(refinement);
1712
1784
  }
1713
1785
  optional() {
1714
- return ZodOptional.create(this);
1786
+ return ZodOptional.create(this, this._def);
1715
1787
  }
1716
1788
  nullable() {
1717
- return ZodNullable.create(this);
1789
+ return ZodNullable.create(this, this._def);
1718
1790
  }
1719
1791
  nullish() {
1720
- return this.optional().nullable();
1792
+ return this.nullable().optional();
1721
1793
  }
1722
1794
  array() {
1723
- return ZodArray.create(this);
1795
+ return ZodArray.create(this, this._def);
1724
1796
  }
1725
1797
  promise() {
1726
- return ZodPromise.create(this);
1798
+ return ZodPromise.create(this, this._def);
1727
1799
  }
1728
1800
  or(option) {
1729
- return ZodUnion.create([this, option]);
1801
+ return ZodUnion.create([this, option], this._def);
1730
1802
  }
1731
1803
  and(incoming) {
1732
- return ZodIntersection.create(this, incoming);
1804
+ return ZodIntersection.create(this, incoming, this._def);
1733
1805
  }
1734
1806
  transform(transform) {
1735
1807
  return new ZodEffects({
1808
+ ...processCreateParams(this._def),
1736
1809
  schema: this,
1737
1810
  typeName: ZodFirstPartyTypeKind.ZodEffects,
1738
1811
  effect: { type: "transform", transform }
@@ -1741,6 +1814,7 @@ var ZodType = class {
1741
1814
  default(def) {
1742
1815
  const defaultValueFunc = typeof def === "function" ? def : () => def;
1743
1816
  return new ZodDefault({
1817
+ ...processCreateParams(this._def),
1744
1818
  innerType: this,
1745
1819
  defaultValue: defaultValueFunc,
1746
1820
  typeName: ZodFirstPartyTypeKind.ZodDefault
@@ -1750,14 +1824,15 @@ var ZodType = class {
1750
1824
  return new ZodBranded({
1751
1825
  typeName: ZodFirstPartyTypeKind.ZodBranded,
1752
1826
  type: this,
1753
- ...processCreateParams(void 0)
1827
+ ...processCreateParams(this._def)
1754
1828
  });
1755
1829
  }
1756
1830
  catch(def) {
1757
- const defaultValueFunc = typeof def === "function" ? def : () => def;
1831
+ const catchValueFunc = typeof def === "function" ? def : () => def;
1758
1832
  return new ZodCatch({
1833
+ ...processCreateParams(this._def),
1759
1834
  innerType: this,
1760
- defaultValue: defaultValueFunc,
1835
+ catchValue: catchValueFunc,
1761
1836
  typeName: ZodFirstPartyTypeKind.ZodCatch
1762
1837
  });
1763
1838
  }
@@ -1771,6 +1846,9 @@ var ZodType = class {
1771
1846
  pipe(target) {
1772
1847
  return ZodPipeline.create(this, target);
1773
1848
  }
1849
+ readonly() {
1850
+ return ZodReadonly.create(this);
1851
+ }
1774
1852
  isOptional() {
1775
1853
  return this.safeParse(void 0).success;
1776
1854
  }
@@ -1779,43 +1857,50 @@ var ZodType = class {
1779
1857
  }
1780
1858
  };
1781
1859
  var cuidRegex = /^c[^\s-]{8,}$/i;
1782
- 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;
1783
- var emailRegex = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
1784
- var datetimeRegex = (args) => {
1860
+ var cuid2Regex = /^[0-9a-z]+$/;
1861
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
1862
+ 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;
1863
+ var nanoidRegex = /^[a-z0-9_-]{21}$/i;
1864
+ 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)?)??$/;
1865
+ var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1866
+ var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1867
+ var emojiRegex;
1868
+ 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])$/;
1869
+ 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})))$/;
1870
+ var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
1871
+ 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])))`;
1872
+ var dateRegex = new RegExp(`^${dateRegexSource}$`);
1873
+ function timeRegexSource(args) {
1874
+ let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
1785
1875
  if (args.precision) {
1786
- if (args.offset) {
1787
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}:\\d{2})|Z)$`);
1788
- } else {
1789
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
1790
- }
1791
- } else if (args.precision === 0) {
1792
- if (args.offset) {
1793
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}:\\d{2})|Z)$`);
1794
- } else {
1795
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
1796
- }
1797
- } else {
1798
- if (args.offset) {
1799
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}:\\d{2})|Z)$`);
1800
- } else {
1801
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
1802
- }
1876
+ regex = `${regex}\\.\\d{${args.precision}}`;
1877
+ } else if (args.precision == null) {
1878
+ regex = `${regex}(\\.\\d+)?`;
1803
1879
  }
1804
- };
1805
- var ZodString = class _ZodString extends ZodType {
1806
- constructor() {
1807
- super(...arguments);
1808
- this._regex = (regex, validation, message) => this.refinement((data) => regex.test(data), {
1809
- validation,
1810
- code: ZodIssueCode.invalid_string,
1811
- ...errorUtil.errToObj(message)
1812
- });
1813
- this.nonempty = (message) => this.min(1, errorUtil.errToObj(message));
1814
- this.trim = () => new _ZodString({
1815
- ...this._def,
1816
- checks: [...this._def.checks, { kind: "trim" }]
1817
- });
1880
+ return regex;
1881
+ }
1882
+ function timeRegex(args) {
1883
+ return new RegExp(`^${timeRegexSource(args)}$`);
1884
+ }
1885
+ function datetimeRegex(args) {
1886
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
1887
+ const opts = [];
1888
+ opts.push(args.local ? `Z?` : `Z`);
1889
+ if (args.offset)
1890
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
1891
+ regex = `${regex}(${opts.join("|")})`;
1892
+ return new RegExp(`^${regex}$`);
1893
+ }
1894
+ function isValidIP(ip, version) {
1895
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1896
+ return true;
1818
1897
  }
1898
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
1899
+ return true;
1900
+ }
1901
+ return false;
1902
+ }
1903
+ var ZodString = class _ZodString extends ZodType {
1819
1904
  _parse(input) {
1820
1905
  if (this._def.coerce) {
1821
1906
  input.data = String(input.data);
@@ -1823,15 +1908,11 @@ var ZodString = class _ZodString extends ZodType {
1823
1908
  const parsedType = this._getType(input);
1824
1909
  if (parsedType !== ZodParsedType.string) {
1825
1910
  const ctx2 = this._getOrReturnCtx(input);
1826
- addIssueToContext(
1827
- ctx2,
1828
- {
1829
- code: ZodIssueCode.invalid_type,
1830
- expected: ZodParsedType.string,
1831
- received: ctx2.parsedType
1832
- }
1833
- //
1834
- );
1911
+ addIssueToContext(ctx2, {
1912
+ code: ZodIssueCode.invalid_type,
1913
+ expected: ZodParsedType.string,
1914
+ received: ctx2.parsedType
1915
+ });
1835
1916
  return INVALID;
1836
1917
  }
1837
1918
  const status = new ParseStatus();
@@ -1899,6 +1980,19 @@ var ZodString = class _ZodString extends ZodType {
1899
1980
  });
1900
1981
  status.dirty();
1901
1982
  }
1983
+ } else if (check.kind === "emoji") {
1984
+ if (!emojiRegex) {
1985
+ emojiRegex = new RegExp(_emojiRegex, "u");
1986
+ }
1987
+ if (!emojiRegex.test(input.data)) {
1988
+ ctx = this._getOrReturnCtx(input, ctx);
1989
+ addIssueToContext(ctx, {
1990
+ validation: "emoji",
1991
+ code: ZodIssueCode.invalid_string,
1992
+ message: check.message
1993
+ });
1994
+ status.dirty();
1995
+ }
1902
1996
  } else if (check.kind === "uuid") {
1903
1997
  if (!uuidRegex.test(input.data)) {
1904
1998
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1909,6 +2003,16 @@ var ZodString = class _ZodString extends ZodType {
1909
2003
  });
1910
2004
  status.dirty();
1911
2005
  }
2006
+ } else if (check.kind === "nanoid") {
2007
+ if (!nanoidRegex.test(input.data)) {
2008
+ ctx = this._getOrReturnCtx(input, ctx);
2009
+ addIssueToContext(ctx, {
2010
+ validation: "nanoid",
2011
+ code: ZodIssueCode.invalid_string,
2012
+ message: check.message
2013
+ });
2014
+ status.dirty();
2015
+ }
1912
2016
  } else if (check.kind === "cuid") {
1913
2017
  if (!cuidRegex.test(input.data)) {
1914
2018
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1919,6 +2023,26 @@ var ZodString = class _ZodString extends ZodType {
1919
2023
  });
1920
2024
  status.dirty();
1921
2025
  }
2026
+ } else if (check.kind === "cuid2") {
2027
+ if (!cuid2Regex.test(input.data)) {
2028
+ ctx = this._getOrReturnCtx(input, ctx);
2029
+ addIssueToContext(ctx, {
2030
+ validation: "cuid2",
2031
+ code: ZodIssueCode.invalid_string,
2032
+ message: check.message
2033
+ });
2034
+ status.dirty();
2035
+ }
2036
+ } else if (check.kind === "ulid") {
2037
+ if (!ulidRegex.test(input.data)) {
2038
+ ctx = this._getOrReturnCtx(input, ctx);
2039
+ addIssueToContext(ctx, {
2040
+ validation: "ulid",
2041
+ code: ZodIssueCode.invalid_string,
2042
+ message: check.message
2043
+ });
2044
+ status.dirty();
2045
+ }
1922
2046
  } else if (check.kind === "url") {
1923
2047
  try {
1924
2048
  new URL(input.data);
@@ -1945,6 +2069,20 @@ var ZodString = class _ZodString extends ZodType {
1945
2069
  }
1946
2070
  } else if (check.kind === "trim") {
1947
2071
  input.data = input.data.trim();
2072
+ } else if (check.kind === "includes") {
2073
+ if (!input.data.includes(check.value, check.position)) {
2074
+ ctx = this._getOrReturnCtx(input, ctx);
2075
+ addIssueToContext(ctx, {
2076
+ code: ZodIssueCode.invalid_string,
2077
+ validation: { includes: check.value, position: check.position },
2078
+ message: check.message
2079
+ });
2080
+ status.dirty();
2081
+ }
2082
+ } else if (check.kind === "toLowerCase") {
2083
+ input.data = input.data.toLowerCase();
2084
+ } else if (check.kind === "toUpperCase") {
2085
+ input.data = input.data.toUpperCase();
1948
2086
  } else if (check.kind === "startsWith") {
1949
2087
  if (!input.data.startsWith(check.value)) {
1950
2088
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1976,12 +2114,71 @@ var ZodString = class _ZodString extends ZodType {
1976
2114
  });
1977
2115
  status.dirty();
1978
2116
  }
2117
+ } else if (check.kind === "date") {
2118
+ const regex = dateRegex;
2119
+ if (!regex.test(input.data)) {
2120
+ ctx = this._getOrReturnCtx(input, ctx);
2121
+ addIssueToContext(ctx, {
2122
+ code: ZodIssueCode.invalid_string,
2123
+ validation: "date",
2124
+ message: check.message
2125
+ });
2126
+ status.dirty();
2127
+ }
2128
+ } else if (check.kind === "time") {
2129
+ const regex = timeRegex(check);
2130
+ if (!regex.test(input.data)) {
2131
+ ctx = this._getOrReturnCtx(input, ctx);
2132
+ addIssueToContext(ctx, {
2133
+ code: ZodIssueCode.invalid_string,
2134
+ validation: "time",
2135
+ message: check.message
2136
+ });
2137
+ status.dirty();
2138
+ }
2139
+ } else if (check.kind === "duration") {
2140
+ if (!durationRegex.test(input.data)) {
2141
+ ctx = this._getOrReturnCtx(input, ctx);
2142
+ addIssueToContext(ctx, {
2143
+ validation: "duration",
2144
+ code: ZodIssueCode.invalid_string,
2145
+ message: check.message
2146
+ });
2147
+ status.dirty();
2148
+ }
2149
+ } else if (check.kind === "ip") {
2150
+ if (!isValidIP(input.data, check.version)) {
2151
+ ctx = this._getOrReturnCtx(input, ctx);
2152
+ addIssueToContext(ctx, {
2153
+ validation: "ip",
2154
+ code: ZodIssueCode.invalid_string,
2155
+ message: check.message
2156
+ });
2157
+ status.dirty();
2158
+ }
2159
+ } else if (check.kind === "base64") {
2160
+ if (!base64Regex.test(input.data)) {
2161
+ ctx = this._getOrReturnCtx(input, ctx);
2162
+ addIssueToContext(ctx, {
2163
+ validation: "base64",
2164
+ code: ZodIssueCode.invalid_string,
2165
+ message: check.message
2166
+ });
2167
+ status.dirty();
2168
+ }
1979
2169
  } else {
1980
2170
  util.assertNever(check);
1981
2171
  }
1982
2172
  }
1983
2173
  return { status: status.value, value: input.data };
1984
2174
  }
2175
+ _regex(regex, validation, message) {
2176
+ return this.refinement((data) => regex.test(data), {
2177
+ validation,
2178
+ code: ZodIssueCode.invalid_string,
2179
+ ...errorUtil.errToObj(message)
2180
+ });
2181
+ }
1985
2182
  _addCheck(check) {
1986
2183
  return new _ZodString({
1987
2184
  ...this._def,
@@ -1994,19 +2191,38 @@ var ZodString = class _ZodString extends ZodType {
1994
2191
  url(message) {
1995
2192
  return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1996
2193
  }
2194
+ emoji(message) {
2195
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
2196
+ }
1997
2197
  uuid(message) {
1998
2198
  return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1999
2199
  }
2200
+ nanoid(message) {
2201
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
2202
+ }
2000
2203
  cuid(message) {
2001
2204
  return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
2002
2205
  }
2206
+ cuid2(message) {
2207
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
2208
+ }
2209
+ ulid(message) {
2210
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
2211
+ }
2212
+ base64(message) {
2213
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
2214
+ }
2215
+ ip(options) {
2216
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
2217
+ }
2003
2218
  datetime(options) {
2004
- var _a;
2219
+ var _a, _b;
2005
2220
  if (typeof options === "string") {
2006
2221
  return this._addCheck({
2007
2222
  kind: "datetime",
2008
2223
  precision: null,
2009
2224
  offset: false,
2225
+ local: false,
2010
2226
  message: options
2011
2227
  });
2012
2228
  }
@@ -2014,9 +2230,30 @@ var ZodString = class _ZodString extends ZodType {
2014
2230
  kind: "datetime",
2015
2231
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2016
2232
  offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
2233
+ local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
2234
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2235
+ });
2236
+ }
2237
+ date(message) {
2238
+ return this._addCheck({ kind: "date", message });
2239
+ }
2240
+ time(options) {
2241
+ if (typeof options === "string") {
2242
+ return this._addCheck({
2243
+ kind: "time",
2244
+ precision: null,
2245
+ message: options
2246
+ });
2247
+ }
2248
+ return this._addCheck({
2249
+ kind: "time",
2250
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
2017
2251
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2018
2252
  });
2019
2253
  }
2254
+ duration(message) {
2255
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
2256
+ }
2020
2257
  regex(regex, message) {
2021
2258
  return this._addCheck({
2022
2259
  kind: "regex",
@@ -2024,6 +2261,14 @@ var ZodString = class _ZodString extends ZodType {
2024
2261
  ...errorUtil.errToObj(message)
2025
2262
  });
2026
2263
  }
2264
+ includes(value, options) {
2265
+ return this._addCheck({
2266
+ kind: "includes",
2267
+ value,
2268
+ position: options === null || options === void 0 ? void 0 : options.position,
2269
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
2270
+ });
2271
+ }
2027
2272
  startsWith(value, message) {
2028
2273
  return this._addCheck({
2029
2274
  kind: "startsWith",
@@ -2059,21 +2304,73 @@ var ZodString = class _ZodString extends ZodType {
2059
2304
  ...errorUtil.errToObj(message)
2060
2305
  });
2061
2306
  }
2307
+ /**
2308
+ * @deprecated Use z.string().min(1) instead.
2309
+ * @see {@link ZodString.min}
2310
+ */
2311
+ nonempty(message) {
2312
+ return this.min(1, errorUtil.errToObj(message));
2313
+ }
2314
+ trim() {
2315
+ return new _ZodString({
2316
+ ...this._def,
2317
+ checks: [...this._def.checks, { kind: "trim" }]
2318
+ });
2319
+ }
2320
+ toLowerCase() {
2321
+ return new _ZodString({
2322
+ ...this._def,
2323
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
2324
+ });
2325
+ }
2326
+ toUpperCase() {
2327
+ return new _ZodString({
2328
+ ...this._def,
2329
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
2330
+ });
2331
+ }
2062
2332
  get isDatetime() {
2063
2333
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
2064
2334
  }
2335
+ get isDate() {
2336
+ return !!this._def.checks.find((ch) => ch.kind === "date");
2337
+ }
2338
+ get isTime() {
2339
+ return !!this._def.checks.find((ch) => ch.kind === "time");
2340
+ }
2341
+ get isDuration() {
2342
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
2343
+ }
2065
2344
  get isEmail() {
2066
2345
  return !!this._def.checks.find((ch) => ch.kind === "email");
2067
2346
  }
2068
2347
  get isURL() {
2069
2348
  return !!this._def.checks.find((ch) => ch.kind === "url");
2070
2349
  }
2350
+ get isEmoji() {
2351
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
2352
+ }
2071
2353
  get isUUID() {
2072
2354
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
2073
2355
  }
2356
+ get isNANOID() {
2357
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
2358
+ }
2074
2359
  get isCUID() {
2075
2360
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
2076
2361
  }
2362
+ get isCUID2() {
2363
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
2364
+ }
2365
+ get isULID() {
2366
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
2367
+ }
2368
+ get isIP() {
2369
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
2370
+ }
2371
+ get isBase64() {
2372
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
2373
+ }
2077
2374
  get minLength() {
2078
2375
  let min = null;
2079
2376
  for (const ch of this._def.checks) {
@@ -2283,6 +2580,19 @@ var ZodNumber = class _ZodNumber extends ZodType {
2283
2580
  message: errorUtil.toString(message)
2284
2581
  });
2285
2582
  }
2583
+ safe(message) {
2584
+ return this._addCheck({
2585
+ kind: "min",
2586
+ inclusive: true,
2587
+ value: Number.MIN_SAFE_INTEGER,
2588
+ message: errorUtil.toString(message)
2589
+ })._addCheck({
2590
+ kind: "max",
2591
+ inclusive: true,
2592
+ value: Number.MAX_SAFE_INTEGER,
2593
+ message: errorUtil.toString(message)
2594
+ });
2595
+ }
2286
2596
  get minValue() {
2287
2597
  let min = null;
2288
2598
  for (const ch of this._def.checks) {
@@ -2304,7 +2614,22 @@ var ZodNumber = class _ZodNumber extends ZodType {
2304
2614
  return max;
2305
2615
  }
2306
2616
  get isInt() {
2307
- return !!this._def.checks.find((ch) => ch.kind === "int");
2617
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
2618
+ }
2619
+ get isFinite() {
2620
+ let max = null, min = null;
2621
+ for (const ch of this._def.checks) {
2622
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
2623
+ return true;
2624
+ } else if (ch.kind === "min") {
2625
+ if (min === null || ch.value > min)
2626
+ min = ch.value;
2627
+ } else if (ch.kind === "max") {
2628
+ if (max === null || ch.value < max)
2629
+ max = ch.value;
2630
+ }
2631
+ }
2632
+ return Number.isFinite(min) && Number.isFinite(max);
2308
2633
  }
2309
2634
  };
2310
2635
  ZodNumber.create = (params) => {
@@ -2315,27 +2640,167 @@ ZodNumber.create = (params) => {
2315
2640
  ...processCreateParams(params)
2316
2641
  });
2317
2642
  };
2318
- var ZodBigInt = class extends ZodType {
2643
+ var ZodBigInt = class _ZodBigInt extends ZodType {
2644
+ constructor() {
2645
+ super(...arguments);
2646
+ this.min = this.gte;
2647
+ this.max = this.lte;
2648
+ }
2319
2649
  _parse(input) {
2320
2650
  if (this._def.coerce) {
2321
2651
  input.data = BigInt(input.data);
2322
2652
  }
2323
2653
  const parsedType = this._getType(input);
2324
2654
  if (parsedType !== ZodParsedType.bigint) {
2325
- const ctx = this._getOrReturnCtx(input);
2326
- addIssueToContext(ctx, {
2655
+ const ctx2 = this._getOrReturnCtx(input);
2656
+ addIssueToContext(ctx2, {
2327
2657
  code: ZodIssueCode.invalid_type,
2328
2658
  expected: ZodParsedType.bigint,
2329
- received: ctx.parsedType
2659
+ received: ctx2.parsedType
2330
2660
  });
2331
2661
  return INVALID;
2332
2662
  }
2333
- return OK(input.data);
2663
+ let ctx = void 0;
2664
+ const status = new ParseStatus();
2665
+ for (const check of this._def.checks) {
2666
+ if (check.kind === "min") {
2667
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
2668
+ if (tooSmall) {
2669
+ ctx = this._getOrReturnCtx(input, ctx);
2670
+ addIssueToContext(ctx, {
2671
+ code: ZodIssueCode.too_small,
2672
+ type: "bigint",
2673
+ minimum: check.value,
2674
+ inclusive: check.inclusive,
2675
+ message: check.message
2676
+ });
2677
+ status.dirty();
2678
+ }
2679
+ } else if (check.kind === "max") {
2680
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
2681
+ if (tooBig) {
2682
+ ctx = this._getOrReturnCtx(input, ctx);
2683
+ addIssueToContext(ctx, {
2684
+ code: ZodIssueCode.too_big,
2685
+ type: "bigint",
2686
+ maximum: check.value,
2687
+ inclusive: check.inclusive,
2688
+ message: check.message
2689
+ });
2690
+ status.dirty();
2691
+ }
2692
+ } else if (check.kind === "multipleOf") {
2693
+ if (input.data % check.value !== BigInt(0)) {
2694
+ ctx = this._getOrReturnCtx(input, ctx);
2695
+ addIssueToContext(ctx, {
2696
+ code: ZodIssueCode.not_multiple_of,
2697
+ multipleOf: check.value,
2698
+ message: check.message
2699
+ });
2700
+ status.dirty();
2701
+ }
2702
+ } else {
2703
+ util.assertNever(check);
2704
+ }
2705
+ }
2706
+ return { status: status.value, value: input.data };
2707
+ }
2708
+ gte(value, message) {
2709
+ return this.setLimit("min", value, true, errorUtil.toString(message));
2710
+ }
2711
+ gt(value, message) {
2712
+ return this.setLimit("min", value, false, errorUtil.toString(message));
2713
+ }
2714
+ lte(value, message) {
2715
+ return this.setLimit("max", value, true, errorUtil.toString(message));
2716
+ }
2717
+ lt(value, message) {
2718
+ return this.setLimit("max", value, false, errorUtil.toString(message));
2719
+ }
2720
+ setLimit(kind, value, inclusive, message) {
2721
+ return new _ZodBigInt({
2722
+ ...this._def,
2723
+ checks: [
2724
+ ...this._def.checks,
2725
+ {
2726
+ kind,
2727
+ value,
2728
+ inclusive,
2729
+ message: errorUtil.toString(message)
2730
+ }
2731
+ ]
2732
+ });
2733
+ }
2734
+ _addCheck(check) {
2735
+ return new _ZodBigInt({
2736
+ ...this._def,
2737
+ checks: [...this._def.checks, check]
2738
+ });
2739
+ }
2740
+ positive(message) {
2741
+ return this._addCheck({
2742
+ kind: "min",
2743
+ value: BigInt(0),
2744
+ inclusive: false,
2745
+ message: errorUtil.toString(message)
2746
+ });
2747
+ }
2748
+ negative(message) {
2749
+ return this._addCheck({
2750
+ kind: "max",
2751
+ value: BigInt(0),
2752
+ inclusive: false,
2753
+ message: errorUtil.toString(message)
2754
+ });
2755
+ }
2756
+ nonpositive(message) {
2757
+ return this._addCheck({
2758
+ kind: "max",
2759
+ value: BigInt(0),
2760
+ inclusive: true,
2761
+ message: errorUtil.toString(message)
2762
+ });
2763
+ }
2764
+ nonnegative(message) {
2765
+ return this._addCheck({
2766
+ kind: "min",
2767
+ value: BigInt(0),
2768
+ inclusive: true,
2769
+ message: errorUtil.toString(message)
2770
+ });
2771
+ }
2772
+ multipleOf(value, message) {
2773
+ return this._addCheck({
2774
+ kind: "multipleOf",
2775
+ value,
2776
+ message: errorUtil.toString(message)
2777
+ });
2778
+ }
2779
+ get minValue() {
2780
+ let min = null;
2781
+ for (const ch of this._def.checks) {
2782
+ if (ch.kind === "min") {
2783
+ if (min === null || ch.value > min)
2784
+ min = ch.value;
2785
+ }
2786
+ }
2787
+ return min;
2788
+ }
2789
+ get maxValue() {
2790
+ let max = null;
2791
+ for (const ch of this._def.checks) {
2792
+ if (ch.kind === "max") {
2793
+ if (max === null || ch.value < max)
2794
+ max = ch.value;
2795
+ }
2796
+ }
2797
+ return max;
2334
2798
  }
2335
2799
  };
2336
2800
  ZodBigInt.create = (params) => {
2337
2801
  var _a;
2338
2802
  return new ZodBigInt({
2803
+ checks: [],
2339
2804
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2340
2805
  coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
2341
2806
  ...processCreateParams(params)
@@ -2661,13 +3126,13 @@ var ZodArray = class _ZodArray extends ZodType {
2661
3126
  }
2662
3127
  }
2663
3128
  if (ctx.common.async) {
2664
- return Promise.all(ctx.data.map((item, i) => {
3129
+ return Promise.all([...ctx.data].map((item, i) => {
2665
3130
  return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2666
3131
  })).then((result2) => {
2667
3132
  return ParseStatus.mergeArray(status, result2);
2668
3133
  });
2669
3134
  }
2670
- const result = ctx.data.map((item, i) => {
3135
+ const result = [...ctx.data].map((item, i) => {
2671
3136
  return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
2672
3137
  });
2673
3138
  return ParseStatus.mergeArray(status, result);
@@ -2707,25 +3172,6 @@ ZodArray.create = (schema3, params) => {
2707
3172
  ...processCreateParams(params)
2708
3173
  });
2709
3174
  };
2710
- var objectUtil;
2711
- (function(objectUtil2) {
2712
- objectUtil2.mergeShapes = (first, second) => {
2713
- return {
2714
- ...first,
2715
- ...second
2716
- // second overwrites first
2717
- };
2718
- };
2719
- })(objectUtil || (objectUtil = {}));
2720
- var AugmentFactory = (def) => (augmentation) => {
2721
- return new ZodObject({
2722
- ...def,
2723
- shape: () => ({
2724
- ...def.shape(),
2725
- ...augmentation
2726
- })
2727
- });
2728
- };
2729
3175
  function deepPartialify(schema3) {
2730
3176
  if (schema3 instanceof ZodObject) {
2731
3177
  const newShape = {};
@@ -2738,7 +3184,10 @@ function deepPartialify(schema3) {
2738
3184
  shape: () => newShape
2739
3185
  });
2740
3186
  } else if (schema3 instanceof ZodArray) {
2741
- return ZodArray.create(deepPartialify(schema3.element));
3187
+ return new ZodArray({
3188
+ ...schema3._def,
3189
+ type: deepPartialify(schema3.element)
3190
+ });
2742
3191
  } else if (schema3 instanceof ZodOptional) {
2743
3192
  return ZodOptional.create(deepPartialify(schema3.unwrap()));
2744
3193
  } else if (schema3 instanceof ZodNullable) {
@@ -2754,8 +3203,7 @@ var ZodObject = class _ZodObject extends ZodType {
2754
3203
  super(...arguments);
2755
3204
  this._cached = null;
2756
3205
  this.nonstrict = this.passthrough;
2757
- this.augment = AugmentFactory(this._def);
2758
- this.extend = AugmentFactory(this._def);
3206
+ this.augment = this.extend;
2759
3207
  }
2760
3208
  _getCached() {
2761
3209
  if (this._cached !== null)
@@ -2836,9 +3284,10 @@ var ZodObject = class _ZodObject extends ZodType {
2836
3284
  const syncPairs = [];
2837
3285
  for (const pair of pairs) {
2838
3286
  const key = await pair.key;
3287
+ const value = await pair.value;
2839
3288
  syncPairs.push({
2840
3289
  key,
2841
- value: await pair.value,
3290
+ value,
2842
3291
  alwaysSet: pair.alwaysSet
2843
3292
  });
2844
3293
  }
@@ -2885,8 +3334,31 @@ var ZodObject = class _ZodObject extends ZodType {
2885
3334
  unknownKeys: "passthrough"
2886
3335
  });
2887
3336
  }
2888
- setKey(key, schema3) {
2889
- return this.augment({ [key]: schema3 });
3337
+ // const AugmentFactory =
3338
+ // <Def extends ZodObjectDef>(def: Def) =>
3339
+ // <Augmentation extends ZodRawShape>(
3340
+ // augmentation: Augmentation
3341
+ // ): ZodObject<
3342
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
3343
+ // Def["unknownKeys"],
3344
+ // Def["catchall"]
3345
+ // > => {
3346
+ // return new ZodObject({
3347
+ // ...def,
3348
+ // shape: () => ({
3349
+ // ...def.shape(),
3350
+ // ...augmentation,
3351
+ // }),
3352
+ // }) as any;
3353
+ // };
3354
+ extend(augmentation) {
3355
+ return new _ZodObject({
3356
+ ...this._def,
3357
+ shape: () => ({
3358
+ ...this._def.shape(),
3359
+ ...augmentation
3360
+ })
3361
+ });
2890
3362
  }
2891
3363
  /**
2892
3364
  * Prior to zod@1.0.12 there was a bug in the
@@ -2897,11 +3369,73 @@ var ZodObject = class _ZodObject extends ZodType {
2897
3369
  const merged = new _ZodObject({
2898
3370
  unknownKeys: merging._def.unknownKeys,
2899
3371
  catchall: merging._def.catchall,
2900
- shape: () => objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3372
+ shape: () => ({
3373
+ ...this._def.shape(),
3374
+ ...merging._def.shape()
3375
+ }),
2901
3376
  typeName: ZodFirstPartyTypeKind.ZodObject
2902
3377
  });
2903
3378
  return merged;
2904
3379
  }
3380
+ // merge<
3381
+ // Incoming extends AnyZodObject,
3382
+ // Augmentation extends Incoming["shape"],
3383
+ // NewOutput extends {
3384
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
3385
+ // ? Augmentation[k]["_output"]
3386
+ // : k extends keyof Output
3387
+ // ? Output[k]
3388
+ // : never;
3389
+ // },
3390
+ // NewInput extends {
3391
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
3392
+ // ? Augmentation[k]["_input"]
3393
+ // : k extends keyof Input
3394
+ // ? Input[k]
3395
+ // : never;
3396
+ // }
3397
+ // >(
3398
+ // merging: Incoming
3399
+ // ): ZodObject<
3400
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3401
+ // Incoming["_def"]["unknownKeys"],
3402
+ // Incoming["_def"]["catchall"],
3403
+ // NewOutput,
3404
+ // NewInput
3405
+ // > {
3406
+ // const merged: any = new ZodObject({
3407
+ // unknownKeys: merging._def.unknownKeys,
3408
+ // catchall: merging._def.catchall,
3409
+ // shape: () =>
3410
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3411
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3412
+ // }) as any;
3413
+ // return merged;
3414
+ // }
3415
+ setKey(key, schema3) {
3416
+ return this.augment({ [key]: schema3 });
3417
+ }
3418
+ // merge<Incoming extends AnyZodObject>(
3419
+ // merging: Incoming
3420
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
3421
+ // ZodObject<
3422
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
3423
+ // Incoming["_def"]["unknownKeys"],
3424
+ // Incoming["_def"]["catchall"]
3425
+ // > {
3426
+ // // const mergedShape = objectUtil.mergeShapes(
3427
+ // // this._def.shape(),
3428
+ // // merging._def.shape()
3429
+ // // );
3430
+ // const merged: any = new ZodObject({
3431
+ // unknownKeys: merging._def.unknownKeys,
3432
+ // catchall: merging._def.catchall,
3433
+ // shape: () =>
3434
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
3435
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
3436
+ // }) as any;
3437
+ // return merged;
3438
+ // }
2905
3439
  catchall(index4) {
2906
3440
  return new _ZodObject({
2907
3441
  ...this._def,
@@ -2910,9 +3444,10 @@ var ZodObject = class _ZodObject extends ZodType {
2910
3444
  }
2911
3445
  pick(mask) {
2912
3446
  const shape = {};
2913
- util.objectKeys(mask).map((key) => {
2914
- if (this.shape[key])
3447
+ util.objectKeys(mask).forEach((key) => {
3448
+ if (mask[key] && this.shape[key]) {
2915
3449
  shape[key] = this.shape[key];
3450
+ }
2916
3451
  });
2917
3452
  return new _ZodObject({
2918
3453
  ...this._def,
@@ -2921,8 +3456,8 @@ var ZodObject = class _ZodObject extends ZodType {
2921
3456
  }
2922
3457
  omit(mask) {
2923
3458
  const shape = {};
2924
- util.objectKeys(this.shape).map((key) => {
2925
- if (util.objectKeys(mask).indexOf(key) === -1) {
3459
+ util.objectKeys(this.shape).forEach((key) => {
3460
+ if (!mask[key]) {
2926
3461
  shape[key] = this.shape[key];
2927
3462
  }
2928
3463
  });
@@ -2931,29 +3466,22 @@ var ZodObject = class _ZodObject extends ZodType {
2931
3466
  shape: () => shape
2932
3467
  });
2933
3468
  }
3469
+ /**
3470
+ * @deprecated
3471
+ */
2934
3472
  deepPartial() {
2935
3473
  return deepPartialify(this);
2936
3474
  }
2937
3475
  partial(mask) {
2938
3476
  const newShape = {};
2939
- if (mask) {
2940
- util.objectKeys(this.shape).map((key) => {
2941
- if (util.objectKeys(mask).indexOf(key) === -1) {
2942
- newShape[key] = this.shape[key];
2943
- } else {
2944
- newShape[key] = this.shape[key].optional();
2945
- }
2946
- });
2947
- return new _ZodObject({
2948
- ...this._def,
2949
- shape: () => newShape
2950
- });
2951
- } else {
2952
- for (const key in this.shape) {
2953
- const fieldSchema = this.shape[key];
3477
+ util.objectKeys(this.shape).forEach((key) => {
3478
+ const fieldSchema = this.shape[key];
3479
+ if (mask && !mask[key]) {
3480
+ newShape[key] = fieldSchema;
3481
+ } else {
2954
3482
  newShape[key] = fieldSchema.optional();
2955
3483
  }
2956
- }
3484
+ });
2957
3485
  return new _ZodObject({
2958
3486
  ...this._def,
2959
3487
  shape: () => newShape
@@ -2961,21 +3489,10 @@ var ZodObject = class _ZodObject extends ZodType {
2961
3489
  }
2962
3490
  required(mask) {
2963
3491
  const newShape = {};
2964
- if (mask) {
2965
- util.objectKeys(this.shape).map((key) => {
2966
- if (util.objectKeys(mask).indexOf(key) === -1) {
2967
- newShape[key] = this.shape[key];
2968
- } else {
2969
- const fieldSchema = this.shape[key];
2970
- let newField = fieldSchema;
2971
- while (newField instanceof ZodOptional) {
2972
- newField = newField._def.innerType;
2973
- }
2974
- newShape[key] = newField;
2975
- }
2976
- });
2977
- } else {
2978
- for (const key in this.shape) {
3492
+ util.objectKeys(this.shape).forEach((key) => {
3493
+ if (mask && !mask[key]) {
3494
+ newShape[key] = this.shape[key];
3495
+ } else {
2979
3496
  const fieldSchema = this.shape[key];
2980
3497
  let newField = fieldSchema;
2981
3498
  while (newField instanceof ZodOptional) {
@@ -2983,7 +3500,7 @@ var ZodObject = class _ZodObject extends ZodType {
2983
3500
  }
2984
3501
  newShape[key] = newField;
2985
3502
  }
2986
- }
3503
+ });
2987
3504
  return new _ZodObject({
2988
3505
  ...this._def,
2989
3506
  shape: () => newShape
@@ -3121,15 +3638,25 @@ var getDiscriminator = (type) => {
3121
3638
  } else if (type instanceof ZodEnum) {
3122
3639
  return type.options;
3123
3640
  } else if (type instanceof ZodNativeEnum) {
3124
- return Object.keys(type.enum);
3641
+ return util.objectValues(type.enum);
3125
3642
  } else if (type instanceof ZodDefault) {
3126
3643
  return getDiscriminator(type._def.innerType);
3127
3644
  } else if (type instanceof ZodUndefined) {
3128
3645
  return [void 0];
3129
3646
  } else if (type instanceof ZodNull) {
3130
3647
  return [null];
3648
+ } else if (type instanceof ZodOptional) {
3649
+ return [void 0, ...getDiscriminator(type.unwrap())];
3650
+ } else if (type instanceof ZodNullable) {
3651
+ return [null, ...getDiscriminator(type.unwrap())];
3652
+ } else if (type instanceof ZodBranded) {
3653
+ return getDiscriminator(type.unwrap());
3654
+ } else if (type instanceof ZodReadonly) {
3655
+ return getDiscriminator(type.unwrap());
3656
+ } else if (type instanceof ZodCatch) {
3657
+ return getDiscriminator(type._def.innerType);
3131
3658
  } else {
3132
- return null;
3659
+ return [];
3133
3660
  }
3134
3661
  };
3135
3662
  var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
@@ -3189,7 +3716,7 @@ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
3189
3716
  const optionsMap = /* @__PURE__ */ new Map();
3190
3717
  for (const type of options) {
3191
3718
  const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3192
- if (!discriminatorValues) {
3719
+ if (!discriminatorValues.length) {
3193
3720
  throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3194
3721
  }
3195
3722
  for (const value of discriminatorValues) {
@@ -3331,7 +3858,7 @@ var ZodTuple = class _ZodTuple extends ZodType {
3331
3858
  });
3332
3859
  status.dirty();
3333
3860
  }
3334
- const items = ctx.data.map((item, itemIndex) => {
3861
+ const items = [...ctx.data].map((item, itemIndex) => {
3335
3862
  const schema3 = this._def.items[itemIndex] || this._def.rest;
3336
3863
  if (!schema3)
3337
3864
  return null;
@@ -3389,7 +3916,8 @@ var ZodRecord = class _ZodRecord extends ZodType {
3389
3916
  for (const key in ctx.data) {
3390
3917
  pairs.push({
3391
3918
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3392
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
3919
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3920
+ alwaysSet: key in ctx.data
3393
3921
  });
3394
3922
  }
3395
3923
  if (ctx.common.async) {
@@ -3419,6 +3947,12 @@ var ZodRecord = class _ZodRecord extends ZodType {
3419
3947
  }
3420
3948
  };
3421
3949
  var ZodMap = class extends ZodType {
3950
+ get keySchema() {
3951
+ return this._def.keyType;
3952
+ }
3953
+ get valueSchema() {
3954
+ return this._def.valueType;
3955
+ }
3422
3956
  _parse(input) {
3423
3957
  const { status, ctx } = this._processInputParams(input);
3424
3958
  if (ctx.parsedType !== ZodParsedType.map) {
@@ -3613,27 +4147,29 @@ var ZodFunction = class _ZodFunction extends ZodType {
3613
4147
  const params = { errorMap: ctx.common.contextualErrorMap };
3614
4148
  const fn = ctx.data;
3615
4149
  if (this._def.returns instanceof ZodPromise) {
3616
- return OK(async (...args) => {
4150
+ const me = this;
4151
+ return OK(async function(...args) {
3617
4152
  const error = new ZodError([]);
3618
- const parsedArgs = await this._def.args.parseAsync(args, params).catch((e) => {
4153
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3619
4154
  error.addIssue(makeArgsIssue(args, e));
3620
4155
  throw error;
3621
4156
  });
3622
- const result = await fn(...parsedArgs);
3623
- const parsedReturns = await this._def.returns._def.type.parseAsync(result, params).catch((e) => {
4157
+ const result = await Reflect.apply(fn, this, parsedArgs);
4158
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3624
4159
  error.addIssue(makeReturnsIssue(result, e));
3625
4160
  throw error;
3626
4161
  });
3627
4162
  return parsedReturns;
3628
4163
  });
3629
4164
  } else {
3630
- return OK((...args) => {
3631
- const parsedArgs = this._def.args.safeParse(args, params);
4165
+ const me = this;
4166
+ return OK(function(...args) {
4167
+ const parsedArgs = me._def.args.safeParse(args, params);
3632
4168
  if (!parsedArgs.success) {
3633
4169
  throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3634
4170
  }
3635
- const result = fn(...parsedArgs.data);
3636
- const parsedReturns = this._def.returns.safeParse(result, params);
4171
+ const result = Reflect.apply(fn, this, parsedArgs.data);
4172
+ const parsedReturns = me._def.returns.safeParse(result, params);
3637
4173
  if (!parsedReturns.success) {
3638
4174
  throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3639
4175
  }
@@ -3698,6 +4234,7 @@ var ZodLiteral = class extends ZodType {
3698
4234
  if (input.data !== this._def.value) {
3699
4235
  const ctx = this._getOrReturnCtx(input);
3700
4236
  addIssueToContext(ctx, {
4237
+ received: ctx.data,
3701
4238
  code: ZodIssueCode.invalid_literal,
3702
4239
  expected: this._def.value
3703
4240
  });
@@ -3723,7 +4260,11 @@ function createZodEnum(values, params) {
3723
4260
  ...processCreateParams(params)
3724
4261
  });
3725
4262
  }
3726
- var ZodEnum = class extends ZodType {
4263
+ var ZodEnum = class _ZodEnum extends ZodType {
4264
+ constructor() {
4265
+ super(...arguments);
4266
+ _ZodEnum_cache.set(this, void 0);
4267
+ }
3727
4268
  _parse(input) {
3728
4269
  if (typeof input.data !== "string") {
3729
4270
  const ctx = this._getOrReturnCtx(input);
@@ -3735,7 +4276,10 @@ var ZodEnum = class extends ZodType {
3735
4276
  });
3736
4277
  return INVALID;
3737
4278
  }
3738
- if (this._def.values.indexOf(input.data) === -1) {
4279
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
4280
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
4281
+ }
4282
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
3739
4283
  const ctx = this._getOrReturnCtx(input);
3740
4284
  const expectedValues = this._def.values;
3741
4285
  addIssueToContext(ctx, {
@@ -3771,9 +4315,26 @@ var ZodEnum = class extends ZodType {
3771
4315
  }
3772
4316
  return enumValues;
3773
4317
  }
4318
+ extract(values, newDef = this._def) {
4319
+ return _ZodEnum.create(values, {
4320
+ ...this._def,
4321
+ ...newDef
4322
+ });
4323
+ }
4324
+ exclude(values, newDef = this._def) {
4325
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
4326
+ ...this._def,
4327
+ ...newDef
4328
+ });
4329
+ }
3774
4330
  };
4331
+ _ZodEnum_cache = /* @__PURE__ */ new WeakMap();
3775
4332
  ZodEnum.create = createZodEnum;
3776
4333
  var ZodNativeEnum = class extends ZodType {
4334
+ constructor() {
4335
+ super(...arguments);
4336
+ _ZodNativeEnum_cache.set(this, void 0);
4337
+ }
3777
4338
  _parse(input) {
3778
4339
  const nativeEnumValues = util.getValidEnumValues(this._def.values);
3779
4340
  const ctx = this._getOrReturnCtx(input);
@@ -3786,7 +4347,10 @@ var ZodNativeEnum = class extends ZodType {
3786
4347
  });
3787
4348
  return INVALID;
3788
4349
  }
3789
- if (nativeEnumValues.indexOf(input.data) === -1) {
4350
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
4351
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
4352
+ }
4353
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
3790
4354
  const expectedValues = util.objectValues(nativeEnumValues);
3791
4355
  addIssueToContext(ctx, {
3792
4356
  received: ctx.data,
@@ -3801,6 +4365,7 @@ var ZodNativeEnum = class extends ZodType {
3801
4365
  return this._def.values;
3802
4366
  }
3803
4367
  };
4368
+ _ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
3804
4369
  ZodNativeEnum.create = (values, params) => {
3805
4370
  return new ZodNativeEnum({
3806
4371
  values,
@@ -3809,6 +4374,9 @@ ZodNativeEnum.create = (values, params) => {
3809
4374
  });
3810
4375
  };
3811
4376
  var ZodPromise = class extends ZodType {
4377
+ unwrap() {
4378
+ return this._def.type;
4379
+ }
3812
4380
  _parse(input) {
3813
4381
  const { ctx } = this._processInputParams(input);
3814
4382
  if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
@@ -3845,24 +4413,6 @@ var ZodEffects = class extends ZodType {
3845
4413
  _parse(input) {
3846
4414
  const { status, ctx } = this._processInputParams(input);
3847
4415
  const effect = this._def.effect || null;
3848
- if (effect.type === "preprocess") {
3849
- const processed = effect.transform(ctx.data);
3850
- if (ctx.common.async) {
3851
- return Promise.resolve(processed).then((processed2) => {
3852
- return this._def.schema._parseAsync({
3853
- data: processed2,
3854
- path: ctx.path,
3855
- parent: ctx
3856
- });
3857
- });
3858
- } else {
3859
- return this._def.schema._parseSync({
3860
- data: processed,
3861
- path: ctx.path,
3862
- parent: ctx
3863
- });
3864
- }
3865
- }
3866
4416
  const checkCtx = {
3867
4417
  addIssue: (arg) => {
3868
4418
  addIssueToContext(ctx, arg);
@@ -3877,6 +4427,42 @@ var ZodEffects = class extends ZodType {
3877
4427
  }
3878
4428
  };
3879
4429
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
4430
+ if (effect.type === "preprocess") {
4431
+ const processed = effect.transform(ctx.data, checkCtx);
4432
+ if (ctx.common.async) {
4433
+ return Promise.resolve(processed).then(async (processed2) => {
4434
+ if (status.value === "aborted")
4435
+ return INVALID;
4436
+ const result = await this._def.schema._parseAsync({
4437
+ data: processed2,
4438
+ path: ctx.path,
4439
+ parent: ctx
4440
+ });
4441
+ if (result.status === "aborted")
4442
+ return INVALID;
4443
+ if (result.status === "dirty")
4444
+ return DIRTY(result.value);
4445
+ if (status.value === "dirty")
4446
+ return DIRTY(result.value);
4447
+ return result;
4448
+ });
4449
+ } else {
4450
+ if (status.value === "aborted")
4451
+ return INVALID;
4452
+ const result = this._def.schema._parseSync({
4453
+ data: processed,
4454
+ path: ctx.path,
4455
+ parent: ctx
4456
+ });
4457
+ if (result.status === "aborted")
4458
+ return INVALID;
4459
+ if (result.status === "dirty")
4460
+ return DIRTY(result.value);
4461
+ if (status.value === "dirty")
4462
+ return DIRTY(result.value);
4463
+ return result;
4464
+ }
4465
+ }
3880
4466
  if (effect.type === "refinement") {
3881
4467
  const executeRefinement = (acc) => {
3882
4468
  const result = effect.refinement(acc, checkCtx);
@@ -4019,26 +4605,45 @@ ZodDefault.create = (type, params) => {
4019
4605
  var ZodCatch = class extends ZodType {
4020
4606
  _parse(input) {
4021
4607
  const { ctx } = this._processInputParams(input);
4608
+ const newCtx = {
4609
+ ...ctx,
4610
+ common: {
4611
+ ...ctx.common,
4612
+ issues: []
4613
+ }
4614
+ };
4022
4615
  const result = this._def.innerType._parse({
4023
- data: ctx.data,
4024
- path: ctx.path,
4025
- parent: ctx
4616
+ data: newCtx.data,
4617
+ path: newCtx.path,
4618
+ parent: {
4619
+ ...newCtx
4620
+ }
4026
4621
  });
4027
4622
  if (isAsync(result)) {
4028
4623
  return result.then((result2) => {
4029
4624
  return {
4030
4625
  status: "valid",
4031
- value: result2.status === "valid" ? result2.value : this._def.defaultValue()
4626
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
4627
+ get error() {
4628
+ return new ZodError(newCtx.common.issues);
4629
+ },
4630
+ input: newCtx.data
4631
+ })
4032
4632
  };
4033
4633
  });
4034
4634
  } else {
4035
4635
  return {
4036
4636
  status: "valid",
4037
- value: result.status === "valid" ? result.value : this._def.defaultValue()
4637
+ value: result.status === "valid" ? result.value : this._def.catchValue({
4638
+ get error() {
4639
+ return new ZodError(newCtx.common.issues);
4640
+ },
4641
+ input: newCtx.data
4642
+ })
4038
4643
  };
4039
4644
  }
4040
4645
  }
4041
- removeDefault() {
4646
+ removeCatch() {
4042
4647
  return this._def.innerType;
4043
4648
  }
4044
4649
  };
@@ -4046,7 +4651,7 @@ ZodCatch.create = (type, params) => {
4046
4651
  return new ZodCatch({
4047
4652
  innerType: type,
4048
4653
  typeName: ZodFirstPartyTypeKind.ZodCatch,
4049
- defaultValue: typeof params.default === "function" ? params.default : () => params.default,
4654
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
4050
4655
  ...processCreateParams(params)
4051
4656
  });
4052
4657
  };
@@ -4141,6 +4746,25 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
4141
4746
  });
4142
4747
  }
4143
4748
  };
4749
+ var ZodReadonly = class extends ZodType {
4750
+ _parse(input) {
4751
+ const result = this._def.innerType._parse(input);
4752
+ if (isValid(result)) {
4753
+ result.value = Object.freeze(result.value);
4754
+ }
4755
+ return result;
4756
+ }
4757
+ unwrap() {
4758
+ return this._def.innerType;
4759
+ }
4760
+ };
4761
+ ZodReadonly.create = (type, params) => {
4762
+ return new ZodReadonly({
4763
+ innerType: type,
4764
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
4765
+ ...processCreateParams(params)
4766
+ });
4767
+ };
4144
4768
  var late = {
4145
4769
  object: ZodObject.lazycreate
4146
4770
  };
@@ -4181,6 +4805,7 @@ var ZodFirstPartyTypeKind;
4181
4805
  ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
4182
4806
  ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
4183
4807
  ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
4808
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
4184
4809
  })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
4185
4810
  var stringType = ZodString.create;
4186
4811
  var numberType = ZodNumber.create;