@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.mjs CHANGED
@@ -18,7 +18,7 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
 
21
- // ../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.mjs
21
+ // ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
22
22
  var util;
23
23
  (function(util2) {
24
24
  util2.assertEqual = (val) => val;
@@ -169,6 +169,9 @@ var quotelessJson = (obj) => {
169
169
  return json.replace(/"([^"]+)":/g, "$1:");
170
170
  };
171
171
  var ZodError = class _ZodError extends Error {
172
+ get errors() {
173
+ return this.issues;
174
+ }
172
175
  constructor(issues) {
173
176
  super();
174
177
  this.issues = [];
@@ -187,9 +190,6 @@ var ZodError = class _ZodError extends Error {
187
190
  this.name = "ZodError";
188
191
  this.issues = issues;
189
192
  }
190
- get errors() {
191
- return this.issues;
192
- }
193
193
  format(_mapper) {
194
194
  const mapper = _mapper || function(issue) {
195
195
  return issue.message;
@@ -397,8 +397,11 @@ function addIssueToContext(ctx, issueData) {
397
397
  path: ctx.path,
398
398
  errorMaps: [
399
399
  ctx.common.contextualErrorMap,
400
+ // contextual error map is first priority
400
401
  ctx.schemaErrorMap,
402
+ // then schema-bound map if available
401
403
  overrideMap,
404
+ // then global override map
402
405
  overrideMap === errorMap ? void 0 : errorMap
403
406
  // then global default map
404
407
  ].filter((x) => !!x)
@@ -549,34 +552,6 @@ function processCreateParams(params) {
549
552
  return { errorMap: customMap, description };
550
553
  }
551
554
  var ZodType = class {
552
- constructor(def) {
553
- this.spa = this.safeParseAsync;
554
- this._def = def;
555
- this.parse = this.parse.bind(this);
556
- this.safeParse = this.safeParse.bind(this);
557
- this.parseAsync = this.parseAsync.bind(this);
558
- this.safeParseAsync = this.safeParseAsync.bind(this);
559
- this.spa = this.spa.bind(this);
560
- this.refine = this.refine.bind(this);
561
- this.refinement = this.refinement.bind(this);
562
- this.superRefine = this.superRefine.bind(this);
563
- this.optional = this.optional.bind(this);
564
- this.nullable = this.nullable.bind(this);
565
- this.nullish = this.nullish.bind(this);
566
- this.array = this.array.bind(this);
567
- this.promise = this.promise.bind(this);
568
- this.or = this.or.bind(this);
569
- this.and = this.and.bind(this);
570
- this.transform = this.transform.bind(this);
571
- this.brand = this.brand.bind(this);
572
- this.default = this.default.bind(this);
573
- this.catch = this.catch.bind(this);
574
- this.describe = this.describe.bind(this);
575
- this.pipe = this.pipe.bind(this);
576
- this.readonly = this.readonly.bind(this);
577
- this.isNullable = this.isNullable.bind(this);
578
- this.isOptional = this.isOptional.bind(this);
579
- }
580
555
  get description() {
581
556
  return this._def.description;
582
557
  }
@@ -640,6 +615,43 @@ var ZodType = class {
640
615
  const result = this._parseSync({ data, path: ctx.path, parent: ctx });
641
616
  return handleResult(ctx, result);
642
617
  }
618
+ "~validate"(data) {
619
+ var _a, _b;
620
+ const ctx = {
621
+ common: {
622
+ issues: [],
623
+ async: !!this["~standard"].async
624
+ },
625
+ path: [],
626
+ schemaErrorMap: this._def.errorMap,
627
+ parent: null,
628
+ data,
629
+ parsedType: getParsedType(data)
630
+ };
631
+ if (!this["~standard"].async) {
632
+ try {
633
+ const result = this._parseSync({ data, path: [], parent: ctx });
634
+ return isValid(result) ? {
635
+ value: result.value
636
+ } : {
637
+ issues: ctx.common.issues
638
+ };
639
+ } catch (err) {
640
+ 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")) {
641
+ this["~standard"].async = true;
642
+ }
643
+ ctx.common = {
644
+ issues: [],
645
+ async: true
646
+ };
647
+ }
648
+ }
649
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
650
+ value: result.value
651
+ } : {
652
+ issues: ctx.common.issues
653
+ });
654
+ }
643
655
  async parseAsync(data, params) {
644
656
  const result = await this.safeParseAsync(data, params);
645
657
  if (result.success)
@@ -716,6 +728,39 @@ var ZodType = class {
716
728
  superRefine(refinement) {
717
729
  return this._refinement(refinement);
718
730
  }
731
+ constructor(def) {
732
+ this.spa = this.safeParseAsync;
733
+ this._def = def;
734
+ this.parse = this.parse.bind(this);
735
+ this.safeParse = this.safeParse.bind(this);
736
+ this.parseAsync = this.parseAsync.bind(this);
737
+ this.safeParseAsync = this.safeParseAsync.bind(this);
738
+ this.spa = this.spa.bind(this);
739
+ this.refine = this.refine.bind(this);
740
+ this.refinement = this.refinement.bind(this);
741
+ this.superRefine = this.superRefine.bind(this);
742
+ this.optional = this.optional.bind(this);
743
+ this.nullable = this.nullable.bind(this);
744
+ this.nullish = this.nullish.bind(this);
745
+ this.array = this.array.bind(this);
746
+ this.promise = this.promise.bind(this);
747
+ this.or = this.or.bind(this);
748
+ this.and = this.and.bind(this);
749
+ this.transform = this.transform.bind(this);
750
+ this.brand = this.brand.bind(this);
751
+ this.default = this.default.bind(this);
752
+ this.catch = this.catch.bind(this);
753
+ this.describe = this.describe.bind(this);
754
+ this.pipe = this.pipe.bind(this);
755
+ this.readonly = this.readonly.bind(this);
756
+ this.isNullable = this.isNullable.bind(this);
757
+ this.isOptional = this.isOptional.bind(this);
758
+ this["~standard"] = {
759
+ version: 1,
760
+ vendor: "zod",
761
+ validate: (data) => this["~validate"](data)
762
+ };
763
+ }
719
764
  optional() {
720
765
  return ZodOptional.create(this, this._def);
721
766
  }
@@ -726,7 +771,7 @@ var ZodType = class {
726
771
  return this.nullable().optional();
727
772
  }
728
773
  array() {
729
- return ZodArray.create(this, this._def);
774
+ return ZodArray.create(this);
730
775
  }
731
776
  promise() {
732
777
  return ZodPromise.create(this, this._def);
@@ -787,16 +832,20 @@ var ZodType = class {
787
832
  };
788
833
  var cuidRegex = /^c[^\s-]{8,}$/i;
789
834
  var cuid2Regex = /^[0-9a-z]+$/;
790
- var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
835
+ var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
791
836
  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;
792
837
  var nanoidRegex = /^[a-z0-9_-]{21}$/i;
838
+ var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
793
839
  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)?)??$/;
794
840
  var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
795
841
  var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
796
842
  var emojiRegex;
797
843
  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])$/;
798
- 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})))$/;
844
+ 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])$/;
845
+ 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]))$/;
846
+ 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])$/;
799
847
  var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
