@tanstack/query-core 5.103.1 → 5.103.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/{classPrivateFieldSet2-CV7wyte-.js → classPrivateFieldSet2-CukOTU3U.js} +5 -5
- package/build/legacy/{classPrivateFieldSet2-Bo0ZyOIv.cjs → classPrivateFieldSet2-CvCEk6bM.cjs} +5 -5
- package/build/legacy/{classPrivateMethodInitSpec-CBwa_Y7C.js → classPrivateMethodInitSpec-CgB-WYk3.js} +2 -2
- package/build/legacy/{classPrivateMethodInitSpec-DVhcLejn.cjs → classPrivateMethodInitSpec-Nr6mgZRs.cjs} +2 -2
- package/build/legacy/focusManager.cjs +1 -1
- package/build/legacy/focusManager.d.cts +1 -1
- package/build/legacy/focusManager.d.ts +1 -1
- package/build/legacy/focusManager.js +1 -1
- package/build/legacy/{hydration-DwR10Hi-.d.cts → hydration-B9t5w6NC.d.ts} +167 -25
- package/build/legacy/hydration-B9t5w6NC.d.ts.map +1 -0
- package/build/legacy/{hydration-Cq7QYAzB.d.ts → hydration-Br9VIGXa.d.cts} +167 -25
- package/build/legacy/hydration-Br9VIGXa.d.cts.map +1 -0
- package/build/legacy/hydration.cjs.map +1 -1
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +1 -1
- package/build/legacy/hydration.js.map +1 -1
- package/build/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
- package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
- package/build/legacy/infiniteQueryObserver.d.cts +2 -2
- package/build/legacy/infiniteQueryObserver.d.ts +2 -2
- package/build/legacy/mutation.cjs +2 -2
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutation.js +2 -2
- package/build/legacy/mutationCache.cjs +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationCache.js +1 -1
- package/build/legacy/mutationObserver.cjs +2 -2
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/mutationObserver.js +2 -2
- package/build/legacy/onlineManager.cjs +1 -1
- package/build/legacy/onlineManager.d.cts +1 -1
- package/build/legacy/onlineManager.d.ts +1 -1
- package/build/legacy/onlineManager.js +1 -1
- package/build/legacy/queriesObserver.cjs +2 -2
- package/build/legacy/queriesObserver.d.cts +2 -2
- package/build/legacy/queriesObserver.d.cts.map +1 -1
- package/build/legacy/queriesObserver.d.ts +2 -2
- package/build/legacy/queriesObserver.d.ts.map +1 -1
- package/build/legacy/queriesObserver.js +2 -2
- package/build/legacy/query.cjs +2 -2
- package/build/legacy/query.cjs.map +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/query.js +2 -2
- package/build/legacy/query.js.map +1 -1
- package/build/legacy/queryCache.cjs +3 -4
- package/build/legacy/queryCache.cjs.map +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryCache.js +3 -4
- package/build/legacy/queryCache.js.map +1 -1
- package/build/legacy/queryClient.cjs +8 -1
- package/build/legacy/queryClient.cjs.map +1 -1
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +1 -1
- package/build/legacy/queryClient.js +8 -1
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.cjs +2 -2
- package/build/legacy/queryObserver.cjs.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/queryObserver.js +2 -2
- package/build/legacy/queryObserver.js.map +1 -1
- package/build/legacy/removable-0GzhW1PK.d.cts +22 -0
- package/build/legacy/removable-0GzhW1PK.d.cts.map +1 -0
- package/build/legacy/removable-0GzhW1PK.d.ts +22 -0
- package/build/legacy/removable-0GzhW1PK.d.ts.map +1 -0
- package/build/legacy/removable.cjs +10 -1
- package/build/legacy/removable.cjs.map +1 -1
- package/build/legacy/removable.d.cts +1 -1
- package/build/legacy/removable.d.ts +1 -1
- package/build/legacy/removable.js +10 -1
- package/build/legacy/removable.js.map +1 -1
- package/build/legacy/retryer.cjs.map +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +1 -1
- package/build/legacy/retryer.js.map +1 -1
- package/build/legacy/streamedQuery.cjs +0 -7
- package/build/legacy/streamedQuery.cjs.map +1 -1
- package/build/legacy/streamedQuery.d.cts +1 -8
- package/build/legacy/streamedQuery.d.cts.map +1 -1
- package/build/legacy/streamedQuery.d.ts +1 -8
- package/build/legacy/streamedQuery.d.ts.map +1 -1
- package/build/legacy/streamedQuery.js +0 -7
- package/build/legacy/streamedQuery.js.map +1 -1
- package/build/legacy/subscribable-CysQ0tne.d.cts +34 -0
- package/build/legacy/subscribable-CysQ0tne.d.cts.map +1 -0
- package/build/legacy/subscribable-CysQ0tne.d.ts +34 -0
- package/build/legacy/subscribable-CysQ0tne.d.ts.map +1 -0
- package/build/legacy/subscribable.cjs +22 -0
- package/build/legacy/subscribable.cjs.map +1 -1
- package/build/legacy/subscribable.d.cts +1 -1
- package/build/legacy/subscribable.d.ts +1 -1
- package/build/legacy/subscribable.js +22 -0
- package/build/legacy/subscribable.js.map +1 -1
- package/build/legacy/timeoutManager.cjs +1 -1
- package/build/legacy/timeoutManager.js +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/types.js.map +1 -1
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/focusManager.cjs.map +1 -1
- package/build/modern/focusManager.d.cts +1 -1
- package/build/modern/focusManager.d.ts +1 -1
- package/build/modern/focusManager.js.map +1 -1
- package/build/modern/{hydration-DwR10Hi-.d.cts → hydration-B9t5w6NC.d.ts} +167 -25
- package/build/modern/hydration-B9t5w6NC.d.ts.map +1 -0
- package/build/modern/{hydration-Cq7QYAzB.d.ts → hydration-Br9VIGXa.d.cts} +167 -25
- package/build/modern/hydration-Br9VIGXa.d.cts.map +1 -0
- package/build/modern/hydration.cjs.map +1 -1
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +1 -1
- package/build/modern/hydration.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/infiniteQueryBehavior.d.cts +1 -1
- package/build/modern/infiniteQueryBehavior.d.ts +1 -1
- package/build/modern/infiniteQueryObserver.d.cts +2 -2
- package/build/modern/infiniteQueryObserver.d.ts +2 -2
- package/build/modern/mutation.cjs.map +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutation.js.map +1 -1
- package/build/modern/mutationCache.cjs.map +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationCache.js.map +1 -1
- package/build/modern/mutationObserver.cjs.map +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/mutationObserver.js.map +1 -1
- package/build/modern/onlineManager.cjs.map +1 -1
- package/build/modern/onlineManager.d.cts +1 -1
- package/build/modern/onlineManager.d.ts +1 -1
- package/build/modern/onlineManager.js.map +1 -1
- package/build/modern/queriesObserver.cjs.map +1 -1
- package/build/modern/queriesObserver.d.cts +2 -2
- package/build/modern/queriesObserver.d.cts.map +1 -1
- package/build/modern/queriesObserver.d.ts +2 -2
- package/build/modern/queriesObserver.d.ts.map +1 -1
- package/build/modern/queriesObserver.js.map +1 -1
- package/build/modern/query.cjs.map +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/query.js.map +1 -1
- package/build/modern/queryCache.cjs +2 -3
- package/build/modern/queryCache.cjs.map +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryCache.js +2 -3
- package/build/modern/queryCache.js.map +1 -1
- package/build/modern/queryClient.cjs +7 -0
- package/build/modern/queryClient.cjs.map +1 -1
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +1 -1
- package/build/modern/queryClient.js +7 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.cjs.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/queryObserver.js.map +1 -1
- package/build/modern/removable-0GzhW1PK.d.cts +22 -0
- package/build/modern/removable-0GzhW1PK.d.cts.map +1 -0
- package/build/modern/removable-0GzhW1PK.d.ts +22 -0
- package/build/modern/removable-0GzhW1PK.d.ts.map +1 -0
- package/build/modern/removable.cjs +9 -0
- package/build/modern/removable.cjs.map +1 -1
- package/build/modern/removable.d.cts +1 -1
- package/build/modern/removable.d.ts +1 -1
- package/build/modern/removable.js +9 -0
- package/build/modern/removable.js.map +1 -1
- package/build/modern/retryer.cjs.map +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +1 -1
- package/build/modern/retryer.js.map +1 -1
- package/build/modern/streamedQuery.cjs +0 -7
- package/build/modern/streamedQuery.cjs.map +1 -1
- package/build/modern/streamedQuery.d.cts +1 -8
- package/build/modern/streamedQuery.d.cts.map +1 -1
- package/build/modern/streamedQuery.d.ts +1 -8
- package/build/modern/streamedQuery.d.ts.map +1 -1
- package/build/modern/streamedQuery.js +0 -7
- package/build/modern/streamedQuery.js.map +1 -1
- package/build/modern/subscribable-CysQ0tne.d.cts +34 -0
- package/build/modern/subscribable-CysQ0tne.d.cts.map +1 -0
- package/build/modern/subscribable-CysQ0tne.d.ts +34 -0
- package/build/modern/subscribable-CysQ0tne.d.ts.map +1 -0
- package/build/modern/subscribable.cjs +22 -0
- package/build/modern/subscribable.cjs.map +1 -1
- package/build/modern/subscribable.d.cts +1 -1
- package/build/modern/subscribable.d.ts +1 -1
- package/build/modern/subscribable.js +22 -0
- package/build/modern/subscribable.js.map +1 -1
- package/build/modern/timeoutManager.cjs.map +1 -1
- package/build/modern/timeoutManager.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/types.js.map +1 -1
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/build/modern/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/hydration.ts +1 -0
- package/src/query.ts +1 -2
- package/src/queryCache.ts +3 -8
- package/src/queryClient.ts +7 -0
- package/src/queryObserver.ts +4 -8
- package/src/removable.ts +9 -0
- package/src/retryer.ts +4 -0
- package/src/streamedQuery.ts +0 -7
- package/src/subscribable.ts +22 -0
- package/src/types.ts +159 -35
- package/src/utils.ts +1 -1
- package/build/legacy/hydration-Cq7QYAzB.d.ts.map +0 -1
- package/build/legacy/hydration-DwR10Hi-.d.cts.map +0 -1
- package/build/legacy/removable-DeMjhW5M.d.cts +0 -13
- package/build/legacy/removable-DeMjhW5M.d.cts.map +0 -1
- package/build/legacy/removable-DeMjhW5M.d.ts +0 -13
- package/build/legacy/removable-DeMjhW5M.d.ts.map +0 -1
- package/build/legacy/subscribable-CbifVTKz.d.cts +0 -12
- package/build/legacy/subscribable-CbifVTKz.d.cts.map +0 -1
- package/build/legacy/subscribable-CbifVTKz.d.ts +0 -12
- package/build/legacy/subscribable-CbifVTKz.d.ts.map +0 -1
- package/build/modern/hydration-Cq7QYAzB.d.ts.map +0 -1
- package/build/modern/hydration-DwR10Hi-.d.cts.map +0 -1
- package/build/modern/removable-DeMjhW5M.d.cts +0 -13
- package/build/modern/removable-DeMjhW5M.d.cts.map +0 -1
- package/build/modern/removable-DeMjhW5M.d.ts +0 -13
- package/build/modern/removable-DeMjhW5M.d.ts.map +0 -1
- package/build/modern/subscribable-CbifVTKz.d.cts +0 -12
- package/build/modern/subscribable-CbifVTKz.d.cts.map +0 -1
- package/build/modern/subscribable-CbifVTKz.d.ts +0 -12
- package/build/modern/subscribable-CbifVTKz.d.ts.map +0 -1
package/src/queryObserver.ts
CHANGED
|
@@ -409,8 +409,7 @@ export class QueryObserver<
|
|
|
409
409
|
|
|
410
410
|
let unsubscribe = () => {}
|
|
411
411
|
let resolveEarly:
|
|
412
|
-
|
|
413
|
-
| undefined
|
|
412
|
+
((result: QueryObserverResult<TData, TError>) => void) | undefined
|
|
414
413
|
|
|
415
414
|
const cachePromise = new Promise<QueryObserverResult<TData, TError>>(
|
|
416
415
|
(resolve) => {
|
|
@@ -569,8 +568,7 @@ export class QueryObserver<
|
|
|
569
568
|
const prevQuery = this.#currentQuery
|
|
570
569
|
const prevOptions = this.options
|
|
571
570
|
const prevResult = this.#currentResult as
|
|
572
|
-
|
|
573
|
-
| undefined
|
|
571
|
+
QueryObserverResult<TData, TError> | undefined
|
|
574
572
|
const prevResultState = this.#currentResultState
|
|
575
573
|
const prevResultOptions = this.#currentResultOptions
|
|
576
574
|
const queryChange = query !== prevQuery
|
|
@@ -734,8 +732,7 @@ export class QueryObserver<
|
|
|
734
732
|
*/
|
|
735
733
|
updateResult(): void {
|
|
736
734
|
const prevResult = this.#currentResult as
|
|
737
|
-
|
|
738
|
-
| undefined
|
|
735
|
+
QueryObserverResult<TData, TError> | undefined
|
|
739
736
|
|
|
740
737
|
const nextResult = this.createResult(this.#currentQuery, this.options)
|
|
741
738
|
|
|
@@ -813,8 +810,7 @@ export class QueryObserver<
|
|
|
813
810
|
}
|
|
814
811
|
|
|
815
812
|
const prevQuery = this.#currentQuery as
|
|
816
|
-
|
|
817
|
-
| undefined
|
|
813
|
+
Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined
|
|
818
814
|
this.#currentQuery = query
|
|
819
815
|
this.#currentQueryInitialState = query.state
|
|
820
816
|
|
package/src/removable.ts
CHANGED
|
@@ -3,10 +3,19 @@ import { isServer as isServerEnvironment } from './environmentManager'
|
|
|
3
3
|
import { isValidTimeout } from './utils'
|
|
4
4
|
import type { ManagedTimerId } from './timeoutManager'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The base class for cache entries that are garbage collected once nothing is using them —
|
|
8
|
+
* `Query` and `Mutation` both extend it. `gcTime` controls how long an unused entry is kept.
|
|
9
|
+
*/
|
|
6
10
|
export abstract class Removable {
|
|
7
11
|
gcTime!: number
|
|
8
12
|
#gcTimeout?: ManagedTimerId
|
|
9
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Clears the pending garbage collection timeout, so the entry is no longer scheduled for removal.
|
|
16
|
+
* A subclass may override this to release what it holds on to as well — `Query` also cancels any
|
|
17
|
+
* in-flight fetch.
|
|
18
|
+
*/
|
|
10
19
|
destroy(): void {
|
|
11
20
|
this.clearGcTimeout()
|
|
12
21
|
}
|
package/src/retryer.ts
CHANGED
|
@@ -32,15 +32,19 @@ export interface Retryer<TData = unknown> {
|
|
|
32
32
|
|
|
33
33
|
type RetryerStatus = 'pending' | 'resolved' | 'rejected'
|
|
34
34
|
|
|
35
|
+
/** @inline */
|
|
35
36
|
export type RetryValue<TError> = boolean | number | ShouldRetryFunction<TError>
|
|
36
37
|
|
|
38
|
+
/** @inline */
|
|
37
39
|
type ShouldRetryFunction<TError = DefaultError> = (
|
|
38
40
|
failureCount: number,
|
|
39
41
|
error: TError,
|
|
40
42
|
) => boolean
|
|
41
43
|
|
|
44
|
+
/** @inline */
|
|
42
45
|
export type RetryDelayValue<TError> = number | RetryDelayFunction<TError>
|
|
43
46
|
|
|
47
|
+
/** @inline */
|
|
44
48
|
type RetryDelayFunction<TError = DefaultError> = (
|
|
45
49
|
failureCount: number,
|
|
46
50
|
error: TError,
|
package/src/streamedQuery.ts
CHANGED
|
@@ -55,13 +55,6 @@ type StreamedQueryParams<TQueryFnData, TData, TQueryKey extends QueryKey> =
|
|
|
55
55
|
* The query will be in a 'pending' state until the first chunk of data is received, but will go to 'success' after that.
|
|
56
56
|
* The query will stay in fetchStatus 'fetching' until the stream ends.
|
|
57
57
|
* @param streamFn - The function that returns an AsyncIterable to stream data from.
|
|
58
|
-
* @param refetchMode - Defines how re-fetches are handled.
|
|
59
|
-
* Defaults to `'reset'`, erases all data and puts the query back into `pending` state.
|
|
60
|
-
* Set to `'append'` to append new data to the existing data.
|
|
61
|
-
* Set to `'replace'` to write all data to the cache once the stream ends.
|
|
62
|
-
* @param reducer - A function to reduce the streamed chunks into the final data.
|
|
63
|
-
* Defaults to a function that appends chunks to the end of the array.
|
|
64
|
-
* @param initialValue - Initial value to be used while the first chunk is being fetched, and returned if the stream yields no values.
|
|
65
58
|
* @example
|
|
66
59
|
* ```ts
|
|
67
60
|
* await queryClient.query({
|
package/src/subscribable.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base class behind everything in Query that you can subscribe to: `QueryCache`, `MutationCache`,
|
|
3
|
+
* the observers, and the `FocusManager`/`OnlineManager` behind `focusManager` and `onlineManager`.
|
|
4
|
+
* Subclasses decide what a listener receives and when it is called.
|
|
5
|
+
*/
|
|
1
6
|
export class Subscribable<TListener extends Function> {
|
|
2
7
|
protected listeners = new Set<TListener>()
|
|
3
8
|
|
|
@@ -5,6 +10,20 @@ export class Subscribable<TListener extends Function> {
|
|
|
5
10
|
this.subscribe = this.subscribe.bind(this)
|
|
6
11
|
}
|
|
7
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Registers a listener to be called on every update this object notifies about. Returns a function
|
|
15
|
+
* that removes the listener again — call it to stop listening. The base class never drops a listener
|
|
16
|
+
* on its own, though some subclasses clear all of theirs in `destroy()`.
|
|
17
|
+
* @param listener - Called on each update, with whatever the subclass passes to its subscribers.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const unsubscribe = subscribable.subscribe(() => {
|
|
21
|
+
* // react to the update
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* unsubscribe()
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
8
27
|
subscribe(listener: TListener): () => void {
|
|
9
28
|
this.listeners.add(listener)
|
|
10
29
|
|
|
@@ -16,6 +35,9 @@ export class Subscribable<TListener extends Function> {
|
|
|
16
35
|
}
|
|
17
36
|
}
|
|
18
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.
|
|
40
|
+
*/
|
|
19
41
|
hasListeners(): boolean {
|
|
20
42
|
return this.listeners.size > 0
|
|
21
43
|
}
|
package/src/types.ts
CHANGED
|
@@ -18,13 +18,12 @@ export type DistributiveOmit<
|
|
|
18
18
|
|
|
19
19
|
export type OmitKeyof<
|
|
20
20
|
TObject,
|
|
21
|
-
TKey extends TStrictly extends 'safely'
|
|
22
|
-
?
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
: keyof TObject,
|
|
21
|
+
TKey extends (TStrictly extends 'safely'
|
|
22
|
+
? | keyof TObject
|
|
23
|
+
| (string & Record<never, never>)
|
|
24
|
+
| (number & Record<never, never>)
|
|
25
|
+
| (symbol & Record<never, never>)
|
|
26
|
+
: keyof TObject),
|
|
28
27
|
TStrictly extends 'strictly' | 'safely' = 'strictly',
|
|
29
28
|
> = Omit<TObject, TKey>
|
|
30
29
|
|
|
@@ -34,6 +33,25 @@ export type Override<TTargetA, TTargetB> = {
|
|
|
34
33
|
: TTargetA[AKey]
|
|
35
34
|
}
|
|
36
35
|
|
|
36
|
+
/**
|
|
37
|
+
* The interface to augment via declaration merging to override Query's default types repository-wide.
|
|
38
|
+
* Each field it declares replaces the default of the matching type: `defaultError` for {@link DefaultError},
|
|
39
|
+
* `queryKey` for {@link QueryKey}, `mutationKey` for {@link MutationKey}, `queryMeta` for {@link QueryMeta} and
|
|
40
|
+
* `mutationMeta` for {@link MutationMeta}. Leave a field out to keep that type's default.
|
|
41
|
+
* Augment the module you install — `@tanstack/react-query`, `@tanstack/vue-query`,
|
|
42
|
+
* `@tanstack/solid-query`, `@tanstack/svelte-query`, `@tanstack/preact-query`,
|
|
43
|
+
* `@tanstack/angular-query-experimental` or `@tanstack/lit-query`. Augmenting `@tanstack/query-core`
|
|
44
|
+
* works too and covers every adapter at once.
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Use the module you installed — here, the React adapter.
|
|
48
|
+
* declare module '@tanstack/react-query' {
|
|
49
|
+
* interface Register {
|
|
50
|
+
* defaultError: AxiosError
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
37
55
|
export interface Register {
|
|
38
56
|
// defaultError: Error
|
|
39
57
|
// queryMeta: Record<string, unknown>
|
|
@@ -42,12 +60,20 @@ export interface Register {
|
|
|
42
60
|
// mutationKey: ReadonlyArray<unknown>
|
|
43
61
|
}
|
|
44
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The error type used wherever an error is not given an explicit type parameter.
|
|
65
|
+
* Defaults to `Error`; declare `defaultError` on {@link Register} to change it everywhere at once.
|
|
66
|
+
*/
|
|
45
67
|
export type DefaultError = Register extends {
|
|
46
68
|
defaultError: infer TError
|
|
47
69
|
}
|
|
48
70
|
? TError
|
|
49
71
|
: Error
|
|
50
72
|
|
|
73
|
+
/**
|
|
74
|
+
* The type of a query key — the serializable array that identifies a query in the cache.
|
|
75
|
+
* Defaults to `ReadonlyArray<unknown>`; declare `queryKey` on {@link Register} to narrow it repository-wide.
|
|
76
|
+
*/
|
|
51
77
|
export type QueryKey = Register extends {
|
|
52
78
|
queryKey: infer TQueryKey
|
|
53
79
|
}
|
|
@@ -99,14 +125,17 @@ export type InferErrorFromTag<TError, TTaggedQueryKey extends QueryKey> =
|
|
|
99
125
|
: TaggedError
|
|
100
126
|
: TError
|
|
101
127
|
|
|
128
|
+
/** @inline */
|
|
102
129
|
export type QueryFunction<
|
|
103
130
|
T = unknown,
|
|
104
131
|
TQueryKey extends QueryKey = QueryKey,
|
|
105
132
|
TPageParam = never,
|
|
106
133
|
> = (context: QueryFunctionContext<TQueryKey, TPageParam>) => T | Promise<T>
|
|
107
134
|
|
|
135
|
+
/** @inline */
|
|
108
136
|
export type StaleTime = number | 'static'
|
|
109
137
|
|
|
138
|
+
/** @inline */
|
|
110
139
|
export type StaleTimeFunction<
|
|
111
140
|
TQueryFnData = unknown,
|
|
112
141
|
TError = DefaultError,
|
|
@@ -116,15 +145,16 @@ export type StaleTimeFunction<
|
|
|
116
145
|
| StaleTime
|
|
117
146
|
| ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => StaleTime)
|
|
118
147
|
|
|
148
|
+
/** @inline */
|
|
119
149
|
export type QueryBooleanOption<
|
|
120
150
|
TQueryFnData = unknown,
|
|
121
151
|
TError = DefaultError,
|
|
122
152
|
TData = TQueryFnData,
|
|
123
153
|
TQueryKey extends QueryKey = QueryKey,
|
|
124
154
|
> =
|
|
125
|
-
| boolean
|
|
126
|
-
| ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => boolean)
|
|
155
|
+
boolean | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => boolean)
|
|
127
156
|
|
|
157
|
+
/** @inline */
|
|
128
158
|
export type QueryPersister<
|
|
129
159
|
T = unknown,
|
|
130
160
|
TQueryKey extends QueryKey = QueryKey,
|
|
@@ -170,10 +200,12 @@ export type QueryFunctionContext<
|
|
|
170
200
|
meta: QueryMeta | undefined
|
|
171
201
|
}
|
|
172
202
|
|
|
203
|
+
/** @inline */
|
|
173
204
|
export type InitialDataFunction<T> = () => T | undefined
|
|
174
205
|
|
|
175
206
|
type NonFunctionGuard<T> = T extends Function ? never : T
|
|
176
207
|
|
|
208
|
+
/** @inline */
|
|
177
209
|
export type PlaceholderDataFunction<
|
|
178
210
|
TQueryFnData = unknown,
|
|
179
211
|
TError = DefaultError,
|
|
@@ -189,10 +221,12 @@ export type QueriesPlaceholderDataFunction<TQueryData> = (
|
|
|
189
221
|
previousQuery: undefined,
|
|
190
222
|
) => TQueryData | undefined
|
|
191
223
|
|
|
224
|
+
/** @inline */
|
|
192
225
|
export type QueryKeyHashFunction<TQueryKey extends QueryKey> = (
|
|
193
226
|
queryKey: TQueryKey,
|
|
194
227
|
) => string
|
|
195
228
|
|
|
229
|
+
/** @inline */
|
|
196
230
|
export type GetPreviousPageParamFunction<TPageParam, TQueryFnData = unknown> = (
|
|
197
231
|
firstPage: TQueryFnData,
|
|
198
232
|
allPages: Array<TQueryFnData>,
|
|
@@ -200,6 +234,7 @@ export type GetPreviousPageParamFunction<TPageParam, TQueryFnData = unknown> = (
|
|
|
200
234
|
allPageParams: Array<TPageParam>,
|
|
201
235
|
) => TPageParam | undefined | null
|
|
202
236
|
|
|
237
|
+
/** @inline */
|
|
203
238
|
export type GetNextPageParamFunction<TPageParam, TQueryFnData = unknown> = (
|
|
204
239
|
lastPage: TQueryFnData,
|
|
205
240
|
allPages: Array<TQueryFnData>,
|
|
@@ -207,11 +242,19 @@ export type GetNextPageParamFunction<TPageParam, TQueryFnData = unknown> = (
|
|
|
207
242
|
allPageParams: Array<TPageParam>,
|
|
208
243
|
) => TPageParam | undefined | null
|
|
209
244
|
|
|
245
|
+
/**
|
|
246
|
+
* The data shape of an infinite query: every page fetched so far, plus the page param each one was fetched with.
|
|
247
|
+
* `pages` and `pageParams` are index-aligned — `pageParams[i]` is the param that produced `pages[i]`.
|
|
248
|
+
*/
|
|
210
249
|
export interface InfiniteData<TData, TPageParam = unknown> {
|
|
211
250
|
pages: Array<TData>
|
|
212
251
|
pageParams: Array<TPageParam>
|
|
213
252
|
}
|
|
214
253
|
|
|
254
|
+
/**
|
|
255
|
+
* The type of the `meta` object that can be attached to a query and read back from `queryFn`, callbacks and
|
|
256
|
+
* cache-level handlers. Defaults to `Record<string, unknown>`; declare `queryMeta` on {@link Register} to narrow it.
|
|
257
|
+
*/
|
|
215
258
|
export type QueryMeta = Register extends {
|
|
216
259
|
queryMeta: infer TQueryMeta
|
|
217
260
|
}
|
|
@@ -220,8 +263,10 @@ export type QueryMeta = Register extends {
|
|
|
220
263
|
: Record<string, unknown>
|
|
221
264
|
: Record<string, unknown>
|
|
222
265
|
|
|
266
|
+
/** @inline */
|
|
223
267
|
export type NetworkMode = 'online' | 'always' | 'offlineFirst'
|
|
224
268
|
|
|
269
|
+
/** @inline */
|
|
225
270
|
export type NotifyOnChangeProps =
|
|
226
271
|
| Array<keyof InfiniteQueryObserverResult>
|
|
227
272
|
| 'all'
|
|
@@ -259,7 +304,7 @@ export interface QueryOptions<
|
|
|
259
304
|
/**
|
|
260
305
|
* Controls whether a query is allowed to run based on the current network connectivity.
|
|
261
306
|
*
|
|
262
|
-
*
|
|
307
|
+
* @defaultValue 'online'
|
|
263
308
|
* @see [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
264
309
|
*/
|
|
265
310
|
networkMode?: NetworkMode
|
|
@@ -325,11 +370,10 @@ export interface QueryOptions<
|
|
|
325
370
|
* Set this to `false` to disable structural sharing between query results.
|
|
326
371
|
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic.
|
|
327
372
|
*
|
|
328
|
-
*
|
|
373
|
+
* @defaultValue true
|
|
329
374
|
*/
|
|
330
375
|
structuralSharing?:
|
|
331
|
-
|
|
|
332
|
-
| ((oldData: unknown | undefined, newData: unknown) => unknown)
|
|
376
|
+
boolean | ((oldData: unknown | undefined, newData: unknown) => unknown)
|
|
333
377
|
/** @internal */
|
|
334
378
|
_defaulted?: boolean
|
|
335
379
|
/** @internal */
|
|
@@ -346,6 +390,13 @@ export interface QueryOptions<
|
|
|
346
390
|
}
|
|
347
391
|
|
|
348
392
|
export interface InitialPageParam<TPageParam = unknown> {
|
|
393
|
+
/**
|
|
394
|
+
* The page param to start from when an infinite query has no pages yet.
|
|
395
|
+
* It is passed to `queryFn` as `pageParam` for the first page; every page after that gets the
|
|
396
|
+
* value returned by `getNextPageParam` or `getPreviousPageParam`.
|
|
397
|
+
* It only applies while the query has no pages: once a first page exists, refetching starts from
|
|
398
|
+
* that page's own param instead.
|
|
399
|
+
*/
|
|
349
400
|
initialPageParam: TPageParam
|
|
350
401
|
}
|
|
351
402
|
|
|
@@ -365,6 +416,7 @@ export interface InfiniteQueryPageParamsOptions<
|
|
|
365
416
|
getNextPageParam: GetNextPageParamFunction<TPageParam, TQueryFnData>
|
|
366
417
|
}
|
|
367
418
|
|
|
419
|
+
/** @inline */
|
|
368
420
|
export type ThrowOnError<
|
|
369
421
|
TQueryFnData,
|
|
370
422
|
TError,
|
|
@@ -393,7 +445,7 @@ export interface QueryObserverOptions<
|
|
|
393
445
|
* To refetch the query, use the `refetch` method returned from the `useQuery` instance.
|
|
394
446
|
* Accepts a boolean or function that returns a boolean.
|
|
395
447
|
*
|
|
396
|
-
*
|
|
448
|
+
* @defaultValue true
|
|
397
449
|
*/
|
|
398
450
|
enabled?: QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
399
451
|
/**
|
|
@@ -402,14 +454,14 @@ export interface QueryObserverOptions<
|
|
|
402
454
|
* If set to `'static'`, the data will never be considered stale.
|
|
403
455
|
* If set to a function, the function will be executed with the query to compute a `staleTime`.
|
|
404
456
|
*
|
|
405
|
-
*
|
|
457
|
+
* @defaultValue 0
|
|
406
458
|
*/
|
|
407
459
|
staleTime?: StaleTimeFunction<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
408
460
|
/**
|
|
409
461
|
* If set to a number, the query will continuously refetch at this frequency in milliseconds.
|
|
410
462
|
* If set to a function, the function will be executed with the latest data and query to compute a frequency
|
|
411
463
|
*
|
|
412
|
-
*
|
|
464
|
+
* @defaultValue false
|
|
413
465
|
*/
|
|
414
466
|
refetchInterval?:
|
|
415
467
|
| number
|
|
@@ -420,7 +472,7 @@ export interface QueryObserverOptions<
|
|
|
420
472
|
/**
|
|
421
473
|
* If set to `true`, the query will continue to refetch while their tab/window is in the background.
|
|
422
474
|
*
|
|
423
|
-
*
|
|
475
|
+
* @defaultValue false
|
|
424
476
|
*/
|
|
425
477
|
refetchIntervalInBackground?: boolean
|
|
426
478
|
/**
|
|
@@ -429,7 +481,7 @@ export interface QueryObserverOptions<
|
|
|
429
481
|
* If set to `'always'`, the query will always refetch on window focus (except when `staleTime: 'static'` is used).
|
|
430
482
|
* If set to a function, the function will be executed with the latest data and query to compute the value.
|
|
431
483
|
*
|
|
432
|
-
*
|
|
484
|
+
* @defaultValue true
|
|
433
485
|
*/
|
|
434
486
|
refetchOnWindowFocus?:
|
|
435
487
|
| boolean
|
|
@@ -457,7 +509,7 @@ export interface QueryObserverOptions<
|
|
|
457
509
|
* If set to `'always'`, the query will always refetch on mount (except when `staleTime: 'static'` is used).
|
|
458
510
|
* If set to a function, the function will be executed with the latest data and query to compute the value
|
|
459
511
|
*
|
|
460
|
-
*
|
|
512
|
+
* @defaultValue true
|
|
461
513
|
*/
|
|
462
514
|
refetchOnMount?:
|
|
463
515
|
| boolean
|
|
@@ -469,7 +521,7 @@ export interface QueryObserverOptions<
|
|
|
469
521
|
* If set to `false`, the query will not be retried on mount if it contains an error.
|
|
470
522
|
* If set to a function, the function will be executed with the query to compute the value.
|
|
471
523
|
*
|
|
472
|
-
*
|
|
524
|
+
* @defaultValue true
|
|
473
525
|
*/
|
|
474
526
|
retryOnMount?: QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
475
527
|
/**
|
|
@@ -488,7 +540,7 @@ export interface QueryObserverOptions<
|
|
|
488
540
|
* If set to `false` and `suspense` is `false`, errors are returned as state.
|
|
489
541
|
* If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`).
|
|
490
542
|
*
|
|
491
|
-
*
|
|
543
|
+
* @defaultValue false
|
|
492
544
|
*/
|
|
493
545
|
throwOnError?: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>
|
|
494
546
|
/**
|
|
@@ -502,7 +554,7 @@ export interface QueryObserverOptions<
|
|
|
502
554
|
* If set to `true`, the query will suspend when `status === 'pending'`
|
|
503
555
|
* and throw errors when `status === 'error'`.
|
|
504
556
|
*
|
|
505
|
-
*
|
|
557
|
+
* @defaultValue false
|
|
506
558
|
*/
|
|
507
559
|
suspense?: boolean
|
|
508
560
|
/**
|
|
@@ -583,6 +635,10 @@ export interface QueryExecuteOptions<
|
|
|
583
635
|
'queryKey'
|
|
584
636
|
> {
|
|
585
637
|
initialPageParam?: never
|
|
638
|
+
/**
|
|
639
|
+
* This option can be used to transform or select a part of the data returned by the query function. It affects
|
|
640
|
+
* the value this call resolves with, but does not affect what gets stored in the query cache.
|
|
641
|
+
*/
|
|
586
642
|
select?: (data: TQueryData) => TData
|
|
587
643
|
/**
|
|
588
644
|
* The time in milliseconds after data is considered stale.
|
|
@@ -694,9 +750,9 @@ export type FetchInfiniteQueryOptions<
|
|
|
694
750
|
export interface ResultOptions {
|
|
695
751
|
/**
|
|
696
752
|
* If set to `true`, the method throws if any of the underlying query refetch tasks fail.
|
|
753
|
+
* If set to `false`, failed refetches are swallowed and not surfaced to the caller.
|
|
697
754
|
*
|
|
698
|
-
*
|
|
699
|
-
* caller.
|
|
755
|
+
* @defaultValue false
|
|
700
756
|
*/
|
|
701
757
|
throwOnError?: boolean
|
|
702
758
|
}
|
|
@@ -707,7 +763,7 @@ export interface RefetchOptions extends ResultOptions {
|
|
|
707
763
|
*
|
|
708
764
|
* If set to `false`, no refetch will be made if there is already a request running.
|
|
709
765
|
*
|
|
710
|
-
*
|
|
766
|
+
* @defaultValue true
|
|
711
767
|
*/
|
|
712
768
|
cancelRefetch?: boolean
|
|
713
769
|
}
|
|
@@ -718,11 +774,12 @@ export interface InvalidateQueryFilters<
|
|
|
718
774
|
/**
|
|
719
775
|
* Controls which of the matched (now-invalidated) queries are refetched in the background.
|
|
720
776
|
*
|
|
721
|
-
* Defaults to `'active'`.
|
|
722
777
|
* - `'active'`: only queries with at least one active observer are refetched.
|
|
723
778
|
* - `'inactive'`: only queries with no active observer are refetched.
|
|
724
779
|
* - `'all'`: every matched query is refetched, active or not.
|
|
725
780
|
* - `'none'`: no query is refetched; matched queries are only marked as invalidated.
|
|
781
|
+
*
|
|
782
|
+
* @defaultValue 'active'
|
|
726
783
|
*/
|
|
727
784
|
refetchType?: QueryTypeFilter | 'none'
|
|
728
785
|
}
|
|
@@ -741,7 +798,7 @@ export interface FetchNextPageOptions extends ResultOptions {
|
|
|
741
798
|
*
|
|
742
799
|
* If set to `false`, calling `fetchNextPage` repeatedly won't have any effect until the first invocation has resolved.
|
|
743
800
|
*
|
|
744
|
-
*
|
|
801
|
+
* @defaultValue true
|
|
745
802
|
*/
|
|
746
803
|
cancelRefetch?: boolean
|
|
747
804
|
}
|
|
@@ -753,12 +810,14 @@ export interface FetchPreviousPageOptions extends ResultOptions {
|
|
|
753
810
|
*
|
|
754
811
|
* If set to `false`, calling `fetchPreviousPage` repeatedly won't have any effect until the first invocation has resolved.
|
|
755
812
|
*
|
|
756
|
-
*
|
|
813
|
+
* @defaultValue true
|
|
757
814
|
*/
|
|
758
815
|
cancelRefetch?: boolean
|
|
759
816
|
}
|
|
760
817
|
|
|
818
|
+
/** @inline */
|
|
761
819
|
export type QueryStatus = 'pending' | 'error' | 'success'
|
|
820
|
+
/** @inline */
|
|
762
821
|
export type FetchStatus = 'fetching' | 'paused' | 'idle'
|
|
763
822
|
|
|
764
823
|
export interface QueryObserverBaseResult<
|
|
@@ -984,10 +1043,7 @@ export interface QueryObserverPlaceholderResult<
|
|
|
984
1043
|
status: 'success'
|
|
985
1044
|
}
|
|
986
1045
|
|
|
987
|
-
export type DefinedQueryObserverResult<
|
|
988
|
-
TData = unknown,
|
|
989
|
-
TError = DefaultError,
|
|
990
|
-
> =
|
|
1046
|
+
export type DefinedQueryObserverResult<TData = unknown, TError = DefaultError> =
|
|
991
1047
|
| QueryObserverRefetchErrorResult<TData, TError>
|
|
992
1048
|
| QueryObserverSuccessResult<TData, TError>
|
|
993
1049
|
|
|
@@ -1162,6 +1218,10 @@ export type InfiniteQueryObserverResult<
|
|
|
1162
1218
|
| InfiniteQueryObserverPendingResult<TData, TError>
|
|
1163
1219
|
| InfiniteQueryObserverPlaceholderResult<TData, TError>
|
|
1164
1220
|
|
|
1221
|
+
/**
|
|
1222
|
+
* The type of a mutation key — the serializable array used to identify and filter mutations.
|
|
1223
|
+
* Defaults to `ReadonlyArray<unknown>`; declare `mutationKey` on {@link Register} to narrow it repository-wide.
|
|
1224
|
+
*/
|
|
1165
1225
|
export type MutationKey = Register extends {
|
|
1166
1226
|
mutationKey: infer TMutationKey
|
|
1167
1227
|
}
|
|
@@ -1172,12 +1232,22 @@ export type MutationKey = Register extends {
|
|
|
1172
1232
|
: ReadonlyArray<unknown>
|
|
1173
1233
|
: ReadonlyArray<unknown>
|
|
1174
1234
|
|
|
1235
|
+
/** @inline */
|
|
1175
1236
|
export type MutationStatus = 'idle' | 'pending' | 'success' | 'error'
|
|
1176
1237
|
|
|
1238
|
+
/**
|
|
1239
|
+
* Groups mutations so they run one after another instead of in parallel.
|
|
1240
|
+
* Mutations that share the same `id` form a queue: while one is running, the others wait in `isPaused: true`
|
|
1241
|
+
* state and resume automatically when their turn comes. Mutations with no scope always run in parallel.
|
|
1242
|
+
*/
|
|
1177
1243
|
export type MutationScope = {
|
|
1178
1244
|
id: string
|
|
1179
1245
|
}
|
|
1180
1246
|
|
|
1247
|
+
/**
|
|
1248
|
+
* The type of the `meta` object that can be attached to a mutation and read back from `mutationFn`, callbacks and
|
|
1249
|
+
* cache-level handlers. Defaults to `Record<string, unknown>`; declare `mutationMeta` on {@link Register} to narrow it.
|
|
1250
|
+
*/
|
|
1181
1251
|
export type MutationMeta = Register extends {
|
|
1182
1252
|
mutationMeta: infer TMutationMeta
|
|
1183
1253
|
}
|
|
@@ -1192,6 +1262,7 @@ export type MutationFunctionContext = {
|
|
|
1192
1262
|
mutationKey?: MutationKey
|
|
1193
1263
|
}
|
|
1194
1264
|
|
|
1265
|
+
/** @inline */
|
|
1195
1266
|
export type MutationFunction<TData = unknown, TVariables = unknown> = (
|
|
1196
1267
|
variables: TVariables,
|
|
1197
1268
|
context: MutationFunctionContext,
|
|
@@ -1203,24 +1274,57 @@ export interface MutationOptions<
|
|
|
1203
1274
|
TVariables = void,
|
|
1204
1275
|
TOnMutateResult = unknown,
|
|
1205
1276
|
> {
|
|
1277
|
+
/**
|
|
1278
|
+
* The function that performs the asynchronous task this mutation runs.
|
|
1279
|
+
* Required, unless a default mutation function has been set for the matching `mutationKey` via
|
|
1280
|
+
* `queryClient.setMutationDefaults`.
|
|
1281
|
+
* Receives the `variables` passed to `mutate`, and a {@link MutationFunctionContext} holding the
|
|
1282
|
+
* `QueryClient`, the `mutationKey` and `meta`.
|
|
1283
|
+
* Must return a promise that resolves the mutation's data.
|
|
1284
|
+
*/
|
|
1206
1285
|
mutationFn?: MutationFunction<TData, TVariables>
|
|
1286
|
+
/**
|
|
1287
|
+
* The key to use for this mutation. Optional, but required to inherit defaults registered with
|
|
1288
|
+
* `queryClient.setMutationDefaults`, and to match this mutation with `useMutationState` or
|
|
1289
|
+
* `queryClient.isMutating`.
|
|
1290
|
+
*/
|
|
1207
1291
|
mutationKey?: MutationKey
|
|
1292
|
+
/**
|
|
1293
|
+
* This function fires before the mutation function runs, and receives the same variables.
|
|
1294
|
+
* Useful for optimistic updates applied in the hope that the mutation succeeds.
|
|
1295
|
+
* The value it returns is passed to `onSuccess`, `onError` and `onSettled` as `onMutateResult`,
|
|
1296
|
+
* which is where an optimistic update is usually rolled back.
|
|
1297
|
+
* If a promise is returned, it is awaited before the mutation function runs.
|
|
1298
|
+
*/
|
|
1208
1299
|
onMutate?: (
|
|
1209
1300
|
variables: TVariables,
|
|
1210
1301
|
context: MutationFunctionContext,
|
|
1211
1302
|
) => Promise<TOnMutateResult> | TOnMutateResult
|
|
1303
|
+
/**
|
|
1304
|
+
* This function fires when the mutation succeeds, and is passed the mutation's result.
|
|
1305
|
+
* If a promise is returned, it is awaited before `onSettled` runs.
|
|
1306
|
+
*/
|
|
1212
1307
|
onSuccess?: (
|
|
1213
1308
|
data: TData,
|
|
1214
1309
|
variables: TVariables,
|
|
1215
1310
|
onMutateResult: TOnMutateResult,
|
|
1216
1311
|
context: MutationFunctionContext,
|
|
1217
1312
|
) => Promise<unknown> | unknown
|
|
1313
|
+
/**
|
|
1314
|
+
* This function fires when the mutation encounters an error, and is passed the error.
|
|
1315
|
+
* If a promise is returned, it is awaited before `onSettled` runs.
|
|
1316
|
+
*/
|
|
1218
1317
|
onError?: (
|
|
1219
1318
|
error: TError,
|
|
1220
1319
|
variables: TVariables,
|
|
1221
1320
|
onMutateResult: TOnMutateResult | undefined,
|
|
1222
1321
|
context: MutationFunctionContext,
|
|
1223
1322
|
) => Promise<unknown> | unknown
|
|
1323
|
+
/**
|
|
1324
|
+
* This function fires when the mutation either succeeds or errors, and is passed either the data
|
|
1325
|
+
* or the error.
|
|
1326
|
+
* If a promise is returned, it is awaited before the mutation settles.
|
|
1327
|
+
*/
|
|
1224
1328
|
onSettled?: (
|
|
1225
1329
|
data: TData | undefined,
|
|
1226
1330
|
error: TError | null,
|
|
@@ -1234,7 +1338,7 @@ export interface MutationOptions<
|
|
|
1234
1338
|
* If set to an integer number, e.g. 3, failed mutations will retry until the failed mutation count meets that number.
|
|
1235
1339
|
* If set to a function `(failureCount, error) => boolean` failed mutations will retry until the function returns false.
|
|
1236
1340
|
*
|
|
1237
|
-
*
|
|
1341
|
+
* @defaultValue 0
|
|
1238
1342
|
*/
|
|
1239
1343
|
retry?: RetryValue<TError>
|
|
1240
1344
|
/**
|
|
@@ -1247,7 +1351,7 @@ export interface MutationOptions<
|
|
|
1247
1351
|
/**
|
|
1248
1352
|
* Controls whether a mutation is allowed to run based on the current network connectivity.
|
|
1249
1353
|
*
|
|
1250
|
-
*
|
|
1354
|
+
* @defaultValue 'online'
|
|
1251
1355
|
* @see [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
|
|
1252
1356
|
*/
|
|
1253
1357
|
networkMode?: NetworkMode
|
|
@@ -1260,7 +1364,17 @@ export interface MutationOptions<
|
|
|
1260
1364
|
gcTime?: number
|
|
1261
1365
|
/** @internal */
|
|
1262
1366
|
_defaulted?: boolean
|
|
1367
|
+
/**
|
|
1368
|
+
* Additional payload to be stored on the mutation cache entry.
|
|
1369
|
+
* Use it to pass information that can be read wherever the `mutation` is available, such as the
|
|
1370
|
+
* `onError` and `onSuccess` callbacks of the `MutationCache`.
|
|
1371
|
+
*/
|
|
1263
1372
|
meta?: MutationMeta
|
|
1373
|
+
/**
|
|
1374
|
+
* Controls whether this mutation runs alongside others or waits its turn.
|
|
1375
|
+
* Mutations sharing the same `scope.id` run serially, in the order they were started.
|
|
1376
|
+
* Without a scope, a mutation runs as soon as it is triggered.
|
|
1377
|
+
*/
|
|
1264
1378
|
scope?: MutationScope
|
|
1265
1379
|
}
|
|
1266
1380
|
|
|
@@ -1276,7 +1390,7 @@ export interface MutationObserverOptions<
|
|
|
1276
1390
|
* If set to a function, it will be passed the error and should return a boolean indicating whether to throw the
|
|
1277
1391
|
* error (`true`) or return it as state (`false`).
|
|
1278
1392
|
*
|
|
1279
|
-
*
|
|
1393
|
+
* @defaultValue false
|
|
1280
1394
|
*/
|
|
1281
1395
|
throwOnError?: boolean | ((error: TError) => boolean)
|
|
1282
1396
|
}
|
|
@@ -1518,15 +1632,25 @@ export interface DefaultOptions<TError = DefaultError> {
|
|
|
1518
1632
|
dehydrate?: DehydrateOptions
|
|
1519
1633
|
}
|
|
1520
1634
|
|
|
1635
|
+
/**
|
|
1636
|
+
* Options for cancelling an in-flight fetch, e.g. via `query.cancel()`.
|
|
1637
|
+
* They are carried on the {@link CancelledError} that the cancelled fetch rejects with.
|
|
1638
|
+
*/
|
|
1521
1639
|
export interface CancelOptions {
|
|
1522
1640
|
revert?: boolean
|
|
1523
1641
|
silent?: boolean
|
|
1524
1642
|
}
|
|
1525
1643
|
|
|
1644
|
+
/**
|
|
1645
|
+
* Options for writing data into the cache, e.g. via `queryClient.setQueryData()`.
|
|
1646
|
+
* `updatedAt` overrides the timestamp the data is recorded with, which is what staleness is measured from;
|
|
1647
|
+
* omit it to use the current time.
|
|
1648
|
+
*/
|
|
1526
1649
|
export interface SetDataOptions {
|
|
1527
1650
|
updatedAt?: number
|
|
1528
1651
|
}
|
|
1529
1652
|
|
|
1653
|
+
/** @inline */
|
|
1530
1654
|
export type NotifyEventType =
|
|
1531
1655
|
| 'added'
|
|
1532
1656
|
| 'removed'
|
package/src/utils.ts
CHANGED