better-call 1.3.3 → 2.0.0-beta.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.
Files changed (59) hide show
  1. package/dist/client.cjs.map +1 -1
  2. package/dist/client.d.cts +13 -17
  3. package/dist/client.d.mts +13 -17
  4. package/dist/client.mjs.map +1 -1
  5. package/dist/context.cjs +10 -9
  6. package/dist/context.cjs.map +1 -1
  7. package/dist/context.d.cts +129 -323
  8. package/dist/context.d.mts +129 -323
  9. package/dist/context.mjs +10 -9
  10. package/dist/context.mjs.map +1 -1
  11. package/dist/cookies.cjs +1 -1
  12. package/dist/cookies.d.cts +1 -12
  13. package/dist/cookies.d.mts +1 -12
  14. package/dist/cookies.mjs +1 -1
  15. package/dist/crypto.cjs.map +1 -1
  16. package/dist/crypto.mjs.map +1 -1
  17. package/dist/endpoint.cjs +21 -7
  18. package/dist/endpoint.cjs.map +1 -1
  19. package/dist/endpoint.d.cts +197 -392
  20. package/dist/endpoint.d.mts +197 -392
  21. package/dist/endpoint.mjs +21 -7
  22. package/dist/endpoint.mjs.map +1 -1
  23. package/dist/error.cjs +1 -1
  24. package/dist/error.cjs.map +1 -1
  25. package/dist/error.mjs +1 -1
  26. package/dist/error.mjs.map +1 -1
  27. package/dist/helper.d.cts +2 -3
  28. package/dist/helper.d.mts +2 -3
  29. package/dist/index.cjs +3 -10
  30. package/dist/index.d.cts +9 -8
  31. package/dist/index.d.mts +9 -8
  32. package/dist/index.mjs +3 -4
  33. package/dist/middleware.cjs +59 -13
  34. package/dist/middleware.cjs.map +1 -1
  35. package/dist/middleware.d.cts +85 -42
  36. package/dist/middleware.d.mts +85 -42
  37. package/dist/middleware.mjs +59 -13
  38. package/dist/middleware.mjs.map +1 -1
  39. package/dist/node.cjs.map +1 -1
  40. package/dist/node.d.cts +1 -1
  41. package/dist/node.d.mts +1 -1
  42. package/dist/node.mjs.map +1 -1
  43. package/dist/openapi.cjs.map +1 -1
  44. package/dist/openapi.d.cts +1 -1
  45. package/dist/openapi.d.mts +1 -1
  46. package/dist/openapi.mjs.map +1 -1
  47. package/dist/router.cjs.map +1 -1
  48. package/dist/router.mjs.map +1 -1
  49. package/dist/to-response.cjs +1 -1
  50. package/dist/to-response.cjs.map +1 -1
  51. package/dist/to-response.mjs +1 -1
  52. package/dist/to-response.mjs.map +1 -1
  53. package/dist/types.d.cts +142 -0
  54. package/dist/types.d.mts +142 -0
  55. package/dist/validator.cjs +1 -1
  56. package/dist/validator.cjs.map +1 -1
  57. package/dist/validator.mjs +1 -1
  58. package/dist/validator.mjs.map +1 -1
  59. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"client.cjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n\ttype BetterFetchOption,\n\ttype BetterFetchResponse,\n\tcreateFetch,\n} from \"@better-fetch/fetch\";\nimport type { Router } from \"./router\";\nimport type { HasRequiredKeys, Prettify, UnionToIntersection } from \"./helper\";\nimport type { Endpoint } from \"./endpoint\";\n\nexport type HasRequired<T extends object> = T extends {}\n\t? false\n\t: T extends {\n\t\t\t\tbody?: any;\n\t\t\t\tquery?: any;\n\t\t\t\tparams?: any;\n\t\t\t}\n\t\t? T[\"body\"] extends object\n\t\t\t? HasRequiredKeys<T[\"body\"]> extends true\n\t\t\t\t? true\n\t\t\t\t: T[\"query\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t\t: false\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t: T[\"query\"] extends object\n\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t? true\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t: false\n\t\t: false;\n\ntype InferContext<T> = T extends (ctx: infer Ctx) => any\n\t? Ctx extends object\n\t\t? Ctx\n\t\t: never\n\t: never;\n\nexport interface ClientOptions extends BetterFetchOption {\n\tbaseURL?: string;\n}\n\ntype WithRequired<T, K> = T & {\n\t[P in K extends string ? K : never]-?: T[P extends keyof T ? P : never];\n};\n\ntype InferClientRoutes<T extends Record<string, Endpoint>> = {\n\t[K in keyof T]: T[K] extends Endpoint<any, infer O>\n\t\t? O extends\n\t\t\t\t| { metadata: { scope: \"http\" } }\n\t\t\t\t| { metadata: { scope: \"server\" } }\n\t\t\t\t| { metadata: { SERVER_ONLY: true } }\n\t\t\t\t| { metadata: { isAction: false } }\n\t\t\t? never\n\t\t\t: T[K]\n\t\t: T[K];\n};\n\nexport type RequiredOptionKeys<\n\tC extends {\n\t\tbody?: any;\n\t\tquery?: any;\n\t\tparams?: any;\n\t},\n> = (undefined extends C[\"body\"]\n\t? {}\n\t: {\n\t\t\tbody: true;\n\t\t}) &\n\t(undefined extends C[\"query\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tquery: true;\n\t\t\t}) &\n\t(undefined extends C[\"params\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tparams: true;\n\t\t\t});\n\nexport const createClient = <R extends Router | Router[\"endpoints\"]>(\n\toptions?: ClientOptions,\n) => {\n\tconst fetch = createFetch(options ?? {});\n\ttype API = InferClientRoutes<\n\t\tR extends { endpoints: Record<string, Endpoint> } ? R[\"endpoints\"] : R\n\t>;\n\ttype Options = API extends {\n\t\t[key: string]: infer T;\n\t}\n\t\t? T extends Endpoint\n\t\t\t? {\n\t\t\t\t\t[key in T[\"options\"][\"method\"] extends \"GET\"\n\t\t\t\t\t\t? T[\"path\"]\n\t\t\t\t\t\t: `@${T[\"options\"][\"method\"] extends string ? Lowercase<T[\"options\"][\"method\"]> : never}${T[\"path\"]}`]: T;\n\t\t\t\t}\n\t\t\t: {}\n\t\t: {};\n\n\ttype O = Prettify<UnionToIntersection<Options>>;\n\treturn async <\n\t\tOPT extends O,\n\t\tK extends keyof OPT,\n\t\tC extends InferContext<OPT[K]>,\n\t>(\n\t\tpath: K,\n\t\t...options: HasRequired<C> extends true\n\t\t\t? [\n\t\t\t\t\tWithRequired<\n\t\t\t\t\t\tBetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>,\n\t\t\t\t\t\tkeyof RequiredOptionKeys<C>\n\t\t\t\t\t>,\n\t\t\t\t]\n\t\t\t: [BetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>?]\n\t): Promise<\n\t\tBetterFetchResponse<\n\t\t\tAwaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>\n\t\t>\n\t> => {\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t})) as any;\n\t};\n};\n\nexport * from \"./error\";\n"],"mappings":";;;;;;AAuFA,MAAa,gBACZ,YACI;CACJ,MAAM,6CAAoB,WAAW,EAAE,CAAC;AAiBxC,QAAO,OAKN,MACA,GAAG,YAYC;AACJ,SAAQ,MAAM,MAAM,MAAgB,EACnC,GAAG,QAAQ,IACX,CAAC"}
