@tanstack/angular-query-experimental 5.17.9 → 5.17.10
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-query-experimental",
|
|
3
|
-
"version": "5.17.
|
|
3
|
+
"version": "5.17.10",
|
|
4
4
|
"description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
|
|
5
5
|
"author": "Arnoud de Vries",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"tslib": "^2.6.2",
|
|
37
|
-
"@tanstack/query-core": "5.17.
|
|
37
|
+
"@tanstack/query-core": "5.17.10"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@analogjs/vite-plugin-angular": "^0.2.29",
|
|
@@ -17,7 +17,7 @@ describe('injectIsFetching', () => {
|
|
|
17
17
|
})
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
test('Returns number of fetching queries', fakeAsync(() => {
|
|
21
21
|
const isFetching = TestBed.runInInjectionContext(() => {
|
|
22
22
|
injectQuery(() => ({
|
|
23
23
|
queryKey: ['isFetching1'],
|
|
@@ -17,7 +17,7 @@ describe('injectIsMutating', () => {
|
|
|
17
17
|
})
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
test('should properly return isMutating state', fakeAsync(() => {
|
|
21
21
|
TestBed.runInInjectionContext(() => {
|
|
22
22
|
const isMutating = injectIsMutating()
|
|
23
23
|
const mutation = injectMutation(() => ({
|
|
@@ -18,7 +18,7 @@ describe('injectQuery', () => {
|
|
|
18
18
|
})
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
test('should return pending status initially', fakeAsync(() => {
|
|
22
22
|
const query = TestBed.runInInjectionContext(() => {
|
|
23
23
|
return injectQuery(() => ({
|
|
24
24
|
queryKey: ['key1'],
|
|
@@ -35,7 +35,7 @@ describe('injectQuery', () => {
|
|
|
35
35
|
flush()
|
|
36
36
|
}))
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
test('should resolve to success and update signal: injectQuery()', fakeAsync(() => {
|
|
39
39
|
const query = TestBed.runInInjectionContext(() => {
|
|
40
40
|
return injectQuery(() => ({
|
|
41
41
|
queryKey: ['key2'],
|
|
@@ -53,7 +53,7 @@ describe('injectQuery', () => {
|
|
|
53
53
|
expect(query.isSuccess()).toBe(true)
|
|
54
54
|
}))
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
test('should reject and update signal', fakeAsync(() => {
|
|
57
57
|
const query = TestBed.runInInjectionContext(() => {
|
|
58
58
|
return injectQuery(() => ({
|
|
59
59
|
retry: false,
|
|
@@ -74,7 +74,7 @@ describe('injectQuery', () => {
|
|
|
74
74
|
expect(query.failureReason()).toMatchObject({ message: 'Some error' })
|
|
75
75
|
}))
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
test('should update query on options contained signal change', fakeAsync(() => {
|
|
78
78
|
const key = signal(['key6', 'key7'])
|
|
79
79
|
const spy = vi.fn(simpleFetcher)
|
|
80
80
|
|
|
@@ -97,7 +97,7 @@ describe('injectQuery', () => {
|
|
|
97
97
|
flush()
|
|
98
98
|
}))
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
test('should only run query once enabled signal is set to true', fakeAsync(() => {
|
|
101
101
|
const spy = vi.fn(simpleFetcher)
|
|
102
102
|
const enabled = signal(false)
|
|
103
103
|
|
|
@@ -119,7 +119,7 @@ describe('injectQuery', () => {
|
|
|
119
119
|
expect(query.status()).toBe('success')
|
|
120
120
|
}))
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
test('should properly execute dependant queries', fakeAsync(() => {
|
|
123
123
|
const query1 = TestBed.runInInjectionContext(() => {
|
|
124
124
|
return injectQuery(() => ({
|
|
125
125
|
queryKey: ['dependant1'],
|
|
@@ -159,7 +159,7 @@ describe('injectQuery', () => {
|
|
|
159
159
|
)
|
|
160
160
|
}))
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
test('should use the current value for the queryKey when refetch is called', fakeAsync(() => {
|
|
163
163
|
const fetchFn = vi.fn(simpleFetcher)
|
|
164
164
|
const keySignal = signal('key11')
|
|
165
165
|
|
|
@@ -200,7 +200,7 @@ describe('injectQuery', () => {
|
|
|
200
200
|
flush()
|
|
201
201
|
}))
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
test('should set state to error when queryFn returns reject promise', fakeAsync(() => {
|
|
204
204
|
const query = TestBed.runInInjectionContext(() => {
|
|
205
205
|
return injectQuery(() => ({
|
|
206
206
|
retry: false,
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { assertType, describe, expectTypeOf } from 'vitest'
|
|
2
|
+
import { QueryClient } from '@tanstack/query-core'
|
|
3
|
+
import { dataTagSymbol } from '@tanstack/query-core'
|
|
4
|
+
import { queryOptions } from '../query-options'
|
|
5
|
+
import { injectQuery } from '../inject-query'
|
|
6
|
+
import type { Signal } from '@angular/core'
|
|
7
|
+
|
|
8
|
+
describe('queryOptions', () => {
|
|
9
|
+
test('should not allow excess properties', () => {
|
|
10
|
+
return queryOptions({
|
|
11
|
+
queryKey: ['key'],
|
|
12
|
+
queryFn: () => Promise.resolve(5),
|
|
13
|
+
// @ts-expect-error this is a good error, because stallTime does not exist!
|
|
14
|
+
stallTime: 1000,
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('should infer types for callbacks', () => {
|
|
19
|
+
return queryOptions({
|
|
20
|
+
queryKey: ['key'],
|
|
21
|
+
queryFn: () => Promise.resolve(5),
|
|
22
|
+
staleTime: 1000,
|
|
23
|
+
select: (data) => {
|
|
24
|
+
expectTypeOf(data).toEqualTypeOf<number>()
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('should work when passed to injectQuery', () => {
|
|
31
|
+
const options = queryOptions({
|
|
32
|
+
queryKey: ['key'],
|
|
33
|
+
queryFn: () => Promise.resolve(5),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const { data } = injectQuery(() => options)
|
|
37
|
+
expectTypeOf(data).toEqualTypeOf<Signal<number | undefined>>()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('should work when passed to fetchQuery', () => {
|
|
41
|
+
const options = queryOptions({
|
|
42
|
+
queryKey: ['key'],
|
|
43
|
+
queryFn: () => Promise.resolve(5),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const data = new QueryClient().fetchQuery(options)
|
|
47
|
+
assertType<Promise<number>>(data)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('should tag the queryKey with the result type of the QueryFn', () => {
|
|
51
|
+
const { queryKey } = queryOptions({
|
|
52
|
+
queryKey: ['key'],
|
|
53
|
+
queryFn: () => Promise.resolve(5),
|
|
54
|
+
})
|
|
55
|
+
assertType<number>(queryKey[dataTagSymbol])
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('should tag the queryKey even if no promise is returned', () => {
|
|
59
|
+
const { queryKey } = queryOptions({
|
|
60
|
+
queryKey: ['key'],
|
|
61
|
+
queryFn: () => 5,
|
|
62
|
+
})
|
|
63
|
+
assertType<number>(queryKey[dataTagSymbol])
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('should tag the queryKey with unknown if there is no queryFn', () => {
|
|
67
|
+
const { queryKey } = queryOptions({
|
|
68
|
+
queryKey: ['key'],
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
assertType<unknown>(queryKey[dataTagSymbol])
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('should return the proper type when passed to getQueryData', () => {
|
|
75
|
+
const { queryKey } = queryOptions({
|
|
76
|
+
queryKey: ['key'],
|
|
77
|
+
queryFn: () => Promise.resolve(5),
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const queryClient = new QueryClient()
|
|
81
|
+
const data = queryClient.getQueryData(queryKey)
|
|
82
|
+
|
|
83
|
+
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('should properly type updaterFn when passed to setQueryData', () => {
|
|
87
|
+
const { queryKey } = queryOptions({
|
|
88
|
+
queryKey: ['key'],
|
|
89
|
+
queryFn: () => Promise.resolve(5),
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const queryClient = new QueryClient()
|
|
93
|
+
const data = queryClient.setQueryData(queryKey, (prev) => {
|
|
94
|
+
expectTypeOf(prev).toEqualTypeOf<number | undefined>()
|
|
95
|
+
return prev
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('should properly type value when passed to setQueryData', () => {
|
|
102
|
+
const { queryKey } = queryOptions({
|
|
103
|
+
queryKey: ['key'],
|
|
104
|
+
queryFn: () => Promise.resolve(5),
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const queryClient = new QueryClient()
|
|
108
|
+
|
|
109
|
+
// @ts-expect-error value should be a number
|
|
110
|
+
queryClient.setQueryData(queryKey, '5')
|
|
111
|
+
// @ts-expect-error value should be a number
|
|
112
|
+
queryClient.setQueryData(queryKey, () => '5')
|
|
113
|
+
|
|
114
|
+
const data = queryClient.setQueryData(queryKey, 5)
|
|
115
|
+
|
|
116
|
+
expectTypeOf(data).toEqualTypeOf<number | undefined>()
|
|
117
|
+
})
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { signal } from '@angular/core'
|
|
2
|
-
import { isReactive } from '@angular/core/primitives/signals'
|
|
1
|
+
import { isSignal, signal } from '@angular/core'
|
|
3
2
|
import { describe } from 'vitest'
|
|
4
3
|
import { signalProxy } from '../signal-proxy'
|
|
5
4
|
|
|
@@ -7,22 +6,22 @@ describe('signalProxy', () => {
|
|
|
7
6
|
const inputSignal = signal({ fn: () => 'bar', baz: 'qux' })
|
|
8
7
|
const proxy = signalProxy(inputSignal)
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
test('should have computed fields', () => {
|
|
11
10
|
expect(proxy.baz()).toEqual('qux')
|
|
12
|
-
expect(
|
|
11
|
+
expect(isSignal(proxy.baz)).toBe(true)
|
|
13
12
|
})
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
test('should pass through functions as-is', () => {
|
|
16
15
|
expect(proxy.fn()).toEqual('bar')
|
|
17
|
-
expect(
|
|
16
|
+
expect(isSignal(proxy.fn)).toBe(false)
|
|
18
17
|
})
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
test('supports "in" operator', () => {
|
|
21
20
|
expect('baz' in proxy).toBe(true)
|
|
22
21
|
expect('foo' in proxy).toBe(false)
|
|
23
22
|
})
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
test('supports "Object.keys"', () => {
|
|
26
25
|
expect(Object.keys(proxy)).toEqual(['fn', 'baz'])
|
|
27
26
|
})
|
|
28
27
|
})
|