@embeddable.com/sdk-core 3.1.9 → 3.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -257,6 +257,11 @@ let ZodError$1 = class ZodError extends Error {
257
257
  processError(this);
258
258
  return fieldErrors;
259
259
  }
260
+ static assert(value) {
261
+ if (!(value instanceof ZodError)) {
262
+ throw new Error(`Not a ZodError: ${value}`);
263
+ }
264
+ }
260
265
  toString() {
261
266
  return this.message;
262
267
  }
@@ -288,6 +293,11 @@ ZodError$1.create = (issues) => {
288
293
  const error = new ZodError$1(issues);
289
294
  return error;
290
295
  };
296
+
297
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
298
+ var e = new Error(message);
299
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
300
+ };
291
301
 
292
302
  var errorUtil$1;
293
303
  (function (errorUtil) {
@@ -745,6 +755,11 @@ class ZodError extends Error {
745
755
  processError(this);
746
756
  return fieldErrors;
747
757
  }
758
+ static assert(value) {
759
+ if (!(value instanceof ZodError)) {
760
+ throw new Error(`Not a ZodError: ${value}`);
761
+ }
762
+ }
748
763
  toString() {
749
764
  return this.message;
750
765
  }
@@ -917,6 +932,13 @@ const makeIssue = (params) => {
917
932
  ...issueData,
918
933
  path: fullPath,
919
934
  };
935
+ if (issueData.message !== undefined) {
936
+ return {
937
+ ...issueData,
938
+ path: fullPath,
939
+ message: issueData.message,
940
+ };
941
+ }
920
942
  let errorMessage = "";
921
943
  const maps = errorMaps
922
944
  .filter((m) => !!m)
@@ -928,11 +950,12 @@ const makeIssue = (params) => {
928
950
  return {
929
951
  ...issueData,
930
952
  path: fullPath,
931
- message: issueData.message || errorMessage,
953
+ message: errorMessage,
932
954
  };
933
955
  };
934
956
  const EMPTY_PATH = [];
935
957
  function addIssueToContext(ctx, issueData) {
958
+ const overrideMap = getErrorMap();
936
959
  const issue = makeIssue({
937
960
  issueData: issueData,
938
961
  data: ctx.data,
@@ -940,8 +963,8 @@ function addIssueToContext(ctx, issueData) {
940
963
  errorMaps: [
941
964
  ctx.common.contextualErrorMap,
942
965
  ctx.schemaErrorMap,
943
- getErrorMap(),
944
- errorMap, // then global default map
966
+ overrideMap,
967
+ overrideMap === errorMap ? undefined : errorMap, // then global default map
945
968
  ].filter((x) => !!x),
946
969
  });
947
970
  ctx.common.issues.push(issue);
@@ -972,9 +995,11 @@ class ParseStatus {
972
995
  static async mergeObjectAsync(status, pairs) {
973
996
  const syncPairs = [];
974
997
  for (const pair of pairs) {
998
+ const key = await pair.key;
999
+ const value = await pair.value;
975
1000
  syncPairs.push({
976
- key: await pair.key,
977
- value: await pair.value,
1001
+ key,
1002
+ value,
978
1003
  });
979
1004
  }
980
1005
  return ParseStatus.mergeObjectSync(status, syncPairs);
@@ -1009,12 +1034,46 @@ const isDirty = (x) => x.status === "dirty";
1009
1034
  const isValid = (x) => x.status === "valid";
1010
1035
  const isAsync$1 = (x) => typeof Promise !== "undefined" && x instanceof Promise;
1011
1036
 
1037
+ /******************************************************************************
1038
+ Copyright (c) Microsoft Corporation.
1039
+
1040
+ Permission to use, copy, modify, and/or distribute this software for any
1041
+ purpose with or without fee is hereby granted.
1042
+
1043
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1044
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1045
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1046
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1047
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1048
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1049
+ PERFORMANCE OF THIS SOFTWARE.
1050
+ ***************************************************************************** */
1051
+
1052
+ function __classPrivateFieldGet(receiver, state, kind, f) {
1053
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1054
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1055
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1056
+ }
1057
+
1058
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
1059
+ if (kind === "m") throw new TypeError("Private method is not writable");
1060
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1061
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1062
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1063
+ }
1064
+
1065
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1066
+ var e = new Error(message);
1067
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1068
+ };
1069
+
1012
1070
  var errorUtil;
1013
1071
  (function (errorUtil) {
1014
1072
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
1015
1073
  errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
1016
1074
  })(errorUtil || (errorUtil = {}));
1017
1075
 
1076
+ var _ZodEnum_cache, _ZodNativeEnum_cache;
1018
1077
  class ParseInputLazyPath {
1019
1078
  constructor(parent, value, path, key) {
1020
1079
  this._cachedPath = [];
@@ -1065,12 +1124,17 @@ function processCreateParams(params) {
1065
1124
  if (errorMap)
1066
1125
  return { errorMap: errorMap, description };
1067
1126
  const customMap = (iss, ctx) => {
1068
- if (iss.code !== "invalid_type")
1069
- return { message: ctx.defaultError };
1127
+ var _a, _b;
1128
+ const { message } = params;
1129
+ if (iss.code === "invalid_enum_value") {
1130
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
1131
+ }
1070
1132
  if (typeof ctx.data === "undefined") {
1071
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
1133
+ return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
1072
1134
  }
1073
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
1135
+ if (iss.code !== "invalid_type")
1136
+ return { message: ctx.defaultError };
1137
+ return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
1074
1138
  };
1075
1139
  return { errorMap: customMap, description };
1076
1140
  }
@@ -1328,11 +1392,13 @@ class ZodType {
1328
1392
  }
1329
1393
  }
1330
1394
  const cuidRegex = /^c[^\s-]{8,}$/i;
1331
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
1395
+ const cuid2Regex = /^[0-9a-z]+$/;
1332
1396
  const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
1333
1397
  // const uuidRegex =
1334
1398
  // /^([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;
1335
1399
  const 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;
1400
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
1401
+ const 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)?)??$/;
1336
1402
  // from https://stackoverflow.com/a/46181/1550155
1337
1403
  // old version: too slow, didn't support unicode
1338
1404
  // const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
@@ -1345,41 +1411,48 @@ const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-
1345
1411
  // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
1346
1412
  // const emailRegex =
1347
1413
  // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
1348
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1414
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
1349
1415
  // const emailRegex =
1350
1416
  // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
1351
1417
  // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
1352
1418
  const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1353
1419
  let emojiRegex;
1354
- const ipv4Regex = /^(((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}))$/;
1420
+ // faster, simpler, safer
1421
+ const 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])$/;
1355
1422
  const 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})))$/;