1
+ {"version":3,"file":"client.cjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n\ttype BetterFetchOption,\n\ttype BetterFetchResponse,\n\tcreateFetch,\n} from \"@better-fetch/fetch\";\nimport type { Endpoint } from \"./endpoint\";\nimport type { HasRequiredKeys, Prettify, UnionToIntersection } from \"./helper\";\nimport type { Router } from \"./router\";\n\nexport type HasRequired<T extends object> = T extends {}\n\t? false\n\t: T extends {\n\t\t\t\tbody?: any;\n\t\t\t\tquery?: any;\n\t\t\t\tparams?: any;\n\t\t\t}\n\t\t? T[\"body\"] extends object\n\t\t\t? HasRequiredKeys<T[\"body\"]> extends true\n\t\t\t\t? true\n\t\t\t\t: T[\"query\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t\t: false\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t: T[\"query\"] extends object\n\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t? true\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t: false\n\t\t: false;\n\ntype InferContext<T> = T extends (ctx: infer Ctx) => any\n\t? Ctx extends object\n\t\t? Ctx\n\t\t: never\n\t: never;\n\nexport interface ClientOptions extends BetterFetchOption {\n\tbaseURL?: string;\n}\n\ntype WithRequired<T, K> = T & {\n\t[P in K extends string ? K : never]-?: T[P extends keyof T ? P : never];\n};\n\n/**\n * Filter out endpoints that should not be exposed to the client.\n * Checks the typed metadata on the Endpoint's options.\n */\ntype InferClientRoutes<T extends Record<string, Endpoint>> = {\n\t[K in keyof T]: T[K] extends Endpoint<\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tinfer Meta\n\t>\n\t\t? Meta extends\n\t\t\t\t| { scope: \"http\" }\n\t\t\t\t| { scope: \"server\" }\n\t\t\t\t| { SERVER_ONLY: true }\n\t\t\t\t| { isAction: false }\n\t\t\t? never\n\t\t\t: T[K]\n\t\t: T[K];\n};\n\nexport type RequiredOptionKeys<\n\tC extends {\n\t\tbody?: any;\n\t\tquery?: any;\n\t\tparams?: any;\n\t},\n> = (undefined extends C[\"body\"]\n\t? {}\n\t: {\n\t\t\tbody: true;\n\t\t}) &\n\t(undefined extends C[\"query\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tquery: true;\n\t\t\t}) &\n\t(undefined extends C[\"params\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tparams: true;\n\t\t\t});\n\nexport const createClient = <R extends Router | Router[\"endpoints\"]>(\n\toptions?: ClientOptions,\n) => {\n\tconst fetch = createFetch(options ?? {});\n\ttype API = InferClientRoutes<\n\t\tR extends { endpoints: Record<string, Endpoint> } ? R[\"endpoints\"] : R\n\t>;\n\ttype Options = API extends {\n\t\t[key: string]: infer T;\n\t}\n\t\t? T extends Endpoint<infer P, infer M>\n\t\t\t? {\n\t\t\t\t\t[key in M extends \"GET\"\n\t\t\t\t\t\t? P\n\t\t\t\t\t\t: `@${M extends string ? Lowercase<M> : never}${P}`]: T;\n\t\t\t\t}\n\t\t\t: {}\n\t\t: {};\n\n\ttype O = Prettify<UnionToIntersection<Options>>;\n\treturn async <\n\t\tOPT extends O,\n\t\tK extends keyof OPT,\n\t\tC extends InferContext<OPT[K]>,\n\t>(\n\t\tpath: K,\n\t\t...options: HasRequired<C> extends true\n\t\t\t? [\n\t\t\t\t\tWithRequired<\n\t\t\t\t\t\tBetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>,\n\t\t\t\t\t\tkeyof RequiredOptionKeys<C>\n\t\t\t\t\t>,\n\t\t\t\t]\n\t\t\t: [BetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>?]\n\t): Promise<\n\t\tBetterFetchResponse<\n\t\t\tAwaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>\n\t\t>\n\t> => {\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t})) as any;\n\t};\n};\n\nexport * from \"./error\";\n"],"mappings":";;;;;;AAmGA,MAAa,gBACZ,YACI;CACJ,MAAM,6CAAoB,WAAW,EAAE,CAAC;AAiBxC,QAAO,OAKN,MACA,GAAG,YAYC;AACJ,SAAQ,MAAM,MAAM,MAAgB,EACnC,GAAG,QAAQ,IACX,CAAC"}
package/dist/client.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { HasRequiredKeys, UnionToIntersection } from "./helper.cjs";
2
1
  import { APIError, BetterCallError, Status, ValidationError, hideInternalStackFrames, kAPIErrorHeaderSymbol, makeErrorForHideStackFrame, statusCodes } from "./error.cjs";
2
+ import { HasRequiredKeys, Prettify, UnionToIntersection } from "./helper.cjs";
3
3
  import { Endpoint } from "./endpoint.cjs";
4
4
  import { Router } from "./router.cjs";
5
5
  import { BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
@@ -15,22 +15,18 @@ interface ClientOptions extends BetterFetchOption {
15
15
  baseURL?: string;
16
16
  }
17
17
  type WithRequired<T, K> = T & { [P in K extends string ? K : never]-?: T[P extends keyof T ? P : never] };
18
- type InferClientRoutes<T extends Record<string, Endpoint>> = { [K in keyof T]: T[K] extends Endpoint<any, infer O> ? O extends {
19
- metadata: {
20
- scope: "http";
21
- };
18
+ /**
19
+ * Filter out endpoints that should not be exposed to the client.
20
+ * Checks the typed metadata on the Endpoint's options.
21
+ */
22
+ type InferClientRoutes<T extends Record<string, Endpoint>> = { [K in keyof T]: T[K] extends Endpoint<any, any, any, any, any, any, infer Meta> ? Meta extends {
23
+ scope: "http";
22
24
  } | {
23
- metadata: {
24
- scope: "server";
25
- };
25
+ scope: "server";
26
26
  } | {
27
- metadata: {
28
- SERVER_ONLY: true;
29
- };
27
+ SERVER_ONLY: true;
30
28
  } | {
31
- metadata: {
32
- isAction: false;
33
- };
29
+ isAction: false;
34
30
  } ? never : T[K] : T[K] };
35
31
  type RequiredOptionKeys<C extends {
36
32
  body?: any;
@@ -43,11 +39,11 @@ type RequiredOptionKeys<C extends {
43
39
  }) & (undefined extends C["params"] ? {} : {
44
40
  params: true;
45
41
  });
46
- declare const createClient: <R extends Router | Router["endpoints"]>(options?: ClientOptions) => <OPT extends (UnionToIntersection<InferClientRoutes<R extends {
42
+ declare const createClient: <R extends Router | Router["endpoints"]>(options?: ClientOptions) => <OPT extends Prettify<UnionToIntersection<InferClientRoutes<R extends {
47
43
  endpoints: Record<string, Endpoint>;
48
44
  } ? R["endpoints"] : R> extends {
49
- [key: string]: infer T_1;
50
- } ? T_1 extends Endpoint ? { [key in T_1["options"]["method"] extends "GET" ? T_1["path"] : `@${T_1["options"]["method"] extends string ? Lowercase<T_1["options"]["method"]> : never}${T_1["path"]}`]: T_1 } : {} : {}> extends infer T ? { [K_1 in keyof T]: T[K_1] } : never), K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<BetterFetchOption<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>] : [BetterFetchOption<C["body"], C["query"], C["params"]>?]) => Promise<BetterFetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
45
+ [key: string]: infer T;
46
+ } ? T extends Endpoint<infer P extends string, infer M> ? { [key in M extends "GET" ? P : `@${M extends string ? Lowercase<M> : never}${P}`]: T } : {} : {}>>, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<BetterFetchOption<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>] : [BetterFetchOption<C["body"], C["query"], C["params"]>?]) => Promise<BetterFetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
51
47
  //#endregion
