@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.mjs CHANGED
@@ -1,59 +1,8 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __pow = Math.pow;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __spreadValues = (a, b) => {
10
- for (var prop in b || (b = {}))
11
- if (__hasOwnProp.call(b, prop))
12
- __defNormalProp(a, prop, b[prop]);
13
- if (__getOwnPropSymbols)
14
- for (var prop of __getOwnPropSymbols(b)) {
15
- if (__propIsEnum.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- var __objRest = (source, exclude) => {
22
- var target = {};
23
- for (var prop in source)
24
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
- target[prop] = source[prop];
26
- if (source != null && __getOwnPropSymbols)
27
- for (var prop of __getOwnPropSymbols(source)) {
28
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
- target[prop] = source[prop];
30
- }
31
- return target;
32
- };
33
2
  var __export = (target, all) => {
34
3
  for (var name in all)
35
4
  __defProp(target, name, { get: all[name], enumerable: true });
36
5
  };
37
- var __async = (__this, __arguments, generator) => {
38
- return new Promise((resolve, reject) => {
39
- var fulfilled = (value) => {
40
- try {
41
- step(generator.next(value));
42
- } catch (e) {
43
- reject(e);
44
- }
45
- };
46
- var rejected = (value) => {
47
- try {
48
- step(generator.throw(value));
49
- } catch (e) {
50
- reject(e);
51
- }
52
- };
53
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
54
- step((generator = generator.apply(__this, __arguments)).next());
55
- });
56
- };
57
6
 
58
7
  // node_modules/zod/v3/external.js
59
8
  var external_exports = {};
@@ -230,7 +179,11 @@ var util;
230
179
  var objectUtil;
231
180
  (function(objectUtil2) {
232
181
  objectUtil2.mergeShapes = (first, second) => {
233
- return __spreadValues(__spreadValues({}, first), second);
182
+ return {
183
+ ...first,
184
+ ...second
185
+ // second overwrites first
186
+ };
234
187
  };
235
188
  })(objectUtil || (objectUtil = {}));
236
189
  var ZodParsedType = util.arrayToEnum([
@@ -531,24 +484,27 @@ function getErrorMap() {
531
484
  var makeIssue = (params) => {
532
485
  const { data, path, errorMaps, issueData } = params;
533
486
  const fullPath = [...path, ...issueData.path || []];
534
- const fullIssue = __spreadProps(__spreadValues({}, issueData), {
487
+ const fullIssue = {
488
+ ...issueData,
535
489
  path: fullPath
536
- });
490
+ };
537
491
  if (issueData.message !== void 0) {
538
- return __spreadProps(__spreadValues({}, issueData), {
492
+ return {
493
+ ...issueData,
539
494
  path: fullPath,
540
495
  message: issueData.message
541
- });
496
+ };
542
497
  }
543
498
  let errorMessage = "";
544
499
  const maps = errorMaps.filter((m) => !!m).slice().reverse();
545
500
  for (const map of maps) {
546
501
  errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
547
502
  }
548
- return __spreadProps(__spreadValues({}, issueData), {
503
+ return {
504
+ ...issueData,
549
505
  path: fullPath,
550
506
  message: errorMessage
551
- });
507
+ };
552
508
  };
553
509
  var EMPTY_PATH = [];
554
510
  function addIssueToContext(ctx, issueData) {
@@ -593,19 +549,17 @@ var ParseStatus = class _ParseStatus {
593
549
  }
594
550
  return { status: status.value, value: arrayValue };
595
551
  }
596
- static mergeObjectAsync(status, pairs) {
597
- return __async(this, null, function* () {
598
- const syncPairs = [];
599
- for (const pair of pairs) {
600
- const key = yield pair.key;
601
- const value = yield pair.value;
602
- syncPairs.push({
603
- key,
604
- value
605
- });
606
- }
607
- return _ParseStatus.mergeObjectSync(status, syncPairs);
608
- });
552
+ static async mergeObjectAsync(status, pairs) {
553
+ const syncPairs = [];
554
+ for (const pair of pairs) {
555
+ const key = await pair.key;
556
+ const value = await pair.value;
557
+ syncPairs.push({
558
+ key,
559
+ value
560
+ });
561
+ }
562
+ return _ParseStatus.mergeObjectSync(status, syncPairs);
609
563
  }
610
564
  static mergeObjectSync(status, pairs) {
611
565
  const finalObject = {};
@@ -640,7 +594,7 @@ var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
640
594
  var errorUtil;
641
595
  (function(errorUtil2) {
642
596
  errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
643
- errorUtil2.toString = (message) => typeof message === "string" ? message : message == null ? void 0 : message.message;
597
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
644
598
  })(errorUtil || (errorUtil = {}));
645
599
 
646
600
  // node_modules/zod/v3/types.js
@@ -692,17 +646,16 @@ function processCreateParams(params) {
692
646
  if (errorMap2)
693
647
  return { errorMap: errorMap2, description };
694
648
  const customMap = (iss, ctx) => {
695
- var _a, _b;
696
649
  const { message } = params;
697
650
  if (iss.code === "invalid_enum_value") {
698
- return { message: message != null ? message : ctx.defaultError };
651
+ return { message: message ?? ctx.defaultError };
699
652
  }
700
653
  if (typeof ctx.data === "undefined") {
701
- return { message: (_a = message != null ? message : required_error) != null ? _a : ctx.defaultError };
654
+ return { message: message ?? required_error ?? ctx.defaultError };
702
655
  }
703
656
  if (iss.code !== "invalid_type")
704
657
  return { message: ctx.defaultError };
705
- return { message: (_b = message != null ? message : invalid_type_error) != null ? _b : ctx.defaultError };
658
+ return { message: message ?? invalid_type_error ?? ctx.defaultError };
706
659
  };
707
660
  return { errorMap: customMap, description };
708
661
  }
@@ -754,14 +707,13 @@ var ZodType = class {
754
707
  throw result.error;
755
708
  }
756
709
  safeParse(data, params) {
757
- var _a;
758
710
  const ctx = {
759
711
  common: {
760
712
  issues: [],
761
- async: (_a = params == null ? void 0 : params.async) != null ? _a : false,
762
- contextualErrorMap: params == null ? void 0 : params.errorMap
713
+ async: params?.async ?? false,
714
+ contextualErrorMap: params?.errorMap
763
715
  },
764
- path: (params == null ? void 0 : params.path) || [],
716
+ path: params?.path || [],
765
717
  schemaErrorMap: this._def.errorMap,
766
718
  parent: null,
767
719
  data,
@@ -771,7 +723,6 @@ var ZodType = class {
771
723
  return handleResult(ctx, result);
772
724
  }
773
725
  "~validate"(data) {
774
- var _a, _b;
775
726
  const ctx = {
776
727
  common: {
777
728
  issues: [],
@@ -792,7 +743,7 @@ var ZodType = class {
792
743
  issues: ctx.common.issues
793
744
  };
794
745
  } catch (err) {
795
- if ((_b = (_a = err == null ? void 0 : err.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) {
746
+ if (err?.message?.toLowerCase()?.includes("encountered")) {
796
747
  this["~standard"].async = true;
797
748
  }
798
749
  ctx.common = {
@@ -807,32 +758,28 @@ var ZodType = class {
807
758
  issues: ctx.common.issues
808
759
  });
809
760
  }
810
- parseAsync(data, params) {
811
- return __async(this, null, function* () {
812
- const result = yield this.safeParseAsync(data, params);
813
- if (result.success)
814
- return result.data;
815
- throw result.error;
816
- });
761
+ async parseAsync(data, params) {
762
+ const result = await this.safeParseAsync(data, params);
763
+ if (result.success)
764
+ return result.data;
765
+ throw result.error;
817
766
  }
818
- safeParseAsync(data, params) {
819
- return __async(this, null, function* () {
820
- const ctx = {
821
- common: {
822
- issues: [],
823
- contextualErrorMap: params == null ? void 0 : params.errorMap,
824
- async: true
825
- },
826
- path: (params == null ? void 0 : params.path) || [],
827
- schemaErrorMap: this._def.errorMap,
828
- parent: null,
829
- data,
830
- parsedType: getParsedType(data)
831
- };
832
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
833
- const result = yield isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult);
834
- return handleResult(ctx, result);
835
- });
767
+ async safeParseAsync(data, params) {
768
+ const ctx = {
769
+ common: {
770
+ issues: [],
771
+ contextualErrorMap: params?.errorMap,
772
+ async: true
773
+ },
774
+ path: params?.path || [],
775
+ schemaErrorMap: this._def.errorMap,
776
+ parent: null,
777
+ data,
778
+ parsedType: getParsedType(data)
779
+ };
780
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
781
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
782
+ return handleResult(ctx, result);
836
783
  }
837
784
  refine(check, message) {
838
785
  const getIssueProperties = (val) => {
@@ -846,9 +793,10 @@ var ZodType = class {
846
793
  };
847
794
  return this._refinement((val, ctx) => {
848
795
  const result = check(val);
849
- const setError = () => ctx.addIssue(__spreadValues({
850
- code: ZodIssueCode.custom
851
- }, getIssueProperties(val)));
796
+ const setError = () => ctx.addIssue({
797
+ code: ZodIssueCode.custom,
798
+ ...getIssueProperties(val)
799
+ });
852
800
  if (typeof Promise !== "undefined" && result instanceof Promise) {
853
801
  return result.then((data) => {
854
802
  if (!data) {
@@ -942,39 +890,44 @@ var ZodType = class {
942
890
  return ZodIntersection.create(this, incoming, this._def);
943
891
  }
944
892
  transform(transform) {
945
- return new ZodEffects(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
893
+ return new ZodEffects({
894
+ ...processCreateParams(this._def),
946
895
  schema: this,
947
896
  typeName: ZodFirstPartyTypeKind.ZodEffects,
948
897
  effect: { type: "transform", transform }
949
- }));
898
+ });
950
899
  }
951
900
  default(def) {
952
901
  const defaultValueFunc = typeof def === "function" ? def : () => def;
953
- return new ZodDefault(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
902
+ return new ZodDefault({
903
+ ...processCreateParams(this._def),
954
904
  innerType: this,
955
905
  defaultValue: defaultValueFunc,
956
906
  typeName: ZodFirstPartyTypeKind.ZodDefault
957
- }));
907
+ });
958
908
  }
959
909
  brand() {
960
- return new ZodBranded(__spreadValues({
910
+ return new ZodBranded({
961
911
  typeName: ZodFirstPartyTypeKind.ZodBranded,
962
- type: this
963
- }, processCreateParams(this._def)));
912
+ type: this,
913
+ ...processCreateParams(this._def)
914
+ });
964
915
  }
965
916
  catch(def) {
966
917
  const catchValueFunc = typeof def === "function" ? def : () => def;
967
- return new ZodCatch(__spreadProps(__spreadValues({}, processCreateParams(this._def)), {
918
+ return new ZodCatch({
919
+ ...processCreateParams(this._def),
968
920
  innerType: this,
969
921
  catchValue: catchValueFunc,
970
922
  typeName: ZodFirstPartyTypeKind.ZodCatch
971
- }));
923
+ });
972
924
  }
973
925
  describe(description) {
974
926
  const This = this.constructor;
975
- return new This(__spreadProps(__spreadValues({}, this._def), {
927
+ return new This({
928
+ ...this._def,
976
929
  description
977
- }));
930
+ });
978
931
  }
979
932
  pipe(target) {
980
933
  return ZodPipeline.create(this, target);
@@ -1049,14 +1002,14 @@ function isValidJWT(jwt, alg) {
1049
1002
  const decoded = JSON.parse(atob(base64));
1050
1003
  if (typeof decoded !== "object" || decoded === null)
1051
1004
  return false;
1052
- if ("typ" in decoded && (decoded == null ? void 0 : decoded.typ) !== "JWT")
1005
+ if ("typ" in decoded && decoded?.typ !== "JWT")
1053
1006
  return false;
1054
1007
  if (!decoded.alg)
1055
1008
  return false;
1056
1009
  if (alg && decoded.alg !== alg)
1057
1010
  return false;
1058
1011
  return true;
1059
- } catch (e) {
1012
+ } catch {
1060
1013
  return false;
1061
1014
  }
1062
1015
  }
@@ -1215,7 +1168,7 @@ var ZodString = class _ZodString extends ZodType {
1215
1168
  } else if (check.kind === "url") {
1216
1169
  try {
1217
1170
  new URL(input.data);
1218
- } catch (e) {
1171
+ } catch {
1219
1172
  ctx = this._getOrReturnCtx(input, ctx);
1220
1173
  addIssueToContext(ctx, {
1221
1174
  validation: "url",
@@ -1372,59 +1325,61 @@ var ZodString = class _ZodString extends ZodType {
1372
1325
  return { status: status.value, value: input.data };
1373
1326
  }
1374
1327
  _regex(regex, validation, message) {
1375
- return this.refinement((data) => regex.test(data), __spreadValues({
1328
+ return this.refinement((data) => regex.test(data), {
1376
1329
  validation,
1377
- code: ZodIssueCode.invalid_string
1378
- }, errorUtil.errToObj(message)));
1330
+ code: ZodIssueCode.invalid_string,
1331
+ ...errorUtil.errToObj(message)
1332
+ });
1379
1333
  }
1380
1334
  _addCheck(check) {
1381
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1335
+ return new _ZodString({
1336
+ ...this._def,
1382
1337
  checks: [...this._def.checks, check]
1383
- }));
1338
+ });
1384
1339
  }
1385
1340
  email(message) {
1386
- return this._addCheck(__spreadValues({ kind: "email" }, errorUtil.errToObj(message)));
1341
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1387
1342
  }
1388
1343
  url(message) {
1389
- return this._addCheck(__spreadValues({ kind: "url" }, errorUtil.errToObj(message)));
1344
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1390
1345
  }
1391
1346
  emoji(message) {
1392
- return this._addCheck(__spreadValues({ kind: "emoji" }, errorUtil.errToObj(message)));
1347
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1393
1348
  }
1394
1349
  uuid(message) {
1395
- return this._addCheck(__spreadValues({ kind: "uuid" }, errorUtil.errToObj(message)));
1350
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1396
1351
  }
1397
1352
  nanoid(message) {
1398
- return this._addCheck(__spreadValues({ kind: "nanoid" }, errorUtil.errToObj(message)));
1353
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1399
1354
  }
1400
1355
  cuid(message) {
1401
- return this._addCheck(__spreadValues({ kind: "cuid" }, errorUtil.errToObj(message)));
1356
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1402
1357
  }
1403
1358
  cuid2(message) {
1404
- return this._addCheck(__spreadValues({ kind: "cuid2" }, errorUtil.errToObj(message)));
1359
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1405
1360
  }
1406
1361
  ulid(message) {
1407
- return this._addCheck(__spreadValues({ kind: "ulid" }, errorUtil.errToObj(message)));
1362
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1408
1363
  }
1409
1364
  base64(message) {
1410
- return this._addCheck(__spreadValues({ kind: "base64" }, errorUtil.errToObj(message)));
1365
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1411
1366
  }
1412
1367
  base64url(message) {
1413
- return this._addCheck(__spreadValues({
1414
- kind: "base64url"
1415
- }, errorUtil.errToObj(message)));
1368
+ return this._addCheck({
1369
+ kind: "base64url",
1370
+ ...errorUtil.errToObj(message)
1371
+ });
1416
1372
  }
1417
1373
  jwt(options) {
1418
- return this._addCheck(__spreadValues({ kind: "jwt" }, errorUtil.errToObj(options)));
1374
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1419
1375
  }
1420
1376
  ip(options) {
1421
- return this._addCheck(__spreadValues({ kind: "ip" }, errorUtil.errToObj(options)));
1377
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1422
1378
  }
1423
1379
  cidr(options) {
1424
- return this._addCheck(__spreadValues({ kind: "cidr" }, errorUtil.errToObj(options)));
1380
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1425
1381
  }
1426
1382
  datetime(options) {
1427
- var _a, _b;
1428
1383
  if (typeof options === "string") {
1429
1384
  return this._addCheck({
1430
1385
  kind: "datetime",
@@ -1434,12 +1389,13 @@ var ZodString = class _ZodString extends ZodType {
1434
1389
  message: options
1435
1390
  });
1436
1391
  }
1437
- return this._addCheck(__spreadValues({
1392
+ return this._addCheck({
1438
1393
  kind: "datetime",
1439
- precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision,
1440
- offset: (_a = options == null ? void 0 : options.offset) != null ? _a : false,
1441
- local: (_b = options == null ? void 0 : options.local) != null ? _b : false
1442
- }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1394
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1395
+ offset: options?.offset ?? false,
1396
+ local: options?.local ?? false,
1397
+ ...errorUtil.errToObj(options?.message)
1398
+ });
1443
1399
  }
1444
1400
  date(message) {
1445
1401
  return this._addCheck({ kind: "date", message });
@@ -1452,56 +1408,64 @@ var ZodString = class _ZodString extends ZodType {
1452
1408
  message: options
1453
1409
  });
1454
1410
  }
1455
- return this._addCheck(__spreadValues({
1411
+ return this._addCheck({
1456
1412
  kind: "time",
1457
- precision: typeof (options == null ? void 0 : options.precision) === "undefined" ? null : options == null ? void 0 : options.precision
1458
- }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1413
+ precision: typeof options?.precision === "undefined" ? null : options?.precision,
1414
+ ...errorUtil.errToObj(options?.message)
1415
+ });
1459
1416
  }
1460
1417
  duration(message) {
1461
- return this._addCheck(__spreadValues({ kind: "duration" }, errorUtil.errToObj(message)));
1418
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1462
1419
  }
1463
1420
  regex(regex, message) {
1464
- return this._addCheck(__spreadValues({
1421
+ return this._addCheck({
1465
1422
  kind: "regex",
1466
- regex
1467
- }, errorUtil.errToObj(message)));
1423
+ regex,
1424
+ ...errorUtil.errToObj(message)
1425
+ });
1468
1426
  }
1469
1427
  includes(value, options) {
1470
- return this._addCheck(__spreadValues({
1428
+ return this._addCheck({
1471
1429
  kind: "includes",
1472
1430
  value,
1473
- position: options == null ? void 0 : options.position
1474
- }, errorUtil.errToObj(options == null ? void 0 : options.message)));
1431
+ position: options?.position,
1432
+ ...errorUtil.errToObj(options?.message)
1433
+ });
1475
1434
  }
1476
1435
  startsWith(value, message) {
1477
- return this._addCheck(__spreadValues({
1436
+ return this._addCheck({
1478
1437
  kind: "startsWith",
1479
- value
1480
- }, errorUtil.errToObj(message)));
1438
+ value,
1439
+ ...errorUtil.errToObj(message)
1440
+ });
1481
1441
  }
1482
1442
  endsWith(value, message) {
1483
- return this._addCheck(__spreadValues({
1443
+ return this._addCheck({
1484
1444
  kind: "endsWith",
1485
- value
1486
- }, errorUtil.errToObj(message)));
1445
+ value,
1446
+ ...errorUtil.errToObj(message)
1447
+ });
1487
1448
  }
1488
1449
  min(minLength, message) {
1489
- return this._addCheck(__spreadValues({
1450
+ return this._addCheck({
1490
1451
  kind: "min",
1491
- value: minLength
1492
- }, errorUtil.errToObj(message)));
1452
+ value: minLength,
1453
+ ...errorUtil.errToObj(message)
1454
+ });
1493
1455
  }
1494
1456
  max(maxLength, message) {
1495
- return this._addCheck(__spreadValues({
1457
+ return this._addCheck({
1496
1458
  kind: "max",
1497
- value: maxLength
1498
- }, errorUtil.errToObj(message)));
1459
+ value: maxLength,
1460
+ ...errorUtil.errToObj(message)
1461
+ });
1499
1462
  }
1500
1463
  length(len, message) {
1501
- return this._addCheck(__spreadValues({
1464
+ return this._addCheck({
1502
1465
  kind: "length",
1503
- value: len
1504
- }, errorUtil.errToObj(message)));
1466
+ value: len,
1467
+ ...errorUtil.errToObj(message)
1468
+ });
1505
1469
  }
1506
1470
  /**
1507
1471
  * Equivalent to `.min(1)`
@@ -1510,19 +1474,22 @@ var ZodString = class _ZodString extends ZodType {
1510
1474
  return this.min(1, errorUtil.errToObj(message));
1511
1475
  }
1512
1476
  trim() {
1513
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1477
+ return new _ZodString({
1478
+ ...this._def,
1514
1479
  checks: [...this._def.checks, { kind: "trim" }]
1515
- }));
1480
+ });
1516
1481
  }
1517
1482
  toLowerCase() {
1518
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1483
+ return new _ZodString({
1484
+ ...this._def,
1519
1485
  checks: [...this._def.checks, { kind: "toLowerCase" }]
1520
- }));
1486
+ });
1521
1487
  }
1522
1488
  toUpperCase() {
1523
- return new _ZodString(__spreadProps(__spreadValues({}, this._def), {
1489
+ return new _ZodString({
1490
+ ...this._def,
1524
1491
  checks: [...this._def.checks, { kind: "toUpperCase" }]
1525
- }));
1492
+ });
1526
1493
  }
1527
1494
  get isDatetime() {
1528
1495
  return !!this._def.checks.find((ch) => ch.kind === "datetime");
@@ -1594,12 +1561,12 @@ var ZodString = class _ZodString extends ZodType {
1594
1561
  }
1595
1562
  };
1596
1563
  ZodString.create = (params) => {
1597
- var _a;
1598
- return new ZodString(__spreadValues({
1564
+ return new ZodString({
1599
1565
  checks: [],
1600
1566
  typeName: ZodFirstPartyTypeKind.ZodString,
1601
- coerce: (_a = params == null ? void 0 : params.coerce) != null ? _a : false
1602
- }, processCreateParams(params)));
1567
+ coerce: params?.coerce ?? false,
1568
+ ...processCreateParams(params)
1569
+ });
1603
1570
  };
1604
1571
  function floatSafeRemainder(val, step) {
1605
1572
  const valDecCount = (val.toString().split(".")[1] || "").length;
@@ -1607,7 +1574,7 @@ function floatSafeRemainder(val, step) {
1607
1574
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1608
1575
  const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
1609
1576
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
1610
- return valInt % stepInt / __pow(10, decCount);
1577
+ return valInt % stepInt / 10 ** decCount;
1611
1578
  }
1612
1579
  var ZodNumber = class _ZodNumber extends ZodType {
1613
1580
  constructor() {
@@ -1710,7 +1677,8 @@ var ZodNumber = class _ZodNumber extends ZodType {
1710
1677
  return this.setLimit("max", value, false, errorUtil.toString(message));
1711
1678
  }
1712
1679
  setLimit(kind, value, inclusive, message) {
1713
- return new _ZodNumber(__spreadProps(__spreadValues({}, this._def), {
1680
+ return new _ZodNumber({
1681
+ ...this._def,
1714
1682
  checks: [
1715
1683
  ...this._def.checks,
1716
1684
  {
@@ -1720,12 +1688,13 @@ var ZodNumber = class _ZodNumber extends ZodType {
1720
1688
  message: errorUtil.toString(message)
1721
1689
  }
1722
1690
  ]
1723
- }));
1691
+ });
1724
1692
  }
1725
1693
  _addCheck(check) {
1726
- return new _ZodNumber(__spreadProps(__spreadValues({}, this._def), {
1694
+ return new _ZodNumber({
1695
+ ...this._def,
1727
1696
  checks: [...this._def.checks, check]
1728
- }));
1697
+ });
1729
1698
  }
1730
1699
  int(message) {
1731
1700
  return this._addCheck({
@@ -1832,11 +1801,12 @@ var ZodNumber = class _ZodNumber extends ZodType {
1832
1801
  }
1833
1802
  };
1834
1803
  ZodNumber.create = (params) => {
1835
- return new ZodNumber(__spreadValues({
1804
+ return new ZodNumber({
1836
1805
  checks: [],
1837
1806
  typeName: ZodFirstPartyTypeKind.ZodNumber,
1838
- coerce: (params == null ? void 0 : params.coerce) || false
1839
- }, processCreateParams(params)));
1807
+ coerce: params?.coerce || false,
1808
+ ...processCreateParams(params)
1809
+ });
1840
1810
  };
1841
1811
  var ZodBigInt = class _ZodBigInt extends ZodType {
1842
1812
  constructor() {
@@ -1848,7 +1818,7 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1848
1818
  if (this._def.coerce) {
1849
1819
  try {
1850
1820
  input.data = BigInt(input.data);
1851
- } catch (e) {
1821
+ } catch {
1852
1822
  return this._getInvalidInput(input);
1853
1823
  }
1854
1824
  }
@@ -1923,7 +1893,8 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1923
1893
  return this.setLimit("max", value, false, errorUtil.toString(message));
1924
1894
  }
1925
1895
  setLimit(kind, value, inclusive, message) {
1926
- return new _ZodBigInt(__spreadProps(__spreadValues({}, this._def), {
1896
+ return new _ZodBigInt({
1897
+ ...this._def,
1927
1898
  checks: [
1928
1899
  ...this._def.checks,
1929
1900
  {
@@ -1933,12 +1904,13 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
1933
1904
  message: errorUtil.toString(message)
1934
1905
  }
1935
1906
  ]
1936
- }));
1907
+ });
1937
1908
  }
1938
1909
  _addCheck(check) {
1939
- return new _ZodBigInt(__spreadProps(__spreadValues({}, this._def), {
1910
+ return new _ZodBigInt({
1911
+ ...this._def,
1940
1912
  checks: [...this._def.checks, check]
1941
- }));
1913
+ });
1942
1914
  }
1943
1915
  positive(message) {
1944
1916
  return this._addCheck({
@@ -2001,12 +1973,12 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
2001
1973
  }
2002
1974
  };
2003
1975
  ZodBigInt.create = (params) => {
2004
- var _a;
2005
- return new ZodBigInt(__spreadValues({
1976
+ return new ZodBigInt({
2006
1977
  checks: [],
2007
1978
  typeName: ZodFirstPartyTypeKind.ZodBigInt,
2008
- coerce: (_a = params == null ? void 0 : params.coerce) != null ? _a : false
2009
- }, processCreateParams(params)));
1979
+ coerce: params?.coerce ?? false,
1980
+ ...processCreateParams(params)
1981
+ });
2010
1982
  };
2011
1983
  var ZodBoolean = class extends ZodType {
2012
1984
  _parse(input) {
@@ -2027,10 +1999,11 @@ var ZodBoolean = class extends ZodType {
2027
1999
  }
2028
2000
  };
2029
2001
  ZodBoolean.create = (params) => {
2030
- return new ZodBoolean(__spreadValues({
2002
+ return new ZodBoolean({
2031
2003
  typeName: ZodFirstPartyTypeKind.ZodBoolean,
2032
- coerce: (params == null ? void 0 : params.coerce) || false
2033
- }, processCreateParams(params)));
2004
+ coerce: params?.coerce || false,
2005
+ ...processCreateParams(params)
2006
+ });
2034
2007
  };
2035
2008
  var ZodDate = class _ZodDate extends ZodType {
2036
2009
  _parse(input) {
@@ -2093,9 +2066,10 @@ var ZodDate = class _ZodDate extends ZodType {
2093
2066
  };
2094
2067
  }
2095
2068
  _addCheck(check) {
2096
- return new _ZodDate(__spreadProps(__spreadValues({}, this._def), {
2069
+ return new _ZodDate({
2070
+ ...this._def,
2097
2071
  checks: [...this._def.checks, check]
2098
- }));
2072
+ });
2099
2073
  }
2100
2074
  min(minDate, message) {
2101
2075
  return this._addCheck({
@@ -2133,11 +2107,12 @@ var ZodDate = class _ZodDate extends ZodType {
2133
2107
  }
2134
2108
  };
2135
2109
  ZodDate.create = (params) => {
2136
- return new ZodDate(__spreadValues({
2110
+ return new ZodDate({
2137
2111
  checks: [],
2138
- coerce: (params == null ? void 0 : params.coerce) || false,
2139
- typeName: ZodFirstPartyTypeKind.ZodDate
2140
- }, processCreateParams(params)));
2112
+ coerce: params?.coerce || false,
2113
+ typeName: ZodFirstPartyTypeKind.ZodDate,
2114
+ ...processCreateParams(params)
2115
+ });
2141
2116
  };
2142
2117
  var ZodSymbol = class extends ZodType {
2143
2118
  _parse(input) {
@@ -2155,9 +2130,10 @@ var ZodSymbol = class extends ZodType {
2155
2130
  }
2156
2131
  };
2157
2132
  ZodSymbol.create = (params) => {
2158
- return new ZodSymbol(__spreadValues({
2159
- typeName: ZodFirstPartyTypeKind.ZodSymbol
2160
- }, processCreateParams(params)));
2133
+ return new ZodSymbol({
2134
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2135
+ ...processCreateParams(params)
2136
+ });
2161
2137
  };
2162
2138
  var ZodUndefined = class extends ZodType {
2163
2139
  _parse(input) {
@@ -2175,9 +2151,10 @@ var ZodUndefined = class extends ZodType {
2175
2151
  }
2176
2152
  };
2177
2153
  ZodUndefined.create = (params) => {
2178
- return new ZodUndefined(__spreadValues({
2179
- typeName: ZodFirstPartyTypeKind.ZodUndefined
2180
- }, processCreateParams(params)));
2154
+ return new ZodUndefined({
2155
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2156
+ ...processCreateParams(params)
2157
+ });
2181
2158
  };
2182
2159
  var ZodNull = class extends ZodType {
2183
2160
  _parse(input) {
@@ -2195,9 +2172,10 @@ var ZodNull = class extends ZodType {
2195
2172
  }
2196
2173
  };
2197
2174
  ZodNull.create = (params) => {
2198
- return new ZodNull(__spreadValues({
2199
- typeName: ZodFirstPartyTypeKind.ZodNull
2200
- }, processCreateParams(params)));
2175
+ return new ZodNull({
2176
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2177
+ ...processCreateParams(params)
2178
+ });
2201
2179
  };
2202
2180
  var ZodAny = class extends ZodType {
2203
2181
  constructor() {
@@ -2209,9 +2187,10 @@ var ZodAny = class extends ZodType {
2209
2187
  }
2210
2188
  };
2211
2189
  ZodAny.create = (params) => {
2212
- return new ZodAny(__spreadValues({
2213
- typeName: ZodFirstPartyTypeKind.ZodAny
2214
- }, processCreateParams(params)));
2190
+ return new ZodAny({
2191
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2192
+ ...processCreateParams(params)
2193
+ });
2215
2194
  };
2216
2195
  var ZodUnknown = class extends ZodType {
2217
2196
  constructor() {
@@ -2223,9 +2202,10 @@ var ZodUnknown = class extends ZodType {
2223
2202
  }
2224
2203
  };
2225
2204
  ZodUnknown.create = (params) => {
2226
- return new ZodUnknown(__spreadValues({
2227
- typeName: ZodFirstPartyTypeKind.ZodUnknown
2228
- }, processCreateParams(params)));
2205
+ return new ZodUnknown({
2206
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2207
+ ...processCreateParams(params)
2208
+ });
2229
2209
  };
2230
2210
  var ZodNever = class extends ZodType {
2231
2211
  _parse(input) {
@@ -2239,9 +2219,10 @@ var ZodNever = class extends ZodType {
2239
2219
  }
2240
2220
  };
2241
2221
  ZodNever.create = (params) => {
2242
- return new ZodNever(__spreadValues({
2243
- typeName: ZodFirstPartyTypeKind.ZodNever
2244
- }, processCreateParams(params)));
2222
+ return new ZodNever({
2223
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2224
+ ...processCreateParams(params)
2225
+ });
2245
2226
  };
2246
2227
  var ZodVoid = class extends ZodType {
2247
2228
  _parse(input) {
@@ -2259,9 +2240,10 @@ var ZodVoid = class extends ZodType {
2259
2240
  }
2260
2241
  };
2261
2242
  ZodVoid.create = (params) => {
2262
- return new ZodVoid(__spreadValues({
2263
- typeName: ZodFirstPartyTypeKind.ZodVoid
2264
- }, processCreateParams(params)));
2243
+ return new ZodVoid({
2244
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2245
+ ...processCreateParams(params)
2246
+ });
2265
2247
  };
2266
2248
  var ZodArray = class _ZodArray extends ZodType {
2267
2249
  _parse(input) {
@@ -2333,32 +2315,36 @@ var ZodArray = class _ZodArray extends ZodType {
2333
2315
  return this._def.type;
2334
2316
  }
2335
2317
  min(minLength, message) {
2336
- return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2318
+ return new _ZodArray({
2319
+ ...this._def,
2337
2320
  minLength: { value: minLength, message: errorUtil.toString(message) }
2338
- }));
2321
+ });
2339
2322
  }
2340
2323
  max(maxLength, message) {
2341
- return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2324
+ return new _ZodArray({
2325
+ ...this._def,
2342
2326
  maxLength: { value: maxLength, message: errorUtil.toString(message) }
2343
- }));
2327
+ });
2344
2328
  }
2345
2329
  length(len, message) {
2346
- return new _ZodArray(__spreadProps(__spreadValues({}, this._def), {
2330
+ return new _ZodArray({
2331
+ ...this._def,
2347
2332
  exactLength: { value: len, message: errorUtil.toString(message) }
2348
- }));
2333
+ });
2349
2334
  }
2350
2335
  nonempty(message) {
2351
2336
  return this.min(1, message);
2352
2337
  }
2353
2338
  };
2354
2339
  ZodArray.create = (schema, params) => {
2355
- return new ZodArray(__spreadValues({
2340
+ return new ZodArray({
2356
2341
  type: schema,
2357
2342
  minLength: null,
2358
2343
  maxLength: null,
2359
2344
  exactLength: null,
2360
- typeName: ZodFirstPartyTypeKind.ZodArray
2361
- }, processCreateParams(params)));
2345
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2346
+ ...processCreateParams(params)
2347
+ });
2362
2348
  };
2363
2349
  function deepPartialify(schema) {
2364
2350
  if (schema instanceof ZodObject) {
@@ -2367,13 +2353,15 @@ function deepPartialify(schema) {
2367
2353
  const fieldSchema = schema.shape[key];
2368
2354
  newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2369
2355
  }
2370
- return new ZodObject(__spreadProps(__spreadValues({}, schema._def), {
2356
+ return new ZodObject({
2357
+ ...schema._def,
2371
2358
  shape: () => newShape
2372
- }));
2359
+ });
2373
2360
  } else if (schema instanceof ZodArray) {
2374
- return new ZodArray(__spreadProps(__spreadValues({}, schema._def), {
2361
+ return new ZodArray({
2362
+ ...schema._def,
2375
2363
  type: deepPartialify(schema.element)
2376
- }));
2364
+ });
2377
2365
  } else if (schema instanceof ZodOptional) {
2378
2366
  return ZodOptional.create(deepPartialify(schema.unwrap()));
2379
2367
  } else if (schema instanceof ZodNullable) {
@@ -2466,11 +2454,11 @@ var ZodObject = class _ZodObject extends ZodType {
2466
2454
  }
2467
2455
  }
2468
2456
  if (ctx.common.async) {
2469
- return Promise.resolve().then(() => __async(this, null, function* () {
2457
+ return Promise.resolve().then(async () => {
2470
2458
  const syncPairs = [];
2471
2459
  for (const pair of pairs) {
2472
- const key = yield pair.key;
2473
- const value = yield pair.value;
2460
+ const key = await pair.key;
2461
+ const value = await pair.value;
2474
2462
  syncPairs.push({
2475
2463
  key,
2476
2464
  value,
@@ -2478,7 +2466,7 @@ var ZodObject = class _ZodObject extends ZodType {
2478
2466
  });
2479
2467
  }
2480
2468
  return syncPairs;
2481
- })).then((syncPairs) => {
2469
+ }).then((syncPairs) => {
2482
2470
  return ParseStatus.mergeObjectSync(status, syncPairs);
2483
2471
  });
2484
2472
  } else {
@@ -2490,31 +2478,34 @@ var ZodObject = class _ZodObject extends ZodType {
2490
2478
  }
2491
2479
  strict(message) {
2492
2480
  errorUtil.errToObj;
2493
- return new _ZodObject(__spreadValues(__spreadProps(__spreadValues({}, this._def), {
2494
- unknownKeys: "strict"
2495
- }), message !== void 0 ? {
2496
- errorMap: (issue, ctx) => {
2497
- var _a, _b, _c, _d;
2498
- const defaultError = (_c = (_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, issue, ctx).message) != null ? _c : ctx.defaultError;
2499
- if (issue.code === "unrecognized_keys")
2481
+ return new _ZodObject({
2482
+ ...this._def,
2483
+ unknownKeys: "strict",
2484
+ ...message !== void 0 ? {
2485
+ errorMap: (issue, ctx) => {
2486
+ const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
2487
+ if (issue.code === "unrecognized_keys")
2488
+ return {
2489
+ message: errorUtil.errToObj(message).message ?? defaultError
2490
+ };
2500
2491
  return {
2501
- message: (_d = errorUtil.errToObj(message).message) != null ? _d : defaultError
2492
+ message: defaultError
2502
2493
  };
2503
- return {
2504
- message: defaultError
2505
- };
2506
- }
2507
- } : {}));
2494
+ }
2495
+ } : {}
2496
+ });
2508
2497
  }
2509
2498
  strip() {
2510
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2499
+ return new _ZodObject({
2500
+ ...this._def,
2511
2501
  unknownKeys: "strip"
2512
- }));
2502
+ });
2513
2503
  }
2514
2504
  passthrough() {
2515
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2505
+ return new _ZodObject({
2506
+ ...this._def,
2516
2507
  unknownKeys: "passthrough"
2517
- }));
2508
+ });
2518
2509
  }
2519
2510
  // const AugmentFactory =
2520
2511
  // <Def extends ZodObjectDef>(def: Def) =>
@@ -2534,9 +2525,13 @@ var ZodObject = class _ZodObject extends ZodType {
2534
2525
  // }) as any;
2535
2526
  // };
2536
2527
  extend(augmentation) {
2537
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2538
- shape: () => __spreadValues(__spreadValues({}, this._def.shape()), augmentation)
2539
- }));
2528
+ return new _ZodObject({
2529
+ ...this._def,
2530
+ shape: () => ({
2531
+ ...this._def.shape(),
2532
+ ...augmentation
2533
+ })
2534
+ });
2540
2535
  }
2541
2536
  /**
2542
2537
  * Prior to zod@1.0.12 there was a bug in the
@@ -2547,7 +2542,10 @@ var ZodObject = class _ZodObject extends ZodType {
2547
2542
  const merged = new _ZodObject({
2548
2543
  unknownKeys: merging._def.unknownKeys,
2549
2544
  catchall: merging._def.catchall,
2550
- shape: () => __spreadValues(__spreadValues({}, this._def.shape()), merging._def.shape()),
2545
+ shape: () => ({
2546
+ ...this._def.shape(),
2547
+ ...merging._def.shape()
2548
+ }),
2551
2549
  typeName: ZodFirstPartyTypeKind.ZodObject
2552
2550
  });
2553
2551
  return merged;
@@ -2612,9 +2610,10 @@ var ZodObject = class _ZodObject extends ZodType {
2612
2610
  // return merged;
2613
2611
  // }
2614
2612
  catchall(index) {
2615
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2613
+ return new _ZodObject({
2614
+ ...this._def,
2616
2615
  catchall: index
2617
- }));
2616
+ });
2618
2617
  }
2619
2618
  pick(mask) {
2620
2619
  const shape = {};
@@ -2623,9 +2622,10 @@ var ZodObject = class _ZodObject extends ZodType {
2623
2622
  shape[key] = this.shape[key];
2624
2623
  }
2625
2624
  }
2626
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2625
+ return new _ZodObject({
2626
+ ...this._def,
2627
2627
  shape: () => shape
2628
- }));
2628
+ });
2629
2629
  }
2630
2630
  omit(mask) {
2631
2631
  const shape = {};
@@ -2634,9 +2634,10 @@ var ZodObject = class _ZodObject extends ZodType {
2634
2634
  shape[key] = this.shape[key];
2635
2635
  }
2636
2636
  }
2637
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2637
+ return new _ZodObject({
2638
+ ...this._def,
2638
2639
  shape: () => shape
2639
- }));
2640
+ });
2640
2641
  }
2641
2642
  /**
2642
2643
  * @deprecated
@@ -2654,9 +2655,10 @@ var ZodObject = class _ZodObject extends ZodType {
2654
2655
  newShape[key] = fieldSchema.optional();
2655
2656
  }
2656
2657
  }
2657
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2658
+ return new _ZodObject({
2659
+ ...this._def,
2658
2660
  shape: () => newShape
2659
- }));
2661
+ });
2660
2662
  }
2661
2663
  required(mask) {
2662
2664
  const newShape = {};
@@ -2672,37 +2674,41 @@ var ZodObject = class _ZodObject extends ZodType {
2672
2674
  newShape[key] = newField;
2673
2675
  }
2674
2676
  }
2675
- return new _ZodObject(__spreadProps(__spreadValues({}, this._def), {
2677
+ return new _ZodObject({
2678
+ ...this._def,
2676
2679
  shape: () => newShape
2677
- }));
2680
+ });
2678
2681
  }
2679
2682
  keyof() {
2680
2683
  return createZodEnum(util.objectKeys(this.shape));
2681
2684
  }
2682
2685
  };
2683
2686
  ZodObject.create = (shape, params) => {
2684
- return new ZodObject(__spreadValues({
2687
+ return new ZodObject({
2685
2688
  shape: () => shape,
2686
2689
  unknownKeys: "strip",
2687
2690
  catchall: ZodNever.create(),
2688
- typeName: ZodFirstPartyTypeKind.ZodObject
2689
- }, processCreateParams(params)));
2691
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2692
+ ...processCreateParams(params)
2693
+ });
2690
2694
  };
2691
2695
  ZodObject.strictCreate = (shape, params) => {
2692
- return new ZodObject(__spreadValues({
2696
+ return new ZodObject({
2693
2697
  shape: () => shape,
2694
2698
  unknownKeys: "strict",
2695
2699
  catchall: ZodNever.create(),
2696
- typeName: ZodFirstPartyTypeKind.ZodObject
2697
- }, processCreateParams(params)));
2700
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2701
+ ...processCreateParams(params)
2702
+ });
2698
2703
  };
2699
2704
  ZodObject.lazycreate = (shape, params) => {
2700
- return new ZodObject(__spreadValues({
2705
+ return new ZodObject({
2701
2706
  shape,
2702
2707
  unknownKeys: "strip",
2703
2708
  catchall: ZodNever.create(),
2704
- typeName: ZodFirstPartyTypeKind.ZodObject
2705
- }, processCreateParams(params)));
2709
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2710
+ ...processCreateParams(params)
2711
+ });
2706
2712
  };
2707
2713
  var ZodUnion = class extends ZodType {
2708
2714
  _parse(input) {
@@ -2728,32 +2734,36 @@ var ZodUnion = class extends ZodType {
2728
2734
  return INVALID;
2729
2735
  }
2730
2736
  if (ctx.common.async) {
2731
- return Promise.all(options.map((option) => __async(this, null, function* () {
2732
- const childCtx = __spreadProps(__spreadValues({}, ctx), {
2733
- common: __spreadProps(__spreadValues({}, ctx.common), {
2737
+ return Promise.all(options.map(async (option) => {
2738
+ const childCtx = {
2739
+ ...ctx,
2740
+ common: {
2741
+ ...ctx.common,
2734
2742
  issues: []
2735
- }),
2743
+ },
2736
2744
  parent: null
2737
- });
2745
+ };
2738
2746
  return {
2739
- result: yield option._parseAsync({
2747
+ result: await option._parseAsync({
2740
2748
  data: ctx.data,
2741
2749
  path: ctx.path,
2742
2750
  parent: childCtx
2743
2751
  }),
2744
2752
  ctx: childCtx
2745
2753
  };
2746
- }))).then(handleResults);
2754
+ })).then(handleResults);
2747
2755
  } else {
2748
2756
  let dirty = void 0;
2749
2757
  const issues = [];
2750
2758
  for (const option of options) {
2751
- const childCtx = __spreadProps(__spreadValues({}, ctx), {
2752
- common: __spreadProps(__spreadValues({}, ctx.common), {
2759
+ const childCtx = {
2760
+ ...ctx,
2761
+ common: {
2762
+ ...ctx.common,
2753
2763
  issues: []
2754
- }),
2764
+ },
2755
2765
  parent: null
2756
- });
2766
+ };
2757
2767
  const result = option._parseSync({
2758
2768
  data: ctx.data,
2759
2769
  path: ctx.path,
@@ -2785,10 +2795,11 @@ var ZodUnion = class extends ZodType {
2785
2795
  }
2786
2796
  };
2787
2797
  ZodUnion.create = (types, params) => {
2788
- return new ZodUnion(__spreadValues({
2798
+ return new ZodUnion({
2789
2799
  options: types,
2790
- typeName: ZodFirstPartyTypeKind.ZodUnion
2791
- }, processCreateParams(params)));
2800
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2801
+ ...processCreateParams(params)
2802
+ });
2792
2803
  };
2793
2804
  var getDiscriminator = (type) => {
2794
2805
  if (type instanceof ZodLazy) {
@@ -2888,12 +2899,13 @@ var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
2888
2899
  optionsMap.set(value, type);
2889
2900
  }
2890
2901
  }
2891
- return new _ZodDiscriminatedUnion(__spreadValues({
2902
+ return new _ZodDiscriminatedUnion({
2892
2903
  typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2893
2904
  discriminator,
2894
2905
  options,
2895
- optionsMap
2896
- }, processCreateParams(params)));
2906
+ optionsMap,
2907
+ ...processCreateParams(params)
2908
+ });
2897
2909
  }
2898
2910
  };
2899
2911
  function mergeValues(a, b) {
@@ -2904,7 +2916,7 @@ function mergeValues(a, b) {
2904
2916
  } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2905
2917
  const bKeys = util.objectKeys(b);
2906
2918
  const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
2907
- const newObj = __spreadValues(__spreadValues({}, a), b);
2919
+ const newObj = { ...a, ...b };
2908
2920
  for (const key of sharedKeys) {
2909
2921
  const sharedValue = mergeValues(a[key], b[key]);
2910
2922
  if (!sharedValue.valid) {
@@ -2980,11 +2992,12 @@ var ZodIntersection = class extends ZodType {
2980
2992
  }
2981
2993
  };
2982
2994
  ZodIntersection.create = (left, right, params) => {
2983
- return new ZodIntersection(__spreadValues({
2995
+ return new ZodIntersection({
2984
2996
  left,
2985
2997
  right,
2986
- typeName: ZodFirstPartyTypeKind.ZodIntersection
2987
- }, processCreateParams(params)));
2998
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2999
+ ...processCreateParams(params)
3000
+ });
2988
3001
  };
2989
3002
  var ZodTuple = class _ZodTuple extends ZodType {
2990
3003
  _parse(input) {
@@ -3036,20 +3049,22 @@ var ZodTuple = class _ZodTuple extends ZodType {
3036
3049
  return this._def.items;
3037
3050
  }
3038
3051
  rest(rest) {
3039
- return new _ZodTuple(__spreadProps(__spreadValues({}, this._def), {
3052
+ return new _ZodTuple({
3053
+ ...this._def,
3040
3054
  rest
3041
- }));
3055
+ });
3042
3056
  }
3043
3057
  };
3044
3058
  ZodTuple.create = (schemas, params) => {
3045
3059
  if (!Array.isArray(schemas)) {
3046
3060
  throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
3047
3061
  }
3048
- return new ZodTuple(__spreadValues({
3062
+ return new ZodTuple({
3049
3063
  items: schemas,
3050
3064
  typeName: ZodFirstPartyTypeKind.ZodTuple,
3051
- rest: null
3052
- }, processCreateParams(params)));
3065
+ rest: null,
3066
+ ...processCreateParams(params)
3067
+ });
3053
3068
  };
3054
3069
  var ZodRecord = class _ZodRecord extends ZodType {
3055
3070
  get keySchema() {
@@ -3089,17 +3104,19 @@ var ZodRecord = class _ZodRecord extends ZodType {
3089
3104
  }
3090
3105
  static create(first, second, third) {
3091
3106
  if (second instanceof ZodType) {
3092
- return new _ZodRecord(__spreadValues({
3107
+ return new _ZodRecord({
3093
3108
  keyType: first,
3094
3109
  valueType: second,
3095
- typeName: ZodFirstPartyTypeKind.ZodRecord
3096
- }, processCreateParams(third)));
3110
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3111
+ ...processCreateParams(third)
3112
+ });
3097
3113
  }
3098
- return new _ZodRecord(__spreadValues({
3114
+ return new _ZodRecord({
3099
3115
  keyType: ZodString.create(),
3100
3116
  valueType: first,
3101
- typeName: ZodFirstPartyTypeKind.ZodRecord
3102
- }, processCreateParams(second)));
3117
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3118
+ ...processCreateParams(second)
3119
+ });
3103
3120
  }
3104
3121
  };
3105
3122
  var ZodMap = class extends ZodType {
@@ -3129,10 +3146,10 @@ var ZodMap = class extends ZodType {
3129
3146
  });
3130
3147
  if (ctx.common.async) {
3131
3148
  const finalMap = /* @__PURE__ */ new Map();
3132
- return Promise.resolve().then(() => __async(this, null, function* () {
3149
+ return Promise.resolve().then(async () => {
3133
3150
  for (const pair of pairs) {
3134
- const key = yield pair.key;
3135
- const value = yield pair.value;
3151
+ const key = await pair.key;
3152
+ const value = await pair.value;
3136
3153
  if (key.status === "aborted" || value.status === "aborted") {
3137
3154
  return INVALID;
3138
3155
  }
@@ -3142,7 +3159,7 @@ var ZodMap = class extends ZodType {
3142
3159
  finalMap.set(key.value, value.value);
3143
3160
  }
3144
3161
  return { status: status.value, value: finalMap };
3145
- }));
3162
+ });
3146
3163
  } else {
3147
3164
  const finalMap = /* @__PURE__ */ new Map();
3148
3165
  for (const pair of pairs) {
@@ -3161,11 +3178,12 @@ var ZodMap = class extends ZodType {
3161
3178
  }
3162
3179
  };
3163
3180
  ZodMap.create = (keyType, valueType, params) => {
3164
- return new ZodMap(__spreadValues({
3181
+ return new ZodMap({
3165
3182
  valueType,
3166
3183
  keyType,
3167
- typeName: ZodFirstPartyTypeKind.ZodMap
3168
- }, processCreateParams(params)));
3184
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3185
+ ...processCreateParams(params)
3186
+ });
3169
3187
  };
3170
3188
  var ZodSet = class _ZodSet extends ZodType {
3171
3189
  _parse(input) {
@@ -3225,14 +3243,16 @@ var ZodSet = class _ZodSet extends ZodType {
3225
3243
  }
3226
3244
  }
3227
3245
  min(minSize, message) {
3228
- return new _ZodSet(__spreadProps(__spreadValues({}, this._def), {
3246
+ return new _ZodSet({
3247
+ ...this._def,
3229
3248
  minSize: { value: minSize, message: errorUtil.toString(message) }
3230
- }));
3249
+ });
3231
3250
  }
3232
3251
  max(maxSize, message) {
3233
- return new _ZodSet(__spreadProps(__spreadValues({}, this._def), {
3252
+ return new _ZodSet({
3253
+ ...this._def,
3234
3254
  maxSize: { value: maxSize, message: errorUtil.toString(message) }
3235
- }));
3255
+ });
3236
3256
  }
3237
3257
  size(size, message) {
3238
3258
  return this.min(size, message).max(size, message);
@@ -3242,12 +3262,13 @@ var ZodSet = class _ZodSet extends ZodType {
3242
3262
  }
3243
3263
  };
3244
3264
  ZodSet.create = (valueType, params) => {
3245
- return new ZodSet(__spreadValues({
3265
+ return new ZodSet({
3246
3266
  valueType,
3247
3267
  minSize: null,
3248
3268
  maxSize: null,
3249
- typeName: ZodFirstPartyTypeKind.ZodSet
3250
- }, processCreateParams(params)));
3269
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3270
+ ...processCreateParams(params)
3271
+ });
3251
3272
  };
3252
3273
  var ZodFunction = class _ZodFunction extends ZodType {
3253
3274
  constructor() {
@@ -3290,20 +3311,18 @@ var ZodFunction = class _ZodFunction extends ZodType {
3290
3311
  const fn = ctx.data;
3291
3312
  if (this._def.returns instanceof ZodPromise) {
3292
3313
  const me = this;
3293
- return OK(function(...args) {
3294
- return __async(this, null, function* () {
3295
- const error = new ZodError([]);
3296
- const parsedArgs = yield me._def.args.parseAsync(args, params).catch((e) => {
3297
- error.addIssue(makeArgsIssue(args, e));
3298
- throw error;
3299
- });
3300
- const result = yield Reflect.apply(fn, this, parsedArgs);
3301
- const parsedReturns = yield me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3302
- error.addIssue(makeReturnsIssue(result, e));
3303
- throw error;
3304
- });
3305
- return parsedReturns;
3314
+ return OK(async function(...args) {
3315
+ const error = new ZodError([]);
3316
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
3317
+ error.addIssue(makeArgsIssue(args, e));
3318
+ throw error;
3319
+ });
3320
+ const result = await Reflect.apply(fn, this, parsedArgs);
3321
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
3322
+ error.addIssue(makeReturnsIssue(result, e));
3323
+ throw error;
3306
3324
  });
3325
+ return parsedReturns;
3307
3326
  });
3308
3327
  } else {
3309
3328
  const me = this;
@@ -3328,14 +3347,16 @@ var ZodFunction = class _ZodFunction extends ZodType {
3328
3347
  return this._def.returns;
3329
3348
  }
3330
3349
  args(...items) {
3331
- return new _ZodFunction(__spreadProps(__spreadValues({}, this._def), {
3350
+ return new _ZodFunction({
3351
+ ...this._def,
3332
3352
  args: ZodTuple.create(items).rest(ZodUnknown.create())
3333
- }));
3353
+ });
3334
3354
  }
3335
3355
  returns(returnType) {
3336
- return new _ZodFunction(__spreadProps(__spreadValues({}, this._def), {
3356
+ return new _ZodFunction({
3357
+ ...this._def,
3337
3358
  returns: returnType
3338
- }));
3359
+ });
3339
3360
  }
3340
3361
  implement(func) {
3341
3362
  const validatedFunc = this.parse(func);
@@ -3346,11 +3367,12 @@ var ZodFunction = class _ZodFunction extends ZodType {
3346
3367
  return validatedFunc;
3347
3368
  }
3348
3369
  static create(args, returns, params) {
3349
- return new _ZodFunction(__spreadValues({
3370
+ return new _ZodFunction({
3350
3371
  args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3351
3372
  returns: returns || ZodUnknown.create(),
3352
- typeName: ZodFirstPartyTypeKind.ZodFunction
3353
- }, processCreateParams(params)));
3373
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3374
+ ...processCreateParams(params)
3375
+ });
3354
3376
  }
3355
3377
  };
3356
3378
  var ZodLazy = class extends ZodType {
@@ -3364,10 +3386,11 @@ var ZodLazy = class extends ZodType {
3364
3386
  }
3365
3387
  };
3366
3388
  ZodLazy.create = (getter, params) => {
3367
- return new ZodLazy(__spreadValues({
3389
+ return new ZodLazy({
3368
3390
  getter,
3369
- typeName: ZodFirstPartyTypeKind.ZodLazy
3370
- }, processCreateParams(params)));
3391
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3392
+ ...processCreateParams(params)
3393
+ });
3371
3394
  };
3372
3395
  var ZodLiteral = class extends ZodType {
3373
3396
  _parse(input) {
@@ -3387,16 +3410,18 @@ var ZodLiteral = class extends ZodType {
3387
3410
  }
3388
3411
  };
3389
3412
  ZodLiteral.create = (value, params) => {
3390
- return new ZodLiteral(__spreadValues({
3413
+ return new ZodLiteral({
3391
3414
  value,
3392
- typeName: ZodFirstPartyTypeKind.ZodLiteral
3393
- }, processCreateParams(params)));
3415
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3416
+ ...processCreateParams(params)
3417
+ });
3394
3418
  };
3395
3419
  function createZodEnum(values, params) {
3396
- return new ZodEnum(__spreadValues({
3420
+ return new ZodEnum({
3397
3421
  values,
3398
- typeName: ZodFirstPartyTypeKind.ZodEnum
3399
- }, processCreateParams(params)));
3422
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3423
+ ...processCreateParams(params)
3424
+ });
3400
3425
  }
3401
3426
  var ZodEnum = class _ZodEnum extends ZodType {
3402
3427
  _parse(input) {
@@ -3450,10 +3475,16 @@ var ZodEnum = class _ZodEnum extends ZodType {
3450
3475
  return enumValues;
3451
3476
  }
3452
3477
  extract(values, newDef = this._def) {
3453
- return _ZodEnum.create(values, __spreadValues(__spreadValues({}, this._def), newDef));
3478
+ return _ZodEnum.create(values, {
3479
+ ...this._def,
3480
+ ...newDef
3481
+ });
3454
3482
  }
3455
3483
  exclude(values, newDef = this._def) {
3456
- return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), __spreadValues(__spreadValues({}, this._def), newDef));
3484
+ return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3485
+ ...this._def,
3486
+ ...newDef
3487
+ });
3457
3488
  }
3458
3489
  };
3459
3490
  ZodEnum.create = createZodEnum;
@@ -3489,10 +3520,11 @@ var ZodNativeEnum = class extends ZodType {
3489
3520
  }
3490
3521
  };
3491
3522
  ZodNativeEnum.create = (values, params) => {
3492
- return new ZodNativeEnum(__spreadValues({
3523
+ return new ZodNativeEnum({
3493
3524
  values,
3494
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum
3495
- }, processCreateParams(params)));
3525
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3526
+ ...processCreateParams(params)
3527
+ });
3496
3528
  };
3497
3529
  var ZodPromise = class extends ZodType {
3498
3530
  unwrap() {
@@ -3518,10 +3550,11 @@ var ZodPromise = class extends ZodType {
3518
3550
  }
3519
3551
  };
3520
3552
  ZodPromise.create = (schema, params) => {
3521
- return new ZodPromise(__spreadValues({
3553
+ return new ZodPromise({
3522
3554
  type: schema,
3523
- typeName: ZodFirstPartyTypeKind.ZodPromise
3524
- }, processCreateParams(params)));
3555
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3556
+ ...processCreateParams(params)
3557
+ });
3525
3558
  };
3526
3559
  var ZodEffects = class extends ZodType {
3527
3560
  innerType() {
@@ -3550,10 +3583,10 @@ var ZodEffects = class extends ZodType {
3550
3583
  if (effect.type === "preprocess") {
3551
3584
  const processed = effect.transform(ctx.data, checkCtx);
3552
3585
  if (ctx.common.async) {
3553
- return Promise.resolve(processed).then((processed2) => __async(this, null, function* () {
3586
+ return Promise.resolve(processed).then(async (processed2) => {
3554
3587
  if (status.value === "aborted")
3555
3588
  return INVALID;
3556
- const result = yield this._def.schema._parseAsync({
3589
+ const result = await this._def.schema._parseAsync({
3557
3590
  data: processed2,
3558
3591
  path: ctx.path,
3559
3592
  parent: ctx
@@ -3565,7 +3598,7 @@ var ZodEffects = class extends ZodType {
3565
3598
  if (status.value === "dirty")
3566
3599
  return DIRTY(result.value);
3567
3600
  return result;
3568
- }));
3601
+ });
3569
3602
  } else {
3570
3603
  if (status.value === "aborted")
3571
3604
  return INVALID;
@@ -3647,18 +3680,20 @@ var ZodEffects = class extends ZodType {
3647
3680
  }
3648
3681
  };
3649
3682
  ZodEffects.create = (schema, effect, params) => {
3650
- return new ZodEffects(__spreadValues({
3683
+ return new ZodEffects({
3651
3684
  schema,
3652
3685
  typeName: ZodFirstPartyTypeKind.ZodEffects,
3653
- effect
3654
- }, processCreateParams(params)));
3686
+ effect,
3687
+ ...processCreateParams(params)
3688
+ });
3655
3689
  };
3656
3690
  ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3657
- return new ZodEffects(__spreadValues({
3691
+ return new ZodEffects({
3658
3692
  schema,
3659
3693
  effect: { type: "preprocess", transform: preprocess },
3660
- typeName: ZodFirstPartyTypeKind.ZodEffects
3661
- }, processCreateParams(params)));
3694
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3695
+ ...processCreateParams(params)
3696
+ });
3662
3697
  };
3663
3698
  var ZodOptional = class extends ZodType {
3664
3699
  _parse(input) {
@@ -3673,10 +3708,11 @@ var ZodOptional = class extends ZodType {
3673
3708
  }
3674
3709
  };
3675
3710
  ZodOptional.create = (type, params) => {
3676
- return new ZodOptional(__spreadValues({
3711
+ return new ZodOptional({
3677
3712
  innerType: type,
3678
- typeName: ZodFirstPartyTypeKind.ZodOptional
3679
- }, processCreateParams(params)));
3713
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3714
+ ...processCreateParams(params)
3715
+ });
3680
3716
  };
3681
3717
  var ZodNullable = class extends ZodType {
3682
3718
  _parse(input) {
@@ -3691,10 +3727,11 @@ var ZodNullable = class extends ZodType {
3691
3727
  }
3692
3728
  };
3693
3729
  ZodNullable.create = (type, params) => {
3694
- return new ZodNullable(__spreadValues({
3730
+ return new ZodNullable({
3695
3731
  innerType: type,
3696
- typeName: ZodFirstPartyTypeKind.ZodNullable
3697
- }, processCreateParams(params)));
3732
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3733
+ ...processCreateParams(params)
3734
+ });
3698
3735
  };
3699
3736
  var ZodDefault = class extends ZodType {
3700
3737
  _parse(input) {
@@ -3714,24 +3751,29 @@ var ZodDefault = class extends ZodType {
3714
3751
  }
3715
3752
  };
3716
3753
  ZodDefault.create = (type, params) => {
3717
- return new ZodDefault(__spreadValues({
3754
+ return new ZodDefault({
3718
3755
  innerType: type,
3719
3756
  typeName: ZodFirstPartyTypeKind.ZodDefault,
3720
- defaultValue: typeof params.default === "function" ? params.default : () => params.default
3721
- }, processCreateParams(params)));
3757
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3758
+ ...processCreateParams(params)
3759
+ });
3722
3760
  };
3723
3761
  var ZodCatch = class extends ZodType {
3724
3762
  _parse(input) {
3725
3763
  const { ctx } = this._processInputParams(input);
3726
- const newCtx = __spreadProps(__spreadValues({}, ctx), {
3727
- common: __spreadProps(__spreadValues({}, ctx.common), {
3764
+ const newCtx = {
3765
+ ...ctx,
3766
+ common: {
3767
+ ...ctx.common,
3728
3768
  issues: []
3729
- })
3730
- });
3769
+ }
3770
+ };
3731
3771
  const result = this._def.innerType._parse({
3732
3772
  data: newCtx.data,
3733
3773
  path: newCtx.path,
3734
- parent: __spreadValues({}, newCtx)
3774
+ parent: {
3775
+ ...newCtx
3776
+ }
3735
3777
  });
3736
3778
  if (isAsync(result)) {
3737
3779
  return result.then((result2) => {
@@ -3762,11 +3804,12 @@ var ZodCatch = class extends ZodType {
3762
3804
  }
3763
3805
  };
3764
3806
  ZodCatch.create = (type, params) => {
3765
- return new ZodCatch(__spreadValues({
3807
+ return new ZodCatch({
3766
3808
  innerType: type,
3767
3809
  typeName: ZodFirstPartyTypeKind.ZodCatch,
3768
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch
3769
- }, processCreateParams(params)));
3810
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3811
+ ...processCreateParams(params)
3812
+ });
3770
3813
  };
3771
3814
  var ZodNaN = class extends ZodType {
3772
3815
  _parse(input) {
@@ -3784,9 +3827,10 @@ var ZodNaN = class extends ZodType {
3784
3827
  }
3785
3828
  };
3786
3829
  ZodNaN.create = (params) => {
3787
- return new ZodNaN(__spreadValues({
3788
- typeName: ZodFirstPartyTypeKind.ZodNaN
3789
- }, processCreateParams(params)));
3830
+ return new ZodNaN({
3831
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3832
+ ...processCreateParams(params)
3833
+ });
3790
3834
  };
3791
3835
  var BRAND = Symbol("zod_brand");
3792
3836
  var ZodBranded = class extends ZodType {
@@ -3807,8 +3851,8 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
3807
3851
  _parse(input) {
3808
3852
  const { status, ctx } = this._processInputParams(input);
3809
3853
  if (ctx.common.async) {
3810
- const handleAsync = () => __async(this, null, function* () {
3811
- const inResult = yield this._def.in._parseAsync({
3854
+ const handleAsync = async () => {
3855
+ const inResult = await this._def.in._parseAsync({
3812
3856
  data: ctx.data,
3813
3857
  path: ctx.path,
3814
3858
  parent: ctx
@@ -3825,7 +3869,7 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
3825
3869
  parent: ctx
3826
3870
  });
3827
3871
  }
3828
- });
3872
+ };
3829
3873
  return handleAsync();
3830
3874
  } else {
3831
3875
  const inResult = this._def.in._parseSync({
@@ -3874,10 +3918,11 @@ var ZodReadonly = class extends ZodType {
3874
3918
  }
3875
3919
  };
3876
3920
  ZodReadonly.create = (type, params) => {
3877
- return new ZodReadonly(__spreadValues({
3921
+ return new ZodReadonly({
3878
3922
  innerType: type,
3879
- typeName: ZodFirstPartyTypeKind.ZodReadonly
3880
- }, processCreateParams(params)));
3923
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3924
+ ...processCreateParams(params)
3925
+ });
3881
3926
  };
3882
3927
  function cleanParams(params, data) {
3883
3928
  const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
@@ -3887,22 +3932,20 @@ function cleanParams(params, data) {
3887
3932
  function custom(check, _params = {}, fatal) {
3888
3933
  if (check)
3889
3934
  return ZodAny.create().superRefine((data, ctx) => {
3890
- var _a, _b;
3891
3935
  const r = check(data);
3892
3936
  if (r instanceof Promise) {
3893
3937
  return r.then((r2) => {
3894
- var _a2, _b2;
3895
3938
  if (!r2) {
3896
3939
  const params = cleanParams(_params, data);
3897
- const _fatal = (_b2 = (_a2 = params.fatal) != null ? _a2 : fatal) != null ? _b2 : true;
3898
- ctx.addIssue(__spreadProps(__spreadValues({ code: "custom" }, params), { fatal: _fatal }));
3940
+ const _fatal = params.fatal ?? fatal ?? true;
3941
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3899
3942
  }
3900
3943
  });
3901
3944
  }
3902
3945
  if (!r) {
3903
3946
  const params = cleanParams(_params, data);
3904
- const _fatal = (_b = (_a = params.fatal) != null ? _a : fatal) != null ? _b : true;
3905
- ctx.addIssue(__spreadProps(__spreadValues({ code: "custom" }, params), { fatal: _fatal }));
3947
+ const _fatal = params.fatal ?? fatal ?? true;
3948
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3906
3949
  }
3907
3950
  return;
3908
3951
  });
@@ -3991,18 +4034,29 @@ var ostring = () => stringType().optional();
3991
4034
  var onumber = () => numberType().optional();
3992
4035
  var oboolean = () => booleanType().optional();
3993
4036
  var coerce = {
3994
- string: ((arg) => ZodString.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
3995
- number: ((arg) => ZodNumber.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
3996
- boolean: ((arg) => ZodBoolean.create(__spreadProps(__spreadValues({}, arg), {
4037
+ string: ((arg) => ZodString.create({ ...arg, coerce: true })),
4038
+ number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
4039
+ boolean: ((arg) => ZodBoolean.create({
4040
+ ...arg,
3997
4041
  coerce: true
3998
- }))),
3999
- bigint: ((arg) => ZodBigInt.create(__spreadProps(__spreadValues({}, arg), { coerce: true }))),
4000
- date: ((arg) => ZodDate.create(__spreadProps(__spreadValues({}, arg), { coerce: true })))
4042
+ })),
4043
+ bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
4044
+ date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
4001
4045
  };
4002
4046
  var NEVER = INVALID;
4003
4047
 
4004
4048
  // src/client.ts
4005
4049
  var RichError = class extends Error {
4050
+ status;
4051
+ // HTTP status code (e.g. 404, 500)
4052
+ code;
4053
+ // Application-level error code (e.g. "USER_NOT_FOUND")
4054
+ title;
4055
+ // Optional title or short summary
4056
+ detail;
4057
+ // Additional human-readable explanation
4058
+ errors;
4059
+ // Field-specific validation errors
4006
4060
  constructor(error) {
4007
4061
  super(error.message);
4008
4062
  Object.assign(this, error);
@@ -4012,17 +4066,31 @@ var ApiClient = class {
4012
4066
  constructor(config, contracts) {
4013
4067
  this.config = config;
4014
4068
  this.contracts = contracts;
4015
- this.middlewares = [];
4016
- this.responseTransform = (d) => d;
4017
- this.useMockData = false;
4018
- this.mockDelay = { min: 100, max: 1e3 };
4019
4069
  this.useMockData = config.useMockData || false;
4020
4070
  this.mockDelay = config.mockDelay || { min: 100, max: 1e3 };
4021
4071
  this.tokenProvider = config.tokenProvider;
4022
4072
  }
4073
+ middlewares = [];
4074
+ // Registered middlewares
4075
+ errorHandler;
4076
+ // Global error handler
4077
+ responseTransform = (d) => d;
4078
+ // Post-parse data transformer
4079
+ useMockData = false;
4080
+ // Whether mock responses are enabled
4081
+ mockDelay = { min: 100, max: 1e3 };
4082
+ // Mock latency range (ms)
4083
+ responseWrapper;
4084
+ // Wrapper for APIs with envelope structures
4085
+ tokenProvider;
4086
+ // Optional async token supplier
4087
+ // Configuration for retry behavior
4088
+ retryConfig;
4089
+ // Holds generated API endpoint methods
4090
+ _modules;
4023
4091
  /**
4024
- * Builds the strongly-typed `modules` API from the provided contracts.
4025
- * Must be called once after constructing the client.
4092
+ * Builds all API methods (`modules`) dynamically from the Zod contract definition.
4093
+ * After `init()` is called, each endpoint can be invoked through `client.modules.moduleName.endpointName()`.
4026
4094
  */
4027
4095
  init() {
4028
4096
  const modules = {};
@@ -4031,333 +4099,215 @@ var ApiClient = class {
4031
4099
  modules[moduleName] = {};
4032
4100
  for (const endpointName in module) {
4033
4101
  const endpoint = module[endpointName];
4034
- modules[moduleName][endpointName] = (input) => this.request(endpoint, input);
4102
+ modules[moduleName][endpointName] = (input, options) => this.request(endpoint, input, options);
4035
4103
  }
4036
4104
  }
4037
4105
  this._modules = modules;
4038
4106
  }
4039
- /**
4040
- * Type-safe entrypoint for calling API endpoints.
4041
- * Populated by `init()` based on the `contracts` passed to the constructor.
4042
- */
4107
+ /** Provides access to initialized modules after calling `init()`. */
4043
4108
  get modules() {
4044
4109
  return this._modules;
4045
4110
  }
4046
- /**
4047
- * Registers a middleware in the pipeline.
4048
- * Middlewares are executed in reverse order of registration.
4049
- */
4111
+ /** Registers a new middleware in the client’s pipeline. */
4050
4112
  use(middleware, options) {
4051
4113
  this.middlewares.push({ fn: middleware, options });
4052
4114
  }
4053
- /**
4054
- * Registers a global error handler.
4055
- * The handler is invoked for normalized errors before they are re-thrown.
4056
- */
4115
+ /** Sets a global error handler function to unify error behavior. */
4057
4116
  onError(handler) {
4058
4117
  this.errorHandler = handler;
4059
4118
  }
4060
- /**
4061
- * Registers a transformation function applied to all successful responses
4062
- * after Zod parsing.
4063
- */
4119
+ /** Defines a global transform function applied to all validated responses. */
4064
4120
  useResponseTransform(fn) {
4065
4121
  this.responseTransform = fn;
4066
4122
  }
4067
- /**
4068
- * Enables or disables mock mode. When enabled, endpoints with `mockData`
4069
- * return mocked responses instead of performing network requests.
4070
- */
4123
+ /** Configures the retry logic (max attempts, backoff mode, etc.). */
4124
+ setRetryConfig(config) {
4125
+ this.retryConfig = config;
4126
+ }
4127
+ /** Provides a custom token provider that returns tokens dynamically. */
4128
+ setTokenProvider(provider) {
4129
+ this.tokenProvider = provider;
4130
+ }
4131
+ /** Enables mock responses instead of network requests. */
4071
4132
  setMockMode(enabled, delay) {
4072
4133
  this.useMockData = enabled;
4073
- if (delay) {
4074
- this.mockDelay = delay;
4075
- }
4134
+ if (delay) this.mockDelay = delay;
4076
4135
  }
4077
- /**
4078
- * Registers a schema wrapper for APIs that wrap data in an envelope.
4079
- * Example: { success, data, message, code, ... }.
4080
- */
4136
+ /** Registers a wrapper schema for APIs that nest response data (e.g. `{ data, success, message }`). */
4081
4137
  setResponseWrapper(wrapper) {
4082
4138
  this.responseWrapper = wrapper;
4083
4139
  }
4084
- /**
4085
- * Sets or updates the token provider used for authenticated endpoints.
4086
- * Overrides any static token provided in the constructor.
4087
- */
4088
- setTokenProvider(provider) {
4089
- this.tokenProvider = provider;
4140
+ /** Retrieves the current auth token, using a provider if available. */
4141
+ async getCurrentToken() {
4142
+ if (this.tokenProvider) return await this.tokenProvider();
4143
+ return this.config.token;
4090
4144
  }
4091
4145
  /**
4092
- * Returns the current token, preferring the tokenProvider if present,
4093
- * otherwise falling back to the static token from the constructor.
4146
+ * Core request entry point used by auto-generated endpoint methods.
4147
+ * Handles caching, deduplication, and mock mode routing.
4094
4148
  */
4095
- getCurrentToken() {
4096
- return __async(this, null, function* () {
4097
- if (this.tokenProvider) {
4098
- return yield this.tokenProvider();
4099
- }
4100
- return this.config.token;
4101
- });
4149
+ async request(endpoint, input, options) {
4150
+ const parsedInput = endpoint.request.parse(input);
4151
+ if (this.useMockData && endpoint.mockData) {
4152
+ return this.handleMockRequest(endpoint);
4153
+ }
4154
+ const { url, body } = this.buildUrlAndBody(endpoint, parsedInput);
4155
+ const requestKey = JSON.stringify({ method: endpoint.method, url, body });
4156
+ const promise = this.performRequestLogic(
4157
+ endpoint,
4158
+ parsedInput,
4159
+ url,
4160
+ body,
4161
+ requestKey,
4162
+ options
4163
+ );
4164
+ return promise;
4102
4165
  }
4103
4166
  /**
4104
- * Executes a single endpoint request.
4105
- *
4106
- * Expected request shape (new style):
4107
- * z.object({
4108
- * path: z.object({...}).optional(),
4109
- * query: z.object({...}).optional(),
4110
- * body: z.any().optional(),
4111
- * header: z.object({...}).optional(),
4112
- * })
4113
- *
4114
- * If the parsed request does not contain `path`, `header`,`query` or `body`,
4115
- * the entire input is treated as the legacy flat request body.
4167
+ * Full HTTP request workflow:
4168
+ * - Token injection
4169
+ * - Timeout support
4170
+ * - Middleware pipeline
4171
+ * - Fetch + response handling
4172
+ * - Zod parsing + transformation
4173
+ * - Caching
4116
4174
  */
4117
- request(endpoint, input) {
4118
- return __async(this, null, function* () {
4119
- var _b, _c, _d, _e;
4120
- const parsedInput = endpoint.request.parse(input);
4121
- const isObject = typeof parsedInput === "object" && parsedInput !== null;
4122
- const looksStructured = isObject && ("path" in parsedInput || "query" in parsedInput || "body" in parsedInput || "headers" in parsedInput);
4123
- const _a = parsedInput, { headers: extraHeaders } = _a, restInput = __objRest(_a, ["headers"]);
4124
- if (this.useMockData && endpoint.mockData) {
4125
- return this.handleMockRequest(endpoint);
4126
- }
4127
- let token = this.config.token;
4128
- if (this.tokenProvider) {
4129
- token = yield this.tokenProvider();
4175
+ async performRequestLogic(endpoint, parsedInput, url, body, key, options) {
4176
+ const headers = {};
4177
+ const token = await this.getCurrentToken();
4178
+ if (endpoint.auth && !token) {
4179
+ const error = this.createError({
4180
+ message: `Missing token for ${endpoint.path}`,
4181
+ status: 401,
4182
+ code: "NO_TOKEN"
4183
+ });
4184
+ this.errorHandler?.(error);
4185
+ throw error;
4186
+ }
4187
+ if (endpoint.auth && token) headers["Authorization"] = `Bearer ${token}`;
4188
+ if (endpoint.bodyType !== "form-data")
4189
+ headers["Content-Type"] = "application/json";
4190
+ const ctx = {
4191
+ url,
4192
+ init: { method: endpoint.method, headers, body }
4193
+ };
4194
+ let controller;
4195
+ let timeoutId;
4196
+ if (options?.timeout) {
4197
+ controller = new AbortController();
4198
+ timeoutId = setTimeout(() => controller.abort(), options.timeout);
4199
+ }
4200
+ if (options?.signal || controller)
4201
+ ctx.init.signal = options?.signal || controller?.signal;
4202
+ const runner = this.middlewares.reduceRight(
4203
+ (next, mw) => () => mw.fn(ctx, next, mw.options),
4204
+ () => fetch(ctx.url, ctx.init)
4205
+ );
4206
+ const execute = async () => {
4207
+ const res = await runner();
4208
+ const json = await res.json();
4209
+ let responseData = json;
4210
+ if (this.responseWrapper) {
4211
+ const wrappedSchema = this.responseWrapper(endpoint.response);
4212
+ const parsedWrapped = wrappedSchema.parse(json);
4213
+ if (parsedWrapped.success === false) {
4214
+ const error = this.createError({
4215
+ message: parsedWrapped.message || "Request failed",
4216
+ status: parsedWrapped.code || res.status,
4217
+ code: `API_ERROR_${parsedWrapped.code}`
4218
+ });
4219
+ this.errorHandler?.(error);
4220
+ throw error;
4221
+ }
4222
+ responseData = parsedWrapped.data;
4130
4223
  }
4131
- if (endpoint.auth && !token) {
4224
+ if (!res.ok) {
4132
4225
  const error = this.createError({
4133
- message: `Missing token for ${endpoint.path}`,
4134
- status: 401,
4135
- code: "NO_TOKEN"
4226
+ message: json.message || res.statusText,
4227
+ status: res.status,
4228
+ code: json.code,
4229
+ title: json.title,
4230
+ detail: json.detail,
4231
+ errors: json.errors
4136
4232
  });
4137
- (_b = this.errorHandler) == null ? void 0 : _b.call(this, error);
4233
+ this.errorHandler?.(error);
4138
4234
  throw error;
4139
4235
  }
4140
- const headers = {};
4141
- if (endpoint.auth && token) {
4142
- headers["Authorization"] = `Bearer ${token}`;
4143
- }
4144
- if (endpoint.bodyType !== "form-data") {
4145
- headers["Content-Type"] = "application/json";
4146
- }
4147
- if (endpoint.headers) {
4148
- const endpointHeaders = typeof endpoint.headers === "function" ? endpoint.headers(parsedInput) : endpoint.headers;
4149
- for (const [key, value] of Object.entries(endpointHeaders)) {
4150
- headers[key] = value;
4151
- }
4152
- }
4153
- if (extraHeaders) {
4154
- for (const [key, value] of Object.entries(extraHeaders)) {
4155
- headers[key] = value;
4156
- }
4157
- }
4158
- const { url, body } = this.buildUrlAndBody(
4159
- endpoint,
4160
- restInput,
4161
- looksStructured
4162
- );
4163
- const ctx = {
4164
- url,
4165
- init: {
4166
- method: endpoint.method,
4167
- headers,
4168
- body
4169
- }
4170
- };
4171
- const runner = this.middlewares.reduceRight(
4172
- (next, mw) => () => mw.fn(ctx, next, mw.options),
4173
- () => fetch(ctx.url, ctx.init)
4174
- );
4236
+ const parsed = endpoint.response.parse(responseData);
4237
+ const result = this.responseTransform(parsed);
4238
+ return result;
4239
+ };
4240
+ try {
4241
+ const result = await this.executeWithRetry(execute);
4242
+ if (timeoutId) clearTimeout(timeoutId);
4243
+ return result;
4244
+ } catch (err) {
4245
+ if (timeoutId) clearTimeout(timeoutId);
4246
+ const error = this.normalizeError(err);
4247
+ this.errorHandler?.(error);
4248
+ throw error;
4249
+ }
4250
+ }
4251
+ // =========================================================
4252
+ // 🔁 RETRY ENGINE
4253
+ // =========================================================
4254
+ /** Executes a function with retry logic and configurable backoff strategy. */
4255
+ async executeWithRetry(fn) {
4256
+ if (!this.retryConfig) return fn();
4257
+ const { maxRetries, backoff, retryCondition } = this.retryConfig;
4258
+ let attempt = 0;
4259
+ while (true) {
4175
4260
  try {
4176
- const res = yield runner();
4177
- const json = yield res.json();
4178
- let responseData = json;
4179
- if (this.responseWrapper) {
4180
- const wrappedSchema = this.responseWrapper(endpoint.response);
4181
- const parsedResponse = wrappedSchema.parse(json);
4182
- if (parsedResponse.success === false) {
4183
- const error = this.createError({
4184
- message: parsedResponse.message || "Request failed",
4185
- status: parsedResponse.code || res.status,
4186
- code: `API_ERROR_${parsedResponse.code}`
4187
- });
4188
- (_c = this.errorHandler) == null ? void 0 : _c.call(this, error);
4189
- throw error;
4190
- }
4191
- responseData = parsedResponse.data;
4192
- }
4193
- if (!res.ok) {
4194
- const error = this.createError({
4195
- message: json.message || res.statusText,
4196
- status: res.status,
4197
- code: json.code,
4198
- title: json.title,
4199
- detail: json.detail,
4200
- errors: json.errors
4201
- });
4202
- (_d = this.errorHandler) == null ? void 0 : _d.call(this, error);
4203
- throw error;
4204
- }
4205
- return this.responseTransform(endpoint.response.parse(responseData));
4261
+ return await fn();
4206
4262
  } catch (err) {
4263
+ attempt++;
4207
4264
  const error = this.normalizeError(err);
4208
- (_e = this.errorHandler) == null ? void 0 : _e.call(this, error);
4209
- throw error;
4265
+ const shouldRetry = attempt <= maxRetries && (retryCondition?.(error, attempt) ?? (error.status !== void 0 && error.status >= 500));
4266
+ if (!shouldRetry) throw error;
4267
+ const delay = this.getBackoffDelay(backoff, attempt);
4268
+ await new Promise((r) => setTimeout(r, delay));
4210
4269
  }
4211
- });
4270
+ }
4212
4271
  }
4213
- /**
4214
- * Builds final URL and body from endpoint + request input.
4215
- * Supports both structured `{ path, query, body, headers }` and legacy flat input.
4216
- */
4217
- buildUrlAndBody(endpoint, parsedInput, looksStructured) {
4218
- if (!looksStructured) {
4219
- const url2 = this.config.baseUrl + endpoint.path;
4220
- let requestBody2 = void 0;
4221
- if (endpoint.method !== "GET") {
4222
- if (endpoint.bodyType === "form-data") {
4223
- const form = new FormData();
4224
- const flat = parsedInput || {};
4225
- for (const [key, value] of Object.entries(flat)) {
4226
- if (value === void 0 || value === null) continue;
4227
- if (Array.isArray(value)) {
4228
- for (const v of value) {
4229
- if (v === void 0 || v === null) continue;
4230
- form.append(key, v);
4231
- }
4232
- } else {
4233
- form.append(key, value);
4234
- }
4235
- }
4236
- requestBody2 = form;
4237
- } else {
4238
- requestBody2 = JSON.stringify(parsedInput);
4239
- }
4240
- }
4241
- return { url: url2, body: requestBody2 };
4272
+ /** Calculates retry delay intervals for various backoff strategies. */
4273
+ getBackoffDelay(type, attempt) {
4274
+ const base = 300;
4275
+ switch (type) {
4276
+ case "fixed":
4277
+ return base;
4278
+ case "linear":
4279
+ return base * attempt;
4280
+ case "exponential":
4281
+ return base * Math.pow(2, attempt - 1);
4242
4282
  }
4243
- const { path, query, body } = parsedInput;
4283
+ }
4284
+ // =========================================================
4285
+ // 🔧 UTILITIES
4286
+ // =========================================================
4287
+ /** Builds the final URL and request body from the endpoint definition and input payload. */
4288
+ buildUrlAndBody(endpoint, input) {
4244
4289
  let url = this.config.baseUrl + endpoint.path;
4245
- if (path) {
4246
- for (const [key, value] of Object.entries(path)) {
4247
- if (value === void 0 || value === null) continue;
4248
- const token = `:${key}`;
4249
- if (!url.includes(token)) {
4250
- continue;
4251
- }
4252
- url = url.replace(token, encodeURIComponent(String(value)));
4253
- }
4254
- }
4255
- const templatePlaceholders = Array.from(
4256
- endpoint.path.matchAll(/:([A-Za-z0-9_]+)/g)
4257
- ).map((m) => m[1]);
4258
- const missingTokens = templatePlaceholders.filter((name) => {
4259
- const v = path ? path[name] : void 0;
4260
- return v === void 0 || v === null;
4261
- });
4262
- if (missingTokens.length > 0) {
4263
- throw this.createError({
4264
- message: `Missing path params for placeholders: ${missingTokens.join(
4265
- ", "
4266
- )} in "${endpoint.path}"`,
4267
- code: "MISSING_PATH_PARAMS"
4268
- });
4269
- }
4270
- if (query) {
4271
- const searchParams = new URLSearchParams();
4272
- for (const [key, value] of Object.entries(query)) {
4273
- if (value === void 0 || value === null) continue;
4274
- if (Array.isArray(value)) {
4275
- for (const v of value) {
4276
- if (v === void 0 || v === null) continue;
4277
- searchParams.append(key, String(v));
4278
- }
4279
- } else if (typeof value === "object") {
4280
- searchParams.append(key, JSON.stringify(value));
4281
- } else {
4282
- searchParams.append(key, String(value));
4283
- }
4284
- }
4285
- const qs = searchParams.toString();
4286
- if (qs) {
4287
- url += (url.includes("?") ? "&" : "?") + qs;
4288
- }
4289
- }
4290
- let requestBody = void 0;
4290
+ let body;
4291
4291
  if (endpoint.method !== "GET") {
4292
- if (body !== void 0 && body !== null) {
4293
- if (endpoint.bodyType === "form-data") {
4294
- const form = new FormData();
4295
- for (const [key, value] of Object.entries(body)) {
4296
- if (value === void 0 || value === null) continue;
4297
- if (Array.isArray(value)) {
4298
- for (const v of value) {
4299
- if (v === void 0 || v === null) continue;
4300
- form.append(key, v);
4301
- }
4302
- } else {
4303
- form.append(key, value);
4304
- }
4305
- }
4306
- requestBody = form;
4307
- } else {
4308
- requestBody = JSON.stringify(body);
4292
+ if (endpoint.bodyType === "form-data") {
4293
+ const form = new FormData();
4294
+ for (const [k, v] of Object.entries(input.body || {})) {
4295
+ if (v != null) form.append(k, v);
4309
4296
  }
4310
- }
4311
- }
4312
- return { url, body: requestBody };
4313
- }
4314
- /**
4315
- * Returns a mocked response based on `endpoint.mockData`,
4316
- * respecting the configured mock delay and response wrapper.
4317
- */
4318
- handleMockRequest(endpoint) {
4319
- return __async(this, null, function* () {
4320
- const delay = this.getRandomDelay();
4321
- yield new Promise((resolve) => setTimeout(resolve, delay));
4322
- let mockData;
4323
- if (typeof endpoint.mockData === "function") {
4324
- mockData = endpoint.mockData();
4297
+ body = form;
4325
4298
  } else {
4326
- mockData = endpoint.mockData;
4299
+ body = JSON.stringify(input.body ?? input);
4327
4300
  }
4328
- if (this.responseWrapper) {
4329
- const wrappedSchema = this.responseWrapper(endpoint.response);
4330
- const mockWrappedResponse = {
4331
- success: true,
4332
- data: mockData,
4333
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
4334
- requestId: `mock-${Math.random().toString(36).substr(2, 9)}`
4335
- };
4336
- const parsedWrappedResponse = wrappedSchema.parse(mockWrappedResponse);
4337
- return this.responseTransform(
4338
- endpoint.response.parse(parsedWrappedResponse.data)
4339
- );
4340
- }
4341
- return this.responseTransform(endpoint.response.parse(mockData));
4342
- });
4343
- }
4344
- /**
4345
- * Returns a random delay in milliseconds within the current mock delay range.
4346
- */
4347
- getRandomDelay() {
4348
- return Math.floor(
4349
- Math.random() * (this.mockDelay.max - this.mockDelay.min + 1)
4350
- ) + this.mockDelay.min;
4301
+ }
4302
+ return { url, body };
4351
4303
  }
4352
- /**
4353
- * Creates a RichError instance from a partial error description.
4354
- */
4304
+ /** Creates and returns a RichError from details. */
4355
4305
  createError(error) {
4356
4306
  return new RichError(error);
4357
4307
  }
4358
4308
  /**
4359
- * Normalizes unknown errors into a RichError instance.
4360
- * Zod validation errors are converted into a standardized validation error.
4309
+ * Converts any thrown error to a standardized RichError instance.
4310
+ * Also flattens Zod validation errors into readable messages.
4361
4311
  */
4362
4312
  normalizeError(err) {
4363
4313
  if (err instanceof RichError) return err;
@@ -4369,78 +4319,99 @@ var ApiClient = class {
4369
4319
  }
4370
4320
  return this.createError({ message: err.message || "Unknown error" });
4371
4321
  }
4322
+ /**
4323
+ * Handles mock-mode requests by simulating a delayed network call
4324
+ * and returning validated mock data.
4325
+ */
4326
+ async handleMockRequest(endpoint) {
4327
+ const delay = Math.floor(
4328
+ Math.random() * (this.mockDelay.max - this.mockDelay.min + 1)
4329
+ ) + this.mockDelay.min;
4330
+ await new Promise((r) => setTimeout(r, delay));
4331
+ const data = typeof endpoint.mockData === "function" ? endpoint.mockData() : endpoint.mockData;
4332
+ return this.responseTransform(endpoint.response.parse(data));
4333
+ }
4372
4334
  };
4373
4335
 
4374
4336
  // src/middlewares/logging.ts
4375
- var loggingMiddleware = (ctx, next, options) => __async(null, null, function* () {
4337
+ var loggingMiddleware = async (ctx, next, options) => {
4376
4338
  const { logRequest = true, logResponse = true, debug = true } = options || {};
4377
4339
  if (debug && logRequest) console.log("\u27A1\uFE0F Request:", ctx.url, ctx.init);
4378
- const res = yield next();
4340
+ const res = await next();
4379
4341
  if (debug && logResponse) console.log("\u2B05\uFE0F Response:", res.status);
4380
4342
  return res;
4381
- });
4343
+ };
4382
4344
 
4383
4345
  // src/middlewares/retry.ts
4384
4346
  var retryMiddleware = (options) => {
4385
4347
  const { maxRetries = 3, delay = 500 } = options || {};
4386
- const middleware = (ctx, next) => __async(null, null, function* () {
4348
+ const middleware = async (ctx, next) => {
4387
4349
  let attempt = 0;
4388
4350
  while (true) {
4389
4351
  try {
4390
- return yield next();
4352
+ return await next();
4391
4353
  } catch (err) {
4392
4354
  if (attempt >= maxRetries) throw err;
4393
4355
  attempt++;
4394
- yield new Promise((r) => setTimeout(r, delay * __pow(2, attempt)));
4356
+ await new Promise((r) => setTimeout(r, delay * 2 ** attempt));
4395
4357
  }
4396
4358
  }
4397
- });
4359
+ };
4398
4360
  return middleware;
4399
4361
  };
4400
4362
 
4401
4363
  // src/middlewares/auth.ts
4402
- var authMiddleware = (ctx, next, options) => __async(null, null, function* () {
4403
- if (options == null ? void 0 : options.refreshToken) {
4364
+ var authMiddleware = async (ctx, next, options) => {
4365
+ if (options?.refreshToken) {
4404
4366
  try {
4405
- const newToken = yield options.refreshToken();
4406
- ctx.init.headers = __spreadProps(__spreadValues({}, ctx.init.headers), {
4367
+ const newToken = await options.refreshToken();
4368
+ ctx.init.headers = {
4369
+ ...ctx.init.headers,
4370
+ // Preserve any headers set by prior middleware
4407
4371
  Authorization: `Bearer ${newToken}`
4408
- });
4409
- } catch (e) {
4372
+ };
4373
+ } catch (error) {
4374
+ console.warn(
4375
+ "Authentication token refresh failed, proceeding without authorization header.",
4376
+ error
4377
+ );
4410
4378
  }
4411
4379
  }
4412
4380
  return next();
4413
- });
4381
+ };
4414
4382
 
4415
4383
  // src/middlewares/cache.ts
4416
4384
  var cacheMiddleware = (options = {}) => {
4417
4385
  const { ttl = 6e4 } = options;
4418
4386
  const cache = /* @__PURE__ */ new Map();
4419
- return (ctx, next) => __async(null, null, function* () {
4387
+ return async (ctx, next) => {
4420
4388
  if (ctx.init.method === "GET") {
4421
- const cached = cache.get(ctx.url);
4389
+ const key = `${ctx.init.method}:${ctx.url}`;
4390
+ const cached = cache.get(key);
4422
4391
  const now = Date.now();
4423
- if (cached && cached.expires > now)
4424
- return new Response(JSON.stringify(cached.data));
4425
- const res = yield next();
4426
- const data = yield res.clone().json().catch(() => null);
4427
- if (data) cache.set(ctx.url, { data, expires: now + ttl });
4392
+ if (cached && cached.expires > now) {
4393
+ return new Response(JSON.stringify(cached.data), {
4394
+ headers: { "Content-Type": "application/json" }
4395
+ });
4396
+ }
4397
+ const res = await next();
4398
+ const data = await res.clone().json().catch(() => null);
4399
+ if (data) {
4400
+ cache.set(key, { data, expires: now + ttl });
4401
+ }
4428
4402
  return res;
4429
4403
  }
4430
4404
  return next();
4431
- });
4405
+ };
4432
4406
  };
4433
4407
 
4434
4408
  // src/utils/make-request-schema.ts
4435
- var makeRequestSchema = () => (defs) => {
4436
- var _a, _b, _c, _d, _e, _f;
4437
- return external_exports.object({
4438
- path: (_b = (_a = defs.path) != null ? _a : external_exports.object({})) == null ? void 0 : _b.optional(),
4439
- query: (_d = (_c = defs.query) != null ? _c : external_exports.object({})) == null ? void 0 : _d.optional(),
4440
- body: (_e = defs.body) != null ? _e : external_exports.undefined(),
4441
- headers: (_f = defs.headers) != null ? _f : external_exports.record(external_exports.string()).optional()
4442
- });
4443
- };
4409
+ var makeRequestSchema = () => (defs) => external_exports.object({
4410
+ path: (defs.path ?? external_exports.object({}))?.optional(),
4411
+ query: (defs.query ?? external_exports.object({}))?.optional(),
4412
+ body: defs.body ?? external_exports.undefined(),
4413
+ headers: defs.headers ?? external_exports.record(external_exports.string()).optional()
4414
+ });
4444
4415
  export {
4445
4416
  ApiClient,
4446
4417
  RichError,