@wise/dynamic-flow-types 2.28.0 → 2.28.2

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/build/main.js CHANGED
@@ -43,7 +43,7 @@ __export(src_exports, {
43
43
  });
44
44
  module.exports = __toCommonJS(src_exports);
45
45
 
46
- // ../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.mjs
46
+ // ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
47
47
  var util;
48
48
  (function(util2) {
49
49
  util2.assertEqual = (val) => val;
@@ -194,6 +194,9 @@ var quotelessJson = (obj) => {
194
194
  return json.replace(/"([^"]+)":/g, "$1:");
195
195
  };
196
196
  var ZodError = class _ZodError extends Error {
197
+ get errors() {
198
+ return this.issues;
199
+ }
197
200
  constructor(issues) {
198
201
  super();
199
202
  this.issues = [];
@@ -212,9 +215,6 @@ var ZodError = class _ZodError extends Error {
212
215
  this.name = "ZodError";
213
216
  this.issues = issues;
214
217
  }
215
- get errors() {
216
- return this.issues;
217
- }
218
218
  format(_mapper) {
219
219
  const mapper = _mapper || function(issue) {
220
220
  return issue.message;
@@ -422,8 +422,11 @@ function addIssueToContext(ctx, issueData) {
422
422
  path: ctx.path,
423
423
  errorMaps: [
424
424
  ctx.common.contextualErrorMap,
425
+ // contextual error map is first priority
425
426
  ctx.schemaErrorMap,
427
+ // then schema-bound map if available
426
428
  overrideMap,
429
+ // then global override map
427
430
  overrideMap === errorMap ? void 0 : errorMap
428
431
  // then global default map
429
432
  ].filter((x) => !!x)
@@ -574,34 +577,6 @@ function processCreateParams(params) {
574
577
  return { errorMap: customMap, description };
575
578
  }
576
579
  var ZodType = class {
577
- constructor(def) {
578
- this.spa = this.safeParseAsync;
579
- this._def = def;
580
- this.parse = this.parse.bind(this);
581
- this.safeParse = this.safeParse.bind(this);
582
- this.parseAsync = this.parseAsync.bind(this);
583
- this.safeParseAsync = this.safeParseAsync.bind(this);
584
- this.spa = this.spa.bind(this);
585
- this.refine = this.refine.bind(this);
586
- this.refinement = this.refinement.bind(this);
587
- this.superRefine = this.superRefine.bind(this);
588
- this.optional = this.optional.bind(this);
589
- this.nullable = this.nullable.bind(this);
590
- this.nullish = this.nullish.bind(this);
591
- this.array = this.array.bind(this);
592
- this.promise = this.promise.bind(this);
593
- this.or = this.or.bind(this);
594
- this.and = this.and.bind(this);
595
- this.transform = this.transform.bind(this);
596
- this.brand = this.brand.bind(this);
597
- this.default = this.default.bind(this);
598
- this.catch = this.catch.bind(this);
599
- this.describe = this.describe.bind(this);
600
- this.pipe = this.pipe.bind(this);
601
- this.readonly = this.readonly.bind(this);
602
- this.isNullable = this.isNullable.bind(this);
603
- this.isOptional = this.isOptional.bind(this);
604
- }
605
580
  get description() {
606
581
  return this._def.description;
607
582
  }
@@ -665,6 +640,43 @@ var ZodType = class {
665
640
  const result = this._parseSync({ data, path: ctx.path, parent: ctx });
666
641
  return handleResult(ctx, result);
667
642
  }
643
+ "~validate"(data) {
644
+ var _a, _b;
645
+ const ctx = {
646
+ common: {
647
+ issues: [],
648
+ async: !!this["~standard"].async
649
+ },
650
+ path: [],
651
+ schemaErrorMap: this._def.errorMap,
652
+ parent: null,
653
+ data,
654
+ parsedType: getParsedType(data)
655
+ };
656
+ if (!this["~standard"].async) {
657
+ try {
658
+ const result = this._parseSync({ data, path: [], parent: ctx });
659
+ return isValid(result) ? {
660
+ value: result.value
661
+ } : {
662
+ issues: ctx.common.issues
663
+ };
664
+ } catch (err) {
665
+ if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
666
+ this["~standard"].async = true;
667
+ }
668
+ ctx.common = {
669
+ issues: [],
670
+ async: true
671
+ };
672
+ }
673
+ }
674
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
675
+ value: result.value
676
+ } : {
677
+ issues: ctx.common.issues
678
+ });
679
+ }
668
680
  async parseAsync(data, params) {
669
681
  const result = await this.safeParseAsync(data, params);
670
682
  if (result.success)
@@ -741,6 +753,39 @@ var ZodType = class {
741
753
  superRefine(refinement) {
742
754
  return this._refinement(refinement);
743
755
  }
756
+ constructor(def) {
757
+ this.spa = this.safeParseAsync;
758
+ this._def = def;
759
+ this.parse = this.parse.bind(this);
760
+ this.safeParse = this.safeParse.bind(this);
761
+ this.parseAsync = this.parseAsync.bind(this);
762
+ this.safeParseAsync = this.safeParseAsync.bind(this);
763
+ this.spa = this.spa.bind(this);
764
+ this.refine = this.refine.bind(this);
765
+ this.refinement = this.refinement.bind(this);
766
+ this.superRefine = this.superRefine.bind(this);
767
+ this.optional = this.optional.bind(this);
768
+ this.nullable = this.nullable.bind(this);
769
+ this.nullish = this.nullish.bind(this);
770
+ this.array = this.array.bind(this);
771
+ this.promise = this.promise.bind(this);
772
+ this.or = this.or.bind(this);
773
+ this.and = this.and.bind(this);
774
+ this.transform = this.transform.bind(this);
775
+ this.brand = this.brand.bind(this);
776
+ this.default = this.default.bind(this);
777
+ this.catch = this.catch.bind(this);
778
+ this.describe = this.describe.bind(this);
779
+ this.pipe = this.pipe.bind(this);
780
+ this.readonly = this.readonly.bind(this);
781
+ this.isNullable = this.isNullable.bind(this);
782
+ this.isOptional = this.isOptional.bind(this);
783
+ this["~standard"] = {
784
+ version: 1,
785
+ vendor: "zod",
786
+ validate: (data) => this["~validate"](data)
787
+ };
788
+ }
744
789
  optional() {
745
790
  return ZodOptional.create(this, this._def);
746
791
  }
@@ -751,7 +796,7 @@ var ZodType = class {
751
796
  return this.nullable().optional();
752
797
  }
753
798
  array() {
754
- return ZodArray.create(this, this._def);
799
+ return ZodArray.create(this);
755
800
  }
756
801
  promise() {
757
802
  return ZodPromise.create(this, this._def);
@@ -812,16 +857,20 @@ var ZodType = class {
812
857
  };
813
858
  var cuidRegex = /^c[^\s-]{8,}$/i;
814
859
  var cuid2Regex = /^[0-9a-z]+$/;
815
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
860
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
816
861
  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;
817
862
  var nanoidRegex = /^[a-z0-9_-]{21}$/i;
863
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
818
864
  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)?)??$/;
819
865
  var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
820
866
  var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
821
867
  var emojiRegex;
822
868
  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])$/;
823
- 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})))$/;
869
+ var ipv4CidrRegex = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/;
870
+ var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
871
+ var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
824
872
  var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
