@geekmidas/client 10.0.0-alpha.2 → 10.0.0-alpha.21

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 (103) hide show
  1. package/README.md +39 -57
  2. package/dist/auth-fetcher.cjs +78 -3
  3. package/dist/auth-fetcher.cjs.map +1 -0
  4. package/dist/auth-fetcher.d.cts +155 -3
  5. package/dist/auth-fetcher.d.cts.map +1 -0
  6. package/dist/auth-fetcher.d.mts +155 -3
  7. package/dist/auth-fetcher.d.mts.map +1 -0
  8. package/dist/auth-fetcher.mjs +77 -3
  9. package/dist/auth-fetcher.mjs.map +1 -0
  10. package/dist/endpoint-hooks.cjs +11 -15
  11. package/dist/endpoint-hooks.cjs.map +1 -1
  12. package/dist/endpoint-hooks.d.cts +4 -7
  13. package/dist/endpoint-hooks.d.cts.map +1 -1
  14. package/dist/endpoint-hooks.d.mts +4 -7
  15. package/dist/endpoint-hooks.d.mts.map +1 -1
  16. package/dist/endpoint-hooks.mjs +5 -9
  17. package/dist/endpoint-hooks.mjs.map +1 -1
  18. package/dist/fetcher.cjs +111 -3
  19. package/dist/fetcher.cjs.map +1 -0
  20. package/dist/fetcher.d.cts +23 -3
  21. package/dist/fetcher.d.cts.map +1 -0
  22. package/dist/fetcher.d.mts +23 -3
  23. package/dist/fetcher.d.mts.map +1 -0
  24. package/dist/fetcher.mjs +86 -2
  25. package/dist/fetcher.mjs.map +1 -0
  26. package/dist/index.cjs +9 -6
  27. package/dist/index.d.cts +6 -5
  28. package/dist/index.d.mts +6 -5
  29. package/dist/index.mjs +6 -6
  30. package/dist/infer.cjs +0 -1
  31. package/dist/infer.d.cts +130 -2
  32. package/dist/infer.d.cts.map +1 -0
  33. package/dist/infer.d.mts +130 -2
  34. package/dist/infer.d.mts.map +1 -0
  35. package/dist/infer.mjs +1 -1
  36. package/dist/methods.cjs +21 -0
  37. package/dist/methods.cjs.map +1 -0
  38. package/dist/methods.d.cts +23 -0
  39. package/dist/methods.d.cts.map +1 -0
  40. package/dist/methods.d.mts +23 -0
  41. package/dist/methods.d.mts.map +1 -0
  42. package/dist/methods.mjs +19 -0
  43. package/dist/methods.mjs.map +1 -0
  44. package/dist/openapi-hooks.cjs +13 -16
  45. package/dist/openapi-hooks.cjs.map +1 -1
  46. package/dist/openapi-hooks.d.cts +8 -11
  47. package/dist/openapi-hooks.d.cts.map +1 -1
  48. package/dist/openapi-hooks.d.mts +8 -11
  49. package/dist/openapi-hooks.d.mts.map +1 -1
  50. package/dist/openapi-hooks.mjs +9 -12
  51. package/dist/openapi-hooks.mjs.map +1 -1
  52. package/dist/openapi-types.d.cts +5 -6
  53. package/dist/openapi-types.d.cts.map +1 -1
  54. package/dist/openapi-types.d.mts +5 -6
  55. package/dist/openapi-types.d.mts.map +1 -1
  56. package/dist/react-query.cjs +17 -16
  57. package/dist/react-query.cjs.map +1 -1
  58. package/dist/react-query.d.cts +12 -17
  59. package/dist/react-query.d.cts.map +1 -1
  60. package/dist/react-query.d.mts +12 -17
  61. package/dist/react-query.d.mts.map +1 -1
  62. package/dist/react-query.mjs +10 -9
  63. package/dist/react-query.mjs.map +1 -1
  64. package/dist/types.cjs +0 -1
  65. package/dist/types.d.cts +114 -2
  66. package/dist/types.d.cts.map +1 -0
  67. package/dist/types.d.mts +114 -2
  68. package/dist/types.d.mts.map +1 -0
  69. package/dist/types.mjs +1 -1
  70. package/package.json +14 -14
  71. package/dist/auth-fetcher-CBYuL6rx.d.cts +0 -158
  72. package/dist/auth-fetcher-CBYuL6rx.d.cts.map +0 -1
  73. package/dist/auth-fetcher-DOj0iz21.mjs +0 -77
  74. package/dist/auth-fetcher-DOj0iz21.mjs.map +0 -1
  75. package/dist/auth-fetcher-DxS8zOLc.d.mts +0 -158
  76. package/dist/auth-fetcher-DxS8zOLc.d.mts.map +0 -1
  77. package/dist/auth-fetcher-HILABmws.cjs +0 -82
  78. package/dist/auth-fetcher-HILABmws.cjs.map +0 -1
  79. package/dist/chunk-CUT6urMc.cjs +0 -30
  80. package/dist/fetcher-C1xtCKpT.d.mts +0 -25
  81. package/dist/fetcher-C1xtCKpT.d.mts.map +0 -1
  82. package/dist/fetcher-CakjC9C7.mjs +0 -88
  83. package/dist/fetcher-CakjC9C7.mjs.map +0 -1
  84. package/dist/fetcher-CwnSqc4D.cjs +0 -100
  85. package/dist/fetcher-CwnSqc4D.cjs.map +0 -1
  86. package/dist/fetcher-cDrfwN-Y.d.cts +0 -25
  87. package/dist/fetcher-cDrfwN-Y.d.cts.map +0 -1
  88. package/dist/infer-6KKCgmg1.cjs +0 -0
  89. package/dist/infer-DfRq5kIb.d.cts +0 -133
  90. package/dist/infer-DfRq5kIb.d.cts.map +0 -1
  91. package/dist/infer-bTirNeNW.d.mts +0 -133
  92. package/dist/infer-bTirNeNW.d.mts.map +0 -1
  93. package/dist/infer-uCUq1whM.mjs +0 -0
  94. package/dist/openapi.cjs +0 -526
  95. package/dist/openapi.cjs.map +0 -1
  96. package/dist/openapi.mjs +0 -501
  97. package/dist/openapi.mjs.map +0 -1
  98. package/dist/types-BH8WgGrm.mjs +0 -0
  99. package/dist/types-BMGM6sZc.d.mts +0 -110
  100. package/dist/types-BMGM6sZc.d.mts.map +0 -1
  101. package/dist/types-DMQMHePI.d.cts +0 -110
  102. package/dist/types-DMQMHePI.d.cts.map +0 -1
  103. package/dist/types-a8gm_IaQ.cjs +0 -0
