@tanstack/vue-query 5.40.0 → 5.41.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.
Files changed (52) hide show
  1. package/build/legacy/index.cjs +3 -0
  2. package/build/legacy/index.cjs.map +1 -1
  3. package/build/legacy/index.d.cts +1 -0
  4. package/build/legacy/index.d.ts +1 -0
  5. package/build/legacy/index.js +2 -0
  6. package/build/legacy/index.js.map +1 -1
  7. package/build/legacy/infiniteQueryOptions.cjs +33 -0
  8. package/build/legacy/infiniteQueryOptions.cjs.map +1 -0
  9. package/build/legacy/infiniteQueryOptions.d.cts +21 -0
  10. package/build/legacy/infiniteQueryOptions.d.ts +21 -0
  11. package/build/legacy/infiniteQueryOptions.js +8 -0
  12. package/build/legacy/infiniteQueryOptions.js.map +1 -0
  13. package/build/legacy/useQueries.cjs.map +1 -1
  14. package/build/legacy/useQueries.d.cts +9 -14
  15. package/build/legacy/useQueries.d.ts +9 -14
  16. package/build/legacy/useQueries.js.map +1 -1
  17. package/build/modern/index.cjs +3 -0
  18. package/build/modern/index.cjs.map +1 -1
  19. package/build/modern/index.d.cts +1 -0
  20. package/build/modern/index.d.ts +1 -0
  21. package/build/modern/index.js +2 -0
  22. package/build/modern/index.js.map +1 -1
  23. package/build/modern/infiniteQueryOptions.cjs +33 -0
  24. package/build/modern/infiniteQueryOptions.cjs.map +1 -0
  25. package/build/modern/infiniteQueryOptions.d.cts +21 -0
  26. package/build/modern/infiniteQueryOptions.d.ts +21 -0
  27. package/build/modern/infiniteQueryOptions.js +8 -0
  28. package/build/modern/infiniteQueryOptions.js.map +1 -0
  29. package/build/modern/useQueries.cjs.map +1 -1
  30. package/build/modern/useQueries.d.cts +9 -14
  31. package/build/modern/useQueries.d.ts +9 -14
  32. package/build/modern/useQueries.js.map +1 -1
  33. package/package.json +1 -1
  34. package/src/__tests__/infiniteQueryOptions.test-d.ts +111 -0
  35. package/src/__tests__/queryClient.test-d.ts +132 -0
  36. package/src/__tests__/queryClient.test.ts +17 -0
  37. package/src/__tests__/queryOptions.test-d.ts +125 -0
  38. package/src/__tests__/test-utils.ts +0 -10
  39. package/src/__tests__/useInfiniteQuery.test-d.tsx +84 -0
  40. package/src/__tests__/useInfiniteQuery.test.ts +32 -0
  41. package/src/__tests__/useMutation.test-d.tsx +74 -0
  42. package/src/__tests__/useQueries.test-d.ts +145 -0
  43. package/src/__tests__/useQuery.test-d.ts +228 -0
  44. package/src/index.ts +5 -0
  45. package/src/infiniteQueryOptions.ts +94 -0
  46. package/src/useQueries.ts +18 -36
  47. package/src/__tests__/queryClient.type.test.ts +0 -174
  48. package/src/__tests__/queryOptions.types.test.ts +0 -170
  49. package/src/__tests__/useInfiniteQuery.types.test.tsx +0 -106
  50. package/src/__tests__/useMutation.types.test.tsx +0 -98
  51. package/src/__tests__/useQueries.types.test.ts +0 -176
  52. package/src/__tests__/useQuery.types.test.ts +0 -282