52
48
  export { APIError, BetterCallError, ClientOptions, HasRequired, RequiredOptionKeys, Status, ValidationError, createClient, hideInternalStackFrames, kAPIErrorHeaderSymbol, makeErrorForHideStackFrame, statusCodes };
53
49
  //# sourceMappingURL=client.d.cts.map
package/dist/client.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { HasRequiredKeys, UnionToIntersection } from "./helper.mjs";
2
1
  import { APIError, BetterCallError, Status, ValidationError, hideInternalStackFrames, kAPIErrorHeaderSymbol, makeErrorForHideStackFrame, statusCodes } from "./error.mjs";
2
+ import { HasRequiredKeys, Prettify, UnionToIntersection } from "./helper.mjs";
3
3
  import { Endpoint } from "./endpoint.mjs";
4
4
  import { Router } from "./router.mjs";
5
5
  import { BetterFetchOption, BetterFetchResponse } from "@better-fetch/fetch";
@@ -15,22 +15,18 @@ interface ClientOptions extends BetterFetchOption {
15
15
  baseURL?: string;
16
16
  }
17
17
  type WithRequired<T, K> = T & { [P in K extends string ? K : never]-?: T[P extends keyof T ? P : never] };
18
- type InferClientRoutes<T extends Record<string, Endpoint>> = { [K in keyof T]: T[K] extends Endpoint<any, infer O> ? O extends {
19
- metadata: {
20
- scope: "http";
21
- };
18
+ /**
19
+ * Filter out endpoints that should not be exposed to the client.
20
+ * Checks the typed metadata on the Endpoint's options.
21
+ */
22
+ type InferClientRoutes<T extends Record<string, Endpoint>> = { [K in keyof T]: T[K] extends Endpoint<any, any, any, any, any, any, infer Meta> ? Meta extends {
23
+ scope: "http";
22
24
  } | {
23
- metadata: {
24
- scope: "server";
25
- };
25
+ scope: "server";
26
26
  } | {
27
- metadata: {
28
- SERVER_ONLY: true;
29
- };
27
+ SERVER_ONLY: true;
30
28
  } | {
31
- metadata: {
32
- isAction: false;
33
- };
29
+ isAction: false;
34
30
  } ? never : T[K] : T[K] };
35
31
  type RequiredOptionKeys<C extends {
36
32
  body?: any;
@@ -43,11 +39,11 @@ type RequiredOptionKeys<C extends {
43
39
  }) & (undefined extends C["params"] ? {} : {
44
40
  params: true;
45
41
  });
46
- declare const createClient: <R extends Router | Router["endpoints"]>(options?: ClientOptions) => <OPT extends (UnionToIntersection<InferClientRoutes<R extends {
42
+ declare const createClient: <R extends Router | Router["endpoints"]>(options?: ClientOptions) => <OPT extends Prettify<UnionToIntersection<InferClientRoutes<R extends {
47
43
  endpoints: Record<string, Endpoint>;
48
44
  } ? R["endpoints"] : R> extends {
49
- [key: string]: infer T_1;
50
- } ? T_1 extends Endpoint ? { [key in T_1["options"]["method"] extends "GET" ? T_1["path"] : `@${T_1["options"]["method"] extends string ? Lowercase<T_1["options"]["method"]> : never}${T_1["path"]}`]: T_1 } : {} : {}> extends infer T ? { [K_1 in keyof T]: T[K_1] } : never), K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<BetterFetchOption<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>] : [BetterFetchOption<C["body"], C["query"], C["params"]>?]) => Promise<BetterFetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
45
+ [key: string]: infer T;
46
+ } ? T extends Endpoint<infer P extends string, infer M> ? { [key in M extends "GET" ? P : `@${M extends string ? Lowercase<M> : never}${P}`]: T } : {} : {}>>, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequired<C> extends true ? [WithRequired<BetterFetchOption<C["body"], C["query"], C["params"]>, keyof RequiredOptionKeys<C>>] : [BetterFetchOption<C["body"], C["query"], C["params"]>?]) => Promise<BetterFetchResponse<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>>;
51
47
  //#endregion
52
48
  export { APIError, BetterCallError, ClientOptions, HasRequired, RequiredOptionKeys, Status, ValidationError, createClient, hideInternalStackFrames, kAPIErrorHeaderSymbol, makeErrorForHideStackFrame, statusCodes };
