@tanstack/query-core 5.103.1 → 5.103.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.
Files changed (102) hide show
  1. package/build/legacy/{hydration-Cq7QYAzB.d.ts → hydration-Bp57N3SP.d.ts} +157 -22
  2. package/build/{modern/hydration-Cq7QYAzB.d.ts.map → legacy/hydration-Bp57N3SP.d.ts.map} +1 -1
  3. package/build/legacy/{hydration-DwR10Hi-.d.cts → hydration-DRcloXEn.d.cts} +157 -22
  4. package/build/{modern/hydration-DwR10Hi-.d.cts.map → legacy/hydration-DRcloXEn.d.cts.map} +1 -1
  5. package/build/legacy/hydration.cjs.map +1 -1
  6. package/build/legacy/hydration.d.cts +1 -1
  7. package/build/legacy/hydration.d.ts +1 -1
  8. package/build/legacy/hydration.js.map +1 -1
  9. package/build/legacy/index.d.cts +1 -1
  10. package/build/legacy/index.d.ts +1 -1
  11. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  12. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  13. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  14. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  15. package/build/legacy/mutation.d.cts +1 -1
  16. package/build/legacy/mutation.d.ts +1 -1
  17. package/build/legacy/mutationCache.d.cts +1 -1
  18. package/build/legacy/mutationCache.d.ts +1 -1
  19. package/build/legacy/mutationObserver.d.cts +1 -1
  20. package/build/legacy/mutationObserver.d.ts +1 -1
  21. package/build/legacy/queriesObserver.d.cts +1 -1
  22. package/build/legacy/queriesObserver.d.ts +1 -1
  23. package/build/legacy/query.d.cts +1 -1
  24. package/build/legacy/query.d.ts +1 -1
  25. package/build/legacy/queryCache.cjs +2 -3
  26. package/build/legacy/queryCache.cjs.map +1 -1
  27. package/build/legacy/queryCache.d.cts +1 -1
  28. package/build/legacy/queryCache.d.ts +1 -1
  29. package/build/legacy/queryCache.js +2 -3
  30. package/build/legacy/queryCache.js.map +1 -1
  31. package/build/legacy/queryClient.d.cts +1 -1
  32. package/build/legacy/queryClient.d.ts +1 -1
  33. package/build/legacy/queryObserver.d.cts +1 -1
  34. package/build/legacy/queryObserver.d.ts +1 -1
  35. package/build/legacy/retryer.cjs.map +1 -1
  36. package/build/legacy/retryer.d.cts +1 -1
  37. package/build/legacy/retryer.d.ts +1 -1
  38. package/build/legacy/retryer.js.map +1 -1
  39. package/build/legacy/streamedQuery.d.cts +1 -1
  40. package/build/legacy/streamedQuery.d.ts +1 -1
  41. package/build/legacy/types.cjs.map +1 -1
  42. package/build/legacy/types.d.cts +1 -1
  43. package/build/legacy/types.d.ts +1 -1
  44. package/build/legacy/types.js.map +1 -1
  45. package/build/legacy/utils.cjs.map +1 -1
  46. package/build/legacy/utils.d.cts +1 -1
  47. package/build/legacy/utils.d.ts +1 -1
  48. package/build/legacy/utils.js.map +1 -1
  49. package/build/modern/{hydration-Cq7QYAzB.d.ts → hydration-Bp57N3SP.d.ts} +157 -22
  50. package/build/{legacy/hydration-Cq7QYAzB.d.ts.map → modern/hydration-Bp57N3SP.d.ts.map} +1 -1
  51. package/build/modern/{hydration-DwR10Hi-.d.cts → hydration-DRcloXEn.d.cts} +157 -22
  52. package/build/{legacy/hydration-DwR10Hi-.d.cts.map → modern/hydration-DRcloXEn.d.cts.map} +1 -1
  53. package/build/modern/hydration.cjs.map +1 -1
  54. package/build/modern/hydration.d.cts +1 -1
  55. package/build/modern/hydration.d.ts +1 -1
  56. package/build/modern/hydration.js.map +1 -1
  57. package/build/modern/index.d.cts +1 -1
  58. package/build/modern/index.d.ts +1 -1
  59. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  60. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  61. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  62. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  63. package/build/modern/mutation.d.cts +1 -1
  64. package/build/modern/mutation.d.ts +1 -1
  65. package/build/modern/mutationCache.d.cts +1 -1
  66. package/build/modern/mutationCache.d.ts +1 -1
  67. package/build/modern/mutationObserver.d.cts +1 -1
  68. package/build/modern/mutationObserver.d.ts +1 -1
  69. package/build/modern/queriesObserver.d.cts +1 -1
  70. package/build/modern/queriesObserver.d.ts +1 -1
  71. package/build/modern/query.d.cts +1 -1
  72. package/build/modern/query.d.ts +1 -1
  73. package/build/modern/queryCache.cjs +2 -3
  74. package/build/modern/queryCache.cjs.map +1 -1
  75. package/build/modern/queryCache.d.cts +1 -1
  76. package/build/modern/queryCache.d.ts +1 -1
  77. package/build/modern/queryCache.js +2 -3
  78. package/build/modern/queryCache.js.map +1 -1
  79. package/build/modern/queryClient.d.cts +1 -1
  80. package/build/modern/queryClient.d.ts +1 -1
  81. package/build/modern/queryObserver.d.cts +1 -1
  82. package/build/modern/queryObserver.d.ts +1 -1
  83. package/build/modern/retryer.cjs.map +1 -1
  84. package/build/modern/retryer.d.cts +1 -1
  85. package/build/modern/retryer.d.ts +1 -1
  86. package/build/modern/retryer.js.map +1 -1
  87. package/build/modern/streamedQuery.d.cts +1 -1
  88. package/build/modern/streamedQuery.d.ts +1 -1
  89. package/build/modern/types.cjs.map +1 -1
  90. package/build/modern/types.d.cts +1 -1
  91. package/build/modern/types.d.ts +1 -1
  92. package/build/modern/types.js.map +1 -1
  93. package/build/modern/utils.cjs.map +1 -1
  94. package/build/modern/utils.d.cts +1 -1
  95. package/build/modern/utils.d.ts +1 -1
  96. package/build/modern/utils.js.map +1 -1
  97. package/package.json +1 -1
  98. package/src/hydration.ts +1 -0
  99. package/src/queryCache.ts +2 -6
  100. package/src/retryer.ts +4 -0
  101. package/src/types.ts +150 -20
  102. package/src/utils.ts +1 -1