873
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
825
874
  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])))`;
826
875
  var dateRegex = new RegExp(`^${dateRegexSource}$`);
827
876
  function timeRegexSource(args) {
@@ -854,6 +903,33 @@ function isValidIP(ip, version) {
854
903
  }
855
904
  return false;
856
905
  }
906
+ function isValidJWT(jwt, alg) {
907
+ if (!jwtRegex.test(jwt))
908
+ return false;
909
+ try {
910
+ const [header] = jwt.split(".");
911
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
912
+ const decoded = JSON.parse(atob(base64));
913
+ if (typeof decoded !== "object" || decoded === null)
914
+ return false;
915
+ if (!decoded.typ || !decoded.alg)
916
+ return false;
917
+ if (alg && decoded.alg !== alg)
918
+ return false;
919
+ return true;
920
+ } catch (_a) {
921
+ return false;
922
+ }
923
+ }
924
+ function isValidCidr(ip, version) {
925
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
926
+ return true;
927
+ }
928
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
929
+ return true;
930
+ }
931
+ return false;
932
+ }
857
933
  var ZodString = class _ZodString extends ZodType {
858
934
  _parse(input) {
859
935
  if (this._def.coerce) {
@@ -1110,6 +1186,26 @@ var ZodString = class _ZodString extends ZodType {
1110
1186
  });
1111
1187
  status.dirty();
1112
1188
  }
1189
+ } else if (check.kind === "jwt") {
1190
+ if (!isValidJWT(input.data, check.alg)) {
1191
+ ctx = this._getOrReturnCtx(input, ctx);
1192
+ addIssueToContext(ctx, {
1193
+ validation: "jwt",
1194
+ code: ZodIssueCode.invalid_string,
1195
+ message: check.message
1196
+ });
1197
+ status.dirty();
1198
+ }
1199
+ } else if (check.kind === "cidr") {
1200
+ if (!isValidCidr(input.data, check.version)) {
1201
+ ctx = this._getOrReturnCtx(input, ctx);
1202
+ addIssueToContext(ctx, {
1203
+ validation: "cidr",
1204
+ code: ZodIssueCode.invalid_string,
1205
+ message: check.message
1206
+ });
1207
+ status.dirty();
1208
+ }
1113
1209
  } else if (check.kind === "base64") {
1114
1210
  if (!base64Regex.test(input.data)) {
1115
1211
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1120,6 +1216,16 @@ var ZodString = class _ZodString extends ZodType {
1120
1216
  });
1121
1217
  status.dirty();
1122
1218
  }
1219
+ } else if (check.kind === "base64url") {
1220
+ if (!base64urlRegex.test(input.data)) {
1221
+ ctx = this._getOrReturnCtx(input, ctx);
1222
+ addIssueToContext(ctx, {
1223
+ validation: "base64url",
1224
+ code: ZodIssueCode.invalid_string,
1225
+ message: check.message
1226
+ });
1227
+ status.dirty();
1228
+ }
1123
1229
  } else {
1124
1230
  util.assertNever(check);
1125
1231
  }
@@ -1164,9 +1270,20 @@ var ZodString = class _ZodString extends ZodType {
1164
1270
  base64(message) {
1165
1271
  return this._addCheck(__spreadValues({ kind: "base64" }, errorUtil.errToObj(message)));
1166
1272
  }
1273
+ base64url(message) {
1274
+ return this._addCheck(__spreadValues({
1275
+ kind: "base64url"
1276
+ }, errorUtil.errToObj(message)));
1277
+ }
1278
+ jwt(options) {
1279
+ return this._addCheck(__spreadValues({ kind: "jwt" }, errorUtil.errToObj(options)));
1280
+ }
1167
1281
  ip(options) {
1168
1282
  return this._addCheck(__spreadValues({ kind: "ip" }, errorUtil.errToObj(options)));
1169
1283
  }
1284
+ cidr(options) {
1285
+ return this._addCheck(__spreadValues({ kind: "cidr" }, errorUtil.errToObj(options)));
1286
+ }
1170
1287
  datetime(options) {
1171
1288
  var _a, _b;
1172
1289
  if (typeof options === "string") {
@@ -1248,8 +1365,7 @@ var ZodString = class _ZodString extends ZodType {
1248
1365
  }, errorUtil.errToObj(message)));
1249
1366
  }
1250
1367
  /**
1251
- * @deprecated Use z.string().min(1) instead.
1252
- * @see {@link ZodString.min}
1368
+ * Equivalent to `.min(1)`
1253
1369
  */
1254
1370
  nonempty(message) {
1255
1371
  return this.min(1, errorUtil.errToObj(message));
@@ -1308,9 +1424,15 @@ var ZodString = class _ZodString extends ZodType {
1308
1424
  get isIP() {
1309
1425
  return !!this._def.checks.find((ch) => ch.kind === "ip");
1310
1426
  }
1427
+ get isCIDR() {
1428
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1429
+ }
1311
1430
  get isBase64() {
1312
1431
  return !!this._def.checks.find((ch) => ch.kind === "base64");
1313
1432
  }
1433
+ get isBase64url() {
1434
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1435
+ }
1314
1436
  get minLength() {
1315
1437
  let min = null;
1316
1438
  for (const ch of this._def.checks) {
@@ -1584,17 +1706,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1584
1706
  }
1585
1707
  _parse(input) {
1586
1708
  if (this._def.coerce) {
1587
- input.data = BigInt(input.data);
1709
+ try {
1710
+ input.data = BigInt(input.data);
1711
+ } catch (_a) {
1712
+ return this._getInvalidInput(input);
1713
+ }
1588
1714
  }
1589
1715
  const parsedType = this._getType(input);
1590
1716
  if (parsedType !== ZodParsedType.bigint) {
1591
- const ctx2 = this._getOrReturnCtx(input);
1592
- addIssueToContext(ctx2, {
1593
- code: ZodIssueCode.invalid_type,
1594
- expected: ZodParsedType.bigint,
1595
- received: ctx2.parsedType
1596
- });
1597
- return INVALID;
1717
+ return this._getInvalidInput(input);
1598
1718
  }
1599
1719
  let ctx = void 0;
1600
1720
  const status = new ParseStatus();
@@ -1641,6 +1761,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1641
1761
  }
1642
1762
  return { status: status.value, value: input.data };
1643
1763
  }
1764
+ _getInvalidInput(input) {
1765
+ const ctx = this._getOrReturnCtx(input);
1766
+ addIssueToContext(ctx, {
1767
+ code: ZodIssueCode.invalid_type,
1768
+ expected: ZodParsedType.bigint,
1769
+ received: ctx.parsedType
1770
+ });
1771
+ return INVALID;
1772
+ }
1644
1773
  gte(value, message) {
1645
1774
  return this.setLimit("min", value, true, errorUtil.toString(message));
1646
1775
  }