@tahanabavi/typefetch 1.3.0 → 1.4.1

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/dist/index.js CHANGED
@@ -1,37 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __pow = Math.pow;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
- var __objRest = (source, exclude) => {
24
- var target = {};
25
- for (var prop in source)
26
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
27
- target[prop] = source[prop];
28
- if (source != null && __getOwnPropSymbols)
29
- for (var prop of __getOwnPropSymbols(source)) {
30
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
31
- target[prop] = source[prop];
32
- }
33
- return target;
34
- };
35
5
  var __export = (target, all) => {
36
6
  for (var name in all)
37
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -45,26 +15,6 @@ var __copyProps = (to, from, except, desc) => {
45
15
  return to;
46
16
  };
47
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
48
- var __async = (__this, __arguments, generator) => {
49
- return new Promise((resolve, reject) => {
50
- var fulfilled = (value) => {
51
- try {
52
- step(generator.next(value));
53
- } catch (e) {
54
- reject(e);
55
- }
56
- };
57
- var rejected = (value) => {
58
- try {
59
- step(generator.throw(value));
60
- } catch (e) {
61
- reject(e);
62
- }
63
- };
64
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
65
- step((generator = generator.apply(__this, __arguments)).next());
66
- });
67
- };
68
18
 
69
19
  // src/index.ts
70
20
  var index_exports = {};
@@ -254,7 +204,11 @@ var util;
254
204
  var objectUtil;
255
205
  (function(objectUtil2) {
256
206
  objectUtil2.mergeShapes = (first, second) => {
257
- return __spreadValues(__spreadValues({}, first), second);
207
+ return {
208
+ ...first,
209
+ ...second
210
+ // second overwrites first
211
+ };
258
212
  };
259
213
  })(objectUtil || (objectUtil = {}));
260
214
  var ZodParsedType = util.arrayToEnum([
@@ -555,24 +509,27 @@ function getErrorMap() {
555
509
  var makeIssue = (params) => {
556
510
  const { data, path, errorMaps, issueData } = params;
557
511
  const fullPath = [...path, ...issueData.path || []];
558
- const fullIssue = __spreadProps(__spreadValues({}, issueData), {
512
+ const fullIssue = {
513
+ ...issueData,
559
514
  path: fullPath
560
- });
515
+ };
561
516
  if (issueData.message !== void 0) {
562
- return __spreadProps(__spreadValues({}, issueData), {
517
+ return {
518
+ ...issueData,
563
519
  path: fullPath,
564
520
  message: issueData.message
565
- });
521
+ };
566
522
  }
567
523
  let errorMessage = "";
568
524
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
569
525
  for (const map of maps) {
570
526
  errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
571
527
  }
572
- return __spreadProps(__spreadValues({}, issueData), {
528
+ return {
529
+ ...issueData,
573
530
  path: fullPath,
574
531
  message: errorMessage
575
- });
532
+ };
576
533
  };
577
534
  var EMPTY_PATH = [];
578
535
  function addIssueToContext(ctx, issueData) {
@@ -617,19 +574,17 @@ var ParseStatus = class _ParseStatus {
617
574
  }
618
575
  return { status: status.value, value: arrayValue };
619
576
  }
620
- static mergeObjectAsync(status, pairs) {
621
- return __async(this, null, function* () {
622
- const syncPairs = [];
623
- for (const pair of pairs) {
624
- const key = yield pair.key;
625
- const value = yield pair.value;
626
- syncPairs.push({
627
- key,
628
- value
629
- });
630
- }
631
- return _ParseStatus.mergeObjectSync(status, syncPairs);
632
- });
577
+ static async mergeObjectAsync(status, pairs) {
578
+ const syncPairs = [];
579
+ for (const pair of pairs) {
580
+ const key = await pair.key;
581
+ const value = await pair.value;
582
+ syncPairs.push({
583
+ key,
584
+ value
585
+ });
586
+ }
587
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
633
588
  }
634
589
  static mergeObjectSync(status, pairs) {
635
590
  const finalObject = {};
@@ -664,7 +619,7 @@ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
664
619
  var errorUtil;
665
620
  (function(errorUtil2) {
666
621
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
667
- errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
622
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
668
623
  })(errorUtil || (errorUtil = {}));
669
624
 
670
625
  // node_modules/zod/v3/types.js
@@ -716,17 +671,16 @@ function processCreateParams(params) {
716
671
  if (errorMap2)
717
672
  return { errorMap: errorMap2, description };
718
673
  const customMap = (iss, ctx) => {
719
- var _a, _b;
720
674
  const { message } = params;
721
675
  if (iss.code === "invalid_enum_value") {
722
- return { message: message != null ? message : ctx.defaultError };
676
+ return { message: message ?? ctx.defaultError };
723
677
  }
724
678
  if (typeof ctx.data === "undefined") {
725
- return { message: (_a = message != null ? message : required_error) != null ? _a : ctx.defaultError };
679
+ return { message: message ?? required_error ?? ctx.defaultError };
726
680
  }
727
681
  if (iss.code !== "invalid_type")
728
682
  return { message: ctx.defaultError };
729
- return { message: (_b = message != null ? message : invalid_type_error) != null ? _b : ctx.defaultError };
683
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
730
684
  };
731
685
  return { errorMap: customMap, description };
732
686
  }
@@ -778,14 +732,13 @@ var ZodType = class {
778
732
  throw result.error;
779
733
  }
780
734
  safeParse(data, params) {
781
- var _a;
782
735
  const ctx = {
783
736
  common: {
784
737
  issues: [],
785
- async: (_a = params == null ? void 0 : params.async) != null ? _a : false,
786
- contextualErrorMap: params == null ? void 0 : params.errorMap
738
+ async: params?.async ?? false,
739
+ contextualErrorMap: params?.errorMap
787
740
  },
788
- path: (params == null ? void 0 : params.path) || [],
741
+ path: params?.path || [],
789
742
  schemaErrorMap: this._def.errorMap,
790
743
  parent: null,
791
744
  data,
@@ -795,7 +748,6 @@ var ZodType = class {
795
748
  return handleResult(ctx, result);
796
749
  }
797
750
  "~validate"(data) {
798
- var _a, _b;
799
751
  const ctx = {
800
752
  common: {
801
753
  issues: [],
@@ -816,7 +768,7 @@ var ZodType = class {
816
768
  issues: ctx.common.issues
817
769
  };
818
770
  } catch (err) {
819
- if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
771
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
820
772
  this["~standard"].async = true;
821
773
  }
822
774
  ctx.common = {
@@ -831,32 +783,28 @@ var ZodType = class {
831
783
  issues: ctx.common.issues
832
784
  });
833
785
  }
834
- parseAsync(data, params) {
835
- return __async(this, null, function* () {
836
- const result = yield this.safeParseAsync(data, params);
837
- if (result.success)
838
- return result.data;
839
- throw result.error;
840
- });
786
+ async parseAsync(data, params) {
787
+ const result = await this.safeParseAsync(data, params);
788
+ if (result.success)
789
+ return result.data;
790
+ throw result.error;
841
791
  }
842
- safeParseAsync(data, params) {
843
- return __async(this, null, function* () {
844
- const ctx = {
845
- common: {
846
- issues: [],
847
- contextualErrorMap: params == null ? void 0 : params.errorMap,
848
- async: true
849
- },
850
- path: (params == null ? void 0 : params.path) || [],
851
- schemaErrorMap: this._def.errorMap,
852
- parent: null,
853
- data,
854
- parsedType: getParsedType(data)
855
- };
856
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
857
- const result = yield isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult);
858
- return handleResult(ctx, result);
859
- });
792
+ async safeParseAsync(data, params) {
793
+ const ctx = {
794
+ common: {
795
+ issues: [],
796
+ contextualErrorMap: params?.errorMap,
797
+ async: true
798
+ },
799
+ path: params?.path || [],
800
+ schemaErrorMap: this._def.errorMap,
801
+ parent: null,
802
+ data,
803
+ parsedType: getParsedType(data)
804
+ };
805
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
806
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
807
+ return handleResult(ctx, result);
860
808
  }
861
809
  refine(check, message) {
862
810
  const getIssueProperties = (val) => {
@@ -870,9 +818,10 @@ var ZodType = class {
870
818
  };
871
819
  return this._refinement((val, ctx) => {
872
820
  const result = check(val);
873
- const setError = () => ctx.addIssue(__spreadValues({
874
- code: ZodIssueCode.custom
875
- }, getIssueProperties(val)));
821
+ const setError = () => ctx.addIssue({
822
+ code: ZodIssueCode.custom,
823
+ ...getIssueProperties(val)
824
+ });
876
825
  if (typeof Promise !== "undefined" && result instanceof Promise) {
877
826
  return result.then((data) => {
878
827
  if (!data) {
@@ -966,39 +915,44 @@ var ZodType = class {
966
915
  return ZodIntersection.create(this, incoming, this._def);
967
916
  }
968
917
  transform(transform) {
969
- return new ZodEffects(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
918
+ return new ZodEffects({
919
+ ...processCreateParams(this._def),
970
920
  schema: this,
971
921
  typeName: ZodFirstPartyTypeKind.ZodEffects,
972
922
  effect: { type: "transform", transform }
973
- }));
923
+ });
974
924
  }
975
925
  default(def) {
976
926
  const defaultValueFunc = typeof def === "function" ? def : () => def;
977
- return new ZodDefault(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
927
+ return new ZodDefault({
928
+ ...processCreateParams(this._def),
978
929
  innerType: this,
979
930
  defaultValue: defaultValueFunc,
980
931
  typeName: ZodFirstPartyTypeKind.ZodDefault
981
- }));
932
+ });
982
933
  }
983
934
  brand() {
984
- return new ZodBranded(__spreadValues({
935
+ return new ZodBranded({
985
936
  typeName: ZodFirstPartyTypeKind.ZodBranded,
986
- type: this
987
- }, processCreateParams(this._def)));
937
+ type: this,
938
+ ...processCreateParams(this._def)
939
+ });
988
940
  }
989
941
  catch(def) {
990
942
  const catchValueFunc = typeof def === "function" ? def : () => def;
991
- return new ZodCatch(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
943
+ return new ZodCatch({
944
+ ...processCreateParams(this._def),
992
945
  innerType: this,
993
946
  catchValue: catchValueFunc,
994
947
  typeName: ZodFirstPartyTypeKind.ZodCatch
995
- }));
948
+ });
996
949
  }
997
950
  describe(description) {
998
951
  const This = this.constructor;
999
- return new This(__spreadProps(__spreadValues({}, this._def), {
952
+ return new This({
953
+ ...this._def,
1000
954
  description
1001
- }));
955
+ });
1002
956
  }
1003
957
  pipe(target) {
1004
958
  return ZodPipeline.create(this, target);
@@ -1073,14 +1027,14 @@ function isValidJWT(jwt, alg) {
1073
1027
  const decoded = JSON.parse(atob(base64));
1074
1028
  if (typeof decoded !== "object" || decoded === null)
1075
1029
  return false;
1076
- if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
1030
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1077
1031
  return false;
1078
1032
  if (!decoded.alg)
1079
1033
  return false;
1080
1034
  if (alg && decoded.alg !== alg)
1081
1035
  return false;
1082
1036
  return true;
1083
- } catch (e) {
1037
+ } catch {
1084
1038
  return false;
1085
1039
  }
1086
1040
  }
@@ -1239,7 +1193,7 @@ var ZodString = class _ZodString extends ZodType {
1239
1193
  } else if (check.kind === "url") {
1240
1194
  try {
1241
1195
  new URL(input.data);
1242
- } catch (e) {
1196
+ } catch {
1243
1197
  ctx = this._getOrReturnCtx(input, ctx);
1244
1198
  addIssueToContext(ctx, {
1245
1199
  validation: "url",
@@ -1396,59 +1350,61 @@ var ZodString = class _ZodString extends ZodType {
1396
1350
  return { status: status.value, value: input.data };
1397
1351
  }
1398
1352
  _regex(regex, validation, message) {
1399
- return this.refinement((data) => regex.test(data), __spreadValues({
1353
+ return this.refinement((data) => regex.test(data), {
1400
1354
  validation,
1401
- code: ZodIssueCode.invalid_string
1402
- }, errorUtil.errToObj(message)));
1355
+ code: ZodIssueCode.invalid_string,
1356
+ ...errorUtil.errToObj(message)
1357
+ });
1403
1358
  }
1404
1359
  _addCheck(check) {
1405
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1360
+ return new _ZodString({
1361
+ ...this._def,
1406
1362
  checks: [...this._def.checks, check]
1407
- }));
1363
+ });
1408
1364
  }
1409
1365
  email(message) {
1410
- return this._addCheck(__spreadValues({ kind: "email" }, errorUtil.errToObj(message)));
1366
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1411
1367
  }
1412
1368
  url(message) {
1413
- return this._addCheck(__spreadValues({ kind: "url" }, errorUtil.errToObj(message)));
1369
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1414
1370
  }
1415
1371
  emoji(message) {
1416
- return this._addCheck(__spreadValues({ kind: "emoji" }, errorUtil.errToObj(message)));
1372
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1417
1373
  }
1418
1374
  uuid(message) {
1419
- return this._addCheck(__spreadValues({ kind: "uuid" }, errorUtil.errToObj(message)));
1375
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1420
1376
  }
1421
1377
  nanoid(message) {
1422
- return this._addCheck(__spreadValues({ kind: "nanoid" }, errorUtil.errToObj(message)));
1378
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1423
1379
  }
1424
1380
  cuid(message) {
1425
- return this._addCheck(__spreadValues({ kind: "cuid" }, errorUtil.errToObj(message)));
1381
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1426
1382
  }
1427
1383
  cuid2(message) {
1428
- return this._addCheck(__spreadValues({ kind: "cuid2" }, errorUtil.errToObj(message)));
1384
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1429
1385
  }
1430
1386
  ulid(message) {
1431
- return this._addCheck(__spreadValues({ kind: "ulid" }, errorUtil.errToObj(message)));
1387
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1432
1388
  }
1433
1389
  base64(message) {
1434
- return this._addCheck(__spreadValues({ kind: "base64" }, errorUtil.errToObj(message)));
1390
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1435
1391
  }
1436
1392
  base64url(message) {
1437
- return this._addCheck(__spreadValues({
1438
- kind: "base64url"
1439
- }, errorUtil.errToObj(message)));
1393
+ return this._addCheck({
1394
+ kind: "base64url",
1395
+ ...errorUtil.errToObj(message)
1396
+ });
1440
1397
  }
1441
1398
  jwt(options) {
1442
- return this._addCheck(__spreadValues({ kind: "jwt" }, errorUtil.errToObj(options)));
1399
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1443
1400
  }
1444
1401
  ip(options) {
1445
- return this._addCheck(__spreadValues({ kind: "ip" }, errorUtil.errToObj(options)));
1402
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1446
1403
  }
1447
1404
  cidr(options) {
1448
- return this._addCheck(__spreadValues({ kind: "cidr" }, errorUtil.errToObj(options)));
1405
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1449
1406
  }
1450
1407
  datetime(options) {
1451
- var _a, _b;
1452
1408
  if (typeof options === "string") {
1453
1409
  return this._addCheck({
1454
1410
  kind: "datetime",
@@ -1458,12 +1414,13 @@ var ZodString = class _ZodString extends ZodType {
1458
1414
  message: options
1459
1415
  });
1460
1416
  }
1461
- return this._addCheck(__spreadValues({
1417
+ return this._addCheck({
1462
1418
  kind: "datetime",
1463
- precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
1464
- offset: (_a = options == null ? void 0 : options.offset) != null ? _a : false,
1465
- local: (_b = options == null ? void 0 : options.local) != null ? _b : false
1466
- }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1419
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1420
+ offset: options?.offset ?? false,
1421
+ local: options?.local ?? false,
1422
+ ...errorUtil.errToObj(options?.message)
1423
+ });
1467
1424
  }
1468
1425
  date(message) {
1469
1426
  return this._addCheck({ kind: "date", message });
@@ -1476,56 +1433,64 @@ var ZodString = class _ZodString extends ZodType {
1476
1433
  message: options
1477
1434
  });
1478
1435
  }
1479
- return this._addCheck(__spreadValues({
1436
+ return this._addCheck({
1480
1437
  kind: "time",
1481
- precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision
1482
- }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1438
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1439
+ ...errorUtil.errToObj(options?.message)
1440
+ });
1483
1441
  }
1484
1442
  duration(message) {
1485
- return this._addCheck(__spreadValues({ kind: "duration" }, errorUtil.errToObj(message)));
1443
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1486
1444
  }
1487
1445
  regex(regex, message) {
1488
- return this._addCheck(__spreadValues({
1446
+ return this._addCheck({
1489
1447
  kind: "regex",
1490
- regex
1491
- }, errorUtil.errToObj(message)));
1448
+ regex,
1449
+ ...errorUtil.errToObj(message)
1450
+ });
1492
1451
  }
1493
1452
  includes(value, options) {
1494
- return this._addCheck(__spreadValues({
1453
+ return this._addCheck({
1495
1454
  kind: "includes",
1496
1455
  value,
1497
- position: options == null ? void 0 : options.position
1498
- }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1456
+ position: options?.position,
1457
+ ...errorUtil.errToObj(options?.message)
1458
+ });
1499
1459
  }
1500
1460
  startsWith(value, message) {
1501
- return this._addCheck(__spreadValues({
1461
+ return this._addCheck({
1502
1462
  kind: "startsWith",
1503
- value
1504
- }, errorUtil.errToObj(message)));
1463
+ value,
1464
+ ...errorUtil.errToObj(message)
1465
+ });
1505
1466
  }
1506
1467
  endsWith(value, message) {
1507
- return this._addCheck(__spreadValues({
1468
+ return this._addCheck({
1508
1469
  kind: "endsWith",
1509
- value
1510
- }, errorUtil.errToObj(message)));
1470
+ value,
1471
+ ...errorUtil.errToObj(message)
1472
+ });
1511
1473
  }
1512
1474
  min(minLength, message) {
1513
- return this._addCheck(__spreadValues({
1475
+ return this._addCheck({
1514
1476
  kind: "min",
1515
- value: minLength
1516
- }, errorUtil.errToObj(message)));
1477
+ value: minLength,
1478
+ ...errorUtil.errToObj(message)
1479
+ });
1517
1480
  }
1518
1481
  max(maxLength, message) {
1519
- return this._addCheck(__spreadValues({
1482
+ return this._addCheck({
1520
1483
  kind: "max",
1521
- value: maxLength
1522
- }, errorUtil.errToObj(message)));
1484
+ value: maxLength,
1485
+ ...errorUtil.errToObj(message)
1486
+ });
1523
1487
  }
1524
1488
  length(len, message) {
1525
- return this._addCheck(__spreadValues({
1489
+ return this._addCheck({
1526
1490
  kind: "length",
1527
- value: len
1528
- }, errorUtil.errToObj(message)));
1491
+ value: len,
1492
+ ...errorUtil.errToObj(message)
1493
+ });
1529
1494
  }
1530
1495
  /**
1531
1496
  * Equivalent to `.min(1)`
@@ -1534,19 +1499,22 @@ var ZodString = class _ZodString extends ZodType {
1534
1499
  return this.min(1, errorUtil.errToObj(message));
1535
1500
  }
1536
1501
  trim() {
1537
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1502
+ return new _ZodString({
1503
+ ...this._def,
1538
1504
  checks: [...this._def.checks, { kind: "trim" }]
1539
- }));
1505
+ });
1540
1506
  }
1541
1507
  toLowerCase() {
1542
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1508
+ return new _ZodString({
1509
+ ...this._def,
1543
1510
  checks: [...this._def.checks, { kind: "toLowerCase" }]
1544
- }));
1511
+ });
1545
1512
  }
1546
1513
  toUpperCase() {
1547
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1514
+ return new _ZodString({
1515
+ ...this._def,
1548
1516
  checks: [...this._def.checks, { kind: "toUpperCase" }]
1549
- }));
1517
+ });
1550
1518
  }
1551
1519
  get isDatetime() {
1552
1520
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
@@ -1618,12 +1586,12 @@ var ZodString = class _ZodString extends ZodType {
1618
1586
  }
1619
1587
  };
1620
1588
  ZodString.create = (params) => {
1621
- var _a;
1622
- return new ZodString(__spreadValues({
1589
+ return new ZodString({
1623
1590
  checks: [],
1624
1591
  typeName: ZodFirstPartyTypeKind.ZodString,
1625
- coerce: (_a = params == null ? void 0 : params.coerce) != null ? _a : false
1626
- }, processCreateParams(params)));
1592
+ coerce: params?.coerce ?? false,
1593
+ ...processCreateParams(params)
1594
+ });
1627
1595
  };
1628
1596
  function floatSafeRemainder(val, step) {
1629
1597
  const valDecCount = (val.toString().split(".")[1] || "").length;
@@ -1631,7 +1599,7 @@ function floatSafeRemainder(val, step) {
1631
1599
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1632
1600
  const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1633
1601
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1634
- return valInt % stepInt / __pow(10, decCount);
1602
+ return valInt % stepInt / 10 ** decCount;
1635
1603
  }
1636
1604
  var ZodNumber = class _ZodNumber extends ZodType {
1637
1605
  constructor() {
@@ -1734,7 +1702,8 @@ var ZodNumber = class _ZodNumber extends ZodType {
1734
1702
  return this.setLimit("max", value, false, errorUtil.toString(message));
1735
1703
  }
1736
1704
  setLimit(kind, value, inclusive, message) {
1737
- return new _ZodNumber(__spreadProps(__spreadValues({}, this._def), {
1705
+ return new _ZodNumber({
1706
+ ...this._def,
1738
1707
  checks: [
1739
1708
  ...this._def.checks,
1740
1709
  {
@@ -1744,12 +1713,13 @@ var ZodNumber = class _ZodNumber extends ZodType {
1744
1713
  message: errorUtil.toString(message)
1745
1714
  }
1746
1715
  ]
1747
- }));
1716
+ });
1748
1717
  }
1749
1718
  _addCheck(check) {
1750
- return new _ZodNumber(__spreadProps(__spreadValues({}, this._def), {
1719
+ return new _ZodNumber({
1720
+ ...this._def,
1751
1721
  checks: [...this._def.checks, check]
1752
- }));
1722
+ });
1753
1723
  }
1754
1724
  int(message) {
1755
1725
  return this._addCheck({
@@ -1856,11 +1826,12 @@ var ZodNumber = class _ZodNumber extends ZodType {
1856
1826
  }
1857
1827
  };
1858
1828
  ZodNumber.create = (params) => {
1859
- return new ZodNumber(__spreadValues({
1829
+ return new ZodNumber({
1860
1830
  checks: [],
1861
1831
  typeName: ZodFirstPartyTypeKind.ZodNumber,
1862
- coerce: (params == null ? void 0 : params.coerce) || false
1863
- }, processCreateParams(params)));
1832
+ coerce: params?.coerce || false,
1833
+ ...processCreateParams(params)
1834
+ });
1864
1835
  };
1865
1836
  var ZodBigInt = class _ZodBigInt extends ZodType {
1866
1837
  constructor() {
@@ -1872,7 +1843,7 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1872
1843
  if (this._def.coerce) {
1873
1844
  try {
1874
1845
  input.data = BigInt(input.data);
1875
- } catch (e) {
1846
+ } catch {
1876
1847
  return this._getInvalidInput(input);
1877
1848
  }
1878
1849
  }
@@ -1947,7 +1918,8 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1947
1918
  return this.setLimit("max", value, false, errorUtil.toString(message));
1948
1919
  }
1949
1920
  setLimit(kind, value, inclusive, message) {
1950
- return new _ZodBigInt(__spreadProps(__spreadValues({}, this._def), {
1921
+ return new _ZodBigInt({
1922
+ ...this._def,
1951
1923
  checks: [
1952
1924
  ...this._def.checks,
1953
1925
  {
@@ -1957,12 +1929,13 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1957
1929
  message: errorUtil.toString(message)
1958
1930
  }
1959
1931
  ]
1960
- }));
1932
+ });
1961
1933
  }
1962
1934
  _addCheck(check) {
1963
- return new _ZodBigInt(__spreadProps(__spreadValues({}, this._def), {
1935
+ return new _ZodBigInt({
1936
+ ...this._def,
1964
1937
  checks: [...this._def.checks, check]
1965
- }));
1938
+ });
1966
1939
  }
1967
1940
  positive(message) {
1968
1941
  return this._addCheck({
@@ -2025,12 +1998,12 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
2025
1998
  }
2026
1999
  };
2027
2000
  ZodBigInt.create = (params) => {
2028
- var _a;
2029
- return new ZodBigInt(__spreadValues({
2001
+ return new ZodBigInt({
2030
2002
  checks: [],
2031
2003
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2032
- coerce: (_a = params == null ? void 0 : params.coerce) != null ? _a : false
2033
- }, processCreateParams(params)));
2004
+ coerce: params?.coerce ?? false,
2005
+ ...processCreateParams(params)
2006
+ });
2034
2007
  };
2035
2008
  var ZodBoolean = class extends ZodType {
2036
2009
  _parse(input) {
@@ -2051,10 +2024,11 @@ var ZodBoolean = class extends ZodType {
2051
2024
  }
2052
2025
  };
2053
2026
  ZodBoolean.create = (params) => {
2054
- return new ZodBoolean(__spreadValues({
2027
+ return new ZodBoolean({
2055
2028
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
2056
- coerce: (params == null ? void 0 : params.coerce) || false
2057
- }, processCreateParams(params)));
2029
+ coerce: params?.coerce || false,
2030
+ ...processCreateParams(params)
2031
+ });
2058
2032
  };
2059
2033
  var ZodDate = class _ZodDate extends ZodType {
2060
2034
  _parse(input) {
@@ -2117,9 +2091,10 @@ var ZodDate = class _ZodDate extends ZodType {
2117
2091
  };
2118
2092
  }
2119
2093
  _addCheck(check) {
2120
- return new _ZodDate(__spreadProps(__spreadValues({}, this._def), {
2094
+ return new _ZodDate({
2095
+ ...this._def,
2121
2096
  checks: [...this._def.checks, check]
2122
- }));
2097
+ });
2123
2098
  }
2124
2099
  min(minDate, message) {
2125
2100
  return this._addCheck({
@@ -2157,11 +2132,12 @@ var ZodDate = class _ZodDate extends ZodType {
2157
2132
  }
2158
2133
  };
2159
2134
  ZodDate.create = (params) => {
2160
- return new ZodDate(__spreadValues({
2135
+ return new ZodDate({
2161
2136
  checks: [],
2162
- coerce: (params == null ? void 0 : params.coerce) || false,
2163
- typeName: ZodFirstPartyTypeKind.ZodDate
2164
- }, processCreateParams(params)));
2137
+ coerce: params?.coerce || false,
2138
+ typeName: ZodFirstPartyTypeKind.ZodDate,
2139
+ ...processCreateParams(params)
2140
+ });
2165
2141
  };
2166
2142
  var ZodSymbol = class extends ZodType {
2167
2143
  _parse(input) {
@@ -2179,9 +2155,10 @@ var ZodSymbol = class extends ZodType {
2179
2155
  }
2180
2156
  };
2181
2157
  ZodSymbol.create = (params) => {
2182
- return new ZodSymbol(__spreadValues({
2183
- typeName: ZodFirstPartyTypeKind.ZodSymbol
2184
- }, processCreateParams(params)));
2158
+ return new ZodSymbol({
2159
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2160
+ ...processCreateParams(params)
2161
+ });
2185
2162
  };
2186
2163
  var ZodUndefined = class extends ZodType {
2187
2164
  _parse(input) {
@@ -2199,9 +2176,10 @@ var ZodUndefined = class extends ZodType {
2199
2176
  }
2200
2177
  };
2201
2178
  ZodUndefined.create = (params) => {
2202
- return new ZodUndefined(__spreadValues({
2203
- typeName: ZodFirstPartyTypeKind.ZodUndefined
2204
- }, processCreateParams(params)));
2179
+ return new ZodUndefined({
2180
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2181
+ ...processCreateParams(params)
2182
+ });
2205
2183
  };
2206
2184
  var ZodNull = class extends ZodType {
2207
2185
  _parse(input) {
@@ -2219,9 +2197,10 @@ var ZodNull = class extends ZodType {
2219
2197
  }
2220
2198
  };
2221
2199
  ZodNull.create = (params) => {
2222
- return new ZodNull(__spreadValues({
2223
- typeName: ZodFirstPartyTypeKind.ZodNull
2224
- }, processCreateParams(params)));
2200
+ return new ZodNull({
2201
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2202
+ ...processCreateParams(params)
2203
+ });
2225
2204
  };
2226
2205
  var ZodAny = class extends ZodType {
2227
2206
  constructor() {
@@ -2233,9 +2212,10 @@ var ZodAny = class extends ZodType {
2233
2212
  }
2234
2213
  };
2235
2214
  ZodAny.create = (params) => {
2236
- return new ZodAny(__spreadValues({
2237
- typeName: ZodFirstPartyTypeKind.ZodAny
2238
- }, processCreateParams(params)));
2215
+ return new ZodAny({
2216
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2217
+ ...processCreateParams(params)
2218
+ });
2239
2219
  };
2240
2220
  var ZodUnknown = class extends ZodType {
2241
2221
  constructor() {
@@ -2247,9 +2227,10 @@ var ZodUnknown = class extends ZodType {
2247
2227
  }
2248
2228
  };
2249
2229
  ZodUnknown.create = (params) => {
2250
- return new ZodUnknown(__spreadValues({
2251
- typeName: ZodFirstPartyTypeKind.ZodUnknown
2252
- }, processCreateParams(params)));
2230
+ return new ZodUnknown({
2231
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2232
+ ...processCreateParams(params)
2233
+ });
2253
2234
  };
2254
2235
  var ZodNever = class extends ZodType {
2255
2236
  _parse(input) {
@@ -2263,9 +2244,10 @@ var ZodNever = class extends ZodType {
2263
2244
  }
2264
2245
  };
2265
2246
  ZodNever.create = (params) => {
2266
- return new ZodNever(__spreadValues({
2267
- typeName: ZodFirstPartyTypeKind.ZodNever
2268
- }, processCreateParams(params)));
2247
+ return new ZodNever({
2248
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2249
+ ...processCreateParams(params)
2250
+ });
2269
2251
  };
2270
2252
  var ZodVoid = class extends ZodType {
2271
2253
  _parse(input) {
@@ -2283,9 +2265,10 @@ var ZodVoid = class extends ZodType {
2283
2265
  }
2284
2266
  };
2285
2267
  ZodVoid.create = (params) => {
2286
- return new ZodVoid(__spreadValues({
2287
- typeName: ZodFirstPartyTypeKind.ZodVoid
2288
- }, processCreateParams(params)));
2268
+ return new ZodVoid({
2269
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2270
+ ...processCreateParams(params)
2271
+ });
2289
2272
  };
2290
2273
  var ZodArray = class _ZodArray extends ZodType {
2291
2274
  _parse(input) {
@@ -2357,32 +2340,36 @@ var ZodArray = class _ZodArray extends ZodType {
2357
2340
  return this._def.type;
2358
2341
  }
2359
2342
  min(minLength, message) {
2360
- return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2343
+ return new _ZodArray({
2344
+ ...this._def,
2361
2345
  minLength: { value: minLength, message: errorUtil.toString(message) }
2362
- }));
2346
+ });
2363
2347
  }
2364
2348
  max(maxLength, message) {
2365
- return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2349
+ return new _ZodArray({
2350
+ ...this._def,
2366
2351
  maxLength: { value: maxLength, message: errorUtil.toString(message) }
2367
- }));
2352
+ });
2368
2353
  }
2369
2354
  length(len, message) {
2370
- return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2355
+ return new _ZodArray({
2356
+ ...this._def,
2371
2357
  exactLength: { value: len, message: errorUtil.toString(message) }
2372
- }));
2358
+ });
2373
2359
  }
2374
2360
  nonempty(message) {
2375
2361
  return this.min(1, message);
2376
2362
  }
2377
2363
  };
2378
2364
  ZodArray.create = (schema, params) => {
2379
- return new ZodArray(__spreadValues({
2365
+ return new ZodArray({
2380
2366
  type: schema,
2381
2367
  minLength: null,
2382
2368
  maxLength: null,
2383
2369
  exactLength: null,
2384
- typeName: ZodFirstPartyTypeKind.ZodArray
2385
- }, processCreateParams(params)));
2370
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2371
+ ...processCreateParams(params)
2372
+ });
2386
2373
  };
2387
2374
  function deepPartialify(schema) {
2388
2375
  if (schema instanceof ZodObject) {
@@ -2391,13 +2378,15 @@ function deepPartialify(schema) {
2391
2378
  const fieldSchema = schema.shape[key];
2392
2379
  newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2393
2380
  }
2394
- return new ZodObject(__spreadProps(__spreadValues({}, schema._def), {
2381
+ return new ZodObject({
2382
+ ...schema._def,
2395
2383
  shape: () => newShape
2396
- }));
2384
+ });
2397
2385
  } else if (schema instanceof ZodArray) {
2398
- return new ZodArray(__spreadProps(__spreadValues({}, schema._def), {
2386
+ return new ZodArray({
2387
+ ...schema._def,
2399
2388
  type: deepPartialify(schema.element)
2400
- }));
2389
+ });
2401
2390
  } else if (schema instanceof ZodOptional) {
2402
2391
  return ZodOptional.create(deepPartialify(schema.unwrap()));
2403
2392
  } else if (schema instanceof ZodNullable) {
@@ -2490,11 +2479,11 @@ var ZodObject = class _ZodObject extends ZodType {
2490
2479
  }
2491
2480
  }
2492
2481
  if (ctx.common.async) {
2493
- return Promise.resolve().then(() => __async(this, null, function* () {
2482
+ return Promise.resolve().then(async () => {
2494
2483
  const syncPairs = [];
2495
2484
  for (const pair of pairs) {
2496
- const key = yield pair.key;
2497
- const value = yield pair.value;
2485
+ const key = await pair.key;
2486
+ const value = await pair.value;
2498
2487
  syncPairs.push({
2499
2488
  key,
2500
2489
  value,
@@ -2502,7 +2491,7 @@ var ZodObject = class _ZodObject extends ZodType {
2502
2491
  });
2503
2492
  }
2504
2493
  return syncPairs;
2505
- })).then((syncPairs) => {
2494
+ }).then((syncPairs) => {
2506
2495
  return ParseStatus.mergeObjectSync(status, syncPairs);
2507
2496
  });
2508
2497
  } else {
@@ -2514,31 +2503,34 @@ var ZodObject = class _ZodObject extends ZodType {
2514
2503
  }
2515
2504
  strict(message) {
2516
2505
  errorUtil.errToObj;
2517
- return new _ZodObject(__spreadValues(__spreadProps(__spreadValues({}, this._def), {
2518
- unknownKeys: "strict"
2519
- }), message !== void 0 ? {
2520
- errorMap: (issue, ctx) => {
2521
- var _a, _b, _c, _d;
2522
- const defaultError = (_c = (_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) != null ? _c : ctx.defaultError;
2523
- if (issue.code === "unrecognized_keys")
2506
+ return new _ZodObject({
2507
+ ...this._def,
2508
+ unknownKeys: "strict",
2509
+ ...message !== void 0 ? {
2510
+ errorMap: (issue, ctx) => {
2511
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2512
+ if (issue.code === "unrecognized_keys")
2513
+ return {
2514
+ message: errorUtil.errToObj(message).message ?? defaultError
2515
+ };
2524
2516
  return {
2525
- message: (_d = errorUtil.errToObj(message).message) != null ? _d : defaultError
2517
+ message: defaultError
2526
2518
  };
2527
- return {
2528
- message: defaultError
2529
- };
2530
- }
2531
- } : {}));
2519
+ }
2520
+ } : {}
2521
+ });
2532
2522
  }
2533
2523
  strip() {
2534
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2524
+ return new _ZodObject({
2525
+ ...this._def,
2535
2526
  unknownKeys: "strip"
2536
- }));
2527
+ });
2537
2528
  }
2538
2529
  passthrough() {
2539
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2530
+ return new _ZodObject({
2531
+ ...this._def,
2540
2532
  unknownKeys: "passthrough"
2541
- }));
2533
+ });
2542
2534
  }
2543
2535
  // const AugmentFactory =
2544
2536
  // <Def extends ZodObjectDef>(def: Def) =>
@@ -2558,9 +2550,13 @@ var ZodObject = class _ZodObject extends ZodType {
2558
2550
  // }) as any;
2559
2551
  // };
2560
2552
  extend(augmentation) {
2561
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2562
- shape: () => __spreadValues(__spreadValues({}, this._def.shape()), augmentation)
2563
- }));
2553
+ return new _ZodObject({
2554
+ ...this._def,
2555
+ shape: () => ({
2556
+ ...this._def.shape(),
2557
+ ...augmentation
2558
+ })
2559
+ });
2564
2560
  }
2565
2561
  /**
2566
2562
  * Prior to zod@1.0.12 there was a bug in the
@@ -2571,7 +2567,10 @@ var ZodObject = class _ZodObject extends ZodType {
2571
2567
  const merged = new _ZodObject({
2572
2568
  unknownKeys: merging._def.unknownKeys,
2573
2569
  catchall: merging._def.catchall,
2574
- shape: () => __spreadValues(__spreadValues({}, this._def.shape()), merging._def.shape()),
2570
+ shape: () => ({
2571
+ ...this._def.shape(),
2572
+ ...merging._def.shape()
2573
+ }),
2575
2574
  typeName: ZodFirstPartyTypeKind.ZodObject
2576
2575
  });
2577
2576
  return merged;
@@ -2636,9 +2635,10 @@ var ZodObject = class _ZodObject extends ZodType {
2636
2635
  // return merged;
2637
2636
  // }
2638
2637
  catchall(index) {
2639
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2638
+ return new _ZodObject({
2639
+ ...this._def,
2640
2640
  catchall: index
2641
- }));
2641
+ });
2642
2642
  }
2643
2643
  pick(mask) {
2644
2644
  const shape = {};
@@ -2647,9 +2647,10 @@ var ZodObject = class _ZodObject extends ZodType {
2647
2647
  shape[key] = this.shape[key];
2648
2648
  }
2649
2649
  }
2650
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2650
+ return new _ZodObject({
2651
+ ...this._def,
2651
2652
  shape: () => shape
2652
- }));
2653
+ });
2653
2654
  }
2654
2655
  omit(mask) {
2655
2656
  const shape = {};
@@ -2658,9 +2659,10 @@ var ZodObject = class _ZodObject extends ZodType {
2658
2659
  shape[key] = this.shape[key];
2659
2660
  }
2660
2661
  }
2661
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2662
+ return new _ZodObject({
2663
+ ...this._def,
2662
2664
  shape: () => shape
2663
- }));
2665
+ });
2664
2666
  }
2665
2667
  /**
2666
2668
  * @deprecated
@@ -2678,9 +2680,10 @@ var ZodObject = class _ZodObject extends ZodType {
2678
2680
  newShape[key] = fieldSchema.optional();
2679
2681
  }
2680
2682
  }
2681
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2683
+ return new _ZodObject({
2684
+ ...this._def,
2682
2685
  shape: () => newShape
2683
- }));
2686
+ });
2684
2687
  }
2685
2688
  required(mask) {
2686
2689
  const newShape = {};
@@ -2696,37 +2699,41 @@ var ZodObject = class _ZodObject extends ZodType {
2696
2699
  newShape[key] = newField;
2697
2700
  }
2698
2701
  }
2699
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2702
+ return new _ZodObject({
2703
+ ...this._def,
2700
2704
  shape: () => newShape
2701
- }));
2705
+ });
2702
2706
  }
2703
2707
  keyof() {
2704
2708
  return createZodEnum(util.objectKeys(this.shape));
2705
2709
  }
2706
2710
  };
2707
2711
  ZodObject.create = (shape, params) => {
2708
- return new ZodObject(__spreadValues({
2712
+ return new ZodObject({
2709
2713
  shape: () => shape,
2710
2714
  unknownKeys: "strip",
2711
2715
  catchall: ZodNever.create(),
2712
- typeName: ZodFirstPartyTypeKind.ZodObject
2713
- }, processCreateParams(params)));
2716
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2717
+ ...processCreateParams(params)
2718
+ });
2714
2719
  };
2715
2720
  ZodObject.strictCreate = (shape, params) => {
2716
- return new ZodObject(__spreadValues({
2721
+ return new ZodObject({
2717
2722
  shape: () => shape,
2718
2723
  unknownKeys: "strict",
2719
2724
  catchall: ZodNever.create(),
2720
- typeName: ZodFirstPartyTypeKind.ZodObject
2721
- }, processCreateParams(params)));
2725
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2726
+ ...processCreateParams(params)
2727
+ });
2722
2728
  };
2723
2729
  ZodObject.lazycreate = (shape, params) => {
2724
- return new ZodObject(__spreadValues({
2730
+ return new ZodObject({
2725
2731
  shape,
2726
2732
  unknownKeys: "strip",
2727
2733
  catchall: ZodNever.create(),
2728
- typeName: ZodFirstPartyTypeKind.ZodObject
2729
- }, processCreateParams(params)));
2734
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2735
+ ...processCreateParams(params)
2736
+ });
2730
2737
  };
2731
2738
  var ZodUnion = class extends ZodType {
2732
2739
  _parse(input) {
@@ -2752,32 +2759,36 @@ var ZodUnion = class extends ZodType {
2752
2759
  return INVALID;
2753
2760
  }
2754
2761
  if (ctx.common.async) {
2755
- return Promise.all(options.map((option) => __async(this, null, function* () {
2756
- const childCtx = __spreadProps(__spreadValues({}, ctx), {
2757
- common: __spreadProps(__spreadValues({}, ctx.common), {
2762
+ return Promise.all(options.map(async (option) => {
2763
+ const childCtx = {
2764
+ ...ctx,
2765
+ common: {
2766
+ ...ctx.common,
2758
2767
  issues: []
2759
- }),
2768
+ },
2760
2769
  parent: null
2761
- });
2770
+ };
2762
2771
  return {
2763
- result: yield option._parseAsync({
2772
+ result: await option._parseAsync({
2764
2773
  data: ctx.data,
2765
2774
  path: ctx.path,
2766
2775
  parent: childCtx
2767
2776
  }),
2768
2777
  ctx: childCtx
2769
2778
  };
2770
- }))).then(handleResults);
2779
+ })).then(handleResults);
2771
2780
  } else {
2772
2781
  let dirty = void 0;
2773
2782
  const issues = [];
2774
2783
  for (const option of options) {
2775
- const childCtx = __spreadProps(__spreadValues({}, ctx), {
2776
- common: __spreadProps(__spreadValues({}, ctx.common), {
2784
+ const childCtx = {
2785
+ ...ctx,
2786
+ common: {
2787
+ ...ctx.common,
2777
2788
  issues: []
2778
- }),
2789
+ },
2779
2790
  parent: null
2780
- });
2791
+ };
2781
2792
  const result = option._parseSync({
2782
2793
  data: ctx.data,
2783
2794
  path: ctx.path,
@@ -2809,10 +2820,11 @@ var ZodUnion = class extends ZodType {
2809
2820
  }
2810
2821
  };
2811
2822
  ZodUnion.create = (types, params) => {
2812
- return new ZodUnion(__spreadValues({
2823
+ return new ZodUnion({
2813
2824
  options: types,
2814
- typeName: ZodFirstPartyTypeKind.ZodUnion
2815
- }, processCreateParams(params)));
2825
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2826
+ ...processCreateParams(params)
2827
+ });
2816
2828
  };
2817
2829
  var getDiscriminator = (type) => {
2818
2830
  if (type instanceof ZodLazy) {
@@ -2912,12 +2924,13 @@ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
2912
2924
  optionsMap.set(value, type);
2913
2925
  }
2914
2926
  }
2915
- return new _ZodDiscriminatedUnion(__spreadValues({
2927
+ return new _ZodDiscriminatedUnion({
2916
2928
  typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2917
2929
  discriminator,
2918
2930
  options,
2919
- optionsMap
2920
- }, processCreateParams(params)));
2931
+ optionsMap,
2932
+ ...processCreateParams(params)
2933
+ });
2921
2934
  }
2922
2935
  };
2923
2936
  function mergeValues(a, b) {
@@ -2928,7 +2941,7 @@ function mergeValues(a, b) {
2928
2941
  } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2929
2942
  const bKeys = util.objectKeys(b);
2930
2943
  const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2931
- const newObj = __spreadValues(__spreadValues({}, a), b);
2944
+ const newObj = { ...a, ...b };
2932
2945
  for (const key of sharedKeys) {
2933
2946
  const sharedValue = mergeValues(a[key], b[key]);
2934
2947
  if (!sharedValue.valid) {
@@ -3004,11 +3017,12 @@ var ZodIntersection = class extends ZodType {
3004
3017
  }
3005
3018
  };
3006
3019
  ZodIntersection.create = (left, right, params) => {
3007
- return new ZodIntersection(__spreadValues({
3020
+ return new ZodIntersection({
3008
3021
  left,
3009
3022
  right,
3010
- typeName: ZodFirstPartyTypeKind.ZodIntersection
3011
- }, processCreateParams(params)));
3023
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
3024
+ ...processCreateParams(params)
3025
+ });
3012
3026
  };
3013
3027
  var ZodTuple = class _ZodTuple extends ZodType {
3014
3028
  _parse(input) {
@@ -3060,20 +3074,22 @@ var ZodTuple = class _ZodTuple extends ZodType {
3060
3074
  return this._def.items;
3061
3075
  }
3062
3076
  rest(rest) {
3063
- return new _ZodTuple(__spreadProps(__spreadValues({}, this._def), {
3077
+ return new _ZodTuple({
3078
+ ...this._def,
3064
3079
  rest
3065
- }));
3080
+ });
3066
3081
  }
3067
3082
  };
3068
3083
  ZodTuple.create = (schemas, params) => {
3069
3084
  if (!Array.isArray(schemas)) {
3070
3085
  throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3071
3086
  }
3072
- return new ZodTuple(__spreadValues({
3087
+ return new ZodTuple({
3073
3088
  items: schemas,
3074
3089
  typeName: ZodFirstPartyTypeKind.ZodTuple,
3075
- rest: null
3076
- }, processCreateParams(params)));
3090
+ rest: null,
3091
+ ...processCreateParams(params)
3092
+ });
3077
3093
  };
3078
3094
  var ZodRecord = class _ZodRecord extends ZodType {
3079
3095
  get keySchema() {
@@ -3113,17 +3129,19 @@ var ZodRecord = class _ZodRecord extends ZodType {
3113
3129
  }
3114
3130
  static create(first, second, third) {
3115
3131
  if (second instanceof ZodType) {
3116
- return new _ZodRecord(__spreadValues({
3132
+ return new _ZodRecord({
3117
3133
  keyType: first,
3118
3134
  valueType: second,
3119
- typeName: ZodFirstPartyTypeKind.ZodRecord
3120
- }, processCreateParams(third)));
3135
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3136
+ ...processCreateParams(third)
3137
+ });
3121
3138
  }
3122
- return new _ZodRecord(__spreadValues({
3139
+ return new _ZodRecord({
3123
3140
  keyType: ZodString.create(),
3124
3141
  valueType: first,
3125
- typeName: ZodFirstPartyTypeKind.ZodRecord
3126
- }, processCreateParams(second)));
3142
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3143
+ ...processCreateParams(second)
3144
+ });
3127
3145
  }
3128
3146
  };
3129
3147
  var ZodMap = class extends ZodType {
@@ -3153,10 +3171,10 @@ var ZodMap = class extends ZodType {
3153
3171
  });
3154
3172
  if (ctx.common.async) {
3155
3173
  const finalMap = /* @__PURE__ */ new Map();
3156
- return Promise.resolve().then(() => __async(this, null, function* () {
3174
+ return Promise.resolve().then(async () => {
3157
3175
  for (const pair of pairs) {
3158
- const key = yield pair.key;
3159
- const value = yield pair.value;
3176
+ const key = await pair.key;
3177
+ const value = await pair.value;
3160
3178
  if (key.status === "aborted" || value.status === "aborted") {
3161
3179
  return INVALID;
3162
3180
  }
@@ -3166,7 +3184,7 @@ var ZodMap = class extends ZodType {
3166
3184
  finalMap.set(key.value, value.value);
3167
3185
  }
3168
3186
  return { status: status.value, value: finalMap };
3169
- }));
3187
+ });
3170
3188
  } else {
3171
3189
  const finalMap = /* @__PURE__ */ new Map();
3172
3190
  for (const pair of pairs) {
@@ -3185,11 +3203,12 @@ var ZodMap = class extends ZodType {
3185
3203
  }
3186
3204
  };
3187
3205
  ZodMap.create = (keyType, valueType, params) => {
3188
- return new ZodMap(__spreadValues({
3206
+ return new ZodMap({
3189
3207
  valueType,
3190
3208
  keyType,
3191
- typeName: ZodFirstPartyTypeKind.ZodMap
3192
- }, processCreateParams(params)));
3209
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3210
+ ...processCreateParams(params)
3211
+ });
3193
3212
  };
3194
3213
  var ZodSet = class _ZodSet extends ZodType {
3195
3214
  _parse(input) {
@@ -3249,14 +3268,16 @@ var ZodSet = class _ZodSet extends ZodType {
3249
3268
  }
3250
3269
  }
3251
3270
  min(minSize, message) {
3252
- return new _ZodSet(__spreadProps(__spreadValues({}, this._def), {
3271
+ return new _ZodSet({
3272
+ ...this._def,
3253
3273
  minSize: { value: minSize, message: errorUtil.toString(message) }
3254
- }));
3274
+ });
3255
3275
  }
3256
3276
  max(maxSize, message) {
3257
- return new _ZodSet(__spreadProps(__spreadValues({}, this._def), {
3277
+ return new _ZodSet({
3278
+ ...this._def,
3258
3279
  maxSize: { value: maxSize, message: errorUtil.toString(message) }
3259
- }));
3280
+ });
3260
3281
  }
3261
3282
  size(size, message) {
3262
3283
  return this.min(size, message).max(size, message);
@@ -3266,12 +3287,13 @@ var ZodSet = class _ZodSet extends ZodType {
3266
3287
  }
3267
3288
  };
3268
3289
  ZodSet.create = (valueType, params) => {
3269
- return new ZodSet(__spreadValues({
3290
+ return new ZodSet({
3270
3291
  valueType,
3271
3292
  minSize: null,
3272
3293
  maxSize: null,
3273
- typeName: ZodFirstPartyTypeKind.ZodSet
3274
- }, processCreateParams(params)));
3294
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3295
+ ...processCreateParams(params)
3296
+ });
3275
3297
  };
3276
3298
  var ZodFunction = class _ZodFunction extends ZodType {
3277
3299
  constructor() {
@@ -3314,20 +3336,18 @@ var ZodFunction = class _ZodFunction extends ZodType {
3314
3336
  const fn = ctx.data;
3315
3337
  if (this._def.returns instanceof ZodPromise) {
3316
3338
  const me = this;
3317
- return OK(function(...args) {
3318
- return __async(this, null, function* () {
3319
- const error = new ZodError([]);
3320
- const parsedArgs = yield me._def.args.parseAsync(args, params).catch((e) => {
3321
- error.addIssue(makeArgsIssue(args, e));
3322
- throw error;
3323
- });
3324
- const result = yield Reflect.apply(fn, this, parsedArgs);
3325
- const parsedReturns = yield me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3326
- error.addIssue(makeReturnsIssue(result, e));
3327
- throw error;
3328
- });
3329
- return parsedReturns;
3339
+ return OK(async function(...args) {
3340
+ const error = new ZodError([]);
3341
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3342
+ error.addIssue(makeArgsIssue(args, e));
3343
+ throw error;
3344
+ });
3345
+ const result = await Reflect.apply(fn, this, parsedArgs);
3346
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3347
+ error.addIssue(makeReturnsIssue(result, e));
3348
+ throw error;
3330
3349
  });
3350
+ return parsedReturns;
3331
3351
  });
3332
3352
  } else {
3333
3353
  const me = this;
@@ -3352,14 +3372,16 @@ var ZodFunction = class _ZodFunction extends ZodType {
3352
3372
  return this._def.returns;
3353
3373
  }
3354
3374
  args(...items) {
3355
- return new _ZodFunction(__spreadProps(__spreadValues({}, this._def), {
3375
+ return new _ZodFunction({
3376
+ ...this._def,
3356
3377
  args: ZodTuple.create(items).rest(ZodUnknown.create())
3357
- }));
3378
+ });
3358
3379
  }
3359
3380
  returns(returnType) {
3360
- return new _ZodFunction(__spreadProps(__spreadValues({}, this._def), {
3381
+ return new _ZodFunction({
3382
+ ...this._def,
3361
3383
  returns: returnType
3362
- }));
3384
+ });
3363
3385
  }
3364
3386
  implement(func) {
3365
3387
  const validatedFunc = this.parse(func);
@@ -3370,11 +3392,12 @@ var ZodFunction = class _ZodFunction extends ZodType {
3370
3392
  return validatedFunc;
3371
3393
  }
3372
3394
  static create(args, returns, params) {
3373
- return new _ZodFunction(__spreadValues({
3395
+ return new _ZodFunction({
3374
3396
  args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3375
3397
  returns: returns || ZodUnknown.create(),
3376
- typeName: ZodFirstPartyTypeKind.ZodFunction
3377
- }, processCreateParams(params)));
3398
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3399
+ ...processCreateParams(params)
3400
+ });
3378
3401
  }
3379
3402
  };
3380
3403
  var ZodLazy = class extends ZodType {
@@ -3388,10 +3411,11 @@ var ZodLazy = class extends ZodType {
3388
3411
  }
3389
3412
  };
3390
3413
  ZodLazy.create = (getter, params) => {
3391
- return new ZodLazy(__spreadValues({
3414
+ return new ZodLazy({
3392
3415
  getter,
3393
- typeName: ZodFirstPartyTypeKind.ZodLazy
3394
- }, processCreateParams(params)));
3416
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3417
+ ...processCreateParams(params)
3418
+ });
3395
3419
  };
3396
3420
  var ZodLiteral = class extends ZodType {
3397
3421
  _parse(input) {
@@ -3411,16 +3435,18 @@ var ZodLiteral = class extends ZodType {
3411
3435
  }
3412
3436
  };
3413
3437
  ZodLiteral.create = (value, params) => {
3414
- return new ZodLiteral(__spreadValues({
3438
+ return new ZodLiteral({
3415
3439
  value,
3416
- typeName: ZodFirstPartyTypeKind.ZodLiteral
3417
- }, processCreateParams(params)));
3440
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3441
+ ...processCreateParams(params)
3442
+ });
3418
3443
  };
3419
3444
  function createZodEnum(values, params) {
3420
- return new ZodEnum(__spreadValues({
3445
+ return new ZodEnum({
3421
3446
  values,
3422
- typeName: ZodFirstPartyTypeKind.ZodEnum
3423
- }, processCreateParams(params)));
3447
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3448
+ ...processCreateParams(params)
3449
+ });
3424
3450
  }
3425
3451
  var ZodEnum = class _ZodEnum extends ZodType {
3426
3452
  _parse(input) {
@@ -3474,10 +3500,16 @@ var ZodEnum = class _ZodEnum extends ZodType {
3474
3500
  return enumValues;
3475
3501
  }
3476
3502
  extract(values, newDef = this._def) {
3477
- return _ZodEnum.create(values, __spreadValues(__spreadValues({}, this._def), newDef));
3503
+ return _ZodEnum.create(values, {
3504
+ ...this._def,
3505
+ ...newDef
3506
+ });
3478
3507
  }
3479
3508
  exclude(values, newDef = this._def) {
3480
- return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), __spreadValues(__spreadValues({}, this._def), newDef));
3509
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3510
+ ...this._def,
3511
+ ...newDef
3512
+ });
3481
3513
  }
3482
3514
  };
3483
3515
  ZodEnum.create = createZodEnum;
@@ -3513,10 +3545,11 @@ var ZodNativeEnum = class extends ZodType {
3513
3545
  }
3514
3546
  };
3515
3547
  ZodNativeEnum.create = (values, params) => {
3516
- return new ZodNativeEnum(__spreadValues({
3548
+ return new ZodNativeEnum({
3517
3549
  values,
3518
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum
3519
- }, processCreateParams(params)));
3550
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3551
+ ...processCreateParams(params)
3552
+ });
3520
3553
  };
3521
3554
  var ZodPromise = class extends ZodType {
3522
3555
  unwrap() {
@@ -3542,10 +3575,11 @@ var ZodPromise = class extends ZodType {
3542
3575
  }
3543
3576
  };
3544
3577
  ZodPromise.create = (schema, params) => {
3545
- return new ZodPromise(__spreadValues({
3578
+ return new ZodPromise({
3546
3579
  type: schema,
3547
- typeName: ZodFirstPartyTypeKind.ZodPromise
3548
- }, processCreateParams(params)));
3580
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3581
+ ...processCreateParams(params)
3582
+ });
3549
3583
  };
3550
3584
  var ZodEffects = class extends ZodType {
3551
3585
  innerType() {
@@ -3574,10 +3608,10 @@ var ZodEffects = class extends ZodType {
3574
3608
  if (effect.type === "preprocess") {
3575
3609
  const processed = effect.transform(ctx.data, checkCtx);
3576
3610
  if (ctx.common.async) {
3577
- return Promise.resolve(processed).then((processed2) => __async(this, null, function* () {
3611
+ return Promise.resolve(processed).then(async (processed2) => {
3578
3612
  if (status.value === "aborted")
3579
3613
  return INVALID;
3580
- const result = yield this._def.schema._parseAsync({
3614
+ const result = await this._def.schema._parseAsync({
3581
3615
  data: processed2,
3582
3616
  path: ctx.path,
3583
3617
  parent: ctx
@@ -3589,7 +3623,7 @@ var ZodEffects = class extends ZodType {
3589
3623
  if (status.value === "dirty")
3590
3624
  return DIRTY(result.value);
3591
3625
  return result;
3592
- }));
3626
+ });
3593
3627
  } else {
3594
3628
  if (status.value === "aborted")
3595
3629
  return INVALID;
@@ -3671,18 +3705,20 @@ var ZodEffects = class extends ZodType {
3671
3705
  }
3672
3706
  };
3673
3707
  ZodEffects.create = (schema, effect, params) => {
3674
- return new ZodEffects(__spreadValues({
3708
+ return new ZodEffects({
3675
3709
  schema,
3676
3710
  typeName: ZodFirstPartyTypeKind.ZodEffects,
3677
- effect
3678
- }, processCreateParams(params)));
3711
+ effect,
3712
+ ...processCreateParams(params)
3713
+ });
3679
3714
  };
3680
3715
  ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3681
- return new ZodEffects(__spreadValues({
3716
+ return new ZodEffects({
3682
3717
  schema,
3683
3718
  effect: { type: "preprocess", transform: preprocess },
3684
- typeName: ZodFirstPartyTypeKind.ZodEffects
3685
- }, processCreateParams(params)));
3719
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3720
+ ...processCreateParams(params)
3721
+ });
3686
3722
  };
3687
3723
  var ZodOptional = class extends ZodType {
3688
3724
  _parse(input) {
@@ -3697,10 +3733,11 @@ var ZodOptional = class extends ZodType {
3697
3733
  }
3698
3734
  };
3699
3735
  ZodOptional.create = (type, params) => {
3700
- return new ZodOptional(__spreadValues({
3736
+ return new ZodOptional({
3701
3737
  innerType: type,
3702
- typeName: ZodFirstPartyTypeKind.ZodOptional
3703
- }, processCreateParams(params)));
3738
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3739
+ ...processCreateParams(params)
3740
+ });
3704
3741
  };
3705
3742
  var ZodNullable = class extends ZodType {
3706
3743
  _parse(input) {
@@ -3715,10 +3752,11 @@ var ZodNullable = class extends ZodType {
3715
3752
  }
3716
3753
  };
3717
3754
  ZodNullable.create = (type, params) => {
3718
- return new ZodNullable(__spreadValues({
3755
+ return new ZodNullable({
3719
3756
  innerType: type,
3720
- typeName: ZodFirstPartyTypeKind.ZodNullable
3721
- }, processCreateParams(params)));
3757
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3758
+ ...processCreateParams(params)
3759
+ });
3722
3760
  };
3723
3761
  var ZodDefault = class extends ZodType {
3724
3762
  _parse(input) {
@@ -3738,24 +3776,29 @@ var ZodDefault = class extends ZodType {
3738
3776
  }
3739
3777
  };
3740
3778
  ZodDefault.create = (type, params) => {
3741
- return new ZodDefault(__spreadValues({
3779
+ return new ZodDefault({
3742
3780
  innerType: type,
3743
3781
  typeName: ZodFirstPartyTypeKind.ZodDefault,
3744
- defaultValue: typeof params.default === "function" ? params.default : () => params.default
3745
- }, processCreateParams(params)));
3782
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3783
+ ...processCreateParams(params)
3784
+ });
3746
3785
  };
3747
3786
  var ZodCatch = class extends ZodType {
3748
3787
  _parse(input) {
3749
3788
  const { ctx } = this._processInputParams(input);
3750
- const newCtx = __spreadProps(__spreadValues({}, ctx), {
3751
- common: __spreadProps(__spreadValues({}, ctx.common), {
3789
+ const newCtx = {
3790
+ ...ctx,
3791
+ common: {
3792
+ ...ctx.common,
3752
3793
  issues: []
3753
- })
3754
- });
3794
+ }
3795
+ };
3755
3796
  const result = this._def.innerType._parse({
3756
3797
  data: newCtx.data,
3757
3798
  path: newCtx.path,
3758
- parent: __spreadValues({}, newCtx)
3799
+ parent: {
3800
+ ...newCtx
3801
+ }
3759
3802
  });
3760
3803
  if (isAsync(result)) {
3761
3804
  return result.then((result2) => {
@@ -3786,11 +3829,12 @@ var ZodCatch = class extends ZodType {
3786
3829
  }
3787
3830
  };
3788
3831
  ZodCatch.create = (type, params) => {
3789
- return new ZodCatch(__spreadValues({
3832
+ return new ZodCatch({
3790
3833
  innerType: type,
3791
3834
  typeName: ZodFirstPartyTypeKind.ZodCatch,
3792
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch
3793
- }, processCreateParams(params)));
3835
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3836
+ ...processCreateParams(params)
3837
+ });
3794
3838
  };
3795
3839
  var ZodNaN = class extends ZodType {
3796
3840
  _parse(input) {
@@ -3808,9 +3852,10 @@ var ZodNaN = class extends ZodType {
3808
3852
  }
3809
3853
  };
3810
3854
  ZodNaN.create = (params) => {
3811
- return new ZodNaN(__spreadValues({
3812
- typeName: ZodFirstPartyTypeKind.ZodNaN
3813
- }, processCreateParams(params)));
3855
+ return new ZodNaN({
3856
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3857
+ ...processCreateParams(params)
3858
+ });
3814
3859
  };
3815
3860
  var BRAND = Symbol("zod_brand");
3816
3861
  var ZodBranded = class extends ZodType {
@@ -3831,8 +3876,8 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
3831
3876
  _parse(input) {
3832
3877
  const { status, ctx } = this._processInputParams(input);
3833
3878
  if (ctx.common.async) {
3834
- const handleAsync = () => __async(this, null, function* () {
3835
- const inResult = yield this._def.in._parseAsync({
3879
+ const handleAsync = async () => {
3880
+ const inResult = await this._def.in._parseAsync({
3836
3881
  data: ctx.data,
3837
3882
  path: ctx.path,
3838
3883
  parent: ctx
@@ -3849,7 +3894,7 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
3849
3894
  parent: ctx
3850
3895
  });
3851
3896
  }
3852
- });
3897
+ };
3853
3898
  return handleAsync();
3854
3899
  } else {
3855
3900
  const inResult = this._def.in._parseSync({
@@ -3898,10 +3943,11 @@ var ZodReadonly = class extends ZodType {
3898
3943
  }
3899
3944
  };
3900
3945
  ZodReadonly.create = (type, params) => {
3901
- return new ZodReadonly(__spreadValues({
3946
+ return new ZodReadonly({
3902
3947
  innerType: type,
3903
- typeName: ZodFirstPartyTypeKind.ZodReadonly
3904
- }, processCreateParams(params)));
3948
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3949
+ ...processCreateParams(params)
3950
+ });
3905
3951
  };
3906
3952
  function cleanParams(params, data) {
3907
3953
  const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
@@ -3911,22 +3957,20 @@ function cleanParams(params, data) {
3911
3957
  function custom(check, _params = {}, fatal) {
3912
3958
  if (check)
3913
3959
  return ZodAny.create().superRefine((data, ctx) => {
3914
- var _a, _b;
3915
3960
  const r = check(data);
3916
3961
  if (r instanceof Promise) {
3917
3962
  return r.then((r2) => {
3918
- var _a2, _b2;
3919
3963
  if (!r2) {
3920
3964
  const params = cleanParams(_params, data);
3921
- const _fatal = (_b2 = (_a2 = params.fatal) != null ? _a2 : fatal) != null ? _b2 : true;
3922
- ctx.addIssue(__spreadProps(__spreadValues({ code: "custom" }, params), { fatal: _fatal }));
3965
+ const _fatal = params.fatal ?? fatal ?? true;
3966
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3923
3967
  }
3924
3968
  });
3925
3969
  }
3926
3970
  if (!r) {
3927
3971
  const params = cleanParams(_params, data);
3928
- const _fatal = (_b = (_a = params.fatal) != null ? _a : fatal) != null ? _b : true;
3929
- ctx.addIssue(__spreadProps(__spreadValues({ code: "custom" }, params), { fatal: _fatal }));
3972
+ const _fatal = params.fatal ?? fatal ?? true;
3973
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3930
3974
  }
3931
3975
  return;
3932
3976
  });
@@ -4015,18 +4059,29 @@ var ostring = () => stringType().optional();
4015
4059
  var onumber = () => numberType().optional();
4016
4060
  var oboolean = () => booleanType().optional();
4017
4061
  var coerce = {
4018
- string: ((arg) => ZodString.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4019
- number: ((arg) => ZodNumber.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4020
- boolean: ((arg) => ZodBoolean.create(__spreadProps(__spreadValues({}, arg), {
4062
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4063
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4064
+ boolean: ((arg) => ZodBoolean.create({
4065
+ ...arg,
4021
4066
  coerce: true
4022
- }))),
4023
- bigint: ((arg) => ZodBigInt.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4024
- date: ((arg) => ZodDate.create(__spreadProps(__spreadValues({}, arg), { coerce: true })))
4067
+ })),
4068
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4069
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4025
4070
  };
4026
4071
  var NEVER = INVALID;
4027
4072
 
4028
4073
  // src/client.ts
4029
4074
  var RichError = class extends Error {
4075
+ status;
4076
+ // HTTP status code (e.g. 404, 500)
4077
+ code;
4078
+ // Application-level error code (e.g. "USER_NOT_FOUND")
4079
+ title;
4080
+ // Optional title or short summary
4081
+ detail;
4082
+ // Additional human-readable explanation
4083
+ errors;
4084
+ // Field-specific validation errors
4030
4085
  constructor(error) {
4031
4086
  super(error.message);
4032
4087
  Object.assign(this, error);
@@ -4036,17 +4091,31 @@ var ApiClient = class {
4036
4091
  constructor(config, contracts) {
4037
4092
  this.config = config;
4038
4093
  this.contracts = contracts;
4039
- this.middlewares = [];
4040
- this.responseTransform = (d) => d;
4041
- this.useMockData = false;
4042
- this.mockDelay = { min: 100, max: 1e3 };
4043
4094
  this.useMockData = config.useMockData || false;
4044
4095
  this.mockDelay = config.mockDelay || { min: 100, max: 1e3 };
4045
4096
  this.tokenProvider = config.tokenProvider;
4046
4097
  }
4098
+ middlewares = [];
4099
+ // Registered middlewares
4100
+ errorHandler;
4101
+ // Global error handler
4102
+ responseTransform = (d) => d;
4103
+ // Post-parse data transformer
4104
+ useMockData = false;
4105
+ // Whether mock responses are enabled
4106
+ mockDelay = { min: 100, max: 1e3 };
4107
+ // Mock latency range (ms)
4108
+ responseWrapper;
4109
+ // Wrapper for APIs with envelope structures
4110
+ tokenProvider;
4111
+ // Optional async token supplier
4112
+ // Configuration for retry behavior
4113
+ retryConfig;
4114
+ // Holds generated API endpoint methods
4115
+ _modules;
4047
4116
  /**
4048
- * Builds the strongly-typed `modules` API from the provided contracts.
4049
- * Must be called once after constructing the client.
4117
+ * Builds all API methods (`modules`) dynamically from the Zod contract definition.
4118
+ * After `init()` is called, each endpoint can be invoked through `client.modules.moduleName.endpointName()`.
4050
4119
  */
4051
4120
  init() {
4052
4121
  const modules = {};
@@ -4055,333 +4124,215 @@ var ApiClient = class {
4055
4124
  modules[moduleName] = {};
4056
4125
  for (const endpointName in module2) {
4057
4126
  const endpoint = module2[endpointName];
4058
- modules[moduleName][endpointName] = (input) => this.request(endpoint, input);
4127
+ modules[moduleName][endpointName] = (input, options) => this.request(endpoint, input, options);
4059
4128
  }
4060
4129
  }
4061
4130
  this._modules = modules;
4062
4131
  }
4063
- /**
4064
- * Type-safe entrypoint for calling API endpoints.
4065
- * Populated by `init()` based on the `contracts` passed to the constructor.
4066
- */
4132
+ /** Provides access to initialized modules after calling `init()`. */
4067
4133
  get modules() {
4068
4134
  return this._modules;
4069
4135
  }
4070
- /**
4071
- * Registers a middleware in the pipeline.
4072
- * Middlewares are executed in reverse order of registration.
4073
- */
4136
+ /** Registers a new middleware in the client’s pipeline. */
4074
4137
  use(middleware, options) {
4075
4138
  this.middlewares.push({ fn: middleware, options });
4076
4139
  }
4077
- /**
4078
- * Registers a global error handler.
4079
- * The handler is invoked for normalized errors before they are re-thrown.
4080
- */
4140
+ /** Sets a global error handler function to unify error behavior. */
4081
4141
  onError(handler) {
4082
4142
  this.errorHandler = handler;
4083
4143
  }
4084
- /**
4085
- * Registers a transformation function applied to all successful responses
4086
- * after Zod parsing.
4087
- */
4144
+ /** Defines a global transform function applied to all validated responses. */
4088
4145
  useResponseTransform(fn) {
4089
4146
  this.responseTransform = fn;
4090
4147
  }
4091
- /**
4092
- * Enables or disables mock mode. When enabled, endpoints with `mockData`
4093
- * return mocked responses instead of performing network requests.
4094
- */
4148
+ /** Configures the retry logic (max attempts, backoff mode, etc.). */
4149
+ setRetryConfig(config) {
4150
+ this.retryConfig = config;
4151
+ }
4152
+ /** Provides a custom token provider that returns tokens dynamically. */
4153
+ setTokenProvider(provider) {
4154
+ this.tokenProvider = provider;
4155
+ }
4156
+ /** Enables mock responses instead of network requests. */
4095
4157
  setMockMode(enabled, delay) {
4096
4158
  this.useMockData = enabled;
4097
- if (delay) {
4098
- this.mockDelay = delay;
4099
- }
4159
+ if (delay) this.mockDelay = delay;
4100
4160
  }
4101
- /**
4102
- * Registers a schema wrapper for APIs that wrap data in an envelope.
4103
- * Example: { success, data, message, code, ... }.
4104
- */
4161
+ /** Registers a wrapper schema for APIs that nest response data (e.g. `{ data, success, message }`). */
4105
4162
  setResponseWrapper(wrapper) {
4106
4163
  this.responseWrapper = wrapper;
4107
4164
  }
4108
- /**
4109
- * Sets or updates the token provider used for authenticated endpoints.
4110
- * Overrides any static token provided in the constructor.
4111
- */
4112
- setTokenProvider(provider) {
4113
- this.tokenProvider = provider;
4165
+ /** Retrieves the current auth token, using a provider if available. */
4166
+ async getCurrentToken() {
4167
+ if (this.tokenProvider) return await this.tokenProvider();
4168
+ return this.config.token;
4114
4169
  }
4115
4170
  /**
4116
- * Returns the current token, preferring the tokenProvider if present,
4117
- * otherwise falling back to the static token from the constructor.
4171
+ * Core request entry point used by auto-generated endpoint methods.
4172
+ * Handles caching, deduplication, and mock mode routing.
4118
4173
  */
4119
- getCurrentToken() {
4120
- return __async(this, null, function* () {
4121
- if (this.tokenProvider) {
4122
- return yield this.tokenProvider();
4123
- }
4124
- return this.config.token;
4125
- });
4174
+ async request(endpoint, input, options) {
4175
+ const parsedInput = endpoint.request.parse(input);
4176
+ if (this.useMockData && endpoint.mockData) {
4177
+ return this.handleMockRequest(endpoint);
4178
+ }
4179
+ const { url, body } = this.buildUrlAndBody(endpoint, parsedInput);
4180
+ const requestKey = JSON.stringify({ method: endpoint.method, url, body });
4181
+ const promise = this.performRequestLogic(
4182
+ endpoint,
4183
+ parsedInput,
4184
+ url,
4185
+ body,
4186
+ requestKey,
4187
+ options
4188
+ );
4189
+ return promise;
4126
4190
  }
4127
4191
  /**
4128
- * Executes a single endpoint request.
4129
- *
4130
- * Expected request shape (new style):
4131
- * z.object({
4132
- * path: z.object({...}).optional(),
4133
- * query: z.object({...}).optional(),
4134
- * body: z.any().optional(),
4135
- * header: z.object({...}).optional(),
4136
- * })
4137
- *
4138
- * If the parsed request does not contain `path`, `header`,`query` or `body`,
4139
- * the entire input is treated as the legacy flat request body.
4192
+ * Full HTTP request workflow:
4193
+ * - Token injection
4194
+ * - Timeout support
4195
+ * - Middleware pipeline
4196
+ * - Fetch + response handling
4197
+ * - Zod parsing + transformation
4198
+ * - Caching
4140
4199
  */
4141
- request(endpoint, input) {
4142
- return __async(this, null, function* () {
4143
- var _b, _c, _d, _e;
4144
- const parsedInput = endpoint.request.parse(input);
4145
- const isObject = typeof parsedInput === "object" && parsedInput !== null;
4146
- const looksStructured = isObject && ("path" in parsedInput || "query" in parsedInput || "body" in parsedInput || "headers" in parsedInput);
4147
- const _a = parsedInput, { headers: extraHeaders } = _a, restInput = __objRest(_a, ["headers"]);
4148
- if (this.useMockData && endpoint.mockData) {
4149
- return this.handleMockRequest(endpoint);
4150
- }
4151
- let token = this.config.token;
4152
- if (this.tokenProvider) {
4153
- token = yield this.tokenProvider();
4200
+ async performRequestLogic(endpoint, parsedInput, url, body, key, options) {
4201
+ const headers = {};
4202
+ const token = await this.getCurrentToken();
4203
+ if (endpoint.auth && !token) {
4204
+ const error = this.createError({
4205
+ message: `Missing token for ${endpoint.path}`,
4206
+ status: 401,
4207
+ code: "NO_TOKEN"
4208
+ });
4209
+ this.errorHandler?.(error);
4210
+ throw error;
4211
+ }
4212
+ if (endpoint.auth && token) headers["Authorization"] = `Bearer ${token}`;
4213
+ if (endpoint.bodyType !== "form-data")
4214
+ headers["Content-Type"] = "application/json";
4215
+ const ctx = {
4216
+ url,
4217
+ init: { method: endpoint.method, headers, body }
4218
+ };
4219
+ let controller;
4220
+ let timeoutId;
4221
+ if (options?.timeout) {
4222
+ controller = new AbortController();
4223
+ timeoutId = setTimeout(() => controller.abort(), options.timeout);
4224
+ }
4225
+ if (options?.signal || controller)
4226
+ ctx.init.signal = options?.signal || controller?.signal;
4227
+ const runner = this.middlewares.reduceRight(
4228
+ (next, mw) => () => mw.fn(ctx, next, mw.options),
4229
+ () => fetch(ctx.url, ctx.init)
4230
+ );
4231
+ const execute = async () => {
4232
+ const res = await runner();
4233
+ const json = await res.json();
4234
+ let responseData = json;
4235
+ if (this.responseWrapper) {
4236
+ const wrappedSchema = this.responseWrapper(endpoint.response);
4237
+ const parsedWrapped = wrappedSchema.parse(json);
4238
+ if (parsedWrapped.success === false) {
4239
+ const error = this.createError({
4240
+ message: parsedWrapped.message || "Request failed",
4241
+ status: parsedWrapped.code || res.status,
4242
+ code: `API_ERROR_${parsedWrapped.code}`
4243
+ });
4244
+ this.errorHandler?.(error);
4245
+ throw error;
4246
+ }
4247
+ responseData = parsedWrapped.data;
4154
4248
  }
4155
- if (endpoint.auth && !token) {
4249
+ if (!res.ok) {
4156
4250
  const error = this.createError({
4157
- message: `Missing token for ${endpoint.path}`,
4158
- status: 401,
4159
- code: "NO_TOKEN"
4251
+ message: json.message || res.statusText,
4252
+ status: res.status,
4253
+ code: json.code,
4254
+ title: json.title,
4255
+ detail: json.detail,
4256
+ errors: json.errors
4160
4257
  });
4161
- (_b = this.errorHandler) == null ? void 0 : _b.call(this, error);
4258
+ this.errorHandler?.(error);
4162
4259
  throw error;
4163
4260
  }
4164
- const headers = {};
4165
- if (endpoint.auth && token) {
4166
- headers["Authorization"] = `Bearer ${token}`;
4167
- }
4168
- if (endpoint.bodyType !== "form-data") {
4169
- headers["Content-Type"] = "application/json";
4170
- }
4171
- if (endpoint.headers) {
4172
- const endpointHeaders = typeof endpoint.headers === "function" ? endpoint.headers(parsedInput) : endpoint.headers;
4173
- for (const [key, value] of Object.entries(endpointHeaders)) {
4174
- headers[key] = value;
4175
- }
4176
- }
4177
- if (extraHeaders) {
4178
- for (const [key, value] of Object.entries(extraHeaders)) {
4179
- headers[key] = value;
4180
- }
4181
- }
4182
- const { url, body } = this.buildUrlAndBody(
4183
- endpoint,
4184
- restInput,
4185
- looksStructured
4186
- );
4187
- const ctx = {
4188
- url,
4189
- init: {
4190
- method: endpoint.method,
4191
- headers,
4192
- body
4193
- }
4194
- };
4195
- const runner = this.middlewares.reduceRight(
4196
- (next, mw) => () => mw.fn(ctx, next, mw.options),
4197
- () => fetch(ctx.url, ctx.init)
4198
- );
4261
+ const parsed = endpoint.response.parse(responseData);
4262
+ const result = this.responseTransform(parsed);
4263
+ return result;
4264
+ };
4265
+ try {
4266
+ const result = await this.executeWithRetry(execute);
4267
+ if (timeoutId) clearTimeout(timeoutId);
4268
+ return result;
4269
+ } catch (err) {
4270
+ if (timeoutId) clearTimeout(timeoutId);
4271
+ const error = this.normalizeError(err);
4272
+ this.errorHandler?.(error);
4273
+ throw error;
4274
+ }
4275
+ }
4276
+ // =========================================================
4277
+ // 🔁 RETRY ENGINE
4278
+ // =========================================================
4279
+ /** Executes a function with retry logic and configurable backoff strategy. */
4280
+ async executeWithRetry(fn) {
4281
+ if (!this.retryConfig) return fn();
4282
+ const { maxRetries, backoff, retryCondition } = this.retryConfig;
4283
+ let attempt = 0;
4284
+ while (true) {
4199
4285
  try {
4200
- const res = yield runner();
4201
- const json = yield res.json();
4202
- let responseData = json;
4203
- if (this.responseWrapper) {
4204
- const wrappedSchema = this.responseWrapper(endpoint.response);
4205
- const parsedResponse = wrappedSchema.parse(json);
4206
- if (parsedResponse.success === false) {
4207
- const error = this.createError({
4208
- message: parsedResponse.message || "Request failed",
4209
- status: parsedResponse.code || res.status,
4210
- code: `API_ERROR_${parsedResponse.code}`
4211
- });
4212
- (_c = this.errorHandler) == null ? void 0 : _c.call(this, error);
4213
- throw error;
4214
- }
4215
- responseData = parsedResponse.data;
4216
- }
4217
- if (!res.ok) {
4218
- const error = this.createError({
4219
- message: json.message || res.statusText,
4220
- status: res.status,
4221
- code: json.code,
4222
- title: json.title,
4223
- detail: json.detail,
4224
- errors: json.errors
4225
- });
4226
- (_d = this.errorHandler) == null ? void 0 : _d.call(this, error);
4227
- throw error;
4228
- }
4229
- return this.responseTransform(endpoint.response.parse(responseData));
4286
+ return await fn();
4230
4287
  } catch (err) {
4288
+ attempt++;
4231
4289
  const error = this.normalizeError(err);
4232
- (_e = this.errorHandler) == null ? void 0 : _e.call(this, error);
4233
- throw error;
4290
+ const shouldRetry = attempt <= maxRetries && (retryCondition?.(error, attempt) ?? (error.status !== void 0 && error.status >= 500));
4291
+ if (!shouldRetry) throw error;
4292
+ const delay = this.getBackoffDelay(backoff, attempt);
4293
+ await new Promise((r) => setTimeout(r, delay));
4234
4294
  }
4235
- });
4295
+ }
4236
4296
  }
4237
- /**
4238
- * Builds final URL and body from endpoint + request input.
4239
- * Supports both structured `{ path, query, body, headers }` and legacy flat input.
4240
- */
4241
- buildUrlAndBody(endpoint, parsedInput, looksStructured) {
4242
- if (!looksStructured) {
4243
- const url2 = this.config.baseUrl + endpoint.path;
4244
- let requestBody2 = void 0;
4245
- if (endpoint.method !== "GET") {
4246
- if (endpoint.bodyType === "form-data") {
4247
- const form = new FormData();
4248
- const flat = parsedInput || {};
4249
- for (const [key, value] of Object.entries(flat)) {
4250
- if (value === void 0 || value === null) continue;
4251
- if (Array.isArray(value)) {
4252
- for (const v of value) {
4253
- if (v === void 0 || v === null) continue;
4254
- form.append(key, v);
4255
- }
4256
- } else {
4257
- form.append(key, value);
4258
- }
4259
- }
4260
- requestBody2 = form;
4261
- } else {
4262
- requestBody2 = JSON.stringify(parsedInput);
4263
- }
4264
- }
4265
- return { url: url2, body: requestBody2 };
4297
+ /** Calculates retry delay intervals for various backoff strategies. */
4298
+ getBackoffDelay(type, attempt) {
4299
+ const base = 300;
4300
+ switch (type) {
4301
+ case "fixed":
4302
+ return base;
4303
+ case "linear":
4304
+ return base * attempt;
4305
+ case "exponential":
4306
+ return base * Math.pow(2, attempt - 1);
4266
4307
  }
4267
- const { path, query, body } = parsedInput;
4308
+ }
4309
+ // =========================================================
4310
+ // 🔧 UTILITIES
4311
+ // =========================================================
4312
+ /** Builds the final URL and request body from the endpoint definition and input payload. */
4313
+ buildUrlAndBody(endpoint, input) {
4268
4314
  let url = this.config.baseUrl + endpoint.path;
4269
- if (path) {
4270
- for (const [key, value] of Object.entries(path)) {
4271
- if (value === void 0 || value === null) continue;
4272
- const token = `:${key}`;
4273
- if (!url.includes(token)) {
4274
- continue;
4275
- }
4276
- url = url.replace(token, encodeURIComponent(String(value)));
4277
- }
4278
- }
4279
- const templatePlaceholders = Array.from(
4280
- endpoint.path.matchAll(/:([A-Za-z0-9_]+)/g)
4281
- ).map((m) => m[1]);
4282
- const missingTokens = templatePlaceholders.filter((name) => {
4283
- const v = path ? path[name] : void 0;
4284
- return v === void 0 || v === null;
4285
- });
4286
- if (missingTokens.length > 0) {
4287
- throw this.createError({
4288
- message: `Missing path params for placeholders: ${missingTokens.join(
4289
- ", "
4290
- )} in "${endpoint.path}"`,
4291
- code: "MISSING_PATH_PARAMS"
4292
- });
4293
- }
4294
- if (query) {
4295
- const searchParams = new URLSearchParams();
4296
- for (const [key, value] of Object.entries(query)) {
4297
- if (value === void 0 || value === null) continue;
4298
- if (Array.isArray(value)) {
4299
- for (const v of value) {
4300
- if (v === void 0 || v === null) continue;
4301
- searchParams.append(key, String(v));
4302
- }
4303
- } else if (typeof value === "object") {
4304
- searchParams.append(key, JSON.stringify(value));
4305
- } else {
4306
- searchParams.append(key, String(value));
4307
- }
4308
- }
4309
- const qs = searchParams.toString();
4310
- if (qs) {
4311
- url += (url.includes("?") ? "&" : "?") + qs;
4312
- }
4313
- }
4314
- let requestBody = void 0;
4315
+ let body;
4315
4316
  if (endpoint.method !== "GET") {
4316
- if (body !== void 0 && body !== null) {
4317
- if (endpoint.bodyType === "form-data") {
4318
- const form = new FormData();
4319
- for (const [key, value] of Object.entries(body)) {
4320
- if (value === void 0 || value === null) continue;
4321
- if (Array.isArray(value)) {
4322
- for (const v of value) {
4323
- if (v === void 0 || v === null) continue;
4324
- form.append(key, v);
4325
- }
4326
- } else {
4327
- form.append(key, value);
4328
- }
4329
- }
4330
- requestBody = form;
4331
- } else {
4332
- requestBody = JSON.stringify(body);
4317
+ if (endpoint.bodyType === "form-data") {
4318
+ const form = new FormData();
4319
+ for (const [k, v] of Object.entries(input.body || {})) {
4320
+ if (v != null) form.append(k, v);
4333
4321
  }
4334
- }
4335
- }
4336
- return { url, body: requestBody };
4337
- }
4338
- /**
4339
- * Returns a mocked response based on `endpoint.mockData`,
4340
- * respecting the configured mock delay and response wrapper.
4341
- */
4342
- handleMockRequest(endpoint) {
4343
- return __async(this, null, function* () {
4344
- const delay = this.getRandomDelay();
4345
- yield new Promise((resolve) => setTimeout(resolve, delay));
4346
- let mockData;
4347
- if (typeof endpoint.mockData === "function") {
4348
- mockData = endpoint.mockData();
4322
+ body = form;
4349
4323
  } else {
4350
- mockData = endpoint.mockData;
4324
+ body = JSON.stringify(input.body ?? input);
4351
4325
  }
4352
- if (this.responseWrapper) {
4353
- const wrappedSchema = this.responseWrapper(endpoint.response);
4354
- const mockWrappedResponse = {
4355
- success: true,
4356
- data: mockData,
4357
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
4358
- requestId: `mock-${Math.random().toString(36).substr(2, 9)}`
4359
- };
4360
- const parsedWrappedResponse = wrappedSchema.parse(mockWrappedResponse);
4361
- return this.responseTransform(
4362
- endpoint.response.parse(parsedWrappedResponse.data)
4363
- );
4364
- }
4365
- return this.responseTransform(endpoint.response.parse(mockData));
4366
- });
4367
- }
4368
- /**
4369
- * Returns a random delay in milliseconds within the current mock delay range.
4370
- */
4371
- getRandomDelay() {
4372
- return Math.floor(
4373
- Math.random() * (this.mockDelay.max - this.mockDelay.min + 1)
4374
- ) + this.mockDelay.min;
4326
+ }
4327
+ return { url, body };
4375
4328
  }
4376
- /**
4377
- * Creates a RichError instance from a partial error description.
4378
- */
4329
+ /** Creates and returns a RichError from details. */
4379
4330
  createError(error) {
4380
4331
  return new RichError(error);
4381
4332
  }
4382
4333
  /**
4383
- * Normalizes unknown errors into a RichError instance.
4384
- * Zod validation errors are converted into a standardized validation error.
4334
+ * Converts any thrown error to a standardized RichError instance.
4335
+ * Also flattens Zod validation errors into readable messages.
4385
4336
  */
4386
4337
  normalizeError(err) {
4387
4338
  if (err instanceof RichError) return err;
@@ -4393,78 +4344,99 @@ var ApiClient = class {
4393
4344
  }
4394
4345
  return this.createError({ message: err.message || "Unknown error" });
4395
4346
  }
4347
+ /**
4348
+ * Handles mock-mode requests by simulating a delayed network call
4349
+ * and returning validated mock data.
4350
+ */
4351
+ async handleMockRequest(endpoint) {
4352
+ const delay = Math.floor(
4353
+ Math.random() * (this.mockDelay.max - this.mockDelay.min + 1)
4354
+ ) + this.mockDelay.min;
4355
+ await new Promise((r) => setTimeout(r, delay));
4356
+ const data = typeof endpoint.mockData === "function" ? endpoint.mockData() : endpoint.mockData;
4357
+ return this.responseTransform(endpoint.response.parse(data));
4358
+ }
4396
4359
  };
4397
4360
 
4398
4361
  // src/middlewares/logging.ts
4399
- var loggingMiddleware = (ctx, next, options) => __async(null, null, function* () {
4362
+ var loggingMiddleware = async (ctx, next, options) => {
4400
4363
  const { logRequest = true, logResponse = true, debug = true } = options || {};
4401
4364
  if (debug && logRequest) console.log("\u27A1\uFE0F Request:", ctx.url, ctx.init);
4402
- const res = yield next();
4365
+ const res = await next();
4403
4366
  if (debug && logResponse) console.log("\u2B05\uFE0F Response:", res.status);
4404
4367
  return res;
4405
- });
4368
+ };
4406
4369
 
4407
4370
  // src/middlewares/retry.ts
4408
4371
  var retryMiddleware = (options) => {
4409
4372
  const { maxRetries = 3, delay = 500 } = options || {};
4410
- const middleware = (ctx, next) => __async(null, null, function* () {
4373
+ const middleware = async (ctx, next) => {
4411
4374
  let attempt = 0;
4412
4375
  while (true) {
4413
4376
  try {
4414
- return yield next();
4377
+ return await next();
4415
4378
  } catch (err) {
4416
4379
  if (attempt >= maxRetries) throw err;
4417
4380
  attempt++;
4418
- yield new Promise((r) => setTimeout(r, delay * __pow(2, attempt)));
4381
+ await new Promise((r) => setTimeout(r, delay * 2 ** attempt));
4419
4382
  }
4420
4383
  }
4421
- });
4384
+ };
4422
4385
  return middleware;
4423
4386
  };
4424
4387
 
4425
4388
  // src/middlewares/auth.ts
4426
- var authMiddleware = (ctx, next, options) => __async(null, null, function* () {
4427
- if (options == null ? void 0 : options.refreshToken) {
4389
+ var authMiddleware = async (ctx, next, options) => {
4390
+ if (options?.refreshToken) {
4428
4391
  try {
4429
- const newToken = yield options.refreshToken();
4430
- ctx.init.headers = __spreadProps(__spreadValues({}, ctx.init.headers), {
4392
+ const newToken = await options.refreshToken();
4393
+ ctx.init.headers = {
4394
+ ...ctx.init.headers,
4395
+ // Preserve any headers set by prior middleware
4431
4396
  Authorization: `Bearer ${newToken}`
4432
- });
4433
- } catch (e) {
4397
+ };
4398
+ } catch (error) {
4399
+ console.warn(
4400
+ "Authentication token refresh failed, proceeding without authorization header.",
4401
+ error
4402
+ );
4434
4403
  }
4435
4404
  }
4436
4405
  return next();
4437
- });
4406
+ };
4438
4407
 
4439
4408
  // src/middlewares/cache.ts
4440
4409
  var cacheMiddleware = (options = {}) => {
4441
4410
  const { ttl = 6e4 } = options;
4442
4411
  const cache = /* @__PURE__ */ new Map();
4443
- return (ctx, next) => __async(null, null, function* () {
4412
+ return async (ctx, next) => {
4444
4413
  if (ctx.init.method === "GET") {
4445
- const cached = cache.get(ctx.url);
4414
+ const key = `${ctx.init.method}:${ctx.url}`;
4415
+ const cached = cache.get(key);
4446
4416
  const now = Date.now();
4447
- if (cached && cached.expires > now)
4448
- return new Response(JSON.stringify(cached.data));
4449
- const res = yield next();
4450
- const data = yield res.clone().json().catch(() => null);
4451
- if (data) cache.set(ctx.url, { data, expires: now + ttl });
4417
+ if (cached && cached.expires > now) {
4418
+ return new Response(JSON.stringify(cached.data), {
4419
+ headers: { "Content-Type": "application/json" }
4420
+ });
4421
+ }
4422
+ const res = await next();
4423
+ const data = await res.clone().json().catch(() => null);
4424
+ if (data) {
4425
+ cache.set(key, { data, expires: now + ttl });
4426
+ }
4452
4427
  return res;
4453
4428
  }
4454
4429
  return next();
4455
- });
4430
+ };
4456
4431
  };
4457
4432
 
4458
4433
  // src/utils/make-request-schema.ts
4459
- var makeRequestSchema = () => (defs) => {
4460
- var _a, _b, _c, _d, _e, _f;
4461
- return external_exports.object({
4462
- path: (_b = (_a = defs.path) != null ? _a : external_exports.object({})) == null ? void 0 : _b.optional(),
4463
- query: (_d = (_c = defs.query) != null ? _c : external_exports.object({})) == null ? void 0 : _d.optional(),
4464
- body: (_e = defs.body) != null ? _e : external_exports.undefined(),
4465
- headers: (_f = defs.headers) != null ? _f : external_exports.record(external_exports.string()).optional()
4466
- });
4467
- };
4434
+ var makeRequestSchema = () => (defs) => external_exports.object({
4435
+ path: (defs.path ?? external_exports.object({}))?.optional(),
4436
+ query: (defs.query ?? external_exports.object({}))?.optional(),
4437
+ body: defs.body ?? external_exports.undefined(),
4438
+ headers: defs.headers ?? external_exports.record(external_exports.string()).optional()
4439
+ });
4468
4440
  // Annotate the CommonJS export names for ESM import in node:
4469
4441
  0 && (module.exports = {
4470
4442
  ApiClient,