package/src/types.ts CHANGED
@@ -34,6 +34,25 @@ export type Override<TTargetA, TTargetB> = {
34
34
  : TTargetA[AKey]
35
35
  }
36
36
 
37
+ /**
38
+ * The interface to augment via declaration merging to override Query's default types repository-wide.
39
+ * Each field it declares replaces the default of the matching type: `defaultError` for {@link DefaultError},
40
+ * `queryKey` for {@link QueryKey}, `mutationKey` for {@link MutationKey}, `queryMeta` for {@link QueryMeta} and
41
+ * `mutationMeta` for {@link MutationMeta}. Leave a field out to keep that type's default.
42
+ * Augment the module you install — `@tanstack/react-query`, `@tanstack/vue-query`,
43
+ * `@tanstack/solid-query`, `@tanstack/svelte-query`, `@tanstack/preact-query`,
44
+ * `@tanstack/angular-query-experimental` or `@tanstack/lit-query`. Augmenting `@tanstack/query-core`
45
+ * works too and covers every adapter at once.
46
+ * @example
47
+ * ```ts
48
+ * // Use the module you installed — here, the React adapter.
49
+ * declare module '@tanstack/react-query' {
50
+ * interface Register {
51
+ * defaultError: AxiosError
52
+ * }
53
+ * }
54
+ * ```
55
+ */
37
56
  export interface Register {
38
57
  // defaultError: Error
39
58
  // queryMeta: Record<string, unknown>
@@ -42,12 +61,20 @@ export interface Register {
42
61
  // mutationKey: ReadonlyArray<unknown>
43
62
  }
44
63
 
64
+ /**
65
+ * The error type used wherever an error is not given an explicit type parameter.
66
+ * Defaults to `Error`; declare `defaultError` on {@link Register} to change it everywhere at once.
67
+ */
45
68
  export type DefaultError = Register extends {
46
69
  defaultError: infer TError
47
70
  }
48
71
  ? TError
49
72
  : Error
50
73
 
74
+ /**
75
+ * The type of a query key — the serializable array that identifies a query in the cache.
76
+ * Defaults to `ReadonlyArray<unknown>`; declare `queryKey` on {@link Register} to narrow it repository-wide.
77
+ */
51
78
  export type QueryKey = Register extends {
52
79
  queryKey: infer TQueryKey
53
80
  }
@@ -99,14 +126,17 @@ export type InferErrorFromTag<TError, TTaggedQueryKey extends QueryKey> =
99
126
  : TaggedError
100
127
  : TError
101
128
 
129
+ /** @inline */
102
130
  export type QueryFunction<
103
131
  T = unknown,
104
132
  TQueryKey extends QueryKey = QueryKey,
105
133
  TPageParam = never,
106
134
  > = (context: QueryFunctionContext<TQueryKey, TPageParam>) => T | Promise<T>
107
135
 
136
+ /** @inline */
108
137
  export type StaleTime = number | 'static'
109
138
 
139
+ /** @inline */
110
140
  export type StaleTimeFunction<
111
141
  TQueryFnData = unknown,
112
142
  TError = DefaultError,
@@ -116,6 +146,7 @@ export type StaleTimeFunction<
116
146
  | StaleTime
117
147
  | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => StaleTime)