848
+ var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
800
849
  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])))`;
801
850
  var dateRegex = new RegExp(`^${dateRegexSource}$`);
802
851
  function timeRegexSource(args) {
@@ -829,6 +878,33 @@ function isValidIP(ip, version) {
829
878
  }
830
879
  return false;
831
880
  }
881
+ function isValidJWT(jwt, alg) {
882
+ if (!jwtRegex.test(jwt))
883
+ return false;
884
+ try {
885
+ const [header] = jwt.split(".");
886
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
887
+ const decoded = JSON.parse(atob(base64));
888
+ if (typeof decoded !== "object" || decoded === null)
889
+ return false;
890
+ if (!decoded.typ || !decoded.alg)
891
+ return false;
892
+ if (alg && decoded.alg !== alg)
893
+ return false;
894
+ return true;
895
+ } catch (_a) {
896
+ return false;
897
+ }
898
+ }
899
+ function isValidCidr(ip, version) {
900
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
901
+ return true;
902
+ }
903
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
904
+ return true;
905
+ }
906
+ return false;
907
+ }
832
908
  var ZodString = class _ZodString extends ZodType {
833
909
  _parse(input) {
834
910
  if (this._def.coerce) {
@@ -1085,6 +1161,26 @@ var ZodString = class _ZodString extends ZodType {
1085
1161
  });
1086
1162
  status.dirty();
1087
1163
  }
1164
+ } else if (check.kind === "jwt") {
1165
+ if (!isValidJWT(input.data, check.alg)) {
1166
+ ctx = this._getOrReturnCtx(input, ctx);
1167
+ addIssueToContext(ctx, {
1168
+ validation: "jwt",
1169
+ code: ZodIssueCode.invalid_string,
1170
+ message: check.message
1171
+ });
1172
+ status.dirty();
1173
+ }
1174
+ } else if (check.kind === "cidr") {
1175
+ if (!isValidCidr(input.data, check.version)) {
1176
+ ctx = this._getOrReturnCtx(input, ctx);
1177
+ addIssueToContext(ctx, {
1178
+ validation: "cidr",
1179
+ code: ZodIssueCode.invalid_string,
1180
+ message: check.message
1181
+ });
1182
+ status.dirty();
1183
+ }
1088
1184
  } else if (check.kind === "base64") {
1089
1185
  if (!base64Regex.test(input.data)) {
1090
1186
  ctx = this._getOrReturnCtx(input, ctx);
@@ -1095,6 +1191,16 @@ var ZodString = class _ZodString extends ZodType {
1095
1191
  });
1096
1192
  status.dirty();
1097
1193
  }
1194
+ } else if (check.kind === "base64url") {
1195
+ if (!base64urlRegex.test(input.data)) {
1196
+ ctx = this._getOrReturnCtx(input, ctx);
1197
+ addIssueToContext(ctx, {
1198
+ validation: "base64url",
1199
+ code: ZodIssueCode.invalid_string,
1200
+ message: check.message
1201
+ });
1202
+ status.dirty();
1203
+ }
1098
1204
  } else {
1099
1205
  util.assertNever(check);
1100
1206
  }
@@ -1139,9 +1245,20 @@ var ZodString = class _ZodString extends ZodType {
1139
1245
  base64(message) {
1140
1246
  return this._addCheck(__spreadValues({ kind: "base64" }, errorUtil.errToObj(message)));
1141
1247
  }
1248
+ base64url(message) {
1249
+ return this._addCheck(__spreadValues({
1250
+ kind: "base64url"
1251
+ }, errorUtil.errToObj(message)));
1252
+ }
1253
+ jwt(options) {
1254
+ return this._addCheck(__spreadValues({ kind: "jwt" }, errorUtil.errToObj(options)));
1255
+ }
1142
1256
  ip(options) {
1143
1257
  return this._addCheck(__spreadValues({ kind: "ip" }, errorUtil.errToObj(options)));
1144
1258
  }
1259
+ cidr(options) {
1260
+ return this._addCheck(__spreadValues({ kind: "cidr" }, errorUtil.errToObj(options)));
1261
+ }
1145
1262
  datetime(options) {
1146
1263
  var _a, _b;
1147
1264
  if (typeof options === "string") {
@@ -1223,8 +1340,7 @@ var ZodString = class _ZodString extends ZodType {
1223
1340
  }, errorUtil.errToObj(message)));
1224
1341
  }
1225
1342
  /**
1226
- * @deprecated Use z.string().min(1) instead.
1227
- * @see {@link ZodString.min}
1343
+ * Equivalent to `.min(1)`
1228
1344
  */
1229
1345
  nonempty(message) {
1230
1346
  return this.min(1, errorUtil.errToObj(message));
@@ -1283,9 +1399,15 @@ var ZodString = class _ZodString extends ZodType {
1283
1399
  get isIP() {
1284
1400
  return !!this._def.checks.find((ch) => ch.kind === "ip");
1285
1401
  }
1402
+ get isCIDR() {
1403
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1404
+ }
1286
1405
  get isBase64() {
1287
1406
  return !!this._def.checks.find((ch) => ch.kind === "base64");
1288
1407
  }
1408
+ get isBase64url() {
1409
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1410
+ }
1289
1411
  get minLength() {
1290
1412
  let min = null;
1291
1413
  for (const ch of this._def.checks) {
@@ -1559,17 +1681,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1559
1681
  }
1560
1682
  _parse(input) {
1561
1683
  if (this._def.coerce) {
1562
- input.data = BigInt(input.data);
1684
+ try {
1685
+ input.data = BigInt(input.data);
1686
+ } catch (_a) {
1687
+ return this._getInvalidInput(input);
1688
+ }
1563
1689
  }
1564
1690
  const parsedType = this._getType(input);
1565
1691
  if (parsedType !== ZodParsedType.bigint) {
1566
- const ctx2 = this._getOrReturnCtx(input);
1567
- addIssueToContext(ctx2, {
1568
- code: ZodIssueCode.invalid_type,
1569
- expected: ZodParsedType.bigint,
1570
- received: ctx2.parsedType
1571
- });
1572
- return INVALID;
1692
+ return this._getInvalidInput(input);
1573
1693
  }
1574
1694
  let ctx = void 0;
1575
1695
  const status = new ParseStatus();
@@ -1616,6 +1736,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1616
1736
  }
1617
1737
  return { status: status.value, value: input.data };
1618
1738
  }
1739
+ _getInvalidInput(input) {
1740
+ const ctx = this._getOrReturnCtx(input);
1741
+ addIssueToContext(ctx, {
1742
+ code: ZodIssueCode.invalid_type,
1743
+ expected: ZodParsedType.bigint,
1744
+ received: ctx.parsedType
1745
+ });
1746
+ return INVALID;
1747
+ }
1619
1748
  gte(value, message) {
1620
1749
  return this.setLimit("min", value, true, errorUtil.toString(message));
1621
1750
  }