@tanstack/query-core 5.55.3 → 5.56.0
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/{hydration-BOOcDeHq.d.cts → hydration-D6canbuP.d.cts} +7 -2
- package/build/legacy/{hydration-DTVzC0E7.d.ts → hydration-DgUcX5FN.d.ts} +7 -2
- package/build/legacy/hydration.d.cts +1 -1
- package/build/legacy/hydration.d.ts +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 +1 -1
- package/build/legacy/infiniteQueryObserver.d.ts +1 -1
- package/build/legacy/mutation.d.cts +1 -1
- package/build/legacy/mutation.d.ts +1 -1
- package/build/legacy/mutationCache.d.cts +1 -1
- package/build/legacy/mutationCache.d.ts +1 -1
- package/build/legacy/mutationObserver.d.cts +1 -1
- package/build/legacy/mutationObserver.d.ts +1 -1
- package/build/legacy/notifyManager.cjs +40 -34
- package/build/legacy/notifyManager.cjs.map +1 -1
- package/build/legacy/notifyManager.d.cts +22 -0
- package/build/legacy/notifyManager.d.ts +22 -0
- package/build/legacy/notifyManager.js +40 -34
- package/build/legacy/notifyManager.js.map +1 -1
- package/build/legacy/queriesObserver.d.cts +1 -1
- package/build/legacy/queriesObserver.d.ts +1 -1
- package/build/legacy/query.d.cts +1 -1
- package/build/legacy/query.d.ts +1 -1
- package/build/legacy/queryCache.d.cts +1 -1
- package/build/legacy/queryCache.d.ts +1 -1
- package/build/legacy/queryClient.cjs +4 -0
- 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 +4 -0
- package/build/legacy/queryClient.js.map +1 -1
- package/build/legacy/queryObserver.d.cts +1 -1
- package/build/legacy/queryObserver.d.ts +1 -1
- package/build/legacy/retryer.d.cts +1 -1
- package/build/legacy/retryer.d.ts +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/utils.d.cts +1 -1
- package/build/legacy/utils.d.ts +1 -1
- package/build/modern/{hydration-BOOcDeHq.d.cts → hydration-D6canbuP.d.cts} +7 -2
- package/build/modern/{hydration-DTVzC0E7.d.ts → hydration-DgUcX5FN.d.ts} +7 -2
- package/build/modern/hydration.d.cts +1 -1
- package/build/modern/hydration.d.ts +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 +1 -1
- package/build/modern/infiniteQueryObserver.d.ts +1 -1
- package/build/modern/mutation.d.cts +1 -1
- package/build/modern/mutation.d.ts +1 -1
- package/build/modern/mutationCache.d.cts +1 -1
- package/build/modern/mutationCache.d.ts +1 -1
- package/build/modern/mutationObserver.d.cts +1 -1
- package/build/modern/mutationObserver.d.ts +1 -1
- package/build/modern/notifyManager.cjs +40 -34
- package/build/modern/notifyManager.cjs.map +1 -1
- package/build/modern/notifyManager.d.cts +22 -0
- package/build/modern/notifyManager.d.ts +22 -0
- package/build/modern/notifyManager.js +40 -34
- package/build/modern/notifyManager.js.map +1 -1
- package/build/modern/queriesObserver.d.cts +1 -1
- package/build/modern/queriesObserver.d.ts +1 -1
- package/build/modern/query.d.cts +1 -1
- package/build/modern/query.d.ts +1 -1
- package/build/modern/queryCache.d.cts +1 -1
- package/build/modern/queryCache.d.ts +1 -1
- package/build/modern/queryClient.cjs +4 -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 +4 -0
- package/build/modern/queryClient.js.map +1 -1
- package/build/modern/queryObserver.d.cts +1 -1
- package/build/modern/queryObserver.d.ts +1 -1
- package/build/modern/retryer.d.cts +1 -1
- package/build/modern/retryer.d.ts +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/utils.d.cts +1 -1
- package/build/modern/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/queryClient.test.tsx +63 -0
- package/src/notifyManager.ts +42 -53
- package/src/queryClient.ts +28 -2
- package/src/types.ts +26 -6
package/src/notifyManager.ts
CHANGED
|
@@ -21,24 +21,6 @@ export function createNotifyManager() {
|
|
|
21
21
|
}
|
|
22
22
|
let scheduleFn: ScheduleFunction = (cb) => setTimeout(cb, 0)
|
|
23
23
|
|
|
24
|
-
const setScheduler = (fn: ScheduleFunction) => {
|
|
25
|
-
scheduleFn = fn
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const batch = <T>(callback: () => T): T => {
|
|
29
|
-
let result
|
|
30
|
-
transactions++
|
|
31
|
-
try {
|
|
32
|
-
result = callback()
|
|
33
|
-
} finally {
|
|
34
|
-
transactions--
|
|
35
|
-
if (!transactions) {
|
|
36
|
-
flush()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return result
|
|
40
|
-
}
|
|
41
|
-
|
|
42
24
|
const schedule = (callback: NotifyCallback): void => {
|
|
43
25
|
if (transactions) {
|
|
44
26
|
queue.push(callback)
|
|
@@ -48,20 +30,6 @@ export function createNotifyManager() {
|
|
|
48
30
|
})
|
|
49
31
|
}
|
|
50
32
|
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* All calls to the wrapped function will be batched.
|
|
54
|
-
*/
|
|
55
|
-
const batchCalls = <T extends Array<unknown>>(
|
|
56
|
-
callback: BatchCallsCallback<T>,
|
|
57
|
-
): BatchCallsCallback<T> => {
|
|
58
|
-
return (...args) => {
|
|
59
|
-
schedule(() => {
|
|
60
|
-
callback(...args)
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
33
|
const flush = (): void => {
|
|
66
34
|
const originalQueue = queue
|
|
67
35
|
queue = []
|
|
@@ -76,29 +44,50 @@ export function createNotifyManager() {
|
|
|
76
44
|
}
|
|
77
45
|
}
|
|
78
46
|
|
|
79
|
-
/**
|
|
80
|
-
* Use this method to set a custom notify function.
|
|
81
|
-
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
82
|
-
*/
|
|
83
|
-
const setNotifyFunction = (fn: NotifyFunction) => {
|
|
84
|
-
notifyFn = fn
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
89
|
-
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
90
|
-
*/
|
|
91
|
-
const setBatchNotifyFunction = (fn: BatchNotifyFunction) => {
|
|
92
|
-
batchNotifyFn = fn
|
|
93
|
-
}
|
|
94
|
-
|
|
95
47
|
return {
|
|
96
|
-
batch
|
|
97
|
-
|
|
48
|
+
batch: <T>(callback: () => T): T => {
|
|
49
|
+
let result
|
|
50
|
+
transactions++
|
|
51
|
+
try {
|
|
52
|
+
result = callback()
|
|
53
|
+
} finally {
|
|
54
|
+
transactions--
|
|
55
|
+
if (!transactions) {
|
|
56
|
+
flush()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* All calls to the wrapped function will be batched.
|
|
63
|
+
*/
|
|
64
|
+
batchCalls: <T extends Array<unknown>>(
|
|
65
|
+
callback: BatchCallsCallback<T>,
|
|
66
|
+
): BatchCallsCallback<T> => {
|
|
67
|
+
return (...args) => {
|
|
68
|
+
schedule(() => {
|
|
69
|
+
callback(...args)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
},
|
|
98
73
|
schedule,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Use this method to set a custom notify function.
|
|
76
|
+
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
77
|
+
*/
|
|
78
|
+
setNotifyFunction: (fn: NotifyFunction) => {
|
|
79
|
+
notifyFn = fn
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
83
|
+
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
84
|
+
*/
|
|
85
|
+
setBatchNotifyFunction: (fn: BatchNotifyFunction) => {
|
|
86
|
+
batchNotifyFn = fn
|
|
87
|
+
},
|
|
88
|
+
setScheduler: (fn: ScheduleFunction) => {
|
|
89
|
+
scheduleFn = fn
|
|
90
|
+
},
|
|
102
91
|
} as const
|
|
103
92
|
}
|
|
104
93
|
|
package/src/queryClient.ts
CHANGED
|
@@ -13,13 +13,13 @@ import { focusManager } from './focusManager'
|
|
|
13
13
|
import { onlineManager } from './onlineManager'
|
|
14
14
|
import { notifyManager } from './notifyManager'
|
|
15
15
|
import { infiniteQueryBehavior } from './infiniteQueryBehavior'
|
|
16
|
-
import type { QueryState } from './query'
|
|
17
16
|
import type {
|
|
18
17
|
CancelOptions,
|
|
19
18
|
DataTag,
|
|
20
19
|
DefaultError,
|
|
21
20
|
DefaultOptions,
|
|
22
21
|
DefaultedQueryObserverOptions,
|
|
22
|
+
EnsureInfiniteQueryDataOptions,
|
|
23
23
|
EnsureQueryDataOptions,
|
|
24
24
|
FetchInfiniteQueryOptions,
|
|
25
25
|
FetchQueryOptions,
|
|
@@ -40,6 +40,7 @@ import type {
|
|
|
40
40
|
ResetOptions,
|
|
41
41
|
SetDataOptions,
|
|
42
42
|
} from './types'
|
|
43
|
+
import type { QueryState } from './query'
|
|
43
44
|
import type { MutationFilters, QueryFilters, Updater } from './utils'
|
|
44
45
|
|
|
45
46
|
// TYPES
|
|
@@ -385,7 +386,7 @@ export class QueryClient {
|
|
|
385
386
|
TData,
|
|
386
387
|
TPageParam
|
|
387
388
|
>(options.pages)
|
|
388
|
-
return this.fetchQuery(options)
|
|
389
|
+
return this.fetchQuery(options as any)
|
|
389
390
|
}
|
|
390
391
|
|
|
391
392
|
prefetchInfiniteQuery<
|
|
@@ -406,6 +407,31 @@ export class QueryClient {
|
|
|
406
407
|
return this.fetchInfiniteQuery(options).then(noop).catch(noop)
|
|
407
408
|
}
|
|
408
409
|
|
|
410
|
+
ensureInfiniteQueryData<
|
|
411
|
+
TQueryFnData,
|
|
412
|
+
TError = DefaultError,
|
|
413
|
+
TData = TQueryFnData,
|
|
414
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
415
|
+
TPageParam = unknown,
|
|
416
|
+
>(
|
|
417
|
+
options: EnsureInfiniteQueryDataOptions<
|
|
418
|
+
TQueryFnData,
|
|
419
|
+
TError,
|
|
420
|
+
TData,
|
|
421
|
+
TQueryKey,
|
|
422
|
+
TPageParam
|
|
423
|
+
>,
|
|
424
|
+
): Promise<InfiniteData<TData, TPageParam>> {
|
|
425
|
+
options.behavior = infiniteQueryBehavior<
|
|
426
|
+
TQueryFnData,
|
|
427
|
+
TError,
|
|
428
|
+
TData,
|
|
429
|
+
TPageParam
|
|
430
|
+
>(options.pages)
|
|
431
|
+
|
|
432
|
+
return this.ensureQueryData(options as any)
|
|
433
|
+
}
|
|
434
|
+
|
|
409
435
|
resumePausedMutations(): Promise<unknown> {
|
|
410
436
|
if (onlineManager.isOnline()) {
|
|
411
437
|
return this.#mutationCache.resumePausedMutations()
|
package/src/types.ts
CHANGED
|
@@ -448,6 +448,7 @@ export interface FetchQueryOptions<
|
|
|
448
448
|
QueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
449
449
|
'queryKey'
|
|
450
450
|
> {
|
|
451
|
+
initialPageParam?: never
|
|
451
452
|
/**
|
|
452
453
|
* The time in milliseconds after data is considered stale.
|
|
453
454
|
* If the data is fresh it will be returned from the cache.
|
|
@@ -471,6 +472,22 @@ export interface EnsureQueryDataOptions<
|
|
|
471
472
|
revalidateIfStale?: boolean
|
|
472
473
|
}
|
|
473
474
|
|
|
475
|
+
export type EnsureInfiniteQueryDataOptions<
|
|
476
|
+
TQueryFnData = unknown,
|
|
477
|
+
TError = DefaultError,
|
|
478
|
+
TData = TQueryFnData,
|
|
479
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
480
|
+
TPageParam = unknown,
|
|
481
|
+
> = FetchInfiniteQueryOptions<
|
|
482
|
+
TQueryFnData,
|
|
483
|
+
TError,
|
|
484
|
+
TData,
|
|
485
|
+
TQueryKey,
|
|
486
|
+
TPageParam
|
|
487
|
+
> & {
|
|
488
|
+
revalidateIfStale?: boolean
|
|
489
|
+
}
|
|
490
|
+
|
|
474
491
|
type FetchInfiniteQueryPages<TQueryFnData = unknown, TPageParam = unknown> =
|
|
475
492
|
| { pages?: never }
|
|
476
493
|
| {
|
|
@@ -484,12 +501,15 @@ export type FetchInfiniteQueryOptions<
|
|
|
484
501
|
TData = TQueryFnData,
|
|
485
502
|
TQueryKey extends QueryKey = QueryKey,
|
|
486
503
|
TPageParam = unknown,
|
|
487
|
-
> =
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
504
|
+
> = Omit<
|
|
505
|
+
FetchQueryOptions<
|
|
506
|
+
TQueryFnData,
|
|
507
|
+
TError,
|
|
508
|
+
InfiniteData<TData, TPageParam>,
|
|
509
|
+
TQueryKey,
|
|
510
|
+
TPageParam
|
|
511
|
+
>,
|
|
512
|
+
'initialPageParam'
|
|
493
513
|
> &
|
|
494
514
|
InitialPageParam<TPageParam> &
|
|
495
515
|
FetchInfiniteQueryPages<TQueryFnData, TPageParam>
|