118
148
 
149
+ /** @inline */
119
150
  export type QueryBooleanOption<
120
151
  TQueryFnData = unknown,
121
152
  TError = DefaultError,
@@ -125,6 +156,7 @@ export type QueryBooleanOption<
125
156
  | boolean
126
157
  | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => boolean)
127
158
 
159
+ /** @inline */
128
160
  export type QueryPersister<
129
161
  T = unknown,
130
162
  TQueryKey extends QueryKey = QueryKey,
@@ -170,10 +202,12 @@ export type QueryFunctionContext<
170
202
  meta: QueryMeta | undefined
171
203
  }
172
204
 
205
+ /** @inline */
173
206
  export type InitialDataFunction<T> = () => T | undefined
174
207
 
175
208
  type NonFunctionGuard<T> = T extends Function ? never : T
176
209
 
210
+ /** @inline */
177
211
  export type PlaceholderDataFunction<
178
212
  TQueryFnData = unknown,
179
213
  TError = DefaultError,
@@ -189,10 +223,12 @@ export type QueriesPlaceholderDataFunction<TQueryData> = (
189
223
  previousQuery: undefined,
190
224
  ) => TQueryData | undefined
191
225
 
226
+ /** @inline */
192
227
  export type QueryKeyHashFunction<TQueryKey extends QueryKey> = (
193
228
  queryKey: TQueryKey,
194
229
  ) => string
195
230
 