53
49
  //# sourceMappingURL=client.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n\ttype BetterFetchOption,\n\ttype BetterFetchResponse,\n\tcreateFetch,\n} from \"@better-fetch/fetch\";\nimport type { Router } from \"./router\";\nimport type { HasRequiredKeys, Prettify, UnionToIntersection } from \"./helper\";\nimport type { Endpoint } from \"./endpoint\";\n\nexport type HasRequired<T extends object> = T extends {}\n\t? false\n\t: T extends {\n\t\t\t\tbody?: any;\n\t\t\t\tquery?: any;\n\t\t\t\tparams?: any;\n\t\t\t}\n\t\t? T[\"body\"] extends object\n\t\t\t? HasRequiredKeys<T[\"body\"]> extends true\n\t\t\t\t? true\n\t\t\t\t: T[\"query\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t\t: false\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t: T[\"query\"] extends object\n\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t? true\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t: false\n\t\t: false;\n\ntype InferContext<T> = T extends (ctx: infer Ctx) => any\n\t? Ctx extends object\n\t\t? Ctx\n\t\t: never\n\t: never;\n\nexport interface ClientOptions extends BetterFetchOption {\n\tbaseURL?: string;\n}\n\ntype WithRequired<T, K> = T & {\n\t[P in K extends string ? K : never]-?: T[P extends keyof T ? P : never];\n};\n\ntype InferClientRoutes<T extends Record<string, Endpoint>> = {\n\t[K in keyof T]: T[K] extends Endpoint<any, infer O>\n\t\t? O extends\n\t\t\t\t| { metadata: { scope: \"http\" } }\n\t\t\t\t| { metadata: { scope: \"server\" } }\n\t\t\t\t| { metadata: { SERVER_ONLY: true } }\n\t\t\t\t| { metadata: { isAction: false } }\n\t\t\t? never\n\t\t\t: T[K]\n\t\t: T[K];\n};\n\nexport type RequiredOptionKeys<\n\tC extends {\n\t\tbody?: any;\n\t\tquery?: any;\n\t\tparams?: any;\n\t},\n> = (undefined extends C[\"body\"]\n\t? {}\n\t: {\n\t\t\tbody: true;\n\t\t}) &\n\t(undefined extends C[\"query\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tquery: true;\n\t\t\t}) &\n\t(undefined extends C[\"params\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tparams: true;\n\t\t\t});\n\nexport const createClient = <R extends Router | Router[\"endpoints\"]>(\n\toptions?: ClientOptions,\n) => {\n\tconst fetch = createFetch(options ?? {});\n\ttype API = InferClientRoutes<\n\t\tR extends { endpoints: Record<string, Endpoint> } ? R[\"endpoints\"] : R\n\t>;\n\ttype Options = API extends {\n\t\t[key: string]: infer T;\n\t}\n\t\t? T extends Endpoint\n\t\t\t? {\n\t\t\t\t\t[key in T[\"options\"][\"method\"] extends \"GET\"\n\t\t\t\t\t\t? T[\"path\"]\n\t\t\t\t\t\t: `@${T[\"options\"][\"method\"] extends string ? Lowercase<T[\"options\"][\"method\"]> : never}${T[\"path\"]}`]: T;\n\t\t\t\t}\n\t\t\t: {}\n\t\t: {};\n\n\ttype O = Prettify<UnionToIntersection<Options>>;\n\treturn async <\n\t\tOPT extends O,\n\t\tK extends keyof OPT,\n\t\tC extends InferContext<OPT[K]>,\n\t>(\n\t\tpath: K,\n\t\t...options: HasRequired<C> extends true\n\t\t\t? [\n\t\t\t\t\tWithRequired<\n\t\t\t\t\t\tBetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>,\n\t\t\t\t\t\tkeyof RequiredOptionKeys<C>\n\t\t\t\t\t>,\n\t\t\t\t]\n\t\t\t: [BetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>?]\n\t): Promise<\n\t\tBetterFetchResponse<\n\t\t\tAwaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>\n\t\t>\n\t> => {\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t})) as any;\n\t};\n};\n\nexport * from \"./error\";\n"],"mappings":";;;;AAuFA,MAAa,gBACZ,YACI;CACJ,MAAM,QAAQ,YAAY,WAAW,EAAE,CAAC;AAiBxC,QAAO,OAKN,MACA,GAAG,YAYC;AACJ,SAAQ,MAAM,MAAM,MAAgB,EACnC,GAAG,QAAQ,IACX,CAAC"}
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n\ttype BetterFetchOption,\n\ttype BetterFetchResponse,\n\tcreateFetch,\n} from \"@better-fetch/fetch\";\nimport type { Endpoint } from \"./endpoint\";\nimport type { HasRequiredKeys, Prettify, UnionToIntersection } from \"./helper\";\nimport type { Router } from \"./router\";\n\nexport type HasRequired<T extends object> = T extends {}\n\t? false\n\t: T extends {\n\t\t\t\tbody?: any;\n\t\t\t\tquery?: any;\n\t\t\t\tparams?: any;\n\t\t\t}\n\t\t? T[\"body\"] extends object\n\t\t\t? HasRequiredKeys<T[\"body\"]> extends true\n\t\t\t\t? true\n\t\t\t\t: T[\"query\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t\t? true\n\t\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t\t: false\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t: T[\"query\"] extends object\n\t\t\t\t? HasRequiredKeys<T[\"query\"]> extends true\n\t\t\t\t\t? true\n\t\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t\t: false\n\t\t\t\t: T[\"params\"] extends object\n\t\t\t\t\t? HasRequiredKeys<T[\"params\"]>\n\t\t\t\t\t: false\n\t\t: false;\n\ntype InferContext<T> = T extends (ctx: infer Ctx) => any\n\t? Ctx extends object\n\t\t? Ctx\n\t\t: never\n\t: never;\n\nexport interface ClientOptions extends BetterFetchOption {\n\tbaseURL?: string;\n}\n\ntype WithRequired<T, K> = T & {\n\t[P in K extends string ? K : never]-?: T[P extends keyof T ? P : never];\n};\n\n/**\n * Filter out endpoints that should not be exposed to the client.\n * Checks the typed metadata on the Endpoint's options.\n */\ntype InferClientRoutes<T extends Record<string, Endpoint>> = {\n\t[K in keyof T]: T[K] extends Endpoint<\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tany,\n\t\tinfer Meta\n\t>\n\t\t? Meta extends\n\t\t\t\t| { scope: \"http\" }\n\t\t\t\t| { scope: \"server\" }\n\t\t\t\t| { SERVER_ONLY: true }\n\t\t\t\t| { isAction: false }\n\t\t\t? never\n\t\t\t: T[K]\n\t\t: T[K];\n};\n\nexport type RequiredOptionKeys<\n\tC extends {\n\t\tbody?: any;\n\t\tquery?: any;\n\t\tparams?: any;\n\t},\n> = (undefined extends C[\"body\"]\n\t? {}\n\t: {\n\t\t\tbody: true;\n\t\t}) &\n\t(undefined extends C[\"query\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tquery: true;\n\t\t\t}) &\n\t(undefined extends C[\"params\"]\n\t\t? {}\n\t\t: {\n\t\t\t\tparams: true;\n\t\t\t});\n\nexport const createClient = <R extends Router | Router[\"endpoints\"]>(\n\toptions?: ClientOptions,\n) => {\n\tconst fetch = createFetch(options ?? {});\n\ttype API = InferClientRoutes<\n\t\tR extends { endpoints: Record<string, Endpoint> } ? R[\"endpoints\"] : R\n\t>;\n\ttype Options = API extends {\n\t\t[key: string]: infer T;\n\t}\n\t\t? T extends Endpoint<infer P, infer M>\n\t\t\t? {\n\t\t\t\t\t[key in M extends \"GET\"\n\t\t\t\t\t\t? P\n\t\t\t\t\t\t: `@${M extends string ? Lowercase<M> : never}${P}`]: T;\n\t\t\t\t}\n\t\t\t: {}\n\t\t: {};\n\n\ttype O = Prettify<UnionToIntersection<Options>>;\n\treturn async <\n\t\tOPT extends O,\n\t\tK extends keyof OPT,\n\t\tC extends InferContext<OPT[K]>,\n\t>(\n\t\tpath: K,\n\t\t...options: HasRequired<C> extends true\n\t\t\t? [\n\t\t\t\t\tWithRequired<\n\t\t\t\t\t\tBetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>,\n\t\t\t\t\t\tkeyof RequiredOptionKeys<C>\n\t\t\t\t\t>,\n\t\t\t\t]\n\t\t\t: [BetterFetchOption<C[\"body\"], C[\"query\"], C[\"params\"]>?]\n\t): Promise<\n\t\tBetterFetchResponse<\n\t\t\tAwaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>\n\t\t>\n\t> => {\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t})) as any;\n\t};\n};\n\nexport * from \"./error\";\n"],"mappings":";;;;AAmGA,MAAa,gBACZ,YACI;CACJ,MAAM,QAAQ,YAAY,WAAW,EAAE,CAAC;AAiBxC,QAAO,OAKN,MACA,GAAG,YAYC;AACJ,SAAQ,MAAM,MAAM,MAAgB,EACnC,GAAG,QAAQ,IACX,CAAC"}
package/dist/context.cjs CHANGED
@@ -1,13 +1,18 @@
1
+ const require_crypto = require('./crypto.cjs');
1
2
  const require_error = require('./error.cjs');
2
3
  const require_utils = require('./utils.cjs');
3
- const require_validator = require('./validator.cjs');
4
- const require_crypto = require('./crypto.cjs');
5
4
  const require_cookies = require('./cookies.cjs');
5
+ const require_validator = require('./validator.cjs');
6
6
 
7
7
  //#region src/context.ts