@@ -1,3 +1,23 @@
1
- import { FetcherOptions, WrappedResult } from "./types-BMGM6sZc.mjs";
2
- import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher-C1xtCKpT.mjs";
3
- export { FetchFn, FetcherOptions, TypedFetcher, WrappedResult, createTypedFetcher };
1
+ import { ErrorTransformer, ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types.mjs";
2
+ import { MethodCalls } from "./methods.mjs";
3
+ //#region src/fetcher.d.ts
4
+ export declare class TypedFetcher<Paths> {
5
+ private baseURL;
6
+ private defaultHeaders;
7
+ private options;
8
+ private fetchFn;
9
+ static getFetchFn(fn?: FetchFn): FetchFn;
10
+ constructor(options?: FetcherOptions);
11
+ request<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
12
+ wrap<E = unknown>(onError?: ErrorTransformer<E>): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>;
13
+ private parseEndpoint;
14
+ }
15
+ export declare function createTypedFetcher<Paths>(options?: FetcherOptions): (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & MethodCalls<Paths> & {
16
+ wrap: <E = unknown>(onError?: ErrorTransformer<E>) => (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T> | undefined) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>>) & (<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<ExtractEndpointResponse<Paths, T>>) & {
17
+ wrap: undefined;
18
+ };
19
+ };
20
+ export type FetchFn = typeof fetch;
21
+ //#endregion
22
+ export type { FetcherOptions, WrappedResult };
23
+ //# sourceMappingURL=fetcher.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.d.mts","names":["_$__methods0.MethodCalls"],"sources":["../src/fetcher.ts"],"mappings":";;;qBAgBa,aAAa;UACjB;UACA;UACA;UACA;SAED,WAAW,KAAK,UAAU;EAmBjC,YAAY,UAAS;EAOf,QAAQ,UAAU,cAAc,QACrC,UAAU,GACV,SAAS,sBAAsB,OAAO,KACpC,QAAQ,wBAAwB,OAAO;EAmF1C,KAAK,aAAa,UAAU,iBAAiB,MACpC,UAAU,cAAc,QAAM,UAC3B,GAAC,SACF,sBAAsB,OAAO,OACpC,QAAQ,cAAc,wBAAwB,OAAO,IAAI;UAUrD;;wBASO,mBAAmB,OAAO,UAAU,mBAEvC,UAAU,cAAc,QAAM,UAC/B,GAAC,SACF,sBAAsB,OAAO,OAAE,QAAA,wBAAA,OAAA,OAAAA,YAAA;EAIjC,OAAA,aAAW,UAAY,iBAAiB,SA9BvC,UAAU,cAAa,QAAO,UAAA,GAAA,SAAA,sBAAA,OAAA,mBAAA,QAAA,cAAA,wBAAA,OAAA,IAAA,SAwB3B,UAAU,cAAc,QAAM,UAC/B,GAAC,SACF,sBAAsB,OAAO,OAAE,QAAA,wBAAA,OAAA;;;;YAW9B,iBAAiB"}
package/dist/fetcher.mjs CHANGED
@@ -1,3 +1,87 @@
1
- import { TypedFetcher, createTypedFetcher } from "./fetcher-CakjC9C7.mjs";
1
+ import { methodCalls } from "./methods.mjs";
2
+ import qs from "qs";
3
+ //#region src/fetcher.ts
4
+ var TypedFetcher = class TypedFetcher {
5
+ baseURL;
6
+ defaultHeaders;
7
+ options;
8
+ fetchFn;
9
+ static getFetchFn(fn) {
10
+ if (fn) return fn;
11
+ if (typeof window !== "undefined" && typeof window.fetch === "function") return window.fetch.bind(window);
12
+ if (typeof globalThis !== "undefined" && typeof globalThis.fetch === "function") return globalThis.fetch.bind(globalThis);
13
+ throw new Error("No fetch implementation found");
14
+ }
15
+ constructor(options = {}) {
16
+ this.baseURL = options.baseURL || "";
17
+ this.defaultHeaders = options.headers || {};
18
+ this.options = options;
19
+ this.fetchFn = TypedFetcher.getFetchFn(options.fetch);
20
+ }
21
+ async request(endpoint, config) {
22
+ const { method, route } = this.parseEndpoint(endpoint);
23
+ let url = route;
24
+ if (config && "params" in config && config.params) Object.entries(config.params).forEach(([key, value]) => {
25
+ url = url.replace(`{${key}}`, encodeURIComponent(String(value)));
26
+ });
27
+ if (config && "query" in config && config.query) {
28
+ const queryString = qs.stringify(config.query, {
29
+ encode: true,
30
+ arrayFormat: "brackets",
31
+ skipNulls: true
32
+ });
33
+ if (queryString) url += `?${queryString}`;
34
+ }
35
+ let requestConfig = {
36
+ method: method.toUpperCase(),
37
+ headers: {
38
+ ...this.defaultHeaders,
39
+ ...config && "headers" in config && config.headers || {}
40
+ }
41
+ };
42
+ if (config && "body" in config && config.body) {
43
+ requestConfig.body = JSON.stringify(config.body);
44
+ requestConfig.headers = {
45
+ ...requestConfig.headers,
46
+ "Content-Type": "application/json"
47
+ };
48
+ }
49
+ if (this.options.onRequest) requestConfig = await this.options.onRequest(requestConfig);
50
+ try {
51
+ let response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);
52
+ if (this.options.onResponse) response = await this.options.onResponse(response);
53
+ if (!response.ok) throw response;
54
+ if (response.status === 204 || response.headers.get("content-length") === "0") return;
55
+ return await response.json();
56
+ } catch (error) {
57
+ if (this.options.onError) await this.options.onError(error);
58
+ throw error;
59
+ }
60
+ }
61
+ wrap(onError) {
62
+ return (endpoint, config) => this.request(endpoint, config).then((data) => ({
63
+ ok: true,
64
+ data
65
+ }), async (error) => ({
66
+ ok: false,
67
+ error: onError ? await onError(error) : error
68
+ }));
69
+ }
70
+ parseEndpoint(endpoint) {
71
+ const [method, ...routeParts] = endpoint.split(" ");
72
+ const route = routeParts.join(" ");
73
+ return {
74
+ method: method?.toLowerCase() ?? "",
75
+ route
76
+ };
77
+ }
78
+ };
79
+ function createTypedFetcher(options) {
80
+ const fetcher = new TypedFetcher(options);
81
+ const fn = (endpoint, config) => fetcher.request(endpoint, config);
82
+ return Object.assign(fn, methodCalls(fn), { wrap: (onError) => Object.assign(fetcher.wrap(onError), fn, { wrap: void 0 }) });
83
+ }
84
+ //#endregion
85
+ export { TypedFetcher, createTypedFetcher };
2
86
 