231
+ /** @inline */
196
232
  export type GetPreviousPageParamFunction<TPageParam, TQueryFnData = unknown> = (
197
233
  firstPage: TQueryFnData,
198
234
  allPages: Array<TQueryFnData>,
@@ -200,6 +236,7 @@ export type GetPreviousPageParamFunction<TPageParam, TQueryFnData = unknown> = (
200
236
  allPageParams: Array<TPageParam>,
201
237
  ) => TPageParam | undefined | null
202
238
 
239
+ /** @inline */
203
240
  export type GetNextPageParamFunction<TPageParam, TQueryFnData = unknown> = (
204
241
  lastPage: TQueryFnData,
205
242
  allPages: Array<TQueryFnData>,
@@ -207,11 +244,19 @@ export type GetNextPageParamFunction<TPageParam, TQueryFnData = unknown> = (
207
244
  allPageParams: Array<TPageParam>,
208
245
  ) => TPageParam | undefined | null
209
246
 
247
+ /**
248
+ * The data shape of an infinite query: every page fetched so far, plus the page param each one was fetched with.
249
+ * `pages` and `pageParams` are index-aligned — `pageParams[i]` is the param that produced `pages[i]`.
250
+ */
210
251
  export interface InfiniteData<TData, TPageParam = unknown> {
211
252
  pages: Array<TData>
212
253
  pageParams: Array<TPageParam>
213
254
  }
214
255
 
256
+ /**
257
+ * The type of the `meta` object that can be attached to a query and read back from `queryFn`, callbacks and
258
+ * cache-level handlers. Defaults to `Record<string, unknown>`; declare `queryMeta` on {@link Register} to narrow it.
259
+ */
215
260
  export type QueryMeta = Register extends {
216
261
  queryMeta: infer TQueryMeta
217
262
  }
@@ -220,8 +265,10 @@ export type QueryMeta = Register extends {
220
265
  : Record<string, unknown>
221
266
  : Record<string, unknown>
222
267
 
268
+ /** @inline */
223
269
  export type NetworkMode = 'online' | 'always' | 'offlineFirst'
224
270
 
271
+ /** @inline */
225
272
  export type NotifyOnChangeProps =
226
273
  | Array<keyof InfiniteQueryObserverResult>
227
274
  | 'all'
@@ -259,7 +306,7 @@ export interface QueryOptions<
259
306
  /**
260
307
  * Controls whether a query is allowed to run based on the current network connectivity.
261
308
  *
262
- * Defaults to `'online'`.
309
+ * @defaultValue 'online'
263
310
  * @see [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
264
311
  */
265
312
  networkMode?: NetworkMode
@@ -325,7 +372,7 @@ export interface QueryOptions<
325
372
  * Set this to `false` to disable structural sharing between query results.
326
373
  * 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
374
  *
328
- * Defaults to `true`.
375
+ * @defaultValue true
329
376
  */
330
377
  structuralSharing?:
331
378
  | boolean
@@ -346,6 +393,13 @@ export interface QueryOptions<
346
393
  }
347
394
 
348
395
  export interface InitialPageParam<TPageParam = unknown> {
396
+ /**
397
+ * The page param to start from when an infinite query has no pages yet.
398
+ * It is passed to `queryFn` as `pageParam` for the first page; every page after that gets the
399
+ * value returned by `getNextPageParam` or `getPreviousPageParam`.
400
+ * It only applies while the query has no pages: once a first page exists, refetching starts from
401
+ * that page's own param instead.
402
+ */
349
403
  initialPageParam: TPageParam
350
404
  }
351
405
 
@@ -365,6 +419,7 @@ export interface InfiniteQueryPageParamsOptions<
365
419
  getNextPageParam: GetNextPageParamFunction<TPageParam, TQueryFnData>
366
420
  }
367
421
 
422
+ /** @inline */
368
423
  export type ThrowOnError<
369
424
  TQueryFnData,
370
425
  TError,
@@ -393,7 +448,7 @@ export interface QueryObserverOptions<
393
448
  * To refetch the query, use the `refetch` method returned from the `useQuery` instance.
394
449
  * Accepts a boolean or function that returns a boolean.
395
450
  *
396
- * Defaults to `true`.
451
+ * @defaultValue true
397
452
  */
398
453
  enabled?: QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>
399
454
  /**
@@ -402,14 +457,14 @@ export interface QueryObserverOptions<
402
457
  * If set to `'static'`, the data will never be considered stale.
403
458
  * If set to a function, the function will be executed with the query to compute a `staleTime`.
404
459
  *
405
- * Defaults to `0`.
460
+ * @defaultValue 0
406
461
  */
407
462
  staleTime?: StaleTimeFunction<TQueryFnData, TError, TQueryData, TQueryKey>
408
463
  /**
409
464
  * If set to a number, the query will continuously refetch at this frequency in milliseconds.
410
465
  * If set to a function, the function will be executed with the latest data and query to compute a frequency
411
466
  *
412
- * Defaults to `false`.
467
+ * @defaultValue false
413
468
  */
414
469
  refetchInterval?:
415
470
  | number
@@ -420,7 +475,7 @@ export interface QueryObserverOptions<
420
475
  /**
421
476
  * If set to `true`, the query will continue to refetch while their tab/window is in the background.
422
477
  *
423
- * Defaults to `false`.
478
+ * @defaultValue false
424
479
  */
425
480
  refetchIntervalInBackground?: boolean
426
481
  /**
@@ -429,7 +484,7 @@ export interface QueryObserverOptions<
429
484
  * If set to `'always'`, the query will always refetch on window focus (except when `staleTime: 'static'` is used).
430
485
  * If set to a function, the function will be executed with the latest data and query to compute the value.
431
486
  *
432
- * Defaults to `true`.
487
+ * @defaultValue true
433
488
  */
434
489
  refetchOnWindowFocus?:
435
490
  | boolean
@@ -457,7 +512,7 @@ export interface QueryObserverOptions<
457
512
  * If set to `'always'`, the query will always refetch on mount (except when `staleTime: 'static'` is used).
458
513
  * If set to a function, the function will be executed with the latest data and query to compute the value
459
514
  *
460
- * Defaults to `true`.
515
+ * @defaultValue true
461
516
  */
462
517
  refetchOnMount?:
463
518
  | boolean
@@ -469,7 +524,7 @@ export interface QueryObserverOptions<
469
524
  * If set to `false`, the query will not be retried on mount if it contains an error.
470
525
  * If set to a function, the function will be executed with the query to compute the value.
471
526
  *
472
- * Defaults to `true`.
527
+ * @defaultValue true
473
528
  */
474
529
  retryOnMount?: QueryBooleanOption<TQueryFnData, TError, TQueryData, TQueryKey>
475
530
  /**
@@ -488,7 +543,7 @@ export interface QueryObserverOptions<
488
543
  * If set to `false` and `suspense` is `false`, errors are returned as state.
489
544
  * 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
545
  *
491
- * Defaults to `false`.
546
+ * @defaultValue false
492
547
  */
493
548
  throwOnError?: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>
494
549
  /**
@@ -502,7 +557,7 @@ export interface QueryObserverOptions<
502
557
  * If set to `true`, the query will suspend when `status === 'pending'`
503
558
  * and throw errors when `status === 'error'`.
504
559
  *
505
- * Defaults to `false`.
560
+ * @defaultValue false
506
561
  */
507
562
  suspense?: boolean
508
563
  /**
@@ -583,6 +638,10 @@ export interface QueryExecuteOptions<
583
638
  'queryKey'
584
639
  > {
585
640
  initialPageParam?: never
641
+ /**
642
+ * This option can be used to transform or select a part of the data returned by the query function. It affects
643
+ * the value this call resolves with, but does not affect what gets stored in the query cache.
644
+ */
586
645
  select?: (data: TQueryData) => TData
587
646
  /**
588
647
  * The time in milliseconds after data is considered stale.
@@ -694,9 +753,9 @@ export type FetchInfiniteQueryOptions<
694
753
  export interface ResultOptions {
695
754
  /**
696
755
  * If set to `true`, the method throws if any of the underlying query refetch tasks fail.
756
+ * If set to `false`, failed refetches are swallowed and not surfaced to the caller.
697
757
  *
698
- * Defaults to `false`, in which case failed refetches are swallowed and not surfaced to the
699
- * caller.
758
+ * @defaultValue false
700
759
  */
701
760
  throwOnError?: boolean
702
761
  }
