@geekmidas/client 10.0.0-alpha.98 → 10.0.0
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 +154 -0
- package/README.md +57 -40
- package/dist/auth-fetcher.cjs +5 -7
- package/dist/auth-fetcher.cjs.map +1 -1
- package/dist/auth-fetcher.d.cts +17 -15
- package/dist/auth-fetcher.d.cts.map +1 -1
- package/dist/auth-fetcher.d.mts +17 -15
- package/dist/auth-fetcher.d.mts.map +1 -1
- package/dist/auth-fetcher.mjs +5 -6
- package/dist/auth-fetcher.mjs.map +1 -1
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/endpoint-hooks.cjs +15 -11
- package/dist/endpoint-hooks.cjs.map +1 -1
- package/dist/endpoint-hooks.d.cts +7 -4
- package/dist/endpoint-hooks.d.cts.map +1 -1
- package/dist/endpoint-hooks.d.mts +7 -4
- package/dist/endpoint-hooks.d.mts.map +1 -1
- package/dist/endpoint-hooks.mjs +9 -5
- package/dist/endpoint-hooks.mjs.map +1 -1
- package/dist/fetcher-CakjC9C7.mjs +88 -0
- package/dist/fetcher-CakjC9C7.mjs.map +1 -0
- package/dist/fetcher-CwnSqc4D.cjs +100 -0
- package/dist/fetcher-CwnSqc4D.cjs.map +1 -0
- package/dist/fetcher.cjs +3 -115
- package/dist/fetcher.d.cts +8 -7
- package/dist/fetcher.d.cts.map +1 -1
- package/dist/fetcher.d.mts +8 -7
- package/dist/fetcher.d.mts.map +1 -1
- package/dist/fetcher.mjs +2 -90
- package/dist/infer.d.cts +13 -10
- package/dist/infer.d.cts.map +1 -1
- package/dist/infer.d.mts +13 -10
- package/dist/infer.d.mts.map +1 -1
- package/dist/infer.mjs +0 -1
- package/dist/openapi-hooks.cjs +16 -13
- package/dist/openapi-hooks.cjs.map +1 -1
- package/dist/openapi-hooks.d.cts +11 -8
- package/dist/openapi-hooks.d.cts.map +1 -1
- package/dist/openapi-hooks.d.mts +11 -8
- package/dist/openapi-hooks.d.mts.map +1 -1
- package/dist/openapi-hooks.mjs +12 -9
- package/dist/openapi-hooks.mjs.map +1 -1
- package/dist/openapi-types.d.cts +6 -5
- package/dist/openapi-types.d.cts.map +1 -1
- package/dist/openapi-types.d.mts +6 -5
- package/dist/openapi-types.d.mts.map +1 -1
- package/dist/openapi.cjs +526 -0
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.mjs +501 -0
- package/dist/openapi.mjs.map +1 -0
- package/dist/react-query.cjs +16 -17
- package/dist/react-query.cjs.map +1 -1
- package/dist/react-query.d.cts +17 -12
- package/dist/react-query.d.cts.map +1 -1
- package/dist/react-query.d.mts +17 -12
- package/dist/react-query.d.mts.map +1 -1
- package/dist/react-query.mjs +9 -10
- package/dist/react-query.mjs.map +1 -1
- package/dist/types-D8Jrl4o3.d.mts +110 -0
- package/dist/types-D8Jrl4o3.d.mts.map +1 -0
- package/dist/types-DMQMHePI.d.cts +110 -0
- package/dist/types-DMQMHePI.d.cts.map +1 -0
- package/dist/types.d.cts +2 -122
- package/dist/types.d.mts +2 -122
- package/dist/types.mjs +0 -1
- package/package.json +15 -31
- package/src/__tests__/auth-fetcher.spec.ts +505 -0
- package/src/__tests__/endpoint-hooks.spec.tsx +374 -0
- package/src/__tests__/fetcher.spec.ts +580 -0
- package/src/__tests__/infer.integration.spec.ts +188 -0
- package/src/__tests__/infer.spec.ts +189 -0
- package/src/__tests__/method-restrictions.spec.tsx +227 -0
- package/src/__tests__/mutation-inference.spec.tsx +343 -0
- package/src/__tests__/openapi-hooks.spec.tsx +557 -0
- package/src/__tests__/react-query-infinite.spec.tsx +1003 -0
- package/src/__tests__/react-query-invalidation.spec.tsx +239 -0
- package/src/__tests__/react-query.spec.tsx +582 -0
- package/src/__tests__/setup.ts +281 -0
- package/src/__tests__/types.spec.ts +134 -0
- package/src/__tests__/url-parsing.spec.ts +196 -0
- package/src/auth-fetcher.ts +288 -0
- package/src/endpoint-hooks.ts +346 -0
- package/src/fetcher.ts +171 -0
- package/src/infer.ts +162 -0
- package/src/openapi-hooks.ts +193 -0
- package/src/openapi-types.d.ts +440 -0
- package/src/openapi.json +595 -0
- package/src/react-query.ts +341 -0
- package/src/types.ts +226 -0
- package/tsconfig.json +12 -0
- package/dist/fetcher.cjs.map +0 -1
- package/dist/fetcher.mjs.map +0 -1
- package/dist/index.cjs +0 -15
- package/dist/index.d.cts +0 -7
- package/dist/index.d.mts +0 -7
- package/dist/index.mjs +0 -7
- package/dist/methods.cjs +0 -21
- package/dist/methods.cjs.map +0 -1
- package/dist/methods.d.cts +0 -23
- package/dist/methods.d.cts.map +0 -1
- package/dist/methods.d.mts +0 -23
- package/dist/methods.d.mts.map +0 -1
- package/dist/methods.mjs +0 -19
- package/dist/methods.mjs.map +0 -1
- package/dist/telemetry-g3BE86Wd.d.cts +0 -68
- package/dist/telemetry-g3BE86Wd.d.cts.map +0 -1
- package/dist/telemetry-g3BE86Wd.d.mts +0 -68
- package/dist/telemetry-g3BE86Wd.d.mts.map +0 -1
- package/dist/telemetry.cjs +0 -128
- package/dist/telemetry.cjs.map +0 -1
- package/dist/telemetry.d.cts +0 -2
- package/dist/telemetry.d.mts +0 -2
- package/dist/telemetry.mjs +0 -125
- package/dist/telemetry.mjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
package/dist/react-query.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const require_fetcher = require(
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_fetcher = require('./fetcher-CwnSqc4D.cjs');
|
|
3
|
+
const __tanstack_react_query = require_chunk.__toESM(require("@tanstack/react-query"));
|
|
4
|
+
const react = require_chunk.__toESM(require("react"));
|
|
5
|
+
|
|
5
6
|
//#region src/react-query.ts
|
|
6
7
|
var TypedQueryClient = class {
|
|
7
8
|
fetcher;
|
|
@@ -22,14 +23,14 @@ var TypedQueryClient = class {
|
|
|
22
23
|
JSON.stringify(config),
|
|
23
24
|
JSON.stringify(options)
|
|
24
25
|
]);
|
|
25
|
-
return (0,
|
|
26
|
+
return (0, __tanstack_react_query.useQuery)(memoizedOptions);
|
|
26
27
|
}
|
|
27
28
|
useMutation(endpoint, options) {
|
|
28
29
|
const memoizedOptions = (0, react.useMemo)(() => ({
|
|
29
30
|
mutationFn: (config) => this.fetcher(endpoint, config),
|
|
30
31
|
...options
|
|
31
32
|
}), [endpoint, JSON.stringify(options)]);
|
|
32
|
-
return (0,
|
|
33
|
+
return (0, __tanstack_react_query.useMutation)(memoizedOptions);
|
|
33
34
|
}
|
|
34
35
|
useInfiniteQuery(endpoint, options, config) {
|
|
35
36
|
const queryKey = this.buildQueryKey(endpoint, config);
|
|
@@ -46,7 +47,10 @@ var TypedQueryClient = class {
|
|
|
46
47
|
...pageQuery
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
|
-
} else if (pageParam !== void 0 && !config)
|
|
50
|
+
} else if (pageParam !== void 0 && !config) {
|
|
51
|
+
const pageQuery = typeof pageParam === "object" ? pageParam : { page: pageParam };
|
|
52
|
+
mergedConfig = { query: pageQuery };
|
|
53
|
+
}
|
|
50
54
|
return this.fetcher(endpoint, mergedConfig);
|
|
51
55
|
},
|
|
52
56
|
...options
|
|
@@ -56,7 +60,7 @@ var TypedQueryClient = class {
|
|
|
56
60
|
JSON.stringify(config),
|
|
57
61
|
JSON.stringify(options)
|
|
58
62
|
]);
|
|
59
|
-
return (0,
|
|
63
|
+
return (0, __tanstack_react_query.useInfiniteQuery)(memoizedOptions);
|
|
60
64
|
}
|
|
61
65
|
buildQueryKey(endpoint, config) {
|
|
62
66
|
const key = [endpoint];
|
|
@@ -83,7 +87,8 @@ var TypedQueryClient = class {
|
|
|
83
87
|
* @returns Promise that resolves when invalidation is complete
|
|
84
88
|
*/
|
|
85
89
|
invalidateAllQueries() {
|
|
86
|
-
|
|
90
|
+
const queryClient = this.getQueryClient();
|
|
91
|
+
return queryClient.invalidateQueries();
|
|
87
92
|
}
|
|
88
93
|
/**
|
|
89
94
|
* Get the underlying QueryClient instance
|
|
@@ -117,11 +122,8 @@ function useTypedInfiniteQuery(client, endpoint, options, config) {
|
|
|
117
122
|
* Hook to invalidate queries using the current QueryClient from context
|
|
118
123
|
*/
|
|
119
124
|
function useTypedInvalidateQueries(client) {
|
|
120
|
-
const queryClient = (0,
|
|
125
|
+
const queryClient = (0, __tanstack_react_query.useQueryClient)();
|
|
121
126
|
return {
|
|
122
|
-
/**
|
|
123
|
-
* Invalidate queries for a specific endpoint
|
|
124
|
-
*/
|
|
125
127
|
invalidateQueries: (endpoint, config) => {
|
|
126
128
|
const queryKey = client.buildQueryKey(endpoint, config);
|
|
127
129
|
return queryClient.invalidateQueries({
|
|
@@ -129,14 +131,12 @@ function useTypedInvalidateQueries(client) {
|
|
|
129
131
|
exact: !!config
|
|
130
132
|
});
|
|
131
133
|
},
|
|
132
|
-
/**
|
|
133
|
-
* Invalidate all queries
|
|
134
|
-
*/
|
|
135
134
|
invalidateAllQueries: () => {
|
|
136
135
|
return queryClient.invalidateQueries();
|
|
137
136
|
}
|
|
138
137
|
};
|
|
139
138
|
}
|
|
139
|
+
|
|
140
140
|
//#endregion
|
|
141
141
|
exports.TypedQueryClient = TypedQueryClient;
|
|
142
142
|
exports.createTypedQueryClient = createTypedQueryClient;
|
|
@@ -144,5 +144,4 @@ exports.useTypedInfiniteQuery = useTypedInfiniteQuery;
|
|
|
144
144
|
exports.useTypedInvalidateQueries = useTypedInvalidateQueries;
|
|
145
145
|
exports.useTypedMutation = useTypedMutation;
|
|
146
146
|
exports.useTypedQuery = useTypedQuery;
|
|
147
|
-
|
|
148
147
|
//# sourceMappingURL=react-query.cjs.map
|
package/dist/react-query.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.cjs","names":["createTypedFetcher","useMemo","useQuery","useMutation","useInfiniteQuery","useQueryClient"],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC;CACA;CAEA,YAAY,UAAmC,CAAC,GAAG;EAClD,KAAK,UAAUA,gBAAAA,mBAA0B,OAAO;EAChD,KAAK,cAAc,QAAQ;CAC5B;CAEA,SACC,UACA,QACA,SAIC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,MAAM;EAGpD,MAAM,mBAAA,GAAkBC,MAAAA,QAAAA,QAChB;GACN;GACA,eAAe,KAAK,QAAQ,UAAU,MAAM;GAC5C,GAAG;EACJ,IAIA;GACC,SAAS,KAAK,GAAG;GACjB;GACA,KAAK,UAAU,MAAM;GACrB,KAAK,UAAU,OAAO;EACvB,CACD;EAEA,QAAA,GAAOC,sBAAAA,SAAAA,CACN,eACD;CACD;CAEA,YACC,UACA,SAQC;EAED,MAAM,mBAAA,GAAkBD,MAAAA,QAAAA,QAChB;GACN,aAAa,WACZ,KAAK,QAAQ,UAAU,MAAM;GAC9B,GAAG;EACJ,IAIA,CAAC,UAAU,KAAK,UAAU,OAAO,CAAC,CACnC;EAEA,QAAA,GAAOE,sBAAAA,YAAAA,CAIL,eAAe;CAClB;CAEA,iBAKC,UACA,SA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Ae,aAAgC;EAC9C,KAAK,cAAc;CACpB;AACD;AAEA,SAAgB,uBACf,SACC;CACD,OAAO,IAAI,iBAAwB,OAAO;AAC3C;AAGA,SAAgB,cACf,QACA,UACA,QACA,SAIC;CACD,OAAO,OAAO,SAAS,UAAU,QAAQ,OAAO;AACjD;AAEA,SAAgB,iBACf,QACA,UACA,SAQC;CACD,OAAO,OAAO,YAAY,UAAU,OAAO;AAC5C;AAEA,SAAgB,sBAMf,QACA,UACA,SAkBA,QACC;CACD,OAAO,OAAO,iBAAiB,UAAU,SAAS,MAAM;AACzD;;;;AAKA,SAAgB,0BACf,QACC;CACD,MAAM,eAAA,GAAcC,sBAAAA,eAAAA,CAAe;CAEnC,OAAO;;;;EAIN,oBACC,UACA,WACI;GACJ,MAAM,WAAW,OAAO,cAAc,UAAU,MAAM;GACtD,OAAO,YAAY,kBAAkB;IACpC;IACA,OAAO,CAAC,CAAC;GACV,CAAC;EACF;;;;EAKA,4BAA4B;GAC3B,OAAO,YAAY,kBAAkB;EACtC;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"react-query.cjs","names":["options: TypedQueryClientOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","options?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>","options?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>","config: FilteredRequestConfig<Paths, T>","options: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t}","key: unknown[]","queryClient: QueryClient","options?: TypedQueryClientOptions","client: TypedQueryClient<Paths>","options?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>","options?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>","options: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t}"],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC,AAAQ;CACR,AAAQ;CAER,YAAYA,UAAmC,CAAE,GAAE;AAClD,OAAK,UAAU,mCAA0B,QAAQ;AACjD,OAAK,cAAc,QAAQ;CAC3B;CAED,SACCC,UACAC,QACAC,SAIC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,OAAO;EAGrD,MAAM,kBAAkB,mBACvB,OAAO;GACN;GACA,SAAS,MAAM,KAAK,QAAQ,UAAU,OAAO;GAC7C,GAAG;EACH,IAID;GACC,SAAS,KAAK,IAAI;GAClB;GACA,KAAK,UAAU,OAAO;GACtB,KAAK,UAAU,QAAQ;EACvB,EACD;AAED,SAAO,qCACN,gBACA;CACD;CAED,YACCF,UACAG,SAQC;EAED,MAAM,kBAAkB,mBACvB,OAAO;GACN,YAAY,CAACC,WACZ,KAAK,QAAQ,UAAU,OAAO;GAC/B,GAAG;EACH,IAID,CAAC,UAAU,KAAK,UAAU,QAAQ,AAAC,EACnC;AAED,SAAO,wCAIL,gBAAgB;CAClB;CAED,iBAKCJ,UACAK,SAkBAJ,QACC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,OAAO;EAGrD,MAAM,kBAAkB,mBACvB,OAAO;GACN;GACA,SAAS,CAAC,EACT,WAC6C,KAAK;IAClD,IAAI,eAAe;AACnB,QAAI,wBAA2B,QAAQ;KAEtC,MAAM,mBACE,cAAc,WAAW,YAAY,EAAE,MAAM,UAAW;AAChE,oBAAe;MACd,GAAG;MACH,OAAO;OAAE,GAAI,OAAe;OAAO,GAAG;MAAW;KACjD;IACD,WAAU,yBAA4B,QAAQ;KAE9C,MAAM,mBACE,cAAc,WAAW,YAAY,EAAE,MAAM,UAAW;AAChE,oBAAe,EAAE,OAAO,UAAW;IACnC;AACD,WAAO,KAAK,Q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AAM,WAAW,OAAO,cAAc,UAAU,OAAO;AACvD,UAAO,YAAY,kBAAkB;IACpC;IACA,SAAS;GACT,EAAC;EACF;EAKD,sBAAsB,MAAM;AAC3B,UAAO,YAAY,mBAAmB;EACtC;CACD;AACD"}
|
package/dist/react-query.d.cts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types.cjs";
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types-DMQMHePI.cjs";
|
|
2
|
+
import * as _tanstack_react_query3 from "@tanstack/react-query";
|
|
2
3
|
import { QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
+
|
|
3
5
|
//#region src/react-query.d.ts
|
|
4
|
-
|
|
6
|
+
interface TypedQueryClientOptions extends FetcherOptions {
|
|
5
7
|
queryClient?: QueryClient;
|
|
6
8
|
}
|
|
7
|
-
|
|
9
|
+
declare class TypedQueryClient<Paths> {
|
|
8
10
|
private fetcher;
|
|
9
11
|
private queryClient?;
|
|
10
12
|
constructor(options?: TypedQueryClientOptions);
|
|
11
|
-
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
12
|
-
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>;
|
|
13
15
|
useInfiniteQuery<T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
14
16
|
pages: TPageData[];
|
|
15
17
|
pageParams: TPageParam[];
|
|
16
18
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
17
19
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
18
20
|
initialPageParam: TPageParam;
|
|
19
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
21
|
+
}, config?: FilteredRequestConfig<Paths, T>): _tanstack_react_query3.UseInfiniteQueryResult<{
|
|
20
22
|
pages: TPageData[];
|
|
21
23
|
pageParams: TPageParam[];
|
|
22
24
|
}, Response>;
|
|
@@ -44,23 +46,23 @@ export declare class TypedQueryClient<Paths> {
|
|
|
44
46
|
*/
|
|
45
47
|
setQueryClient(queryClient: QueryClient): void;
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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'>): _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
|
+
declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
51
53
|
pages: TPageData[];
|
|
52
54
|
pageParams: TPageParam[];
|
|
53
55
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
54
56
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
55
57
|
initialPageParam: TPageParam;
|
|
56
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
58
|
+
}, config?: FilteredRequestConfig<Paths, T>): _tanstack_react_query3.UseInfiniteQueryResult<{
|
|
57
59
|
pages: TPageData[];
|
|
58
60
|
pageParams: TPageParam[];
|
|
59
61
|
}, Response>;
|
|
60
62
|
/**
|
|
61
63
|
* Hook to invalidate queries using the current QueryClient from context
|
|
62
64
|
*/
|
|
63
|
-
|
|
65
|
+
declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths>): {
|
|
64
66
|
/**
|
|
65
67
|
* Invalidate queries for a specific endpoint
|
|
66
68
|
*/
|
|
@@ -70,5 +72,8 @@ export declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClien
|
|
|
70
72
|
*/
|
|
71
73
|
invalidateAllQueries: () => Promise<void>;
|
|
72
74
|
};
|
|
75
|
+
//# sourceMappingURL=react-query.d.ts.map
|
|
76
|
+
|
|
73
77
|
//#endregion
|
|
78
|
+
export { TypedQueryClient, TypedQueryClientOptions, createTypedQueryClient, useTypedInfiniteQuery, useTypedInvalidateQueries, useTypedMutation, useTypedQuery };
|
|
74
79
|
//# sourceMappingURL=react-query.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.d.cts","names":[],"sources":["../src/react-query.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"react-query.d.cts","names":[],"sources":["../src/react-query.ts"],"sourcesContent":[],"mappings":";;;;;UAwBiB,uBAAA,SAAgC;gBAClC;;AADE,cAIJ,gBAJ4B,CAAA,KAAA,CAAA,CAAA;EAAA,QAAA,OAAA;EAAA,QAC1B,WAAA;EAAW,WADuB,CAAA,OAAA,CAAA,EAQ3B,uBAR2B;EAAc,QAAA,CAAA,UAa3C,aAb2C,CAa7B,KAb6B,CAAA,CAAA,CAAA,QAAA,EAcnD,CAdmD,EAAA,MAAA,CAAA,EAepD,qBAfoD,CAe9B,KAf8B,EAevB,CAfuB,CAAA,EAAA,OAAA,CAAA,EAgBnD,IAhBmD,CAiB5D,eAjB4D,CAiB5C,uBAjB4C,CAiBpB,KAjBoB,EAiBb,CAjBa,CAAA,EAiBT,QAjBS,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAA,EAmB5D,sBAAA,CAAA,cAnB4D,CAmB5D,sBAAA,CAAA,OAnB4D,CAmB5D,uBAnB4D,CAmB5D,KAnB4D,EAmB5D,CAnB4D,CAAA,CAAA,EAmB5D,QAnB4D,CAAA;EAIlD,WAAA,CAAA,UA0CU,gBA1CM,CA0CW,KA1CX,CAAA,CAAA,CAAA,QAAA,EA2CjB,CA3CiB,EAAA,OAAA,CAAA,EA4CjB,IA5CiB,CA6C1B,kBA7C0B,CA8CzB,uBA9CyB,CA8CD,KA9CC,EA8CM,CA9CN,CAAA,EA+CzB,QA/CyB,EA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A0MiB,SA1MjB,EAAA;EAAuB,UAGzB,YAAA,EAAA;CAAC,UAGT,CAAA;;;;AAIA,iBAwMY,yBAxMZ,CAAA,KAAA,CAAA,CAAA,MAAA,EAyMK,gBAzML,CAyMsB,KAzMtB,CAAA,CAAA,EAAA;EAAU;;;EAKS,iBACT,EAAA,CAAA,UA2MkB,aA3MlB,CA2MgC,KA3MhC,CAAA,CAAA,CAAA,QAAA,EA4MD,CA5MC,EAAA,MAAA,CAAA,EA6MF,qBA7ME,CA6MoB,KA7MpB,EA6M2B,CA7M3B,CAAA,EAAA,GA6M6B,OA7M7B,CAAA,IAAA,CAAA;EAAS;;;EAGL,oBACG,EAAA,GAAA,GAyMsB,OAzMtB,CAAA,IAAA,CAAA;CAAU"}
|
package/dist/react-query.d.mts
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types.mjs";
|
|
1
|
+
import { ExtractEndpointResponse, FetcherOptions, FilteredRequestConfig, MutationEndpoint, QueryEndpoint, TypedEndpoint } from "./types-D8Jrl4o3.mjs";
|
|
2
|
+
import * as _tanstack_react_query3 from "@tanstack/react-query";
|
|
2
3
|
import { QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
|
4
|
+
|
|
3
5
|
//#region src/react-query.d.ts
|
|
4
|
-
|
|
6
|
+
interface TypedQueryClientOptions extends FetcherOptions {
|
|
5
7
|
queryClient?: QueryClient;
|
|
6
8
|
}
|
|
7
|
-
|
|
9
|
+
declare class TypedQueryClient<Paths> {
|
|
8
10
|
private fetcher;
|
|
9
11
|
private queryClient?;
|
|
10
12
|
constructor(options?: TypedQueryClientOptions);
|
|
11
|
-
useQuery<T extends QueryEndpoint<Paths>>(endpoint: T, config?: FilteredRequestConfig<Paths, T>, options?: Omit<UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>, 'queryKey' | 'queryFn'>):
|
|
12
|
-
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>;
|
|
13
15
|
useInfiniteQuery<T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
14
16
|
pages: TPageData[];
|
|
15
17
|
pageParams: TPageParam[];
|
|
16
18
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
17
19
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
18
20
|
initialPageParam: TPageParam;
|
|
19
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
21
|
+
}, config?: FilteredRequestConfig<Paths, T>): _tanstack_react_query3.UseInfiniteQueryResult<{
|
|
20
22
|
pages: TPageData[];
|
|
21
23
|
pageParams: TPageParam[];
|
|
22
24
|
}, Response>;
|
|
@@ -44,23 +46,23 @@ export declare class TypedQueryClient<Paths> {
|
|
|
44
46
|
*/
|
|
45
47
|
setQueryClient(queryClient: QueryClient): void;
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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'>): _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
|
+
declare function useTypedInfiniteQuery<Paths, T extends QueryEndpoint<Paths>, TPageData = ExtractEndpointResponse<Paths, T>, TPageParam = unknown>(client: TypedQueryClient<Paths>, endpoint: T, options: Omit<UseInfiniteQueryOptions<TPageData, Response, {
|
|
51
53
|
pages: TPageData[];
|
|
52
54
|
pageParams: TPageParam[];
|
|
53
55
|
}, unknown[], TPageParam>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'> & {
|
|
54
56
|
getNextPageParam: (lastPage: TPageData, allPages: TPageData[], lastPageParam: TPageParam, allPageParams: TPageParam[]) => TPageParam | undefined;
|
|
55
57
|
initialPageParam: TPageParam;
|
|
56
|
-
}, config?: FilteredRequestConfig<Paths, T>):
|
|
58
|
+
}, config?: FilteredRequestConfig<Paths, T>): _tanstack_react_query3.UseInfiniteQueryResult<{
|
|
57
59
|
pages: TPageData[];
|
|
58
60
|
pageParams: TPageParam[];
|
|
59
61
|
}, Response>;
|
|
60
62
|
/**
|
|
61
63
|
* Hook to invalidate queries using the current QueryClient from context
|
|
62
64
|
*/
|
|
63
|
-
|
|
65
|
+
declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClient<Paths>): {
|
|
64
66
|
/**
|
|
65
67
|
* Invalidate queries for a specific endpoint
|
|
66
68
|
*/
|
|
@@ -70,5 +72,8 @@ export declare function useTypedInvalidateQueries<Paths>(client: TypedQueryClien
|
|
|
70
72
|
*/
|
|
71
73
|
invalidateAllQueries: () => Promise<void>;
|
|
72
74
|
};
|
|
75
|
+
//# sourceMappingURL=react-query.d.ts.map
|
|
76
|
+
|
|
73
77
|
//#endregion
|
|
78
|
+
export { TypedQueryClient, TypedQueryClientOptions, createTypedQueryClient, useTypedInfiniteQuery, useTypedInvalidateQueries, useTypedMutation, useTypedQuery };
|
|
74
79
|
//# sourceMappingURL=react-query.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.d.mts","names":[],"sources":["../src/react-query.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"react-query.d.mts","names":[],"sources":["../src/react-query.ts"],"sourcesContent":[],"mappings":";;;;;UAwBiB,uBAAA,SAAgC;gBAClC;;AADE,cAIJ,gBAJ4B,CAAA,KAAA,CAAA,CAAA;EAAA,QAAA,OAAA;EAAA,QAC1B,WAAA;EAAW,WADuB,CAAA,OAAA,CAAA,EAQ3B,uBAR2B;EAAc,QAAA,CAAA,UAa3C,aAb2C,CAa7B,KAb6B,CAAA,CAAA,CAAA,QAAA,EAcnD,CAdmD,EAAA,MAAA,CAAA,EAepD,qBAfoD,CAe9B,KAf8B,EAevB,CAfuB,CAAA,EAAA,OAAA,CAAA,EAgBnD,IAhBmD,CAiB5D,eAjB4D,CAiB5C,uBAjB4C,CAiBpB,KAjBoB,EAiBb,CAjBa,CAAA,EAiBT,QAjBS,CAAA,EAAA,UAAA,GAAA,SAAA,CAAA,CAAA,EAmB5D,sBAAA,CAAA,cAnB4D,CAmB5D,sBAAA,CAAA,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AnB,EAAA,CAAA,QAAA,EAoMC,SApMD,EAAA,QAAA,EAqMC,SArMD,EAAA,EAAA,aAAA,EAsMM,UAtMN,EAAA,aAAA,EAuMM,UAvMN,EAAA,EAAA,GAwML,UAxMK,GAAA,SAAA;EAAa,gBACa,EAwMlB,UAxMkB;CAAK,EAAA,MAAE,CAAA,EA0MnC,qBA1MmC,CA0Mb,KA1Ma,EA0MN,CA1MM,CAAA,CAAA,yBA0MJ,sBA1MI,CAAA;EAAC,KAAhC,EA0MiB,SA1MjB,EAAA;EAAuB,UAGzB,YAAA,EAAA;CAAC,UAGT,CAAA;;;;AAIA,iBAwMY,yBAxMZ,CAAA,KAAA,CAAA,CAAA,MAAA,EAyMK,gBAzML,CAyMsB,KAzMtB,CAAA,CAAA,EAAA;EAAU;;;EAKS,iBACT,EAAA,CAAA,UA2MkB,aA3MlB,CA2MgC,KA3MhC,CAAA,CAAA,CAAA,QAAA,EA4MD,CA5MC,EAAA,MAAA,CAAA,EA6MF,qBA7ME,CA6MoB,KA7MpB,EA6M2B,CA7M3B,CAAA,EAAA,GA6M6B,OA7M7B,CAAA,IAAA,CAAA;EAAS;;;EAGL,oBACG,EAAA,GAAA,GAyMsB,OAzMtB,CAAA,IAAA,CAAA;CAAU"}
|
package/dist/react-query.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createTypedFetcher } from "./fetcher.mjs";
|
|
1
|
+
import { createTypedFetcher } from "./fetcher-CakjC9C7.mjs";
|
|
2
2
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
|
+
|
|
4
5
|
//#region src/react-query.ts
|
|
5
6
|
var TypedQueryClient = class {
|
|
6
7
|
fetcher;
|
|
@@ -45,7 +46,10 @@ var TypedQueryClient = class {
|
|
|
45
46
|
...pageQuery
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
|
-
} else if (pageParam !== void 0 && !config)
|
|
49
|
+
} else if (pageParam !== void 0 && !config) {
|
|
50
|
+
const pageQuery = typeof pageParam === "object" ? pageParam : { page: pageParam };
|
|
51
|
+
mergedConfig = { query: pageQuery };
|
|
52
|
+
}
|
|
49
53
|
return this.fetcher(endpoint, mergedConfig);
|
|
50
54
|
},
|
|
51
55
|
...options
|
|
@@ -82,7 +86,8 @@ var TypedQueryClient = class {
|
|
|
82
86
|
* @returns Promise that resolves when invalidation is complete
|
|
83
87
|
*/
|
|
84
88
|
invalidateAllQueries() {
|
|
85
|
-
|
|
89
|
+
const queryClient = this.getQueryClient();
|
|
90
|
+
return queryClient.invalidateQueries();
|
|
86
91
|
}
|
|
87
92
|
/**
|
|
88
93
|
* Get the underlying QueryClient instance
|
|
@@ -118,9 +123,6 @@ function useTypedInfiniteQuery(client, endpoint, options, config) {
|
|
|
118
123
|
function useTypedInvalidateQueries(client) {
|
|
119
124
|
const queryClient = useQueryClient();
|
|
120
125
|
return {
|
|
121
|
-
/**
|
|
122
|
-
* Invalidate queries for a specific endpoint
|
|
123
|
-
*/
|
|
124
126
|
invalidateQueries: (endpoint, config) => {
|
|
125
127
|
const queryKey = client.buildQueryKey(endpoint, config);
|
|
126
128
|
return queryClient.invalidateQueries({
|
|
@@ -128,15 +130,12 @@ function useTypedInvalidateQueries(client) {
|
|
|
128
130
|
exact: !!config
|
|
129
131
|
});
|
|
130
132
|
},
|
|
131
|
-
/**
|
|
132
|
-
* Invalidate all queries
|
|
133
|
-
*/
|
|
134
133
|
invalidateAllQueries: () => {
|
|
135
134
|
return queryClient.invalidateQueries();
|
|
136
135
|
}
|
|
137
136
|
};
|
|
138
137
|
}
|
|
138
|
+
|
|
139
139
|
//#endregion
|
|
140
140
|
export { TypedQueryClient, createTypedQueryClient, useTypedInfiniteQuery, useTypedInvalidateQueries, useTypedMutation, useTypedQuery };
|
|
141
|
-
|
|
142
141
|
//# sourceMappingURL=react-query.mjs.map
|
package/dist/react-query.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-query.mjs","names":[],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;AA4BA,IAAa,mBAAb,MAAqC;CACpC;CACA;CAEA,YAAY,UAAmC,CAAC,GAAG;EAClD,KAAK,UAAU,mBAA0B,OAAO;EAChD,KAAK,cAAc,QAAQ;CAC5B;CAEA,SACC,UACA,QACA,SAIC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,MAAM;EAGpD,MAAM,kBAAkB,eAChB;GACN;GACA,eAAe,KAAK,QAAQ,UAAU,MAAM;GAC5C,GAAG;EACJ,IAIA;GACC,SAAS,KAAK,GAAG;GACjB;GACA,KAAK,UAAU,MAAM;GACrB,KAAK,UAAU,OAAO;EACvB,CACD;EAEA,OAAO,SACN,eACD;CACD;CAEA,YACC,UACA,SAQC;EAED,MAAM,kBAAkB,eAChB;GACN,aAAa,WACZ,KAAK,QAAQ,UAAU,MAAM;GAC9B,GAAG;EACJ,IAIA,CAAC,UAAU,KAAK,UAAU,OAAO,CAAC,CACnC;EAEA,OAAO,YAIL,eAAe;CAClB;CAEA,iBAKC,UACA,SAkBA,QACC;EACD,MAAM,WAAW,KAAK,cAAc,UAAU,MAAM;EAGpD,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;AAGA,SAAgB,cACf,QACA,UACA,QACA,SAIC;CACD,OAAO,OAAO,SAAS,UAAU,QAAQ,OAAO;AACjD;AAEA,SAAgB,iBACf,QACA,UACA,SAQC;CACD,OAAO,OAAO,YAAY,UAAU,OAAO;AAC5C;AAEA,SAAgB,sBAMf,QACA,UACA,SAkBA,QACC;CACD,OAAO,OAAO,iBAAiB,UAAU,SAAS,MAAM;AACzD;;;;AAKA,SAAgB,0BACf,QACC;CACD,MAAM,cAAc,eAAe;CAEnC,OAAO;;;;EAIN,oBACC,UACA,WACI;GACJ,MAAM,WAAW,OAAO,cAAc,UAAU,MAAM;GACtD,OAAO,YAAY,kBAAkB;IACpC;IACA,OAAO,CAAC,CAAC;GACV,CAAC;EACF;;;;EAKA,4BAA4B;GAC3B,OAAO,YAAY,kBAAkB;EACtC;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"react-query.mjs","names":["options: TypedQueryClientOptions","endpoint: T","config?: FilteredRequestConfig<Paths, T>","options?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>","options?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>","config: FilteredRequestConfig<Paths, T>","options: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t}","key: unknown[]","queryClient: QueryClient","options?: TypedQueryClientOptions","client: TypedQueryClient<Paths>","options?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>","options?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>","options: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t}"],"sources":["../src/react-query.ts"],"sourcesContent":["import type {\n\tQueryClient,\n\tQueryFunctionContext,\n\tUseInfiniteQueryOptions,\n\tUseMutationOptions,\n\tUseQueryOptions,\n} from '@tanstack/react-query';\nimport {\n\tuseInfiniteQuery,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { createTypedFetcher } from './fetcher';\nimport type {\n\tExtractEndpointResponse,\n\tFetcherOptions,\n\tFilteredRequestConfig,\n\tMutationEndpoint,\n\tQueryEndpoint,\n\tTypedEndpoint,\n} from './types';\n\nexport interface TypedQueryClientOptions extends FetcherOptions {\n\tqueryClient?: QueryClient;\n}\n\nexport class TypedQueryClient<Paths> {\n\tprivate fetcher: ReturnType<typeof createTypedFetcher<Paths>>;\n\tprivate queryClient?: QueryClient;\n\n\tconstructor(options: TypedQueryClientOptions = {}) {\n\t\tthis.fetcher = createTypedFetcher<Paths>(options);\n\t\tthis.queryClient = options.queryClient;\n\t}\n\n\tuseQuery<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\toptions?: Omit<\n\t\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t\t'queryKey' | 'queryFn'\n\t\t>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: () => this.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useQuery<ExtractEndpointResponse<Paths, T>, Response>(\n\t\t\tmemoizedOptions,\n\t\t);\n\t}\n\n\tuseMutation<T extends MutationEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\toptions?: Omit<\n\t\t\tUseMutationOptions<\n\t\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\t\tResponse,\n\t\t\t\tFilteredRequestConfig<Paths, T>\n\t\t\t>,\n\t\t\t'mutationFn'\n\t\t>,\n\t) {\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tmutationFn: (config: FilteredRequestConfig<Paths, T>) =>\n\t\t\t\t\tthis.fetcher(endpoint, config),\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: endpoint and options\n\t\t\t// Note: We stringify options to ensure stable reference\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[endpoint, JSON.stringify(options)],\n\t\t);\n\n\t\treturn useMutation<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>(memoizedOptions);\n\t}\n\n\tuseInfiniteQuery<\n\t\tT extends QueryEndpoint<Paths>,\n\t\tTPageData = ExtractEndpointResponse<Paths, T>,\n\t\tTPageParam = unknown,\n\t>(\n\t\tendpoint: T,\n\t\toptions: Omit<\n\t\t\tUseInfiniteQueryOptions<\n\t\t\t\tTPageData,\n\t\t\t\tResponse,\n\t\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\t\tunknown[],\n\t\t\t\tTPageParam\n\t\t\t>,\n\t\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t\t> & {\n\t\t\tgetNextPageParam: (\n\t\t\t\tlastPage: TPageData,\n\t\t\t\tallPages: TPageData[],\n\t\t\t\tlastPageParam: TPageParam,\n\t\t\t\tallPageParams: TPageParam[],\n\t\t\t) => TPageParam | undefined;\n\t\t\tinitialPageParam: TPageParam;\n\t\t},\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t) {\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\t// Memoize the combined options to prevent unnecessary re-renders\n\t\tconst memoizedOptions = useMemo(\n\t\t\t() => ({\n\t\t\t\tqueryKey,\n\t\t\t\tqueryFn: ({\n\t\t\t\t\tpageParam,\n\t\t\t\t}: QueryFunctionContext<unknown[], TPageParam>) => {\n\t\t\t\t\tlet mergedConfig = config;\n\t\t\t\t\tif (pageParam !== undefined && config) {\n\t\t\t\t\t\t// If pageParam is an object, spread it into query\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = {\n\t\t\t\t\t\t\t...config,\n\t\t\t\t\t\t\tquery: { ...(config as any).query, ...pageQuery },\n\t\t\t\t\t\t} as any;\n\t\t\t\t\t} else if (pageParam !== undefined && !config) {\n\t\t\t\t\t\t// If pageParam is an object, use it directly, otherwise wrap in page property\n\t\t\t\t\t\tconst pageQuery =\n\t\t\t\t\t\t\ttypeof pageParam === 'object' ? pageParam : { page: pageParam };\n\t\t\t\t\t\tmergedConfig = { query: pageQuery } as any;\n\t\t\t\t\t}\n\t\t\t\t\treturn this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;\n\t\t\t\t},\n\t\t\t\t...options,\n\t\t\t}),\n\t\t\t// Dependencies: queryKey, endpoint, config, and options\n\t\t\t// Note: We stringify config and options to ensure stable references\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[\n\t\t\t\tqueryKey.join(','),\n\t\t\t\tendpoint,\n\t\t\t\tJSON.stringify(config),\n\t\t\t\tJSON.stringify(options),\n\t\t\t],\n\t\t);\n\n\t\treturn useInfiniteQuery<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>(memoizedOptions);\n\t}\n\n\tbuildQueryKey<T extends TypedEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): unknown[] {\n\t\tconst key: unknown[] = [endpoint];\n\n\t\tif (config && 'params' in config && config.params) {\n\t\t\tkey.push({ params: config.params });\n\t\t}\n\n\t\tif (config && 'query' in config && config.query) {\n\t\t\tkey.push({ query: config.query });\n\t\t}\n\n\t\treturn key;\n\t}\n\n\t/**\n\t * Invalidate queries for a specific endpoint with optional config\n\t * @param endpoint - The endpoint to invalidate (e.g., 'GET /users')\n\t * @param config - Optional params/query to match specific queries\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateQueries<T extends QueryEndpoint<Paths>>(\n\t\tendpoint: T,\n\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\tconst queryKey = this.buildQueryKey(endpoint, config);\n\n\t\treturn queryClient.invalidateQueries({\n\t\t\tqueryKey,\n\t\t\texact: !!config, // Use exact matching if config is provided\n\t\t});\n\t}\n\n\t/**\n\t * Invalidate all queries in the cache\n\t * @returns Promise that resolves when invalidation is complete\n\t */\n\tinvalidateAllQueries(): Promise<void> {\n\t\tconst queryClient = this.getQueryClient();\n\t\treturn queryClient.invalidateQueries();\n\t}\n\n\t/**\n\t * Get the underlying QueryClient instance\n\t * @returns The QueryClient instance\n\t */\n\tgetQueryClient(): QueryClient {\n\t\tif (this.queryClient) {\n\t\t\treturn this.queryClient;\n\t\t}\n\n\t\t// If no query client was provided, try to get it from context\n\t\t// This will throw if used outside of QueryClientProvider\n\t\tthrow new Error(\n\t\t\t'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',\n\t\t);\n\t}\n\n\t/**\n\t * Set the QueryClient instance\n\t * @param queryClient - The QueryClient instance to use\n\t */\n\tsetQueryClient(queryClient: QueryClient): void {\n\t\tthis.queryClient = queryClient;\n\t}\n}\n\nexport function createTypedQueryClient<Paths>(\n\toptions?: TypedQueryClientOptions,\n) {\n\treturn new TypedQueryClient<Paths>(options);\n}\n\n// Hook exports for convenience\nexport function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\tconfig?: FilteredRequestConfig<Paths, T>,\n\toptions?: Omit<\n\t\tUseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,\n\t\t'queryKey' | 'queryFn'\n\t>,\n) {\n\treturn client.useQuery(endpoint, config, options);\n}\n\nexport function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions?: Omit<\n\t\tUseMutationOptions<\n\t\t\tExtractEndpointResponse<Paths, T>,\n\t\t\tResponse,\n\t\t\tFilteredRequestConfig<Paths, T>\n\t\t>,\n\t\t'mutationFn'\n\t>,\n) {\n\treturn client.useMutation(endpoint, options);\n}\n\nexport function useTypedInfiniteQuery<\n\tPaths,\n\tT extends QueryEndpoint<Paths>,\n\tTPageData = ExtractEndpointResponse<Paths, T>,\n\tTPageParam = unknown,\n>(\n\tclient: TypedQueryClient<Paths>,\n\tendpoint: T,\n\toptions: Omit<\n\t\tUseInfiniteQueryOptions<\n\t\t\tTPageData,\n\t\t\tResponse,\n\t\t\t{ pages: TPageData[]; pageParams: TPageParam[] },\n\t\t\tunknown[],\n\t\t\tTPageParam\n\t\t>,\n\t\t'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'\n\t> & {\n\t\tgetNextPageParam: (\n\t\t\tlastPage: TPageData,\n\t\t\tallPages: TPageData[],\n\t\t\tlastPageParam: TPageParam,\n\t\t\tallPageParams: TPageParam[],\n\t\t) => TPageParam | undefined;\n\t\tinitialPageParam: TPageParam;\n\t},\n\tconfig?: FilteredRequestConfig<Paths, T>,\n) {\n\treturn client.useInfiniteQuery(endpoint, options, config);\n}\n\n/**\n * Hook to invalidate queries using the current QueryClient from context\n */\nexport function useTypedInvalidateQueries<Paths>(\n\tclient: TypedQueryClient<Paths>,\n) {\n\tconst queryClient = useQueryClient();\n\n\treturn {\n\t\t/**\n\t\t * Invalidate queries for a specific endpoint\n\t\t */\n\t\tinvalidateQueries: <T extends QueryEndpoint<Paths>>(\n\t\t\tendpoint: T,\n\t\t\tconfig?: FilteredRequestConfig<Paths, T>,\n\t\t) => {\n\t\t\tconst queryKey = client.buildQueryKey(endpoint, config);\n\t\t\treturn queryClient.invalidateQueries({\n\t\t\t\tqueryKey,\n\t\t\t\texact: !!config,\n\t\t\t});\n\t\t},\n\n\t\t/**\n\t\t * Invalidate all queries\n\t\t */\n\t\tinvalidateAllQueries: () => {\n\t\t\treturn queryClient.invalidateQueries();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;AA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,mBAAmB;EACtC;CACD;AACD"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
type OpenAPIRoutes<Paths> = keyof Paths;
|
|
3
|
+
type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options';
|
|
4
|
+
type ExtractMethod<Paths, Route extends OpenAPIRoutes<Paths>> = Extract<keyof Paths[Route], HttpMethod>;
|
|
5
|
+
type ExtractPathParams<Paths, Route extends OpenAPIRoutes<Paths>> = Paths[Route] extends {
|
|
6
|
+
parameters?: {
|
|
7
|
+
path?: infer P;
|
|
8
|
+
};
|
|
9
|
+
} ? P : never;
|
|
10
|
+
type ExtractQueryParams<Paths, Route extends OpenAPIRoutes<Paths>, Method extends ExtractMethod<Paths, Route>> = Paths[Route][Method] extends {
|
|
11
|
+
parameters?: {
|
|
12
|
+
query?: infer Q;
|
|
13
|
+
};
|
|
14
|
+
} ? Q : never;
|
|
15
|
+
type ExtractRequestBody<Paths, Route extends OpenAPIRoutes<Paths>, Method extends ExtractMethod<Paths, Route>> = Paths[Route][Method] extends {
|
|
16
|
+
requestBody?: {
|
|
17
|
+
content?: {
|
|
18
|
+
'application/json'?: infer B;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} ? B : never;
|
|
22
|
+
type ExtractResponse<Paths, Route extends OpenAPIRoutes<Paths>, Method extends ExtractMethod<Paths, Route>> = Paths[Route][Method] extends {
|
|
23
|
+
responses?: {
|
|
24
|
+
200?: {
|
|
25
|
+
content?: {
|
|
26
|
+
'application/json'?: infer R;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
} ? R : Paths[Route][Method] extends {
|
|
31
|
+
responses?: {
|
|
32
|
+
201?: {
|
|
33
|
+
content?: {
|
|
34
|
+
'application/json'?: infer R;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
} ? R : never;
|
|
39
|
+
type RequestConfig<Paths, Route extends OpenAPIRoutes<Paths>, Method extends ExtractMethod<Paths, Route>> = {
|
|
40
|
+
params?: ExtractPathParams<Paths, Route>;
|
|
41
|
+
query?: ExtractQueryParams<Paths, Route, Method>;
|
|
42
|
+
body?: ExtractRequestBody<Paths, Route, Method>;
|
|
43
|
+
headers?: Record<string, string>;
|
|
44
|
+
};
|
|
45
|
+
type EndpointString = `${Uppercase<string>} ${string}`;
|
|
46
|
+
type ValidEndpoint<Paths> = { [Route in keyof Paths]: { [Method in Extract<keyof Paths[Route], HttpMethod>]: `${Uppercase<string & Method>} ${string & Route}` }[Extract<keyof Paths[Route], HttpMethod>] }[keyof Paths];
|
|
47
|
+
type TypedEndpoint<Paths> = ValidEndpoint<Paths> extends infer E ? (E extends string ? E : never) : never;
|
|
48
|
+
type FilterEndpointByMethod<Paths, Method extends string> = ValidEndpoint<Paths> extends infer E ? E extends `${Method} ${string}` ? E : never : never;
|
|
49
|
+
type QueryEndpoint<Paths> = FilterEndpointByMethod<Paths, 'GET'>;
|
|
50
|
+
type MutationEndpoint<Paths> = FilterEndpointByMethod<Paths, 'POST'> | FilterEndpointByMethod<Paths, 'PATCH'> | FilterEndpointByMethod<Paths, 'PUT'> | FilterEndpointByMethod<Paths, 'DELETE'>;
|
|
51
|
+
type ParseEndpoint<T extends EndpointString> = T extends `${infer Method} ${infer Route}` ? {
|
|
52
|
+
method: Lowercase<Method>;
|
|
53
|
+
route: Route;
|
|
54
|
+
} : never;
|
|
55
|
+
type ExtractEndpointResponse<Paths, T extends EndpointString> = T extends `${infer Method} ${infer Route}` ? Route extends OpenAPIRoutes<Paths> ? Lowercase<Method> extends ExtractMethod<Paths, Route> ? ExtractResponse<Paths, Route, Lowercase<Method>> : never : never : never;
|
|
56
|
+
type ExtractEndpointConfig<Paths, T extends EndpointString> = T extends `${infer Method} ${infer Route}` ? Route extends OpenAPIRoutes<Paths> ? Lowercase<Method> extends ExtractMethod<Paths, Route> ? RequestConfig<Paths, Route, Lowercase<Method>> : never : never : never;
|
|
57
|
+
/**
|
|
58
|
+
* Build a request config type where:
|
|
59
|
+
* - `params` is required if the endpoint has path parameters
|
|
60
|
+
* - `body` is required if the endpoint has a request body
|
|
61
|
+
* - `query` and `headers` are always optional
|
|
62
|
+
*/
|
|
63
|
+
type FilteredRequestConfig<Paths, T extends EndpointString> = T extends `${infer Method} ${infer Route}` ? Route extends OpenAPIRoutes<Paths> ? Lowercase<Method> extends ExtractMethod<Paths, Route> ? BuildRequestConfig<ExtractPathParams<Paths, Route>, ExtractQueryParams<Paths, Route, Lowercase<Method>>, ExtractRequestBody<Paths, Route, Lowercase<Method>>> : never : never : never;
|
|
64
|
+
/**
|
|
65
|
+
* Helper to build request config with correct required/optional fields.
|
|
66
|
+
* Uses [T] extends [never] pattern to prevent distribution over union types,
|
|
67
|
+
* which would cause the entire type to become `never`.
|
|
68
|
+
*/
|
|
69
|
+
type BuildRequestConfig<TParams, TQuery, TBody> = SimplifyIntersection<([TParams] extends [never] ? {} : {
|
|
70
|
+
params: TParams;
|
|
71
|
+
}) & ([TBody] extends [never] ? {} : {
|
|
72
|
+
body: TBody;
|
|
73
|
+
}) & ([TQuery] extends [never] ? {} : {
|
|
74
|
+
query?: TQuery;
|
|
75
|
+
}) & {
|
|
76
|
+
headers?: Record<string, string>;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Simplify intersection types for better IDE display
|
|
80
|
+
*/
|
|
81
|
+
type SimplifyIntersection<T> = { [K in keyof T]: T[K] };
|
|
82
|
+
/**
|
|
83
|
+
* Check if the config object is required (has any required fields)
|
|
84
|
+
*/
|
|
85
|
+
type IsConfigRequired<Paths, T extends EndpointString> = T extends `${infer Method} ${infer Route}` ? Route extends OpenAPIRoutes<Paths> ? Lowercase<Method> extends ExtractMethod<Paths, Route> ? ExtractPathParams<Paths, Route> extends never ? ExtractRequestBody<Paths, Route, Lowercase<Method>> extends never ? false : true : true : false : false : false;
|
|
86
|
+
/**
|
|
87
|
+
* Typed function signature for the API client.
|
|
88
|
+
* Config is required when endpoint has path params or body.
|
|
89
|
+
*/
|
|
90
|
+
type TypedApiFunction<Paths> = <T extends TypedEndpoint<Paths>>(endpoint: T, ...args: IsConfigRequired<Paths, T> extends true ? [config: FilteredRequestConfig<Paths, T>] : [config?: FilteredRequestConfig<Paths, T>]) => Promise<ExtractEndpointResponse<Paths, T>>;
|
|
91
|
+
interface FetcherOptions {
|
|
92
|
+
baseURL?: string;
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
onRequest?: (config: RequestInit) => RequestInit | Promise<RequestInit>;
|
|
95
|
+
onResponse?: (response: Response) => Response | Promise<Response>;
|
|
96
|
+
onError?: (error: Error) => void | Promise<void>;
|
|
97
|
+
fetch?: typeof fetch;
|
|
98
|
+
}
|
|
99
|
+
type WrappedResult<T, E = unknown> = {
|
|
100
|
+
ok: true;
|
|
101
|
+
data: T;
|
|
102
|
+
} | {
|
|
103
|
+
ok: false;
|
|
104
|
+
error: E;
|
|
105
|
+
};
|
|
106
|
+
type ErrorTransformer<E> = (error: unknown) => E | Promise<E>;
|
|
107
|
+
type WrappedApiFunction<Paths, E = unknown> = <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>, E>>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { EndpointString, ErrorTransformer, ExtractEndpointConfig, ExtractEndpointResponse, ExtractMethod, ExtractPathParams, ExtractQueryParams, ExtractRequestBody, ExtractResponse, FetcherOptions, FilterEndpointByMethod, FilteredRequestConfig, IsConfigRequired, MutationEndpoint, OpenAPIRoutes, ParseEndpoint, QueryEndpoint, RequestConfig, TypedApiFunction, TypedEndpoint, ValidEndpoint, WrappedApiFunction, WrappedResult };
|
|
110
|
+
//# sourceMappingURL=types-D8Jrl4o3.d.mts.map
|