1356
- // Adapted from https://stackoverflow.com/a/3143231
1357
- const datetimeRegex = (args) => {
1423
+ // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
1424
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
1425
+ // simple
1426
+ // const dateRegexSource = `\\d{4}-\\d{2}-\\d{2}`;
1427
+ // no leap year validation
1428
+ // const dateRegexSource = `\\d{4}-((0[13578]|10|12)-31|(0[13-9]|1[0-2])-30|(0[1-9]|1[0-2])-(0[1-9]|1\\d|2\\d))`;
1429
+ // with leap year validation
1430
+ const dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
1431
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
1432
+ function timeRegexSource(args) {
1433
+ // let regex = `\\d{2}:\\d{2}:\\d{2}`;
1434
+ let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
1358
1435
  if (args.precision) {
1359
- if (args.offset) {
1360
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1361
- }
1362
- else {
1363
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
1364
- }
1365
- }
1366
- else if (args.precision === 0) {
1367
- if (args.offset) {
1368
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1369
- }
1370
- else {
1371
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
1372
- }
1436
+ regex = `${regex}\\.\\d{${args.precision}}`;
1373
1437
  }
1374
- else {
1375
- if (args.offset) {
1376
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
1377
- }
1378
- else {
1379
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
1380
- }
1438
+ else if (args.precision == null) {
1439
+ regex = `${regex}(\\.\\d+)?`;
1381
1440
  }
1382
- };
1441
+ return regex;
1442
+ }
1443
+ function timeRegex(args) {
1444
+ return new RegExp(`^${timeRegexSource(args)}$`);
1445
+ }
1446
+ // Adapted from https://stackoverflow.com/a/3143231
1447
+ function datetimeRegex(args) {
1448
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
1449
+ const opts = [];
1450
+ opts.push(args.local ? `Z?` : `Z`);
1451
+ if (args.offset)
1452
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
1453
+ regex = `${regex}(${opts.join("|")})`;
1454
+ return new RegExp(`^${regex}$`);
1455
+ }
1383
1456
  function isValidIP(ip, version) {
1384
1457
  if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
1385
1458
  return true;
@@ -1401,9 +1474,7 @@ class ZodString extends ZodType {
1401
1474
  code: ZodIssueCode.invalid_type,
1402
1475
  expected: ZodParsedType.string,
1403
1476
  received: ctx.parsedType,
1404
- }
1405
- //
1406
- );
1477
+ });
1407
1478
  return INVALID;