@@ -707,7 +766,7 @@ export interface RefetchOptions extends ResultOptions {
707
766
  *
708
767
  * If set to `false`, no refetch will be made if there is already a request running.
709
768
  *
710
- * Defaults to `true`.
769
+ * @defaultValue true
711
770
  */
712
771
  cancelRefetch?: boolean
713
772
  }
@@ -718,11 +777,12 @@ export interface InvalidateQueryFilters<
718
777
  /**
719
778
  * Controls which of the matched (now-invalidated) queries are refetched in the background.
720
779
  *
721
- * Defaults to `'active'`.
722
780
  * - `'active'`: only queries with at least one active observer are refetched.
723
781
  * - `'inactive'`: only queries with no active observer are refetched.
724
782
  * - `'all'`: every matched query is refetched, active or not.
725
783
  * - `'none'`: no query is refetched; matched queries are only marked as invalidated.
784
+ *
785
+ * @defaultValue 'active'
726
786
  */
727
787
  refetchType?: QueryTypeFilter | 'none'
728
788
  }
@@ -741,7 +801,7 @@ export interface FetchNextPageOptions extends ResultOptions {
741
801
  *
742
802
  * If set to `false`, calling `fetchNextPage` repeatedly won't have any effect until the first invocation has resolved.
743
803
  *
744
- * Defaults to `true`.
804
+ * @defaultValue true
745
805
  */
746
806
  cancelRefetch?: boolean
747
807
  }
