better-call 0.0.5-beta.17 → 0.0.5-beta.19

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/client.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var a=(t,e)=>{for(var r in e)o(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of d(e))!y.call(t,n)&&n!==r&&o(t,n,{get:()=>e[n],enumerable:!(s=p(e,n))||s.enumerable});return t};var u=t=>x(o({},"__esModule",{value:!0}),t);var c={};a(c,{createClient:()=>T});module.exports=u(c);var i=require("@better-fetch/fetch"),T=t=>{let e=(0,i.createFetch)(t);return async(r,...s)=>{let n=s[0];return await e(r,{...s[0],body:n.body,params:n.params})}};0&&(module.exports={createClient});
1
+ "use strict";var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var a=(t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})},x=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!y.call(t,n)&&n!==r&&s(t,n,{get:()=>e[n],enumerable:!(o=d(e,n))||o.enumerable});return t};var u=t=>x(s({},"__esModule",{value:!0}),t);var c={};a(c,{createClient:()=>T});module.exports=u(c);var i=require("@better-fetch/fetch"),T=t=>{let e=(0,i.createFetch)(t);return async(r,...o)=>{let n=o[0];return await e(r,{...o[0],body:n.body,params:n.params})}};0&&(module.exports={createClient});
2
2
  //# sourceMappingURL=client.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { Endpoint, Prettify } from \"./types\";\nimport type { HasRequiredKeys, UnionToIntersection } from \"type-fest\";\nimport { type BetterFetchOption, type BetterFetchResponse, createFetch } from \"@better-fetch/fetch\";\nimport type { Router } from \"./router\";\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\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>(options: ClientOptions) => {\n\tconst fetch = createFetch(options);\n\ttype API = R[\"endpoints\"];\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 <OPT extends O, K extends keyof OPT, C extends InferContext<OPT[K]>>(\n\t\tpath: K,\n\t\t...options: HasRequiredKeys<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<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>\n\t> => {\n\t\tconst opts = options[0] as {\n\t\t\tparams?: Record<string, any>;\n\t\t\tbody?: Record<string, any>;\n\t\t};\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t\tbody: opts.body,\n\t\t\tparams: opts.params,\n\t\t})) as any;\n\t};\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAA8E,+BAuCjEF,EAAkCG,GAA2B,CACzE,IAAMC,KAAQ,eAAYD,CAAO,EAejC,MAAO,OACNE,KACGF,IAUC,CACJ,IAAMG,EAAOH,EAAQ,CAAC,EAItB,OAAQ,MAAMC,EAAMC,EAAgB,CACnC,GAAGF,EAAQ,CAAC,EACZ,KAAMG,EAAK,KACX,OAAQA,EAAK,MACd,CAAC,CACF,CACD","names":["client_exports","__export","createClient","__toCommonJS","import_fetch","options","fetch","path","opts"]}
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { Endpoint, Prettify } from \"./types\";\nimport type { HasRequiredKeys, UnionToIntersection } from \"type-fest\";\nimport { type BetterFetchOption, type BetterFetchResponse, createFetch } from \"@better-fetch/fetch\";\nimport type { Router } from \"./router\";\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\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\"]>(options: ClientOptions) => {\n\tconst fetch = createFetch(options);\n\ttype API = R extends Router ? R[\"endpoints\"] : R;\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 <OPT extends O, K extends keyof OPT, C extends InferContext<OPT[K]>>(\n\t\tpath: K,\n\t\t...options: HasRequiredKeys<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<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>\n\t> => {\n\t\tconst opts = options[0] as {\n\t\t\tparams?: Record<string, any>;\n\t\t\tbody?: Record<string, any>;\n\t\t};\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t\tbody: opts.body,\n\t\t\tparams: opts.params,\n\t\t})) as any;\n\t};\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAA8E,+BAuCjEF,EAAwDG,GAA2B,CAC/F,IAAMC,KAAQ,eAAYD,CAAO,EAejC,MAAO,OACNE,KACGF,IAUC,CACJ,IAAMG,EAAOH,EAAQ,CAAC,EAItB,OAAQ,MAAMC,EAAMC,EAAgB,CACnC,GAAGF,EAAQ,CAAC,EACZ,KAAMG,EAAK,KACX,OAAQA,EAAK,MACd,CAAC,CACF,CACD","names":["client_exports","__export","createClient","__toCommonJS","import_fetch","options","fetch","path","opts"]}
package/dist/client.d.cts CHANGED
@@ -21,9 +21,15 @@ type RequiredOptionKeys<C extends {
21
21
  }) & (undefined extends C["params"] ? {} : {
22
22
  params: true;
23
23
  });