3
- export { TypedFetcher, createTypedFetcher };
87
+ //# sourceMappingURL=fetcher.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetcher.mjs","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport { methodCalls } from './methods';\nimport type {\n\tEndpointString,\n\tErrorTransformer,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedApiFunction,\n\tTypedEndpoint,\n\tWrappedResult,\n} from './types';\n\nexport type { FetcherOptions, WrappedResult } from './types';\n\nexport class TypedFetcher<Paths> {\n\tprivate baseURL: string;\n\tprivate defaultHeaders: Record<string, string>;\n\tprivate options: FetcherOptions;\n\tprivate fetchFn: FetchFn;\n\n\tstatic getFetchFn(fn?: FetchFn): FetchFn {\n\t\tif (fn) {\n\t\t\treturn fn;\n\t\t}\n\n\t\tif (typeof window !== 'undefined' && typeof window.fetch === 'function') {\n\t\t\treturn window.fetch.bind(window);\n\t\t}\n\n\t\tif (\n\t\t\ttypeof globalThis !== 'undefined' &&\n\t\t\ttypeof globalThis.fetch === 'function'\n\t\t) {\n\t\t\treturn globalThis.fetch.bind(globalThis);\n\t\t}\n\n\t\tthrow new Error('No fetch implementation found');\n\t}\n\n\tconstructor(options: FetcherOptions = {}) {\n\t\tthis.baseURL = options.baseURL || '';\n\t\tthis.defaultHeaders = options.headers || {};\n\t\tthis.options = options;\n\t\tthis.fetchFn = TypedFetcher.getFetchFn(options.fetch);\n\t}\n\n\tasync request<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<ExtractEndpointResponse<Paths, T>> {\n\t\tconst { method, route } = this.parseEndpoint(endpoint);\n\n\t\t// Replace path parameters\n\t\tlet url = route;\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tObject.entries(config.params as Record<string, unknown>).forEach(\n\t\t\t\t([key, value]) => {\n\t\t\t\t\turl = url.replace(`{${key}}`, encodeURIComponent(String(value)));\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\t// Add query parameters\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tconst queryString = qs.stringify(config.query, {\n\t\t\t\tencode: true,\n\t\t\t\tarrayFormat: 'brackets',\n\t\t\t\tskipNulls: true,\n\t\t\t});\n\t\t\tif (queryString) {\n\t\t\t\turl += `?${queryString}`;\n\t\t\t}\n\t\t}\n\n\t\t// Build request configuration\n\t\tlet requestConfig: RequestInit = {\n\t\t\tmethod: method.toUpperCase(),\n\t\t\theaders: {\n\t\t\t\t...this.defaultHeaders,\n\t\t\t\t...((config && 'headers' in config && config.headers) || {}),\n\t\t\t},\n\t\t};\n\n\t\t// Add body if present\n\t\tif (config && 'body' in config && config.body) {\n\t\t\trequestConfig.body = JSON.stringify(config.body);\n\t\t\trequestConfig.headers = {\n\t\t\t\t...requestConfig.headers,\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t};\n\t\t}\n\n\t\t// Apply request interceptor\n\t\tif (this.options.onRequest) {\n\t\t\trequestConfig = await this.options.onRequest(requestConfig);\n\t\t}\n\n\t\ttry {\n\t\t\t// Make the request\n\t\t\tlet response = await this.fetchFn(`${this.baseURL}${url}`, requestConfig);\n\n\t\t\t// Apply response interceptor\n\t\t\tif (this.options.onResponse) {\n\t\t\t\tresponse = await this.options.onResponse(response);\n\t\t\t}\n\n\t\t\t// Handle errors\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow response;\n\t\t\t}\n\n\t\t\t// Handle empty responses (204 No Content, etc.)\n\t\t\tif (\n\t\t\t\tresponse.status === 204 ||\n\t\t\t\tresponse.headers.get('content-length') === '0'\n\t\t\t) {\n\t\t\t\treturn undefined as ExtractEndpointResponse<Paths, T>;\n\t\t\t}\n\n\t\t\t// Parse JSON response\n\t\t\tconst data = await response.json();\n\t\t\treturn data as ExtractEndpointResponse<Paths, T>;\n\t\t} catch (error) {\n\t\t\t// Apply error handler\n\t\t\tif (this.options.onError) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tawait this.options.onError(error);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\twrap<E = unknown>(onError?: ErrorTransformer<E>) {\n\t\treturn <T extends TypedEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>, E>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ ok: true as const, data }),\n\t\t\t\tasync (error) => ({\n\t\t\t\t\tok: false as const,\n\t\t\t\t\terror: onError ? await onError(error) : (error as E),\n\t\t\t\t}),\n\t\t\t);\n\t}\n\n\tprivate parseEndpoint<T extends EndpointString>(\n\t\tendpoint: T,\n\t): ParseEndpoint<T> {\n\t\tconst [method, ...routeParts] = endpoint.split(' ');\n\t\tconst route = routeParts.join(' ');\n\t\treturn { method: method?.toLowerCase() ?? '', route } as ParseEndpoint<T>;\n\t}\n}\n\nexport function createTypedFetcher<Paths>(options?: FetcherOptions) {\n\tconst fetcher = new TypedFetcher<Paths>(options);\n\tconst fn = <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n\n\treturn Object.assign(fn, methodCalls<Paths>(fn as TypedApiFunction<Paths>), {\n\t\twrap: <E = unknown>(onError?: ErrorTransformer<E>) =>\n\t\t\tObject.assign(fetcher.wrap(onError), fn, {\n\t\t\t\twrap: undefined,\n\t\t\t}),\n\t});\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;AAgBA,IAAa,eAAb,MAAa,aAAoB;CAChC;CACA;CACA;CACA;CAEA,OAAO,WAAW,IAAuB;EACxC,IAAI,IACH,OAAO;EAGR,IAAI,OAAO,WAAW,eAAe,OAAO,OAAO,UAAU,YAC5D,OAAO,OAAO,MAAM,KAAK,MAAM;EAGhC,IACC,OAAO,eAAe,eACtB,OAAO,WAAW,UAAU,YAE5B,OAAO,WAAW,MAAM,KAAK,UAAU;EAGxC,MAAM,IAAI,MAAM,+BAA+B;CAChD;CAEA,YAAY,UAA0B,CAAC,GAAG;EACzC,KAAK,UAAU,QAAQ,WAAW;EAClC,KAAK,iBAAiB,QAAQ,WAAW,CAAC;EAC1C,KAAK,UAAU;EACf,KAAK,UAAU,aAAa,WAAW,QAAQ,KAAK;CACrD;CAEA,MAAM,QACL,UACA,QAC6C;EAC7C,MAAM,EAAE,QAAQ,UAAU,KAAK,cAAc,QAAQ;EAGrD,IAAI,MAAM;EACV,IAAI,UAAU,YAAY,UAAU,OAAO,QAC1C,OAAO,QAAQ,OAAO,MAAiC,CAAC,CAAC,SACvD,CAAC,KAAK,WAAW;GACjB,MAAM,IAAI,QAAQ,IAAI,IAAI,IAAI,mBAAmB,OAAO,KAAK,CAAC,CAAC;EAChE,CACD;EAID,IAAI,UAAU,WAAW,UAAU,OAAO,OAAO;GAChD,MAAM,cAAc,GAAG,UAAU,OAAO,OAAO;IAC9C,QAAQ;IACR,aAAa;IACb,WAAW;GACZ,CAAC;GACD,IAAI,aACH,OAAO,IAAI;EAEb;EAGA,IAAI,gBAA6B;GAChC,QAAQ,OAAO,YAAY;GAC3B,SAAS;IACR,GAAG,KAAK;IACR,GAAK,UAAU,aAAa,UAAU,OAAO,WAAY,CAAC;GAC3D;EACD;EAGA,IAAI,UAAU,UAAU,UAAU,OAAO,MAAM;GAC9C,cAAc,OAAO,KAAK,UAAU,OAAO,IAAI;GAC/C,cAAc,UAAU;IACvB,GAAG,cAAc;IACjB,gBAAgB;GACjB;EACD;EAGA,IAAI,KAAK,QAAQ,WAChB,gBAAgB,MAAM,KAAK,QAAQ,UAAU,aAAa;EAG3D,IAAI;GAEH,IAAI,WAAW,MAAM,KAAK,QAAQ,GAAG,KAAK,UAAU,OAAO,aAAa;GAGxE,IAAI,KAAK,QAAQ,YAChB,WAAW,MAAM,KAAK,QAAQ,WAAW,QAAQ;GAIlD,IAAI,CAAC,SAAS,IACb,MAAM;GAIP,IACC,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,gBAAgB,MAAM,KAE3C;GAKD,OAAO,MADY,SAAS,KAAK;EAElC,SAAS,OAAO;GAEf,IAAI,KAAK,QAAQ,SAEhB,MAAM,KAAK,QAAQ,QAAQ,KAAK;GAEjC,MAAM;EACP;CACD;CAEA,KAAkB,SAA+B;EAChD,QACC,UACA,WAEA,KAAK,QAAQ,UAAU,MAAM,CAAC,CAAC,MAC7B,UAAU;GAAE,IAAI;GAAe;EAAK,IACrC,OAAO,WAAW;GACjB,IAAI;GACJ,OAAO,UAAU,MAAM,QAAQ,KAAK,IAAK;EAC1C,EACD;CACF;CAEA,cACC,UACmB;EACnB,MAAM,CAAC,QAAQ,GAAG,cAAc,SAAS,MAAM,GAAG;EAClD,MAAM,QAAQ,WAAW,KAAK,GAAG;EACjC,OAAO;GAAE,QAAQ,QAAQ,YAAY,KAAK;GAAI;EAAM;CACrD;AACD;AAEA,SAAgB,mBAA0B,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB,OAAO;CAC/C,MAAM,MACL,UACA,WACI,QAAQ,QAAQ,UAAU,MAAM;CAErC,OAAO,OAAO,OAAO,IAAI,YAAmB,EAA6B,GAAG,EAC3E,OAAoB,YACnB,OAAO,OAAO,QAAQ,KAAK,OAAO,GAAG,IAAI,EACxC,MAAM,KAAA,EACP,CAAC,EACH,CAAC;AACF"}
package/dist/index.cjs CHANGED
@@ -1,8 +1,11 @@
1
- const require_fetcher = require('./fetcher-CwnSqc4D.cjs');
2
- const require_auth_fetcher = require('./auth-fetcher-HILABmws.cjs');
3
- require('./infer-6KKCgmg1.cjs');
4
- require('./types-a8gm_IaQ.cjs');
5
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_methods = require("./methods.cjs");
3
+ const require_fetcher = require("./fetcher.cjs");
4
+ const require_auth_fetcher = require("./auth-fetcher.cjs");
5
+ require("./infer.cjs");
6
+ require("./types.cjs");
7
+ exports.CALL_METHODS = require_methods.CALL_METHODS;
6
8
  exports.TypedFetcher = require_fetcher.TypedFetcher;
