better-call 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,8 +1,7 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
1
+ const require_node = require('./node.cjs');
2
2
  let __better_auth_utils = require("@better-auth/utils");
3
- __better_auth_utils = require_chunk.__toESM(__better_auth_utils);
4
3
  let rou3 = require("rou3");
5
- rou3 = require_chunk.__toESM(rou3);
4
+ let zod = require("zod");
6
5
 
7
6
  //#region src/error.ts
8
7
  function isErrorStackTraceLimitWritable() {
@@ -314,8 +313,8 @@ async function runValidation(options, context = {}) {
314
313
  }
315
314
  function fromError(error, validating) {
316
315
  const errorMessages = [];
317
- for (const issue$1 of error) {
318
- const message = issue$1.message;
316
+ for (const issue of error) {
317
+ const message = issue.message;
319
318
  errorMessages.push(message);
320
319
  }
321
320
  return { message: `Invalid ${validating} parameters` };
@@ -615,1674 +614,6 @@ createMiddleware.create = (opts) => {
615
614
  return fn;
616
615
  };
617
616
 
618
- //#endregion
619
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/core.js
620
- /** A special constant with type `never` */
621
- const NEVER = Object.freeze({ status: "aborted" });
622
- function $constructor(name, initializer$2, params) {
623
- function init(inst, def) {
624
- var _a;
625
- Object.defineProperty(inst, "_zod", {
626
- value: inst._zod ?? {},
627
- enumerable: false
628
- });
629
- (_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
630
- inst._zod.traits.add(name);
631
- initializer$2(inst, def);
632
- for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
633
- inst._zod.constr = _;
634
- inst._zod.def = def;
635
- }
636
- const Parent = params?.Parent ?? Object;
637
- class Definition extends Parent {}
638
- Object.defineProperty(Definition, "name", { value: name });
639
- function _(def) {
640
- var _a;
641
- const inst = params?.Parent ? new Definition() : this;
642
- init(inst, def);
643
- (_a = inst._zod).deferred ?? (_a.deferred = []);
644
- for (const fn of inst._zod.deferred) fn();
645
- return inst;
646
- }
647
- Object.defineProperty(_, "init", { value: init });
648
- Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
649
- if (params?.Parent && inst instanceof params.Parent) return true;
650
- return inst?._zod?.traits?.has(name);
651
- } });
652
- Object.defineProperty(_, "name", { value: name });
653
- return _;
654
- }
655
- const $brand = Symbol("zod_brand");
656
- var $ZodAsyncError = class extends Error {
657
- constructor() {
658
- super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
659
- }
660
- };
661
- const globalConfig = {};
662
- function config(newConfig) {
663
- if (newConfig) Object.assign(globalConfig, newConfig);
664
- return globalConfig;
665
- }
666
-
667
- //#endregion
668
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/util.js
669
- function getEnumValues(entries) {
670
- const numericValues = Object.values(entries).filter((v) => typeof v === "number");
671
- return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
672
- }
673
- function jsonStringifyReplacer(_, value) {
674
- if (typeof value === "bigint") return value.toString();
675
- return value;
676
- }
677
- function cached(getter) {
678
- return { get value() {
679
- {
680
- const value = getter();
681
- Object.defineProperty(this, "value", { value });
682
- return value;
683
- }
684
- throw new Error("cached value already set");
685
- } };
686
- }
687
- function nullish(input) {
688
- return input === null || input === void 0;
689
- }
690
- function cleanRegex(source) {
691
- const start = source.startsWith("^") ? 1 : 0;
692
- const end = source.endsWith("$") ? source.length - 1 : source.length;
693
- return source.slice(start, end);
694
- }
695
- function defineLazy(object, key, getter) {
696
- Object.defineProperty(object, key, {
697
- get() {
698
- {
699
- const value = getter();
700
- object[key] = value;
701
- return value;
702
- }
703
- throw new Error("cached value already set");
704
- },
705
- set(v) {
706
- Object.defineProperty(object, key, { value: v });
707
- },
708
- configurable: true
709
- });
710
- }
711
- function assignProp(target, prop, value) {
712
- Object.defineProperty(target, prop, {
713
- value,
714
- writable: true,
715
- enumerable: true,
716
- configurable: true
717
- });
718
- }
719
- function esc(str) {
720
- return JSON.stringify(str);
721
- }
722
- const captureStackTrace = Error.captureStackTrace ? Error.captureStackTrace : (..._args) => {};
723
- function isObject(data) {
724
- return typeof data === "object" && data !== null && !Array.isArray(data);
725
- }
726
- const allowsEval = cached(() => {
727
- if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
728
- try {
729
- new Function("");
730
- return true;
731
- } catch (_) {
732
- return false;
733
- }
734
- });
735
- function isPlainObject(o) {
736
- if (isObject(o) === false) return false;
737
- const ctor = o.constructor;
738
- if (ctor === void 0) return true;
739
- const prot = ctor.prototype;
740
- if (isObject(prot) === false) return false;
741
- if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
742
- return true;
743
- }
744
- const propertyKeyTypes = new Set([
745
- "string",
746
- "number",
747
- "symbol"
748
- ]);
749
- function escapeRegex(str) {
750
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
751
- }
752
- function clone(inst, def, params) {
753
- const cl = new inst._zod.constr(def ?? inst._zod.def);
754
- if (!def || params?.parent) cl._zod.parent = inst;
755
- return cl;
756
- }
757
- function normalizeParams(_params) {
758
- const params = _params;
759
- if (!params) return {};
760
- if (typeof params === "string") return { error: () => params };
761
- if (params?.message !== void 0) {
762
- if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
763
- params.error = params.message;
764
- }
765
- delete params.message;
766
- if (typeof params.error === "string") return {
767
- ...params,
768
- error: () => params.error
769
- };
770
- return params;
771
- }
772
- function optionalKeys(shape) {
773
- return Object.keys(shape).filter((k) => {
774
- return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
775
- });
776
- }
777
- const NUMBER_FORMAT_RANGES = {
778
- safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
779
- int32: [-2147483648, 2147483647],
780
- uint32: [0, 4294967295],
781
- float32: [-34028234663852886e22, 34028234663852886e22],
782
- float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
783
- };
784
- function pick(schema, mask) {
785
- const newShape = {};
786
- const currDef = schema._zod.def;
787
- for (const key in mask) {
788
- if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
789
- if (!mask[key]) continue;
790
- newShape[key] = currDef.shape[key];
791
- }
792
- return clone(schema, {
793
- ...schema._zod.def,
794
- shape: newShape,
795
- checks: []
796
- });
797
- }
798
- function omit(schema, mask) {
799
- const newShape = { ...schema._zod.def.shape };
800
- const currDef = schema._zod.def;
801
- for (const key in mask) {
802
- if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
803
- if (!mask[key]) continue;
804
- delete newShape[key];
805
- }
806
- return clone(schema, {
807
- ...schema._zod.def,
808
- shape: newShape,
809
- checks: []
810
- });
811
- }
812
- function extend(schema, shape) {
813
- if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
814
- return clone(schema, {
815
- ...schema._zod.def,
816
- get shape() {
817
- const _shape = {
818
- ...schema._zod.def.shape,
819
- ...shape
820
- };
821
- assignProp(this, "shape", _shape);
822
- return _shape;
823
- },
824
- checks: []
825
- });
826
- }
827
- function merge(a, b) {
828
- return clone(a, {
829
- ...a._zod.def,
830
- get shape() {
831
- const _shape = {
832
- ...a._zod.def.shape,
833
- ...b._zod.def.shape
834
- };
835
- assignProp(this, "shape", _shape);
836
- return _shape;
837
- },
838
- catchall: b._zod.def.catchall,
839
- checks: []
840
- });
841
- }
842
- function partial(Class, schema, mask) {
843
- const oldShape = schema._zod.def.shape;
844
- const shape = { ...oldShape };
845
- if (mask) for (const key in mask) {
846
- if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
847
- if (!mask[key]) continue;
848
- shape[key] = Class ? new Class({
849
- type: "optional",
850
- innerType: oldShape[key]
851
- }) : oldShape[key];
852
- }
853
- else for (const key in oldShape) shape[key] = Class ? new Class({
854
- type: "optional",
855
- innerType: oldShape[key]
856
- }) : oldShape[key];
857
- return clone(schema, {
858
- ...schema._zod.def,
859
- shape,
860
- checks: []
861
- });
862
- }
863
- function required(Class, schema, mask) {
864
- const oldShape = schema._zod.def.shape;
865
- const shape = { ...oldShape };
866
- if (mask) for (const key in mask) {
867
- if (!(key in shape)) throw new Error(`Unrecognized key: "${key}"`);
868
- if (!mask[key]) continue;
869
- shape[key] = new Class({
870
- type: "nonoptional",
871
- innerType: oldShape[key]
872
- });
873
- }
874
- else for (const key in oldShape) shape[key] = new Class({
875
- type: "nonoptional",
876
- innerType: oldShape[key]
877
- });
878
- return clone(schema, {
879
- ...schema._zod.def,
880
- shape,
881
- checks: []
882
- });
883
- }
884
- function aborted(x, startIndex = 0) {
885
- for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
886
- return false;
887
- }
888
- function prefixIssues(path, issues) {
889
- return issues.map((iss) => {
890
- var _a;
891
- (_a = iss).path ?? (_a.path = []);
892
- iss.path.unshift(path);
893
- return iss;
894
- });
895
- }
896
- function unwrapMessage(message) {
897
- return typeof message === "string" ? message : message?.message;
898
- }
899
- function finalizeIssue(iss, ctx, config$1) {
900
- const full = {
901
- ...iss,
902
- path: iss.path ?? []
903
- };
904
- if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
905
- delete full.inst;
906
- delete full.continue;
907
- if (!ctx?.reportInput) delete full.input;
908
- return full;
909
- }
910
- function getLengthableOrigin(input) {
911
- if (Array.isArray(input)) return "array";
912
- if (typeof input === "string") return "string";
913
- return "unknown";
914
- }
915
- function issue(...args) {
916
- const [iss, input, inst] = args;
917
- if (typeof iss === "string") return {
918
- message: iss,
919
- code: "custom",
920
- input,
921
- inst
922
- };
923
- return { ...iss };
924
- }
925
-
926
- //#endregion
927
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/errors.js
928
- const initializer$1 = (inst, def) => {
929
- inst.name = "$ZodError";
930
- Object.defineProperty(inst, "_zod", {
931
- value: inst._zod,
932
- enumerable: false
933
- });
934
- Object.defineProperty(inst, "issues", {
935
- value: def,
936
- enumerable: false
937
- });
938
- Object.defineProperty(inst, "message", {
939
- get() {
940
- return JSON.stringify(def, jsonStringifyReplacer, 2);
941
- },
942
- enumerable: true
943
- });
944
- Object.defineProperty(inst, "toString", {
945
- value: () => inst.message,
946
- enumerable: false
947
- });
948
- };
949
- const $ZodError = $constructor("$ZodError", initializer$1);
950
- const $ZodRealError = $constructor("$ZodError", initializer$1, { Parent: Error });
951
- function flattenError(error, mapper = (issue$1) => issue$1.message) {
952
- const fieldErrors = {};
953
- const formErrors = [];
954
- for (const sub of error.issues) if (sub.path.length > 0) {
955
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
956
- fieldErrors[sub.path[0]].push(mapper(sub));
957
- } else formErrors.push(mapper(sub));
958
- return {
959
- formErrors,
960
- fieldErrors
961
- };
962
- }
963
- function formatError(error, _mapper) {
964
- const mapper = _mapper || function(issue$1) {
965
- return issue$1.message;
966
- };
967
- const fieldErrors = { _errors: [] };
968
- const processError = (error$1) => {
969
- for (const issue$1 of error$1.issues) if (issue$1.code === "invalid_union" && issue$1.errors.length) issue$1.errors.map((issues) => processError({ issues }));
970
- else if (issue$1.code === "invalid_key") processError({ issues: issue$1.issues });
971
- else if (issue$1.code === "invalid_element") processError({ issues: issue$1.issues });
972
- else if (issue$1.path.length === 0) fieldErrors._errors.push(mapper(issue$1));
973
- else {
974
- let curr = fieldErrors;
975
- let i = 0;
976
- while (i < issue$1.path.length) {
977
- const el = issue$1.path[i];
978
- if (!(i === issue$1.path.length - 1)) curr[el] = curr[el] || { _errors: [] };
979
- else {
980
- curr[el] = curr[el] || { _errors: [] };
981
- curr[el]._errors.push(mapper(issue$1));
982
- }
983
- curr = curr[el];
984
- i++;
985
- }
986
- }
987
- };
988
- processError(error);
989
- return fieldErrors;
990
- }
991
-
992
- //#endregion
993
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/parse.js
994
- const _parse = (_Err) => (schema, value, _ctx, _params) => {
995
- const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
996
- const result = schema._zod.run({
997
- value,
998
- issues: []
999
- }, ctx);
1000
- if (result instanceof Promise) throw new $ZodAsyncError();
1001
- if (result.issues.length) {
1002
- const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
1003
- captureStackTrace(e, _params?.callee);
1004
- throw e;
1005
- }
1006
- return result.value;
1007
- };
1008
- const parse$1 = /* @__PURE__ */ _parse($ZodRealError);
1009
- const _parseAsync = (_Err) => async (schema, value, _ctx, params) => {
1010
- const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
1011
- let result = schema._zod.run({
1012
- value,
1013
- issues: []
1014
- }, ctx);
1015
- if (result instanceof Promise) result = await result;
1016
- if (result.issues.length) {
1017
- const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
1018
- captureStackTrace(e, params?.callee);
1019
- throw e;
1020
- }
1021
- return result.value;
1022
- };
1023
- const parseAsync$1 = /* @__PURE__ */ _parseAsync($ZodRealError);
1024
- const _safeParse = (_Err) => (schema, value, _ctx) => {
1025
- const ctx = _ctx ? {
1026
- ..._ctx,
1027
- async: false
1028
- } : { async: false };
1029
- const result = schema._zod.run({
1030
- value,
1031
- issues: []
1032
- }, ctx);
1033
- if (result instanceof Promise) throw new $ZodAsyncError();
1034
- return result.issues.length ? {
1035
- success: false,
1036
- error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1037
- } : {
1038
- success: true,
1039
- data: result.value
1040
- };
1041
- };
1042
- const safeParse$1 = /* @__PURE__ */ _safeParse($ZodRealError);
1043
- const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
1044
- const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
1045
- let result = schema._zod.run({
1046
- value,
1047
- issues: []
1048
- }, ctx);
1049
- if (result instanceof Promise) result = await result;
1050
- return result.issues.length ? {
1051
- success: false,
1052
- error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1053
- } : {
1054
- success: true,
1055
- data: result.value
1056
- };
1057
- };
1058
- const safeParseAsync$1 = /* @__PURE__ */ _safeParseAsync($ZodRealError);
1059
-
1060
- //#endregion
1061
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/checks.js
1062
- const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
1063
- var _a;
1064
- inst._zod ?? (inst._zod = {});
1065
- inst._zod.def = def;
1066
- (_a = inst._zod).onattach ?? (_a.onattach = []);
1067
- });
1068
- const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
1069
- var _a;
1070
- $ZodCheck.init(inst, def);
1071
- (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1072
- const val = payload.value;
1073
- return !nullish(val) && val.length !== void 0;
1074
- });
1075
- inst._zod.onattach.push((inst$1) => {
1076
- const curr = inst$1._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
1077
- if (def.maximum < curr) inst$1._zod.bag.maximum = def.maximum;
1078
- });
1079
- inst._zod.check = (payload) => {
1080
- const input = payload.value;
1081
- if (input.length <= def.maximum) return;
1082
- const origin = getLengthableOrigin(input);
1083
- payload.issues.push({
1084
- origin,
1085
- code: "too_big",
1086
- maximum: def.maximum,
1087
- inclusive: true,
1088
- input,
1089
- inst,
1090
- continue: !def.abort
1091
- });
1092
- };
1093
- });
1094
- const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
1095
- var _a;
1096
- $ZodCheck.init(inst, def);
1097
- (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1098
- const val = payload.value;
1099
- return !nullish(val) && val.length !== void 0;
1100
- });
1101
- inst._zod.onattach.push((inst$1) => {
1102
- const curr = inst$1._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
1103
- if (def.minimum > curr) inst$1._zod.bag.minimum = def.minimum;
1104
- });
1105
- inst._zod.check = (payload) => {
1106
- const input = payload.value;
1107
- if (input.length >= def.minimum) return;
1108
- const origin = getLengthableOrigin(input);
1109
- payload.issues.push({
1110
- origin,
1111
- code: "too_small",
1112
- minimum: def.minimum,
1113
- inclusive: true,
1114
- input,
1115
- inst,
1116
- continue: !def.abort
1117
- });
1118
- };
1119
- });
1120
- const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
1121
- var _a;
1122
- $ZodCheck.init(inst, def);
1123
- (_a = inst._zod.def).when ?? (_a.when = (payload) => {
1124
- const val = payload.value;
1125
- return !nullish(val) && val.length !== void 0;
1126
- });
1127
- inst._zod.onattach.push((inst$1) => {
1128
- const bag = inst$1._zod.bag;
1129
- bag.minimum = def.length;
1130
- bag.maximum = def.length;
1131
- bag.length = def.length;
1132
- });
1133
- inst._zod.check = (payload) => {
1134
- const input = payload.value;
1135
- const length = input.length;
1136
- if (length === def.length) return;
1137
- const origin = getLengthableOrigin(input);
1138
- const tooBig = length > def.length;
1139
- payload.issues.push({
1140
- origin,
1141
- ...tooBig ? {
1142
- code: "too_big",
1143
- maximum: def.length
1144
- } : {
1145
- code: "too_small",
1146
- minimum: def.length
1147
- },
1148
- inclusive: true,
1149
- exact: true,
1150
- input: payload.value,
1151
- inst,
1152
- continue: !def.abort
1153
- });
1154
- };
1155
- });
1156
- const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (inst, def) => {
1157
- $ZodCheck.init(inst, def);
1158
- inst._zod.check = (payload) => {
1159
- payload.value = def.tx(payload.value);
1160
- };
1161
- });
1162
-
1163
- //#endregion
1164
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/doc.js
1165
- var Doc = class {
1166
- constructor(args = []) {
1167
- this.content = [];
1168
- this.indent = 0;
1169
- if (this) this.args = args;
1170
- }
1171
- indented(fn) {
1172
- this.indent += 1;
1173
- fn(this);
1174
- this.indent -= 1;
1175
- }
1176
- write(arg) {
1177
- if (typeof arg === "function") {
1178
- arg(this, { execution: "sync" });
1179
- arg(this, { execution: "async" });
1180
- return;
1181
- }
1182
- const lines = arg.split("\n").filter((x) => x);
1183
- const minIndent = Math.min(...lines.map((x) => x.length - x.trimStart().length));
1184
- const dedented = lines.map((x) => x.slice(minIndent)).map((x) => " ".repeat(this.indent * 2) + x);
1185
- for (const line of dedented) this.content.push(line);
1186
- }
1187
- compile() {
1188
- const F = Function;
1189
- const args = this?.args;
1190
- const lines = [...(this?.content ?? [``]).map((x) => ` ${x}`)];
1191
- return new F(...args, lines.join("\n"));
1192
- }
1193
- };
1194
-
1195
- //#endregion
1196
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/versions.js
1197
- const version = {
1198
- major: 4,
1199
- minor: 0,
1200
- patch: 0
1201
- };
1202
-
1203
- //#endregion
1204
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/schemas.js
1205
- const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
1206
- var _a;
1207
- inst ?? (inst = {});
1208
- inst._zod.def = def;
1209
- inst._zod.bag = inst._zod.bag || {};
1210
- inst._zod.version = version;
1211
- const checks = [...inst._zod.def.checks ?? []];
1212
- if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
1213
- for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
1214
- if (checks.length === 0) {
1215
- (_a = inst._zod).deferred ?? (_a.deferred = []);
1216
- inst._zod.deferred?.push(() => {
1217
- inst._zod.run = inst._zod.parse;
1218
- });
1219
- } else {
1220
- const runChecks = (payload, checks$1, ctx) => {
1221
- let isAborted = aborted(payload);
1222
- let asyncResult;
1223
- for (const ch of checks$1) {
1224
- if (ch._zod.def.when) {
1225
- if (!ch._zod.def.when(payload)) continue;
1226
- } else if (isAborted) continue;
1227
- const currLen = payload.issues.length;
1228
- const _ = ch._zod.check(payload);
1229
- if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
1230
- if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
1231
- await _;
1232
- if (payload.issues.length === currLen) return;
1233
- if (!isAborted) isAborted = aborted(payload, currLen);
1234
- });
1235
- else {
1236
- if (payload.issues.length === currLen) continue;
1237
- if (!isAborted) isAborted = aborted(payload, currLen);
1238
- }
1239
- }
1240
- if (asyncResult) return asyncResult.then(() => {
1241
- return payload;
1242
- });
1243
- return payload;
1244
- };
1245
- inst._zod.run = (payload, ctx) => {
1246
- const result = inst._zod.parse(payload, ctx);
1247
- if (result instanceof Promise) {
1248
- if (ctx.async === false) throw new $ZodAsyncError();
1249
- return result.then((result$1) => runChecks(result$1, checks, ctx));
1250
- }
1251
- return runChecks(result, checks, ctx);
1252
- };
1253
- }
1254
- inst["~standard"] = {
1255
- validate: (value) => {
1256
- try {
1257
- const r = safeParse$1(inst, value);
1258
- return r.success ? { value: r.data } : { issues: r.error?.issues };
1259
- } catch (_) {
1260
- return safeParseAsync$1(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
1261
- }
1262
- },
1263
- vendor: "zod",
1264
- version: 1
1265
- };
1266
- });
1267
- const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
1268
- $ZodType.init(inst, def);
1269
- inst._zod.parse = (payload) => payload;
1270
- });
1271
- const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
1272
- $ZodType.init(inst, def);
1273
- inst._zod.parse = (payload, _ctx) => {
1274
- payload.issues.push({
1275
- expected: "never",
1276
- code: "invalid_type",
1277
- input: payload.value,
1278
- inst
1279
- });
1280
- return payload;
1281
- };
1282
- });
1283
- function handleArrayResult(result, final, index) {
1284
- if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
1285
- final.value[index] = result.value;
1286
- }
1287
- const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
1288
- $ZodType.init(inst, def);
1289
- inst._zod.parse = (payload, ctx) => {
1290
- const input = payload.value;
1291
- if (!Array.isArray(input)) {
1292
- payload.issues.push({
1293
- expected: "array",
1294
- code: "invalid_type",
1295
- input,
1296
- inst
1297
- });
1298
- return payload;
1299
- }
1300
- payload.value = Array(input.length);
1301
- const proms = [];
1302
- for (let i = 0; i < input.length; i++) {
1303
- const item = input[i];
1304
- const result = def.element._zod.run({
1305
- value: item,
1306
- issues: []
1307
- }, ctx);
1308
- if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i)));
1309
- else handleArrayResult(result, payload, i);
1310
- }
1311
- if (proms.length) return Promise.all(proms).then(() => payload);
1312
- return payload;
1313
- };
1314
- });
1315
- function handleObjectResult(result, final, key) {
1316
- if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
1317
- final.value[key] = result.value;
1318
- }
1319
- function handleOptionalObjectResult(result, final, key, input) {
1320
- if (result.issues.length) if (input[key] === void 0) if (key in input) final.value[key] = void 0;
1321
- else final.value[key] = result.value;
1322
- else final.issues.push(...prefixIssues(key, result.issues));
1323
- else if (result.value === void 0) {
1324
- if (key in input) final.value[key] = void 0;
1325
- } else final.value[key] = result.value;
1326
- }
1327
- const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
1328
- $ZodType.init(inst, def);
1329
- const _normalized = cached(() => {
1330
- const keys = Object.keys(def.shape);
1331
- for (const k of keys) if (!(def.shape[k] instanceof $ZodType)) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1332
- const okeys = optionalKeys(def.shape);
1333
- return {
1334
- shape: def.shape,
1335
- keys,
1336
- keySet: new Set(keys),
1337
- numKeys: keys.length,
1338
- optionalKeys: new Set(okeys)
1339
- };
1340
- });
1341
- defineLazy(inst._zod, "propValues", () => {
1342
- const shape = def.shape;
1343
- const propValues = {};
1344
- for (const key in shape) {
1345
- const field = shape[key]._zod;
1346
- if (field.values) {
1347
- propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
1348
- for (const v of field.values) propValues[key].add(v);
1349
- }
1350
- }
1351
- return propValues;
1352
- });
1353
- const generateFastpass = (shape) => {
1354
- const doc = new Doc([
1355
- "shape",
1356
- "payload",
1357
- "ctx"
1358
- ]);
1359
- const normalized = _normalized.value;
1360
- const parseStr = (key) => {
1361
- const k = esc(key);
1362
- return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1363
- };
1364
- doc.write(`const input = payload.value;`);
1365
- const ids = Object.create(null);
1366
- let counter = 0;
1367
- for (const key of normalized.keys) ids[key] = `key_${counter++}`;
1368
- doc.write(`const newResult = {}`);
1369
- for (const key of normalized.keys) if (normalized.optionalKeys.has(key)) {
1370
- const id = ids[key];
1371
- doc.write(`const ${id} = ${parseStr(key)};`);
1372
- const k = esc(key);
1373
- doc.write(`
1374
- if (${id}.issues.length) {
1375
- if (input[${k}] === undefined) {
1376
- if (${k} in input) {
1377
- newResult[${k}] = undefined;
1378
- }
1379
- } else {
1380
- payload.issues = payload.issues.concat(
1381
- ${id}.issues.map((iss) => ({
1382
- ...iss,
1383
- path: iss.path ? [${k}, ...iss.path] : [${k}],
1384
- }))
1385
- );
1386
- }
1387
- } else if (${id}.value === undefined) {
1388
- if (${k} in input) newResult[${k}] = undefined;
1389
- } else {
1390
- newResult[${k}] = ${id}.value;
1391
- }
1392
- `);
1393
- } else {
1394
- const id = ids[key];
1395
- doc.write(`const ${id} = ${parseStr(key)};`);
1396
- doc.write(`
1397
- if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
1398
- ...iss,
1399
- path: iss.path ? [${esc(key)}, ...iss.path] : [${esc(key)}]
1400
- })));`);
1401
- doc.write(`newResult[${esc(key)}] = ${id}.value`);
1402
- }
1403
- doc.write(`payload.value = newResult;`);
1404
- doc.write(`return payload;`);
1405
- const fn = doc.compile();
1406
- return (payload, ctx) => fn(shape, payload, ctx);
1407
- };
1408
- let fastpass;
1409
- const isObject$1 = isObject;
1410
- const jit = !globalConfig.jitless;
1411
- const allowsEval$1 = allowsEval;
1412
- const fastEnabled = jit && allowsEval$1.value;
1413
- const catchall = def.catchall;
1414
- let value;
1415
- inst._zod.parse = (payload, ctx) => {
1416
- value ?? (value = _normalized.value);
1417
- const input = payload.value;
1418
- if (!isObject$1(input)) {
1419
- payload.issues.push({
1420
- expected: "object",
1421
- code: "invalid_type",
1422
- input,
1423
- inst
1424
- });
1425
- return payload;
1426
- }
1427
- const proms = [];
1428
- if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
1429
- if (!fastpass) fastpass = generateFastpass(def.shape);
1430
- payload = fastpass(payload, ctx);
1431
- } else {
1432
- payload.value = {};
1433
- const shape = value.shape;
1434
- for (const key of value.keys) {
1435
- const el = shape[key];
1436
- const r = el._zod.run({
1437
- value: input[key],
1438
- issues: []
1439
- }, ctx);
1440
- const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
1441
- if (r instanceof Promise) proms.push(r.then((r$1) => isOptional ? handleOptionalObjectResult(r$1, payload, key, input) : handleObjectResult(r$1, payload, key)));
1442
- else if (isOptional) handleOptionalObjectResult(r, payload, key, input);
1443
- else handleObjectResult(r, payload, key);
1444
- }
1445
- }
1446
- if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
1447
- const unrecognized = [];
1448
- const keySet = value.keySet;
1449
- const _catchall = catchall._zod;
1450
- const t = _catchall.def.type;
1451
- for (const key of Object.keys(input)) {
1452
- if (keySet.has(key)) continue;
1453
- if (t === "never") {
1454
- unrecognized.push(key);
1455
- continue;
1456
- }
1457
- const r = _catchall.run({
1458
- value: input[key],
1459
- issues: []
1460
- }, ctx);
1461
- if (r instanceof Promise) proms.push(r.then((r$1) => handleObjectResult(r$1, payload, key)));
1462
- else handleObjectResult(r, payload, key);
1463
- }
1464
- if (unrecognized.length) payload.issues.push({
1465
- code: "unrecognized_keys",
1466
- keys: unrecognized,
1467
- input,
1468
- inst
1469
- });
1470
- if (!proms.length) return payload;
1471
- return Promise.all(proms).then(() => {
1472
- return payload;
1473
- });
1474
- };
1475
- });
1476
- function handleUnionResults(results, final, inst, ctx) {
1477
- for (const result of results) if (result.issues.length === 0) {
1478
- final.value = result.value;
1479
- return final;
1480
- }
1481
- final.issues.push({
1482
- code: "invalid_union",
1483
- input: final.value,
1484
- inst,
1485
- errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
1486
- });
1487
- return final;
1488
- }
1489
- const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
1490
- $ZodType.init(inst, def);
1491
- defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
1492
- defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
1493
- defineLazy(inst._zod, "values", () => {
1494
- if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
1495
- });
1496
- defineLazy(inst._zod, "pattern", () => {
1497
- if (def.options.every((o) => o._zod.pattern)) {
1498
- const patterns = def.options.map((o) => o._zod.pattern);
1499
- return /* @__PURE__ */ new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
1500
- }
1501
- });
1502
- inst._zod.parse = (payload, ctx) => {
1503
- let async = false;
1504
- const results = [];
1505
- for (const option of def.options) {
1506
- const result = option._zod.run({
1507
- value: payload.value,
1508
- issues: []
1509
- }, ctx);
1510
- if (result instanceof Promise) {
1511
- results.push(result);
1512
- async = true;
1513
- } else {
1514
- if (result.issues.length === 0) return result;
1515
- results.push(result);
1516
- }
1517
- }
1518
- if (!async) return handleUnionResults(results, payload, inst, ctx);
1519
- return Promise.all(results).then((results$1) => {
1520
- return handleUnionResults(results$1, payload, inst, ctx);
1521
- });
1522
- };
1523
- });
1524
- const $ZodIntersection = /* @__PURE__ */ $constructor("$ZodIntersection", (inst, def) => {
1525
- $ZodType.init(inst, def);
1526
- inst._zod.parse = (payload, ctx) => {
1527
- const input = payload.value;
1528
- const left = def.left._zod.run({
1529
- value: input,
1530
- issues: []
1531
- }, ctx);
1532
- const right = def.right._zod.run({
1533
- value: input,
1534
- issues: []
1535
- }, ctx);
1536
- if (left instanceof Promise || right instanceof Promise) return Promise.all([left, right]).then(([left$1, right$1]) => {
1537
- return handleIntersectionResults(payload, left$1, right$1);
1538
- });
1539
- return handleIntersectionResults(payload, left, right);
1540
- };
1541
- });
1542
- function mergeValues(a, b) {
1543
- if (a === b) return {
1544
- valid: true,
1545
- data: a
1546
- };
1547
- if (a instanceof Date && b instanceof Date && +a === +b) return {
1548
- valid: true,
1549
- data: a
1550
- };
1551
- if (isPlainObject(a) && isPlainObject(b)) {
1552
- const bKeys = Object.keys(b);
1553
- const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
1554
- const newObj = {
1555
- ...a,
1556
- ...b
1557
- };
1558
- for (const key of sharedKeys) {
1559
- const sharedValue = mergeValues(a[key], b[key]);
1560
- if (!sharedValue.valid) return {
1561
- valid: false,
1562
- mergeErrorPath: [key, ...sharedValue.mergeErrorPath]
1563
- };
1564
- newObj[key] = sharedValue.data;
1565
- }
1566
- return {
1567
- valid: true,
1568
- data: newObj
1569
- };
1570
- }
1571
- if (Array.isArray(a) && Array.isArray(b)) {
1572
- if (a.length !== b.length) return {
1573
- valid: false,
1574
- mergeErrorPath: []
1575
- };
1576
- const newArray = [];
1577
- for (let index = 0; index < a.length; index++) {
1578
- const itemA = a[index];
1579
- const itemB = b[index];
1580
- const sharedValue = mergeValues(itemA, itemB);
1581
- if (!sharedValue.valid) return {
1582
- valid: false,
1583
- mergeErrorPath: [index, ...sharedValue.mergeErrorPath]
1584
- };
1585
- newArray.push(sharedValue.data);
1586
- }
1587
- return {
1588
- valid: true,
1589
- data: newArray
1590
- };
1591
- }
1592
- return {
1593
- valid: false,
1594
- mergeErrorPath: []
1595
- };
1596
- }
1597
- function handleIntersectionResults(result, left, right) {
1598
- if (left.issues.length) result.issues.push(...left.issues);
1599
- if (right.issues.length) result.issues.push(...right.issues);
1600
- if (aborted(result)) return result;
1601
- const merged = mergeValues(left.value, right.value);
1602
- if (!merged.valid) throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
1603
- result.value = merged.data;
1604
- return result;
1605
- }
1606
- const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
1607
- $ZodType.init(inst, def);
1608
- const values = getEnumValues(def.entries);
1609
- inst._zod.values = new Set(values);
1610
- inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${values.filter((k) => propertyKeyTypes.has(typeof k)).map((o) => typeof o === "string" ? escapeRegex(o) : o.toString()).join("|")})$`);
1611
- inst._zod.parse = (payload, _ctx) => {
1612
- const input = payload.value;
1613
- if (inst._zod.values.has(input)) return payload;
1614
- payload.issues.push({
1615
- code: "invalid_value",
1616
- values,
1617
- input,
1618
- inst
1619
- });
1620
- return payload;
1621
- };
1622
- });
1623
- const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
1624
- $ZodType.init(inst, def);
1625
- inst._zod.parse = (payload, _ctx) => {
1626
- const _out = def.transform(payload.value, payload);
1627
- if (_ctx.async) return (_out instanceof Promise ? _out : Promise.resolve(_out)).then((output) => {
1628
- payload.value = output;
1629
- return payload;
1630
- });
1631
- if (_out instanceof Promise) throw new $ZodAsyncError();
1632
- payload.value = _out;
1633
- return payload;
1634
- };
1635
- });
1636
- const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
1637
- $ZodType.init(inst, def);
1638
- inst._zod.optin = "optional";
1639
- inst._zod.optout = "optional";
1640
- defineLazy(inst._zod, "values", () => {
1641
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
1642
- });
1643
- defineLazy(inst._zod, "pattern", () => {
1644
- const pattern = def.innerType._zod.pattern;
1645
- return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
1646
- });
1647
- inst._zod.parse = (payload, ctx) => {
1648
- if (def.innerType._zod.optin === "optional") return def.innerType._zod.run(payload, ctx);
1649
- if (payload.value === void 0) return payload;
1650
- return def.innerType._zod.run(payload, ctx);
1651
- };
1652
- });
1653
- const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
1654
- $ZodType.init(inst, def);
1655
- defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1656
- defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1657
- defineLazy(inst._zod, "pattern", () => {
1658
- const pattern = def.innerType._zod.pattern;
1659
- return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
1660
- });
1661
- defineLazy(inst._zod, "values", () => {
1662
- return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
1663
- });
1664
- inst._zod.parse = (payload, ctx) => {
1665
- if (payload.value === null) return payload;
1666
- return def.innerType._zod.run(payload, ctx);
1667
- };
1668
- });
1669
- const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
1670
- $ZodType.init(inst, def);
1671
- inst._zod.optin = "optional";
1672
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1673
- inst._zod.parse = (payload, ctx) => {
1674
- if (payload.value === void 0) {
1675
- payload.value = def.defaultValue;
1676
- /**
1677
- * $ZodDefault always returns the default value immediately.
1678
- * It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
1679
- return payload;
1680
- }
1681
- const result = def.innerType._zod.run(payload, ctx);
1682
- if (result instanceof Promise) return result.then((result$1) => handleDefaultResult(result$1, def));
1683
- return handleDefaultResult(result, def);
1684
- };
1685
- });
1686
- function handleDefaultResult(payload, def) {
1687
- if (payload.value === void 0) payload.value = def.defaultValue;
1688
- return payload;
1689
- }
1690
- const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
1691
- $ZodType.init(inst, def);
1692
- inst._zod.optin = "optional";
1693
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1694
- inst._zod.parse = (payload, ctx) => {
1695
- if (payload.value === void 0) payload.value = def.defaultValue;
1696
- return def.innerType._zod.run(payload, ctx);
1697
- };
1698
- });
1699
- const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
1700
- $ZodType.init(inst, def);
1701
- defineLazy(inst._zod, "values", () => {
1702
- const v = def.innerType._zod.values;
1703
- return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
1704
- });
1705
- inst._zod.parse = (payload, ctx) => {
1706
- const result = def.innerType._zod.run(payload, ctx);
1707
- if (result instanceof Promise) return result.then((result$1) => handleNonOptionalResult(result$1, inst));
1708
- return handleNonOptionalResult(result, inst);
1709
- };
1710
- });
1711
- function handleNonOptionalResult(payload, inst) {
1712
- if (!payload.issues.length && payload.value === void 0) payload.issues.push({
1713
- code: "invalid_type",
1714
- expected: "nonoptional",
1715
- input: payload.value,
1716
- inst
1717
- });
1718
- return payload;
1719
- }
1720
- const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
1721
- $ZodType.init(inst, def);
1722
- inst._zod.optin = "optional";
1723
- defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1724
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1725
- inst._zod.parse = (payload, ctx) => {
1726
- const result = def.innerType._zod.run(payload, ctx);
1727
- if (result instanceof Promise) return result.then((result$1) => {
1728
- payload.value = result$1.value;
1729
- if (result$1.issues.length) {
1730
- payload.value = def.catchValue({
1731
- ...payload,
1732
- error: { issues: result$1.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1733
- input: payload.value
1734
- });
1735
- payload.issues = [];
1736
- }
1737
- return payload;
1738
- });
1739
- payload.value = result.value;
1740
- if (result.issues.length) {
1741
- payload.value = def.catchValue({
1742
- ...payload,
1743
- error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
1744
- input: payload.value
1745
- });
1746
- payload.issues = [];
1747
- }
1748
- return payload;
1749
- };
1750
- });
1751
- const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
1752
- $ZodType.init(inst, def);
1753
- defineLazy(inst._zod, "values", () => def.in._zod.values);
1754
- defineLazy(inst._zod, "optin", () => def.in._zod.optin);
1755
- defineLazy(inst._zod, "optout", () => def.out._zod.optout);
1756
- inst._zod.parse = (payload, ctx) => {
1757
- const left = def.in._zod.run(payload, ctx);
1758
- if (left instanceof Promise) return left.then((left$1) => handlePipeResult(left$1, def, ctx));
1759
- return handlePipeResult(left, def, ctx);
1760
- };
1761
- });
1762
- function handlePipeResult(left, def, ctx) {
1763
- if (aborted(left)) return left;
1764
- return def.out._zod.run({
1765
- value: left.value,
1766
- issues: left.issues
1767
- }, ctx);
1768
- }
1769
- const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
1770
- $ZodType.init(inst, def);
1771
- defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1772
- defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1773
- defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1774
- defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1775
- inst._zod.parse = (payload, ctx) => {
1776
- const result = def.innerType._zod.run(payload, ctx);
1777
- if (result instanceof Promise) return result.then(handleReadonlyResult);
1778
- return handleReadonlyResult(result);
1779
- };
1780
- });
1781
- function handleReadonlyResult(payload) {
1782
- payload.value = Object.freeze(payload.value);
1783
- return payload;
1784
- }
1785
- const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
1786
- $ZodCheck.init(inst, def);
1787
- $ZodType.init(inst, def);
1788
- inst._zod.parse = (payload, _) => {
1789
- return payload;
1790
- };
1791
- inst._zod.check = (payload) => {
1792
- const input = payload.value;
1793
- const r = def.fn(input);
1794
- if (r instanceof Promise) return r.then((r$1) => handleRefineResult(r$1, payload, input, inst));
1795
- handleRefineResult(r, payload, input, inst);
1796
- };
1797
- });
1798
- function handleRefineResult(result, payload, input, inst) {
1799
- if (!result) {
1800
- const _iss = {
1801
- code: "custom",
1802
- input,
1803
- inst,
1804
- path: [...inst._zod.def.path ?? []],
1805
- continue: !inst._zod.def.abort
1806
- };
1807
- if (inst._zod.def.params) _iss.params = inst._zod.def.params;
1808
- payload.issues.push(issue(_iss));
1809
- }
1810
- }
1811
-
1812
- //#endregion
1813
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/registries.js
1814
- const $output = Symbol("ZodOutput");
1815
- const $input = Symbol("ZodInput");
1816
- var $ZodRegistry = class {
1817
- constructor() {
1818
- this._map = /* @__PURE__ */ new Map();
1819
- this._idmap = /* @__PURE__ */ new Map();
1820
- }
1821
- add(schema, ..._meta) {
1822
- const meta = _meta[0];
1823
- this._map.set(schema, meta);
1824
- if (meta && typeof meta === "object" && "id" in meta) {
1825
- if (this._idmap.has(meta.id)) throw new Error(`ID ${meta.id} already exists in the registry`);
1826
- this._idmap.set(meta.id, schema);
1827
- }
1828
- return this;
1829
- }
1830
- clear() {
1831
- this._map = /* @__PURE__ */ new Map();
1832
- this._idmap = /* @__PURE__ */ new Map();
1833
- return this;
1834
- }
1835
- remove(schema) {
1836
- const meta = this._map.get(schema);
1837
- if (meta && typeof meta === "object" && "id" in meta) this._idmap.delete(meta.id);
1838
- this._map.delete(schema);
1839
- return this;
1840
- }
1841
- get(schema) {
1842
- const p = schema._zod.parent;
1843
- if (p) {
1844
- const pm = { ...this.get(p) ?? {} };
1845
- delete pm.id;
1846
- return {
1847
- ...pm,
1848
- ...this._map.get(schema)
1849
- };
1850
- }
1851
- return this._map.get(schema);
1852
- }
1853
- has(schema) {
1854
- return this._map.has(schema);
1855
- }
1856
- };
1857
- function registry() {
1858
- return new $ZodRegistry();
1859
- }
1860
- const globalRegistry = /* @__PURE__ */ registry();
1861
-
1862
- //#endregion
1863
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/api.js
1864
- function _unknown(Class) {
1865
- return new Class({ type: "unknown" });
1866
- }
1867
- function _never(Class, params) {
1868
- return new Class({
1869
- type: "never",
1870
- ...normalizeParams(params)
1871
- });
1872
- }
1873
- function _maxLength(maximum, params) {
1874
- return new $ZodCheckMaxLength({
1875
- check: "max_length",
1876
- ...normalizeParams(params),
1877
- maximum
1878
- });
1879
- }
1880
- function _minLength(minimum, params) {
1881
- return new $ZodCheckMinLength({
1882
- check: "min_length",
1883
- ...normalizeParams(params),
1884
- minimum
1885
- });
1886
- }
1887
- function _length(length, params) {
1888
- return new $ZodCheckLengthEquals({
1889
- check: "length_equals",
1890
- ...normalizeParams(params),
1891
- length
1892
- });
1893
- }
1894
- function _overwrite(tx) {
1895
- return new $ZodCheckOverwrite({
1896
- check: "overwrite",
1897
- tx
1898
- });
1899
- }
1900
- function _array(Class, element, params) {
1901
- return new Class({
1902
- type: "array",
1903
- element,
1904
- ...normalizeParams(params)
1905
- });
1906
- }
1907
- function _refine(Class, fn, _params) {
1908
- return new Class({
1909
- type: "custom",
1910
- check: "custom",
1911
- fn,
1912
- ...normalizeParams(_params)
1913
- });
1914
- }
1915
-
1916
- //#endregion
1917
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/classic/errors.js
1918
- const initializer = (inst, issues) => {
1919
- $ZodError.init(inst, issues);
1920
- inst.name = "ZodError";
1921
- Object.defineProperties(inst, {
1922
- format: { value: (mapper) => formatError(inst, mapper) },
1923
- flatten: { value: (mapper) => flattenError(inst, mapper) },
1924
- addIssue: { value: (issue$1) => inst.issues.push(issue$1) },
1925
- addIssues: { value: (issues$1) => inst.issues.push(...issues$1) },
1926
- isEmpty: { get() {
1927
- return inst.issues.length === 0;
1928
- } }
1929
- });
1930
- };
1931
- const ZodError = $constructor("ZodError", initializer);
1932
- const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
1933
-
1934
- //#endregion
1935
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/classic/parse.js
1936
- const parse = /* @__PURE__ */ _parse(ZodRealError);
1937
- const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
1938
- const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
1939
- const safeParseAsync = /* @__PURE__ */ _safeParseAsync(ZodRealError);
1940
-
1941
- //#endregion
1942
- //#region node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/classic/schemas.js
1943
- const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
1944
- $ZodType.init(inst, def);
1945
- inst.def = def;
1946
- Object.defineProperty(inst, "_def", { value: def });
1947
- inst.check = (...checks) => {
1948
- return inst.clone({
1949
- ...def,
1950
- checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
1951
- check: ch,
1952
- def: { check: "custom" },
1953
- onattach: []
1954
- } } : ch)]
1955
- });
1956
- };
1957
- inst.clone = (def$1, params) => clone(inst, def$1, params);
1958
- inst.brand = () => inst;
1959
- inst.register = ((reg, meta) => {
1960
- reg.add(inst, meta);
1961
- return inst;
1962
- });
1963
- inst.parse = (data, params) => parse(inst, data, params, { callee: inst.parse });
1964
- inst.safeParse = (data, params) => safeParse(inst, data, params);
1965
- inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
1966
- inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
1967
- inst.spa = inst.safeParseAsync;
1968
- inst.refine = (check$1, params) => inst.check(refine(check$1, params));
1969
- inst.superRefine = (refinement) => inst.check(superRefine(refinement));
1970
- inst.overwrite = (fn) => inst.check(_overwrite(fn));
1971
- inst.optional = () => optional(inst);
1972
- inst.nullable = () => nullable(inst);
1973
- inst.nullish = () => optional(nullable(inst));
1974
- inst.nonoptional = (params) => nonoptional(inst, params);
1975
- inst.array = () => array(inst);
1976
- inst.or = (arg) => union([inst, arg]);
1977
- inst.and = (arg) => intersection(inst, arg);
1978
- inst.transform = (tx) => pipe(inst, transform(tx));
1979
- inst.default = (def$1) => _default(inst, def$1);
1980
- inst.prefault = (def$1) => prefault(inst, def$1);
1981
- inst.catch = (params) => _catch(inst, params);
1982
- inst.pipe = (target) => pipe(inst, target);
1983
- inst.readonly = () => readonly(inst);
1984
- inst.describe = (description) => {
1985
- const cl = inst.clone();
1986
- globalRegistry.add(cl, { description });
1987
- return cl;
1988
- };
1989
- Object.defineProperty(inst, "description", {
1990
- get() {
1991
- return globalRegistry.get(inst)?.description;
1992
- },
1993
- configurable: true
1994
- });
1995
- inst.meta = (...args) => {
1996
- if (args.length === 0) return globalRegistry.get(inst);
1997
- const cl = inst.clone();
1998
- globalRegistry.add(cl, args[0]);
1999
- return cl;
2000
- };
2001
- inst.isOptional = () => inst.safeParse(void 0).success;
2002
- inst.isNullable = () => inst.safeParse(null).success;
2003
- return inst;
2004
- });
2005
- const ZodUnknown = /* @__PURE__ */ $constructor("ZodUnknown", (inst, def) => {
2006
- $ZodUnknown.init(inst, def);
2007
- ZodType.init(inst, def);
2008
- });
2009
- function unknown() {
2010
- return _unknown(ZodUnknown);
2011
- }
2012
- const ZodNever = /* @__PURE__ */ $constructor("ZodNever", (inst, def) => {
2013
- $ZodNever.init(inst, def);
2014
- ZodType.init(inst, def);
2015
- });
2016
- function never(params) {
2017
- return _never(ZodNever, params);
2018
- }
2019
- const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
2020
- $ZodArray.init(inst, def);
2021
- ZodType.init(inst, def);
2022
- inst.element = def.element;
2023
- inst.min = (minLength, params) => inst.check(_minLength(minLength, params));
2024
- inst.nonempty = (params) => inst.check(_minLength(1, params));
2025
- inst.max = (maxLength, params) => inst.check(_maxLength(maxLength, params));
2026
- inst.length = (len, params) => inst.check(_length(len, params));
2027
- inst.unwrap = () => inst.element;
2028
- });
2029
- function array(element, params) {
2030
- return _array(ZodArray, element, params);
2031
- }
2032
- const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
2033
- $ZodObject.init(inst, def);
2034
- ZodType.init(inst, def);
2035
- defineLazy(inst, "shape", () => def.shape);
2036
- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
2037
- inst.catchall = (catchall) => inst.clone({
2038
- ...inst._zod.def,
2039
- catchall
2040
- });
2041
- inst.passthrough = () => inst.clone({
2042
- ...inst._zod.def,
2043
- catchall: unknown()
2044
- });
2045
- inst.loose = () => inst.clone({
2046
- ...inst._zod.def,
2047
- catchall: unknown()
2048
- });
2049
- inst.strict = () => inst.clone({
2050
- ...inst._zod.def,
2051
- catchall: never()
2052
- });
2053
- inst.strip = () => inst.clone({
2054
- ...inst._zod.def,
2055
- catchall: void 0
2056
- });
2057
- inst.extend = (incoming) => {
2058
- return extend(inst, incoming);
2059
- };
2060
- inst.merge = (other) => merge(inst, other);
2061
- inst.pick = (mask) => pick(inst, mask);
2062
- inst.omit = (mask) => omit(inst, mask);
2063
- inst.partial = (...args) => partial(ZodOptional, inst, args[0]);
2064
- inst.required = (...args) => required(ZodNonOptional, inst, args[0]);
2065
- });
2066
- const ZodUnion = /* @__PURE__ */ $constructor("ZodUnion", (inst, def) => {
2067
- $ZodUnion.init(inst, def);
2068
- ZodType.init(inst, def);
2069
- inst.options = def.options;
2070
- });
2071
- function union(options, params) {
2072
- return new ZodUnion({
2073
- type: "union",
2074
- options,
2075
- ...normalizeParams(params)
2076
- });
2077
- }
2078
- const ZodIntersection = /* @__PURE__ */ $constructor("ZodIntersection", (inst, def) => {
2079
- $ZodIntersection.init(inst, def);
2080
- ZodType.init(inst, def);
2081
- });
2082
- function intersection(left, right) {
2083
- return new ZodIntersection({
2084
- type: "intersection",
2085
- left,
2086
- right
2087
- });
2088
- }
2089
- const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
2090
- $ZodEnum.init(inst, def);
2091
- ZodType.init(inst, def);
2092
- inst.enum = def.entries;
2093
- inst.options = Object.values(def.entries);
2094
- const keys = new Set(Object.keys(def.entries));
2095
- inst.extract = (values, params) => {
2096
- const newEntries = {};
2097
- for (const value of values) if (keys.has(value)) newEntries[value] = def.entries[value];
2098
- else throw new Error(`Key ${value} not found in enum`);
2099
- return new ZodEnum({
2100
- ...def,
2101
- checks: [],
2102
- ...normalizeParams(params),
2103
- entries: newEntries
2104
- });
2105
- };
2106
- inst.exclude = (values, params) => {
2107
- const newEntries = { ...def.entries };
2108
- for (const value of values) if (keys.has(value)) delete newEntries[value];
2109
- else throw new Error(`Key ${value} not found in enum`);
2110
- return new ZodEnum({
2111
- ...def,
2112
- checks: [],
2113
- ...normalizeParams(params),
2114
- entries: newEntries
2115
- });
2116
- };
2117
- });
2118
- function _enum(values, params) {
2119
- return new ZodEnum({
2120
- type: "enum",
2121
- entries: Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values,
2122
- ...normalizeParams(params)
2123
- });
2124
- }
2125
- const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
2126
- $ZodTransform.init(inst, def);
2127
- ZodType.init(inst, def);
2128
- inst._zod.parse = (payload, _ctx) => {
2129
- payload.addIssue = (issue$1) => {
2130
- if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, def));
2131
- else {
2132
- const _issue = issue$1;
2133
- if (_issue.fatal) _issue.continue = false;
2134
- _issue.code ?? (_issue.code = "custom");
2135
- _issue.input ?? (_issue.input = payload.value);
2136
- _issue.inst ?? (_issue.inst = inst);
2137
- _issue.continue ?? (_issue.continue = true);
2138
- payload.issues.push(issue(_issue));
2139
- }
2140
- };
2141
- const output = def.transform(payload.value, payload);
2142
- if (output instanceof Promise) return output.then((output$1) => {
2143
- payload.value = output$1;
2144
- return payload;
2145
- });
2146
- payload.value = output;
2147
- return payload;
2148
- };
2149
- });
2150
- function transform(fn) {
2151
- return new ZodTransform({
2152
- type: "transform",
2153
- transform: fn
2154
- });
2155
- }
2156
- const ZodOptional = /* @__PURE__ */ $constructor("ZodOptional", (inst, def) => {
2157
- $ZodOptional.init(inst, def);
2158
- ZodType.init(inst, def);
2159
- inst.unwrap = () => inst._zod.def.innerType;
2160
- });
2161
- function optional(innerType) {
2162
- return new ZodOptional({
2163
- type: "optional",
2164
- innerType
2165
- });
2166
- }
2167
- const ZodNullable = /* @__PURE__ */ $constructor("ZodNullable", (inst, def) => {
2168
- $ZodNullable.init(inst, def);
2169
- ZodType.init(inst, def);
2170
- inst.unwrap = () => inst._zod.def.innerType;
2171
- });
2172
- function nullable(innerType) {
2173
- return new ZodNullable({
2174
- type: "nullable",
2175
- innerType
2176
- });
2177
- }
2178
- const ZodDefault = /* @__PURE__ */ $constructor("ZodDefault", (inst, def) => {
2179
- $ZodDefault.init(inst, def);
2180
- ZodType.init(inst, def);
2181
- inst.unwrap = () => inst._zod.def.innerType;
2182
- inst.removeDefault = inst.unwrap;
2183
- });
2184
- function _default(innerType, defaultValue) {
2185
- return new ZodDefault({
2186
- type: "default",
2187
- innerType,
2188
- get defaultValue() {
2189
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
2190
- }
2191
- });
2192
- }
2193
- const ZodPrefault = /* @__PURE__ */ $constructor("ZodPrefault", (inst, def) => {
2194
- $ZodPrefault.init(inst, def);
2195
- ZodType.init(inst, def);
2196
- inst.unwrap = () => inst._zod.def.innerType;
2197
- });
2198
- function prefault(innerType, defaultValue) {
2199
- return new ZodPrefault({
2200
- type: "prefault",
2201
- innerType,
2202
- get defaultValue() {
2203
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
2204
- }
2205
- });
2206
- }
2207
- const ZodNonOptional = /* @__PURE__ */ $constructor("ZodNonOptional", (inst, def) => {
2208
- $ZodNonOptional.init(inst, def);
2209
- ZodType.init(inst, def);
2210
- inst.unwrap = () => inst._zod.def.innerType;
2211
- });
2212
- function nonoptional(innerType, params) {
2213
- return new ZodNonOptional({
2214
- type: "nonoptional",
2215
- innerType,
2216
- ...normalizeParams(params)
2217
- });
2218
- }
2219
- const ZodCatch = /* @__PURE__ */ $constructor("ZodCatch", (inst, def) => {
2220
- $ZodCatch.init(inst, def);
2221
- ZodType.init(inst, def);
2222
- inst.unwrap = () => inst._zod.def.innerType;
2223
- inst.removeCatch = inst.unwrap;
2224
- });
2225
- function _catch(innerType, catchValue) {
2226
- return new ZodCatch({
2227
- type: "catch",
2228
- innerType,
2229
- catchValue: typeof catchValue === "function" ? catchValue : () => catchValue
2230
- });
2231
- }
2232
- const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
2233
- $ZodPipe.init(inst, def);
2234
- ZodType.init(inst, def);
2235
- inst.in = def.in;
2236
- inst.out = def.out;
2237
- });
2238
- function pipe(in_, out) {
2239
- return new ZodPipe({
2240
- type: "pipe",
2241
- in: in_,
2242
- out
2243
- });
2244
- }
2245
- const ZodReadonly = /* @__PURE__ */ $constructor("ZodReadonly", (inst, def) => {
2246
- $ZodReadonly.init(inst, def);
2247
- ZodType.init(inst, def);
2248
- });
2249
- function readonly(innerType) {
2250
- return new ZodReadonly({
2251
- type: "readonly",
2252
- innerType
2253
- });
2254
- }
2255
- const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
2256
- $ZodCustom.init(inst, def);
2257
- ZodType.init(inst, def);
2258
- });
2259
- function check(fn) {
2260
- const ch = new $ZodCheck({ check: "custom" });
2261
- ch._zod.check = fn;
2262
- return ch;
2263
- }
2264
- function refine(fn, _params = {}) {
2265
- return _refine(ZodCustom, fn, _params);
2266
- }
2267
- function superRefine(fn) {
2268
- const ch = check((payload) => {
2269
- payload.addIssue = (issue$1) => {
2270
- if (typeof issue$1 === "string") payload.issues.push(issue(issue$1, payload.value, ch._zod.def));
2271
- else {
2272
- const _issue = issue$1;
2273
- if (_issue.fatal) _issue.continue = false;
2274
- _issue.code ?? (_issue.code = "custom");
2275
- _issue.input ?? (_issue.input = payload.value);
2276
- _issue.inst ?? (_issue.inst = ch);
2277
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
2278
- payload.issues.push(issue(_issue));
2279
- }
2280
- };
2281
- return fn(payload.value, payload);
2282
- });
2283
- return ch;
2284
- }
2285
-
2286
617
  //#endregion
2287
618
  //#region src/openapi.ts
2288
619
  const paths = {};
@@ -2302,8 +633,8 @@ function getParameters(options) {
2302
633
  parameters.push(...options.metadata.openapi.parameters);
2303
634
  return parameters;
2304
635
  }
2305
- if (options.query instanceof ZodObject) Object.entries(options.query.shape).forEach(([key, value]) => {
2306
- if (value instanceof ZodObject) parameters.push({
636
+ if (options.query instanceof zod.ZodObject) Object.entries(options.query.shape).forEach(([key, value]) => {
637
+ if (value instanceof zod.ZodObject) parameters.push({
2307
638
  name: key,
2308
639
  in: "query",
2309
640
  schema: {
@@ -2318,26 +649,26 @@ function getParameters(options) {
2318
649
  function getRequestBody(options) {
2319
650
  if (options.metadata?.openapi?.requestBody) return options.metadata.openapi.requestBody;
2320
651
  if (!options.body) return void 0;
2321
- if (options.body instanceof ZodObject || options.body instanceof ZodOptional) {
652
+ if (options.body instanceof zod.ZodObject || options.body instanceof zod.ZodOptional) {
2322
653
  const shape = options.body.shape;
2323
654
  if (!shape) return void 0;
2324
655
  const properties = {};
2325
- const required$1 = [];
656
+ const required = [];
2326
657
  Object.entries(shape).forEach(([key, value]) => {
2327
- if (value instanceof ZodObject) {
658
+ if (value instanceof zod.ZodObject) {
2328
659
  properties[key] = {
2329
660
  type: getTypeFromZodType(value),
2330
661
  description: value.description
2331
662
  };
2332
- if (!(value instanceof ZodOptional)) required$1.push(key);
663
+ if (!(value instanceof zod.ZodOptional)) required.push(key);
2333
664
  }
2334
665
  });
2335
666
  return {
2336
- required: options.body instanceof ZodOptional ? false : options.body ? true : false,
667
+ required: options.body instanceof zod.ZodOptional ? false : options.body ? true : false,
2337
668
  content: { "application/json": { schema: {
2338
669
  type: "object",
2339
670
  properties,
2340
- required: required$1
671
+ required
2341
672
  } } }
2342
673
  };
2343
674
  }
@@ -2391,7 +722,7 @@ function getResponse(responses) {
2391
722
  ...responses
2392
723
  };
2393
724
  }
2394
- async function generator(endpoints, config$1) {
725
+ async function generator(endpoints, config) {
2395
726
  const components = { schemas: {} };
2396
727
  Object.entries(endpoints).forEach(([_, value]) => {
2397
728
  const options = value.options;
@@ -2429,7 +760,7 @@ async function generator(endpoints, config$1) {
2429
760
  },
2430
761
  components,
2431
762
  security: [{ apiKeyCookie: [] }],
2432
- servers: [{ url: config$1?.url }],
763
+ servers: [{ url: config?.url }],
2433
764
  tags: [{
2434
765
  name: "Default",
2435
766
  description: "Default endpoints that are included with Better Auth by default. These endpoints are not part of any plugin."
@@ -2437,7 +768,7 @@ async function generator(endpoints, config$1) {
2437
768
  paths
2438
769
  };
2439
770
  }
2440
- const getHTML = (apiReference, config$1) => `<!doctype html>
771
+ const getHTML = (apiReference, config) => `<!doctype html>
2441
772
  <html>
2442
773
  <head>
2443
774
  <title>Scalar API Reference</title>
@@ -2454,11 +785,11 @@ const getHTML = (apiReference, config$1) => `<!doctype html>
2454
785
  <\/script>