8
+ /**
9
+ * Creates the internal context for an endpoint or middleware invocation.
10
+ * This is the runtime function that does validation, cookie handling,
11
+ * middleware execution, etc.
12
+ */
8
13
  const createInternalContext = async (context, { options, path }) => {
9
14
  const headers = new Headers();
10
- let responseStatus = void 0;
15
+ let responseStatus;
11
16
  const { data, error } = await require_validator.runValidation(options, context);
12
17
  if (error) throw new require_error.ValidationError(error.message, error.issues);
13
18
  const requestHeaders = "headers" in context ? context.headers instanceof Headers ? context.headers : new Headers(context.headers) : "request" in context && require_utils.isRequest(context.request) ? context.request.headers : null;
@@ -19,7 +24,6 @@ const createInternalContext = async (context, { options, path }) => {
19
24
  query: data.query,
20
25
  path: context.path || path || "virtual:",
21
26
  context: "context" in context && context.context ? context.context : {},
22
- returned: void 0,
23
27
  headers: context?.headers,
24
28
  request: context?.request,
25
29
  params: "params" in context ? context.params : void 0,
@@ -76,10 +80,10 @@ const createInternalContext = async (context, { options, path }) => {
76
80
  _flag: "json"
77
81
  };
78
82
  },
79
- responseHeaders: headers,
80
83
  get responseStatus() {
81
84
  return responseStatus;
82
- }
85
+ },
86
+ responseHeaders: headers
83
87
  };
