@tanstack/solid-query 6.0.0-rc.0 → 6.0.0-rc.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/README.md +15 -1
- package/build/_tsup-dts-rollup.d.cts +203 -152
- package/build/_tsup-dts-rollup.d.ts +203 -152
- package/build/dev.cjs +755 -559
- package/build/dev.d.cts +2 -22
- package/build/dev.d.ts +2 -22
- package/build/dev.js +757 -559
- package/build/index.cjs +755 -550
- package/build/index.d.cts +2 -22
- package/build/index.d.ts +2 -22
- package/build/index.js +757 -550
- package/package.json +7 -6
- package/src/QueryClient.ts +24 -45
- package/src/QueryClientProvider.tsx +136 -58
- package/src/cacheAggregate.ts +90 -0
- package/src/dehydrateSettled.ts +42 -0
- package/src/index.ts +3 -29
- package/src/types.ts +62 -44
- package/src/useBaseQuery.ts +674 -412
- package/src/useInfiniteQuery.ts +156 -4
- package/src/useIsFetching.ts +6 -16
- package/src/useIsMutating.ts +6 -16
- package/src/useMutation.ts +317 -56
- package/src/useMutationState.ts +9 -22
- package/src/useQueries.ts +61 -110
- package/src/hydrationChannel.ts +0 -260
package/src/types.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
DefinedInfiniteQueryObserverResult,
|
|
6
6
|
DefinedQueryObserverResult,
|
|
7
7
|
InfiniteQueryObserverResult,
|
|
8
|
-
MutateFunction,
|
|
9
8
|
MutationObserverOptions,
|
|
10
9
|
MutationObserverResult,
|
|
11
10
|
OmitKeyof,
|
|
@@ -30,18 +29,22 @@ export interface UseBaseQueryOptions<
|
|
|
30
29
|
'suspense'
|
|
31
30
|
> {
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
32
|
+
* Defer the SSR stream flush until this query resolves on the server,
|
|
33
|
+
* instead of letting the surrounding `<Loading>` boundary render its
|
|
34
|
+
* fallback into the HTML. Passed through to Solid's own per-computation
|
|
35
|
+
* `deferStream` option; server-only, ignored on the client.
|
|
37
36
|
*/
|
|
38
37
|
deferStream?: boolean
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
39
|
+
* Reconciliation key for the data store. `data` is served as a Solid
|
|
40
|
+
* store projection: every landing (refetch, invalidation, placeholder
|
|
41
|
+
* upgrade) reconciles into the existing proxy graph instead of replacing
|
|
42
|
+
* it, so deep reads are fine-grained and item identity survives across
|
|
43
|
+
* fetches. This sets the identity key for that reconciliation — a
|
|
44
|
+
* property name, a key-extraction function, or `null` to merge
|
|
45
|
+
* positionally. Defaults to `'id'`. Read once at creation.
|
|
43
46
|
*/
|
|
44
|
-
|
|
47
|
+
reconcile?: string | ((item: NonNullable<any>) => any) | null
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
export interface QueryOptions<
|
|
@@ -66,20 +69,39 @@ export type UseQueryOptions<
|
|
|
66
69
|
|
|
67
70
|
/* --- Create Query and Create Base Query Types --- */
|
|
68
71
|
|
|
72
|
+
/**
|
|
73
|
+
* `data` is non-optional: it is a suspending async read. It never returns
|
|
74
|
+
* `undefined` — a read either suspends into the nearest `<Loading>`
|
|
75
|
+
* boundary (first fetch in flight, disabled, restoring), returns a value
|
|
76
|
+
* (committed, placeholder, initial), or throws (`<Errored>` /
|
|
77
|
+
* `throwOnError`). The v5 `TData | undefined` face existed because reads
|
|
78
|
+
* could observe the pre-fetch gap; here that gap is suspension.
|
|
79
|
+
*/
|
|
69
80
|
export type UseBaseQueryResult<
|
|
70
81
|
TData = unknown,
|
|
71
82
|
TError = DefaultError,
|
|
72
|
-
> =
|
|
83
|
+
> = Override<
|
|
84
|
+
OmitKeyof<QueryObserverResult<TData, TError>, 'isInitialLoading'>,
|
|
85
|
+
{ data: TData }
|
|
86
|
+
>
|
|
73
87
|
|
|
74
88
|
export type UseQueryResult<
|
|
75
89
|
TData = unknown,
|
|
76
90
|
TError = DefaultError,
|
|
77
91
|
> = UseBaseQueryResult<TData, TError>
|
|
78
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Distributes an `isInitialLoading` omit over result unions so status
|
|
95
|
+
* discriminants survive (a plain Omit over a union collapses it).
|
|
96
|
+
*/
|
|
97
|
+
type OmitIsInitialLoading<T> = T extends unknown
|
|
98
|
+
? OmitKeyof<T, 'isInitialLoading' & keyof T>
|
|
99
|
+
: never
|
|
100
|
+
|
|
79
101
|
export type DefinedUseBaseQueryResult<
|
|
80
102
|
TData = unknown,
|
|
81
103
|
TError = DefaultError,
|
|
82
|
-
> = DefinedQueryObserverResult<TData, TError
|
|
104
|
+
> = OmitIsInitialLoading<DefinedQueryObserverResult<TData, TError>>
|
|
83
105
|
|
|
84
106
|
export type DefinedUseQueryResult<
|
|
85
107
|
TData = unknown,
|
|
@@ -105,18 +127,16 @@ export interface InfiniteQueryOptions<
|
|
|
105
127
|
> {
|
|
106
128
|
queryKey: TQueryKey
|
|
107
129
|
/**
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* This can be useful to avoid sending a loading state to the client before the query has resolved.
|
|
111
|
-
* Defaults to `false`.
|
|
130
|
+
* Defer the SSR stream flush until this query resolves on the server —
|
|
131
|
+
* see {@link UseBaseQueryOptions.deferStream}.
|
|
112
132
|
*/
|
|
113
133
|
deferStream?: boolean
|
|
114
134
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
135
|
+
* Reconciliation key for the data store — see
|
|
136
|
+
* {@link UseBaseQueryOptions.reconcile}. For infinite queries this keys
|
|
137
|
+
* items within pages; pages themselves merge positionally.
|
|
118
138
|
*/
|
|
119
|
-
|
|
139
|
+
reconcile?: string | ((item: NonNullable<any>) => any) | null
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
export type UseInfiniteQueryOptions<
|
|
@@ -129,15 +149,19 @@ export type UseInfiniteQueryOptions<
|
|
|
129
149
|
InfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>
|
|
130
150
|
>
|
|
131
151
|
|
|
152
|
+
/** Non-optional `data` for the same reason as {@link UseBaseQueryResult}. */
|
|
132
153
|
export type UseInfiniteQueryResult<
|
|
133
154
|
TData = unknown,
|
|
134
155
|
TError = DefaultError,
|
|
135
|
-
> =
|
|
156
|
+
> = Override<
|
|
157
|
+
OmitKeyof<InfiniteQueryObserverResult<TData, TError>, 'isInitialLoading'>,
|
|
158
|
+
{ data: TData }
|
|
159
|
+
>
|
|
136
160
|
|
|
137
161
|
export type DefinedUseInfiniteQueryResult<
|
|
138
162
|
TData = unknown,
|
|
139
163
|
TError = DefaultError,
|
|
140
|
-
> = DefinedInfiniteQueryObserverResult<TData, TError
|
|
164
|
+
> = OmitIsInitialLoading<DefinedInfiniteQueryObserverResult<TData, TError>>
|
|
141
165
|
|
|
142
166
|
/* --- Create Mutation Types --- */
|
|
143
167
|
export interface MutationOptions<
|
|
@@ -157,23 +181,21 @@ export type UseMutationOptions<
|
|
|
157
181
|
TOnMutateResult = unknown,
|
|
158
182
|
> = Accessor<MutationOptions<TData, TError, TVariables, TOnMutateResult>>
|
|
159
183
|
|
|
184
|
+
/**
|
|
185
|
+
* One `mutate`, returning a safe-to-ignore promise: errors are also routed
|
|
186
|
+
* into reactive state, and ignoring the promise never surfaces an
|
|
187
|
+
* unhandled rejection. Call-site callbacks are gone — settle logic that
|
|
188
|
+
* used to live in `mutate(vars, { onSuccess })` is linear code after
|
|
189
|
+
* `await mutate(vars)` or a config-level callback.
|
|
190
|
+
*/
|
|
160
191
|
export type UseMutateFunction<
|
|
161
192
|
TData = unknown,
|
|
162
|
-
|
|
193
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
194
|
+
_TError = DefaultError,
|
|
163
195
|
TVariables = void,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
MutateFunction<TData, TError, TVariables, TOnMutateResult>
|
|
168
|
-
>
|
|
169
|
-
) => void
|
|
170
|
-
|
|
171
|
-
export type UseMutateAsyncFunction<
|
|
172
|
-
TData = unknown,
|
|
173
|
-
TError = DefaultError,
|
|
174
|
-
TVariables = void,
|
|
175
|
-
TOnMutateResult = unknown,
|
|
176
|
-
> = MutateFunction<TData, TError, TVariables, TOnMutateResult>
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
197
|
+
_TOnMutateResult = unknown,
|
|
198
|
+
> = (variables: TVariables) => Promise<TData>
|
|
177
199
|
|
|
178
200
|
export type UseBaseMutationResult<
|
|
179
201
|
TData = unknown,
|
|
@@ -181,16 +203,12 @@ export type UseBaseMutationResult<
|
|
|
181
203
|
TVariables = unknown,
|
|
182
204
|
TOnMutateResult = unknown,
|
|
183
205
|
> = Override<
|
|
184
|
-
|
|
206
|
+
OmitKeyof<
|
|
207
|
+
MutationObserverResult<TData, TError, TVariables, TOnMutateResult>,
|
|
208
|
+
'context'
|
|
209
|
+
>,
|
|
185
210
|
{ mutate: UseMutateFunction<TData, TError, TVariables, TOnMutateResult> }
|
|
186
|
-
>
|
|
187
|
-
mutateAsync: UseMutateAsyncFunction<
|
|
188
|
-
TData,
|
|
189
|
-
TError,
|
|
190
|
-
TVariables,
|
|
191
|
-
TOnMutateResult
|
|
192
|
-
>
|
|
193
|
-
}
|
|
211
|
+
>
|
|
194
212
|
|
|
195
213
|
export type UseMutationResult<
|
|
196
214
|
TData = unknown,
|