@tanstack/query-core 5.8.1 → 5.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/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-b7fce2ff.d.ts → queryClient-13f81fcb.d.ts} +8 -2
- package/build/legacy/{queryClient-65193a81.d.ts → queryClient-89a8a2bf.d.ts} +8 -2
- package/build/legacy/queryClient.d.cts +1 -1
- package/build/legacy/queryClient.d.ts +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.cjs +2 -2
- 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 +2 -2
- package/build/legacy/utils.js.map +1 -1
- 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/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-b7fce2ff.d.ts → queryClient-13f81fcb.d.ts} +8 -2
- package/build/modern/{queryClient-65193a81.d.ts → queryClient-89a8a2bf.d.ts} +8 -2
- package/build/modern/queryClient.d.cts +1 -1
- package/build/modern/queryClient.d.ts +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.cjs +2 -2
- 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 +2 -2
- package/build/modern/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/tests/queryObserver.types.test.tsx +64 -0
- package/src/types.ts +12 -1
- package/src/utils.ts +2 -2
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, it } from 'vitest'
|
|
2
|
+
import { QueryObserver } from '..'
|
|
3
|
+
import { createQueryClient, doNotExecute } from './utils'
|
|
4
|
+
import type { Equal, Expect } from './utils'
|
|
5
|
+
|
|
6
|
+
describe('placeholderData', () => {
|
|
7
|
+
describe('placeholderData function', () => {
|
|
8
|
+
it('previousQuery should have typed queryKey', () => {
|
|
9
|
+
doNotExecute(() => {
|
|
10
|
+
const queryKey = ['SomeQuery', 42, { foo: 'bar' }] as const
|
|
11
|
+
type QueryKey = typeof queryKey
|
|
12
|
+
|
|
13
|
+
new QueryObserver(createQueryClient(), {
|
|
14
|
+
queryKey,
|
|
15
|
+
placeholderData: (_, previousQuery) => {
|
|
16
|
+
const previousQueryKey = previousQuery?.queryKey
|
|
17
|
+
|
|
18
|
+
const result: Expect<
|
|
19
|
+
Equal<typeof previousQueryKey, QueryKey | undefined>
|
|
20
|
+
> = true
|
|
21
|
+
return result
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('previousQuery should have typed error', () => {
|
|
28
|
+
doNotExecute(() => {
|
|
29
|
+
class CustomError extends Error {
|
|
30
|
+
name = 'CustomError' as const
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
new QueryObserver<boolean, CustomError>(createQueryClient(), {
|
|
34
|
+
placeholderData: (_, previousQuery) => {
|
|
35
|
+
const error = previousQuery?.state.error
|
|
36
|
+
|
|
37
|
+
const result: Expect<
|
|
38
|
+
Equal<typeof error, CustomError | null | undefined>
|
|
39
|
+
> = true
|
|
40
|
+
return result
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('previousData should have the same type as query data', () => {
|
|
47
|
+
doNotExecute(() => {
|
|
48
|
+
const queryData = { foo: 'bar' } as const
|
|
49
|
+
type QueryData = typeof queryData
|
|
50
|
+
|
|
51
|
+
new QueryObserver(createQueryClient(), {
|
|
52
|
+
queryFn: () => queryData,
|
|
53
|
+
select: (data) => data.foo,
|
|
54
|
+
placeholderData: (previousData) => {
|
|
55
|
+
const result: Expect<
|
|
56
|
+
Equal<typeof previousData, QueryData | undefined>
|
|
57
|
+
> = true
|
|
58
|
+
return result ? previousData : undefined
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
})
|
package/src/types.ts
CHANGED
|
@@ -140,6 +140,12 @@ export interface QueryOptions<
|
|
|
140
140
|
retry?: RetryValue<TError>
|
|
141
141
|
retryDelay?: RetryDelayValue<TError>
|
|
142
142
|
networkMode?: NetworkMode
|
|
143
|
+
/**
|
|
144
|
+
* The time in milliseconds that unused/inactive cache data remains in memory.
|
|
145
|
+
* When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration.
|
|
146
|
+
* When different garbage collection times are specified, the longest one will be used.
|
|
147
|
+
* Setting it to `Infinity` will disable garbage collection.
|
|
148
|
+
*/
|
|
143
149
|
gcTime?: number
|
|
144
150
|
queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam>
|
|
145
151
|
persister?: QueryPersister<
|
|
@@ -319,7 +325,12 @@ export interface QueryObserverOptions<
|
|
|
319
325
|
*/
|
|
320
326
|
placeholderData?:
|
|
321
327
|
| NonFunctionGuard<TQueryData>
|
|
322
|
-
| PlaceholderDataFunction<
|
|
328
|
+
| PlaceholderDataFunction<
|
|
329
|
+
NonFunctionGuard<TQueryData>,
|
|
330
|
+
TError,
|
|
331
|
+
NonFunctionGuard<TQueryData>,
|
|
332
|
+
TQueryKey
|
|
333
|
+
>
|
|
323
334
|
|
|
324
335
|
_optimisticResults?: 'optimistic' | 'isRestoring'
|
|
325
336
|
}
|
package/src/utils.ts
CHANGED
|
@@ -297,9 +297,9 @@ function hasObjectPrototype(o: any): boolean {
|
|
|
297
297
|
return Object.prototype.toString.call(o) === '[object Object]'
|
|
298
298
|
}
|
|
299
299
|
|
|
300
|
-
export function sleep(
|
|
300
|
+
export function sleep(ms: number): Promise<void> {
|
|
301
301
|
return new Promise((resolve) => {
|
|
302
|
-
setTimeout(resolve,
|
|
302
|
+
setTimeout(resolve, ms)
|
|
303
303
|
})
|
|
304
304
|
}
|
|
305
305
|
|