@tanstack/query-core 5.25.0 → 5.26.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.
Files changed (33) hide show
  1. package/build/legacy/focusManager.cjs +2 -1
  2. package/build/legacy/focusManager.cjs.map +1 -1
  3. package/build/legacy/focusManager.d.cts +2 -1
  4. package/build/legacy/focusManager.d.ts +2 -1
  5. package/build/legacy/focusManager.js +2 -1
  6. package/build/legacy/focusManager.js.map +1 -1
  7. package/build/legacy/queryClient.cjs +2 -2
  8. package/build/legacy/queryClient.cjs.map +1 -1
  9. package/build/legacy/queryClient.js +2 -2
  10. package/build/legacy/queryClient.js.map +1 -1
  11. package/build/modern/focusManager.cjs +2 -1
  12. package/build/modern/focusManager.cjs.map +1 -1
  13. package/build/modern/focusManager.d.cts +2 -1
  14. package/build/modern/focusManager.d.ts +2 -1
  15. package/build/modern/focusManager.js +2 -1
  16. package/build/modern/focusManager.js.map +1 -1
  17. package/build/modern/queryClient.cjs +2 -2
  18. package/build/modern/queryClient.cjs.map +1 -1
  19. package/build/modern/queryClient.js +2 -2
  20. package/build/modern/queryClient.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/focusManager.ts +5 -2
  23. package/src/queryClient.ts +2 -2
  24. package/src/tests/focusManager.test.tsx +3 -0
  25. package/src/tests/infiniteQueryObserver.test-d.tsx +62 -0
  26. package/src/tests/infiniteQueryObserver.test.tsx +2 -51
  27. package/src/tests/query.test.tsx +9 -3
  28. package/src/tests/queryClient.test-d.tsx +135 -0
  29. package/src/tests/queryObserver.test-d.tsx +108 -0
  30. package/src/tests/queryObserver.test.tsx +6 -40
  31. package/src/tests/utils.ts +0 -10
  32. package/src/tests/queryClient.types.test.tsx +0 -174
  33. package/src/tests/queryObserver.types.test.tsx +0 -66