24
- declare const createClient: <R extends Router>(options: ClientOptions) => <OPT extends UnionToIntersection<R["endpoints"] extends {
24
+ declare const createClient: <R extends Router | Router["endpoints"]>(options: ClientOptions) => <OPT extends UnionToIntersection<(R extends {
25
+ handler: (request: Request) => Promise<Response>;
26
+ endpoints: Record<string, Endpoint>;
27
+ } ? R["endpoints"] : R) extends {
25
28
  [key: string]: infer T_1;
26
- } ? T_1 extends Endpoint ? { [key_1 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 ? { [key in keyof T]: UnionToIntersection<R["endpoints"] extends {
29
+ } ? T_1 extends Endpoint ? { [key_1 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 ? { [key in keyof T]: UnionToIntersection<(R extends {
30
+ handler: (request: Request) => Promise<Response>;
31
+ endpoints: Record<string, Endpoint>;
32
+ } ? R["endpoints"] : R) extends {
27
33
  [key: string]: infer T_1;
28
34
  } ? T_1 extends Endpoint ? { [key_1 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; } : {} : {}>[key]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequiredKeys<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>>>>;
29
35
 
package/dist/client.d.ts CHANGED
@@ -21,9 +21,15 @@ type RequiredOptionKeys<C extends {
21
21
  }) & (undefined extends C["params"] ? {} : {
22
22
  params: true;
23
23
  });
24
- declare const createClient: <R extends Router>(options: ClientOptions) => <OPT extends UnionToIntersection<R["endpoints"] extends {
24
+ declare const createClient: <R extends Router | Router["endpoints"]>(options: ClientOptions) => <OPT extends UnionToIntersection<(R extends {
25
+ handler: (request: Request) => Promise<Response>;
26
+ endpoints: Record<string, Endpoint>;
27
+ } ? R["endpoints"] : R) extends {
25
28
  [key: string]: infer T_1;
26
- } ? T_1 extends Endpoint ? { [key_1 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 ? { [key in keyof T]: UnionToIntersection<R["endpoints"] extends {
29
+ } ? T_1 extends Endpoint ? { [key_1 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 ? { [key in keyof T]: UnionToIntersection<(R extends {
30
+ handler: (request: Request) => Promise<Response>;
31
+ endpoints: Record<string, Endpoint>;
32
+ } ? R["endpoints"] : R) extends {
27
33
  [key: string]: infer T_1;
28
34
  } ? T_1 extends Endpoint ? { [key_1 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; } : {} : {}>[key]; } : never, K extends keyof OPT, C extends InferContext<OPT[K]>>(path: K, ...options: HasRequiredKeys<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>>>>;
29
35
 
package/dist/client.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createFetch as o}from"@better-fetch/fetch";var p=n=>{let r=o(n);return async(s,...e)=>{let t=e[0];return await r(s,{...e[0],body:t.body,params:t.params})}};export{p as createClient};
1
+ import{createFetch as s}from"@better-fetch/fetch";var d=n=>{let r=s(n);return async(o,...e)=>{let t=e[0];return await r(o,{...e[0],body:t.body,params:t.params})}};export{d as createClient};
2
2
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { Endpoint, Prettify } from \"./types\";\nimport type { HasRequiredKeys, UnionToIntersection } from \"type-fest\";\nimport { type BetterFetchOption, type BetterFetchResponse, createFetch } from \"@better-fetch/fetch\";\nimport type { Router } from \"./router\";\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\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>(options: ClientOptions) => {\n\tconst fetch = createFetch(options);\n\ttype API = R[\"endpoints\"];\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 <OPT extends O, K extends keyof OPT, C extends InferContext<OPT[K]>>(\n\t\tpath: K,\n\t\t...options: HasRequiredKeys<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<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>\n\t> => {\n\t\tconst opts = options[0] as {\n\t\t\tparams?: Record<string, any>;\n\t\t\tbody?: Record<string, any>;\n\t\t};\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t\tbody: opts.body,\n\t\t\tparams: opts.params,\n\t\t})) as any;\n\t};\n};\n"],"mappings":"AAEA,OAA2D,eAAAA,MAAmB,sBAuCvE,IAAMC,EAAkCC,GAA2B,CACzE,IAAMC,EAAQH,EAAYE,CAAO,EAejC,MAAO,OACNE,KACGF,IAUC,CACJ,IAAMG,EAAOH,EAAQ,CAAC,EAItB,OAAQ,MAAMC,EAAMC,EAAgB,CACnC,GAAGF,EAAQ,CAAC,EACZ,KAAMG,EAAK,KACX,OAAQA,EAAK,MACd,CAAC,CACF,CACD","names":["createFetch","createClient","options","fetch","path","opts"]}
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import type { Endpoint, Prettify } from \"./types\";\nimport type { HasRequiredKeys, UnionToIntersection } from \"type-fest\";\nimport { type BetterFetchOption, type BetterFetchResponse, createFetch } from \"@better-fetch/fetch\";\nimport type { Router } from \"./router\";\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\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\"]>(options: ClientOptions) => {\n\tconst fetch = createFetch(options);\n\ttype API = R extends Router ? R[\"endpoints\"] : R;\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 <OPT extends O, K extends keyof OPT, C extends InferContext<OPT[K]>>(\n\t\tpath: K,\n\t\t...options: HasRequiredKeys<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<Awaited<ReturnType<OPT[K] extends Endpoint ? OPT[K] : never>>>\n\t> => {\n\t\tconst opts = options[0] as {\n\t\t\tparams?: Record<string, any>;\n\t\t\tbody?: Record<string, any>;\n\t\t};\n\t\treturn (await fetch(path as string, {\n\t\t\t...options[0],\n\t\t\tbody: opts.body,\n\t\t\tparams: opts.params,\n\t\t})) as any;\n\t};\n};\n"],"mappings":"AAEA,OAA2D,eAAAA,MAAmB,sBAuCvE,IAAMC,EAAwDC,GAA2B,CAC/F,IAAMC,EAAQH,EAAYE,CAAO,EAejC,MAAO,OACNE,KACGF,IAUC,CACJ,IAAMG,EAAOH,EAAQ,CAAC,EAItB,OAAQ,MAAMC,EAAMC,EAAgB,CACnC,GAAGF,EAAQ,CAAC,EACZ,KAAMG,EAAK,KACX,OAAQA,EAAK,MACd,CAAC,CACF,CACD","names":["createFetch","createClient","options","fetch","path","opts"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-call",
3
- "version": "0.0.5-beta.17",
3
+ "version": "0.0.5-beta.19",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -32,6 +32,11 @@
32
32
  "types": "./dist/index.d.ts",
33
33
  "import": "./dist/index.js",
34
34
  "require": "./dist/index.cjs"
35
+ },
36
+ "./client": {
37
+ "types": "./dist/client.d.ts",
38
+ "import": "./dist/client.js",
39
+ "require": "./dist/client.cjs"
35
40
  }
36
41
  },
37
42
  "files": [