@openapi-qraft/react 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +117 -8
- package/package.json +3 -2
- package/src/ServiceOperation.ts +70 -18
- package/src/callbacks/cancelQueries.ts +22 -0
- package/src/callbacks/invalidateQueries.ts +7 -55
- package/src/lib/callQueryClientMethodWithQueryFilters.ts +84 -0
- package/dist/QraftContext.d.ts +0 -11
- package/dist/QraftContext.d.ts.map +0 -1
- package/dist/QraftContext.js +0 -4
- package/dist/QraftContext.js.map +0 -1
- package/dist/RequestClient.d.ts +0 -19
- package/dist/RequestClient.d.ts.map +0 -1
- package/dist/RequestClient.js +0 -2
- package/dist/RequestClient.js.map +0 -1
- package/dist/ServiceOperation.d.ts +0 -287
- package/dist/ServiceOperation.d.ts.map +0 -1
- package/dist/ServiceOperation.js +0 -2
- package/dist/ServiceOperation.js.map +0 -1
- package/dist/callbacks/getInfiniteQueryData.d.ts +0 -6
- package/dist/callbacks/getInfiniteQueryData.d.ts.map +0 -1
- package/dist/callbacks/getInfiniteQueryData.js +0 -8
- package/dist/callbacks/getInfiniteQueryData.js.map +0 -1
- package/dist/callbacks/getInfiniteQueryKey.d.ts +0 -5
- package/dist/callbacks/getInfiniteQueryKey.d.ts.map +0 -1
- package/dist/callbacks/getInfiniteQueryKey.js +0 -5
- package/dist/callbacks/getInfiniteQueryKey.js.map +0 -1
- package/dist/callbacks/getMutationKey.d.ts +0 -5
- package/dist/callbacks/getMutationKey.d.ts.map +0 -1
- package/dist/callbacks/getMutationKey.js +0 -5
- package/dist/callbacks/getMutationKey.js.map +0 -1
- package/dist/callbacks/getQueryData.d.ts +0 -5
- package/dist/callbacks/getQueryData.d.ts.map +0 -1
- package/dist/callbacks/getQueryData.js +0 -6
- package/dist/callbacks/getQueryData.js.map +0 -1
- package/dist/callbacks/getQueryKey.d.ts +0 -5
- package/dist/callbacks/getQueryKey.d.ts.map +0 -1
- package/dist/callbacks/getQueryKey.js +0 -5
- package/dist/callbacks/getQueryKey.js.map +0 -1
- package/dist/callbacks/invalidateQueries.d.ts +0 -5
- package/dist/callbacks/invalidateQueries.d.ts.map +0 -1
- package/dist/callbacks/invalidateQueries.js +0 -36
- package/dist/callbacks/invalidateQueries.js.map +0 -1
- package/dist/callbacks/mutationFn.d.ts +0 -4
- package/dist/callbacks/mutationFn.d.ts.map +0 -1
- package/dist/callbacks/mutationFn.js +0 -8
- package/dist/callbacks/mutationFn.js.map +0 -1
- package/dist/callbacks/queryFn.d.ts +0 -7
- package/dist/callbacks/queryFn.d.ts.map +0 -1
- package/dist/callbacks/queryFn.js +0 -9
- package/dist/callbacks/queryFn.js.map +0 -1
- package/dist/callbacks/setInfiniteQueryData.d.ts +0 -6
- package/dist/callbacks/setInfiniteQueryData.d.ts.map +0 -1
- package/dist/callbacks/setInfiniteQueryData.js +0 -9
- package/dist/callbacks/setInfiniteQueryData.js.map +0 -1
- package/dist/callbacks/setQueryData.d.ts +0 -5
- package/dist/callbacks/setQueryData.d.ts.map +0 -1
- package/dist/callbacks/setQueryData.js +0 -9
- package/dist/callbacks/setQueryData.js.map +0 -1
- package/dist/callbacks/useInfiniteQuery.d.ts +0 -7
- package/dist/callbacks/useInfiniteQuery.d.ts.map +0 -1
- package/dist/callbacks/useInfiniteQuery.js +0 -28
- package/dist/callbacks/useInfiniteQuery.js.map +0 -1
- package/dist/callbacks/useMutation.d.ts +0 -7
- package/dist/callbacks/useMutation.d.ts.map +0 -1
- package/dist/callbacks/useMutation.js +0 -39
- package/dist/callbacks/useMutation.js.map +0 -1
- package/dist/callbacks/useMutationState.d.ts +0 -7
- package/dist/callbacks/useMutationState.d.ts.map +0 -1
- package/dist/callbacks/useMutationState.js +0 -29
- package/dist/callbacks/useMutationState.js.map +0 -1
- package/dist/callbacks/useQueries.d.ts +0 -6
- package/dist/callbacks/useQueries.d.ts.map +0 -1
- package/dist/callbacks/useQueries.js +0 -37
- package/dist/callbacks/useQueries.js.map +0 -1
- package/dist/callbacks/useQuery.d.ts +0 -7
- package/dist/callbacks/useQuery.d.ts.map +0 -1
- package/dist/callbacks/useQuery.js +0 -27
- package/dist/callbacks/useQuery.js.map +0 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.d.ts +0 -7
- package/dist/callbacks/useSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/callbacks/useSuspenseInfiniteQuery.js +0 -28
- package/dist/callbacks/useSuspenseInfiniteQuery.js.map +0 -1
- package/dist/callbacks/useSuspenseQueries.d.ts +0 -6
- package/dist/callbacks/useSuspenseQueries.d.ts.map +0 -1
- package/dist/callbacks/useSuspenseQueries.js +0 -37
- package/dist/callbacks/useSuspenseQueries.js.map +0 -1
- package/dist/callbacks/useSuspenseQuery.d.ts +0 -7
- package/dist/callbacks/useSuspenseQuery.d.ts.map +0 -1
- package/dist/callbacks/useSuspenseQuery.js +0 -27
- package/dist/callbacks/useSuspenseQuery.js.map +0 -1
- package/dist/index.d.ts +0 -9
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/lib/composeInfiniteQueryKey.d.ts +0 -4
- package/dist/lib/composeInfiniteQueryKey.d.ts.map +0 -1
- package/dist/lib/composeInfiniteQueryKey.js +0 -4
- package/dist/lib/composeInfiniteQueryKey.js.map +0 -1
- package/dist/lib/composeMutationKey.d.ts +0 -10
- package/dist/lib/composeMutationKey.d.ts.map +0 -1
- package/dist/lib/composeMutationKey.js +0 -21
- package/dist/lib/composeMutationKey.js.map +0 -1
- package/dist/lib/composeQueryKey.d.ts +0 -4
- package/dist/lib/composeQueryKey.d.ts.map +0 -1
- package/dist/lib/composeQueryKey.js +0 -4
- package/dist/lib/composeQueryKey.js.map +0 -1
- package/dist/lib/createRecursiveProxy.d.ts +0 -9
- package/dist/lib/createRecursiveProxy.d.ts.map +0 -1
- package/dist/lib/createRecursiveProxy.js +0 -29
- package/dist/lib/createRecursiveProxy.js.map +0 -1
- package/dist/lib/request.d.ts +0 -32
- package/dist/lib/request.d.ts.map +0 -1
- package/dist/lib/request.js +0 -179
- package/dist/lib/request.js.map +0 -1
- package/dist/lib/shelfMerge.d.ts +0 -7
- package/dist/lib/shelfMerge.d.ts.map +0 -1
- package/dist/lib/shelfMerge.js +0 -28
- package/dist/lib/shelfMerge.js.map +0 -1
- package/dist/qraftAPIClient.d.ts +0 -36
- package/dist/qraftAPIClient.d.ts.map +0 -1
- package/dist/qraftAPIClient.js +0 -31
- package/dist/qraftAPIClient.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @openapi-qraft/react
|
|
2
2
|
|
|
3
|
+
## 1.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2d92043: feature: add support for `cancelQueries` method
|
|
8
|
+
|
|
9
|
+
## 1.1.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- cd51935: docs: Update docs
|
|
14
|
+
- 1674847: refactor: optimize Tanstack type imports
|
|
15
|
+
|
|
3
16
|
## 1.1.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -174,7 +174,7 @@ function App() {
|
|
|
174
174
|
With the client set up, you can now use the generated Hooks in your React Components to fetch data, execute mutations,
|
|
175
175
|
and more.
|
|
176
176
|
|
|
177
|
-
### [useQuery 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery)
|
|
177
|
+
### [useQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useQuery)
|
|
178
178
|
|
|
179
179
|
```ts
|
|
180
180
|
/**
|
|
@@ -193,7 +193,7 @@ const { data, error, isPending } = qraft.entities.getEntities.useQuery({
|
|
|
193
193
|
});
|
|
194
194
|
```
|
|
195
195
|
|
|
196
|
-
### [useMutation 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation)
|
|
196
|
+
### [useMutation(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useMutation)
|
|
197
197
|
|
|
198
198
|
#### With predefined parameters
|
|
199
199
|
|
|
@@ -253,7 +253,7 @@ mutation.mutate({
|
|
|
253
253
|
});
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
### [useMutationState 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useMutationState)
|
|
256
|
+
### [useMutationState(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useMutationState)
|
|
257
257
|
|
|
258
258
|
Mutation state is a helper hook that provides the current state of a mutation globally.
|
|
259
259
|
It could be used to track the status of a mutation in any component, which is useful for showing loading spinners or
|
|
@@ -281,7 +281,7 @@ useEffect(() => {
|
|
|
281
281
|
}, [mutate, mutationState?.status]);
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
### [useInfiniteQuery 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useInfiniteQuery)
|
|
284
|
+
### [useInfiniteQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useInfiniteQuery)
|
|
285
285
|
|
|
286
286
|
#### _Offset-based_
|
|
287
287
|
|
|
@@ -358,7 +358,7 @@ infiniteQuery.fetchNextPage();
|
|
|
358
358
|
infiniteQuery.fetchPreviousPage();
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
### [useQueries 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useQueries)
|
|
361
|
+
### [useQueries(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useQueries)
|
|
362
362
|
|
|
363
363
|
```ts
|
|
364
364
|
/**
|
|
@@ -397,13 +397,122 @@ qraft.entities.getEntities.useQueries({
|
|
|
397
397
|
});
|
|
398
398
|
```
|
|
399
399
|
|
|
400
|
+
### [invalidateQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientinvalidatequeries)
|
|
401
|
+
|
|
402
|
+
[Queries Invalidation 🔗](https://tanstack.com/query/latest/docs/framework/react/guides/query-invalidation) is possible
|
|
403
|
+
using `<operation>.invalidateQueries(..)` method.
|
|
404
|
+
This method is a wrapper around the `queryClient.invalidateQueries(..)`.
|
|
405
|
+
|
|
406
|
+
##### Invalidation with _parameters_:
|
|
407
|
+
|
|
408
|
+
To invalidate queries, with the specified parameters, you can use the `invalidateQueries` method:
|
|
409
|
+
|
|
410
|
+
```ts
|
|
411
|
+
/**
|
|
412
|
+
* Will invalidate the queries with the specified parameters:
|
|
413
|
+
* ###
|
|
414
|
+
* GET /entities/3e3e-3e3e-3e3e
|
|
415
|
+
* x-monite-version: 2023-09-01
|
|
416
|
+
**/
|
|
417
|
+
qraft.entities.getEntities.invalidateQueries(
|
|
418
|
+
{
|
|
419
|
+
parameters: {
|
|
420
|
+
header: {
|
|
421
|
+
'x-monite-version': '2023-09-01',
|
|
422
|
+
},
|
|
423
|
+
path: {
|
|
424
|
+
entity_id: '3e3e-3e3e-3e3e',
|
|
425
|
+
},
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
queryClient
|
|
429
|
+
);
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
##### Invalidation without _parameters_:
|
|
433
|
+
|
|
434
|
+
To invalidate all queries for a specific endpoint, you can call `invalidateQueries` without any parameters:
|
|
435
|
+
|
|
436
|
+
```ts
|
|
437
|
+
/**
|
|
438
|
+
* Will invalidate the queries matching the specified endpoint:
|
|
439
|
+
* ###
|
|
440
|
+
* GET /entities/3e3e-3e3e-3e3e
|
|
441
|
+
* x-monite-version: 2023-09-01
|
|
442
|
+
* ###
|
|
443
|
+
* GET /entities/4c4c-4c4c-4c4c
|
|
444
|
+
* x-monite-version: 2023-09-01
|
|
445
|
+
**/
|
|
446
|
+
qraft.entities.getEntities.invalidateQueries(queryClient);
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
##### Invalidation with _queryKey_:
|
|
450
|
+
|
|
451
|
+
It could be useful to invalidate queries using `queryKey` directly:
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
/**
|
|
455
|
+
* Will invalidate the queries matching the specified endpoint:
|
|
456
|
+
* ###
|
|
457
|
+
* GET /entities/3e3e-3e3e-3e3e
|
|
458
|
+
* x-monite-version: 2023-09-01
|
|
459
|
+
**/
|
|
460
|
+
qraft.entities.getEntities.invalidateQueries(
|
|
461
|
+
{
|
|
462
|
+
// `queryKey` is fully typed to `qraft.entities.getEntities`
|
|
463
|
+
queryKey: qraft.entities.getEntities.getQueryKey({
|
|
464
|
+
header: {
|
|
465
|
+
'x-monite-version': '2023-09-01',
|
|
466
|
+
},
|
|
467
|
+
path: {
|
|
468
|
+
entity_id: '3e3e-3e3e-3e3e',
|
|
469
|
+
},
|
|
470
|
+
}),
|
|
471
|
+
},
|
|
472
|
+
queryClient
|
|
473
|
+
);
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
##### [Invalidation with _predicate_: 🔗](https://tanstack.com/query/latest/docs/framework/react/guides/filters#query-filters)
|
|
477
|
+
|
|
478
|
+
The `predicate(..)` function will be used as a final filter on all matching queries.
|
|
479
|
+
|
|
480
|
+
```ts
|
|
481
|
+
/**
|
|
482
|
+
* Will invalidate the queries matching the specified endpoint and predicate:
|
|
483
|
+
* ###
|
|
484
|
+
* GET /entities/3e3e-3e3e-3e3e
|
|
485
|
+
* x-monite-version: 2023-09-01
|
|
486
|
+
**/
|
|
487
|
+
qraft.entities.getEntities.invalidateQueries(
|
|
488
|
+
{
|
|
489
|
+
parameters, // * optional, or specific parameters, alternatively, you can use `queryKey`
|
|
490
|
+
predicate: (query) => {
|
|
491
|
+
// `infinite`⬇︎ property will preset for Infinite Queries
|
|
492
|
+
if ('infinite' in query.queryKey[0]) return false;
|
|
493
|
+
|
|
494
|
+
// `queryKey`⬇︎ is fully typed to `qraft.entities.getEntities` operation parameters
|
|
495
|
+
if (query.queryKey[1].path.entity_id === '4c4c-4c4c-4c4c') return false;
|
|
496
|
+
|
|
497
|
+
return true;
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
queryClient
|
|
501
|
+
);
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### [cancelQueries(...) 🔗](https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientcancelqueries)
|
|
505
|
+
|
|
506
|
+
[Query Cancellation](https://tanstack.com/query/latest/docs/framework/react/guides/query-cancellation) has the
|
|
507
|
+
same interface as `invalidateQueries(..)`, but it will cancel the queries instead of invalidating them.
|
|
508
|
+
|
|
400
509
|
### Suspense Queries
|
|
401
510
|
|
|
402
511
|
Supported Suspense Queries are:
|
|
403
512
|
|
|
404
|
-
- [useSuspenseQuery 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseQuery)
|
|
405
|
-
- [useSuspenseInfiniteQuery 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseInfiniteQuery)
|
|
406
|
-
- [useSuspenseQueries 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseQueries)
|
|
513
|
+
- [useSuspenseQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseQuery)
|
|
514
|
+
- [useSuspenseInfiniteQuery(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseInfiniteQuery)
|
|
515
|
+
- [useSuspenseQueries(...) 🔗](https://tanstack.com/query/latest/docs/framework/react/reference/useSuspenseQueries)
|
|
407
516
|
|
|
408
517
|
### Documentation in Progress 🚧
|
|
409
518
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openapi-qraft/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "API client for React, providing type-safe requests and dynamic Tanstack Query React Hooks via a modular, Proxy-based architecture.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rimraf dist/ && tsc --project tsconfig.build.json",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@openapi-qraft/cli": "~1.1.
|
|
17
|
+
"@openapi-qraft/cli": "~1.1.1",
|
|
18
18
|
"@openapi-qraft/openapi-typescript": "^1.0.0",
|
|
19
19
|
"@tanstack/react-query": "^5.17.3",
|
|
20
20
|
"@testing-library/jest-dom": "^5.17.0",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@vitest/coverage-v8": "^1.1.3",
|
|
26
26
|
"jsdom": "latest",
|
|
27
27
|
"msw": "^2.0.12",
|
|
28
|
+
"prettier": "^3.1.1",
|
|
28
29
|
"query-string": "^8.1.0",
|
|
29
30
|
"react": "^18.2.0",
|
|
30
31
|
"rimraf": "^5.0.5",
|
package/src/ServiceOperation.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
|
+
CancelOptions,
|
|
2
3
|
DefaultError,
|
|
3
4
|
FetchStatus,
|
|
4
5
|
InfiniteData,
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
SetDataOptions,
|
|
15
16
|
Updater,
|
|
16
17
|
} from '@tanstack/query-core';
|
|
17
|
-
import {
|
|
18
|
+
import type {
|
|
18
19
|
DefinedInitialDataInfiniteOptions,
|
|
19
20
|
DefinedInitialDataOptions,
|
|
20
21
|
DefinedUseInfiniteQueryResult,
|
|
@@ -63,7 +64,8 @@ export interface ServiceOperationQuery<
|
|
|
63
64
|
ServiceOperationGetInfiniteQueryData<TSchema, TData, TParams>,
|
|
64
65
|
ServiceOperationSetQueryData<TSchema, TData, TParams>,
|
|
65
66
|
ServiceOperationSetInfiniteQueryData<TSchema, TData, TParams>,
|
|
66
|
-
ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError
|
|
67
|
+
ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError>,
|
|
68
|
+
ServiceOperationCancelQueries<TSchema, TData, TParams, TError> {
|
|
67
69
|
schema: TSchema;
|
|
68
70
|
types: {
|
|
69
71
|
parameters: TParams;
|
|
@@ -144,7 +146,7 @@ interface ServiceOperationUseQueries<
|
|
|
144
146
|
|
|
145
147
|
type QueryTypeFilter = 'all' | 'active' | 'inactive';
|
|
146
148
|
|
|
147
|
-
interface
|
|
149
|
+
interface QueryFiltersBase<
|
|
148
150
|
TSchema extends { url: string; method: string },
|
|
149
151
|
TData,
|
|
150
152
|
TParams = {},
|
|
@@ -178,34 +180,44 @@ interface InvalidateQueryFiltersBase<
|
|
|
178
180
|
* Include queries matching their fetchStatus
|
|
179
181
|
*/
|
|
180
182
|
fetchStatus?: FetchStatus;
|
|
181
|
-
|
|
182
|
-
refetchType?: QueryTypeFilter | 'none';
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
interface
|
|
185
|
+
interface QueryFiltersByQueryKey<
|
|
186
186
|
TSchema extends { url: string; method: string },
|
|
187
187
|
TData,
|
|
188
188
|
TParams = {},
|
|
189
189
|
TError = DefaultError,
|
|
190
|
-
> extends
|
|
190
|
+
> extends QueryFiltersBase<TSchema, TData, TParams, TError> {
|
|
191
191
|
/**
|
|
192
192
|
* Include queries matching this query key
|
|
193
193
|
*/
|
|
194
194
|
queryKey?: ServiceOperationQueryKey<TSchema, TParams>;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
interface
|
|
197
|
+
interface QueryFiltersByParameters<
|
|
198
198
|
TSchema extends { url: string; method: string },
|
|
199
199
|
TData,
|
|
200
200
|
TParams = {},
|
|
201
201
|
TError = DefaultError,
|
|
202
|
-
> extends
|
|
202
|
+
> extends QueryFiltersBase<TSchema, TData, TParams, TError> {
|
|
203
203
|
/**
|
|
204
204
|
* Include queries matching parameters
|
|
205
205
|
*/
|
|
206
206
|
parameters?: TParams;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
type InvalidateQueryFilters<
|
|
210
|
+
TSchema extends { url: string; method: string },
|
|
211
|
+
TData,
|
|
212
|
+
TParams = {},
|
|
213
|
+
TError = DefaultError,
|
|
214
|
+
> = (
|
|
215
|
+
| QueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
216
|
+
| QueryFiltersByQueryKey<TSchema, TData, TParams, TError>
|
|
217
|
+
) & {
|
|
218
|
+
refetchType?: QueryTypeFilter | 'none';
|
|
219
|
+
};
|
|
220
|
+
|
|
209
221
|
interface ServiceOperationInvalidateQueries<
|
|
210
222
|
TSchema extends { url: string; method: string },
|
|
211
223
|
TData,
|
|
@@ -213,21 +225,20 @@ interface ServiceOperationInvalidateQueries<
|
|
|
213
225
|
TError = DefaultError,
|
|
214
226
|
> {
|
|
215
227
|
invalidateQueries(
|
|
216
|
-
filters:
|
|
217
|
-
| InvalidateQueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
218
|
-
| InvalidateQueryFiltersByQueryKey<TSchema, TData, TParams, TError>,
|
|
228
|
+
filters: InvalidateQueryFilters<TSchema, TData, TParams, TError>,
|
|
219
229
|
options: InvalidateOptions,
|
|
220
230
|
queryClient: QueryClient
|
|
221
231
|
): Promise<void>;
|
|
222
232
|
invalidateQueries(
|
|
223
|
-
filters:
|
|
224
|
-
| InvalidateQueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
225
|
-
| InvalidateQueryFiltersByQueryKey<TSchema, TData, TParams, TError>,
|
|
233
|
+
filters: InvalidateQueryFilters<TSchema, TData, TParams, TError>,
|
|
226
234
|
queryClient: QueryClient
|
|
227
235
|
): Promise<void>;
|
|
228
236
|
invalidateQueries(queryClient: QueryClient): Promise<void>;
|
|
229
237
|
}
|
|
230
238
|
|
|
239
|
+
/**
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
231
242
|
export interface ServiceOperationInvalidateQueriesCallback<
|
|
232
243
|
TSchema extends { url: string; method: string },
|
|
233
244
|
TData,
|
|
@@ -236,14 +247,55 @@ export interface ServiceOperationInvalidateQueriesCallback<
|
|
|
236
247
|
> extends ServiceOperationInvalidateQueries<TSchema, TData, TParams, TError> {
|
|
237
248
|
invalidateQueries(
|
|
238
249
|
filters:
|
|
239
|
-
|
|
|
240
|
-
|
|
|
250
|
+
| QueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
251
|
+
| QueryFiltersByQueryKey<TSchema, TData, TParams, TError>
|
|
241
252
|
| QueryClient,
|
|
242
253
|
options?: InvalidateOptions | QueryClient,
|
|
243
254
|
queryClient?: QueryClient
|
|
244
255
|
): Promise<void>;
|
|
245
256
|
}
|
|
246
257
|
|
|
258
|
+
interface ServiceOperationCancelQueries<
|
|
259
|
+
TSchema extends { url: string; method: string },
|
|
260
|
+
TData,
|
|
261
|
+
TParams = {},
|
|
262
|
+
TError = DefaultError,
|
|
263
|
+
> {
|
|
264
|
+
cancelQueries(
|
|
265
|
+
filters:
|
|
266
|
+
| QueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
267
|
+
| QueryFiltersByQueryKey<TSchema, TData, TParams, TError>,
|
|
268
|
+
options: CancelOptions,
|
|
269
|
+
queryClient: QueryClient
|
|
270
|
+
): Promise<void>;
|
|
271
|
+
cancelQueries(
|
|
272
|
+
filters:
|
|
273
|
+
| QueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
274
|
+
| QueryFiltersByQueryKey<TSchema, TData, TParams, TError>,
|
|
275
|
+
queryClient: QueryClient
|
|
276
|
+
): Promise<void>;
|
|
277
|
+
cancelQueries(queryClient: QueryClient): Promise<void>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @internal
|
|
282
|
+
*/
|
|
283
|
+
export interface ServiceOperationCancelQueriesCallback<
|
|
284
|
+
TSchema extends { url: string; method: string },
|
|
285
|
+
TData,
|
|
286
|
+
TParams = {},
|
|
287
|
+
TError = DefaultError,
|
|
288
|
+
> extends ServiceOperationCancelQueries<TSchema, TData, TParams, TError> {
|
|
289
|
+
cancelQueries(
|
|
290
|
+
filters:
|
|
291
|
+
| QueryFiltersByParameters<TSchema, TData, TParams, TError>
|
|
292
|
+
| QueryFiltersByQueryKey<TSchema, TData, TParams, TError>
|
|
293
|
+
| QueryClient,
|
|
294
|
+
options?: CancelOptions | QueryClient,
|
|
295
|
+
queryClient?: QueryClient
|
|
296
|
+
): Promise<void>;
|
|
297
|
+
}
|
|
298
|
+
|
|
247
299
|
interface ServiceOperationUseSuspenseQueries<
|
|
248
300
|
TSchema extends { url: string; method: string },
|
|
249
301
|
TData,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { callQueryClientMethodWithQueryFilters } from '../lib/callQueryClientMethodWithQueryFilters.js';
|
|
2
|
+
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
3
|
+
import type { RequestClientSchema } from '../RequestClient.js';
|
|
4
|
+
import { ServiceOperationCancelQueriesCallback } from '../ServiceOperation.js';
|
|
5
|
+
|
|
6
|
+
export function cancelQueries<TData>(
|
|
7
|
+
qraftOptions: QraftClientOptions | undefined,
|
|
8
|
+
schema: RequestClientSchema,
|
|
9
|
+
args: Parameters<
|
|
10
|
+
ServiceOperationCancelQueriesCallback<
|
|
11
|
+
RequestClientSchema,
|
|
12
|
+
unknown,
|
|
13
|
+
TData
|
|
14
|
+
>['cancelQueries']
|
|
15
|
+
>
|
|
16
|
+
): Promise<void> {
|
|
17
|
+
return callQueryClientMethodWithQueryFilters(
|
|
18
|
+
'cancelQueries',
|
|
19
|
+
schema,
|
|
20
|
+
args as never
|
|
21
|
+
) as never;
|
|
22
|
+
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
3
|
-
|
|
4
|
-
import { composeQueryKey } from '../lib/composeQueryKey.js';
|
|
1
|
+
import { callQueryClientMethodWithQueryFilters } from '../lib/callQueryClientMethodWithQueryFilters.js';
|
|
5
2
|
import type { QraftClientOptions } from '../qraftAPIClient.js';
|
|
6
3
|
import type { RequestClientSchema } from '../RequestClient.js';
|
|
7
|
-
import { ServiceOperationInvalidateQueriesCallback } from '../ServiceOperation.js';
|
|
4
|
+
import type { ServiceOperationInvalidateQueriesCallback } from '../ServiceOperation.js';
|
|
8
5
|
|
|
9
6
|
export function invalidateQueries<TData>(
|
|
10
7
|
qraftOptions: QraftClientOptions | undefined,
|
|
@@ -17,54 +14,9 @@ export function invalidateQueries<TData>(
|
|
|
17
14
|
>['invalidateQueries']
|
|
18
15
|
>
|
|
19
16
|
): Promise<void> {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
);
|
|
17
|
+
return callQueryClientMethodWithQueryFilters(
|
|
18
|
+
'invalidateQueries',
|
|
19
|
+
schema,
|
|
20
|
+
args as never
|
|
21
|
+
) as never;
|
|
70
22
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { QueryClient } from '@tanstack/query-core';
|
|
2
|
+
|
|
3
|
+
import type { RequestClientSchema } from '../RequestClient.js';
|
|
4
|
+
import { composeQueryKey } from './composeQueryKey.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Calls a query client method with query filters and options,
|
|
8
|
+
* and automatically composes the `QueryKey` based on the schema and parameters.
|
|
9
|
+
*/
|
|
10
|
+
export function callQueryClientMethodWithQueryFilters<
|
|
11
|
+
QFMethod extends QueryFilterMethods,
|
|
12
|
+
>(
|
|
13
|
+
queryFilterMethod: QFMethod,
|
|
14
|
+
schema: RequestClientSchema,
|
|
15
|
+
args: [QueryClient, ...Parameters<(typeof QueryClient.prototype)[QFMethod]>]
|
|
16
|
+
): ReturnType<(typeof QueryClient.prototype)[QFMethod]> {
|
|
17
|
+
const queryClient = (
|
|
18
|
+
args.length === 1
|
|
19
|
+
? args[0]
|
|
20
|
+
: args.length === 2
|
|
21
|
+
? args[1]
|
|
22
|
+
: args.length === 3
|
|
23
|
+
? args[2]
|
|
24
|
+
: undefined
|
|
25
|
+
) as QueryClient | undefined;
|
|
26
|
+
|
|
27
|
+
const filters = args.length === 1 ? undefined : args[0];
|
|
28
|
+
const options = args.length === 3 ? args[1] : undefined;
|
|
29
|
+
|
|
30
|
+
if (!queryClient) throw new Error('queryClient is required');
|
|
31
|
+
if (!queryClient[queryFilterMethod])
|
|
32
|
+
throw new Error(
|
|
33
|
+
`queryClient is invalid, ${queryFilterMethod} method does not exist`
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (!filters) {
|
|
37
|
+
return queryClient[queryFilterMethod](
|
|
38
|
+
{
|
|
39
|
+
queryKey: composeQueryKey(schema, undefined),
|
|
40
|
+
},
|
|
41
|
+
options as never
|
|
42
|
+
) as never;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ('queryKey' in filters) {
|
|
46
|
+
return queryClient[queryFilterMethod](
|
|
47
|
+
filters as never,
|
|
48
|
+
options as never
|
|
49
|
+
) as never;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if ('parameters' in filters) {
|
|
53
|
+
const { parameters, ...filtersRest } = filters;
|
|
54
|
+
|
|
55
|
+
return queryClient[queryFilterMethod](
|
|
56
|
+
{
|
|
57
|
+
...filtersRest,
|
|
58
|
+
queryKey: composeQueryKey(schema, parameters),
|
|
59
|
+
} as never,
|
|
60
|
+
options as never
|
|
61
|
+
) as never;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return queryClient[queryFilterMethod](
|
|
65
|
+
{
|
|
66
|
+
...filters,
|
|
67
|
+
queryKey: composeQueryKey(schema, undefined),
|
|
68
|
+
} as never,
|
|
69
|
+
options as never
|
|
70
|
+
) as never;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
type QueryFiltersMethod<QFMethod extends keyof typeof QueryClient.prototype> =
|
|
74
|
+
QFMethod;
|
|
75
|
+
|
|
76
|
+
type QueryFilterMethods =
|
|
77
|
+
| QueryFiltersMethod<'isFetching'>
|
|
78
|
+
| QueryFiltersMethod<'getQueriesData'>
|
|
79
|
+
| QueryFiltersMethod<'setQueriesData'>
|
|
80
|
+
| QueryFiltersMethod<'removeQueries'>
|
|
81
|
+
| QueryFiltersMethod<'resetQueries'>
|
|
82
|
+
| QueryFiltersMethod<'cancelQueries'>
|
|
83
|
+
| QueryFiltersMethod<'invalidateQueries'>
|
|
84
|
+
| QueryFiltersMethod<'refetchQueries'>;
|
package/dist/QraftContext.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { QueryClient } from '@tanstack/react-query';
|
|
3
|
-
import type { RequestClient } from './RequestClient.js';
|
|
4
|
-
export type QraftContextValue = {
|
|
5
|
-
/** The request client to use for making requests. Will be invoked with every request. */
|
|
6
|
-
requestClient: RequestClient;
|
|
7
|
-
/** The QueryClient to use in Hooks */
|
|
8
|
-
queryClient?: QueryClient;
|
|
9
|
-
} | undefined;
|
|
10
|
-
export declare const QraftContext: import("react").Context<QraftContextValue>;
|
|
11
|
-
//# sourceMappingURL=QraftContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QraftContext.d.ts","sourceRoot":"","sources":["../src/QraftContext.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,MAAM,iBAAiB,GACzB;IACE,yFAAyF;IACzF,aAAa,EAAE,aAAa,CAAC;IAC7B,sCAAsC;IACtC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B,GACD,SAAS,CAAC;AAEd,eAAO,MAAM,YAAY,4CAA8C,CAAC"}
|
package/dist/QraftContext.js
DELETED
package/dist/QraftContext.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QraftContext.js","sourceRoot":"","sources":["../src/QraftContext.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAetC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAoB,SAAS,CAAC,CAAC"}
|
package/dist/RequestClient.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type RequestClient = <T>(schema: RequestClientSchema, options: RequestClientOptions) => Promise<T>;
|
|
2
|
-
export type RequestClientSchema = {
|
|
3
|
-
url: string;
|
|
4
|
-
method: 'get' | 'put' | 'post' | 'patch' | 'delete' | 'options' | 'head' | 'trace';
|
|
5
|
-
mediaType?: string;
|
|
6
|
-
};
|
|
7
|
-
export type RequestClientOptions = {
|
|
8
|
-
body?: BodyInit | Record<string, unknown> | null;
|
|
9
|
-
parameters?: RequestClientParams;
|
|
10
|
-
signal?: AbortSignal;
|
|
11
|
-
meta?: Record<string, unknown>;
|
|
12
|
-
};
|
|
13
|
-
export type RequestClientParams = {
|
|
14
|
-
header?: Record<string, any>;
|
|
15
|
-
path?: Record<string, any>;
|
|
16
|
-
query?: Record<string, any>;
|
|
17
|
-
cookie?: Record<string, any>;
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=RequestClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RequestClient.d.ts","sourceRoot":"","sources":["../src/RequestClient.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,EAC5B,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,oBAAoB,KAC1B,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EACF,KAAK,GACL,KAAK,GACL,MAAM,GACN,OAAO,GACP,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACjD,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC"}
|
package/dist/RequestClient.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RequestClient.js","sourceRoot":"","sources":["../src/RequestClient.ts"],"names":[],"mappings":""}
|