@@ -1,282 +0,0 @@
1
- import { describe, it } from 'vitest'
2
- import { reactive } from 'vue-demi'
3
- import { useQuery } from '../useQuery'
4
- import { queryOptions } from '../queryOptions'
5
- import { doNotExecute, simpleFetcher } from './test-utils'
6
- import type { OmitKeyof } from '..'
7
- import type { UseQueryOptions } from '../useQuery'
8
- import type { Equal, Expect } from './test-utils'
9
-
10
- describe('initialData', () => {
11
- describe('Config object overload', () => {
12
- it('TData should always be defined when initialData is provided as an object', () => {
13
- doNotExecute(() => {
14
- const { data } = reactive(
15
- useQuery({
16
- queryKey: ['key'],
17
- queryFn: () => {
18
- return {
19
- wow: true,
20
- }
21
- },
22
- initialData: {
23
- wow: true,
24
- },
25
- }),
26
- )
27
-
28
- const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
29
-
30
- return result
31
- })
32
- })
33
-
34
- it('TData should be defined when passed through queryOptions', () => {
35
- doNotExecute(() => {
36
- const options = queryOptions({
37
- queryKey: ['key'],
38
- queryFn: () => {
39
- return {
40
- wow: true,
41
- }
42
- },
43
- initialData: {
44
- wow: true,
45
- },
46
- })
47
- const { data } = reactive(useQuery(options))
48
-
49
- const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
50
- return result
51
- })
52
- })
53
-
54
- it('it should be possible to define a different TData than TQueryFnData using select with queryOptions spread into useQuery', () => {
55
- doNotExecute(() => {
56
- const options = queryOptions({
57
- queryKey: ['key'],
58
- queryFn: () => Promise.resolve(1),
59
- })
60
-
61
- const query = reactive(
62
- useQuery({
63
- ...options,
64
- select: (data) => data > 1,
65
- }),
66
- )
67
-
68
- const result: Expect<Equal<boolean | undefined, typeof query.data>> =
69
- true
70
- return result
71
- })
72
- })
73
-
74
- it('TData should always be defined when initialData is provided as a function which ALWAYS returns the data', () => {
75
- doNotExecute(() => {
76
- const { data } = reactive(
77
- useQuery({
78
- queryKey: ['key'],
79
- queryFn: () => {
80
- return {
81
- wow: true,
82
- }
83
- },
84
- initialData: () => ({
85
- wow: true,
86
- }),
87
- }),
88
- )
89
-
90
- const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
91
- return result
92
- })
93
- })
94
-
95
- it('TData should have undefined in the union when initialData is NOT provided', () => {
96
- doNotExecute(() => {
97
- const { data } = reactive(
98
- useQuery({
99
- queryKey: ['key'],
100
- queryFn: () => {
101
- return {
102
- wow: true,
103
- }
104
- },
105
- }),
106
- )
107
-
108
- const result: Expect<Equal<{ wow: boolean } | undefined, typeof data>> =
109
- true
110
- return result
111
- })
112
- })
113
-
114
- it('TData should have undefined in the union when initialData is provided as a function which can return undefined', () => {
115
- doNotExecute(() => {
116
- const { data } = reactive(
117
- useQuery({
118
- queryKey: ['key'],
119
- queryFn: () => {
120
- return {
121
- wow: true,
122
- }
123
- },
124
- initialData: () => undefined as { wow: boolean } | undefined,
125
- }),
126
- )
127
-
128
- const result: Expect<Equal<{ wow: boolean } | undefined, typeof data>> =
129
- true
130
- return result
131
- })
132
- })
133
-
134
- it('TData should be narrowed after an isSuccess check when initialData is provided as a function which can return undefined', () => {
135
- doNotExecute(() => {
136
- const { data, isSuccess } = reactive(
137
- useQuery({
138
- queryKey: ['key'],
139
- queryFn: () => {
140
- return {
141
- wow: true,
142
- }
143
- },
144
- initialData: () => undefined as { wow: boolean } | undefined,
145
- }),
146
- )
147
-
148
- if (isSuccess) {
149
- const result: Expect<Equal<{ wow: boolean }, typeof data>> = true
150
- return result
151
- }
152
- return false
153
- })
154
- })
155
- })
156
-
157
- describe('custom composable', () => {
158
- it('should allow custom composable using UseQueryOptions', () => {
159
- doNotExecute(() => {
160
- type Data = string
161
-
162
- const useCustomQuery = (
163
- options?: OmitKeyof<
164
- UseQueryOptions<Data>,
165
- 'queryKey' | 'queryFn',
166
- 'safely'
167
- >,
168
- ) => {
169
- return useQuery({
170
- ...options,
171
- queryKey: ['todos-key'],
172
- queryFn: () => Promise.resolve('data'),
173
- })
174
- }
175
-
176
- const { data } = reactive(useCustomQuery())
177
-
178
- const result: Expect<Equal<Data | undefined, typeof data>> = true
179
- return result
180
- })
181
- })
182
- })
183
-
184
- describe('structuralSharing', () => {
185
- it('should restrict to same types', () => {
186
- doNotExecute(() => {
187
- useQuery({
188
- queryKey: ['key'],
189
- queryFn: () => 5,
190
- structuralSharing: (_oldData, newData) => {
191
- return newData
192
- },
193
- })
194
- })
195
- })
196
- })
197
-
198
- describe('Discriminated union return type', () => {
199
- it('data should be possibly undefined by default', () => {
200
- doNotExecute(() => {
201
- const query = reactive(
202
- useQuery({
203
- queryKey: ['key'],
204
- queryFn: simpleFetcher,
205
- }),
206
- )
207
-
208
- const result: Expect<Equal<string | undefined, typeof query.data>> =
209
- true
210
- return result
211
- })
212
- })
213
-
214
- it('data should be defined when query is success', () => {
215
- doNotExecute(() => {
216
- const query = reactive(
217
- useQuery({
218
- queryKey: ['key'],
219
- queryFn: simpleFetcher,
220
- }),
221
- )
222
-
223
- if (query.isSuccess) {
224
- const result: Expect<Equal<string, typeof query.data>> = true
225
- return result
226
- }
227
- return
228
- })
229
- })
230
-
231
- it('error should be null when query is success', () => {
232
- doNotExecute(() => {
233
- const query = reactive(
234
- useQuery({
235
- queryKey: ['key'],
236
- queryFn: simpleFetcher,
237
- }),
238
- )
239
-
240
- if (query.isSuccess) {
241
- const result: Expect<Equal<null, typeof query.error>> = true
242
- return result
243
- }
244
- return
245
- })
246
- })
247
-
248
- it('data should be undefined when query is pending', () => {
249
- doNotExecute(() => {
250
- const query = reactive(
251
- useQuery({
252
- queryKey: ['key'],
253
- queryFn: simpleFetcher,
254
- }),
255
- )
256
-
257
- if (query.isPending) {
258
- const result: Expect<Equal<undefined, typeof query.data>> = true
259
- return result
260
- }
261
- return
262
- })
263
- })
264
-
265
- it('error should be defined when query is error', () => {
266
- doNotExecute(() => {
267
- const query = reactive(
268
- useQuery({
269
- queryKey: ['key'],
270
- queryFn: simpleFetcher,
271
- }),
272
- )
273
-
274
- if (query.isError) {
275
- const result: Expect<Equal<Error, typeof query.error>> = true
276
- return result
277
- }
278
- return
279
- })
280
- })
281
- })
282
- })