react-query-kit 1.5.2 → 2.0.1
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/README.md +67 -54
- package/build/lib/createBaseQuery.d.ts +3 -2
- package/build/lib/createBaseQuery.esm.js +19 -26
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +16 -23
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +19 -26
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/lib/createInfiniteQuery.d.ts +1 -4
- package/build/lib/createInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createInfiniteQuery.js.map +1 -1
- package/build/lib/createInfiniteQuery.mjs.map +1 -1
- package/build/lib/createMutation.d.ts +1 -5
- package/build/lib/createMutation.esm.js.map +1 -1
- package/build/lib/createMutation.js.map +1 -1
- package/build/lib/createMutation.mjs.map +1 -1
- package/build/lib/createQuery.d.ts +1 -5
- package/build/lib/createQuery.esm.js.map +1 -1
- package/build/lib/createQuery.js.map +1 -1
- package/build/lib/createQuery.mjs.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.d.ts +1 -4
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.d.ts +1 -5
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/types.d.ts +38 -36
- package/build/lib/utils.d.ts +2 -3
- package/build/lib/utils.esm.js +12 -20
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +12 -21
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +12 -20
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +81 -81
- package/build/umd/index.development.js +30 -45
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -7
- package/src/createBaseQuery.ts +26 -41
- package/src/createInfiniteQuery.ts +1 -22
- package/src/createMutation.ts +1 -11
- package/src/createQuery.tsx +1 -20
- package/src/createSuspenseInfiniteQuery.ts +1 -30
- package/src/createSuspenseQuery.ts +2 -27
- package/src/index.ts +8 -1
- package/src/types.ts +173 -117
- package/src/utils.ts +14 -21
package/src/createBaseQuery.ts
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
QueryClient,
|
|
3
|
-
SetDataOptions,
|
|
4
|
-
Updater,
|
|
5
3
|
UseBaseQueryOptions,
|
|
4
|
+
UseInfiniteQueryOptions,
|
|
6
5
|
} from '@tanstack/react-query'
|
|
7
6
|
|
|
8
7
|
import type {
|
|
9
8
|
AdditionalCreateOptions,
|
|
10
|
-
AdditionalQueryHookOptions,
|
|
11
9
|
CompatibleWithV4,
|
|
12
10
|
Middleware,
|
|
13
11
|
} from './types'
|
|
14
|
-
import { getQueryKey,
|
|
12
|
+
import { getKey as getQueryKey, withMiddleware } from './utils'
|
|
15
13
|
|
|
16
|
-
interface
|
|
17
|
-
extends Omit<
|
|
14
|
+
interface CreateBaseQueryOptions
|
|
15
|
+
extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,
|
|
18
16
|
AdditionalCreateOptions<any, any> {
|
|
19
17
|
use?: Middleware[]
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
type QueryBaseHookOptions = Omit<
|
|
23
21
|
UseBaseQueryOptions,
|
|
24
|
-
'queryKey' | 'queryFn'
|
|
25
|
-
> &
|
|
26
|
-
|
|
22
|
+
'queryKey' | 'queryFn'
|
|
23
|
+
> & {
|
|
24
|
+
variables?: any
|
|
25
|
+
}
|
|
27
26
|
|
|
28
27
|
export function createBaseQuery(
|
|
29
28
|
defaultOptions: any,
|
|
30
29
|
useRQHook: (options: any, queryClient?: any) => any,
|
|
31
30
|
overrideOptions?: QueryBaseHookOptions
|
|
32
31
|
): any {
|
|
33
|
-
const {
|
|
34
|
-
|
|
32
|
+
const {
|
|
33
|
+
primaryKey,
|
|
34
|
+
queryFn,
|
|
35
|
+
queryKeyHashFn,
|
|
36
|
+
getPreviousPageParam,
|
|
37
|
+
getNextPageParam,
|
|
38
|
+
initialPageParam,
|
|
39
|
+
} = defaultOptions as CreateBaseQueryOptions
|
|
35
40
|
|
|
36
41
|
if (process.env.NODE_ENV !== 'production') {
|
|
37
42
|
// @ts-ignore
|
|
@@ -51,43 +56,23 @@ export function createBaseQuery(
|
|
|
51
56
|
queryKey: getKey(variables),
|
|
52
57
|
queryFn,
|
|
53
58
|
queryKeyHashFn,
|
|
54
|
-
getPreviousPageParam
|
|
55
|
-
getNextPageParam
|
|
56
|
-
initialPageParam
|
|
59
|
+
getPreviousPageParam,
|
|
60
|
+
getNextPageParam,
|
|
61
|
+
initialPageParam,
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
const useBaseHook = (
|
|
61
|
-
|
|
66
|
+
{ variables, ...rest }: QueryBaseHookOptions,
|
|
62
67
|
queryClient?: CompatibleWithV4<QueryClient, void>
|
|
63
68
|
) => {
|
|
64
|
-
|
|
65
|
-
const { enabled, variables, ...mergedOptions } = {
|
|
66
|
-
...options,
|
|
67
|
-
...overrideOptions,
|
|
68
|
-
} as QueryBaseHookOptions
|
|
69
|
-
const queryKey = getKey(variables)
|
|
70
|
-
|
|
71
|
-
return Object.assign(
|
|
72
|
-
useRQHook(
|
|
73
|
-
{
|
|
74
|
-
...mergedOptions,
|
|
75
|
-
enabled:
|
|
76
|
-
typeof enabled === 'function'
|
|
77
|
-
? enabled(client.getQueryData(queryKey), variables)
|
|
78
|
-
: enabled,
|
|
79
|
-
queryKey,
|
|
80
|
-
},
|
|
81
|
-
client
|
|
82
|
-
),
|
|
69
|
+
return useRQHook(
|
|
83
70
|
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
) => client.setQueryData(queryKey, updater, setDataOptions),
|
|
90
|
-
}
|
|
71
|
+
...rest,
|
|
72
|
+
...overrideOptions,
|
|
73
|
+
queryKey: getKey(variables),
|
|
74
|
+
},
|
|
75
|
+
queryClient
|
|
91
76
|
)
|
|
92
77
|
}
|
|
93
78
|
|
|
@@ -2,32 +2,11 @@ import { useInfiniteQuery } from '@tanstack/react-query'
|
|
|
2
2
|
|
|
3
3
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
4
|
import type {
|
|
5
|
-
|
|
6
|
-
CompatibleUseInfiniteQueryOptions,
|
|
5
|
+
CreateInfiniteQueryOptions,
|
|
7
6
|
DefaultError,
|
|
8
7
|
InfiniteQueryHook,
|
|
9
|
-
Middleware,
|
|
10
8
|
} from './types'
|
|
11
9
|
|
|
12
|
-
export interface CreateInfiniteQueryOptions<
|
|
13
|
-
TFnData = unknown,
|
|
14
|
-
TVariables = any,
|
|
15
|
-
TError = DefaultError,
|
|
16
|
-
TPageParam = number
|
|
17
|
-
> extends Omit<
|
|
18
|
-
CompatibleUseInfiniteQueryOptions<
|
|
19
|
-
TFnData,
|
|
20
|
-
TVariables,
|
|
21
|
-
TFnData,
|
|
22
|
-
TError,
|
|
23
|
-
TPageParam
|
|
24
|
-
>,
|
|
25
|
-
'queryKey' | 'queryFn' | 'enabled' | 'select'
|
|
26
|
-
>,
|
|
27
|
-
AdditionalCreateOptions<TFnData, TVariables, TPageParam> {
|
|
28
|
-
use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
10
|
export const createInfiniteQuery = <
|
|
32
11
|
TFnData,
|
|
33
12
|
TVariables = any,
|
package/src/createMutation.ts
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { useMutation } from '@tanstack/react-query'
|
|
2
|
-
import type { UseMutationOptions } from '@tanstack/react-query'
|
|
3
2
|
|
|
4
|
-
import type {
|
|
3
|
+
import type { CreateMutationOptions, DefaultError, MutationHook } from './types'
|
|
5
4
|
import { withMiddleware } from './utils'
|
|
6
5
|
|
|
7
|
-
export interface CreateMutationOptions<
|
|
8
|
-
TData = unknown,
|
|
9
|
-
TVariables = void,
|
|
10
|
-
TError = DefaultError,
|
|
11
|
-
TContext = unknown
|
|
12
|
-
> extends UseMutationOptions<TData, TError, TVariables, TContext> {
|
|
13
|
-
use?: Middleware<MutationHook<TData, TError, TVariables>>[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
6
|
export const createMutation = <
|
|
17
7
|
TData = unknown,
|
|
18
8
|
TVariables = void,
|
package/src/createQuery.tsx
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import type { UseQueryOptions } from '@tanstack/react-query'
|
|
2
1
|
import { useQuery } from '@tanstack/react-query'
|
|
3
2
|
|
|
4
3
|
import { createBaseQuery } from './createBaseQuery'
|
|
5
|
-
import type {
|
|
6
|
-
AdditionalCreateOptions,
|
|
7
|
-
DefaultError,
|
|
8
|
-
Middleware,
|
|
9
|
-
QueryHook,
|
|
10
|
-
inferQueryKey,
|
|
11
|
-
} from './types'
|
|
12
|
-
|
|
13
|
-
export interface CreateQueryOptions<
|
|
14
|
-
TFnData = unknown,
|
|
15
|
-
TVariables = any,
|
|
16
|
-
TError = DefaultError
|
|
17
|
-
> extends Omit<
|
|
18
|
-
UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
|
|
19
|
-
'queryKey' | 'queryFn' | 'enabled' | 'select'
|
|
20
|
-
>,
|
|
21
|
-
AdditionalCreateOptions<TFnData, TVariables> {
|
|
22
|
-
use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]
|
|
23
|
-
}
|
|
4
|
+
import type { CreateQueryOptions, DefaultError, QueryHook } from './types'
|
|
24
5
|
|
|
25
6
|
export const createQuery = <TFnData, TVariables = any, TError = DefaultError>(
|
|
26
7
|
options: CreateQueryOptions<TFnData, TVariables, TError>
|
|
@@ -2,40 +2,11 @@ import { useInfiniteQuery } from '@tanstack/react-query'
|
|
|
2
2
|
|
|
3
3
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
4
|
import type {
|
|
5
|
-
|
|
6
|
-
CompatibleUseInfiniteQueryOptions,
|
|
5
|
+
CreateSuspenseInfiniteQueryOptions,
|
|
7
6
|
DefaultError,
|
|
8
|
-
Middleware,
|
|
9
7
|
SuspenseInfiniteQueryHook,
|
|
10
8
|
} from './types'
|
|
11
9
|
|
|
12
|
-
export interface CreateSuspenseInfiniteQueryOptions<
|
|
13
|
-
TFnData = unknown,
|
|
14
|
-
TVariables = any,
|
|
15
|
-
TError = DefaultError,
|
|
16
|
-
TPageParam = number
|
|
17
|
-
> extends Omit<
|
|
18
|
-
CompatibleUseInfiniteQueryOptions<
|
|
19
|
-
TFnData,
|
|
20
|
-
TVariables,
|
|
21
|
-
TFnData,
|
|
22
|
-
TError,
|
|
23
|
-
TPageParam
|
|
24
|
-
>,
|
|
25
|
-
| 'queryKey'
|
|
26
|
-
| 'queryFn'
|
|
27
|
-
| 'enabled'
|
|
28
|
-
| 'select'
|
|
29
|
-
| 'suspense'
|
|
30
|
-
| 'throwOnError'
|
|
31
|
-
| 'placeholderData'
|
|
32
|
-
| 'keepPreviousData'
|
|
33
|
-
| 'useErrorBoundary'
|
|
34
|
-
>,
|
|
35
|
-
Omit<AdditionalCreateOptions<TFnData, TVariables, TPageParam>, 'enabled'> {
|
|
36
|
-
use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]
|
|
37
|
-
}
|
|
38
|
-
|
|
39
10
|
export const createSuspenseInfiniteQuery = <
|
|
40
11
|
TFnData,
|
|
41
12
|
TVariables = any,
|
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
import type { DefaultError
|
|
1
|
+
import type { DefaultError } from '@tanstack/react-query'
|
|
2
2
|
import { useQuery } from '@tanstack/react-query'
|
|
3
3
|
|
|
4
4
|
import { createBaseQuery } from './createBaseQuery'
|
|
5
|
-
import type {
|
|
6
|
-
AdditionalCreateOptions,
|
|
7
|
-
Middleware,
|
|
8
|
-
SuspenseQueryHook,
|
|
9
|
-
inferQueryKey,
|
|
10
|
-
} from './types'
|
|
11
|
-
|
|
12
|
-
export interface CreateSuspenseQueryOptions<
|
|
13
|
-
TFnData = unknown,
|
|
14
|
-
TVariables = any,
|
|
15
|
-
TError = DefaultError
|
|
16
|
-
> extends Omit<
|
|
17
|
-
UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
|
|
18
|
-
| 'queryKey'
|
|
19
|
-
| 'queryFn'
|
|
20
|
-
| 'enabled'
|
|
21
|
-
| 'select'
|
|
22
|
-
| 'suspense'
|
|
23
|
-
| 'throwOnError'
|
|
24
|
-
| 'placeholderData'
|
|
25
|
-
| 'keepPreviousData'
|
|
26
|
-
| 'useErrorBoundary'
|
|
27
|
-
>,
|
|
28
|
-
Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {
|
|
29
|
-
use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]
|
|
30
|
-
}
|
|
5
|
+
import type { CreateSuspenseQueryOptions, SuspenseQueryHook } from './types'
|
|
31
6
|
|
|
32
7
|
export const createSuspenseQuery = <
|
|
33
8
|
TFnData,
|
package/src/index.ts
CHANGED
|
@@ -3,25 +3,32 @@ export * from './createSuspenseQuery'
|
|
|
3
3
|
export * from './createInfiniteQuery'
|
|
4
4
|
export * from './createSuspenseInfiniteQuery'
|
|
5
5
|
export * from './createMutation'
|
|
6
|
-
export {
|
|
6
|
+
export { getKey } from './utils'
|
|
7
7
|
export type {
|
|
8
|
+
CreateQueryOptions,
|
|
8
9
|
QueryHookOptions,
|
|
9
10
|
QueryHook,
|
|
10
11
|
QueryHookResult,
|
|
12
|
+
CreateInfiniteQueryOptions,
|
|
11
13
|
InfiniteQueryHookOptions,
|
|
12
14
|
InfiniteQueryHook,
|
|
13
15
|
InfiniteQueryHookResult,
|
|
16
|
+
CreateSuspenseQueryOptions,
|
|
14
17
|
SuspenseQueryHook,
|
|
15
18
|
SuspenseQueryHookOptions,
|
|
16
19
|
SuspenseQueryHookResult,
|
|
20
|
+
CreateSuspenseInfiniteQueryOptions,
|
|
17
21
|
SuspenseInfiniteQueryHook,
|
|
18
22
|
SuspenseInfiniteQueryHookOptions,
|
|
19
23
|
SuspenseInfiniteQueryHookResult,
|
|
24
|
+
CreateMutationOptions,
|
|
20
25
|
MutationHookOptions,
|
|
21
26
|
MutationHook,
|
|
22
27
|
inferVariables,
|
|
23
28
|
inferData,
|
|
24
29
|
inferFnData,
|
|
25
30
|
inferOptions,
|
|
31
|
+
inferError,
|
|
32
|
+
inferCreateOptions,
|
|
26
33
|
Middleware,
|
|
27
34
|
} from './types'
|