@tanstack/vue-query 5.59.17 → 5.59.20
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/package.json +4 -3
- package/src/__tests__/infiniteQueryOptions.test-d.ts +0 -111
- package/src/__tests__/mutationCache.test.ts +0 -39
- package/src/__tests__/queryCache.test.ts +0 -47
- package/src/__tests__/queryClient.test-d.ts +0 -132
- package/src/__tests__/queryClient.test.ts +0 -433
- package/src/__tests__/queryOptions.test-d.ts +0 -125
- package/src/__tests__/test-utils.ts +0 -52
- package/src/__tests__/useInfiniteQuery.test-d.tsx +0 -84
- package/src/__tests__/useInfiniteQuery.test.ts +0 -69
- package/src/__tests__/useIsFetching.test.ts +0 -76
- package/src/__tests__/useIsMutating.test.ts +0 -122
- package/src/__tests__/useMutation.test-d.tsx +0 -74
- package/src/__tests__/useMutation.test.ts +0 -355
- package/src/__tests__/useQueries.test-d.ts +0 -222
- package/src/__tests__/useQueries.test.ts +0 -370
- package/src/__tests__/useQuery.test-d.ts +0 -271
- package/src/__tests__/useQuery.test.ts +0 -497
- package/src/__tests__/useQueryClient.test.ts +0 -51
- package/src/__tests__/utils.test.ts +0 -155
- package/src/__tests__/vueQueryPlugin.test.ts +0 -393
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-query",
|
|
3
|
-
"version": "5.59.
|
|
3
|
+
"version": "5.59.20",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
|
|
5
5
|
"author": "Damian Osipiuk",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"files": [
|
|
36
36
|
"build",
|
|
37
|
-
"src"
|
|
37
|
+
"src",
|
|
38
|
+
"!src/__tests__"
|
|
38
39
|
],
|
|
39
40
|
"nx": {
|
|
40
41
|
"targets": {
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"@tanstack/match-sorter-utils": "^8.15.1",
|
|
50
51
|
"@vue/devtools-api": "^6.6.3",
|
|
51
52
|
"vue-demi": "^0.14.10",
|
|
52
|
-
"@tanstack/query-core": "5.59.
|
|
53
|
+
"@tanstack/query-core": "5.59.20"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@vitejs/plugin-vue": "^5.1.1",
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { describe, expectTypeOf, it } from 'vitest'
|
|
2
|
-
import { QueryClient, dataTagSymbol } from '@tanstack/query-core'
|
|
3
|
-
import { reactive } from 'vue-demi'
|
|
4
|
-
import { infiniteQueryOptions } from '../infiniteQueryOptions'
|
|
5
|
-
import { useInfiniteQuery } from '../useInfiniteQuery'
|
|
6
|
-
import type { InfiniteData } from '@tanstack/query-core'
|
|
7
|
-
|
|
8
|
-
describe('infiniteQueryOptions', () => {
|
|
9
|
-
it('should not allow excess properties', () => {
|
|
10
|
-
infiniteQueryOptions({
|
|
11
|
-
queryKey: ['key'],
|
|
12
|
-
queryFn: () => Promise.resolve('data'),
|
|
13
|
-
getNextPageParam: () => 1,
|
|
14
|
-
initialPageParam: 1,
|
|
15
|
-
// @ts-expect-error this is a good error, because stallTime does not exist!
|
|
16
|
-
stallTime: 1000,
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
it('should infer types for callbacks', () => {
|
|
20
|
-
infiniteQueryOptions({
|
|
21
|
-
queryKey: ['key'],
|
|
22
|
-
queryFn: () => Promise.resolve('data'),
|
|
23
|
-
staleTime: 1000,
|
|
24
|
-
getNextPageParam: () => 1,
|
|
25
|
-
initialPageParam: 1,
|
|
26
|
-
select: (data) => {
|
|
27
|
-
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
|
|
28
|
-
},
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
it('should work when passed to useInfiniteQuery', () => {
|
|
32
|
-
const options = infiniteQueryOptions({
|
|
33
|
-
queryKey: ['key'],
|
|
34
|
-
queryFn: () => Promise.resolve('string'),
|
|
35
|
-
getNextPageParam: () => 1,
|
|
36
|
-
initialPageParam: 1,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const { data } = reactive(useInfiniteQuery(options))
|
|
40
|
-
|
|
41
|
-
expectTypeOf(data).toEqualTypeOf<
|
|
42
|
-
InfiniteData<string, unknown> | undefined
|
|
43
|
-
>()
|
|
44
|
-
})
|
|
45
|
-
it('should tag the queryKey with the result type of the QueryFn', () => {
|
|
46
|
-
const { queryKey } = infiniteQueryOptions({
|
|
47
|
-
queryKey: ['key'],
|
|
48
|
-
queryFn: () => Promise.resolve('string'),
|
|
49
|
-
getNextPageParam: () => 1,
|
|
50
|
-
initialPageParam: 1,
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
|
|
54
|
-
})
|
|
55
|
-
it('should tag the queryKey even if no promise is returned', () => {
|
|
56
|
-
const { queryKey } = infiniteQueryOptions({
|
|
57
|
-
queryKey: ['key'],
|
|
58
|
-
queryFn: () => 'string',
|
|
59
|
-
getNextPageParam: () => 1,
|
|
60
|
-
initialPageParam: 1,
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
|
|
64
|
-
})
|
|
65
|
-
it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
|
|
66
|
-
const { queryKey } = infiniteQueryOptions({
|
|
67
|
-
queryKey: ['key'],
|
|
68
|
-
queryFn: () => Promise.resolve('string'),
|
|
69
|
-
select: (data) => data.pages,
|
|
70
|
-
getNextPageParam: () => 1,
|
|
71
|
-
initialPageParam: 1,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<InfiniteData<string>>()
|
|
75
|
-
})
|
|
76
|
-
it('should return the proper type when passed to getQueryData', () => {
|
|
77
|
-
const { queryKey } = infiniteQueryOptions({
|
|
78
|
-
queryKey: ['key'],
|
|
79
|
-
queryFn: () => Promise.resolve('string'),
|
|
80
|
-
getNextPageParam: () => 1,
|
|
81
|
-
initialPageParam: 1,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const queryClient = new QueryClient()
|
|
85
|
-
const data = queryClient.getQueryData(queryKey)
|
|
86
|
-
|
|
87
|
-
expectTypeOf(data).toEqualTypeOf<
|
|
88
|
-
InfiniteData<string, unknown> | undefined
|
|
89
|
-
>()
|
|
90
|
-
})
|
|
91
|
-
it('should properly type when passed to setQueryData', () => {
|
|
92
|
-
const { queryKey } = infiniteQueryOptions({
|
|
93
|
-
queryKey: ['key'],
|
|
94
|
-
queryFn: () => Promise.resolve('string'),
|
|
95
|
-
getNextPageParam: () => 1,
|
|
96
|
-
initialPageParam: 1,
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
const queryClient = new QueryClient()
|
|
100
|
-
const data = queryClient.setQueryData(queryKey, (prev) => {
|
|
101
|
-
expectTypeOf(prev).toEqualTypeOf<
|
|
102
|
-
InfiniteData<string, unknown> | undefined
|
|
103
|
-
>()
|
|
104
|
-
return prev
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
expectTypeOf(data).toEqualTypeOf<
|
|
108
|
-
InfiniteData<string, unknown> | undefined
|
|
109
|
-
>()
|
|
110
|
-
})
|
|
111
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { beforeAll, describe, expect, test, vi } from 'vitest'
|
|
2
|
-
import { ref } from 'vue-demi'
|
|
3
|
-
import { MutationCache as MutationCacheOrigin } from '@tanstack/query-core'
|
|
4
|
-
import { MutationCache } from '../mutationCache'
|
|
5
|
-
|
|
6
|
-
describe('MutationCache', () => {
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
vi.spyOn(MutationCacheOrigin.prototype, 'find')
|
|
9
|
-
vi.spyOn(MutationCacheOrigin.prototype, 'findAll')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
describe('find', () => {
|
|
13
|
-
test('should properly unwrap parameters', async () => {
|
|
14
|
-
const mutationCache = new MutationCache()
|
|
15
|
-
|
|
16
|
-
mutationCache.find({
|
|
17
|
-
mutationKey: ref(['baz']),
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
expect(MutationCacheOrigin.prototype.find).toBeCalledWith({
|
|
21
|
-
mutationKey: ['baz'],
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('findAll', () => {
|
|
27
|
-
test('should properly unwrap parameters', async () => {
|
|
28
|
-
const mutationCache = new MutationCache()
|
|
29
|
-
|
|
30
|
-
mutationCache.findAll({
|
|
31
|
-
mutationKey: ref(['baz']),
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
expect(MutationCacheOrigin.prototype.findAll).toBeCalledWith({
|
|
35
|
-
mutationKey: ['baz'],
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { beforeAll, describe, expect, test, vi } from 'vitest'
|
|
2
|
-
import { ref } from 'vue-demi'
|
|
3
|
-
import { QueryCache as QueryCacheOrigin } from '@tanstack/query-core'
|
|
4
|
-
import { QueryCache } from '../queryCache'
|
|
5
|
-
|
|
6
|
-
describe('QueryCache', () => {
|
|
7
|
-
beforeAll(() => {
|
|
8
|
-
vi.spyOn(QueryCacheOrigin.prototype, 'find')
|
|
9
|
-
vi.spyOn(QueryCacheOrigin.prototype, 'findAll')
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
describe('find', () => {
|
|
13
|
-
test('should properly unwrap parameters', async () => {
|
|
14
|
-
const queryCache = new QueryCache()
|
|
15
|
-
|
|
16
|
-
queryCache.find({
|
|
17
|
-
queryKey: ['foo', ref('bar')],
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
expect(QueryCacheOrigin.prototype.find).toBeCalledWith({
|
|
21
|
-
queryKey: ['foo', 'bar'],
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
describe('findAll', () => {
|
|
27
|
-
test('should properly unwrap two parameters', async () => {
|
|
28
|
-
const queryCache = new QueryCache()
|
|
29
|
-
|
|
30
|
-
queryCache.findAll({
|
|
31
|
-
queryKey: ['foo', ref('bar')],
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({
|
|
35
|
-
queryKey: ['foo', 'bar'],
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('should default to empty filters', async () => {
|
|
40
|
-
const queryCache = new QueryCache()
|
|
41
|
-
|
|
42
|
-
queryCache.findAll()
|
|
43
|
-
|
|
44
|
-
expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({})
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
})
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { describe, expectTypeOf, it } from 'vitest'
|
|
2
|
-
import { QueryClient } from '../queryClient'
|
|
3
|
-
import type { DataTag, InfiniteData } from '@tanstack/query-core'
|
|
4
|
-
|
|
5
|
-
describe('getQueryData', () => {
|
|
6
|
-
it('should be typed if key is tagged', () => {
|
|
7
|
-
const queryKey = ['key'] as DataTag<Array<string>, number>
|
|
8
|
-
const queryClient = new QueryClient()
|
|
9
|
-
const data = queryClient.getQueryData(queryKey)
|
|
10
|
-
|
|
11
|
-
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
it('should infer unknown if key is not tagged', () => {
|
|
15
|
-
const queryKey = ['key'] as const
|
|
16
|
-
const queryClient = new QueryClient()
|
|
17
|
-
const data = queryClient.getQueryData(queryKey)
|
|
18
|
-
|
|
19
|
-
expectTypeOf(data).toEqualTypeOf<unknown>()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should infer passed generic if passed', () => {
|
|
23
|
-
const queryKey = ['key'] as const
|
|
24
|
-
const queryClient = new QueryClient()
|
|
25
|
-
const data = queryClient.getQueryData<number>(queryKey)
|
|
26
|
-
|
|
27
|
-
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should only allow Arrays to be passed', () => {
|
|
31
|
-
const queryKey = 'key'
|
|
32
|
-
const queryClient = new QueryClient()
|
|
33
|
-
// @ts-expect-error TS2345: Argument of type 'string' is not assignable to parameter of type 'QueryKey'
|
|
34
|
-
return queryClient.getQueryData(queryKey)
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe('setQueryData', () => {
|
|
39
|
-
it('updater should be typed if key is tagged', () => {
|
|
40
|
-
const queryKey = ['key'] as DataTag<Array<string>, number>
|
|
41
|
-
const queryClient = new QueryClient()
|
|
42
|
-
const data = queryClient.setQueryData(queryKey, (prev) => {
|
|
43
|
-
expectTypeOf(prev).toEqualTypeOf<number | undefined>()
|
|
44
|
-
return prev
|
|
45
|
-
})
|
|
46
|
-
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('value should be typed if key is tagged', () => {
|
|
50
|
-
const queryKey = ['key'] as DataTag<Array<string>, number>
|
|
51
|
-
const queryClient = new QueryClient()
|
|
52
|
-
|
|
53
|
-
// @ts-expect-error value should be a number
|
|
54
|
-
queryClient.setQueryData(queryKey, '1')
|
|
55
|
-
|
|
56
|
-
// @ts-expect-error value should be a number
|
|
57
|
-
queryClient.setQueryData(queryKey, () => '1')
|
|
58
|
-
|
|
59
|
-
const data = queryClient.setQueryData(queryKey, 1)
|
|
60
|
-
|
|
61
|
-
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('should infer unknown for updater if key is not tagged', () => {
|
|
65
|
-
const queryKey = ['key'] as const
|
|
66
|
-
const queryClient = new QueryClient()
|
|
67
|
-
const data = queryClient.setQueryData(queryKey, (prev) => {
|
|
68
|
-
expectTypeOf(prev).toEqualTypeOf<unknown>()
|
|
69
|
-
return prev
|
|
70
|
-
})
|
|
71
|
-
expectTypeOf(data).toEqualTypeOf<unknown>()
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it('should infer unknown for value if key is not tagged', () => {
|
|
75
|
-
const queryKey = ['key'] as const
|
|
76
|
-
const queryClient = new QueryClient()
|
|
77
|
-
const data = queryClient.setQueryData(queryKey, 'foo')
|
|
78
|
-
|
|
79
|
-
expectTypeOf(data).toEqualTypeOf<unknown>()
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('should infer passed generic if passed', () => {
|
|
83
|
-
const queryKey = ['key'] as const
|
|
84
|
-
const queryClient = new QueryClient()
|
|
85
|
-
const data = queryClient.setQueryData<string>(queryKey, (prev) => {
|
|
86
|
-
expectTypeOf(prev).toEqualTypeOf<string | undefined>()
|
|
87
|
-
return prev
|
|
88
|
-
})
|
|
89
|
-
expectTypeOf(data).toEqualTypeOf<string | undefined>()
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
it('should infer passed generic for value', () => {
|
|
93
|
-
const queryKey = ['key'] as const
|
|
94
|
-
const queryClient = new QueryClient()
|
|
95
|
-
const data = queryClient.setQueryData<string>(queryKey, 'foo')
|
|
96
|
-
|
|
97
|
-
expectTypeOf(data).toEqualTypeOf<string | undefined>()
|
|
98
|
-
})
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
describe('fetchInfiniteQuery', () => {
|
|
102
|
-
it('should allow passing pages', async () => {
|
|
103
|
-
const data = await new QueryClient().fetchInfiniteQuery({
|
|
104
|
-
queryKey: ['key'],
|
|
105
|
-
queryFn: () => Promise.resolve('string'),
|
|
106
|
-
getNextPageParam: () => 1,
|
|
107
|
-
initialPageParam: 1,
|
|
108
|
-
pages: 5,
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, number>>()
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('should not allow passing getNextPageParam without pages', () => {
|
|
115
|
-
new QueryClient().fetchInfiniteQuery({
|
|
116
|
-
queryKey: ['key'],
|
|
117
|
-
queryFn: () => Promise.resolve('string'),
|
|
118
|
-
initialPageParam: 1,
|
|
119
|
-
getNextPageParam: () => 1,
|
|
120
|
-
})
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('should not allow passing pages without getNextPageParam', () => {
|
|
124
|
-
// @ts-expect-error Property 'getNextPageParam' is missing
|
|
125
|
-
new QueryClient().fetchInfiniteQuery({
|
|
126
|
-
queryKey: ['key'],
|
|
127
|
-
queryFn: () => Promise.resolve('string'),
|
|
128
|
-
initialPageParam: 1,
|
|
129
|
-
pages: 5,
|
|
130
|
-
})
|
|
131
|
-
})
|
|
132
|
-
})
|