@tanstack/solid-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.
@@ -1,81 +0,0 @@
1
- import { describe, expectTypeOf, it } from 'vitest'
2
- import { dataTagSymbol } from '@tanstack/query-core'
3
- import { createInfiniteQuery } from '../createInfiniteQuery'
4
- import { infiniteQueryOptions } from '../infiniteQueryOptions'
5
- import type { InfiniteData } from '@tanstack/query-core'
6
- import type {
7
- DefinedInitialDataInfiniteOptions,
8
- UndefinedInitialDataInfiniteOptions,
9
- } from '../infiniteQueryOptions'
10
-
11
- const doNotRun = (_callback: () => void) => {}
12
-
13
- describe('infiniteQueryOptions', () => {
14
- it('should infer defined types', () => {
15
- const options = infiniteQueryOptions({
16
- getNextPageParam: () => 10,
17
- queryKey: ['key'],
18
- queryFn: () => ({ wow: true }),
19
- initialData: {
20
- pageParams: [undefined],
21
- pages: [{ wow: true }],
22
- },
23
- initialPageParam: 0,
24
- })
25
-
26
- doNotRun(() => {
27
- expectTypeOf(createInfiniteQuery(() => options).data).toEqualTypeOf<
28
- InfiniteData<{ wow: boolean }, unknown>
29
- >()
30
-
31
- expectTypeOf(options).toMatchTypeOf<
32
- ReturnType<
33
- DefinedInitialDataInfiniteOptions<
34
- { wow: boolean },
35
- Error,
36
- InfiniteData<{ wow: boolean }, unknown>,
37
- Array<string>,
38
- number | undefined
39
- >
40
- >
41
- >()
42
-
43
- expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf<
44
- InfiniteData<{ wow: boolean }>
45
- >()
46
- })
47
- })
48
-
49
- it('should work without defined types', () => {
50
- const options = infiniteQueryOptions({
51
- getNextPageParam: () => undefined,
52
- queryKey: ['key'],
53
- queryFn: () => ({ wow: true }),
54
- initialPageParam: 0,
55
- })
56
-
57
- doNotRun(() => {
58
- expectTypeOf(() => createInfiniteQuery(() => options).data).toEqualTypeOf<
59
- () => InfiniteData<{ wow: boolean }, unknown> | undefined
60
- >()
61
-
62
- expectTypeOf(options).toMatchTypeOf<
63
- ReturnType<
64
- UndefinedInitialDataInfiniteOptions<
65
- { wow: boolean },
66
- Error,
67
- InfiniteData<{ wow: boolean }, unknown>,
68
- Array<string>,
69
- number
70
- >
71
- >
72
- >()
73
-
74
- expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf<
75
- InfiniteData<{
76
- wow: boolean
77
- }>
78
- >()
79
- })
80
- })
81
- })
@@ -1,146 +0,0 @@
1
- import { describe, expectTypeOf, it } from 'vitest'
2
- import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core'
3
- import { createQuery } from '../createQuery'
4
- import { queryOptions } from '../queryOptions'
5
-
6
- describe('queryOptions', () => {
7
- it('should not allow excess properties', () => {
8
- queryOptions({
9
- queryKey: ['key'],
10
- queryFn: () => Promise.resolve(5),
11
- // @ts-expect-error this is a good error, because stallTime does not exist!
12
- stallTime: 1000,
13
- })
14
- })
15
- it('should infer types for callbacks', () => {
16
- queryOptions({
17
- queryKey: ['key'],
18
- queryFn: () => Promise.resolve(5),
19
- staleTime: 1000,
20
- select: (data) => {
21
- expectTypeOf(data).toEqualTypeOf<number>()
22
- },
23
- })
24
- })
25
- it('should work when passed to createQuery', () => {
26
- const options = queryOptions({
27
- queryKey: ['key'],
28
- queryFn: () => Promise.resolve(5),
29
- })
30
-
31
- const { data } = createQuery(() => options)
32
- expectTypeOf(data).toEqualTypeOf<number | undefined>()
33
- })
34
- it('should work when passed to fetchQuery', async () => {
35
- const options = queryOptions({
36
- queryKey: ['key'],
37
- queryFn: () => Promise.resolve(5),
38
- })
39
-
40
- const data = await new QueryClient().fetchQuery(options)
41
- expectTypeOf(data).toEqualTypeOf<number>()
42
- })
43
- it('should tag the queryKey with the result type of the QueryFn', () => {
44
- const { queryKey } = queryOptions({
45
- queryKey: ['key'],
46
- queryFn: () => Promise.resolve(5),
47
- })
48
-
49
- expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<number>()
50
- })
51
- it('should tag the queryKey even if no promise is returned', () => {
52
- const { queryKey } = queryOptions({
53
- queryKey: ['key'],
54
- queryFn: () => 5,
55
- })
56
-
57
- expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<number>()
58
- })
59
- it('should tag the queryKey with unknown if there is no queryFn', () => {
60
- const { queryKey } = queryOptions({
61
- queryKey: ['key'],
62
- })
63
-
64
- expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<unknown>()
65
- })
66
- it('should tag the queryKey with the result type of the QueryFn if select is used', () => {
67
- const { queryKey } = queryOptions({
68
- queryKey: ['key'],
69
- queryFn: () => Promise.resolve(5),
70
- select: (data) => data.toString(),
71
- })
72
-
73
- expectTypeOf(queryKey[dataTagSymbol]).toEqualTypeOf<number>()
74
- })
75
- it('should return the proper type when passed to getQueryData', () => {
76
- const { queryKey } = queryOptions({
77
- queryKey: ['key'],
78
- queryFn: () => Promise.resolve(5),
79
- })
80
-
81
- const queryClient = new QueryClient()
82
- const data = queryClient.getQueryData(queryKey)
83
- expectTypeOf(data).toEqualTypeOf<number | undefined>()
84
- })
85
- it('should return the proper type when passed to getQueryState', () => {
86
- const { queryKey } = queryOptions({
87
- queryKey: ['key'],
88
- queryFn: () => Promise.resolve(5),
89
- })
90
-
91
- const queryClient = new QueryClient()
92
- const state = queryClient.getQueryState(queryKey)
93
- expectTypeOf(state?.data).toEqualTypeOf<number | undefined>()
94
- })
95
- it('should properly type updaterFn when passed to setQueryData', () => {
96
- const { queryKey } = queryOptions({
97
- queryKey: ['key'],
98
- queryFn: () => Promise.resolve(5),
99
- })
100
-
101
- const queryClient = new QueryClient()
102
- const data = queryClient.setQueryData(queryKey, (prev) => {
103
- expectTypeOf(prev).toEqualTypeOf<number | undefined>()
104
- return prev
105
- })
106
- expectTypeOf(data).toEqualTypeOf<number | undefined>()
107
- })
108
- it('should properly type value when passed to setQueryData', () => {
109
- const { queryKey } = queryOptions({
110
- queryKey: ['key'],
111
- queryFn: () => Promise.resolve(5),
112
- })
113
-
114
- const queryClient = new QueryClient()
115
-
116
- // @ts-expect-error value should be a number
117
- queryClient.setQueryData(queryKey, '5')
118
- // @ts-expect-error value should be a number
119
- queryClient.setQueryData(queryKey, () => '5')
120
-
121
- const data = queryClient.setQueryData(queryKey, 5)
122
- expectTypeOf(data).toEqualTypeOf<number | undefined>()
123
- })
124
-
125
- it('should infer even if there is a conditional skipToken', () => {
126
- const options = queryOptions({
127
- queryKey: ['key'],
128
- queryFn: Math.random() > 0.5 ? skipToken : () => Promise.resolve(5),
129
- })
130
-
131
- const queryClient = new QueryClient()
132
- const data = queryClient.getQueryData(options.queryKey)
133
- expectTypeOf(data).toEqualTypeOf<number | undefined>()
134
- })
135
-
136
- it('should infer to unknown if we disable a query with just a skipToken', () => {
137
- const options = queryOptions({
138
- queryKey: ['key'],
139
- queryFn: skipToken,
140
- })
141
-
142
- const queryClient = new QueryClient()
143
- const data = queryClient.getQueryData(options.queryKey)
144
- expectTypeOf(data).toEqualTypeOf<unknown>()
145
- })
146
- })