@tanstack/query-core 5.100.1 → 5.100.3
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/legacy/_tsup-dts-rollup.d.cts +5 -7
- package/build/legacy/_tsup-dts-rollup.d.ts +5 -7
- package/build/legacy/hydration.cjs +13 -3
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.js +13 -3
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/infiniteQueryObserver.cjs +3 -5
- package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
- package/build/legacy/infiniteQueryObserver.js +4 -10
- package/build/legacy/infiniteQueryObserver.js.map +1 -1
- package/build/legacy/queriesObserver.cjs +12 -4
- package/build/legacy/queriesObserver.cjs.map +1 -1
- package/build/legacy/queriesObserver.js +12 -4
- package/build/legacy/queriesObserver.js.map +1 -1
- package/build/legacy/query.cjs +26 -14
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +0 -1
- package/build/legacy/query.d.ts +0 -1
- package/build/legacy/query.js +26 -14
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryClient.cjs +2 -3
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.js +2 -3
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.cts +5 -7
- package/build/modern/_tsup-dts-rollup.d.ts +5 -7
- package/build/modern/hydration.cjs +13 -3
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.js +13 -3
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/infiniteQueryObserver.cjs +3 -5
- package/build/modern/infiniteQueryObserver.cjs.map +1 -1
- package/build/modern/infiniteQueryObserver.js +4 -10
- package/build/modern/infiniteQueryObserver.js.map +1 -1
- package/build/modern/queriesObserver.cjs +9 -3
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.js +9 -3
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs +14 -3
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +0 -1
- package/build/modern/query.d.ts +0 -1
- package/build/modern/query.js +14 -3
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryClient.cjs +2 -3
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.js +2 -3
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.js.map +1 -1
- package/package.json +1 -1
- package/src/hydration.ts +12 -1
- package/src/infiniteQueryObserver.ts +4 -10
- package/src/queriesObserver.ts +17 -3
- package/src/query.ts +19 -11
- package/src/queryClient.ts +2 -13
- package/src/types.ts +2 -5
package/src/query.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { notifyManager } from './notifyManager'
|
|
11
11
|
import { CancelledError, canFetch, createRetryer } from './retryer'
|
|
12
12
|
import { Removable } from './removable'
|
|
13
|
+
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
|
|
13
14
|
import type { QueryCache } from './queryCache'
|
|
14
15
|
import type { QueryClient } from './queryClient'
|
|
15
16
|
import type {
|
|
@@ -137,7 +138,6 @@ interface ContinueAction {
|
|
|
137
138
|
interface SetStateAction<TData, TError> {
|
|
138
139
|
type: 'setState'
|
|
139
140
|
state: Partial<QueryState<TData, TError>>
|
|
140
|
-
setStateOptions?: SetStateOptions
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
export type Action<TData, TError> =
|
|
@@ -150,10 +150,6 @@ export type Action<TData, TError> =
|
|
|
150
150
|
| SetStateAction<TData, TError>
|
|
151
151
|
| SuccessAction<TData>
|
|
152
152
|
|
|
153
|
-
export interface SetStateOptions {
|
|
154
|
-
meta?: any
|
|
155
|
-
}
|
|
156
|
-
|
|
157
153
|
// CLASS
|
|
158
154
|
|
|
159
155
|
export class Query<
|
|
@@ -166,6 +162,7 @@ export class Query<
|
|
|
166
162
|
queryHash: string
|
|
167
163
|
options!: QueryOptions<TQueryFnData, TError, TData, TQueryKey>
|
|
168
164
|
state: QueryState<TData, TError>
|
|
165
|
+
#queryType?: 'infinite'
|
|
169
166
|
|
|
170
167
|
#initialState: QueryState<TData, TError>
|
|
171
168
|
#revertState?: QueryState<TData, TError>
|
|
@@ -195,6 +192,10 @@ export class Query<
|
|
|
195
192
|
return this.options.meta
|
|
196
193
|
}
|
|
197
194
|
|
|
195
|
+
get queryType() {
|
|
196
|
+
return this.#queryType
|
|
197
|
+
}
|
|
198
|
+
|
|
198
199
|
get promise(): Promise<TData> | undefined {
|
|
199
200
|
return this.#retryer?.promise
|
|
200
201
|
}
|
|
@@ -204,6 +205,10 @@ export class Query<
|
|
|
204
205
|
): void {
|
|
205
206
|
this.options = { ...this.#defaultOptions, ...options }
|
|
206
207
|
|
|
208
|
+
if (options?._type) {
|
|
209
|
+
this.#queryType = options._type
|
|
210
|
+
}
|
|
211
|
+
|
|
207
212
|
this.updateGcTime(this.options.gcTime)
|
|
208
213
|
|
|
209
214
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -241,11 +246,8 @@ export class Query<
|
|
|
241
246
|
return data
|
|
242
247
|
}
|
|
243
248
|
|
|
244
|
-
setState(
|
|
245
|
-
|
|
246
|
-
setStateOptions?: SetStateOptions,
|
|
247
|
-
): void {
|
|
248
|
-
this.#dispatch({ type: 'setState', state, setStateOptions })
|
|
249
|
+
setState(state: Partial<QueryState<TData, TError>>): void {
|
|
250
|
+
this.#dispatch({ type: 'setState', state })
|
|
249
251
|
}
|
|
250
252
|
|
|
251
253
|
cancel(options?: CancelOptions): Promise<void> {
|
|
@@ -511,7 +513,13 @@ export class Query<
|
|
|
511
513
|
|
|
512
514
|
const context = createFetchContext()
|
|
513
515
|
|
|
514
|
-
|
|
516
|
+
const behavior =
|
|
517
|
+
this.#queryType === 'infinite'
|
|
518
|
+
? (infiniteQueryBehavior(
|
|
519
|
+
(this.options as { pages?: number }).pages,
|
|
520
|
+
) as QueryBehavior<TQueryFnData, TError, TData, TQueryKey>)
|
|
521
|
+
: this.options.behavior
|
|
522
|
+
behavior?.onFetch(context, this as unknown as Query)
|
|
515
523
|
|
|
516
524
|
// Store state in case the current fetch needs to be reverted
|
|
517
525
|
this.#revertState = this.state
|
package/src/queryClient.ts
CHANGED
|
@@ -12,7 +12,6 @@ import { MutationCache } from './mutationCache'
|
|
|
12
12
|
import { focusManager } from './focusManager'
|
|
13
13
|
import { onlineManager } from './onlineManager'
|
|
14
14
|
import { notifyManager } from './notifyManager'
|
|
15
|
-
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
|
|
16
15
|
import type {
|
|
17
16
|
CancelOptions,
|
|
18
17
|
DefaultError,
|
|
@@ -395,12 +394,7 @@ export class QueryClient {
|
|
|
395
394
|
TPageParam
|
|
396
395
|
>,
|
|
397
396
|
): Promise<InfiniteData<TData, TPageParam>> {
|
|
398
|
-
options.
|
|
399
|
-
TQueryFnData,
|
|
400
|
-
TError,
|
|
401
|
-
TData,
|
|
402
|
-
TPageParam
|
|
403
|
-
>(options.pages)
|
|
397
|
+
options._type = 'infinite'
|
|
404
398
|
return this.fetchQuery(options as any)
|
|
405
399
|
}
|
|
406
400
|
|
|
@@ -437,12 +431,7 @@ export class QueryClient {
|
|
|
437
431
|
TPageParam
|
|
438
432
|
>,
|
|
439
433
|
): Promise<InfiniteData<TData, TPageParam>> {
|
|
440
|
-
options.
|
|
441
|
-
TQueryFnData,
|
|
442
|
-
TError,
|
|
443
|
-
TData,
|
|
444
|
-
TPageParam
|
|
445
|
-
>(options.pages)
|
|
434
|
+
options._type = 'infinite'
|
|
446
435
|
|
|
447
436
|
return this.ensureQueryData(options as any)
|
|
448
437
|
}
|
package/src/types.ts
CHANGED
|
@@ -246,11 +246,7 @@ export interface QueryOptions<
|
|
|
246
246
|
*/
|
|
247
247
|
gcTime?: number
|
|
248
248
|
queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam> | SkipToken
|
|
249
|
-
persister?: QueryPersister<
|
|
250
|
-
NoInfer<TQueryFnData>,
|
|
251
|
-
NoInfer<TQueryKey>,
|
|
252
|
-
NoInfer<TPageParam>
|
|
253
|
-
>
|
|
249
|
+
persister?: QueryPersister<TQueryFnData, TQueryKey, TPageParam>
|
|
254
250
|
queryHash?: string
|
|
255
251
|
queryKey?: TQueryKey
|
|
256
252
|
queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>
|
|
@@ -266,6 +262,7 @@ export interface QueryOptions<
|
|
|
266
262
|
| boolean
|
|
267
263
|
| ((oldData: unknown | undefined, newData: unknown) => unknown)
|
|
268
264
|
_defaulted?: boolean
|
|
265
|
+
_type?: 'infinite'
|
|
269
266
|
/**
|
|
270
267
|
* Additional payload to be stored on each query.
|
|
271
268
|
* Use this property to pass information that can be used in other places.
|