2455
786
  <script>
2456
787
  var configuration = {
2457
- favicon: ${config$1?.logo ? `data:image/svg+xml;utf8,${encodeURIComponent(config$1.logo)}` : void 0} ,
2458
- theme: ${config$1?.theme || "saturn"},
788
+ favicon: ${config?.logo ? `data:image/svg+xml;utf8,${encodeURIComponent(config.logo)}` : void 0} ,
789
+ theme: ${config?.theme || "saturn"},
2459
790
  metaData: {
2460
- title: ${config$1?.title || "Open API Reference"},
2461
- description: ${config$1?.description || "Better Call Open API"},
791
+ title: ${config?.title || "Open API Reference"},
792
+ description: ${config?.description || "Better Call Open API"},
2462
793
  }
2463
794
  }
2464
795
  document.getElementById('api-reference').dataset.configuration =
@@ -2470,11 +801,11 @@ const getHTML = (apiReference, config$1) => `<!doctype html>
2470
801
 
2471
802
  //#endregion
2472
803
  //#region src/router.ts
2473
- const createRouter = (endpoints, config$1) => {
2474
- if (!config$1?.openapi?.disabled) {
804
+ const createRouter = (endpoints, config) => {
805
+ if (!config?.openapi?.disabled) {
2475
806
  const openapi = {
2476
807
  path: "/api/reference",
2477
- ...config$1?.openapi
808
+ ...config?.openapi
2478
809
  };
2479
810
  endpoints["openapi"] = createEndpoint(openapi.path, { method: "GET" }, async (c) => {
2480
811
  const schema = await generator(endpoints);
@@ -2489,11 +820,11 @@ const createRouter = (endpoints, config$1) => {
2489
820
  const methods = Array.isArray(endpoint.options?.method) ? endpoint.options.method : [endpoint.options?.method];
2490
821
  for (const method of methods) (0, rou3.addRoute)(router, method, endpoint.path, endpoint);
2491
822
  }
2492
- if (config$1?.routerMiddleware?.length) for (const { path, middleware } of config$1.routerMiddleware) (0, rou3.addRoute)(middlewareRouter, "*", path, middleware);
823
+ if (config?.routerMiddleware?.length) for (const { path, middleware } of config.routerMiddleware) (0, rou3.addRoute)(middlewareRouter, "*", path, middleware);
2493
824
  const processRequest = async (request) => {
2494
825
  const url = new URL(request.url);
2495
- const path = config$1?.basePath ? url.pathname.split(config$1.basePath).reduce((acc, curr, index) => {
2496
- if (index !== 0) if (index > 1) acc.push(`${config$1.basePath}${curr}`);
826
+ const path = config?.basePath ? url.pathname.split(config.basePath).reduce((acc, curr, index) => {
827
+ if (index !== 0) if (index > 1) acc.push(`${config.basePath}${curr}`);
2497
828
  else acc.push(curr);
2498
829
  return acc;
2499
830
  }, []).join("") : url.pathname;
@@ -2514,7 +845,7 @@ const createRouter = (endpoints, config$1) => {
2514
845
  });
2515
846
  const handler = route.data;
2516
847
  try {
2517
- const allowedMediaTypes = handler.options.metadata?.allowedMediaTypes || config$1?.allowedMediaTypes;
848
+ const allowedMediaTypes = handler.options.metadata?.allowedMediaTypes || config?.allowedMediaTypes;
2518
849
  const context = {
2519
850
  path,
2520
851
  method: request.method,
@@ -2525,7 +856,7 @@ const createRouter = (endpoints, config$1) => {
2525
856
  query,
2526
857
  _flag: "router",
2527
858
  asResponse: true,
2528
- context: config$1?.routerContext
859
+ context: config?.routerContext
2529
860
  };
2530
861
  const middlewareRoutes = (0, rou3.findAllRoutes)(middlewareRouter, "*", path);
2531
862
  if (middlewareRoutes?.length) for (const { data: middleware, params } of middlewareRoutes) {
@@ -2538,14 +869,14 @@ const createRouter = (endpoints, config$1) => {
2538
869
  }
2539
870
  return await handler(context);
2540
871
  } catch (error) {
2541
- if (config$1?.onError) try {
2542
- const errorResponse = await config$1.onError(error);
872
+ if (config?.onError) try {
873
+ const errorResponse = await config.onError(error);
2543
874
  if (errorResponse instanceof Response) return toResponse(errorResponse);
2544
875
  } catch (error$1) {
2545
876
  if (isAPIError(error$1)) return toResponse(error$1);
2546
877
  throw error$1;
2547
878
  }
2548
- if (config$1?.throwError) throw error;
879
+ if (config?.throwError) throw error;
2549
880
  if (isAPIError(error)) return toResponse(error);
2550
881
  console.error(`# SERVER_ERROR: `, error);
2551
882
  return new Response(null, {
@@ -2556,10 +887,10 @@ const createRouter = (endpoints, config$1) => {
2556
887
  };
2557
888
  return {
2558
889
  handler: async (request) => {
2559
- const onReq = await config$1?.onRequest?.(request);
890
+ const onReq = await config?.onRequest?.(request);
2560
891
  if (onReq instanceof Response) return onReq;
2561
892
  const res = await processRequest(onReq instanceof Request ? onReq : request);
2562
- const onRes = await config$1?.onResponse?.(res);
893
+ const onRes = await config?.onResponse?.(res);
2563
894
  if (onRes instanceof Response) return onRes;
2564
895
  return res;
2565
896
  },