7
9
  exports.createAuthAwareFetcher = require_auth_fetcher.createAuthAwareFetcher;
8
- exports.createTypedFetcher = require_fetcher.createTypedFetcher;
10
+ exports.createTypedFetcher = require_fetcher.createTypedFetcher;
11
+ exports.methodCalls = require_methods.methodCalls;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types-DMQMHePI.cjs";
2
- import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher-CBYuL6rx.cjs";
3
- import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher-cDrfwN-Y.cjs";
4
- import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer-DfRq5kIb.cjs";
5
- export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetchFn, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, GetEndpointAuth, InferOpenApi, InferOpenApiFromEndpoint, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, PublicEndpoints, QueryEndpoint, RequestConfig, SecuritySchemeObject, TokenProvider, TypedApiFunction, TypedEndpoint, TypedFetcher, UsedSecuritySchemes, ValidEndpoint, WrappedApiFunction, WrappedResult, createAuthAwareFetcher, createTypedFetcher };
1
+ import { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types.cjs";
2
+ import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher.cjs";
3
+ import { CALL_METHODS, CallMethod, MethodCall, MethodCalls, RoutesFor, methodCalls } from "./methods.cjs";
4
+ import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher.cjs";
5
+ import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer.cjs";
6
+ export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, CALL_METHODS, CallMethod, EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetchFn, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, GetEndpointAuth, InferOpenApi, InferOpenApiFromEndpoint, IsConfigRequired, MethodCall, MethodCalls, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, PublicEndpoints, QueryEndpoint, RequestConfig, RoutesFor, SecuritySchemeObject, TokenProvider, TypedApiFunction, TypedEndpoint, TypedFetcher, UsedSecuritySchemes, ValidEndpoint, WrappedApiFunction, WrappedResult, createAuthAwareFetcher, createTypedFetcher, methodCalls };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types-BMGM6sZc.mjs";
2
- import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher-DxS8zOLc.mjs";
3
- import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher-C1xtCKpT.mjs";
4
- import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer-bTirNeNW.mjs";
5
- export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetchFn, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, GetEndpointAuth, InferOpenApi, InferOpenApiFromEndpoint, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, PublicEndpoints, QueryEndpoint, RequestConfig, SecuritySchemeObject, TokenProvider, TypedApiFunction, TypedEndpoint, TypedFetcher, UsedSecuritySchemes, ValidEndpoint, WrappedApiFunction, WrappedResult, createAuthAwareFetcher, createTypedFetcher };
1
+ import { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types.mjs";
2
+ import { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, GetEndpointAuth, PublicEndpoints, SecuritySchemeObject, TokenProvider, UsedSecuritySchemes, createAuthAwareFetcher } from "./auth-fetcher.mjs";
3
+ import { CALL_METHODS, CallMethod, MethodCall, MethodCalls, RoutesFor, methodCalls } from "./methods.mjs";
4
+ import { FetchFn, TypedFetcher, createTypedFetcher } from "./fetcher.mjs";
5
+ import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer.mjs";
6
+ export { ApiKeyProvider, AuthFetcherOptions, AuthStrategy, AuthenticatedEndpoints, AwsSigner, CALL_METHODS, CallMethod, EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetchFn, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, GetEndpointAuth, InferOpenApi, InferOpenApiFromEndpoint, IsConfigRequired, MethodCall, MethodCalls, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, PublicEndpoints, QueryEndpoint, RequestConfig, RoutesFor, SecuritySchemeObject, TokenProvider, TypedApiFunction, TypedEndpoint, TypedFetcher, UsedSecuritySchemes, ValidEndpoint, WrappedApiFunction, WrappedResult, createAuthAwareFetcher, createTypedFetcher, methodCalls };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { TypedFetcher, createTypedFetcher } from "./fetcher-CakjC9C7.mjs";
2
- import { createAuthAwareFetcher } from "./auth-fetcher-DOj0iz21.mjs";
3
- import "./infer-uCUq1whM.mjs";
4
- import "./types-BH8WgGrm.mjs";
5
-
6
- export { TypedFetcher, createAuthAwareFetcher, createTypedFetcher };
1
+ import { CALL_METHODS, methodCalls } from "./methods.mjs";
2
+ import { TypedFetcher, createTypedFetcher } from "./fetcher.mjs";
3
+ import { createAuthAwareFetcher } from "./auth-fetcher.mjs";
4
+ import "./infer.mjs";
5
+ import "./types.mjs";
6
+ export { CALL_METHODS, TypedFetcher, createAuthAwareFetcher, createTypedFetcher, methodCalls };
package/dist/infer.cjs CHANGED
@@ -1 +0,0 @@
1
- require('./infer-6KKCgmg1.cjs');
package/dist/infer.d.cts CHANGED
@@ -1,2 +1,130 @@
1
- import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer-DfRq5kIb.cjs";
2
- export { InferOpenApi, InferOpenApiFromEndpoint };
1
+ import { ConvertRouteParams, Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
2
+ import { HttpMethod } from "@geekmidas/constructs/types";
3
+ import { InferStandardSchema, InferStandardSchemaInput } from "@geekmidas/schema";
4
+ import { StandardSchemaV1 } from "@standard-schema/spec";
5
+ //#region src/infer.d.ts
6
+ /**
7
+ * Infers path parameters from a route string as an object
8
+ * @example '/users/{id}/posts/{postId}' -> { id: string, postId: string }
9
+ */
10
+ type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string; } & InferPathParams<Rest> : {};
11
+ /**
12
+ * Converts an HTTP method to lowercase for TypedFetcher compatibility
13
+ */
14
+ type LowercaseMethod<T extends HttpMethod> = Lowercase<T>;
15
+ /**
16
+ * Infers route-level parameters (path params)
17
+ */
18
+ type InferRouteParameters<TRoute extends string> = InferPathParams<TRoute> extends Record<string, never> ? {} : {
19
+ parameters: {
20
+ path: InferPathParams<TRoute>;
21
+ };
22
+ };
23
+ /**
24
+ * Infers operation-level parameters (query params)
25
+ */
26
+ type InferOperationParameters<TInput extends EndpointSchemas> = TInput extends {
27
+ query: infer Q;
28
+ } ? {
29
+ parameters: {
30
+ query: InferStandardSchemaInput<Q>;
31
+ };
32
+ } : {};
33
+ /**
34
+ * Infers the operation object compatible with TypedFetcher
35
+ */
36
+ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSchemaV1 | undefined> = InferOperationParameters<TInput> & {
37
+ requestBody?: TInput extends {
38
+ body: infer B;
39
+ } ? {
40
+ content: {
41
+ 'application/json': InferStandardSchemaInput<B>;
42
+ };
43
+ } : never;
44
+ responses: {
45
+ 200: {
46
+ content: TOutput extends StandardSchemaV1 ? {
47
+ 'application/json': InferStandardSchema<TOutput>;
48
+ } : never;
49
+ };
50
+ };
51
+ };
52
+ /**
53
+ * Infers the TypedFetcher-compatible paths structure from a single endpoint
54
+ *
55
+ * This generates a structure compatible with @geekmidas/client TypedFetcher,
56
+ * allowing you to create a typed client directly from endpoint definitions
57
+ * without needing OpenAPI JSON + codegen.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { api } from './constructs/api.js';
62
+ * import { createTypedFetcher, type InferOpenApiFromEndpoint } from '@geekmidas/client';
63
+ * import { z } from 'zod';
64
+ *
65
+ * const endpoint = e
66
+ * .get('/users/{id}')
67
+ * .params(z.object({ id: z.string() }))
68
+ * .output(z.object({ id: z.string(), name: z.string() }))
69
+ * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
70
+ *
71
+ * type Paths = InferOpenApiFromEndpoint<typeof endpoint>['paths'];
72
+ * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
73
+ * const user = await client('GET /users/{id}', { params: { id: '123' } });
74
+ * ```
75
+ */
76
+ export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer TMethod, infer TInput, infer TOutput, any, any, any> ? {
77
+ paths: { [K in ConvertRouteParams<TRoute>]: InferRouteParameters<ConvertRouteParams<TRoute>> & { [M in LowercaseMethod<TMethod>]: InferOperation<TInput, TOutput>; }; };
78
+ } : never;
79
+ /**
80
+ * Infers TypedFetcher-compatible paths structure from multiple endpoints
81
+ *
82
+ * Merges multiple endpoint definitions into a single paths object that can be
83
+ * used with @geekmidas/client TypedFetcher for fully type-safe API calls.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * import { api } from './constructs/api.js';
88
+ * import { createTypedFetcher, type InferOpenApi } from '@geekmidas/client';
89
+ * import { z } from 'zod';
90
+ *
91
+ * // Define endpoints
92
+ * const getUserEndpoint = e
93
+ * .get('/users/{id}')
94
+ * .params(z.object({ id: z.string() }))
95
+ * .output(z.object({ id: z.string(), name: z.string() }))
96
+ * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
97
+ *
98
+ * const createUserEndpoint = e
99
+ * .post('/users')
100
+ * .body(z.object({ name: z.string() }))
101
+ * .output(z.object({ id: z.string(), name: z.string() }))
102
+ * .handle(async ({ body }) => ({ id: '123', name: body.name }));
103
+ *
104
+ * // Export for client
105
+ * export const endpoints = [getUserEndpoint, createUserEndpoint] as const;
106
+ * export type Paths = InferOpenApi<typeof endpoints>['paths'];
107
+ *
108
+ * // Client usage
109
+ * import type { Paths } from './endpoints';
110
+ * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
111
+ *
112
+ * const user = await client('GET /users/{id}', { params: { id: '123' } });
113
+ * const newUser = await client('POST /users', { body: { name: 'Jane' } });
114
+ * ```
115
+ */
116
+ export type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
117
+ paths: infer P1;
118
+ } ? Rest extends [] ? {
119
+ paths: P1;
120
+ } : InferOpenApi<Rest> extends {
121
+ paths: infer P2;
122
+ } ? {
123
+ paths: P1 & P2;
124
+ } : {
125
+ paths: P1;
126
+ } : InferOpenApi<Rest> : {
127
+ paths: {};
128
+ };
129
+ //#endregion
130
+ //# sourceMappingURL=infer.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer.d.cts","names":[],"sources":["../src/infer.ts"],"mappings":";;;;;;;;;KAgBK,gBAAgB,yBACpB,kCAAkC,eAAe,YAC3C,KAAK,oBAAmB,gBAAgB;;;;KAM1C,gBAAgB,UAAU,cAAc,UAAU;;;;KAKlD,qBAAqB,yBACzB,gBAAgB,gBAAgB;EAG7B;IACC,MAAM,gBAAgB;;;;;;KAOtB,yBAAyB,eAAe,mBAAmB;EAC/D,aAAa;;EAGX;IAMC,OAAO,yBAAyB;;;;;;KAQ/B,eACJ,eAAe,iBACf,gBAAgB,gCACb,yBAAyB;EAC5B,cAAc;IAAiB,YAAY;;IAExC;MAKC,oBAAoB,yBAAyB;;;EAIjD;IACC;MACC,SAAS,gBAAgB;QAEtB,oBAAoB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+BlC,yBAAyB,KACpC,UAAU,eACH,cACA,eACA,cACA;EAUJ,UACE,KAAK,mBAAmB,UAAU,qBAClC,mBAAmB,cAElB,KAAK,gBAAgB,WAAW,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA2ClD,aAAa,qCACxB,mCAAmC,gBAAgB,QAChD,yBAAyB;EAAiB,aAAa;IACtD;EACG,OAAO;IACT,aAAa;EAAgB,aAAa;;EACvC,OAAO,KAAK;;EACZ,OAAO;IACX,aAAa;EACZ"}
package/dist/infer.d.mts CHANGED
@@ -1,2 +1,130 @@
1
- import { InferOpenApi, InferOpenApiFromEndpoint } from "./infer-bTirNeNW.mjs";
2
- export { InferOpenApi, InferOpenApiFromEndpoint };
1
+ import { ConvertRouteParams, Endpoint, EndpointSchemas } from "@geekmidas/constructs/endpoints";
2
+ import { HttpMethod } from "@geekmidas/constructs/types";
3
+ import { InferStandardSchema, InferStandardSchemaInput } from "@geekmidas/schema";
4
+ import { StandardSchemaV1 } from "@standard-schema/spec";
5
+ //#region src/infer.d.ts
6
+ /**
7
+ * Infers path parameters from a route string as an object
8
+ * @example '/users/{id}/posts/{postId}' -> { id: string, postId: string }
9
+ */
10
+ type InferPathParams<TRoute extends string> = TRoute extends `${string}{${infer Param}}${infer Rest}` ? { [K in Param]: string; } & InferPathParams<Rest> : {};
11
+ /**
12
+ * Converts an HTTP method to lowercase for TypedFetcher compatibility
13
+ */
14
+ type LowercaseMethod<T extends HttpMethod> = Lowercase<T>;
15
+ /**
16
+ * Infers route-level parameters (path params)
17
+ */
18
+ type InferRouteParameters<TRoute extends string> = InferPathParams<TRoute> extends Record<string, never> ? {} : {
19
+ parameters: {
20
+ path: InferPathParams<TRoute>;
21
+ };
22
+ };
23
+ /**
24
+ * Infers operation-level parameters (query params)
25
+ */
26
+ type InferOperationParameters<TInput extends EndpointSchemas> = TInput extends {
27
+ query: infer Q;
28
+ } ? {
29
+ parameters: {
30
+ query: InferStandardSchemaInput<Q>;
31
+ };
32
+ } : {};
33
+ /**
34
+ * Infers the operation object compatible with TypedFetcher
35
+ */
36
+ type InferOperation<TInput extends EndpointSchemas, TOutput extends StandardSchemaV1 | undefined> = InferOperationParameters<TInput> & {
37
+ requestBody?: TInput extends {
38
+ body: infer B;
39
+ } ? {
40
+ content: {
41
+ 'application/json': InferStandardSchemaInput<B>;
42
+ };
43
+ } : never;
44
+ responses: {
45
+ 200: {
46
+ content: TOutput extends StandardSchemaV1 ? {
47
+ 'application/json': InferStandardSchema<TOutput>;
48
+ } : never;
49
+ };
50
+ };
51
+ };
52
+ /**
53
+ * Infers the TypedFetcher-compatible paths structure from a single endpoint
54
+ *
55
+ * This generates a structure compatible with @geekmidas/client TypedFetcher,
56
+ * allowing you to create a typed client directly from endpoint definitions
57
+ * without needing OpenAPI JSON + codegen.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { api } from './constructs/api.js';
62
+ * import { createTypedFetcher, type InferOpenApiFromEndpoint } from '@geekmidas/client';
63
+ * import { z } from 'zod';
64
+ *
65
+ * const endpoint = e
66
+ * .get('/users/{id}')
67
+ * .params(z.object({ id: z.string() }))
68
+ * .output(z.object({ id: z.string(), name: z.string() }))
69
+ * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
70
+ *
71
+ * type Paths = InferOpenApiFromEndpoint<typeof endpoint>['paths'];
72
+ * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
73
+ * const user = await client('GET /users/{id}', { params: { id: '123' } });
74
+ * ```
75
+ */
76
+ export type InferOpenApiFromEndpoint<T> = T extends Endpoint<infer TRoute, infer TMethod, infer TInput, infer TOutput, any, any, any> ? {
77
+ paths: { [K in ConvertRouteParams<TRoute>]: InferRouteParameters<ConvertRouteParams<TRoute>> & { [M in LowercaseMethod<TMethod>]: InferOperation<TInput, TOutput>; }; };
78
+ } : never;
79
+ /**
80
+ * Infers TypedFetcher-compatible paths structure from multiple endpoints
81
+ *
82
+ * Merges multiple endpoint definitions into a single paths object that can be
83
+ * used with @geekmidas/client TypedFetcher for fully type-safe API calls.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * import { api } from './constructs/api.js';
88
+ * import { createTypedFetcher, type InferOpenApi } from '@geekmidas/client';
89
+ * import { z } from 'zod';
90
+ *
91
+ * // Define endpoints
92
+ * const getUserEndpoint = e
93
+ * .get('/users/{id}')
94
+ * .params(z.object({ id: z.string() }))
95
+ * .output(z.object({ id: z.string(), name: z.string() }))
96
+ * .handle(async ({ params }) => ({ id: params.id, name: 'John' }));
97
+ *
98
+ * const createUserEndpoint = e
99
+ * .post('/users')
100
+ * .body(z.object({ name: z.string() }))
101
+ * .output(z.object({ id: z.string(), name: z.string() }))
102
+ * .handle(async ({ body }) => ({ id: '123', name: body.name }));
103
+ *
104
+ * // Export for client
105
+ * export const endpoints = [getUserEndpoint, createUserEndpoint] as const;
106
+ * export type Paths = InferOpenApi<typeof endpoints>['paths'];
107
+ *
108
+ * // Client usage
109
+ * import type { Paths } from './endpoints';
110
+ * const client = createTypedFetcher<Paths>({ baseURL: 'http://localhost:3000' });
111
+ *
112
+ * const user = await client('GET /users/{id}', { params: { id: '123' } });
113
+ * const newUser = await client('POST /users', { body: { name: 'Jane' } });
114
+ * ```
115
+ */
116
+ export type InferOpenApi<TEndpoints extends readonly any[]> = TEndpoints extends readonly [infer First, ...infer Rest] ? InferOpenApiFromEndpoint<First> extends {
117
+ paths: infer P1;
118
+ } ? Rest extends [] ? {
119
+ paths: P1;
120
+ } : InferOpenApi<Rest> extends {
121
+ paths: infer P2;
122
+ } ? {
123
+ paths: P1 & P2;
124
+ } : {
125
+ paths: P1;
126
+ } : InferOpenApi<Rest> : {
127
+ paths: {};
128
+ };
129
+ //#endregion
130
+ //# sourceMappingURL=infer.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer.d.mts","names":[],"sources":["../src/infer.ts"],"mappings":";;;;;;;;;KAgBK,gBAAgB,yBACpB,kCAAkC,eAAe,YAC3C,KAAK,oBAAmB,gBAAgB;;;;KAM1C,gBAAgB,UAAU,cAAc,UAAU;;;;KAKlD,qBAAqB,yBACzB,gBAAgB,gBAAgB;EAG7B;IACC,MAAM,gBAAgB;;;;;;KAOtB,yBAAyB,eAAe,mBAAmB;EAC/D,aAAa;;EAGX;IAMC,OAAO,yBAAyB;;;;;;KAQ/B,eACJ,eAAe,iBACf,gBAAgB,gCACb,yBAAyB;EAC5B,cAAc;IAAiB,YAAY;;IAExC;MAKC,oBAAoB,yBAAyB;;;EAIjD;IACC;MACC,SAAS,gBAAgB;QAEtB,oBAAoB,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+BlC,yBAAyB,KACpC,UAAU,eACH,cACA,eACA,cACA;EAUJ,UACE,KAAK,mBAAmB,UAAU,qBAClC,mBAAmB,cAElB,KAAK,gBAAgB,WAAW,eAAe,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA2ClD,aAAa,qCACxB,mCAAmC,gBAAgB,QAChD,yBAAyB;EAAiB,aAAa;IACtD;EACG,OAAO;IACT,aAAa;EAAgB,aAAa;;EACvC,OAAO,KAAK;;EACZ,OAAO;IACX,aAAa;EACZ"}
package/dist/infer.mjs CHANGED
@@ -1 +1 @@
1
- import "./infer-uCUq1whM.mjs";
1
+ export {};
@@ -0,0 +1,21 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/methods.ts
3
+ /** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */
4
+ const CALL_METHODS = [
5
+ "get",
6
+ "post",
7
+ "put",
8
+ "patch",
9
+ "delete",
10
+ "options"
11
+ ];
12
+ /** The method calls for a client, each delegating to `api('METHOD /route', …)`. */
13
+ function methodCalls(fn) {
14
+ const call = (method) => (route, config) => fn(`${method.toUpperCase()} ${route}`, config);
15
+ return Object.fromEntries(CALL_METHODS.map((method) => [method, call(method)]));
16
+ }
17
+ //#endregion
18
+ exports.CALL_METHODS = CALL_METHODS;
19
+ exports.methodCalls = methodCalls;
20
+
21
+ //# sourceMappingURL=methods.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.cjs","names":[],"sources":["../src/methods.ts"],"sourcesContent":["import type {\n\tExtractEndpointResponse,\n\tExtractMethod,\n\tFilteredRequestConfig,\n\tIsConfigRequired,\n\tTypedApiFunction,\n\tTypedEndpoint,\n} from './types';\n\n/** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */\nexport const CALL_METHODS = [\n\t'get',\n\t'post',\n\t'put',\n\t'patch',\n\t'delete',\n\t'options',\n] as const;\n\nexport type CallMethod = (typeof CALL_METHODS)[number];\n\n/**\n * The routes that answer `M` — only routes with a `POST` appear in `api.post`,\n * so a route that exists under another method is a type error, not a 405.\n */\nexport type RoutesFor<Paths, M extends CallMethod> = {\n\t[R in keyof Paths]: M extends ExtractMethod<Paths, R> ? R : never;\n}[keyof Paths] &\n\tstring;\n\n/**\n * One method's call: `api.post('/users', { body })`.\n *\n * The second argument has only the keys the endpoint declares, and is required\n * exactly when something in it is — the same rule as `api('POST /users', …)`,\n * which this is sugar over.\n */\nexport type MethodCall<Paths, M extends CallMethod> = <\n\tR extends RoutesFor<Paths, M>,\n>(\n\troute: R,\n\t...args: `${Uppercase<M>} ${R}` extends TypedEndpoint<Paths>\n\t\t? IsConfigRequired<Paths, `${Uppercase<M>} ${R}`> extends true\n\t\t\t? [config: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>]\n\t\t\t: [config?: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>]\n\t\t: never\n) => Promise<ExtractEndpointResponse<Paths, `${Uppercase<M>} ${R}`>>;\n\nexport type MethodCalls<Paths> = {\n\t[M in CallMethod]: MethodCall<Paths, M>;\n};\n\n/** The method calls for a client, each delegating to `api('METHOD /route', …)`. */\nexport function methodCalls<Paths>(\n\tfn: TypedApiFunction<Paths>,\n): MethodCalls<Paths> {\n\tconst call =\n\t\t(method: CallMethod) =>\n\t\t(route: string, config?: unknown): Promise<unknown> =>\n\t\t\t(fn as (endpoint: string, config?: unknown) => Promise<unknown>)(\n\t\t\t\t`${method.toUpperCase()} ${route}`,\n\t\t\t\tconfig,\n\t\t\t);\n\n\treturn Object.fromEntries(\n\t\tCALL_METHODS.map((method) => [method, call(method)]),\n\t) as unknown as MethodCalls<Paths>;\n}\n"],"mappings":";;;AAUA,MAAa,eAAe;CAC3B;CACA;CACA;CACA;CACA;CACA;AACD;;AAoCA,SAAgB,YACf,IACqB;CACrB,MAAM,QACJ,YACA,OAAe,WACd,GACA,GAAG,OAAO,YAAY,EAAE,GAAG,SAC3B,MACD;CAEF,OAAO,OAAO,YACb,aAAa,KAAK,WAAW,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CACpD;AACD"}
@@ -0,0 +1,23 @@
1
+ import { ExtractEndpointResponse, ExtractMethod, FilteredRequestConfig, IsConfigRequired, TypedApiFunction, TypedEndpoint } from "./types.cjs";
2
+ //#region src/methods.d.ts
3
+ /** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */
4
+ export declare const CALL_METHODS: readonly ['get', 'post', 'put', 'patch', 'delete', 'options'];
5
+ export type CallMethod = (typeof CALL_METHODS)[number];
6
+ /**
7
+ * The routes that answer `M` — only routes with a `POST` appear in `api.post`,
8
+ * so a route that exists under another method is a type error, not a 405.
9
+ */
10
+ export type RoutesFor<Paths, M extends CallMethod> = { [R in keyof Paths]: M extends ExtractMethod<Paths, R> ? R : never; }[keyof Paths] & string;
11
+ /**
12
+ * One method's call: `api.post('/users', { body })`.
13
+ *
14
+ * The second argument has only the keys the endpoint declares, and is required
15
+ * exactly when something in it is — the same rule as `api('POST /users', …)`,
16
+ * which this is sugar over.
17
+ */
18
+ export type MethodCall<Paths, M extends CallMethod> = <R extends RoutesFor<Paths, M>>(route: R, ...args: `${Uppercase<M>} ${R}` extends TypedEndpoint<Paths> ? IsConfigRequired<Paths, `${Uppercase<M>} ${R}`> extends true ? [config: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>] : [config?: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>] : never) => Promise<ExtractEndpointResponse<Paths, `${Uppercase<M>} ${R}`>>;
19
+ export type MethodCalls<Paths> = { [M in CallMethod]: MethodCall<Paths, M>; };
20
+ /** The method calls for a client, each delegating to `api('METHOD /route', …)`. */
21
+ export declare function methodCalls<Paths>(fn: TypedApiFunction<Paths>): MethodCalls<Paths>;
22
+ //#endregion
23
+ //# sourceMappingURL=methods.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.d.cts","names":[],"sources":["../src/methods.ts"],"mappings":";;;qBAUa;YASD,qBAAqB;;;;;YAMrB,UAAU,OAAO,UAAU,iBACrC,WAAW,QAAQ,UAAU,cAAc,OAAO,KAAK,mBACjD;;;;;;;;YAUI,WAAW,OAAO,UAAU,eACvC,UAAU,UAAU,OAAO,IAE3B,OAAO,MACJ,SAAS,UAAU,MAAM,YAAY,cAAc,SACnD,iBAAiB,UAAU,UAAU,MAAM,qBACzC,QAAQ,sBAAsB,UAAU,UAAU,MAAM,SACxD,SAAS,sBAAsB,UAAU,UAAU,MAAM,kBAE1D,QAAQ,wBAAwB,UAAU,UAAU,MAAM;YAEnD,YAAY,YACtB,KAAK,aAAa,WAAW,OAAO;;wBAItB,YAAY,OAC3B,IAAI,iBAAiB,SACnB,YAAY"}
@@ -0,0 +1,23 @@
1
+ import { ExtractEndpointResponse, ExtractMethod, FilteredRequestConfig, IsConfigRequired, TypedApiFunction, TypedEndpoint } from "./types.mjs";
2
+ //#region src/methods.d.ts
3
+ /** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */
4
+ export declare const CALL_METHODS: readonly ['get', 'post', 'put', 'patch', 'delete', 'options'];
5
+ export type CallMethod = (typeof CALL_METHODS)[number];
6
+ /**
7
+ * The routes that answer `M` — only routes with a `POST` appear in `api.post`,
8
+ * so a route that exists under another method is a type error, not a 405.
9
+ */
10
+ export type RoutesFor<Paths, M extends CallMethod> = { [R in keyof Paths]: M extends ExtractMethod<Paths, R> ? R : never; }[keyof Paths] & string;
11
+ /**
12
+ * One method's call: `api.post('/users', { body })`.
13
+ *
14
+ * The second argument has only the keys the endpoint declares, and is required
15
+ * exactly when something in it is — the same rule as `api('POST /users', …)`,
16
+ * which this is sugar over.
17
+ */
18
+ export type MethodCall<Paths, M extends CallMethod> = <R extends RoutesFor<Paths, M>>(route: R, ...args: `${Uppercase<M>} ${R}` extends TypedEndpoint<Paths> ? IsConfigRequired<Paths, `${Uppercase<M>} ${R}`> extends true ? [config: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>] : [config?: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>] : never) => Promise<ExtractEndpointResponse<Paths, `${Uppercase<M>} ${R}`>>;
19
+ export type MethodCalls<Paths> = { [M in CallMethod]: MethodCall<Paths, M>; };
20
+ /** The method calls for a client, each delegating to `api('METHOD /route', …)`. */
21
+ export declare function methodCalls<Paths>(fn: TypedApiFunction<Paths>): MethodCalls<Paths>;
22
+ //#endregion
23
+ //# sourceMappingURL=methods.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.d.mts","names":[],"sources":["../src/methods.ts"],"mappings":";;;qBAUa;YASD,qBAAqB;;;;;YAMrB,UAAU,OAAO,UAAU,iBACrC,WAAW,QAAQ,UAAU,cAAc,OAAO,KAAK,mBACjD;;;;;;;;YAUI,WAAW,OAAO,UAAU,eACvC,UAAU,UAAU,OAAO,IAE3B,OAAO,MACJ,SAAS,UAAU,MAAM,YAAY,cAAc,SACnD,iBAAiB,UAAU,UAAU,MAAM,qBACzC,QAAQ,sBAAsB,UAAU,UAAU,MAAM,SACxD,SAAS,sBAAsB,UAAU,UAAU,MAAM,kBAE1D,QAAQ,wBAAwB,UAAU,UAAU,MAAM;YAEnD,YAAY,YACtB,KAAK,aAAa,WAAW,OAAO;;wBAItB,YAAY,OAC3B,IAAI,iBAAiB,SACnB,YAAY"}
@@ -0,0 +1,19 @@
1
+ //#region src/methods.ts
2
+ /** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */
3
+ const CALL_METHODS = [
4
+ "get",
5
+ "post",
6
+ "put",
7
+ "patch",
8
+ "delete",
9
+ "options"
10
+ ];
11
+ /** The method calls for a client, each delegating to `api('METHOD /route', …)`. */
12
+ function methodCalls(fn) {
13
+ const call = (method) => (route, config) => fn(`${method.toUpperCase()} ${route}`, config);
14
+ return Object.fromEntries(CALL_METHODS.map((method) => [method, call(method)]));
15
+ }
16
+ //#endregion
17
+ export { CALL_METHODS, methodCalls };
18
+
19
+ //# sourceMappingURL=methods.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.mjs","names":[],"sources":["../src/methods.ts"],"sourcesContent":["import type {\n\tExtractEndpointResponse,\n\tExtractMethod,\n\tFilteredRequestConfig,\n\tIsConfigRequired,\n\tTypedApiFunction,\n\tTypedEndpoint,\n} from './types';\n\n/** The HTTP methods a client offers as calls: `api.get(…)`, `api.post(…)`. */\nexport const CALL_METHODS = [\n\t'get',\n\t'post',\n\t'put',\n\t'patch',\n\t'delete',\n\t'options',\n] as const;\n\nexport type CallMethod = (typeof CALL_METHODS)[number];\n\n/**\n * The routes that answer `M` — only routes with a `POST` appear in `api.post`,\n * so a route that exists under another method is a type error, not a 405.\n */\nexport type RoutesFor<Paths, M extends CallMethod> = {\n\t[R in keyof Paths]: M extends ExtractMethod<Paths, R> ? R : never;\n}[keyof Paths] &\n\tstring;\n\n/**\n * One method's call: `api.post('/users', { body })`.\n *\n * The second argument has only the keys the endpoint declares, and is required\n * exactly when something in it is — the same rule as `api('POST /users', …)`,\n * which this is sugar over.\n */\nexport type MethodCall<Paths, M extends CallMethod> = <\n\tR extends RoutesFor<Paths, M>,\n>(\n\troute: R,\n\t...args: `${Uppercase<M>} ${R}` extends TypedEndpoint<Paths>\n\t\t? IsConfigRequired<Paths, `${Uppercase<M>} ${R}`> extends true\n\t\t\t? [config: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>]\n\t\t\t: [config?: FilteredRequestConfig<Paths, `${Uppercase<M>} ${R}`>]\n\t\t: never\n) => Promise<ExtractEndpointResponse<Paths, `${Uppercase<M>} ${R}`>>;\n\nexport type MethodCalls<Paths> = {\n\t[M in CallMethod]: MethodCall<Paths, M>;\n};\n\n/** The method calls for a client, each delegating to `api('METHOD /route', …)`. */\nexport function methodCalls<Paths>(\n\tfn: TypedApiFunction<Paths>,\n): MethodCalls<Paths> {\n\tconst call =\n\t\t(method: CallMethod) =>\n\t\t(route: string, config?: unknown): Promise<unknown> =>\n\t\t\t(fn as (endpoint: string, config?: unknown) => Promise<unknown>)(\n\t\t\t\t`${method.toUpperCase()} ${route}`,\n\t\t\t\tconfig,\n\t\t\t);\n\n\treturn Object.fromEntries(\n\t\tCALL_METHODS.map((method) => [method, call(method)]),\n\t) as unknown as MethodCalls<Paths>;\n}\n"],"mappings":";;AAUA,MAAa,eAAe;CAC3B;CACA;CACA;CACA;CACA;CACA;AACD;;AAoCA,SAAgB,YACf,IACqB;CACrB,MAAM,QACJ,YACA,OAAe,WACd,GACA,GAAG,OAAO,YAAY,EAAE,GAAG,SAC3B,MACD;CAEF,OAAO,OAAO,YACb,aAAa,KAAK,WAAW,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CACpD;AACD"}