84
88
  for (const middleware of options.use || []) {
85
89
  const response = await middleware({
@@ -88,9 +92,6 @@ const createInternalContext = async (context, { options, path }) => {
88
92
  asResponse: false
89
93
  });
90
94
  if (response.response) Object.assign(internalContext.context, response.response);
91
- /**
92
- * Apply headers from the middleware to the endpoint headers
93
- */
94
95
  if (response.headers) response.headers.forEach((value, key) => {
95
96
  internalContext.responseHeaders.set(key, value);
96
97
  });
@@ -1 +1 @@
1
- {"version":3,"file":"context.cjs","names":["runValidation","ValidationError","isRequest","parseCookies","getCookieKey","verifySignature","getCryptoKey","serializeCookie","serializeSignedCookie","APIError"],"sources":["../src/context.ts"],"sourcesContent":["import type { EndpointOptions } from \"./endpoint\";\nimport {\n\ttype statusCodes,\n\tAPIError,\n\tValidationError,\n\ttype Status,\n} from \"./error\";\nimport type {\n\tInferParamPath,\n\tInferParamWildCard,\n\tIsEmptyObject,\n\tPrettify,\n\tUnionToIntersection,\n} from \"./helper\";\nimport type {\n\tMiddleware,\n\tMiddlewareContext,\n\tMiddlewareOptions,\n} from \"./middleware\";\nimport { runValidation } from \"./validator\";\nimport {\n\tgetCookieKey,\n\tparseCookies,\n\tserializeCookie,\n\tserializeSignedCookie,\n\ttype CookieOptions,\n\ttype CookiePrefixOptions,\n} from \"./cookies\";\nimport { getCryptoKey, verifySignature } from \"./crypto\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport { isRequest } from \"./utils\";\n\nexport type HTTPMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"PATCH\";\nexport type Method = HTTPMethod | \"*\";\n\nexport type InferBodyInput<\n\tOptions extends EndpointOptions | MiddlewareOptions,\n\tBody = Options[\"metadata\"] extends {\n\t\t$Infer: {\n\t\t\tbody: infer B;\n\t\t};\n\t}\n\t\t? B\n\t\t: Options[\"body\"] extends StandardSchemaV1\n\t\t\t? StandardSchemaV1.InferInput<Options[\"body\"]>\n\t\t\t: undefined,\n> = undefined extends Body\n\t? {\n\t\t\tbody?: Body;\n\t\t}\n\t: {\n\t\t\tbody: Body;\n\t\t};\n\nexport type InferBody<Options extends EndpointOptions | MiddlewareOptions> =\n\tOptions[\"metadata\"] extends {\n\t\t$Infer: {\n\t\t\tbody: infer Body;\n\t\t};\n\t}\n\t\t? Body\n\t\t: Options[\"body\"] extends StandardSchemaV1\n\t\t\t? StandardSchemaV1.InferOutput<Options[\"body\"]>\n\t\t\t: any;\n\nexport type InferQueryInput<\n\tOptions extends EndpointOptions | MiddlewareOptions,\n\tQuery = Options[\"metadata\"] extends {\n\t\t$Infer: {\n\t\t\tquery: infer Query;\n\t\t};\n\t}\n\t\t? Query\n\t\t: Options[\"query\"] extends StandardSchemaV1\n\t\t\t? StandardSchemaV1.InferInput<Options[\"query\"]>\n\t\t\t: Record<string, any> | undefined,\n> = undefined extends Query\n\t? {\n\t\t\tquery?: Query;\n\t\t}\n\t: {\n\t\t\tquery: Query;\n\t\t};\n\nexport type InferQuery<Options extends EndpointOptions | MiddlewareOptions> =\n\tOptions[\"metadata\"] extends {\n\t\t$Infer: {\n\t\t\tquery: infer Query;\n\t\t};\n\t}\n\t\t? Query\n\t\t: Options[\"query\"] extends StandardSchemaV1\n\t\t\t? StandardSchemaV1.InferOutput<Options[\"query\"]>\n\t\t\t: Record<string, any> | undefined;\n\nexport type InferMethod<Options extends EndpointOptions> =\n\tOptions[\"method\"] extends Array<Method>\n\t\t? Options[\"method\"][number]\n\t\t: Options[\"method\"] extends \"*\"\n\t\t\t? HTTPMethod\n\t\t\t: Options[\"method\"];\n\nexport type InferInputMethod<\n\tOptions extends EndpointOptions,\n\tMethod = Options[\"method\"] extends Array<any>\n\t\t? Options[\"method\"][number] | undefined\n\t\t: Options[\"method\"] extends \"*\"\n\t\t\t? HTTPMethod\n\t\t\t: Options[\"method\"] | undefined,\n> = undefined extends Method\n\t? {\n\t\t\tmethod?: Method;\n\t\t}\n\t: {\n\t\t\tmethod: Method;\n\t\t};\n\nexport type InferParam<Path extends string> = [Path] extends [never]\n\t? Record<string, any> | undefined\n\t: IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true\n\t\t? Record<string, any> | undefined\n\t\t: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;\n\nexport type InferParamInput<Path extends string> = [Path] extends [never]\n\t? { params?: Record<string, any> }\n\t: IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true\n\t\t? {\n\t\t\t\tparams?: Record<string, any>;\n\t\t\t}\n\t\t: {\n\t\t\t\tparams: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;\n\t\t\t};\n\nexport type InferRequest<Option extends EndpointOptions | MiddlewareOptions> =\n\tOption[\"requireRequest\"] extends true ? Request : Request | undefined;\n\nexport type InferRequestInput<\n\tOption extends EndpointOptions | MiddlewareOptions,\n> = Option[\"requireRequest\"] extends true\n\t? {\n\t\t\trequest: Request;\n\t\t}\n\t: {\n\t\t\trequest?: Request;\n\t\t};\n\nexport type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> =\n\tOption[\"requireHeaders\"] extends true ? Headers : Headers | undefined;\n\nexport type InferHeadersInput<\n\tOption extends EndpointOptions | MiddlewareOptions,\n> = Option[\"requireHeaders\"] extends true\n\t? {\n\t\t\theaders: HeadersInit;\n\t\t}\n\t: {\n\t\t\theaders?: HeadersInit;\n\t\t};\n\nexport type InferUse<Opts extends EndpointOptions[\"use\"]> =\n\tOpts extends Middleware[]\n\t\t? UnionToIntersection<Awaited<ReturnType<Opts[number]>>>\n\t\t: {};\n\nexport type InferMiddlewareBody<Options extends MiddlewareOptions> =\n\tOptions[\"body\"] extends StandardSchemaV1<infer T> ? T : any;\n\nexport type InferMiddlewareQuery<Options extends MiddlewareOptions> =\n\tOptions[\"query\"] extends StandardSchemaV1<infer T>\n\t\t? T\n\t\t: Record<string, any> | undefined;\n\nexport type InputContext<\n\tPath extends string,\n\tOptions extends EndpointOptions,\n> = InferBodyInput<Options> &\n\tInferInputMethod<Options> &\n\tInferQueryInput<Options> &\n\tInferParamInput<Path> &\n\tInferRequestInput<Options> &\n\tInferHeadersInput<Options> & {\n\t\tasResponse?: boolean;\n\t\treturnHeaders?: boolean;\n\t\treturnStatus?: boolean;\n\t\tuse?: Middleware[];\n\t\tpath?: string;\n\t\tcontext?: Record<string, any>;\n\t};\n\nexport const createInternalContext = async (\n\tcontext: InputContext<any, any>,\n\t{\n\t\toptions,\n\t\tpath,\n\t}: {\n\t\toptions: EndpointOptions;\n\t\tpath?: string;\n\t},\n) => {\n\tconst headers = new Headers();\n\tlet responseStatus: Status | undefined = undefined;\n\n\tconst { data, error } = await runValidation(options, context);\n\tif (error) {\n\t\tthrow new ValidationError(error.message, error.issues);\n\t}\n\tconst requestHeaders: Headers | null =\n\t\t\"headers\" in context\n\t\t\t? context.headers instanceof Headers\n\t\t\t\t? context.headers\n\t\t\t\t: new Headers(context.headers)\n\t\t\t: \"request\" in context && isRequest(context.request)\n\t\t\t\t? context.request.headers\n\t\t\t\t: null;\n\tconst requestCookies = requestHeaders?.get(\"cookie\");\n\tconst parsedCookies = requestCookies\n\t\t? parseCookies(requestCookies)\n\t\t: undefined;\n\n\tconst internalContext = {\n\t\t...context,\n\t\tbody: data.body,\n\t\tquery: data.query,\n\t\tpath: context.path || path || \"virtual:\",\n\t\tcontext: \"context\" in context && context.context ? context.context : {},\n\t\treturned: undefined as any,\n\t\theaders: context?.headers,\n\t\trequest: context?.request,\n\t\tparams: \"params\" in context ? context.params : undefined,\n\t\tmethod:\n\t\t\tcontext.method ??\n\t\t\t(Array.isArray(options.method)\n\t\t\t\t? options.method[0]\n\t\t\t\t: options.method === \"*\"\n\t\t\t\t\t? \"GET\"\n\t\t\t\t\t: options.method),\n\t\tsetHeader: (key: string, value: string) => {\n\t\t\theaders.set(key, value);\n\t\t},\n\t\tgetHeader: (key: string) => {\n\t\t\tif (!requestHeaders) return null;\n\t\t\treturn requestHeaders.get(key);\n\t\t},\n\t\tgetCookie: (key: string, prefix?: CookiePrefixOptions) => {\n\t\t\tconst finalKey = getCookieKey(key, prefix);\n\t\t\tif (!finalKey) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn parsedCookies?.get(finalKey) || null;\n\t\t},\n\t\tgetSignedCookie: async (\n\t\t\tkey: string,\n\t\t\tsecret: string,\n\t\t\tprefix?: CookiePrefixOptions,\n\t\t) => {\n\t\t\tconst finalKey = getCookieKey(key, prefix);\n\t\t\tif (!finalKey) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst value = parsedCookies?.get(finalKey);\n\t\t\tif (!value) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst signatureStartPos = value.lastIndexOf(\".\");\n\t\t\tif (signatureStartPos < 1) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst signedValue = value.substring(0, signatureStartPos);\n\t\t\tconst signature = value.substring(signatureStartPos + 1);\n\t\t\tif (signature.length !== 44 || !signature.endsWith(\"=\")) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst secretKey = await getCryptoKey(secret);\n\t\t\tconst isVerified = await verifySignature(\n\t\t\t\tsignature,\n\t\t\t\tsignedValue,\n\t\t\t\tsecretKey,\n\t\t\t);\n\t\t\treturn isVerified ? signedValue : false;\n\t\t},\n\t\tsetCookie: (key: string, value: string, options?: CookieOptions) => {\n\t\t\tconst cookie = serializeCookie(key, value, options);\n\t\t\theaders.append(\"set-cookie\", cookie);\n\t\t\treturn cookie;\n\t\t},\n\t\tsetSignedCookie: async (\n\t\t\tkey: string,\n\t\t\tvalue: string,\n\t\t\tsecret: string,\n\t\t\toptions?: CookieOptions,\n\t\t) => {\n\t\t\tconst cookie = await serializeSignedCookie(key, value, secret, options);\n\t\t\theaders.append(\"set-cookie\", cookie);\n\t\t\treturn cookie;\n\t\t},\n\t\tredirect: (url: string) => {\n\t\t\theaders.set(\"location\", url);\n\t\t\treturn new APIError(\"FOUND\", undefined, headers);\n\t\t},\n\t\terror: (\n\t\t\tstatus: keyof typeof statusCodes | Status,\n\t\t\tbody?:\n\t\t\t\t| {\n\t\t\t\t\t\tmessage?: string;\n\t\t\t\t\t\tcode?: string;\n\t\t\t\t }\n\t\t\t\t| undefined,\n\t\t\theaders?: HeadersInit,\n\t\t) => {\n\t\t\treturn new APIError(status, body, headers);\n\t\t},\n\t\tsetStatus: (status: Status) => {\n\t\t\tresponseStatus = status;\n\t\t},\n\t\tjson: (\n\t\t\tjson: Record<string, any>,\n\t\t\trouterResponse?:\n\t\t\t\t| {\n\t\t\t\t\t\tstatus?: number;\n\t\t\t\t\t\theaders?: Record<string, string>;\n\t\t\t\t\t\tresponse?: Response;\n\t\t\t\t\t\tbody?: Record<string, any>;\n\t\t\t\t }\n\t\t\t\t| Response,\n\t\t) => {\n\t\t\tif (!context.asResponse) {\n\t\t\t\treturn json;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tbody: routerResponse?.body || json,\n\t\t\t\trouterResponse,\n\t\t\t\t_flag: \"json\",\n\t\t\t};\n\t\t},\n\t\tresponseHeaders: headers,\n\t\tget responseStatus() {\n\t\t\treturn responseStatus;\n\t\t},\n\t};\n\t//if context was shimmed through the input we want to apply it\n\tfor (const middleware of options.use || []) {\n\t\tconst response = (await middleware({\n\t\t\t...internalContext,\n\t\t\treturnHeaders: true,\n\t\t\tasResponse: false,\n\t\t})) as {\n\t\t\tresponse?: any;\n\t\t\theaders?: Headers;\n\t\t};\n\t\tif (response.response) {\n\t\t\tObject.assign(internalContext.context, response.response);\n\t\t}\n\t\t/**\n\t\t * Apply headers from the middleware to the endpoint headers\n\t\t */\n\t\tif (response.headers) {\n\t\t\tresponse.headers.forEach((value, key) => {\n\t\t\t\tinternalContext.responseHeaders.set(key, value);\n\t\t\t});\n\t\t}\n\t}\n\treturn internalContext;\n};\n"],"mappings":";;;;;;;AA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QAAQ;AACxC,mBAAgB,gBAAgB,IAAI,KAAK,MAAM;IAC9C;;AAGJ,QAAO"}
1
+ {"version":3,"file":"context.cjs","names":["runValidation","ValidationError","isRequest","parseCookies","getCookieKey","verifySignature","getCryptoKey","serializeCookie","serializeSignedCookie","APIError"],"sources":["../src/context.ts"],"sourcesContent":["import type { CookieOptions, CookiePrefixOptions } from \"./cookies\";\nimport {\n\tgetCookieKey,\n\tparseCookies,\n\tserializeCookie,\n\tserializeSignedCookie,\n} from \"./cookies\";\nimport { getCryptoKey, verifySignature } from \"./crypto\";\nimport {\n\tAPIError,\n\ttype Status,\n\ttype statusCodes,\n\tValidationError,\n} from \"./error\";\nimport type { Prettify } from \"./helper\";\nimport type { Middleware, MiddlewareContext } from \"./middleware\";\nimport type { StandardSchemaV1 } from \"./standard-schema\";\nimport type {\n\tInferParam,\n\tInferUse,\n\tResolveBody,\n\tResolveMethod,\n\tResolveQuery,\n} from \"./types\";\nimport { isRequest } from \"./utils\";\nimport { runValidation } from \"./validator\";\n\nexport type EndpointContext<\n\tPath extends string,\n\tM,\n\tBodySchema extends object | undefined,\n\tQuerySchema extends object | undefined,\n\tUse extends Middleware[],\n\tReqHeaders extends boolean,\n\tReqRequest extends boolean,\n\tContext = {},\n\tMeta = undefined,\n> = {\n\t/**\n\t * Method\n\t *\n\t * The request method\n\t */\n\tmethod: ResolveMethod<M>;\n\t/**\n\t * Path\n\t *\n\t * The path of the endpoint\n\t */\n\tpath: Path;\n\t/**\n\t * Body\n\t *\n\t * The body object will be the parsed JSON from the request and validated\n\t * against the body schema if it exists.\n\t */\n\tbody: ResolveBody<BodySchema, Meta>;\n\t/**\n\t * Query\n\t *\n\t * The query object will be the parsed query string from the request\n\t * and validated against the query schema if it exists\n\t */\n\tquery: ResolveQuery<QuerySchema, Meta>;\n\t/**\n\t * Params\n\t *\n\t * If the path is `/user/:id` and the request is `/user/1` then the params will\n\t * be `{ id: \"1\" }` and if the path includes a wildcard like `/user/*` then the\n\t * params will be `{ _: \"1\" }` where `_` is the wildcard key. If the wildcard\n\t * is named like `/user/**:name` then the params will be `{ name: string }`\n\t */\n\tparams: InferParam<Path>;\n\t/**\n\t * Request object\n\t *\n\t * If `requireRequest` is set to true in the endpoint options this will be\n\t * required\n\t */\n\trequest: ReqRequest extends true ? Request : Request | undefined;\n\t/**\n\t * Headers\n\t *\n\t * If `requireHeaders` is set to true in the endpoint options this will be\n\t * required\n\t */\n\theaders: ReqHeaders extends true ? Headers : Headers | undefined;\n\t/**\n\t * Set header\n\t *\n\t * If it's called outside of a request it will just be ignored.\n\t */\n\tsetHeader: (key: string, value: string) => void;\n\t/**\n\t * Set the response status code\n\t */\n\tsetStatus: (status: Status) => void;\n\t/**\n\t * Get header\n\t *\n\t * If it's called outside of a request it will just return null\n\t *\n\t * @param key - The key of the header\n\t */\n\tgetHeader: (key: string) => string | null;\n\t/**\n\t * Get a cookie value from the request\n\t *\n\t * @param key - The key of the cookie\n\t * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`\n\t * @returns The value of the cookie\n\t */\n\tgetCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;\n\t/**\n\t * Get a signed cookie value from the request\n\t *\n\t * @param key - The key of the cookie\n\t * @param secret - The secret of the signed cookie\n\t * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`\n\t * @returns The value of the cookie or null if the cookie is not found or false if the signature is invalid\n\t */\n\tgetSignedCookie: (\n\t\tkey: string,\n\t\tsecret: string,\n\t\tprefix?: CookiePrefixOptions,\n\t) => Promise<string | null | false>;\n\t/**\n\t * Set a cookie value in the response\n\t *\n\t * @param key - The key of the cookie\n\t * @param value - The value to set\n\t * @param options - The options of the cookie\n\t * @returns The cookie string\n\t */\n\tsetCookie: (key: string, value: string, options?: CookieOptions) => string;\n\t/**\n\t * Set signed cookie\n\t *\n\t * @param key - The key of the cookie\n\t * @param value - The value to set\n\t * @param secret - The secret to sign the cookie with\n\t * @param options - The options of the cookie\n\t * @returns The cookie string\n\t */\n\tsetSignedCookie: (\n\t\tkey: string,\n\t\tvalue: string,\n\t\tsecret: string,\n\t\toptions?: CookieOptions,\n\t) => Promise<string>;\n\t/**\n\t * JSON\n\t *\n\t * A helper function to create a JSON response with the correct headers\n\t * and status code. If `asResponse` is set to true in the context then\n\t * it will return a Response object instead of the JSON object.\n\t *\n\t * @param json - The JSON object to return\n\t * @param routerResponse - The response object to return if `asResponse` is\n\t * true in the context this will take precedence\n\t */\n\tjson: <R extends Record<string, any> | null>(\n\t\tjson: R,\n\t\trouterResponse?:\n\t\t\t| {\n\t\t\t\t\tstatus?: number;\n\t\t\t\t\theaders?: Record<string, string>;\n\t\t\t\t\tresponse?: Response;\n\t\t\t\t\tbody?: Record<string, any>;\n\t\t\t }\n\t\t\t| Response,\n\t) => R;\n\t/**\n\t * Middleware context\n\t */\n\tcontext: 0 extends 1 & Use\n\t\t? Prettify<Context>\n\t\t: Prettify<Context & InferUse<Use>>;\n\t/**\n\t * Redirect to a new URL\n\t */\n\tredirect: (url: string) => APIError;\n\t/**\n\t * Return error\n\t */\n\terror: (\n\t\tstatus: keyof typeof statusCodes | Status,\n\t\tbody?: {\n\t\t\tmessage?: string;\n\t\t\tcode?: string;\n\t\t} & Record<string, any>,\n\t\theaders?: HeadersInit,\n\t) => APIError;\n};\n\n/**\n * Creates the internal context for an endpoint or middleware invocation.\n * This is the runtime function that does validation, cookie handling,\n * middleware execution, etc.\n */\nexport const createInternalContext = async (\n\tcontext: Record<string, any>,\n\t{\n\t\toptions,\n\t\tpath,\n\t}: {\n\t\toptions: {\n\t\t\tmethod?: string | string[];\n\t\t\tbody?: StandardSchemaV1;\n\t\t\tquery?: StandardSchemaV1;\n\t\t\trequireHeaders?: boolean;\n\t\t\trequireRequest?: boolean;\n\t\t\tuse?: Middleware[];\n\t\t\t[key: string]: any;\n\t\t};\n\t\tpath?: string;\n\t},\n) => {\n\tconst headers = new Headers();\n\tlet responseStatus: Status | undefined;\n\n\tconst { data, error } = await runValidation(options as any, context as any);\n\tif (error) {\n\t\tthrow new ValidationError(error.message, error.issues);\n\t}\n\n\tconst requestHeaders: Headers | null =\n\t\t\"headers\" in context\n\t\t\t? context.headers instanceof Headers\n\t\t\t\t? context.headers\n\t\t\t\t: new Headers(context.headers)\n\t\t\t: \"request\" in context && isRequest(context.request)\n\t\t\t\t? context.request.headers\n\t\t\t\t: null;\n\n\tconst requestCookies = requestHeaders?.get(\"cookie\");\n\tconst parsedCookies = requestCookies\n\t\t? parseCookies(requestCookies)\n\t\t: undefined;\n\n\tconst internalContext = {\n\t\t...context,\n\t\tbody: data.body,\n\t\tquery: data.query,\n\t\tpath: context.path || path || \"virtual:\",\n\t\tcontext: \"context\" in context && context.context ? context.context : {},\n\t\theaders: context?.headers,\n\t\trequest: context?.request,\n\t\tparams: \"params\" in context ? context.params : undefined,\n\t\tmethod:\n\t\t\tcontext.method ??\n\t\t\t(Array.isArray(options.method)\n\t\t\t\t? options.method[0]\n\t\t\t\t: options.method === \"*\"\n\t\t\t\t\t? \"GET\"\n\t\t\t\t\t: options.method),\n\t\tsetHeader: (key: string, value: string) => {\n\t\t\theaders.set(key, value);\n\t\t},\n\t\tgetHeader: (key: string) => {\n\t\t\tif (!requestHeaders) return null;\n\t\t\treturn requestHeaders.get(key);\n\t\t},\n\t\tgetCookie: (key: string, prefix?: CookiePrefixOptions) => {\n\t\t\tconst finalKey = getCookieKey(key, prefix);\n\t\t\tif (!finalKey) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn parsedCookies?.get(finalKey) || null;\n\t\t},\n\t\tgetSignedCookie: async (\n\t\t\tkey: string,\n\t\t\tsecret: string,\n\t\t\tprefix?: CookiePrefixOptions,\n\t\t) => {\n\t\t\tconst finalKey = getCookieKey(key, prefix);\n\t\t\tif (!finalKey) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst value = parsedCookies?.get(finalKey);\n\t\t\tif (!value) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst signatureStartPos = value.lastIndexOf(\".\");\n\t\t\tif (signatureStartPos < 1) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst signedValue = value.substring(0, signatureStartPos);\n\t\t\tconst signature = value.substring(signatureStartPos + 1);\n\t\t\tif (signature.length !== 44 || !signature.endsWith(\"=\")) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst secretKey = await getCryptoKey(secret);\n\t\t\tconst isVerified = await verifySignature(\n\t\t\t\tsignature,\n\t\t\t\tsignedValue,\n\t\t\t\tsecretKey,\n\t\t\t);\n\t\t\treturn isVerified ? signedValue : false;\n\t\t},\n\t\tsetCookie: (key: string, value: string, options?: CookieOptions) => {\n\t\t\tconst cookie = serializeCookie(key, value, options);\n\t\t\theaders.append(\"set-cookie\", cookie);\n\t\t\treturn cookie;\n\t\t},\n\t\tsetSignedCookie: async (\n\t\t\tkey: string,\n\t\t\tvalue: string,\n\t\t\tsecret: string,\n\t\t\toptions?: CookieOptions,\n\t\t) => {\n\t\t\tconst cookie = await serializeSignedCookie(key, value, secret, options);\n\t\t\theaders.append(\"set-cookie\", cookie);\n\t\t\treturn cookie;\n\t\t},\n\t\tredirect: (url: string) => {\n\t\t\theaders.set(\"location\", url);\n\t\t\treturn new APIError(\"FOUND\", undefined, headers);\n\t\t},\n\t\terror: (\n\t\t\tstatus: keyof typeof statusCodes | Status,\n\t\t\tbody?:\n\t\t\t\t| {\n\t\t\t\t\t\tmessage?: string;\n\t\t\t\t\t\tcode?: string;\n\t\t\t\t }\n\t\t\t\t| undefined,\n\t\t\theaders?: HeadersInit,\n\t\t) => {\n\t\t\treturn new APIError(status, body, headers);\n\t\t},\n\t\tsetStatus: (status: Status) => {\n\t\t\tresponseStatus = status;\n\t\t},\n\t\tjson: <R extends Record<string, any> | null>(\n\t\t\tjson: R,\n\t\t\trouterResponse?:\n\t\t\t\t| {\n\t\t\t\t\t\tstatus?: number;\n\t\t\t\t\t\theaders?: Record<string, string>;\n\t\t\t\t\t\tresponse?: Response;\n\t\t\t\t\t\tbody?: Record<string, any>;\n\t\t\t\t }\n\t\t\t\t| Response,\n\t\t): R => {\n\t\t\tif (!context.asResponse) {\n\t\t\t\treturn json;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tbody: routerResponse?.body || json,\n\t\t\t\trouterResponse,\n\t\t\t\t_flag: \"json\",\n\t\t\t} as any;\n\t\t},\n\t\tget responseStatus() {\n\t\t\treturn responseStatus;\n\t\t},\n\t\tresponseHeaders: headers,\n\t} satisfies MiddlewareContext<any>;\n\n\t// Execute middleware chain\n\tfor (const middleware of options.use || []) {\n\t\tconst response = (await middleware({\n\t\t\t...internalContext,\n\t\t\treturnHeaders: true,\n\t\t\tasResponse: false,\n\t\t})) as {\n\t\t\tresponse?: any;\n\t\t\theaders?: Headers;\n\t\t};\n\t\tif (response.response) {\n\t\t\tObject.assign(internalContext.context, response.response);\n\t\t}\n\t\tif (response.headers) {\n\t\t\tresponse.headers.forEach((value, key) => {\n\t\t\t\tinternalContext.responseHeaders.set(key, value);\n\t\t\t});\n\t\t}\n\t}\n\n\treturn internalContext;\n};\n"],"mappings":";;;;;;;;;;;;AAwMA,MAAa,wBAAwB,OACpC,SACA,EACC,SACA,WAaG;CACJ,MAAM,UAAU,IAAI,SAAS;CAC7B,IAAI;CAEJ,MAAM,EAAE,MAAM,UAAU,MAAMA,gCAAc,SAAgB,QAAe;AAC3E,KAAI,MACH,OAAM,IAAIC,8BAAgB,MAAM,SAAS,MAAM,OAAO;CAGvD,MAAM,iBACL,aAAa,UACV,QAAQ,mBAAmB,UAC1B,QAAQ,UACR,IAAI,QAAQ,QAAQ,QAAQ,GAC7B,aAAa,WAAWC,wBAAU,QAAQ,QAAQ,GACjD,QAAQ,QAAQ,UAChB;CAEL,MAAM,iBAAiB,gBAAgB,IAAI,SAAS;CACpD,MAAM,gBAAgB,iBACnBC,6BAAa,eAAe,GAC5B;CAEH,MAAM,kBAAkB;EACvB,GAAG;EACH,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,MAAM,QA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