@@ -753,12 +813,14 @@ export interface FetchPreviousPageOptions extends ResultOptions {
753
813
  *
754
814
  * If set to `false`, calling `fetchPreviousPage` repeatedly won't have any effect until the first invocation has resolved.
755
815
  *
756
- * Defaults to `true`.
816
+ * @defaultValue true
757
817
  */
758
818
  cancelRefetch?: boolean
759
819
  }
760
820
 
821
+ /** @inline */
761
822
  export type QueryStatus = 'pending' | 'error' | 'success'
823
+ /** @inline */
762
824
  export type FetchStatus = 'fetching' | 'paused' | 'idle'
763
825
 
764
826
  export interface QueryObserverBaseResult<
@@ -1162,6 +1224,10 @@ export type InfiniteQueryObserverResult<
1162
1224
  | InfiniteQueryObserverPendingResult<TData, TError>
1163
1225
  | InfiniteQueryObserverPlaceholderResult<TData, TError>
1164
1226
 
1227
+ /**
1228
+ * The type of a mutation key — the serializable array used to identify and filter mutations.
1229
+ * Defaults to `ReadonlyArray<unknown>`; declare `mutationKey` on {@link Register} to narrow it repository-wide.
1230
+ */
1165
1231
  export type MutationKey = Register extends {
1166
1232
  mutationKey: infer TMutationKey
1167
1233
  }