@@ -1,174 +0,0 @@
1
- import { describe, it } from 'vitest'
2
- import { QueryClient } from '../queryClient'
3
- import { doNotExecute } from './utils'
4
- import type { Equal, Expect } from './utils'
5
- import type { DataTag, InfiniteData } from '../types'
6
-
7
- describe('getQueryData', () => {
8
- it('should be typed if key is tagged', () => {
9
- doNotExecute(() => {
10
- const queryKey = ['key'] as DataTag<Array<string>, number>
11
- const queryClient = new QueryClient()
12
- const data = queryClient.getQueryData(queryKey)
13
-
14
- const result: Expect<Equal<typeof data, number | undefined>> = true
15
- return result
16
- })
17
- })
18
-
19
- it('should infer unknown if key is not tagged', () => {
20
- doNotExecute(() => {
21
- const queryKey = ['key'] as const
22
- const queryClient = new QueryClient()
23
- const data = queryClient.getQueryData(queryKey)
24
-
25
- const result: Expect<Equal<typeof data, unknown>> = true
26
- return result
27
- })
28
- })
29
-
30
- it('should infer passed generic if passed', () => {
31
- doNotExecute(() => {
32
- const queryKey = ['key'] as const
33
- const queryClient = new QueryClient()
34
- const data = queryClient.getQueryData<number>(queryKey)
35
-
36
- const result: Expect<Equal<typeof data, number | undefined>> = true
37
- return result
38
- })
39
- })
40
-
41
- it('should only allow Arrays to be passed', () => {
42
- doNotExecute(() => {
43
- const queryKey = 'key' as const
44
- const queryClient = new QueryClient()
45
- // @ts-expect-error TS2345: Argument of type 'string' is not assignable to parameter of type 'QueryKey'
46
- return queryClient.getQueryData(queryKey)
47
- })
48
- })
49
- })
50
-
51
- describe('setQueryData', () => {
52
- it('updater should be typed if key is tagged', () => {
53
- doNotExecute(() => {
54
- const queryKey = ['key'] as DataTag<Array<string>, number>
55
- const queryClient = new QueryClient()
56
- const data = queryClient.setQueryData(queryKey, (prev) => {
57
- const result: Expect<Equal<typeof prev, number | undefined>> = true
58
- return result ? prev : 1
59
- })
60
-
61
- const result: Expect<Equal<typeof data, number | undefined>> = true
62
- return result
63
- })
64
- })
65
-
66
- it('value should be typed if key is tagged', () => {
67
- doNotExecute(() => {
68
- const queryKey = ['key'] as DataTag<Array<string>, number>
69
- const queryClient = new QueryClient()
70
-
71
- // @ts-expect-error value should be a number
72
- queryClient.setQueryData(queryKey, '1')
73
-
74
- // @ts-expect-error value should be a number
75
- queryClient.setQueryData(queryKey, () => '1')
76
-
77
- const data = queryClient.setQueryData(queryKey, 1)
78
-
79
- const result: Expect<Equal<typeof data, number | undefined>> = true
80
- return result
81
- })
82
- })
83
-
84
- it('should infer unknown for updater if key is not tagged', () => {
85
- doNotExecute(() => {
86
- const queryKey = ['key'] as const
87
- const queryClient = new QueryClient()
88
- const data = queryClient.setQueryData(queryKey, (prev) => {
89
- const result: Expect<Equal<typeof prev, unknown>> = true
90
- return result ? prev : 1
91
- })
92
-
93
- const result: Expect<Equal<typeof data, unknown>> = true
94
- return result
95
- })
96
- })
97
-
98
- it('should infer unknown for value if key is not tagged', () => {
99
- doNotExecute(() => {
100
- const queryKey = ['key'] as const
101
- const queryClient = new QueryClient()
102
- const data = queryClient.setQueryData(queryKey, 'foo')
103
-
104
- const result: Expect<Equal<typeof data, unknown>> = true
105
- return result
106
- })
107
- })
108
-
109
- it('should infer passed generic if passed', () => {
110
- doNotExecute(() => {
111
- const queryKey = ['key'] as const
112
- const queryClient = new QueryClient()
113
- const data = queryClient.setQueryData<string>(queryKey, (prev) => {
114
- const result: Expect<Equal<typeof prev, string | undefined>> = true
115
- return result ? prev : '1'
116
- })
117
-
118
- const result: Expect<Equal<typeof data, string | undefined>> = true
119
- return result
120
- })
121
- })
122
-
123
- it('should infer passed generic for value', () => {
124
- doNotExecute(() => {
125
- const queryKey = ['key'] as const
126
- const queryClient = new QueryClient()
127
- const data = queryClient.setQueryData<string>(queryKey, 'foo')
128
-
129
- const result: Expect<Equal<typeof data, string | undefined>> = true
130
- return result
131
- })
132
- })
133
- })
134
-
135
- describe('fetchInfiniteQuery', () => {
136
- it('should allow passing pages', () => {
137
- doNotExecute(async () => {
138
- const data = await new QueryClient().fetchInfiniteQuery({
139
- queryKey: ['key'],
140
- queryFn: () => Promise.resolve('string'),
141
- getNextPageParam: () => 1,
142
- initialPageParam: 1,
143
- pages: 5,
144
- })
145
-
146
- const result: Expect<Equal<typeof data, InfiniteData<string, number>>> =
147
- true
148
- return result
149
- })
150
- })
151
-
152
- it('should not allow passing getNextPageParam without pages', () => {
153
- doNotExecute(async () => {
154
- return new QueryClient().fetchInfiniteQuery({
155
- queryKey: ['key'],
156
- queryFn: () => Promise.resolve('string'),
157
- initialPageParam: 1,
158
- getNextPageParam: () => 1,
159
- })
160
- })
161
- })
162
-
163
- it('should not allow passing pages without getNextPageParam', () => {
164
- doNotExecute(async () => {
165
- // @ts-expect-error Property 'getNextPageParam' is missing
166
- return new QueryClient().fetchInfiniteQuery({
167
- queryKey: ['key'],
168
- queryFn: () => Promise.resolve('string'),
169
- initialPageParam: 1,
170
- pages: 5,
171
- })
172
- })
173
- })
174
- })
@@ -1,66 +0,0 @@
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
- queryKey: ['key'],
35
- placeholderData: (_, previousQuery) => {
36
- const error = previousQuery?.state.error
37
-
38
- const result: Expect<
39
- Equal<typeof error, CustomError | null | undefined>
40
- > = true
41
- return result
42
- },
43
- })
44
- })
45
- })
46
-
47
- it('previousData should have the same type as query data', () => {
48
- doNotExecute(() => {
49
- const queryData = { foo: 'bar' } as const
50
- type QueryData = typeof queryData
51
-
52
- new QueryObserver(createQueryClient(), {
53
- queryKey: ['key'],
54
- queryFn: () => queryData,
55
- select: (data) => data.foo,
56
- placeholderData: (previousData) => {
57
- const result: Expect<
58
- Equal<typeof previousData, QueryData | undefined>
59
- > = true
60
- return result ? previousData : undefined
61
- },
62
- })
63
- })
64
- })
65
- })
66
- })