1408
1479
  }
1409
1480
  const status = new ParseStatus();
@@ -1501,6 +1572,17 @@ class ZodString extends ZodType {
1501
1572
  status.dirty();
1502
1573
  }
1503
1574
  }
1575
+ else if (check.kind === "nanoid") {
1576
+ if (!nanoidRegex.test(input.data)) {
1577
+ ctx = this._getOrReturnCtx(input, ctx);
1578
+ addIssueToContext(ctx, {
1579
+ validation: "nanoid",
1580
+ code: ZodIssueCode.invalid_string,
1581
+ message: check.message,
1582
+ });
1583
+ status.dirty();
1584
+ }
1585
+ }
1504
1586
  else if (check.kind === "cuid") {
1505
1587
  if (!cuidRegex.test(input.data)) {
1506
1588
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1615,6 +1697,41 @@ class ZodString extends ZodType {
1615
1697
  status.dirty();
1616
1698
  }
1617
1699
  }
1700
+ else if (check.kind === "date") {
1701
+ const regex = dateRegex;
1702
+ if (!regex.test(input.data)) {
1703
+ ctx = this._getOrReturnCtx(input, ctx);
1704
+ addIssueToContext(ctx, {
1705
+ code: ZodIssueCode.invalid_string,
1706
+ validation: "date",
1707
+ message: check.message,
1708
+ });
1709
+ status.dirty();
1710
+ }
1711
+ }
1712
+ else if (check.kind === "time") {
1713
+ const regex = timeRegex(check);
1714
+ if (!regex.test(input.data)) {
1715
+ ctx = this._getOrReturnCtx(input, ctx);
1716
+ addIssueToContext(ctx, {
1717
+ code: ZodIssueCode.invalid_string,
1718
+ validation: "time",
1719
+ message: check.message,
1720
+ });
1721
+ status.dirty();
1722
+ }
1723
+ }
1724
+ else if (check.kind === "duration") {
1725
+ if (!durationRegex.test(input.data)) {
1726
+ ctx = this._getOrReturnCtx(input, ctx);
1727
+ addIssueToContext(ctx, {
1728
+ validation: "duration",
1729
+ code: ZodIssueCode.invalid_string,
1730
+ message: check.message,
1731
+ });
1732
+ status.dirty();
1733
+ }
1734
+ }
1618
1735
  else if (check.kind === "ip") {
1619
1736
  if (!isValidIP(input.data, check.version)) {
1620
1737
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1626,6 +1743,17 @@ class ZodString extends ZodType {
1626
1743
  status.dirty();
1627
1744
  }
1628
1745
  }
1746
+ else if (check.kind === "base64") {
1747
+ if (!base64Regex.test(input.data)) {
1748
+ ctx = this._getOrReturnCtx(input, ctx);
1749
+ addIssueToContext(ctx, {
1750
+ validation: "base64",
1751
+ code: ZodIssueCode.invalid_string,
1752
+ message: check.message,
1753
+ });
1754
+ status.dirty();
1755
+ }
1756
+ }
1629
1757
  else {
1630
1758
  util$7.assertNever(check);
1631
1759
  }
@@ -1657,6 +1785,9 @@ class ZodString extends ZodType {
1657
1785
  uuid(message) {
1658
1786
  return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1659
1787
  }
1788
+ nanoid(message) {
1789
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1790
+ }
1660
1791
  cuid(message) {
1661
1792
  return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1662
1793
  }
@@ -1666,16 +1797,20 @@ class ZodString extends ZodType {
1666
1797
  ulid(message) {
1667
1798
  return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1668
1799
  }
1800
+ base64(message) {
1801
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1802
+ }
1669
1803
  ip(options) {
1670
1804
  return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1671
1805
  }
1672
1806
  datetime(options) {
1673
- var _a;
1807
+ var _a, _b;
1674
1808
  if (typeof options === "string") {
1675
1809
  return this._addCheck({
1676
1810
  kind: "datetime",
1677
1811
  precision: null,
1678
1812
  offset: false,
1813
+ local: false,
1679
1814
  message: options,
1680
1815
  });
1681
1816
  }
@@ -1683,9 +1818,30 @@ class ZodString extends ZodType {
1683
1818
  kind: "datetime",
1684
1819
  precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1685
1820
  offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1821
+ local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1686
1822
  ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1687
1823
  });
1688
1824
  }
1825
+ date(message) {
1826
+ return this._addCheck({ kind: "date", message });
1827
+ }
1828
+ time(options) {
1829
+ if (typeof options === "string") {
1830
+ return this._addCheck({
1831
+ kind: "time",
1832
+ precision: null,
1833
+ message: options,
1834
+ });
1835
+ }
1836
+ return this._addCheck({
1837
+ kind: "time",
1838
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1839
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
1840
+ });
1841
+ }
1842
+ duration(message) {
1843
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1844
+ }
1689
1845
  regex(regex, message) {
1690
1846
  return this._addCheck({
1691
1847
  kind: "regex",
@@ -1764,6 +1920,15 @@ class ZodString extends ZodType {
1764
1920
  get isDatetime() {
1765
1921
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
1766
1922
  }
1923
+ get isDate() {
1924
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1925
+ }
1926
+ get isTime() {
1927
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1928
+ }
1929
+ get isDuration() {
1930
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1931
+ }
1767
1932
  get isEmail() {
1768
1933
  return !!this._def.checks.find((ch) => ch.kind === "email");
1769
1934
  }
@@ -1776,6 +1941,9 @@ class ZodString extends ZodType {
1776
1941
  get isUUID() {
1777
1942
  return !!this._def.checks.find((ch) => ch.kind === "uuid");
1778
1943
  }
1944
+ get isNANOID() {
1945
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1946
+ }
1779
1947
  get isCUID() {
1780
1948
  return !!this._def.checks.find((ch) => ch.kind === "cuid");
1781
1949
  }
@@ -1788,6 +1956,9 @@ class ZodString extends ZodType {
1788
1956
  get isIP() {
1789
1957
  return !!this._def.checks.find((ch) => ch.kind === "ip");
1790
1958
  }
1959
+ get isBase64() {
1960
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1961
+ }
1791
1962
  get minLength() {
1792
1963
  let min = null;
1793
1964
  for (const ch of this._def.checks) {
@@ -2775,9 +2946,10 @@ class ZodObject extends ZodType {
2775
2946
  const syncPairs = [];
2776
2947
  for (const pair of pairs) {
2777
2948
  const key = await pair.key;
2949
+ const value = await pair.value;
2778
2950
  syncPairs.push({
2779
2951
  key,
2780
- value: await pair.value,
2952
+ value,
2781
2953
  alwaysSet: pair.alwaysSet,
2782
2954
  });
2783
2955
  }
@@ -3151,7 +3323,7 @@ const getDiscriminator = (type) => {
3151
3323
  }
3152
3324
  else if (type instanceof ZodNativeEnum) {
3153
3325
  // eslint-disable-next-line ban/ban
3154
- return Object.keys(type.enum);
3326
+ return util$7.objectValues(type.enum);
3155
3327
  }
3156
3328
  else if (type instanceof ZodDefault) {
3157
3329
  return getDiscriminator(type._def.innerType);
@@ -3162,8 +3334,23 @@ const getDiscriminator = (type) => {
3162
3334
  else if (type instanceof ZodNull) {
3163
3335
  return [null];
3164
3336
  }
3337
+ else if (type instanceof ZodOptional) {
3338
+ return [undefined, ...getDiscriminator(type.unwrap())];
3339
+ }
3340
+ else if (type instanceof ZodNullable) {
3341
+ return [null, ...getDiscriminator(type.unwrap())];
3342
+ }
3343
+ else if (type instanceof ZodBranded) {
3344
+ return getDiscriminator(type.unwrap());
3345
+ }
3346
+ else if (type instanceof ZodReadonly) {
3347
+ return getDiscriminator(type.unwrap());
3348
+ }
3349
+ else if (type instanceof ZodCatch) {
3350
+ return getDiscriminator(type._def.innerType);
3351
+ }
3165
3352
  else {
3166
- return null;
3353
+ return [];
3167
3354
  }
3168
3355
  };
3169
3356
  class ZodDiscriminatedUnion extends ZodType {
@@ -3226,7 +3413,7 @@ class ZodDiscriminatedUnion extends ZodType {
3226
3413
  // try {
3227
3414
  for (const type of options) {
3228
3415
  const discriminatorValues = getDiscriminator(type.shape[discriminator]);
3229
- if (!discriminatorValues) {
3416
+ if (!discriminatorValues.length) {
3230
3417
  throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
3231
3418
  }
3232
3419
  for (const value of discriminatorValues) {
@@ -3439,6 +3626,7 @@ class ZodRecord extends ZodType {
3439
3626
  pairs.push({
3440
3627
  key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
3441
3628
  value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
3629
+ alwaysSet: key in ctx.data,
3442
3630
  });
3443
3631
  }
3444
3632
  if (ctx.common.async) {
@@ -3798,6 +3986,10 @@ function createZodEnum(values, params) {
3798
3986
  });
3799
3987
  }
3800
3988
  class ZodEnum extends ZodType {
3989
+ constructor() {
3990
+ super(...arguments);
3991
+ _ZodEnum_cache.set(this, void 0);
3992
+ }
3801
3993
  _parse(input) {
3802
3994
  if (typeof input.data !== "string") {
3803
3995
  const ctx = this._getOrReturnCtx(input);
@@ -3809,7 +4001,10 @@ class ZodEnum extends ZodType {
3809
4001
  });
3810
4002
  return INVALID;
3811
4003
  }
3812
- if (this._def.values.indexOf(input.data) === -1) {
4004
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
4005
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
4006
+ }
4007
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
3813
4008
  const ctx = this._getOrReturnCtx(input);
3814
4009
  const expectedValues = this._def.values;
3815
4010
  addIssueToContext(ctx, {
@@ -3845,15 +4040,26 @@ class ZodEnum extends ZodType {
3845
4040
  }
3846
4041
  return enumValues;
3847
4042
  }
3848
- extract(values) {
3849
- return ZodEnum.create(values);
4043
+ extract(values, newDef = this._def) {
4044
+ return ZodEnum.create(values, {
4045
+ ...this._def,
4046
+ ...newDef,
4047
+ });
3850
4048
  }
3851
- exclude(values) {
3852
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
4049
+ exclude(values, newDef = this._def) {
4050
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
4051
+ ...this._def,
4052
+ ...newDef,
4053
+ });
3853
4054
  }
3854
4055
  }
4056
+ _ZodEnum_cache = new WeakMap();
3855
4057
  ZodEnum.create = createZodEnum;
3856
4058
  class ZodNativeEnum extends ZodType {
4059
+ constructor() {
4060
+ super(...arguments);
4061
+ _ZodNativeEnum_cache.set(this, void 0);
4062
+ }
3857
4063
  _parse(input) {
3858
4064
  const nativeEnumValues = util$7.getValidEnumValues(this._def.values);
3859
4065
  const ctx = this._getOrReturnCtx(input);
@@ -3867,7 +4073,10 @@ class ZodNativeEnum extends ZodType {
3867
4073
  });
3868
4074
  return INVALID;
3869
4075
  }
3870
- if (nativeEnumValues.indexOf(input.data) === -1) {
4076
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
4077
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$7.getValidEnumValues(this._def.values)), "f");
4078
+ }
4079
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
3871
4080
  const expectedValues = util$7.objectValues(nativeEnumValues);
3872
4081
  addIssueToContext(ctx, {
3873
4082
  received: ctx.data,
@@ -3882,6 +4091,7 @@ class ZodNativeEnum extends ZodType {
3882
4091
  return this._def.values;
3883
4092
  }
3884
4093
  }
4094
+ _ZodNativeEnum_cache = new WeakMap();
3885
4095
  ZodNativeEnum.create = (values, params) => {
3886
4096
  return new ZodNativeEnum({
3887
4097
  values: values,
@@ -3951,33 +4161,43 @@ class ZodEffects extends ZodType {
3951
4161
  checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3952
4162
  if (effect.type === "preprocess") {
3953
4163
  const processed = effect.transform(ctx.data, checkCtx);
3954
- if (ctx.common.issues.length) {
3955
- return {
3956
- status: "dirty",
3957
- value: ctx.data,
3958
- };
3959
- }
3960
4164
  if (ctx.common.async) {
3961
- return Promise.resolve(processed).then((processed) => {
3962
- return this._def.schema._parseAsync({
4165
+ return Promise.resolve(processed).then(async (processed) => {
4166
+ if (status.value === "aborted")
4167
+ return INVALID;
4168
+ const result = await this._def.schema._parseAsync({
3963
4169
  data: processed,
3964
4170
  path: ctx.path,
3965
4171
  parent: ctx,
3966
4172
  });
4173
+ if (result.status === "aborted")
4174
+ return INVALID;
4175
+ if (result.status === "dirty")
4176
+ return DIRTY(result.value);
4177
+ if (status.value === "dirty")
4178
+ return DIRTY(result.value);
4179
+ return result;
3967
4180
  });
3968
4181
  }
3969
4182
  else {
3970
- return this._def.schema._parseSync({
4183
+ if (status.value === "aborted")
4184
+ return INVALID;
4185
+ const result = this._def.schema._parseSync({
3971
4186
  data: processed,
3972
4187
  path: ctx.path,
3973
4188
  parent: ctx,
3974
4189
  });
4190
+ if (result.status === "aborted")
4191
+ return INVALID;
4192
+ if (result.status === "dirty")
4193
+ return DIRTY(result.value);
4194
+ if (status.value === "dirty")
4195
+ return DIRTY(result.value);
4196
+ return result;
3975
4197
  }
3976
4198
  }
3977
4199
  if (effect.type === "refinement") {
3978
- const executeRefinement = (acc
3979
- // effect: RefinementEffect<any>
3980
- ) => {
4200
+ const executeRefinement = (acc) => {
3981
4201
  const result = effect.refinement(acc, checkCtx);
3982
4202
  if (ctx.common.async) {
3983
4203
  return Promise.resolve(result);
@@ -4280,10 +4500,18 @@ class ZodPipeline extends ZodType {
4280
4500
  class ZodReadonly extends ZodType {
4281
4501
  _parse(input) {
4282
4502
  const result = this._def.innerType._parse(input);
4283
- if (isValid(result)) {
4284
- result.value = Object.freeze(result.value);
4285
- }
4286
- return result;
4503
+ const freeze = (data) => {
4504
+ if (isValid(data)) {
4505
+ data.value = Object.freeze(data.value);
4506
+ }
4507
+ return data;
4508
+ };
4509
+ return isAsync$1(result)
4510
+ ? result.then((data) => freeze(data))
4511
+ : freeze(result);
4512
+ }
4513
+ unwrap() {
4514
+ return this._def.innerType;
4287
4515
  }
4288
4516
  }
4289
4517
  ZodReadonly.create = (type, params) => {
@@ -4293,7 +4521,7 @@ ZodReadonly.create = (type, params) => {
4293
4521
  ...processCreateParams(params),
4294
4522
  });
4295
4523
  };
4296
- const custom = (check, params = {},
4524
+ function custom(check, params = {},
4297
4525
  /**
4298
4526
  * @deprecated
4299
4527
  *
@@ -4304,7 +4532,7 @@ const custom = (check, params = {},
4304
4532
  * ```
4305
4533
  *
4306
4534
  */
4307
- fatal) => {
4535
+ fatal) {
4308
4536
  if (check)
4309
4537
  return ZodAny.create().superRefine((data, ctx) => {
4310
4538
  var _a, _b;
@@ -4320,7 +4548,7 @@ fatal) => {
4320
4548
  }
4321
4549
  });
4322
4550
  return ZodAny.create();
4323
- };
4551
+ }
4324
4552
  const late = {
4325
4553
  object: ZodObject.lazycreate,
4326
4554
  };
@@ -4438,6 +4666,7 @@ var z = /*#__PURE__*/Object.freeze({
4438
4666
  ZodParsedType: ZodParsedType,
4439
4667
  getParsedType: getParsedType,
4440
4668
  ZodType: ZodType,
4669
+ datetimeRegex: datetimeRegex,
4441
4670
  ZodString: ZodString,
4442
4671
  ZodNumber: ZodNumber,
4443
4672
  ZodBigInt: ZodBigInt,
@@ -20161,13 +20390,13 @@ var push = async () => {
20161
20390
  checkNodeVersion();
20162
20391
  ora$1 = (await oraP$1).default;
20163
20392
  const config = await provideConfig();
20164
- const token = await verify(config);
20165
20393
  if (process.argv.includes("--api-key") || process.argv.includes("-k")) {
20166
20394
  spinnerPushing = ora$1("Using API key...").start();
20167
20395
  await pushByApiKey(config, spinnerPushing);
20168
20396
  spinnerPushing.succeed("Published using API key");
20169
20397
  return;
20170
20398
  }
20399
+ const token = await verify(config);
20171
20400
  const { workspaceId, name: workspaceName } = await selectWorkspace(config, token);
20172
20401
  const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
20173
20402
  await buildArchive(config);