@openapi-qraft/react 1.0.10 → 1.1.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 +8 -0
- package/dist/ServiceOperation.d.ts +98 -22
- package/dist/ServiceOperation.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryData.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryData.js +4 -4
- package/dist/callbacks/getInfiniteQueryData.js.map +1 -1
- package/dist/callbacks/getInfiniteQueryKey.d.ts +1 -5
- package/dist/callbacks/getInfiniteQueryKey.d.ts.map +1 -1
- package/dist/callbacks/getInfiniteQueryKey.js +2 -4
- package/dist/callbacks/getInfiniteQueryKey.js.map +1 -1
- package/dist/callbacks/getQueryData.d.ts.map +1 -1
- package/dist/callbacks/getQueryData.js +2 -4
- package/dist/callbacks/getQueryData.js.map +1 -1
- package/dist/callbacks/getQueryKey.d.ts +1 -4
- package/dist/callbacks/getQueryKey.d.ts.map +1 -1
- package/dist/callbacks/getQueryKey.js +2 -4
- package/dist/callbacks/getQueryKey.js.map +1 -1
- package/dist/callbacks/invalidateQueries.d.ts +5 -0
- package/dist/callbacks/invalidateQueries.d.ts.map +1 -0
- package/dist/callbacks/invalidateQueries.js +36 -0
- package/dist/callbacks/invalidateQueries.js.map +1 -0
- package/dist/callbacks/setInfiniteQueryData.d.ts.map +1 -1
- package/dist/callbacks/setInfiniteQueryData.js +4 -1
- package/dist/callbacks/setInfiniteQueryData.js.map +1 -1
- package/dist/callbacks/setQueryData.d.ts.map +1 -1
- package/dist/callbacks/setQueryData.js +4 -4
- package/dist/callbacks/setQueryData.js.map +1 -1
- package/dist/callbacks/useInfiniteQuery.d.ts.map +1 -1
- package/dist/callbacks/useInfiniteQuery.js +5 -4
- package/dist/callbacks/useInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useQueries.d.ts.map +1 -1
- package/dist/callbacks/useQueries.js +23 -15
- package/dist/callbacks/useQueries.js.map +1 -1
- package/dist/callbacks/useQuery.d.ts +1 -1
- package/dist/callbacks/useQuery.d.ts.map +1 -1
- package/dist/callbacks/useQuery.js +4 -4
- package/dist/callbacks/useQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.js +5 -4
- package/dist/callbacks/useSuspenseInfiniteQuery.js.map +1 -1
- package/dist/callbacks/useSuspenseQueries.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseQueries.js +23 -15
- package/dist/callbacks/useSuspenseQueries.js.map +1 -1
- package/dist/callbacks/useSuspenseQuery.d.ts.map +1 -1
- package/dist/callbacks/useSuspenseQuery.js +4 -4
- package/dist/callbacks/useSuspenseQuery.js.map +1 -1
- package/dist/lib/composeInfiniteQueryKey.d.ts +4 -0
- package/dist/lib/composeInfiniteQueryKey.d.ts.map +1 -0
- package/dist/lib/composeInfiniteQueryKey.js +4 -0
- package/dist/lib/composeInfiniteQueryKey.js.map +1 -0
- package/dist/lib/composeQueryKey.d.ts +4 -0
- package/dist/lib/composeQueryKey.d.ts.map +1 -0
- package/dist/lib/composeQueryKey.js +4 -0
- package/dist/lib/composeQueryKey.js.map +1 -0
- package/dist/lib/createRecursiveProxy.d.ts +7 -5
- package/dist/lib/createRecursiveProxy.d.ts.map +1 -1
- package/dist/lib/createRecursiveProxy.js +14 -9
- package/dist/lib/createRecursiveProxy.js.map +1 -1
- package/dist/lib/request.d.ts.map +1 -1
- package/dist/lib/request.js +15 -3
- package/dist/lib/request.js.map +1 -1
- package/dist/qraftAPIClient.d.ts.map +1 -1
- package/dist/qraftAPIClient.js +16 -7
- package/dist/qraftAPIClient.js.map +1 -1
- package/package.json +3 -2
- package/src/ServiceOperation.ts +152 -25
- package/src/callbacks/getInfiniteQueryData.ts +6 -4
- package/src/callbacks/getInfiniteQueryKey.ts +3 -8
- package/src/callbacks/getQueryData.ts +5 -8
- package/src/callbacks/getQueryKey.ts +3 -8
- package/src/callbacks/invalidateQueries.ts +70 -0
- package/src/callbacks/setInfiniteQueryData.ts +4 -1
- package/src/callbacks/setQueryData.ts +5 -4
- package/src/callbacks/useInfiniteQuery.ts +13 -5
- package/src/callbacks/useQueries.ts +30 -20
- package/src/callbacks/useQuery.ts +6 -9
- package/src/callbacks/useSuspenseInfiniteQuery.ts +13 -5
- package/src/callbacks/useSuspenseQueries.ts +30 -20
- package/src/callbacks/useSuspenseQuery.ts +5 -4
- package/src/lib/composeInfiniteQueryKey.ts +12 -0
- package/src/lib/composeQueryKey.ts +9 -0
- package/src/lib/createRecursiveProxy.ts +32 -11
- package/src/lib/request.ts +20 -2
- package/src/qraftAPIClient.ts +25 -13
- package/dist/lib/createCallbackProxyDecoration.d.ts +0 -5
- package/dist/lib/createCallbackProxyDecoration.d.ts.map +0 -1
- package/dist/lib/createCallbackProxyDecoration.js +0 -21
- package/dist/lib/createCallbackProxyDecoration.js.map +0 -1
- package/src/lib/createCallbackProxyDecoration.ts +0 -34
package/src/ServiceOperation.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DefaultError,
|
|
3
|
+
FetchStatus,
|
|
3
4
|
InfiniteData,
|
|
4
5
|
InfiniteQueryPageParamsOptions,
|
|
6
|
+
InvalidateOptions,
|
|
5
7
|
Mutation,
|
|
6
8
|
MutationState,
|
|
7
9
|
MutationStatus,
|
|
8
10
|
NoInfer,
|
|
9
11
|
QueriesPlaceholderDataFunction,
|
|
12
|
+
Query,
|
|
10
13
|
QueryClient,
|
|
11
14
|
SetDataOptions,
|
|
12
15
|
Updater,
|
|
@@ -56,10 +59,11 @@ export interface ServiceOperationQuery<
|
|
|
56
59
|
ServiceOperationUseSuspenseQueryQuery<TSchema, TData, TParams, TError>,
|
|
57
60
|
ServiceOperationUseSuspenseInfiniteQuery<TSchema, TData, TParams, TError>,
|
|
58
61
|
ServiceOperationQueryFn<TSchema, TData, TParams>,
|
|
59
|
-
ServiceOperationGetQueryData<TData, TParams>,
|
|
60
|
-
ServiceOperationGetInfiniteQueryData<TData, TParams>,
|
|
61
|
-
ServiceOperationSetQueryData<TData, TParams>,
|
|
62
|
-
ServiceOperationSetInfiniteQueryData<TData, TParams
|
|
62
|
+
ServiceOperationGetQueryData<TSchema, TData, TParams>,
|
|
63
|
+
ServiceOperationGetInfiniteQueryData<TSchema, TData, TParams>,
|
|
64
|
+
ServiceOperationSetQueryData<TSchema, TData, TParams>,
|
|
65
|
+
ServiceOperationSetInfiniteQueryData<TSchema, TData, TParams>,
|
|
66
|
+
ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError> {
|
|
63
67
|
schema: TSchema;
|
|
64
68
|
types: {
|
|
65
69
|
parameters: TParams;
|
|
@@ -74,12 +78,12 @@ interface ServiceOperationUseQuery<
|
|
|
74
78
|
TParams = {},
|
|
75
79
|
TError = DefaultError,
|
|
76
80
|
> {
|
|
77
|
-
getQueryKey<QueryKeyParams extends TParams>(
|
|
78
|
-
parameters
|
|
81
|
+
getQueryKey<QueryKeyParams extends TParams | undefined = undefined>(
|
|
82
|
+
parameters?: QueryKeyParams
|
|
79
83
|
): ServiceOperationQueryKey<TSchema, QueryKeyParams>;
|
|
80
84
|
|
|
81
85
|
useQuery(
|
|
82
|
-
parameters: TParams,
|
|
86
|
+
parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
|
|
83
87
|
options?: Omit<
|
|
84
88
|
UndefinedInitialDataOptions<
|
|
85
89
|
TData,
|
|
@@ -92,7 +96,7 @@ interface ServiceOperationUseQuery<
|
|
|
92
96
|
queryClient?: QueryClient
|
|
93
97
|
): UseQueryResult<TData, TError | Error>;
|
|
94
98
|
useQuery(
|
|
95
|
-
parameters: TParams,
|
|
99
|
+
parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
|
|
96
100
|
options: Omit<
|
|
97
101
|
DefinedInitialDataOptions<
|
|
98
102
|
TData,
|
|
@@ -124,9 +128,11 @@ interface ServiceOperationUseQueries<
|
|
|
124
128
|
>,
|
|
125
129
|
'placeholderData' | 'suspense' | 'queryKey'
|
|
126
130
|
> & {
|
|
127
|
-
parameters: TParams;
|
|
128
131
|
placeholderData?: TData | QueriesPlaceholderDataFunction<TData>;
|
|
129
|
-
}
|
|
132
|
+
} & (
|
|
133
|
+
| { parameters: TParams }
|
|
134
|
+
| { queryKey: ServiceOperationQueryKey<TSchema, TParams> }
|
|
135
|
+
)
|
|
130
136
|
>;
|
|
131
137
|
combine?: (
|
|
132
138
|
results: Array<UseQueryResult<TData, TError>>
|
|
@@ -136,6 +142,108 @@ interface ServiceOperationUseQueries<
|
|
|
136
142
|
): TCombinedResult;
|
|
137
143
|
}
|
|
138
144
|
|
|
145
|
+
type QueryTypeFilter = 'all' | 'active' | 'inactive';
|
|
146
|
+
|
|
147
|
+
interface InvalidateQueryFiltersBase<
|
|
148
|
+
TSchema extends { url: string; method: string },
|
|
149
|
+
TData,
|
|
150
|
+
TParams = {},
|
|
151
|
+
TError = DefaultError,
|
|
152
|
+
> {
|
|
153
|
+
/**
|
|
154
|
+
* Filter to active queries, inactive queries or all queries
|
|
155
|
+
*/
|
|
156
|
+
type?: QueryTypeFilter;
|
|
157
|
+
/**
|
|
158
|
+
* Match query key exactly
|
|
159
|
+
*/
|
|
160
|
+
exact?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Include queries matching this predicate function
|
|
163
|
+
*/
|
|
164
|
+
predicate?: (
|
|
165
|
+
query: Query<
|
|
166
|
+
TData,
|
|
167
|
+
TError,
|
|
168
|
+
TData,
|
|
169
|
+
| ServiceOperationQueryKey<TSchema, TParams>
|
|
170
|
+
| ServiceOperationInfiniteQueryKey<TSchema, TParams>
|
|
171
|
+
>
|
|
172
|
+
) => boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Include or exclude stale queries
|
|
175
|
+
*/
|
|
176
|
+
stale?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Include queries matching their fetchStatus
|
|
179
|
+
*/
|
|
180
|
+
fetchStatus?: FetchStatus;
|
|
181
|
+
|
|
182
|
+
refetchType?: QueryTypeFilter | 'none';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
interface InvalidateQueryFiltersByQueryKey<
|
|
186
|
+
TSchema extends { url: string; method: string },
|
|
187
|
+
TData,
|
|
188
|
+
TParams = {},
|
|
189
|
+
TError = DefaultError,
|
|
190
|
+
> extends InvalidateQueryFiltersBase<TSchema, TData, TParams, TError> {
|
|
191
|
+
/**
|
|
192
|
+
* Include queries matching this query key
|
|
193
|
+
*/
|
|
194
|
+
queryKey?: ServiceOperationQueryKey<TSchema, TParams>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
interface InvalidateQueryFiltersByParameters<
|
|
198
|
+
TSchema extends { url: string; method: string },
|
|
199
|
+
TData,
|
|
200
|
+
TParams = {},
|
|
201
|
+
TError = DefaultError,
|
|
202
|
+
> extends InvalidateQueryFiltersBase<TSchema, TData, TParams, TError> {
|
|
203
|
+
/**
|
|
204
|
+
* Include queries matching parameters
|
|
205
|
+
*/
|
|
206
|
+
parameters?: TParams;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface ServiceOperationInvalidateQueries<
|
|
210
|
+
TSchema extends { url: string; method: string },
|
|
211
|
+
TData,
|
|
212
|
+
TParams = {},
|
|
213
|
+
TError = DefaultError,
|
|
214
|
+
> {
|
|
215
|
+
invalidateQueries(
|
|
216
|
+
filters:
|
|
217
|
+
| InvalidateQueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
218
|
+
| InvalidateQueryFiltersByQueryKey<TSchema, TData, TParams, TError>,
|
|
219
|
+
options: InvalidateOptions,
|
|
220
|
+
queryClient: QueryClient
|
|
221
|
+
): Promise<void>;
|
|
222
|
+
invalidateQueries(
|
|
223
|
+
filters:
|
|
224
|
+
| InvalidateQueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
225
|
+
| InvalidateQueryFiltersByQueryKey<TSchema, TData, TParams, TError>,
|
|
226
|
+
queryClient: QueryClient
|
|
227
|
+
): Promise<void>;
|
|
228
|
+
invalidateQueries(queryClient: QueryClient): Promise<void>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface ServiceOperationInvalidateQueriesCallback<
|
|
232
|
+
TSchema extends { url: string; method: string },
|
|
233
|
+
TData,
|
|
234
|
+
TParams = {},
|
|
235
|
+
TError = DefaultError,
|
|
236
|
+
> extends ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError> {
|
|
237
|
+
invalidateQueries(
|
|
238
|
+
filters:
|
|
239
|
+
| InvalidateQueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
240
|
+
| InvalidateQueryFiltersByQueryKey<TSchema, TData, TParams, TError>
|
|
241
|
+
| QueryClient,
|
|
242
|
+
options?: InvalidateOptions | QueryClient,
|
|
243
|
+
queryClient?: QueryClient
|
|
244
|
+
): Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
|
|
139
247
|
interface ServiceOperationUseSuspenseQueries<
|
|
140
248
|
TSchema extends { url: string; method: string },
|
|
141
249
|
TData,
|
|
@@ -155,7 +263,11 @@ interface ServiceOperationUseSuspenseQueries<
|
|
|
155
263
|
ServiceOperationQueryKey<TSchema, TParams>
|
|
156
264
|
>,
|
|
157
265
|
'queryKey'
|
|
158
|
-
> &
|
|
266
|
+
> &
|
|
267
|
+
(
|
|
268
|
+
| { parameters: TParams }
|
|
269
|
+
| { queryKey: ServiceOperationQueryKey<TSchema, TParams> }
|
|
270
|
+
)
|
|
159
271
|
>;
|
|
160
272
|
combine?: (
|
|
161
273
|
results: Array<UseSuspenseQueryResult<TData, TError>>
|
|
@@ -176,7 +288,7 @@ interface ServiceOperationUseInfiniteQuery<
|
|
|
176
288
|
): ServiceOperationInfiniteQueryKey<TSchema, TQueryKeyParams>;
|
|
177
289
|
|
|
178
290
|
useInfiniteQuery<TPageParam extends TParams>(
|
|
179
|
-
parameters: TParams,
|
|
291
|
+
parameters: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>,
|
|
180
292
|
options: Omit<
|
|
181
293
|
UndefinedInitialDataInfiniteOptions<
|
|
182
294
|
TData,
|
|
@@ -194,7 +306,7 @@ interface ServiceOperationUseInfiniteQuery<
|
|
|
194
306
|
queryClient?: QueryClient
|
|
195
307
|
): UseInfiniteQueryResult<InfiniteData<TData>, TError | Error>;
|
|
196
308
|
useInfiniteQuery<TPageParam extends TParams>(
|
|
197
|
-
parameters: TParams,
|
|
309
|
+
parameters: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>,
|
|
198
310
|
options: Omit<
|
|
199
311
|
DefinedInitialDataInfiniteOptions<
|
|
200
312
|
TData,
|
|
@@ -220,7 +332,7 @@ interface ServiceOperationUseSuspenseInfiniteQuery<
|
|
|
220
332
|
TError = DefaultError,
|
|
221
333
|
> {
|
|
222
334
|
useSuspenseInfiniteQuery<TPageParam extends TParams>(
|
|
223
|
-
parameters: TParams,
|
|
335
|
+
parameters: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>,
|
|
224
336
|
options: Omit<
|
|
225
337
|
UseSuspenseInfiniteQueryOptions<
|
|
226
338
|
TData,
|
|
@@ -247,7 +359,7 @@ interface ServiceOperationUseSuspenseQueryQuery<
|
|
|
247
359
|
TError = DefaultError,
|
|
248
360
|
> {
|
|
249
361
|
useSuspenseQuery(
|
|
250
|
-
parameters: TParams,
|
|
362
|
+
parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
|
|
251
363
|
options?: Omit<
|
|
252
364
|
UseSuspenseQueryOptions<
|
|
253
365
|
TData,
|
|
@@ -269,8 +381,7 @@ export interface ServiceOperationMutation<
|
|
|
269
381
|
TError = DefaultError,
|
|
270
382
|
> extends ServiceOperationUseMutation<TSchema, TBody, TData, TParams, TError>,
|
|
271
383
|
ServiceOperationUseMutationState<TSchema, TBody, TData, TParams, TError>,
|
|
272
|
-
ServiceOperationMutationFn<TSchema, TBody, TData, TParams
|
|
273
|
-
ServiceOperationSetQueryData<TData, TParams> {
|
|
384
|
+
ServiceOperationMutationFn<TSchema, TBody, TData, TParams> {
|
|
274
385
|
schema: TSchema;
|
|
275
386
|
types: {
|
|
276
387
|
parameters: TParams;
|
|
@@ -489,18 +600,26 @@ interface ServiceOperationQueryFn<
|
|
|
489
600
|
): Promise<TData>;
|
|
490
601
|
}
|
|
491
602
|
|
|
492
|
-
interface ServiceOperationSetQueryData<
|
|
603
|
+
interface ServiceOperationSetQueryData<
|
|
604
|
+
TSchema extends { url: string; method: string },
|
|
605
|
+
TData,
|
|
606
|
+
TParams = {}, // todo::try to replace `TParams = {}` with `TParams = undefined`
|
|
607
|
+
> {
|
|
493
608
|
setQueryData(
|
|
494
|
-
parameters: TParams,
|
|
609
|
+
parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
|
|
495
610
|
updater: Updater<NoInfer<TData> | undefined, NoInfer<TData> | undefined>,
|
|
496
611
|
queryClient: QueryClient,
|
|
497
612
|
options?: SetDataOptions
|
|
498
613
|
): TData | undefined;
|
|
499
614
|
}
|
|
500
615
|
|
|
501
|
-
interface ServiceOperationSetInfiniteQueryData<
|
|
616
|
+
interface ServiceOperationSetInfiniteQueryData<
|
|
617
|
+
TSchema extends { url: string; method: string },
|
|
618
|
+
TData,
|
|
619
|
+
TParams = {},
|
|
620
|
+
> {
|
|
502
621
|
setInfiniteQueryData(
|
|
503
|
-
parameters: TParams,
|
|
622
|
+
parameters: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>,
|
|
504
623
|
updater: Updater<
|
|
505
624
|
NoInfer<InfiniteData<TData>> | undefined,
|
|
506
625
|
NoInfer<InfiniteData<TData>> | undefined
|
|
@@ -510,16 +629,24 @@ interface ServiceOperationSetInfiniteQueryData<TData, TParams = {}> {
|
|
|
510
629
|
): InfiniteData<TData> | undefined;
|
|
511
630
|
}
|
|
512
631
|
|
|
513
|
-
interface ServiceOperationGetQueryData<
|
|
632
|
+
interface ServiceOperationGetQueryData<
|
|
633
|
+
TSchema extends { url: string; method: string },
|
|
634
|
+
TData,
|
|
635
|
+
TParams = {},
|
|
636
|
+
> {
|
|
514
637
|
getQueryData(
|
|
515
|
-
parameters: TParams,
|
|
638
|
+
parameters: TParams | ServiceOperationQueryKey<TSchema, TParams>,
|
|
516
639
|
queryClient: QueryClient
|
|
517
640
|
): TData | undefined;
|
|
518
641
|
}
|
|
519
642
|
|
|
520
|
-
interface ServiceOperationGetInfiniteQueryData<
|
|
643
|
+
interface ServiceOperationGetInfiniteQueryData<
|
|
644
|
+
TSchema extends { url: string; method: string },
|
|
645
|
+
TData,
|
|
646
|
+
TParams = {},
|
|
647
|
+
> {
|
|
521
648
|
getInfiniteQueryData(
|
|
522
|
-
parameters: TParams,
|
|
649
|
+
parameters: TParams | ServiceOperationInfiniteQueryKey<TSchema, TParams>,
|
|
523
650
|
queryClient: QueryClient
|
|
524
651
|
): InfiniteData<TData> | undefined;
|
|
525
652
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InfiniteData } from '@tanstack/query-core';
|
|
2
2
|
|
|
3
|
+
import { composeInfiniteQueryKey } from '../lib/composeInfiniteQueryKey.js';
|
|
3
4
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
4
5
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
5
6
|
import {
|
|
@@ -19,8 +20,9 @@ export function getInfiniteQueryData<TData>(
|
|
|
19
20
|
>
|
|
20
21
|
): InfiniteData<TData> | undefined {
|
|
21
22
|
const [parameters, queryClient] = args;
|
|
22
|
-
return queryClient.getQueryData(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
return queryClient.getQueryData(
|
|
24
|
+
Array.isArray(parameters)
|
|
25
|
+
? parameters
|
|
26
|
+
: composeInfiniteQueryKey(schema, parameters)
|
|
27
|
+
);
|
|
26
28
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { composeInfiniteQueryKey } from '../lib/composeInfiniteQueryKey.js';
|
|
1
2
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
2
3
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
3
|
-
import {
|
|
4
|
-
ServiceOperationInfiniteQueryKey,
|
|
5
|
-
ServiceOperationQuery,
|
|
6
|
-
} from '../ServiceOperation.js';
|
|
4
|
+
import { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
7
5
|
|
|
8
6
|
export const getInfiniteQueryKey = (
|
|
9
7
|
qraftOptions: QraftClientOptions | undefined,
|
|
@@ -16,8 +14,5 @@ export const getInfiniteQueryKey = (
|
|
|
16
14
|
>['getInfiniteQueryKey']
|
|
17
15
|
>
|
|
18
16
|
) => {
|
|
19
|
-
return [
|
|
20
|
-
{ url: schema.url, method: schema.method, infinite: true },
|
|
21
|
-
args[0],
|
|
22
|
-
] satisfies ServiceOperationInfiniteQueryKey<RequestClientSchema, unknown>;
|
|
17
|
+
return composeInfiniteQueryKey(schema, args[0]);
|
|
23
18
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
1
2
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
2
3
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
3
|
-
import {
|
|
4
|
-
ServiceOperationQuery,
|
|
5
|
-
ServiceOperationQueryKey,
|
|
6
|
-
} from '../ServiceOperation.js';
|
|
4
|
+
import { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
7
5
|
|
|
8
6
|
export function getQueryData<TData>(
|
|
9
7
|
qraftOptions: QraftClientOptions | undefined,
|
|
@@ -13,8 +11,7 @@ export function getQueryData<TData>(
|
|
|
13
11
|
>
|
|
14
12
|
): TData | undefined {
|
|
15
13
|
const [parameters, queryClient] = args;
|
|
16
|
-
return queryClient.getQueryData(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
] satisfies ServiceOperationQueryKey<RequestClientSchema, unknown>);
|
|
14
|
+
return queryClient.getQueryData(
|
|
15
|
+
Array.isArray(parameters) ? parameters : composeQueryKey(schema, parameters)
|
|
16
|
+
);
|
|
20
17
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
1
2
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
2
3
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
3
|
-
import {
|
|
4
|
-
ServiceOperationQuery,
|
|
5
|
-
ServiceOperationQueryKey,
|
|
6
|
-
} from '../ServiceOperation.js';
|
|
4
|
+
import { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
7
5
|
|
|
8
6
|
export const getQueryKey = (
|
|
9
7
|
qraftOptions: QraftClientOptions | undefined,
|
|
@@ -12,8 +10,5 @@ export const getQueryKey = (
|
|
|
12
10
|
ServiceOperationQuery<RequestClientSchema, unknown, unknown>['getQueryKey']
|
|
13
11
|
>
|
|
14
12
|
) => {
|
|
15
|
-
return [
|
|
16
|
-
{ url: schema.url, method: schema.method },
|
|
17
|
-
args[0],
|
|
18
|
-
] satisfies ServiceOperationQueryKey<RequestClientSchema, unknown>;
|
|
13
|
+
return composeQueryKey(schema, args[0]);
|
|
19
14
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { InvalidateOptions } from '@tanstack/query-core';
|
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
5
|
+
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
6
|
+
import type { RequestClientSchema } from '../RequestClient.js';
|
|
7
|
+
import { ServiceOperationInvalidateQueriesCallback } from '../ServiceOperation.js';
|
|
8
|
+
|
|
9
|
+
export function invalidateQueries<TData>(
|
|
10
|
+
qraftOptions: QraftClientOptions | undefined,
|
|
11
|
+
schema: RequestClientSchema,
|
|
12
|
+
args: Parameters<
|
|
13
|
+
ServiceOperationInvalidateQueriesCallback<
|
|
14
|
+
RequestClientSchema,
|
|
15
|
+
unknown,
|
|
16
|
+
TData
|
|
17
|
+
>['invalidateQueries']
|
|
18
|
+
>
|
|
19
|
+
): Promise<void> {
|
|
20
|
+
const queryClient = (
|
|
21
|
+
args.length === 1
|
|
22
|
+
? args[0]
|
|
23
|
+
: args.length === 2
|
|
24
|
+
? args[1]
|
|
25
|
+
: args.length === 3
|
|
26
|
+
? args[2]
|
|
27
|
+
: undefined
|
|
28
|
+
) as QueryClient | undefined;
|
|
29
|
+
|
|
30
|
+
const filters = args.length === 1 ? undefined : args[0];
|
|
31
|
+
const options = (args.length === 3 ? args[1] : undefined) as
|
|
32
|
+
| InvalidateOptions
|
|
33
|
+
| undefined;
|
|
34
|
+
|
|
35
|
+
if (!queryClient) throw new Error('queryClient is required');
|
|
36
|
+
if (!queryClient.invalidateQueries) throw new Error('queryClient is invalid');
|
|
37
|
+
|
|
38
|
+
if (!filters) {
|
|
39
|
+
return queryClient.invalidateQueries(
|
|
40
|
+
{
|
|
41
|
+
queryKey: composeQueryKey(schema, undefined),
|
|
42
|
+
},
|
|
43
|
+
options
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if ('queryKey' in filters) {
|
|
48
|
+
return queryClient.invalidateQueries(filters as never, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ('parameters' in filters) {
|
|
52
|
+
const { parameters, ...filtersRest } = filters;
|
|
53
|
+
|
|
54
|
+
return queryClient.invalidateQueries(
|
|
55
|
+
{
|
|
56
|
+
...filtersRest,
|
|
57
|
+
queryKey: composeQueryKey(schema, parameters),
|
|
58
|
+
} as never,
|
|
59
|
+
options
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return queryClient.invalidateQueries(
|
|
64
|
+
{
|
|
65
|
+
...filters,
|
|
66
|
+
queryKey: composeQueryKey(schema, undefined),
|
|
67
|
+
} as never,
|
|
68
|
+
options
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InfiniteData } from '@tanstack/query-core';
|
|
2
2
|
|
|
3
|
+
import { composeInfiniteQueryKey } from '../lib/composeInfiniteQueryKey.js';
|
|
3
4
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
4
5
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
5
6
|
import type {
|
|
@@ -23,7 +24,9 @@ export function setInfiniteQueryData<TData>(
|
|
|
23
24
|
const queryKey: ServiceOperationInfiniteQueryKey<
|
|
24
25
|
RequestClientSchema,
|
|
25
26
|
unknown
|
|
26
|
-
> =
|
|
27
|
+
> = Array.isArray(parameters)
|
|
28
|
+
? parameters
|
|
29
|
+
: composeInfiniteQueryKey(schema, parameters);
|
|
27
30
|
|
|
28
31
|
return queryClient.setQueryData(queryKey, updater as never, options);
|
|
29
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
1
2
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
2
3
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
3
4
|
import {
|
|
@@ -14,10 +15,10 @@ export function setQueryData<TData>(
|
|
|
14
15
|
): TData | undefined {
|
|
15
16
|
const [parameters, updater, queryClient, options] = args;
|
|
16
17
|
|
|
17
|
-
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> =
|
|
19
|
+
Array.isArray(parameters)
|
|
20
|
+
? parameters
|
|
21
|
+
: composeQueryKey(schema, parameters);
|
|
21
22
|
|
|
22
23
|
return queryClient.setQueryData(queryKey, updater as never, options);
|
|
23
24
|
}
|
|
@@ -9,11 +9,15 @@ import {
|
|
|
9
9
|
useQueryClient,
|
|
10
10
|
} from '@tanstack/react-query';
|
|
11
11
|
|
|
12
|
+
import { composeInfiniteQueryKey } from '../lib/composeInfiniteQueryKey.js';
|
|
12
13
|
import { shelfMerge } from '../lib/shelfMerge.js';
|
|
13
14
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
14
15
|
import { QraftContext } from '../QraftContext.js';
|
|
15
16
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
ServiceOperationInfiniteQueryKey,
|
|
19
|
+
ServiceOperationQuery,
|
|
20
|
+
} from '../ServiceOperation.js';
|
|
17
21
|
|
|
18
22
|
export const useInfiniteQuery: <
|
|
19
23
|
TQueryFnData,
|
|
@@ -37,13 +41,17 @@ export const useInfiniteQuery: <
|
|
|
37
41
|
|
|
38
42
|
if (!requestClient) throw new Error(`QraftContext.requestClient not found`);
|
|
39
43
|
|
|
44
|
+
const queryKey: ServiceOperationInfiniteQueryKey<
|
|
45
|
+
RequestClientSchema,
|
|
46
|
+
unknown
|
|
47
|
+
> = Array.isArray(parameters)
|
|
48
|
+
? (parameters as never)
|
|
49
|
+
: composeInfiniteQueryKey(schema, parameters);
|
|
50
|
+
|
|
40
51
|
return useInfiniteQueryBase(
|
|
41
52
|
{
|
|
42
53
|
...options,
|
|
43
|
-
queryKey
|
|
44
|
-
{ url: schema.url, method: schema.method, infinite: true },
|
|
45
|
-
parameters as never,
|
|
46
|
-
] as const,
|
|
54
|
+
queryKey,
|
|
47
55
|
queryFn:
|
|
48
56
|
options?.queryFn ??
|
|
49
57
|
function ({ queryKey: [, queryParams], signal, meta, pageParam }) {
|
|
@@ -8,13 +8,11 @@ import {
|
|
|
8
8
|
useQueryClient,
|
|
9
9
|
} from '@tanstack/react-query';
|
|
10
10
|
|
|
11
|
+
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
11
12
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
12
13
|
import { QraftContext } from '../QraftContext.js';
|
|
13
14
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
14
|
-
import {
|
|
15
|
-
ServiceOperationQuery,
|
|
16
|
-
ServiceOperationQueryKey,
|
|
17
|
-
} from '../ServiceOperation.js';
|
|
15
|
+
import { ServiceOperationQuery } from '../ServiceOperation.js';
|
|
18
16
|
|
|
19
17
|
export const useQueries: (
|
|
20
18
|
qraftOptions: QraftClientOptions | undefined,
|
|
@@ -33,22 +31,34 @@ export const useQueries: (
|
|
|
33
31
|
return useQueriesTanstack(
|
|
34
32
|
{
|
|
35
33
|
...options,
|
|
36
|
-
queries: options.queries.map((
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
queries: options.queries.map((queryOptions) => {
|
|
35
|
+
const optionsWithQueryKey =
|
|
36
|
+
'parameters' in queryOptions
|
|
37
|
+
? (() => {
|
|
38
|
+
const queryOptionsCopy = Object.assign(
|
|
39
|
+
{
|
|
40
|
+
queryKey: composeQueryKey(schema, queryOptions.parameters),
|
|
41
|
+
},
|
|
42
|
+
queryOptions
|
|
43
|
+
);
|
|
44
|
+
delete queryOptionsCopy.parameters;
|
|
45
|
+
return queryOptionsCopy;
|
|
46
|
+
})()
|
|
47
|
+
: queryOptions;
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
...optionsWithQueryKey,
|
|
51
|
+
queryFn:
|
|
52
|
+
optionsWithQueryKey.queryFn ??
|
|
53
|
+
function ({ queryKey: [, queryParams], signal, meta }) {
|
|
54
|
+
return requestClient(schema, {
|
|
55
|
+
parameters: queryParams as never,
|
|
56
|
+
signal,
|
|
57
|
+
meta,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}),
|
|
52
62
|
},
|
|
53
63
|
useQueryClient(queryClientByArg ?? queryClientByContext)
|
|
54
64
|
) as never;
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
UseQueryResult,
|
|
10
10
|
} from '@tanstack/react-query';
|
|
11
11
|
|
|
12
|
+
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
12
13
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
13
14
|
import { QraftContext } from '../QraftContext.js';
|
|
14
15
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
@@ -17,11 +18,7 @@ import {
|
|
|
17
18
|
ServiceOperationQueryKey,
|
|
18
19
|
} from '../ServiceOperation.js';
|
|
19
20
|
|
|
20
|
-
export const useQuery: <
|
|
21
|
-
TQueryFnData = unknown,
|
|
22
|
-
TError = DefaultError,
|
|
23
|
-
TData = TQueryFnData,
|
|
24
|
-
>(
|
|
21
|
+
export const useQuery: <TData = unknown, TError = DefaultError>(
|
|
25
22
|
qraftOptions: QraftClientOptions | undefined,
|
|
26
23
|
schema: RequestClientSchema,
|
|
27
24
|
args: Parameters<
|
|
@@ -35,10 +32,10 @@ export const useQuery: <
|
|
|
35
32
|
|
|
36
33
|
if (!requestClient) throw new Error(`QraftContext.requestClient not found`);
|
|
37
34
|
|
|
38
|
-
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
const queryKey: ServiceOperationQueryKey<RequestClientSchema, unknown> =
|
|
36
|
+
Array.isArray(parameters)
|
|
37
|
+
? (parameters as ServiceOperationQueryKey<RequestClientSchema, unknown>)
|
|
38
|
+
: composeQueryKey(schema, parameters);
|
|
42
39
|
|
|
43
40
|
return useQueryTanstack(
|
|
44
41
|
{
|
|
@@ -9,11 +9,15 @@ import {
|
|
|
9
9
|
UseSuspenseInfiniteQueryResult,
|
|
10
10
|
} from '@tanstack/react-query';
|
|
11
11
|
|
|
12
|
+
import { composeInfiniteQueryKey } from '../lib/composeInfiniteQueryKey.js';
|
|
12
13
|
import { shelfMerge } from '../lib/shelfMerge.js';
|
|
13
14
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
14
15
|
import { QraftContext } from '../QraftContext.js';
|
|
15
16
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
ServiceOperationInfiniteQueryKey,
|
|
19
|
+
ServiceOperationQuery,
|
|
20
|
+
} from '../ServiceOperation.js';
|
|
17
21
|
|
|
18
22
|
export const useSuspenseInfiniteQuery: <
|
|
19
23
|
TQueryFnData,
|
|
@@ -41,13 +45,17 @@ export const useSuspenseInfiniteQuery: <
|
|
|
41
45
|
|
|
42
46
|
if (!requestClient) throw new Error(`QraftContext.requestClient not found`);
|
|
43
47
|
|
|
48
|
+
const queryKey: ServiceOperationInfiniteQueryKey<
|
|
49
|
+
RequestClientSchema,
|
|
50
|
+
unknown
|
|
51
|
+
> = Array.isArray(parameters)
|
|
52
|
+
? (parameters as never)
|
|
53
|
+
: composeInfiniteQueryKey(schema, parameters);
|
|
54
|
+
|
|
44
55
|
return useSuspenseInfiniteQueryTanstack(
|
|
45
56
|
{
|
|
46
57
|
...options,
|
|
47
|
-
queryKey
|
|
48
|
-
{ url: schema.url, method: schema.method, infinite: true },
|
|
49
|
-
parameters as never,
|
|
50
|
-
] as const,
|
|
58
|
+
queryKey,
|
|
51
59
|
queryFn:
|
|
52
60
|
options?.queryFn ??
|
|
53
61
|
function ({ queryKey: [, queryParams], signal, meta, pageParam }) {
|