@@ -1172,12 +1238,22 @@ export type MutationKey = Register extends {
1172
1238
  : ReadonlyArray<unknown>
1173
1239
  : ReadonlyArray<unknown>
1174
1240
 
1241
+ /** @inline */
1175
1242
  export type MutationStatus = 'idle' | 'pending' | 'success' | 'error'
1176
1243
 
1244
+ /**
1245
+ * Groups mutations so they run one after another instead of in parallel.
1246
+ * Mutations that share the same `id` form a queue: while one is running, the others wait in `isPaused: true`
1247
+ * state and resume automatically when their turn comes. Mutations with no scope always run in parallel.
1248
+ */
1177
1249
  export type MutationScope = {
1178
1250
  id: string
1179
1251
  }
1180
1252
 
1253
+ /**
1254
+ * The type of the `meta` object that can be attached to a mutation and read back from `mutationFn`, callbacks and
1255
+ * cache-level handlers. Defaults to `Record<string, unknown>`; declare `mutationMeta` on {@link Register} to narrow it.
1256
+ */
1181
1257
  export type MutationMeta = Register extends {
1182
1258
  mutationMeta: infer TMutationMeta
1183
1259
  }
@@ -1192,6 +1268,7 @@ export type MutationFunctionContext = {
1192
1268
  mutationKey?: MutationKey
1193
1269
  }
1194
1270
 
1271
+ /** @inline */
1195
1272
  export type MutationFunction<TData = unknown, TVariables = unknown> = (
1196
1273
  variables: TVariables,
1197
1274
  context: MutationFunctionContext,
@@ -1203,24 +1280,57 @@ export interface MutationOptions<
1203
1280
  TVariables = void,
1204
1281
  TOnMutateResult = unknown,
1205
1282
  > {
1283
+ /**
1284
+ * The function that performs the asynchronous task this mutation runs.
1285
+ * Required, unless a default mutation function has been set for the matching `mutationKey` via
1286
+ * `queryClient.setMutationDefaults`.
1287
+ * Receives the `variables` passed to `mutate`, and a {@link MutationFunctionContext} holding the
1288
+ * `QueryClient`, the `mutationKey` and `meta`.
1289
+ * Must return a promise that resolves the mutation's data.
1290
+ */
1206
1291
  mutationFn?: MutationFunction<TData, TVariables>
1292
+ /**
1293
+ * The key to use for this mutation. Optional, but required to inherit defaults registered with
1294
+ * `queryClient.setMutationDefaults`, and to match this mutation with `useMutationState` or
1295
+ * `queryClient.isMutating`.
1296
+ */
1207
1297
  mutationKey?: MutationKey
1298
+ /**
1299
+ * This function fires before the mutation function runs, and receives the same variables.
1300
+ * Useful for optimistic updates applied in the hope that the mutation succeeds.
1301
+ * The value it returns is passed to `onSuccess`, `onError` and `onSettled` as `onMutateResult`,
1302
+ * which is where an optimistic update is usually rolled back.
1303
+ * If a promise is returned, it is awaited before the mutation function runs.
1304
+ */
1208
1305
  onMutate?: (
1209
1306
  variables: TVariables,
1210
1307
  context: MutationFunctionContext,
1211
1308
  ) => Promise<TOnMutateResult> | TOnMutateResult
1309
+ /**
1310
+ * This function fires when the mutation succeeds, and is passed the mutation's result.
1311
+ * If a promise is returned, it is awaited before `onSettled` runs.
1312
+ */
1212
1313
  onSuccess?: (
1213
1314
  data: TData,
1214
1315
  variables: TVariables,
1215
1316
  onMutateResult: TOnMutateResult,
1216
1317
  context: MutationFunctionContext,
1217
1318
  ) => Promise<unknown> | unknown
1319
+ /**
1320
+ * This function fires when the mutation encounters an error, and is passed the error.
1321
+ * If a promise is returned, it is awaited before `onSettled` runs.
1322
+ */
1218
1323
  onError?: (
1219
1324
  error: TError,
1220
1325
  variables: TVariables,
1221
1326
  onMutateResult: TOnMutateResult | undefined,
1222
1327
  context: MutationFunctionContext,
1223
1328
  ) => Promise<unknown> | unknown
1329
+ /**
1330
+ * This function fires when the mutation either succeeds or errors, and is passed either the data
1331
+ * or the error.
1332
+ * If a promise is returned, it is awaited before the mutation settles.
1333
+ */
1224
1334
  onSettled?: (
1225
1335
  data: TData | undefined,
1226
1336
  error: TError | null,
@@ -1234,7 +1344,7 @@ export interface MutationOptions<
1234
1344
  * If set to an integer number, e.g. 3, failed mutations will retry until the failed mutation count meets that number.
1235
1345
  * If set to a function `(failureCount, error) => boolean` failed mutations will retry until the function returns false.
1236
1346
  *
1237
- * Defaults to `0`.
1347
+ * @defaultValue 0
1238
1348
  */
1239
1349
  retry?: RetryValue<TError>
1240
1350
  /**
@@ -1247,7 +1357,7 @@ export interface MutationOptions<
1247
1357
  /**
1248
1358
  * Controls whether a mutation is allowed to run based on the current network connectivity.
1249
1359
  *
1250
- * Defaults to `'online'`.
1360
+ * @defaultValue 'online'
1251
1361
  * @see [Network Mode](https://tanstack.com/query/latest/docs/framework/react/guides/network-mode) for more information.
1252
1362
  */
1253
1363
  networkMode?: NetworkMode
@@ -1260,7 +1370,17 @@ export interface MutationOptions<
1260
1370
  gcTime?: number
1261
1371
  /** @internal */
1262
1372
  _defaulted?: boolean
1373
+ /**
1374
+ * Additional payload to be stored on the mutation cache entry.
1375
+ * Use it to pass information that can be read wherever the `mutation` is available, such as the
1376
+ * `onError` and `onSuccess` callbacks of the `MutationCache`.
1377
+ */
1263
1378
  meta?: MutationMeta
1379
+ /**
1380
+ * Controls whether this mutation runs alongside others or waits its turn.
1381
+ * Mutations sharing the same `scope.id` run serially, in the order they were started.
1382
+ * Without a scope, a mutation runs as soon as it is triggered.
1383
+ */
1264
1384
  scope?: MutationScope
1265
1385
  }
1266
1386
 
@@ -1276,7 +1396,7 @@ export interface MutationObserverOptions<
1276
1396
  * If set to a function, it will be passed the error and should return a boolean indicating whether to throw the
1277
1397
  * error (`true`) or return it as state (`false`).
1278
1398
  *
1279
- * Defaults to `false`.
1399
+ * @defaultValue false
1280
1400
  */
1281
1401
  throwOnError?: boolean | ((error: TError) => boolean)
1282
1402
  }
@@ -1518,15 +1638,25 @@ export interface DefaultOptions<TError = DefaultError> {
1518
1638
  dehydrate?: DehydrateOptions
1519
1639
  }
1520
1640
 
1641
+ /**
1642
+ * Options for cancelling an in-flight fetch, e.g. via `query.cancel()`.
1643
+ * They are carried on the {@link CancelledError} that the cancelled fetch rejects with.
1644
+ */
1521
1645
  export interface CancelOptions {
1522
1646
  revert?: boolean
1523
1647
  silent?: boolean
1524
1648
  }
1525
1649
 
1650
+ /**
1651
+ * Options for writing data into the cache, e.g. via `queryClient.setQueryData()`.
1652
+ * `updatedAt` overrides the timestamp the data is recorded with, which is what staleness is measured from;
1653
+ * omit it to use the current time.
1654
+ */
1526
1655
  export interface SetDataOptions {
1527
1656
  updatedAt?: number
1528
1657
  }
1529
1658
 
1659
+ /** @inline */
1530
1660
  export type NotifyEventType =
1531
1661
  | 'added'
1532
1662
  | 'removed'
package/src/utils.ts CHANGED
@@ -32,7 +32,7 @@ export interface QueryFilters<TQueryKey extends QueryKey = QueryKey> {
32
32
  /**
33
33
  * Filter to active queries, inactive queries or all queries
34
34
  *
35
- * Defaults to `'all'`.
35
+ * @defaultValue 'all'
36
36
  */
37
37
  type?: QueryTypeFilter
38
38
  /**