@tanstack/solid-query 5.0.0-alpha.1 → 5.0.0-alpha.15
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/build/cjs/index.js +32 -28
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +32 -28
- package/build/esm/index.js.map +1 -1
- package/build/source/__tests__/QueryClientProvider.test.jsx +2 -1
- package/build/source/__tests__/createInfiniteQuery.test.jsx +11 -10
- package/build/source/__tests__/createMutation.test.jsx +19 -18
- package/build/source/__tests__/createQueries.test.jsx +2 -18
- package/build/source/__tests__/createQuery.test.jsx +26 -25
- package/build/source/__tests__/suspense.test.jsx +6 -5
- package/build/source/__tests__/useIsFetching.test.jsx +2 -4
- package/build/source/__tests__/useIsMutating.test.jsx +25 -28
- package/build/source/__tests__/utils.jsx +3 -2
- package/build/source/createBaseQuery.js +20 -12
- package/build/source/createQueries.js +5 -5
- package/build/source/useIsFetching.js +5 -5
- package/build/source/useIsMutating.js +5 -5
- package/build/types/__tests__/utils.d.ts +2 -3
- package/build/types/createBaseQuery.d.ts +1 -1
- package/build/types/createInfiniteQuery.d.ts +3 -2
- package/build/types/createMutation.d.ts +3 -2
- package/build/types/createQueries.d.ts +6 -6
- package/build/types/createQuery.d.ts +5 -5
- package/build/types/types.d.ts +17 -17
- package/build/types/useIsFetching.d.ts +1 -6
- package/build/types/useIsMutating.d.ts +1 -6
- package/build/umd/index.js +1 -1
- package/build/umd/index.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/QueryClientProvider.test.tsx +2 -1
- package/src/__tests__/createInfiniteQuery.test.tsx +20 -18
- package/src/__tests__/createMutation.test.tsx +19 -18
- package/src/__tests__/createQueries.test.tsx +2 -24
- package/src/__tests__/createQuery.test.tsx +27 -25
- package/src/__tests__/suspense.test.tsx +6 -5
- package/src/__tests__/useIsFetching.test.tsx +2 -4
- package/src/__tests__/useIsMutating.test.tsx +32 -40
- package/src/__tests__/utils.tsx +3 -2
- package/src/createBaseQuery.ts +28 -14
- package/src/createInfiniteQuery.ts +4 -3
- package/src/createMutation.ts +4 -3
- package/src/createQueries.ts +11 -10
- package/src/createQuery.ts +8 -11
- package/src/types.ts +17 -17
- package/src/useIsFetching.ts +8 -12
- package/src/useIsMutating.ts +8 -10
package/src/createMutation.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QueryClient,
|
|
1
|
+
import type { QueryClient, DefaultError } from '@tanstack/query-core'
|
|
2
2
|
import { MutationObserver } from '@tanstack/query-core'
|
|
3
3
|
import { useQueryClient } from './QueryClientProvider'
|
|
4
4
|
import type {
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
CreateMutationOptions,
|
|
7
7
|
CreateMutationResult,
|
|
8
8
|
} from './types'
|
|
9
|
+
import type { Accessor } from 'solid-js'
|
|
9
10
|
import { createComputed, onCleanup, on } from 'solid-js'
|
|
10
11
|
import { createStore } from 'solid-js/store'
|
|
11
12
|
import { shouldThrowError } from './utils'
|
|
@@ -13,12 +14,12 @@ import { shouldThrowError } from './utils'
|
|
|
13
14
|
// HOOK
|
|
14
15
|
export function createMutation<
|
|
15
16
|
TData = unknown,
|
|
16
|
-
TError =
|
|
17
|
+
TError = DefaultError,
|
|
17
18
|
TVariables = void,
|
|
18
19
|
TContext = unknown,
|
|
19
20
|
>(
|
|
20
21
|
options: CreateMutationOptions<TData, TError, TVariables, TContext>,
|
|
21
|
-
queryClient?:
|
|
22
|
+
queryClient?: Accessor<QueryClient>,
|
|
22
23
|
): CreateMutationResult<TData, TError, TVariables, TContext> {
|
|
23
24
|
const client = useQueryClient(queryClient?.())
|
|
24
25
|
|
package/src/createQueries.ts
CHANGED
|
@@ -3,9 +3,10 @@ import type {
|
|
|
3
3
|
QueryClient,
|
|
4
4
|
QueryFunction,
|
|
5
5
|
QueryKey,
|
|
6
|
-
|
|
6
|
+
DefaultError,
|
|
7
7
|
} from '@tanstack/query-core'
|
|
8
8
|
import { notifyManager, QueriesObserver } from '@tanstack/query-core'
|
|
9
|
+
import type { Accessor } from 'solid-js'
|
|
9
10
|
import { createComputed, onCleanup, onMount } from 'solid-js'
|
|
10
11
|
import { createStore, unwrap } from 'solid-js/store'
|
|
11
12
|
import { useQueryClient } from './QueryClientProvider'
|
|
@@ -15,7 +16,7 @@ import type { CreateQueryResult, SolidQueryOptions } from './types'
|
|
|
15
16
|
// `placeholderData` function does not have a parameter
|
|
16
17
|
type CreateQueryOptionsForCreateQueries<
|
|
17
18
|
TQueryFnData = unknown,
|
|
18
|
-
TError =
|
|
19
|
+
TError = DefaultError,
|
|
19
20
|
TData = TQueryFnData,
|
|
20
21
|
TQueryKey extends QueryKey = QueryKey,
|
|
21
22
|
> = Omit<
|
|
@@ -142,26 +143,26 @@ export type QueriesResults<
|
|
|
142
143
|
? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results
|
|
143
144
|
CreateQueryResult<
|
|
144
145
|
unknown extends TData ? TQueryFnData : TData,
|
|
145
|
-
unknown extends TError ?
|
|
146
|
+
unknown extends TError ? DefaultError : TError
|
|
146
147
|
>[]
|
|
147
148
|
: // Fallback
|
|
148
149
|
CreateQueryResult[]
|
|
149
150
|
|
|
150
151
|
export function createQueries<T extends any[]>(
|
|
151
|
-
queriesOptions:
|
|
152
|
+
queriesOptions: Accessor<{
|
|
152
153
|
queries: readonly [...QueriesOptions<T>]
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
}>,
|
|
155
|
+
queryClient?: Accessor<QueryClient>,
|
|
155
156
|
): QueriesResults<T> {
|
|
156
|
-
const
|
|
157
|
+
const client = useQueryClient(queryClient?.())
|
|
157
158
|
|
|
158
159
|
const defaultedQueries = queriesOptions().queries.map((options) => {
|
|
159
|
-
const defaultedOptions =
|
|
160
|
+
const defaultedOptions = client.defaultQueryOptions(options)
|
|
160
161
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
161
162
|
return defaultedOptions
|
|
162
163
|
})
|
|
163
164
|
|
|
164
|
-
const observer = new QueriesObserver(
|
|
165
|
+
const observer = new QueriesObserver(client, defaultedQueries)
|
|
165
166
|
|
|
166
167
|
const [state, setState] = createStore(
|
|
167
168
|
observer.getOptimisticResult(defaultedQueries),
|
|
@@ -181,7 +182,7 @@ export function createQueries<T extends any[]>(
|
|
|
181
182
|
|
|
182
183
|
createComputed(() => {
|
|
183
184
|
const updatedQueries = queriesOptions().queries.map((options) => {
|
|
184
|
-
const defaultedOptions =
|
|
185
|
+
const defaultedOptions = client.defaultQueryOptions(options)
|
|
185
186
|
defaultedOptions._optimisticResults = 'optimistic'
|
|
186
187
|
return defaultedOptions
|
|
187
188
|
})
|
package/src/createQuery.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
QueryClient,
|
|
3
|
-
QueryKey,
|
|
4
|
-
RegisteredError,
|
|
5
|
-
} from '@tanstack/query-core'
|
|
1
|
+
import type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'
|
|
6
2
|
import { QueryObserver } from '@tanstack/query-core'
|
|
3
|
+
import type { Accessor } from 'solid-js'
|
|
7
4
|
import { createMemo } from 'solid-js'
|
|
8
5
|
import { createBaseQuery } from './createBaseQuery'
|
|
9
6
|
import type {
|
|
@@ -16,7 +13,7 @@ import type {
|
|
|
16
13
|
|
|
17
14
|
type UndefinedInitialDataOptions<
|
|
18
15
|
TQueryFnData = unknown,
|
|
19
|
-
TError =
|
|
16
|
+
TError = DefaultError,
|
|
20
17
|
TData = TQueryFnData,
|
|
21
18
|
TQueryKey extends QueryKey = QueryKey,
|
|
22
19
|
> = FunctionedParams<
|
|
@@ -27,7 +24,7 @@ type UndefinedInitialDataOptions<
|
|
|
27
24
|
|
|
28
25
|
type DefinedInitialDataOptions<
|
|
29
26
|
TQueryFnData = unknown,
|
|
30
|
-
TError =
|
|
27
|
+
TError = DefaultError,
|
|
31
28
|
TData = TQueryFnData,
|
|
32
29
|
TQueryKey extends QueryKey = QueryKey,
|
|
33
30
|
> = FunctionedParams<
|
|
@@ -38,7 +35,7 @@ type DefinedInitialDataOptions<
|
|
|
38
35
|
|
|
39
36
|
export function createQuery<
|
|
40
37
|
TQueryFnData = unknown,
|
|
41
|
-
TError =
|
|
38
|
+
TError = DefaultError,
|
|
42
39
|
TData = TQueryFnData,
|
|
43
40
|
TQueryKey extends QueryKey = QueryKey,
|
|
44
41
|
>(
|
|
@@ -48,7 +45,7 @@ export function createQuery<
|
|
|
48
45
|
|
|
49
46
|
export function createQuery<
|
|
50
47
|
TQueryFnData = unknown,
|
|
51
|
-
TError =
|
|
48
|
+
TError = DefaultError,
|
|
52
49
|
TData = TQueryFnData,
|
|
53
50
|
TQueryKey extends QueryKey = QueryKey,
|
|
54
51
|
>(
|
|
@@ -57,12 +54,12 @@ export function createQuery<
|
|
|
57
54
|
): DefinedCreateQueryResult<TData, TError>
|
|
58
55
|
export function createQuery<
|
|
59
56
|
TQueryFnData,
|
|
60
|
-
TError =
|
|
57
|
+
TError = DefaultError,
|
|
61
58
|
TData = TQueryFnData,
|
|
62
59
|
TQueryKey extends QueryKey = QueryKey,
|
|
63
60
|
>(
|
|
64
61
|
options: CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
65
|
-
queryClient?:
|
|
62
|
+
queryClient?: Accessor<QueryClient>,
|
|
66
63
|
) {
|
|
67
64
|
return createBaseQuery(
|
|
68
65
|
createMemo(() => options()),
|
package/src/types.ts
CHANGED
|
@@ -11,14 +11,14 @@ import type {
|
|
|
11
11
|
InfiniteQueryObserverOptions,
|
|
12
12
|
InfiniteQueryObserverResult,
|
|
13
13
|
WithRequired,
|
|
14
|
-
|
|
14
|
+
DefaultError,
|
|
15
15
|
} from '@tanstack/query-core'
|
|
16
16
|
|
|
17
17
|
export type FunctionedParams<T> = () => T
|
|
18
18
|
|
|
19
19
|
export interface CreateBaseQueryOptions<
|
|
20
20
|
TQueryFnData = unknown,
|
|
21
|
-
TError =
|
|
21
|
+
TError = DefaultError,
|
|
22
22
|
TData = TQueryFnData,
|
|
23
23
|
TQueryData = TQueryFnData,
|
|
24
24
|
TQueryKey extends QueryKey = QueryKey,
|
|
@@ -31,7 +31,7 @@ export interface CreateBaseQueryOptions<
|
|
|
31
31
|
|
|
32
32
|
export interface SolidQueryOptions<
|
|
33
33
|
TQueryFnData = unknown,
|
|
34
|
-
TError =
|
|
34
|
+
TError = DefaultError,
|
|
35
35
|
TData = TQueryFnData,
|
|
36
36
|
TQueryKey extends QueryKey = QueryKey,
|
|
37
37
|
> extends WithRequired<
|
|
@@ -47,7 +47,7 @@ export interface SolidQueryOptions<
|
|
|
47
47
|
|
|
48
48
|
export type CreateQueryOptions<
|
|
49
49
|
TQueryFnData = unknown,
|
|
50
|
-
TError =
|
|
50
|
+
TError = DefaultError,
|
|
51
51
|
TData = TQueryFnData,
|
|
52
52
|
TQueryKey extends QueryKey = QueryKey,
|
|
53
53
|
> = FunctionedParams<SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey>>
|
|
@@ -56,28 +56,28 @@ export type CreateQueryOptions<
|
|
|
56
56
|
|
|
57
57
|
export type CreateBaseQueryResult<
|
|
58
58
|
TData = unknown,
|
|
59
|
-
TError =
|
|
59
|
+
TError = DefaultError,
|
|
60
60
|
> = QueryObserverResult<TData, TError>
|
|
61
61
|
|
|
62
62
|
export type CreateQueryResult<
|
|
63
63
|
TData = unknown,
|
|
64
|
-
TError =
|
|
64
|
+
TError = DefaultError,
|
|
65
65
|
> = CreateBaseQueryResult<TData, TError>
|
|
66
66
|
|
|
67
67
|
export type DefinedCreateBaseQueryResult<
|
|
68
68
|
TData = unknown,
|
|
69
|
-
TError =
|
|
69
|
+
TError = DefaultError,
|
|
70
70
|
> = DefinedQueryObserverResult<TData, TError>
|
|
71
71
|
|
|
72
72
|
export type DefinedCreateQueryResult<
|
|
73
73
|
TData = unknown,
|
|
74
|
-
TError =
|
|
74
|
+
TError = DefaultError,
|
|
75
75
|
> = DefinedCreateBaseQueryResult<TData, TError>
|
|
76
76
|
|
|
77
77
|
/* --- Create Infinite Queries Types --- */
|
|
78
78
|
export interface SolidInfiniteQueryOptions<
|
|
79
79
|
TQueryFnData = unknown,
|
|
80
|
-
TError =
|
|
80
|
+
TError = DefaultError,
|
|
81
81
|
TData = TQueryFnData,
|
|
82
82
|
TQueryData = TQueryFnData,
|
|
83
83
|
TQueryKey extends QueryKey = QueryKey,
|
|
@@ -99,7 +99,7 @@ export interface SolidInfiniteQueryOptions<
|
|
|
99
99
|
|
|
100
100
|
export type CreateInfiniteQueryOptions<
|
|
101
101
|
TQueryFnData = unknown,
|
|
102
|
-
TError =
|
|
102
|
+
TError = DefaultError,
|
|
103
103
|
TData = TQueryFnData,
|
|
104
104
|
TQueryKey extends QueryKey = QueryKey,
|
|
105
105
|
TPageParam = unknown,
|
|
@@ -116,13 +116,13 @@ export type CreateInfiniteQueryOptions<
|
|
|
116
116
|
|
|
117
117
|
export type CreateInfiniteQueryResult<
|
|
118
118
|
TData = unknown,
|
|
119
|
-
TError =
|
|
119
|
+
TError = DefaultError,
|
|
120
120
|
> = InfiniteQueryObserverResult<TData, TError>
|
|
121
121
|
|
|
122
122
|
/* --- Create Mutation Types --- */
|
|
123
123
|
export interface SolidMutationOptions<
|
|
124
124
|
TData = unknown,
|
|
125
|
-
TError =
|
|
125
|
+
TError = DefaultError,
|
|
126
126
|
TVariables = void,
|
|
127
127
|
TContext = unknown,
|
|
128
128
|
> extends Omit<
|
|
@@ -132,14 +132,14 @@ export interface SolidMutationOptions<
|
|
|
132
132
|
|
|
133
133
|
export type CreateMutationOptions<
|
|
134
134
|
TData = unknown,
|
|
135
|
-
TError =
|
|
135
|
+
TError = DefaultError,
|
|
136
136
|
TVariables = void,
|
|
137
137
|
TContext = unknown,
|
|
138
138
|
> = FunctionedParams<SolidMutationOptions<TData, TError, TVariables, TContext>>
|
|
139
139
|
|
|
140
140
|
export type CreateMutateFunction<
|
|
141
141
|
TData = unknown,
|
|
142
|
-
TError =
|
|
142
|
+
TError = DefaultError,
|
|
143
143
|
TVariables = void,
|
|
144
144
|
TContext = unknown,
|
|
145
145
|
> = (
|
|
@@ -148,14 +148,14 @@ export type CreateMutateFunction<
|
|
|
148
148
|
|
|
149
149
|
export type CreateMutateAsyncFunction<
|
|
150
150
|
TData = unknown,
|
|
151
|
-
TError =
|
|
151
|
+
TError = DefaultError,
|
|
152
152
|
TVariables = void,
|
|
153
153
|
TContext = unknown,
|
|
154
154
|
> = MutateFunction<TData, TError, TVariables, TContext>
|
|
155
155
|
|
|
156
156
|
export type CreateBaseMutationResult<
|
|
157
157
|
TData = unknown,
|
|
158
|
-
TError =
|
|
158
|
+
TError = DefaultError,
|
|
159
159
|
TVariables = unknown,
|
|
160
160
|
TContext = unknown,
|
|
161
161
|
> = Override<
|
|
@@ -167,7 +167,7 @@ export type CreateBaseMutationResult<
|
|
|
167
167
|
|
|
168
168
|
export type CreateMutationResult<
|
|
169
169
|
TData = unknown,
|
|
170
|
-
TError =
|
|
170
|
+
TError = DefaultError,
|
|
171
171
|
TVariables = unknown,
|
|
172
172
|
TContext = unknown,
|
|
173
173
|
> = CreateBaseMutationResult<TData, TError, TVariables, TContext>
|
package/src/useIsFetching.ts
CHANGED
|
@@ -3,21 +3,17 @@ import type { Accessor } from 'solid-js'
|
|
|
3
3
|
import { createMemo, createSignal, onCleanup } from 'solid-js'
|
|
4
4
|
import { useQueryClient } from './QueryClientProvider'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
filters?: QueryFilters
|
|
8
|
-
queryClient?: QueryClient
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const queryClient = createMemo(() => useQueryClient(options().queryClient))
|
|
13
|
-
const queryCache = createMemo(() => queryClient().getQueryCache())
|
|
6
|
+
export function useIsFetching(
|
|
7
|
+
filters?: Accessor<QueryFilters>,
|
|
8
|
+
queryClient?: Accessor<QueryClient>,
|
|
9
|
+
): Accessor<number> {
|
|
10
|
+
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
11
|
+
const queryCache = createMemo(() => client().getQueryCache())
|
|
14
12
|
|
|
15
|
-
const [fetches, setFetches] = createSignal(
|
|
16
|
-
queryClient().isFetching(options().filters),
|
|
17
|
-
)
|
|
13
|
+
const [fetches, setFetches] = createSignal(client().isFetching(filters?.()))
|
|
18
14
|
|
|
19
15
|
const unsubscribe = queryCache().subscribe(() => {
|
|
20
|
-
setFetches(
|
|
16
|
+
setFetches(client().isFetching(filters?.()))
|
|
21
17
|
})
|
|
22
18
|
|
|
23
19
|
onCleanup(unsubscribe)
|
package/src/useIsMutating.ts
CHANGED
|
@@ -3,21 +3,19 @@ import { useQueryClient } from './QueryClientProvider'
|
|
|
3
3
|
import type { Accessor } from 'solid-js'
|
|
4
4
|
import { createSignal, onCleanup, createMemo } from 'solid-js'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
filters?: MutationFilters
|
|
8
|
-
queryClient?: QueryClient
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const queryClient = createMemo(() => useQueryClient(options().queryClient))
|
|
13
|
-
const mutationCache = createMemo(() => queryClient().getMutationCache())
|
|
6
|
+
export function useIsMutating(
|
|
7
|
+
filters?: Accessor<MutationFilters>,
|
|
8
|
+
queryClient?: Accessor<QueryClient>,
|
|
9
|
+
): Accessor<number> {
|
|
10
|
+
const client = createMemo(() => useQueryClient(queryClient?.()))
|
|
11
|
+
const mutationCache = createMemo(() => client().getMutationCache())
|
|
14
12
|
|
|
15
13
|
const [mutations, setMutations] = createSignal(
|
|
16
|
-
|
|
14
|
+
client().isMutating(filters?.()),
|
|
17
15
|
)
|
|
18
16
|
|
|
19
17
|
const unsubscribe = mutationCache().subscribe((_result) => {
|
|
20
|
-
setMutations(
|
|
18
|
+
setMutations(client().isMutating(filters?.()))
|
|
21
19
|
})
|
|
22
20
|
|
|
23
21
|
onCleanup(unsubscribe)
|