@geekmidas/client 0.3.0 → 0.5.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/dist/auth-fetcher.cjs +2 -3
- package/dist/auth-fetcher.cjs.map +1 -1
- package/dist/auth-fetcher.d.cts +2 -1
- package/dist/auth-fetcher.d.cts.map +1 -0
- package/dist/auth-fetcher.d.mts +2 -1
- package/dist/auth-fetcher.d.mts.map +1 -0
- package/dist/auth-fetcher.mjs +2 -3
- package/dist/auth-fetcher.mjs.map +1 -1
- package/dist/endpoint-hooks.cjs +10 -5
- package/dist/endpoint-hooks.cjs.map +1 -1
- package/dist/endpoint-hooks.d.cts +2 -2
- package/dist/endpoint-hooks.d.cts.map +1 -0
- package/dist/endpoint-hooks.d.mts +2 -2
- package/dist/endpoint-hooks.d.mts.map +1 -0
- package/dist/endpoint-hooks.mjs +10 -5
- package/dist/endpoint-hooks.mjs.map +1 -1
- package/dist/{fetcher-DLDD_7Sa.mjs → fetcher-5fnBE7Dk.mjs} +2 -2
- package/dist/fetcher-5fnBE7Dk.mjs.map +1 -0
- package/dist/{fetcher-KdwHgdAl.cjs → fetcher-CgLEaIAC.cjs} +2 -2
- package/dist/fetcher-CgLEaIAC.cjs.map +1 -0
- package/dist/fetcher.cjs +1 -1
- package/dist/fetcher.d.cts +3 -1
- package/dist/fetcher.d.cts.map +1 -0
- package/dist/fetcher.d.mts +3 -1
- package/dist/fetcher.d.mts.map +1 -0
- package/dist/fetcher.mjs +1 -1
- package/dist/infer.d.cts.map +1 -0
- package/dist/infer.d.mts.map +1 -0
- package/dist/openapi-hooks.cjs +3 -5
- package/dist/openapi-hooks.cjs.map +1 -1
- package/dist/openapi-hooks.d.cts +3 -3
- package/dist/openapi-hooks.d.cts.map +1 -0
- package/dist/openapi-hooks.d.mts +6 -6
- package/dist/openapi-hooks.d.mts.map +1 -0
- package/dist/openapi-hooks.mjs +3 -5
- package/dist/openapi-hooks.mjs.map +1 -1
- package/dist/openapi-types.d.cts.map +1 -0
- package/dist/openapi-types.d.mts.map +1 -0
- package/dist/openapi.cjs.map +1 -1
- package/dist/openapi.mjs.map +1 -1
- package/dist/react-query.cjs +1 -1
- package/dist/react-query.cjs.map +1 -1
- package/dist/react-query.d.cts +3 -1
- package/dist/react-query.d.cts.map +1 -0
- package/dist/react-query.d.mts +10 -8
- package/dist/react-query.d.mts.map +1 -0
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/{types-D4OSWveN.d.cts → types-4K4N-Fl1.d.cts} +8 -6
- package/dist/types-4K4N-Fl1.d.cts.map +1 -0
- package/dist/{types-Cdv1XAWr.d.mts → types-hhkZWjQn.d.mts} +8 -6
- package/dist/types-hhkZWjQn.d.mts.map +1 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +6 -5
- package/src/__tests__/auth-fetcher.spec.ts +505 -0
- package/src/__tests__/endpoint-hooks.spec.tsx +348 -348
- package/src/__tests__/fetcher.spec.ts +403 -403
- package/src/__tests__/infer.integration.spec.ts +171 -171
- package/src/__tests__/infer.spec.ts +182 -182
- package/src/__tests__/method-restrictions.spec.tsx +165 -165
- package/src/__tests__/openapi-hooks.spec.tsx +536 -537
- package/src/__tests__/react-query-infinite.spec.tsx +989 -989
- package/src/__tests__/react-query-invalidation.spec.tsx +223 -222
- package/src/__tests__/react-query.spec.tsx +567 -567
- package/src/__tests__/setup.ts +260 -260
- package/src/__tests__/types.spec.ts +127 -127
- package/src/__tests__/url-parsing.spec.ts +191 -191
- package/src/auth-fetcher.ts +160 -162
- package/src/endpoint-hooks.ts +151 -150
- package/src/fetcher.ts +163 -163
- package/src/infer.ts +64 -63
- package/src/openapi-hooks.ts +146 -146
- package/src/openapi-types.d.ts +428 -428
- package/src/openapi.json +593 -593
- package/src/react-query.ts +281 -281
- package/src/types.ts +124 -125
- package/tsconfig.json +12 -0
- package/dist/fetcher-DLDD_7Sa.mjs.map +0 -1
- package/dist/fetcher-KdwHgdAl.cjs.map +0 -1
package/src/react-query.ts
CHANGED
|
@@ -1,341 +1,341 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
QueryClient,
|
|
3
|
+
QueryFunctionContext,
|
|
4
|
+
UseInfiniteQueryOptions,
|
|
5
|
+
UseMutationOptions,
|
|
6
|
+
UseQueryOptions,
|
|
7
7
|
} from '@tanstack/react-query';
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
useInfiniteQuery,
|
|
10
|
+
useMutation,
|
|
11
|
+
useQuery,
|
|
12
|
+
useQueryClient,
|
|
13
13
|
} from '@tanstack/react-query';
|
|
14
14
|
import { useMemo } from 'react';
|
|
15
15
|
import { createTypedFetcher } from './fetcher';
|
|
16
16
|
import type {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
ExtractEndpointResponse,
|
|
18
|
+
FetcherOptions,
|
|
19
|
+
FilteredRequestConfig,
|
|
20
|
+
MutationEndpoint,
|
|
21
|
+
QueryEndpoint,
|
|
22
|
+
TypedEndpoint,
|
|
23
23
|
} from './types';
|
|
24
24
|
|
|
25
25
|
export interface TypedQueryClientOptions extends FetcherOptions {
|
|
26
|
-
|
|
26
|
+
queryClient?: QueryClient;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export class TypedQueryClient<Paths> {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
private fetcher: ReturnType<typeof createTypedFetcher<Paths>>;
|
|
31
|
+
private queryClient?: QueryClient;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
constructor(options: TypedQueryClientOptions = {}) {
|
|
34
|
+
this.fetcher = createTypedFetcher<Paths>(options);
|
|
35
|
+
this.queryClient = options.queryClient;
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
useQuery<T extends QueryEndpoint<Paths>>(
|
|
39
|
+
endpoint: T,
|
|
40
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
41
|
+
options?: Omit<
|
|
42
|
+
UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,
|
|
43
|
+
'queryKey' | 'queryFn'
|
|
44
|
+
>,
|
|
45
|
+
) {
|
|
46
|
+
const queryKey = this.buildQueryKey(endpoint, config);
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
// Memoize the combined options to prevent unnecessary re-renders
|
|
49
|
+
const memoizedOptions = useMemo(
|
|
50
|
+
() => ({
|
|
51
|
+
queryKey,
|
|
52
|
+
queryFn: () => this.fetcher(endpoint, config),
|
|
53
|
+
...options,
|
|
54
|
+
}),
|
|
55
|
+
// Dependencies: queryKey, endpoint, config, and options
|
|
56
|
+
// Note: We stringify config and options to ensure stable references
|
|
57
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
|
+
[
|
|
59
|
+
queryKey.join(','),
|
|
60
|
+
endpoint,
|
|
61
|
+
JSON.stringify(config),
|
|
62
|
+
JSON.stringify(options),
|
|
63
|
+
],
|
|
64
|
+
);
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
return useQuery<ExtractEndpointResponse<Paths, T>, Response>(
|
|
67
|
+
memoizedOptions,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
useMutation<T extends MutationEndpoint<Paths>>(
|
|
72
|
+
endpoint: T,
|
|
73
|
+
options?: Omit<
|
|
74
|
+
UseMutationOptions<
|
|
75
|
+
ExtractEndpointResponse<Paths, T>,
|
|
76
|
+
Response,
|
|
77
|
+
FilteredRequestConfig<Paths, T>
|
|
78
|
+
>,
|
|
79
|
+
'mutationFn'
|
|
80
|
+
>,
|
|
81
|
+
) {
|
|
82
|
+
// Memoize the combined options to prevent unnecessary re-renders
|
|
83
|
+
const memoizedOptions = useMemo(
|
|
84
|
+
() => ({
|
|
85
|
+
mutationFn: (config: FilteredRequestConfig<Paths, T>) =>
|
|
86
|
+
this.fetcher(endpoint, config),
|
|
87
|
+
...options,
|
|
88
|
+
}),
|
|
89
|
+
// Dependencies: endpoint and options
|
|
90
|
+
// Note: We stringify options to ensure stable reference
|
|
91
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
|
+
[endpoint, JSON.stringify(options)],
|
|
93
|
+
);
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
return useMutation<
|
|
96
|
+
ExtractEndpointResponse<Paths, T>,
|
|
97
|
+
Response,
|
|
98
|
+
FilteredRequestConfig<Paths, T>
|
|
99
|
+
>(memoizedOptions);
|
|
100
|
+
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
102
|
+
useInfiniteQuery<
|
|
103
|
+
T extends QueryEndpoint<Paths>,
|
|
104
|
+
TPageData = ExtractEndpointResponse<Paths, T>,
|
|
105
|
+
TPageParam = unknown,
|
|
106
|
+
>(
|
|
107
|
+
endpoint: T,
|
|
108
|
+
options: Omit<
|
|
109
|
+
UseInfiniteQueryOptions<
|
|
110
|
+
TPageData,
|
|
111
|
+
Response,
|
|
112
|
+
{ pages: TPageData[]; pageParams: TPageParam[] },
|
|
113
|
+
unknown[],
|
|
114
|
+
TPageParam
|
|
115
|
+
>,
|
|
116
|
+
'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'
|
|
117
|
+
> & {
|
|
118
|
+
getNextPageParam: (
|
|
119
|
+
lastPage: TPageData,
|
|
120
|
+
allPages: TPageData[],
|
|
121
|
+
lastPageParam: TPageParam,
|
|
122
|
+
allPageParams: TPageParam[],
|
|
123
|
+
) => TPageParam | undefined;
|
|
124
|
+
initialPageParam: TPageParam;
|
|
125
|
+
},
|
|
126
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
127
|
+
) {
|
|
128
|
+
const queryKey = this.buildQueryKey(endpoint, config);
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
130
|
+
// Memoize the combined options to prevent unnecessary re-renders
|
|
131
|
+
const memoizedOptions = useMemo(
|
|
132
|
+
() => ({
|
|
133
|
+
queryKey,
|
|
134
|
+
queryFn: ({
|
|
135
|
+
pageParam,
|
|
136
|
+
}: QueryFunctionContext<unknown[], TPageParam>) => {
|
|
137
|
+
let mergedConfig = config;
|
|
138
|
+
if (pageParam !== undefined && config) {
|
|
139
|
+
// If pageParam is an object, spread it into query
|
|
140
|
+
const pageQuery =
|
|
141
|
+
typeof pageParam === 'object' ? pageParam : { page: pageParam };
|
|
142
|
+
mergedConfig = {
|
|
143
|
+
...config,
|
|
144
|
+
query: { ...(config as any).query, ...pageQuery },
|
|
145
|
+
} as any;
|
|
146
|
+
} else if (pageParam !== undefined && !config) {
|
|
147
|
+
// If pageParam is an object, use it directly, otherwise wrap in page property
|
|
148
|
+
const pageQuery =
|
|
149
|
+
typeof pageParam === 'object' ? pageParam : { page: pageParam };
|
|
150
|
+
mergedConfig = { query: pageQuery } as any;
|
|
151
|
+
}
|
|
152
|
+
return this.fetcher(endpoint, mergedConfig) as Promise<TPageData>;
|
|
153
|
+
},
|
|
154
|
+
...options,
|
|
155
|
+
}),
|
|
156
|
+
// Dependencies: queryKey, endpoint, config, and options
|
|
157
|
+
// Note: We stringify config and options to ensure stable references
|
|
158
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
159
|
+
[
|
|
160
|
+
queryKey.join(','),
|
|
161
|
+
endpoint,
|
|
162
|
+
JSON.stringify(config),
|
|
163
|
+
JSON.stringify(options),
|
|
164
|
+
],
|
|
165
|
+
);
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
return useInfiniteQuery<
|
|
168
|
+
TPageData,
|
|
169
|
+
Response,
|
|
170
|
+
{ pages: TPageData[]; pageParams: TPageParam[] },
|
|
171
|
+
unknown[],
|
|
172
|
+
TPageParam
|
|
173
|
+
>(memoizedOptions);
|
|
174
|
+
}
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
buildQueryKey<T extends TypedEndpoint<Paths>>(
|
|
177
|
+
endpoint: T,
|
|
178
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
179
|
+
): unknown[] {
|
|
180
|
+
const key: unknown[] = [endpoint];
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
182
|
+
if (config && 'params' in config && config.params) {
|
|
183
|
+
key.push({ params: config.params });
|
|
184
|
+
}
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
if (config && 'query' in config && config.query) {
|
|
187
|
+
key.push({ query: config.query });
|
|
188
|
+
}
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
return key;
|
|
191
|
+
}
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Invalidate queries for a specific endpoint with optional config
|
|
195
|
+
* @param endpoint - The endpoint to invalidate (e.g., 'GET /users')
|
|
196
|
+
* @param config - Optional params/query to match specific queries
|
|
197
|
+
* @returns Promise that resolves when invalidation is complete
|
|
198
|
+
*/
|
|
199
|
+
invalidateQueries<T extends QueryEndpoint<Paths>>(
|
|
200
|
+
endpoint: T,
|
|
201
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
202
|
+
): Promise<void> {
|
|
203
|
+
const queryClient = this.getQueryClient();
|
|
204
|
+
const queryKey = this.buildQueryKey(endpoint, config);
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
return queryClient.invalidateQueries({
|
|
207
|
+
queryKey,
|
|
208
|
+
exact: !!config, // Use exact matching if config is provided
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
212
|
+
/**
|
|
213
|
+
* Invalidate all queries in the cache
|
|
214
|
+
* @returns Promise that resolves when invalidation is complete
|
|
215
|
+
*/
|
|
216
|
+
invalidateAllQueries(): Promise<void> {
|
|
217
|
+
const queryClient = this.getQueryClient();
|
|
218
|
+
return queryClient.invalidateQueries();
|
|
219
|
+
}
|
|
220
220
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Get the underlying QueryClient instance
|
|
223
|
+
* @returns The QueryClient instance
|
|
224
|
+
*/
|
|
225
|
+
getQueryClient(): QueryClient {
|
|
226
|
+
if (this.queryClient) {
|
|
227
|
+
return this.queryClient;
|
|
228
|
+
}
|
|
229
229
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
// If no query client was provided, try to get it from context
|
|
231
|
+
// This will throw if used outside of QueryClientProvider
|
|
232
|
+
throw new Error(
|
|
233
|
+
'No QueryClient set, please provide a QueryClient via the queryClient option or ensure you are within a QueryClientProvider',
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Set the QueryClient instance
|
|
239
|
+
* @param queryClient - The QueryClient instance to use
|
|
240
|
+
*/
|
|
241
|
+
setQueryClient(queryClient: QueryClient): void {
|
|
242
|
+
this.queryClient = queryClient;
|
|
243
|
+
}
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
export function createTypedQueryClient<Paths>(
|
|
247
|
-
|
|
247
|
+
options?: TypedQueryClientOptions,
|
|
248
248
|
) {
|
|
249
|
-
|
|
249
|
+
return new TypedQueryClient<Paths>(options);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// Hook exports for convenience
|
|
253
253
|
export function useTypedQuery<Paths, T extends QueryEndpoint<Paths>>(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
client: TypedQueryClient<Paths>,
|
|
255
|
+
endpoint: T,
|
|
256
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
257
|
+
options?: Omit<
|
|
258
|
+
UseQueryOptions<ExtractEndpointResponse<Paths, T>, Response>,
|
|
259
|
+
'queryKey' | 'queryFn'
|
|
260
|
+
>,
|
|
261
261
|
) {
|
|
262
|
-
|
|
262
|
+
return client.useQuery(endpoint, config, options);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
export function useTypedMutation<Paths, T extends MutationEndpoint<Paths>>(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
266
|
+
client: TypedQueryClient<Paths>,
|
|
267
|
+
endpoint: T,
|
|
268
|
+
options?: Omit<
|
|
269
|
+
UseMutationOptions<
|
|
270
|
+
ExtractEndpointResponse<Paths, T>,
|
|
271
|
+
Response,
|
|
272
|
+
FilteredRequestConfig<Paths, T>
|
|
273
|
+
>,
|
|
274
|
+
'mutationFn'
|
|
275
|
+
>,
|
|
276
276
|
) {
|
|
277
|
-
|
|
277
|
+
return client.useMutation(endpoint, options);
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
export function useTypedInfiniteQuery<
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
281
|
+
Paths,
|
|
282
|
+
T extends QueryEndpoint<Paths>,
|
|
283
|
+
TPageData = ExtractEndpointResponse<Paths, T>,
|
|
284
|
+
TPageParam = unknown,
|
|
285
285
|
>(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
286
|
+
client: TypedQueryClient<Paths>,
|
|
287
|
+
endpoint: T,
|
|
288
|
+
options: Omit<
|
|
289
|
+
UseInfiniteQueryOptions<
|
|
290
|
+
TPageData,
|
|
291
|
+
Response,
|
|
292
|
+
{ pages: TPageData[]; pageParams: TPageParam[] },
|
|
293
|
+
unknown[],
|
|
294
|
+
TPageParam
|
|
295
|
+
>,
|
|
296
|
+
'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam'
|
|
297
|
+
> & {
|
|
298
|
+
getNextPageParam: (
|
|
299
|
+
lastPage: TPageData,
|
|
300
|
+
allPages: TPageData[],
|
|
301
|
+
lastPageParam: TPageParam,
|
|
302
|
+
allPageParams: TPageParam[],
|
|
303
|
+
) => TPageParam | undefined;
|
|
304
|
+
initialPageParam: TPageParam;
|
|
305
|
+
},
|
|
306
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
307
307
|
) {
|
|
308
|
-
|
|
308
|
+
return client.useInfiniteQuery(endpoint, options, config);
|
|
309
309
|
}
|
|
310
310
|
|
|
311
311
|
/**
|
|
312
312
|
* Hook to invalidate queries using the current QueryClient from context
|
|
313
313
|
*/
|
|
314
314
|
export function useTypedInvalidateQueries<Paths>(
|
|
315
|
-
|
|
315
|
+
client: TypedQueryClient<Paths>,
|
|
316
316
|
) {
|
|
317
|
-
|
|
317
|
+
const queryClient = useQueryClient();
|
|
318
318
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
319
|
+
return {
|
|
320
|
+
/**
|
|
321
|
+
* Invalidate queries for a specific endpoint
|
|
322
|
+
*/
|
|
323
|
+
invalidateQueries: <T extends QueryEndpoint<Paths>>(
|
|
324
|
+
endpoint: T,
|
|
325
|
+
config?: FilteredRequestConfig<Paths, T>,
|
|
326
|
+
) => {
|
|
327
|
+
const queryKey = client.buildQueryKey(endpoint, config);
|
|
328
|
+
return queryClient.invalidateQueries({
|
|
329
|
+
queryKey,
|
|
330
|
+
exact: !!config,
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
333
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
/**
|
|
335
|
+
* Invalidate all queries
|
|
336
|
+
*/
|
|
337
|
+
invalidateAllQueries: () => {
|
|
338
|
+
return queryClient.invalidateQueries();
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
341
|
}
|