@geekmidas/client 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/auth-fetcher.cjs +1 -1
- package/dist/auth-fetcher.d.cts +1 -1
- package/dist/auth-fetcher.d.mts +1 -1
- package/dist/auth-fetcher.mjs +1 -1
- package/dist/endpoint-hooks.d.cts +1 -1
- package/dist/endpoint-hooks.d.mts +1 -1
- package/dist/{fetcher-BG3q_AKO.cjs → fetcher-CbQRQD5f.cjs} +13 -2
- package/dist/fetcher-CbQRQD5f.cjs.map +1 -0
- package/dist/{fetcher-DSSmqcRW.mjs → fetcher-DNt7DDn9.mjs} +13 -2
- package/dist/fetcher-DNt7DDn9.mjs.map +1 -0
- package/dist/fetcher.cjs +1 -1
- package/dist/fetcher.d.cts +7 -3
- package/dist/fetcher.d.cts.map +1 -1
- package/dist/fetcher.d.mts +7 -3
- package/dist/fetcher.d.mts.map +1 -1
- package/dist/fetcher.mjs +1 -1
- package/dist/openapi-hooks.cjs +1 -1
- package/dist/openapi-hooks.d.cts +4 -4
- package/dist/openapi-hooks.d.mts +1 -1
- package/dist/openapi-hooks.mjs +1 -1
- package/dist/react-query.cjs +1 -1
- package/dist/react-query.d.cts +8 -8
- package/dist/react-query.d.mts +1 -1
- package/dist/react-query.mjs +1 -1
- package/dist/{types-4K4N-Fl1.d.cts → types-BtQ80bpa.d.mts} +10 -2
- package/dist/{types-4K4N-Fl1.d.cts.map → types-BtQ80bpa.d.mts.map} +1 -1
- package/dist/{types-hhkZWjQn.d.mts → types-C7tGYTBD.d.cts} +10 -2
- package/dist/{types-hhkZWjQn.d.mts.map → types-C7tGYTBD.d.cts.map} +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.mts +2 -2
- package/package.json +3 -3
- package/src/__tests__/fetcher.spec.ts +84 -0
- package/src/fetcher.ts +18 -2
- package/src/types.ts +11 -0
- package/dist/fetcher-BG3q_AKO.cjs.map +0 -1
- package/dist/fetcher-DSSmqcRW.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @geekmidas/client
|
|
2
2
|
|
|
3
|
+
## 4.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ✨ [`414e7e1`](https://github.com/geekmidas/toolbox/commit/414e7e1f8ca038e397a5533279bf3a2f6f193a6d) Thanks [@geekmidas](https://github.com/geekmidas)! - Add .wrap on the fetch client for no throw handling
|
|
8
|
+
|
|
3
9
|
## 4.0.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/auth-fetcher.cjs
CHANGED
package/dist/auth-fetcher.d.cts
CHANGED
package/dist/auth-fetcher.d.mts
CHANGED
package/dist/auth-fetcher.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-
|
|
1
|
+
import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-C7tGYTBD.cjs";
|
|
2
2
|
import { QueryClient, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
3
3
|
|
|
4
4
|
//#region src/endpoint-hooks.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-
|
|
1
|
+
import { ExtractEndpointResponse, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, QueryEndpoint, TypedApiFunction } from "./types-BtQ80bpa.mjs";
|
|
2
2
|
import { QueryClient, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from "@tanstack/react-query";
|
|
3
3
|
|
|
4
4
|
//#region src/endpoint-hooks.d.ts
|
|
@@ -60,6 +60,15 @@ var TypedFetcher = class TypedFetcher {
|
|
|
60
60
|
throw error;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
wrap() {
|
|
64
|
+
return (endpoint, config) => this.request(endpoint, config).then((data) => ({
|
|
65
|
+
data,
|
|
66
|
+
error: null
|
|
67
|
+
}), (error) => ({
|
|
68
|
+
data: null,
|
|
69
|
+
error
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
63
72
|
parseEndpoint(endpoint) {
|
|
64
73
|
const [method, ...routeParts] = endpoint.split(" ");
|
|
65
74
|
const route = routeParts.join(" ");
|
|
@@ -71,7 +80,9 @@ var TypedFetcher = class TypedFetcher {
|
|
|
71
80
|
};
|
|
72
81
|
function createTypedFetcher(options) {
|
|
73
82
|
const fetcher = new TypedFetcher(options);
|
|
74
|
-
|
|
83
|
+
const fn = (endpoint, config) => fetcher.request(endpoint, config);
|
|
84
|
+
fn.wrap = () => fetcher.wrap();
|
|
85
|
+
return fn;
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
//#endregion
|
|
@@ -87,4 +98,4 @@ Object.defineProperty(exports, 'createTypedFetcher', {
|
|
|
87
98
|
return createTypedFetcher;
|
|
88
99
|
}
|
|
89
100
|
});
|
|
90
|
-
//# sourceMappingURL=fetcher-
|
|
101
|
+
//# sourceMappingURL=fetcher-CbQRQD5f.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher-CbQRQD5f.cjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport type {\n\tEndpointString,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\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() {\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>>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ data, error: null }),\n\t\t\t\t(error) => ({ data: null, error }),\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\tfn.wrap = () => fetcher.wrap();\n\n\treturn fn;\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;;AAaA,IAAa,eAAb,MAAa,aAAoB;CAChC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACxC,MAAI,GACH,QAAO;AAGR,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC5D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGjC,aACQ,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAGzC,QAAM,IAAI,MAAM;CAChB;CAED,YAAYC,UAA0B,CAAE,GAAE;AACzC,OAAK,UAAU,QAAQ,WAAW;AAClC,OAAK,iBAAiB,QAAQ,WAAW,CAAE;AAC3C,OAAK,UAAU;AACf,OAAK,UAAU,aAAa,WAAW,QAAQ,MAAM;CACrD;CAED,MAAM,QACLC,UACAC,QAC6C;EAC7C,MAAM,EAAE,QAAQ,OAAO,GAAG,KAAK,cAAc,SAAS;EAGtD,IAAI,MAAM;AACV,MAAI,UAAU,YAAY,UAAU,OAAO,OAC1C,QAAO,QAAQ,OAAO,OAAkC,CAAC,QACxD,CAAC,CAAC,KAAK,MAAM,KAAK;AACjB,SAAM,IAAI,SAAS,GAAG,IAAI,IAAI,mBAAmB,OAAO,MAAM,CAAC,CAAC;EAChE,EACD;AAIF,MAAI,UAAU,WAAW,UAAU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,aAAa,IAAI;GAAI;EAAO;CACrD;AACD;AAED,SAAgB,mBAA0BG,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB;CACxC,MAAM,KAAK,CACVH,UACAC,WACI,QAAQ,QAAQ,UAAU,OAAO;AAEtC,IAAG,OAAO,MAAM,QAAQ,MAAM;AAE9B,QAAO;AACP"}
|
|
@@ -59,6 +59,15 @@ var TypedFetcher = class TypedFetcher {
|
|
|
59
59
|
throw error;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
wrap() {
|
|
63
|
+
return (endpoint, config) => this.request(endpoint, config).then((data) => ({
|
|
64
|
+
data,
|
|
65
|
+
error: null
|
|
66
|
+
}), (error) => ({
|
|
67
|
+
data: null,
|
|
68
|
+
error
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
62
71
|
parseEndpoint(endpoint) {
|
|
63
72
|
const [method, ...routeParts] = endpoint.split(" ");
|
|
64
73
|
const route = routeParts.join(" ");
|
|
@@ -70,9 +79,11 @@ var TypedFetcher = class TypedFetcher {
|
|
|
70
79
|
};
|
|
71
80
|
function createTypedFetcher(options) {
|
|
72
81
|
const fetcher = new TypedFetcher(options);
|
|
73
|
-
|
|
82
|
+
const fn = (endpoint, config) => fetcher.request(endpoint, config);
|
|
83
|
+
fn.wrap = () => fetcher.wrap();
|
|
84
|
+
return fn;
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
//#endregion
|
|
77
88
|
export { TypedFetcher, createTypedFetcher };
|
|
78
|
-
//# sourceMappingURL=fetcher-
|
|
89
|
+
//# sourceMappingURL=fetcher-DNt7DDn9.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetcher-DNt7DDn9.mjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport type {\n\tEndpointString,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\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() {\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>>> =>\n\t\t\tthis.request(endpoint, config).then(\n\t\t\t\t(data) => ({ data, error: null }),\n\t\t\t\t(error) => ({ data: null, error }),\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\tfn.wrap = () => fetcher.wrap();\n\n\treturn fn;\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;AAaA,IAAa,eAAb,MAAa,aAAoB;CAChC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACxC,MAAI,GACH,QAAO;AAGR,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC5D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGjC,aACQ,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAGzC,QAAM,IAAI,MAAM;CAChB;CAED,YAAYC,UAA0B,CAAE,GAAE;AACzC,OAAK,UAAU,QAAQ,WAAW;AAClC,OAAK,iBAAiB,QAAQ,WAAW,CAAE;AAC3C,OAAK,UAAU;AACf,OAAK,UAAU,aAAa,WAAW,QAAQ,MAAM;CACrD;CAED,MAAM,QACLC,UACAC,QAC6C;EAC7C,MAAM,EAAE,QAAQ,OAAO,GAAG,KAAK,cAAc,SAAS;EAGtD,IAAI,MAAM;AACV,MAAI,UAAU,YAAY,UAAU,OAAO,OAC1C,QAAO,QAAQ,OAAO,OAAkC,CAAC,QACxD,CAAC,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PD,UACmB;EACnB,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,SAAS,MAAM,IAAI;EACnD,MAAM,QAAQ,WAAW,KAAK,IAAI;AAClC,SAAO;GAAE,QAAQ,QAAQ,aAAa,IAAI;GAAI;EAAO;CACrD;AACD;AAED,SAAgB,mBAA0BG,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB;CACxC,MAAM,KAAK,CACVH,UACAC,WACI,QAAQ,QAAQ,UAAU,OAAO;AAEtC,IAAG,OAAO,MAAM,QAAQ,MAAM;AAE9B,QAAO;AACP"}
|
package/dist/fetcher.cjs
CHANGED
package/dist/fetcher.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint } from "./types-
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types-C7tGYTBD.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/fetcher.d.ts
|
|
4
4
|
declare class TypedFetcher<Paths> {
|
|
@@ -9,12 +9,16 @@ declare class TypedFetcher<Paths> {
|
|
|
9
9
|
static getFetchFn(fn?: FetchFn): FetchFn;
|
|
10
10
|
constructor(options?: FetcherOptions);
|
|
11
11
|
request<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
|
|
12
|
+
wrap(): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
12
13
|
private parseEndpoint;
|
|
13
14
|
}
|
|
14
|
-
declare function createTypedFetcher<Paths>(options?: FetcherOptions):
|
|
15
|
+
declare function createTypedFetcher<Paths>(options?: FetcherOptions): {
|
|
16
|
+
<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
|
|
17
|
+
wrap(): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T> | undefined) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
18
|
+
};
|
|
15
19
|
type FetchFn = typeof fetch;
|
|
16
20
|
//# sourceMappingURL=fetcher.d.ts.map
|
|
17
21
|
|
|
18
22
|
//#endregion
|
|
19
|
-
export { FetchFn, FetcherOptions, TypedFetcher, createTypedFetcher };
|
|
23
|
+
export { FetchFn, FetcherOptions, TypedFetcher, WrappedResult, createTypedFetcher };
|
|
20
24
|
//# sourceMappingURL=fetcher.d.cts.map
|
package/dist/fetcher.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.cts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fetcher.d.cts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;cAaa;EAAA,QAAA,OAAY;EAAA,QAAA,cAAA;EAAA,QAMD,OAAA;EAAO,QAAG,OAAA;EAAO,OAmBnB,UAAA,CAAA,EAAA,CAAA,EAnBE,OAmBF,CAAA,EAnBY,OAmBZ;EAAmB,WAOF,CAAA,OAAA,CAAA,EAPjB,cAOiB;EAAK,OAAnB,CAAA,UAAA,aAAA,CAAc,KAAd,CAAA,CAAA,CAAA,QAAA,EACb,CADa,EAAA,MAAA,CAAA,EAEd,qBAFc,CAEQ,KAFR,EAEe,CAFf,CAAA,CAAA,EAGrB,OAHqB,CAGb,uBAHa,CAGW,KAHX,EAGkB,CAHlB,CAAA,CAAA;EAAa,IAC1B,CAAA,CAAA,EAAA,CAAA,UAsFQ,aAtFR,CAsFsB,KAtFtB,CAAA,CAAA,CAAA,QAAA,EAuFC,CAvFD,EAAA,MAAA,CAAA,EAwFA,qBAxFA,CAwFsB,KAxFtB,EAwF6B,CAxF7B,CAAA,EAAA,GAyFP,OAzFO,CAyFC,aAzFD,CAyFe,uBAzFf,CAyFuC,KAzFvC,EAyF8C,CAzF9C,CAAA,CAAA,CAAA;EAAC,QACoB,aAAA;;AAAtB,iBAwGK,kBAxGL,CAAA,KAAA,CAAA,CAAA,OAAA,CAAA,EAwGyC,cAxGzC,CAAA,EAAA;EAAqB,CAAA,UA0GT,aAzGa,CAyGC,KAzGD,CAAA,CAAA,CAAA,QAAA,EA0GxB,CA1GwB,EAAA,MAAA,CAAA,EA2GzB,qBA3GyB,CA2GH,KA3GG,EA2GI,CA3GJ,CAAA,CAAA,EA2GM,OA3GN,CA2GM,uBA3GN,CA2GM,KA3GN,EA2GM,CA3GN,CAAA,CAAA;EAAK,IAAE,EAAA,EAAA,CAAA,UAoFhC,aApFgC,CAoFhC,KApFgC,CAAA,CAAA,CAAA,QAAA,EAoFhC,CApFgC,EAAA,MAAA,CAAA,EAoFhC,qBApFgC,CAoFhC,KApFgC,EAoFhC,CApFgC,CAAA,GAAA,SAAA,EAAA,GAoFhC,OApFgC,CAoFhC,aApFgC,CAoFhC,uBApFgC,CAoFhC,KApFgC,EAoFhC,CApFgC,CAAA,CAAA,CAAA;CAAC;AAAxC,KAmHQ,OAAA,GAnHR,OAmHyB,KAnHzB"}
|
package/dist/fetcher.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint } from "./types-
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, TypedEndpoint, WrappedResult } from "./types-BtQ80bpa.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/fetcher.d.ts
|
|
4
4
|
declare class TypedFetcher<Paths> {
|
|
@@ -9,12 +9,16 @@ declare class TypedFetcher<Paths> {
|
|
|
9
9
|
static getFetchFn(fn?: FetchFn): FetchFn;
|
|
10
10
|
constructor(options?: FetcherOptions);
|
|
11
11
|
request<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
|
|
12
|
+
wrap(): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
12
13
|
private parseEndpoint;
|
|
13
14
|
}
|
|
14
|
-
declare function createTypedFetcher<Paths>(options?: FetcherOptions):
|
|
15
|
+
declare function createTypedFetcher<Paths>(options?: FetcherOptions): {
|
|
16
|
+
<T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>): Promise<ExtractEndpointResponse<Paths, T>>;
|
|
17
|
+
wrap(): <T extends TypedEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T> | undefined) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
18
|
+
};
|
|
15
19
|
type FetchFn = typeof fetch;
|
|
16
20
|
//# sourceMappingURL=fetcher.d.ts.map
|
|
17
21
|
|
|
18
22
|
//#endregion
|
|
19
|
-
export { FetchFn, FetcherOptions, TypedFetcher, createTypedFetcher };
|
|
23
|
+
export { FetchFn, FetcherOptions, TypedFetcher, WrappedResult, createTypedFetcher };
|
|
20
24
|
//# sourceMappingURL=fetcher.d.mts.map
|
package/dist/fetcher.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.mts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fetcher.d.mts","names":[],"sources":["../src/fetcher.ts"],"sourcesContent":[],"mappings":";;;cAaa;EAAA,QAAA,OAAY;EAAA,QAAA,cAAA;EAAA,QAMD,OAAA;EAAO,QAAG,OAAA;EAAO,OAmBnB,UAAA,CAAA,EAAA,CAAA,EAnBE,OAmBF,CAAA,EAnBY,OAmBZ;EAAmB,WAOF,CAAA,OAAA,CAAA,EAPjB,cAOiB;EAAK,OAAnB,CAAA,UAAA,aAAA,CAAc,KAAd,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k = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_fetcher = require('./fetcher-
|
|
2
|
+
const require_fetcher = require('./fetcher-CbQRQD5f.cjs');
|
|
3
3
|
const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
|
|
4
4
|
|
|
5
5
|
//#region src/openapi-hooks.ts
|
package/dist/openapi-hooks.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FetcherOptions } from "./types-
|
|
2
|
-
import * as
|
|
1
|
+
import { FetcherOptions } from "./types-C7tGYTBD.cjs";
|
|
2
|
+
import * as _tanstack_react_query0 from "@tanstack/react-query";
|
|
3
3
|
import { UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
//#region src/openapi-hooks.d.ts
|
|
@@ -91,8 +91,8 @@ interface OperationRegistry {
|
|
|
91
91
|
declare function createOpenAPIHooks<Paths>(options?: FetcherOptions & {
|
|
92
92
|
operations?: OperationRegistry;
|
|
93
93
|
}): {
|
|
94
|
-
useQuery: <OpId extends OperationsByMethod<Paths, "get">>(operationId: OpId, config?: RemoveNever<OperationParams<Paths, OpId>>, options?: Omit<UseQueryOptions<OperationResponse<Paths, OpId>, Error>, "queryKey" | "queryFn">) =>
|
|
95
|
-
useMutation: <OpId extends Exclude<OperationId<Paths>, OperationsByMethod<Paths, "get">>>(operationId: OpId, options?: Omit<UseMutationOptions<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>>, "mutationFn">) =>
|
|
94
|
+
useQuery: <OpId extends OperationsByMethod<Paths, "get">>(operationId: OpId, config?: RemoveNever<OperationParams<Paths, OpId>>, options?: Omit<UseQueryOptions<OperationResponse<Paths, OpId>, Error>, "queryKey" | "queryFn">) => _tanstack_react_query0.UseQueryResult<_tanstack_react_query0.NoInfer<OperationResponse<Paths, OpId>>, Error>;
|
|
95
|
+
useMutation: <OpId extends Exclude<OperationId<Paths>, OperationsByMethod<Paths, "get">>>(operationId: OpId, options?: Omit<UseMutationOptions<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>>, "mutationFn">) => _tanstack_react_query0.UseMutationResult<OperationResponse<Paths, OpId>, Error, RemoveNever<OperationParams<Paths, OpId>>, unknown>;
|
|
96
96
|
};
|
|
97
97
|
//#endregion
|
|
98
98
|
export { createOpenAPIHooks };
|
package/dist/openapi-hooks.d.mts
CHANGED
package/dist/openapi-hooks.mjs
CHANGED
package/dist/react-query.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_fetcher = require('./fetcher-
|
|
2
|
+
const require_fetcher = require('./fetcher-CbQRQD5f.cjs');
|
|
3
3
|
const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
|
|
4
4
|
const react = require_chunk.__toESM(require("react"));
|
|
5
5
|
|
package/dist/react-query.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types-
|
|
2
|
-
import * as
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types-C7tGYTBD.cjs";
|
|
2
|
+
import * as _tanstack_react_query3 from "@tanstack/react-query";
|
|
3
3
|
import { QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
//#region src/react-query.d.ts
|
|
@@ -10,15 +10,15 @@ declare class TypedQueryClient<Paths> {
|
|
|
10
10
|
private fetcher;
|
|
11
11
|
private queryClient?;
|
|
12
12
|
constructor(options?: TypedQueryClientOptions);
|
|
13
|
-
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
14
|
-
useMutation<T extends MutationEndpoint<Paths>>(endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>):
|
|
13
|
+
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>): _tanstack_react_query3.UseQueryResult<_tanstack_react_query3.NoInfer<ExtractEndpointResponse<Paths, T>>, Response>;
|
|
14
|
+
useMutation<T extends MutationEndpoint<Paths>>(endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>): _tanstack_react_query3.UseMutationResult<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>, unknown>;
|
|
15
15
|
useInfiniteQuery<T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
16
16
|
pages: TPageData[];
|
|
17
17
|
pageParams: TPageParam[];
|
|
18
18
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
19
19
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
20
20
|
initialPageParam: TPageParam;
|
|
21
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
21
|
+
}, config?: FilteredRequestConfig<Paths, T>): _tanstack_react_query3.UseInfiniteQueryResult<{
|
|
22
22
|
pages: TPageData[];
|
|
23
23
|
pageParams: TPageParam[];
|
|
24
24
|
}, Response>;
|
|
@@ -47,15 +47,15 @@ declare class TypedQueryClient<Paths> {
|
|
|
47
47
|
setQueryClient(queryClient: QueryClient): void;
|
|
48
48
|
}
|
|
49
49
|
declare function createTypedQueryClient<Paths>(options?: TypedQueryClientOptions): TypedQueryClient<Paths>;
|
|
50
|
-
declare function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
51
|
-
declare function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>):
|
|
50
|
+
declare function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>): _tanstack_react_query3.UseQueryResult<_tanstack_react_query3.NoInfer<ExtractEndpointResponse<Paths, T>>, Response>;
|
|
51
|
+
declare function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(client: TypedQueryClient<Paths>, endpoint: T, options?: Omit<UseMutationOptions<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>>, 'mutationFn'>): _tanstack_react_query3.UseMutationResult<ExtractEndpointResponse<Paths, T>, Response, FilteredRequestConfig<Paths, T>, unknown>;
|
|
52
52
|
declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
53
53
|
pages: TPageData[];
|
|
54
54
|
pageParams: TPageParam[];
|
|
55
55
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
56
56
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
57
57
|
initialPageParam: TPageParam;
|
|
58
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
58
|
+
}, config?: FilteredRequestConfig<Paths, T>): _tanstack_react_query3.UseInfiniteQueryResult<{
|
|
59
59
|
pages: TPageData[];
|
|
60
60
|
pageParams: TPageParam[];
|
|
61
61
|
}, Response>;
|
package/dist/react-query.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types-
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types-BtQ80bpa.mjs";
|
|
2
2
|
import * as _tanstack_react_query3 from "@tanstack/react-query";
|
|
3
3
|
import { QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
4
|
|
package/dist/react-query.mjs
CHANGED
|
@@ -96,6 +96,14 @@ interface FetcherOptions {
|
|
|
96
96
|
onError?: (error: Error) => void | Promise<void>;
|
|
97
97
|
fetch?: typeof fetch;
|
|
98
98
|
}
|
|
99
|
+
type WrappedResult<T> = {
|
|
100
|
+
data: T;
|
|
101
|
+
error: null;
|
|
102
|
+
} | {
|
|
103
|
+
data: null;
|
|
104
|
+
error: unknown;
|
|
105
|
+
};
|
|
106
|
+
type WrappedApiFunction<Paths> = <T extends TypedEndpoint<Paths>>(endpoint: T, ...args: IsConfigRequired<Paths, T> extends true ? [config: FilteredRequestConfig<Paths, T>] : [config?: FilteredRequestConfig<Paths, T>]) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
99
107
|
//#endregion
|
|
100
|
-
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint };
|
|
101
|
-
//# sourceMappingURL=types-
|
|
108
|
+
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult };
|
|
109
|
+
//# sourceMappingURL=types-BtQ80bpa.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-BtQ80bpa.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";KAAY,6BAA6B;AAAzC,KAEK,UAAA,GAFO,KAAa,GAAA,MAAgB,GAAA,KAAK,GAAA,OAAA,GAAA,QAAA,GAAA,MAAA,GAAA,SAAA;AAEzC,KASO,aATG,CAAA,KAAA,EAAA,cASgC,aAThC,CAS8C,KAT9C,CAAA,CAAA,GASwD,OATxD,CAAA,MAUR,KAVQ,CAUF,KAVE,CAAA,EAWd,UAXc,CAAA;AASH,KAKA,iBALa,CAAA,KAAA,EAAA,cAOV,aAPU,CAOI,KAPJ,CAAA,CAAA,GAQrB,KARqB,CAQf,KARe,CAAA,SAAA;EAAA,UAAA,CAAA,EAAA;IAAoC,IAAA,CAAA,EAAA,KAAA,EAAA;EAAK,CAAA;CAAN,GAWzD,CAXyD,GACrD,KAAA;AAAM,KAaD,kBAbC,CAAA,KAAA,EAAA,cAeE,aAfF,CAegB,KAfhB,CAAA,EAAA,eAgBG,aAhBH,CAgBiB,KAhBjB,EAgBwB,KAhBxB,CAAA,CAAA,GAiBT,KAjB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2B,OA7H3B,CA6HmC,WA7HnC,CAAA;EAAA,UACV,CAAA,EAAA,CAAA,QAAA,EA6HU,QA7HV,EAAA,GA6HuB,QA7HvB,GA6HkC,OA7HlC,CA6H0C,QA7H1C,CAAA;EAAK,OAAnB,CAAA,EAAA,CAAA,KAAA,EA8HkB,KA9HlB,EAAA,GAAA,IAAA,GA8HmC,OA9HnC,CAAA,IAAA,CAAA;EAAa,KAA2B,CAAA,EAAA,OA+HzB,KA/HyB;;AAAoB,KAkIjD,aAlIiD,CAAA,CAAA,CAAA,GAAA;EAGjD,IAAA,EAgID,CAhIC;EAAsB,KAAA,EAAA,IAAA;CAAA,GAAA;EAGX,IAAnB,EAAA,IAAA;EAAa,KACd,EAAA,OAAA;CAAC;AACA,KA8HQ,kBA9HR,CAAA,KAAA,CAAA,GAAA,CAAA,UA8H+C,aA9H/C,CA8H6D,KA9H7D,CAAA,CAAA,CAAA,QAAA,EA+HO,CA/HP,EAAA,GAAA,IAAA,EAgIM,gBAhIN,CAgIuB,KAhIvB,EAgI8B,CAhI9B,CAAA,SAAA,IAAA,GAAA,CAAA,MAAA,EAiIS,qBAjIT,CAiI+B,KAjI/B,EAiIsC,CAjItC,CAAA,CAAA,GAAA,CAAA,MAAA,GAkIU,qBAlIV,CAkIgC,KAlIhC,EAkIuC,CAlIvC,CAAA,CAAA,EAAA,GAmIC,OAnID,CAmIS,aAnIT,CAmIuB,uBAnIvB,CAmI+C,KAnI/C,EAmIsD,CAnItD,CAAA,CAAA,CAAA"}
|
|
@@ -96,6 +96,14 @@ interface FetcherOptions {
|
|
|
96
96
|
onError?: (error: Error) => void | Promise<void>;
|
|
97
97
|
fetch?: typeof fetch;
|
|
98
98
|
}
|
|
99
|
+
type WrappedResult<T> = {
|
|
100
|
+
data: T;
|
|
101
|
+
error: null;
|
|
102
|
+
} | {
|
|
103
|
+
data: null;
|
|
104
|
+
error: unknown;
|
|
105
|
+
};
|
|
106
|
+
type WrappedApiFunction<Paths> = <T extends TypedEndpoint<Paths>>(endpoint: T, ...args: IsConfigRequired<Paths, T> extends true ? [config: FilteredRequestConfig<Paths, T>] : [config?: FilteredRequestConfig<Paths, T>]) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
99
107
|
//#endregion
|
|
100
|
-
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint };
|
|
101
|
-
//# sourceMappingURL=types-
|
|
108
|
+
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult };
|
|
109
|
+
//# sourceMappingURL=types-C7tGYTBD.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-C7tGYTBD.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";KAAY,6BAA6B;AAAzC,KAEK,UAAA,GAFO,KAAa,GAAA,MAAgB,GAAA,KAAK,GAAA,OAAA,GAAA,QAAA,GAAA,MAAA,GAAA,SAAA;AAEzC,KASO,aATG,CAAA,KAAA,EAAA,cASgC,aAThC,CAS8C,KAT9C,CAAA,CAAA,GASwD,OATxD,CAAA,MAUR,KAVQ,CAUF,KAVE,CAAA,EAWd,UAXc,CAAA;AASH,KAKA,iBALa,CAAA,KAAA,EAAA,cAOV,aAPU,CAOI,KAPJ,CAAA,CAAA,GAQrB,KARqB,CAQf,KARe,CAA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+1,2 @@
|
|
|
1
|
-
import { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint } from "./types-
|
|
2
|
-
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint };
|
|
1
|
+
import { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types-C7tGYTBD.cjs";
|
|
2
|
+
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint } from "./types-
|
|
2
|
-
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint };
|
|
1
|
+
import { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult } from "./types-BtQ80bpa.mjs";
|
|
2
|
+
export { EndpointString, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geekmidas/client",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"react": ">=18.0.0",
|
|
77
77
|
"react-dom": ">=18.0.0",
|
|
78
78
|
"zod": "~4.1.13",
|
|
79
|
-
"@geekmidas/
|
|
80
|
-
"@geekmidas/
|
|
79
|
+
"@geekmidas/constructs": "^3.0.3",
|
|
80
|
+
"@geekmidas/schema": "^1.0.0"
|
|
81
81
|
},
|
|
82
82
|
"peerDependenciesMeta": {
|
|
83
83
|
"@geekmidas/constructs": {
|
|
@@ -382,6 +382,90 @@ describe('TypedFetcher', () => {
|
|
|
382
382
|
});
|
|
383
383
|
});
|
|
384
384
|
|
|
385
|
+
describe('wrap', () => {
|
|
386
|
+
it('should return { data, error: null } on success', async () => {
|
|
387
|
+
const client = createTypedFetcher<paths>({
|
|
388
|
+
baseURL: 'https://api.example.com',
|
|
389
|
+
});
|
|
390
|
+
const wrappedClient = client.wrap();
|
|
391
|
+
|
|
392
|
+
const result = await wrappedClient('GET /users');
|
|
393
|
+
|
|
394
|
+
expect(result.error).toBeNull();
|
|
395
|
+
expect(result.data).toEqual({
|
|
396
|
+
users: [
|
|
397
|
+
{ id: '1', name: 'John Doe', email: 'john@example.com' },
|
|
398
|
+
{ id: '2', name: 'Jane Smith', email: 'jane@example.com' },
|
|
399
|
+
],
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('should return { data: null, error } on failure', async () => {
|
|
404
|
+
const client = createTypedFetcher<paths>({
|
|
405
|
+
baseURL: 'https://api.example.com',
|
|
406
|
+
});
|
|
407
|
+
const wrappedClient = client.wrap();
|
|
408
|
+
|
|
409
|
+
const result = await wrappedClient('GET /users/{id}', {
|
|
410
|
+
params: { id: '404' },
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
expect(result.data).toBeNull();
|
|
414
|
+
expect(result.error).toBeInstanceOf(Response);
|
|
415
|
+
const response = result.error as Response;
|
|
416
|
+
expect(response.status).toBe(404);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it('should return { data: null, error } on 500 errors', async () => {
|
|
420
|
+
const client = createTypedFetcher<paths>({
|
|
421
|
+
baseURL: 'https://api.example.com',
|
|
422
|
+
});
|
|
423
|
+
const wrappedClient = client.wrap();
|
|
424
|
+
|
|
425
|
+
const result = await wrappedClient('GET /error');
|
|
426
|
+
|
|
427
|
+
expect(result.data).toBeNull();
|
|
428
|
+
expect(result.error).toBeInstanceOf(Response);
|
|
429
|
+
const response = result.error as Response;
|
|
430
|
+
expect(response.status).toBe(500);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('should work with path params and body', async () => {
|
|
434
|
+
const client = createTypedFetcher<paths>({
|
|
435
|
+
baseURL: 'https://api.example.com',
|
|
436
|
+
});
|
|
437
|
+
const wrappedClient = client.wrap();
|
|
438
|
+
|
|
439
|
+
const result = await wrappedClient('PUT /users/{id}', {
|
|
440
|
+
params: { id: '456' },
|
|
441
|
+
body: { name: 'Updated Name' },
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
expect(result.error).toBeNull();
|
|
445
|
+
expect(result.data).toEqual({
|
|
446
|
+
id: '456',
|
|
447
|
+
name: 'Updated Name',
|
|
448
|
+
email: 'john@example.com',
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('should still call onError handler', async () => {
|
|
453
|
+
const onError = vi.fn();
|
|
454
|
+
const client = createTypedFetcher<paths>({
|
|
455
|
+
baseURL: 'https://api.example.com',
|
|
456
|
+
onError,
|
|
457
|
+
});
|
|
458
|
+
const wrappedClient = client.wrap();
|
|
459
|
+
|
|
460
|
+
const result = await wrappedClient('GET /users/{id}', {
|
|
461
|
+
params: { id: '404' },
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
expect(result.data).toBeNull();
|
|
465
|
+
expect(onError).toHaveBeenCalledWith(expect.any(Response));
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
|
|
385
469
|
it('should URL encode special characters in path parameters', async () => {
|
|
386
470
|
// Mock fetch to verify the actual URL being called
|
|
387
471
|
const mockFetch = vi.fn(async (url: string) => {
|
package/src/fetcher.ts
CHANGED
|
@@ -6,9 +6,10 @@ import type {
|
|
|
6
6
|
FilteredRequestConfig,
|
|
7
7
|
ParseEndpoint,
|
|
8
8
|
TypedEndpoint,
|
|
9
|
+
WrappedResult,
|
|
9
10
|
} from './types';
|
|
10
11
|
|
|
11
|
-
export type { FetcherOptions } from './types';
|
|
12
|
+
export type { FetcherOptions, WrappedResult } from './types';
|
|
12
13
|
|
|
13
14
|
export class TypedFetcher<Paths> {
|
|
14
15
|
private baseURL: string;
|
|
@@ -128,6 +129,17 @@ export class TypedFetcher<Paths> {
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
wrap() {
|
|
133
|
+
return <T extends TypedEndpoint<Paths>>(
|
|
134
|
+
endpoint: T,
|
|
135
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
136
|
+
): Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>> =>
|
|
137
|
+
this.request(endpoint, config).then(
|
|
138
|
+
(data) => ({ data, error: null }),
|
|
139
|
+
(error) => ({ data: null, error }),
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
131
143
|
private parseEndpoint<T extends EndpointString>(
|
|
132
144
|
endpoint: T,
|
|
133
145
|
): ParseEndpoint<T> {
|
|
@@ -139,10 +151,14 @@ export class TypedFetcher<Paths> {
|
|
|
139
151
|
|
|
140
152
|
export function createTypedFetcher<Paths>(options?: FetcherOptions) {
|
|
141
153
|
const fetcher = new TypedFetcher<Paths>(options);
|
|
142
|
-
|
|
154
|
+
const fn = <T extends TypedEndpoint<Paths>>(
|
|
143
155
|
endpoint: T,
|
|
144
156
|
config?: FilteredRequestConfig<Paths, T>,
|
|
145
157
|
) => fetcher.request(endpoint, config);
|
|
158
|
+
|
|
159
|
+
fn.wrap = () => fetcher.wrap();
|
|
160
|
+
|
|
161
|
+
return fn;
|
|
146
162
|
}
|
|
147
163
|
|
|
148
164
|
export type FetchFn = typeof fetch;
|
package/src/types.ts
CHANGED
|
@@ -209,3 +209,14 @@ export interface FetcherOptions {
|
|
|
209
209
|
onError?: (error: Error) => void | Promise<void>;
|
|
210
210
|
fetch?: typeof fetch;
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
export type WrappedResult<T> =
|
|
214
|
+
| { data: T; error: null }
|
|
215
|
+
| { data: null; error: unknown };
|
|
216
|
+
|
|
217
|
+
export type WrappedApiFunction<Paths> = <T extends TypedEndpoint<Paths>>(
|
|
218
|
+
endpoint: T,
|
|
219
|
+
...args: IsConfigRequired<Paths, T> extends true
|
|
220
|
+
? [config: FilteredRequestConfig<Paths, T>]
|
|
221
|
+
: [config?: FilteredRequestConfig<Paths, T>]
|
|
222
|
+
) => Promise<WrappedResult<ExtractEndpointResponse<Paths, T>>>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher-BG3q_AKO.cjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport type {\n\tEndpointString,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } 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\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\treturn <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;;AAYA,IAAa,eAAb,MAAa,aAAoB;CAChC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACxC,MAAI,GACH,QAAO;AAGR,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC5D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGjC,aACQ,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAGzC,QAAM,IAAI,MAAM;CAChB;CAED,YAAYC,UAA0B,CAAE,GAAE;AACzC,OAAK,UAAU,QA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SAAS,MAAM;AAClC,UAAO;EACP,SAAQ,OAAO;AAEf,OAAI,KAAK,QAAQ,QAEhB,OAAM,KAAK,QAAQ,QAAQ,MAAM;AAElC,SAAM;EACN;CACD;CAED,AAAQ,cACPF,UACmB;EACnB,MAAM,CAAC,QAAQ,GAAG,WAAW,GAAG,SAAS,MAAM,IAAI;EACnD,MAAM,QAAQ,WAAW,KAAK,IAAI;AAClC,SAAO;GAAE,QAAQ,QAAQ,aAAa,IAAI;GAAI;EAAO;CACrD;AACD;AAED,SAAgB,mBAA0BG,SAA0B;CACnE,MAAM,UAAU,IAAI,aAAoB;AACxC,QAAO,CACNH,UACAC,WACI,QAAQ,QAAQ,UAAU,OAAO;AACtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher-DSSmqcRW.mjs","names":["fn?: FetchFn","options: FetcherOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","requestConfig: RequestInit","options?: FetcherOptions"],"sources":["../src/fetcher.ts"],"sourcesContent":["import qs from 'qs';\nimport type {\n\tEndpointString,\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tParseEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport type { FetcherOptions } 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\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\treturn <T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) => fetcher.request(endpoint, config);\n}\n\nexport type FetchFn = typeof fetch;\n"],"mappings":";;;AAYA,IAAa,eAAb,MAAa,aAAoB;CAChC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,OAAO,WAAWA,IAAuB;AACxC,MAAI,GACH,QAAO;AAGR,aAAW,WAAW,sBAAsB,OAAO,UAAU,WAC5D,QAAO,OAAO,MAAM,KAAK,OAAO;AAGjC,aACQ,eAAe,sBACf,WAAW,UAAU,WAE5B,QAAO,WAAW,MAAM,KAAK,WAAW;AAGzC,QAAM,IAAI,MAAM;CAChB;C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