@tanstack/solid-query 5.0.0-beta.18 → 5.0.0-beta.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/build/index.d.cts +3 -3
- package/build/index.d.ts +3 -3
- package/package.json +2 -2
- package/src/__tests__/createInfiniteQuery.test.tsx +36 -29
- package/src/__tests__/createMutation.test.tsx +4 -4
- package/src/__tests__/createQueries.test.tsx +30 -28
- package/src/__tests__/createQuery.test.tsx +74 -72
- package/src/__tests__/suspense.test.tsx +4 -4
- package/src/__tests__/useIsFetching.test.tsx +2 -2
- package/src/__tests__/useIsMutating.test.tsx +3 -3
- package/src/createQueries.ts +35 -27
- package/src/utils.ts +1 -1
package/build/index.d.cts
CHANGED
|
@@ -129,12 +129,12 @@ type GetResults<T> = T extends {
|
|
|
129
129
|
/**
|
|
130
130
|
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
131
131
|
*/
|
|
132
|
-
type QueriesOptions<T extends any
|
|
132
|
+
type QueriesOptions<T extends Array<any>, Result extends Array<any> = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryOptionsForCreateQueries> : T extends [] ? [] : T extends [infer Head] ? [...Result, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]> : Array<unknown> extends T ? T : T extends Array<CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>> : Array<CreateQueryOptionsForCreateQueries>;
|
|
133
133
|
/**
|
|
134
134
|
* QueriesResults reducer recursively maps type param to results
|
|
135
135
|
*/
|
|
136
|
-
type QueriesResults<T extends any
|
|
137
|
-
declare function createQueries<T extends any
|
|
136
|
+
type QueriesResults<T extends Array<any>, Result extends Array<any> = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends Array<CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>> ? Array<CreateQueryResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>> : Array<CreateQueryResult>;
|
|
137
|
+
declare function createQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>(queriesOptions: Accessor<{
|
|
138
138
|
queries: readonly [...QueriesOptions<T>];
|
|
139
139
|
combine?: (result: QueriesResults<T>) => TCombinedResult;
|
|
140
140
|
}>, queryClient?: Accessor<QueryClient>): TCombinedResult;
|
package/build/index.d.ts
CHANGED
|
@@ -129,12 +129,12 @@ type GetResults<T> = T extends {
|
|
|
129
129
|
/**
|
|
130
130
|
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
131
131
|
*/
|
|
132
|
-
type QueriesOptions<T extends any
|
|
132
|
+
type QueriesOptions<T extends Array<any>, Result extends Array<any> = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryOptionsForCreateQueries> : T extends [] ? [] : T extends [infer Head] ? [...Result, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]> : Array<unknown> extends T ? T : T extends Array<CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>> : Array<CreateQueryOptionsForCreateQueries>;
|
|
133
133
|
/**
|
|
134
134
|
* QueriesResults reducer recursively maps type param to results
|
|
135
135
|
*/
|
|
136
|
-
type QueriesResults<T extends any
|
|
137
|
-
declare function createQueries<T extends any
|
|
136
|
+
type QueriesResults<T extends Array<any>, Result extends Array<any> = [], Depth extends ReadonlyArray<number> = []> = Depth['length'] extends MAXIMUM_DEPTH ? Array<CreateQueryResult> : T extends [] ? [] : T extends [infer Head] ? [...Result, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]> : T extends Array<CreateQueryOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>> ? Array<CreateQueryResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>> : Array<CreateQueryResult>;
|
|
137
|
+
declare function createQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>(queriesOptions: Accessor<{
|
|
138
138
|
queries: readonly [...QueriesOptions<T>];
|
|
139
139
|
combine?: (result: QueriesResults<T>) => TCombinedResult;
|
|
140
140
|
}>, queryClient?: Accessor<QueryClient>): TCombinedResult;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-query",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.20",
|
|
4
4
|
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"solid-js": "^1.7.8",
|
|
51
|
-
"@tanstack/query-core": "5.0.0-beta.
|
|
51
|
+
"@tanstack/query-core": "5.0.0-beta.20"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsup-preset-solid": "^2.0.1",
|
|
@@ -33,7 +33,7 @@ import type {
|
|
|
33
33
|
import type { Mock } from 'vitest'
|
|
34
34
|
|
|
35
35
|
interface Result {
|
|
36
|
-
items: number
|
|
36
|
+
items: Array<number>
|
|
37
37
|
nextId?: number
|
|
38
38
|
prevId?: number
|
|
39
39
|
ts: number
|
|
@@ -62,7 +62,7 @@ describe('useInfiniteQuery', () => {
|
|
|
62
62
|
|
|
63
63
|
it('should return the correct states for a successful query', async () => {
|
|
64
64
|
const key = queryKey()
|
|
65
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
65
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
66
66
|
|
|
67
67
|
function Page() {
|
|
68
68
|
const state = createInfiniteQuery(() => ({
|
|
@@ -199,8 +199,9 @@ describe('useInfiniteQuery', () => {
|
|
|
199
199
|
|
|
200
200
|
it('should keep the previous data when placeholderData is set', async () => {
|
|
201
201
|
const key = queryKey()
|
|
202
|
-
const states:
|
|
203
|
-
|
|
202
|
+
const states: Array<
|
|
203
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<string>>>
|
|
204
|
+
> = []
|
|
204
205
|
|
|
205
206
|
function Page() {
|
|
206
207
|
const [order, setOrder] = createSignal('desc')
|
|
@@ -304,7 +305,7 @@ describe('useInfiniteQuery', () => {
|
|
|
304
305
|
|
|
305
306
|
it('should be able to select a part of the data', async () => {
|
|
306
307
|
const key = queryKey()
|
|
307
|
-
const states: CreateInfiniteQueryResult<InfiniteData<string
|
|
308
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<string>>> = []
|
|
308
309
|
|
|
309
310
|
function Page() {
|
|
310
311
|
const state = createInfiniteQuery(() => ({
|
|
@@ -344,9 +345,9 @@ describe('useInfiniteQuery', () => {
|
|
|
344
345
|
|
|
345
346
|
it('should be able to select a new result and not cause infinite renders', async () => {
|
|
346
347
|
const key = queryKey()
|
|
347
|
-
const states:
|
|
348
|
-
InfiniteData<{ count: number; id: number }
|
|
349
|
-
>
|
|
348
|
+
const states: Array<
|
|
349
|
+
CreateInfiniteQueryResult<InfiniteData<{ count: number; id: number }>>
|
|
350
|
+
> = []
|
|
350
351
|
let selectCalled = 0
|
|
351
352
|
|
|
352
353
|
function Page() {
|
|
@@ -391,8 +392,9 @@ describe('useInfiniteQuery', () => {
|
|
|
391
392
|
|
|
392
393
|
it('should be able to reverse the data', async () => {
|
|
393
394
|
const key = queryKey()
|
|
394
|
-
const states:
|
|
395
|
-
|
|
395
|
+
const states: Array<
|
|
396
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
397
|
+
> = []
|
|
396
398
|
|
|
397
399
|
function Page() {
|
|
398
400
|
const state = createInfiniteQuery(() => ({
|
|
@@ -466,8 +468,9 @@ describe('useInfiniteQuery', () => {
|
|
|
466
468
|
|
|
467
469
|
it('should be able to fetch a previous page', async () => {
|
|
468
470
|
const key = queryKey()
|
|
469
|
-
const states:
|
|
470
|
-
|
|
471
|
+
const states: Array<
|
|
472
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
473
|
+
> = []
|
|
471
474
|
|
|
472
475
|
function Page() {
|
|
473
476
|
const start = 10
|
|
@@ -554,8 +557,9 @@ describe('useInfiniteQuery', () => {
|
|
|
554
557
|
|
|
555
558
|
it('should be able to refetch when providing page params automatically', async () => {
|
|
556
559
|
const key = queryKey()
|
|
557
|
-
const states:
|
|
558
|
-
|
|
560
|
+
const states: Array<
|
|
561
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
562
|
+
> = []
|
|
559
563
|
|
|
560
564
|
function Page() {
|
|
561
565
|
const state = createInfiniteQuery(() => ({
|
|
@@ -675,8 +679,9 @@ describe('useInfiniteQuery', () => {
|
|
|
675
679
|
|
|
676
680
|
it('should silently cancel any ongoing fetch when fetching more', async () => {
|
|
677
681
|
const key = queryKey()
|
|
678
|
-
const states:
|
|
679
|
-
|
|
682
|
+
const states: Array<
|
|
683
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
684
|
+
> = []
|
|
680
685
|
|
|
681
686
|
function Page() {
|
|
682
687
|
const start = 10
|
|
@@ -764,8 +769,8 @@ describe('useInfiniteQuery', () => {
|
|
|
764
769
|
it('should silently cancel an ongoing fetchNextPage request when another fetchNextPage is invoked', async () => {
|
|
765
770
|
const key = queryKey()
|
|
766
771
|
const start = 10
|
|
767
|
-
const onAborts: Mock<any, any
|
|
768
|
-
const abortListeners: Mock<any, any
|
|
772
|
+
const onAborts: Array<Mock<any, any>> = []
|
|
773
|
+
const abortListeners: Array<Mock<any, any>> = []
|
|
769
774
|
const fetchPage = vi.fn<
|
|
770
775
|
[QueryFunctionContext<typeof key, number>],
|
|
771
776
|
Promise<number>
|
|
@@ -846,8 +851,8 @@ describe('useInfiniteQuery', () => {
|
|
|
846
851
|
it('should not cancel an ongoing fetchNextPage request when another fetchNextPage is invoked if `cancelRefetch: false` is used ', async () => {
|
|
847
852
|
const key = queryKey()
|
|
848
853
|
const start = 10
|
|
849
|
-
const onAborts: Mock<any, any
|
|
850
|
-
const abortListeners: Mock<any, any
|
|
854
|
+
const onAborts: Array<Mock<any, any>> = []
|
|
855
|
+
const abortListeners: Array<Mock<any, any>> = []
|
|
851
856
|
const fetchPage = vi.fn<
|
|
852
857
|
[QueryFunctionContext<typeof key, number>],
|
|
853
858
|
Promise<number>
|
|
@@ -918,7 +923,7 @@ describe('useInfiniteQuery', () => {
|
|
|
918
923
|
|
|
919
924
|
it('should keep fetching first page when not loaded yet and triggering fetch more', async () => {
|
|
920
925
|
const key = queryKey()
|
|
921
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
926
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
922
927
|
|
|
923
928
|
function Page() {
|
|
924
929
|
const start = 10
|
|
@@ -1028,8 +1033,9 @@ describe('useInfiniteQuery', () => {
|
|
|
1028
1033
|
|
|
1029
1034
|
it('should be able to set new pages with the query client', async () => {
|
|
1030
1035
|
const key = queryKey()
|
|
1031
|
-
const states:
|
|
1032
|
-
|
|
1036
|
+
const states: Array<
|
|
1037
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
1038
|
+
> = []
|
|
1033
1039
|
|
|
1034
1040
|
function Page() {
|
|
1035
1041
|
const [firstPage, setFirstPage] = createSignal(0)
|
|
@@ -1123,8 +1129,9 @@ describe('useInfiniteQuery', () => {
|
|
|
1123
1129
|
|
|
1124
1130
|
it('should only refetch the first page when initialData is provided', async () => {
|
|
1125
1131
|
const key = queryKey()
|
|
1126
|
-
const states:
|
|
1127
|
-
|
|
1132
|
+
const states: Array<
|
|
1133
|
+
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
|
|
1134
|
+
> = []
|
|
1128
1135
|
|
|
1129
1136
|
function Page() {
|
|
1130
1137
|
const state = createInfiniteQuery(() => ({
|
|
@@ -1201,7 +1208,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1201
1208
|
|
|
1202
1209
|
it('should set hasNextPage to false if getNextPageParam returns undefined', async () => {
|
|
1203
1210
|
const key = queryKey()
|
|
1204
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
1211
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1205
1212
|
|
|
1206
1213
|
function Page() {
|
|
1207
1214
|
const state = createInfiniteQuery(() => ({
|
|
@@ -1245,7 +1252,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1245
1252
|
|
|
1246
1253
|
it('should compute hasNextPage correctly using initialData', async () => {
|
|
1247
1254
|
const key = queryKey()
|
|
1248
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
1255
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1249
1256
|
|
|
1250
1257
|
function Page() {
|
|
1251
1258
|
const state = createInfiniteQuery(() => ({
|
|
@@ -1289,7 +1296,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1289
1296
|
|
|
1290
1297
|
it('should compute hasNextPage correctly for falsy getFetchMore return value using initialData', async () => {
|
|
1291
1298
|
const key = queryKey()
|
|
1292
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
1299
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
1293
1300
|
|
|
1294
1301
|
function Page() {
|
|
1295
1302
|
const state = createInfiniteQuery(() => ({
|
|
@@ -1333,7 +1340,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1333
1340
|
|
|
1334
1341
|
it('should not use selected data when computing hasNextPage', async () => {
|
|
1335
1342
|
const key = queryKey()
|
|
1336
|
-
const states: CreateInfiniteQueryResult<InfiniteData<string
|
|
1343
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<string>>> = []
|
|
1337
1344
|
|
|
1338
1345
|
function Page() {
|
|
1339
1346
|
const state = createInfiniteQuery(() => ({
|
|
@@ -318,7 +318,7 @@ describe('createMutation', () => {
|
|
|
318
318
|
})
|
|
319
319
|
|
|
320
320
|
it('should be able to override the useMutation success callbacks', async () => {
|
|
321
|
-
const callbacks: string
|
|
321
|
+
const callbacks: Array<string> = []
|
|
322
322
|
|
|
323
323
|
function Page() {
|
|
324
324
|
const mutation = createMutation(() => ({
|
|
@@ -369,7 +369,7 @@ describe('createMutation', () => {
|
|
|
369
369
|
})
|
|
370
370
|
|
|
371
371
|
it('should be able to override the error callbacks when using mutateAsync', async () => {
|
|
372
|
-
const callbacks: string
|
|
372
|
+
const callbacks: Array<string> = []
|
|
373
373
|
|
|
374
374
|
function Page() {
|
|
375
375
|
const mutation = createMutation(() => ({
|
|
@@ -431,7 +431,7 @@ describe('createMutation', () => {
|
|
|
431
431
|
},
|
|
432
432
|
})
|
|
433
433
|
|
|
434
|
-
const states: CreateMutationResult<any, any, any, any
|
|
434
|
+
const states: Array<CreateMutationResult<any, any, any, any>> = []
|
|
435
435
|
|
|
436
436
|
function Page() {
|
|
437
437
|
const mutation = createMutation<string, unknown, string>(() => ({
|
|
@@ -676,7 +676,7 @@ describe('createMutation', () => {
|
|
|
676
676
|
const onlineMock = mockOnlineManagerIsOnline(false)
|
|
677
677
|
|
|
678
678
|
let count = 0
|
|
679
|
-
const states: CreateMutationResult<any, any, any, any
|
|
679
|
+
const states: Array<CreateMutationResult<any, any, any, any>> = []
|
|
680
680
|
|
|
681
681
|
function Page() {
|
|
682
682
|
const mutation = createMutation(() => ({
|
|
@@ -31,7 +31,7 @@ describe('useQueries', () => {
|
|
|
31
31
|
it('should return the correct states', async () => {
|
|
32
32
|
const key1 = queryKey()
|
|
33
33
|
const key2 = queryKey()
|
|
34
|
-
const results: CreateQueryResult
|
|
34
|
+
const results: Array<Array<CreateQueryResult>> = []
|
|
35
35
|
|
|
36
36
|
function Page() {
|
|
37
37
|
const result = createQueries(() => ({
|
|
@@ -89,30 +89,30 @@ describe('useQueries', () => {
|
|
|
89
89
|
// @ts-expect-error (Page component is not rendered)
|
|
90
90
|
// eslint-disable-next-line
|
|
91
91
|
function Page() {
|
|
92
|
-
const result1 = createQueries<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
92
|
+
const result1 = createQueries<
|
|
93
|
+
[[number], [string], [Array<string>, boolean]]
|
|
94
|
+
>(() => ({
|
|
95
|
+
queries: [
|
|
96
|
+
{
|
|
97
|
+
queryKey: key1,
|
|
98
|
+
queryFn: () => 1,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
queryKey: key2,
|
|
102
|
+
queryFn: () => 'string',
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
queryKey: key3,
|
|
106
|
+
queryFn: () => ['string[]'],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
}))
|
|
110
110
|
expectType<QueryObserverResult<number, unknown>>(result1[0])
|
|
111
111
|
expectType<QueryObserverResult<string, unknown>>(result1[1])
|
|
112
|
-
expectType<QueryObserverResult<string
|
|
112
|
+
expectType<QueryObserverResult<Array<string>, boolean>>(result1[2])
|
|
113
113
|
expectType<number | undefined>(result1[0].data)
|
|
114
114
|
expectType<string | undefined>(result1[1].data)
|
|
115
|
-
expectType<string
|
|
115
|
+
expectType<Array<string> | undefined>(result1[2].data)
|
|
116
116
|
expectType<boolean | null>(result1[2].error)
|
|
117
117
|
|
|
118
118
|
// TData (3rd element) takes precedence over TQueryFnData (1st element)
|
|
@@ -201,7 +201,7 @@ describe('useQueries', () => {
|
|
|
201
201
|
[
|
|
202
202
|
{ queryFnData: number },
|
|
203
203
|
{ queryFnData: string },
|
|
204
|
-
{ queryFnData: string
|
|
204
|
+
{ queryFnData: Array<string>; error: boolean },
|
|
205
205
|
]
|
|
206
206
|
>(() => ({
|
|
207
207
|
queries: [
|
|
@@ -221,10 +221,10 @@ describe('useQueries', () => {
|
|
|
221
221
|
}))
|
|
222
222
|
expectType<QueryObserverResult<number, unknown>>(result1[0])
|
|
223
223
|
expectType<QueryObserverResult<string, unknown>>(result1[1])
|
|
224
|
-
expectType<QueryObserverResult<string
|
|
224
|
+
expectType<QueryObserverResult<Array<string>, boolean>>(result1[2])
|
|
225
225
|
expectType<number | undefined>(result1[0].data)
|
|
226
226
|
expectType<string | undefined>(result1[1].data)
|
|
227
|
-
expectType<string
|
|
227
|
+
expectType<Array<string> | undefined>(result1[2].data)
|
|
228
228
|
expectType<boolean | null>(result1[2].error)
|
|
229
229
|
|
|
230
230
|
// TData (data prop) takes precedence over TQueryFnData (queryFnData prop)
|
|
@@ -353,7 +353,7 @@ describe('useQueries', () => {
|
|
|
353
353
|
queryFn: () => i + 10,
|
|
354
354
|
})),
|
|
355
355
|
}))
|
|
356
|
-
expectType<QueryObserverResult<number, unknown
|
|
356
|
+
expectType<Array<QueryObserverResult<number, unknown>>>(result1)
|
|
357
357
|
expectType<number | undefined>(result1[0]?.data)
|
|
358
358
|
|
|
359
359
|
// Array.map preserves TData
|
|
@@ -364,7 +364,7 @@ describe('useQueries', () => {
|
|
|
364
364
|
select: (data: number) => data.toString(),
|
|
365
365
|
})),
|
|
366
366
|
}))
|
|
367
|
-
expectType<QueryObserverResult<string, unknown
|
|
367
|
+
expectType<Array<QueryObserverResult<string, unknown>>>(result2)
|
|
368
368
|
|
|
369
369
|
const result3 = createQueries(() => ({
|
|
370
370
|
queries: [
|
|
@@ -582,7 +582,9 @@ describe('useQueries', () => {
|
|
|
582
582
|
TError,
|
|
583
583
|
TData,
|
|
584
584
|
TQueryKey extends QueryKey,
|
|
585
|
-
>(
|
|
585
|
+
>(
|
|
586
|
+
queries: Array<SolidQueryOptions<TQueryFnData, TError, TData, TQueryKey>>,
|
|
587
|
+
) {
|
|
586
588
|
return createQueries(() => ({
|
|
587
589
|
queries: queries.map(
|
|
588
590
|
// no need to type the mapped query
|
|
@@ -650,7 +652,7 @@ describe('useQueries', () => {
|
|
|
650
652
|
})),
|
|
651
653
|
)
|
|
652
654
|
|
|
653
|
-
expectType<QueryObserverResult<number | undefined, unknown
|
|
655
|
+
expectType<Array<QueryObserverResult<number | undefined, unknown>>>(
|
|
654
656
|
withWrappedQueries,
|
|
655
657
|
)
|
|
656
658
|
}
|
|
@@ -227,7 +227,7 @@ describe('createQuery', () => {
|
|
|
227
227
|
|
|
228
228
|
it('should return the correct states for a successful query', async () => {
|
|
229
229
|
const key = queryKey()
|
|
230
|
-
const states: CreateQueryResult<string
|
|
230
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
231
231
|
|
|
232
232
|
function Page(): JSX.Element {
|
|
233
233
|
const state = createQuery<string, Error>(() => ({
|
|
@@ -333,7 +333,7 @@ describe('createQuery', () => {
|
|
|
333
333
|
it('should return the correct states for an unsuccessful query', async () => {
|
|
334
334
|
const key = queryKey()
|
|
335
335
|
|
|
336
|
-
const states: CreateQueryResult<unknown, Error
|
|
336
|
+
const states: Array<CreateQueryResult<unknown, Error>> = []
|
|
337
337
|
|
|
338
338
|
function Page() {
|
|
339
339
|
const state = createQuery(() => ({
|
|
@@ -448,7 +448,7 @@ describe('createQuery', () => {
|
|
|
448
448
|
|
|
449
449
|
it('should set isFetchedAfterMount to true after a query has been fetched', async () => {
|
|
450
450
|
const key = queryKey()
|
|
451
|
-
const states: CreateQueryResult<string
|
|
451
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
452
452
|
|
|
453
453
|
await queryClient.prefetchQuery({
|
|
454
454
|
queryKey: key,
|
|
@@ -605,7 +605,7 @@ describe('createQuery', () => {
|
|
|
605
605
|
|
|
606
606
|
it('should be able to watch a query without providing a query function', async () => {
|
|
607
607
|
const key = queryKey()
|
|
608
|
-
const states: CreateQueryResult<string
|
|
608
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
609
609
|
|
|
610
610
|
queryClient.setQueryDefaults(key, { queryFn: () => 'data' })
|
|
611
611
|
|
|
@@ -632,7 +632,7 @@ describe('createQuery', () => {
|
|
|
632
632
|
|
|
633
633
|
it('should pick up a query when re-mounting with gcTime 0', async () => {
|
|
634
634
|
const key = queryKey()
|
|
635
|
-
const states: CreateQueryResult<string
|
|
635
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
636
636
|
|
|
637
637
|
function Page() {
|
|
638
638
|
const [toggle, setToggle] = createSignal(false)
|
|
@@ -712,7 +712,7 @@ describe('createQuery', () => {
|
|
|
712
712
|
|
|
713
713
|
it('should fetch when refetchOnMount is false and nothing has been fetched yet', async () => {
|
|
714
714
|
const key = queryKey()
|
|
715
|
-
const states: CreateQueryResult<string
|
|
715
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
716
716
|
|
|
717
717
|
function Page() {
|
|
718
718
|
const state = createQuery(() => ({
|
|
@@ -741,7 +741,7 @@ describe('createQuery', () => {
|
|
|
741
741
|
|
|
742
742
|
it('should not fetch when refetchOnMount is false and data has been fetched already', async () => {
|
|
743
743
|
const key = queryKey()
|
|
744
|
-
const states: CreateQueryResult<string
|
|
744
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
745
745
|
|
|
746
746
|
queryClient.setQueryData(key, 'prefetched')
|
|
747
747
|
|
|
@@ -771,7 +771,7 @@ describe('createQuery', () => {
|
|
|
771
771
|
|
|
772
772
|
it('should be able to select a part of the data with select', async () => {
|
|
773
773
|
const key = queryKey()
|
|
774
|
-
const states: CreateQueryResult<string
|
|
774
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
775
775
|
|
|
776
776
|
function Page() {
|
|
777
777
|
const state = createQuery(() => ({
|
|
@@ -800,7 +800,7 @@ describe('createQuery', () => {
|
|
|
800
800
|
|
|
801
801
|
it('should be able to select a part of the data with select in object syntax', async () => {
|
|
802
802
|
const key = queryKey()
|
|
803
|
-
const states: CreateQueryResult<string
|
|
803
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
804
804
|
|
|
805
805
|
function Page() {
|
|
806
806
|
const state = createQuery(() => ({
|
|
@@ -829,7 +829,7 @@ describe('createQuery', () => {
|
|
|
829
829
|
|
|
830
830
|
it('should be able to select a part of the data with select in object syntax', async () => {
|
|
831
831
|
const key = queryKey()
|
|
832
|
-
const states: CreateQueryResult<string
|
|
832
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
833
833
|
|
|
834
834
|
function Page() {
|
|
835
835
|
const state = createQuery(() => ({
|
|
@@ -858,7 +858,7 @@ describe('createQuery', () => {
|
|
|
858
858
|
|
|
859
859
|
it('should not re-render when it should only re-render only data change and the selected data did not change', async () => {
|
|
860
860
|
const key = queryKey()
|
|
861
|
-
const states: CreateQueryResult<string
|
|
861
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
862
862
|
|
|
863
863
|
function Page() {
|
|
864
864
|
const state = createQuery(() => ({
|
|
@@ -898,7 +898,7 @@ describe('createQuery', () => {
|
|
|
898
898
|
|
|
899
899
|
it('should throw an error when a selector throws', async () => {
|
|
900
900
|
const key = queryKey()
|
|
901
|
-
const states: CreateQueryResult<string
|
|
901
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
902
902
|
const error = new Error('Select Error')
|
|
903
903
|
|
|
904
904
|
function Page() {
|
|
@@ -931,7 +931,7 @@ describe('createQuery', () => {
|
|
|
931
931
|
|
|
932
932
|
it('should track properties and only re-render when a tracked property changes', async () => {
|
|
933
933
|
const key = queryKey()
|
|
934
|
-
const states: CreateQueryResult<string
|
|
934
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
935
935
|
|
|
936
936
|
function Page() {
|
|
937
937
|
const state = createQuery(() => ({
|
|
@@ -979,7 +979,7 @@ describe('createQuery', () => {
|
|
|
979
979
|
it('should always re-render if we are tracking props but not using any', async () => {
|
|
980
980
|
const key = queryKey()
|
|
981
981
|
let renderCount = 0
|
|
982
|
-
const states: CreateQueryResult<string
|
|
982
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
983
983
|
|
|
984
984
|
function Page() {
|
|
985
985
|
const state = createQuery(() => ({
|
|
@@ -1032,7 +1032,7 @@ describe('createQuery', () => {
|
|
|
1032
1032
|
{ id: '2', done: true },
|
|
1033
1033
|
]
|
|
1034
1034
|
|
|
1035
|
-
const states: CreateQueryResult<typeof result1
|
|
1035
|
+
const states: Array<CreateQueryResult<typeof result1>> = []
|
|
1036
1036
|
|
|
1037
1037
|
let count = 0
|
|
1038
1038
|
|
|
@@ -1091,7 +1091,7 @@ describe('createQuery', () => {
|
|
|
1091
1091
|
|
|
1092
1092
|
it('should use query function from hook when the existing query does not have a query function', async () => {
|
|
1093
1093
|
const key = queryKey()
|
|
1094
|
-
const results: CreateQueryResult<string
|
|
1094
|
+
const results: Array<CreateQueryResult<string>> = []
|
|
1095
1095
|
|
|
1096
1096
|
queryClient.setQueryData(key, 'set')
|
|
1097
1097
|
|
|
@@ -1140,7 +1140,7 @@ describe('createQuery', () => {
|
|
|
1140
1140
|
|
|
1141
1141
|
it('should update query stale state and refetch when invalidated with invalidateQueries', async () => {
|
|
1142
1142
|
const key = queryKey()
|
|
1143
|
-
const states: CreateQueryResult<number
|
|
1143
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1144
1144
|
let count = 0
|
|
1145
1145
|
|
|
1146
1146
|
function Page() {
|
|
@@ -1214,7 +1214,7 @@ describe('createQuery', () => {
|
|
|
1214
1214
|
|
|
1215
1215
|
it('should not update disabled query when refetched with refetchQueries', async () => {
|
|
1216
1216
|
const key = queryKey()
|
|
1217
|
-
const states: CreateQueryResult<number
|
|
1217
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1218
1218
|
let count = 0
|
|
1219
1219
|
|
|
1220
1220
|
function Page() {
|
|
@@ -1260,7 +1260,7 @@ describe('createQuery', () => {
|
|
|
1260
1260
|
|
|
1261
1261
|
it('should not refetch disabled query when invalidated with invalidateQueries', async () => {
|
|
1262
1262
|
const key = queryKey()
|
|
1263
|
-
const states: CreateQueryResult<number
|
|
1263
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1264
1264
|
let count = 0
|
|
1265
1265
|
|
|
1266
1266
|
function Page() {
|
|
@@ -1306,7 +1306,7 @@ describe('createQuery', () => {
|
|
|
1306
1306
|
|
|
1307
1307
|
it('should not fetch when switching to a disabled query', async () => {
|
|
1308
1308
|
const key = queryKey()
|
|
1309
|
-
const states: CreateQueryResult<number
|
|
1309
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1310
1310
|
|
|
1311
1311
|
function Page() {
|
|
1312
1312
|
const [count, setCount] = createSignal(0)
|
|
@@ -1363,7 +1363,7 @@ describe('createQuery', () => {
|
|
|
1363
1363
|
|
|
1364
1364
|
it('should keep the previous data when placeholderData is set', async () => {
|
|
1365
1365
|
const key = queryKey()
|
|
1366
|
-
const states: CreateQueryResult<number
|
|
1366
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1367
1367
|
|
|
1368
1368
|
function Page() {
|
|
1369
1369
|
const [count, setCount] = createSignal(0)
|
|
@@ -1430,7 +1430,7 @@ describe('createQuery', () => {
|
|
|
1430
1430
|
|
|
1431
1431
|
it('should not show initial data from next query if placeholderData is set', async () => {
|
|
1432
1432
|
const key = queryKey()
|
|
1433
|
-
const states: DefinedCreateQueryResult<number
|
|
1433
|
+
const states: Array<DefinedCreateQueryResult<number>> = []
|
|
1434
1434
|
|
|
1435
1435
|
function Page() {
|
|
1436
1436
|
const [count, setCount] = createSignal(0)
|
|
@@ -1510,7 +1510,7 @@ describe('createQuery', () => {
|
|
|
1510
1510
|
|
|
1511
1511
|
it('should keep the previous data on disabled query when placeholderData is set to identity function', async () => {
|
|
1512
1512
|
const key = queryKey()
|
|
1513
|
-
const states: CreateQueryResult<number
|
|
1513
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1514
1514
|
|
|
1515
1515
|
function Page() {
|
|
1516
1516
|
const [count, setCount] = createSignal(0)
|
|
@@ -1602,7 +1602,7 @@ describe('createQuery', () => {
|
|
|
1602
1602
|
|
|
1603
1603
|
it('should keep the previous data on disabled query when placeholderData is set and switching query key multiple times', async () => {
|
|
1604
1604
|
const key = queryKey()
|
|
1605
|
-
const states: CreateQueryResult<number
|
|
1605
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1606
1606
|
|
|
1607
1607
|
queryClient.setQueryData([key, 10], 10)
|
|
1608
1608
|
|
|
@@ -1684,7 +1684,7 @@ describe('createQuery', () => {
|
|
|
1684
1684
|
|
|
1685
1685
|
it('should use the correct query function when components use different configurations', async () => {
|
|
1686
1686
|
const key = queryKey()
|
|
1687
|
-
const states: CreateQueryResult<number
|
|
1687
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
1688
1688
|
|
|
1689
1689
|
function FirstComponent() {
|
|
1690
1690
|
const state = createQuery(() => ({
|
|
@@ -1752,8 +1752,8 @@ describe('createQuery', () => {
|
|
|
1752
1752
|
|
|
1753
1753
|
it('should be able to set different stale times for a query', async () => {
|
|
1754
1754
|
const key = queryKey()
|
|
1755
|
-
const states1: CreateQueryResult<string
|
|
1756
|
-
const states2: CreateQueryResult<string
|
|
1755
|
+
const states1: Array<CreateQueryResult<string>> = []
|
|
1756
|
+
const states2: Array<CreateQueryResult<string>> = []
|
|
1757
1757
|
|
|
1758
1758
|
await queryClient.prefetchQuery({
|
|
1759
1759
|
queryKey: key,
|
|
@@ -1859,7 +1859,7 @@ describe('createQuery', () => {
|
|
|
1859
1859
|
|
|
1860
1860
|
it('should re-render when a query becomes stale', async () => {
|
|
1861
1861
|
const key = queryKey()
|
|
1862
|
-
const states: CreateQueryResult<string
|
|
1862
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
1863
1863
|
|
|
1864
1864
|
function Page() {
|
|
1865
1865
|
const state = createQuery(() => ({
|
|
@@ -1889,7 +1889,7 @@ describe('createQuery', () => {
|
|
|
1889
1889
|
|
|
1890
1890
|
it('should not re-render when it should only re-render on data changes and the data did not change', async () => {
|
|
1891
1891
|
const key = queryKey()
|
|
1892
|
-
const states: CreateQueryResult<string
|
|
1892
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
1893
1893
|
|
|
1894
1894
|
function Page() {
|
|
1895
1895
|
const state = createQuery(() => ({
|
|
@@ -2131,7 +2131,7 @@ describe('createQuery', () => {
|
|
|
2131
2131
|
|
|
2132
2132
|
it('should not refetch query on focus when `enabled` is set to `false`', async () => {
|
|
2133
2133
|
const key = queryKey()
|
|
2134
|
-
const queryFn = vi.fn<unknown
|
|
2134
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
2135
2135
|
|
|
2136
2136
|
function Page() {
|
|
2137
2137
|
const { data = 'default' } = createQuery(() => ({
|
|
@@ -2162,7 +2162,7 @@ describe('createQuery', () => {
|
|
|
2162
2162
|
|
|
2163
2163
|
it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to `false`', async () => {
|
|
2164
2164
|
const key = queryKey()
|
|
2165
|
-
const states: CreateQueryResult<number
|
|
2165
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2166
2166
|
let count = 0
|
|
2167
2167
|
|
|
2168
2168
|
function Page() {
|
|
@@ -2197,7 +2197,7 @@ describe('createQuery', () => {
|
|
|
2197
2197
|
|
|
2198
2198
|
it('should not refetch stale query on focus when `refetchOnWindowFocus` is set to a function that returns `false`', async () => {
|
|
2199
2199
|
const key = queryKey()
|
|
2200
|
-
const states: CreateQueryResult<number
|
|
2200
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2201
2201
|
let count = 0
|
|
2202
2202
|
|
|
2203
2203
|
function Page() {
|
|
@@ -2232,7 +2232,7 @@ describe('createQuery', () => {
|
|
|
2232
2232
|
|
|
2233
2233
|
it('should not refetch fresh query on focus when `refetchOnWindowFocus` is set to `true`', async () => {
|
|
2234
2234
|
const key = queryKey()
|
|
2235
|
-
const states: CreateQueryResult<number
|
|
2235
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2236
2236
|
let count = 0
|
|
2237
2237
|
|
|
2238
2238
|
function Page() {
|
|
@@ -2267,7 +2267,7 @@ describe('createQuery', () => {
|
|
|
2267
2267
|
|
|
2268
2268
|
it('should refetch fresh query on focus when `refetchOnWindowFocus` is set to `always`', async () => {
|
|
2269
2269
|
const key = queryKey()
|
|
2270
|
-
const states: CreateQueryResult<number
|
|
2270
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2271
2271
|
let count = 0
|
|
2272
2272
|
|
|
2273
2273
|
function Page() {
|
|
@@ -2307,7 +2307,7 @@ describe('createQuery', () => {
|
|
|
2307
2307
|
|
|
2308
2308
|
it('should calculate focus behaviour for refetchOnWindowFocus depending on function', async () => {
|
|
2309
2309
|
const key = queryKey()
|
|
2310
|
-
const states: CreateQueryResult<number
|
|
2310
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
2311
2311
|
let count = 0
|
|
2312
2312
|
|
|
2313
2313
|
function Page() {
|
|
@@ -2357,7 +2357,7 @@ describe('createQuery', () => {
|
|
|
2357
2357
|
|
|
2358
2358
|
it('should refetch fresh query when refetchOnMount is set to always', async () => {
|
|
2359
2359
|
const key = queryKey()
|
|
2360
|
-
const states: CreateQueryResult<string
|
|
2360
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2361
2361
|
|
|
2362
2362
|
await queryClient.prefetchQuery({
|
|
2363
2363
|
queryKey: key,
|
|
@@ -2400,7 +2400,7 @@ describe('createQuery', () => {
|
|
|
2400
2400
|
|
|
2401
2401
|
it('should refetch stale query when refetchOnMount is set to true', async () => {
|
|
2402
2402
|
const key = queryKey()
|
|
2403
|
-
const states: CreateQueryResult<string
|
|
2403
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2404
2404
|
|
|
2405
2405
|
await queryClient.prefetchQuery({
|
|
2406
2406
|
queryKey: key,
|
|
@@ -2731,7 +2731,7 @@ describe('createQuery', () => {
|
|
|
2731
2731
|
|
|
2732
2732
|
it('should always fetch if refetchOnMount is set to always', async () => {
|
|
2733
2733
|
const key = queryKey()
|
|
2734
|
-
const states: CreateQueryResult<string
|
|
2734
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
2735
2735
|
|
|
2736
2736
|
await queryClient.prefetchQuery({
|
|
2737
2737
|
queryKey: key,
|
|
@@ -2785,7 +2785,7 @@ describe('createQuery', () => {
|
|
|
2785
2785
|
|
|
2786
2786
|
it('should fetch if initial data is set', async () => {
|
|
2787
2787
|
const key = queryKey()
|
|
2788
|
-
const states: DefinedCreateQueryResult<string
|
|
2788
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2789
2789
|
|
|
2790
2790
|
function Page() {
|
|
2791
2791
|
const state = createQuery(() => ({
|
|
@@ -2823,7 +2823,7 @@ describe('createQuery', () => {
|
|
|
2823
2823
|
|
|
2824
2824
|
it('should not fetch if initial data is set with a stale time', async () => {
|
|
2825
2825
|
const key = queryKey()
|
|
2826
|
-
const states: DefinedCreateQueryResult<string
|
|
2826
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2827
2827
|
|
|
2828
2828
|
function Page() {
|
|
2829
2829
|
const state = createQuery(() => ({
|
|
@@ -2861,7 +2861,7 @@ describe('createQuery', () => {
|
|
|
2861
2861
|
|
|
2862
2862
|
it('should fetch if initial data updated at is older than stale time', async () => {
|
|
2863
2863
|
const key = queryKey()
|
|
2864
|
-
const states: DefinedCreateQueryResult<string
|
|
2864
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2865
2865
|
|
|
2866
2866
|
const oneSecondAgo = Date.now() - 1000
|
|
2867
2867
|
|
|
@@ -2907,7 +2907,7 @@ describe('createQuery', () => {
|
|
|
2907
2907
|
|
|
2908
2908
|
it('should fetch if "initial data updated at" is exactly 0', async () => {
|
|
2909
2909
|
const key = queryKey()
|
|
2910
|
-
const states: DefinedCreateQueryResult<string
|
|
2910
|
+
const states: Array<DefinedCreateQueryResult<string>> = []
|
|
2911
2911
|
|
|
2912
2912
|
function Page() {
|
|
2913
2913
|
const state = createQuery(() => ({
|
|
@@ -2946,7 +2946,8 @@ describe('createQuery', () => {
|
|
|
2946
2946
|
|
|
2947
2947
|
it('should keep initial data when the query key changes', async () => {
|
|
2948
2948
|
const key = queryKey()
|
|
2949
|
-
const states: Partial<DefinedCreateQueryResult<{ count: number }
|
|
2949
|
+
const states: Array<Partial<DefinedCreateQueryResult<{ count: number }>>> =
|
|
2950
|
+
[]
|
|
2950
2951
|
|
|
2951
2952
|
function Page() {
|
|
2952
2953
|
const [count, setCount] = createSignal(0)
|
|
@@ -2988,7 +2989,7 @@ describe('createQuery', () => {
|
|
|
2988
2989
|
it('should retry specified number of times', async () => {
|
|
2989
2990
|
const key = queryKey()
|
|
2990
2991
|
|
|
2991
|
-
const queryFn = vi.fn<unknown
|
|
2992
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
2992
2993
|
queryFn.mockImplementation(() => {
|
|
2993
2994
|
return Promise.reject(new Error('Error test Barrett'))
|
|
2994
2995
|
})
|
|
@@ -3029,7 +3030,7 @@ describe('createQuery', () => {
|
|
|
3029
3030
|
it('should not retry if retry function `false`', async () => {
|
|
3030
3031
|
const key = queryKey()
|
|
3031
3032
|
|
|
3032
|
-
const queryFn = vi.fn<unknown
|
|
3033
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
3033
3034
|
|
|
3034
3035
|
queryFn.mockImplementationOnce(() => {
|
|
3035
3036
|
return Promise.reject(new Error('Error test Tanner'))
|
|
@@ -3077,7 +3078,7 @@ describe('createQuery', () => {
|
|
|
3077
3078
|
|
|
3078
3079
|
type DelayError = { delay: number }
|
|
3079
3080
|
|
|
3080
|
-
const queryFn = vi.fn<unknown
|
|
3081
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
3081
3082
|
queryFn.mockImplementation(() => {
|
|
3082
3083
|
return Promise.reject({ delay: 50 })
|
|
3083
3084
|
})
|
|
@@ -3179,7 +3180,7 @@ describe('createQuery', () => {
|
|
|
3179
3180
|
|
|
3180
3181
|
it('should fetch on mount when a query was already created with setQueryData', async () => {
|
|
3181
3182
|
const key = queryKey()
|
|
3182
|
-
const states: CreateQueryResult<string
|
|
3183
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3183
3184
|
|
|
3184
3185
|
queryClient.setQueryData(key, 'prefetched')
|
|
3185
3186
|
|
|
@@ -3219,7 +3220,7 @@ describe('createQuery', () => {
|
|
|
3219
3220
|
|
|
3220
3221
|
it('should refetch after focus regain', async () => {
|
|
3221
3222
|
const key = queryKey()
|
|
3222
|
-
const states: CreateQueryResult<string
|
|
3223
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3223
3224
|
|
|
3224
3225
|
// make page unfocused
|
|
3225
3226
|
const visibilityMock = mockVisibilityState('hidden')
|
|
@@ -3286,12 +3287,12 @@ describe('createQuery', () => {
|
|
|
3286
3287
|
// See https://github.com/tannerlinsley/react-query/issues/195
|
|
3287
3288
|
it('should refetch if stale after a prefetch', async () => {
|
|
3288
3289
|
const key = queryKey()
|
|
3289
|
-
const states: CreateQueryResult<string
|
|
3290
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3290
3291
|
|
|
3291
|
-
const queryFn = vi.fn<unknown
|
|
3292
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3292
3293
|
queryFn.mockImplementation(() => 'data')
|
|
3293
3294
|
|
|
3294
|
-
const prefetchQueryFn = vi.fn<unknown
|
|
3295
|
+
const prefetchQueryFn = vi.fn<Array<unknown>, string>()
|
|
3295
3296
|
prefetchQueryFn.mockImplementation(() => 'not yet...')
|
|
3296
3297
|
|
|
3297
3298
|
await queryClient.prefetchQuery({
|
|
@@ -3325,10 +3326,10 @@ describe('createQuery', () => {
|
|
|
3325
3326
|
it('should not refetch if not stale after a prefetch', async () => {
|
|
3326
3327
|
const key = queryKey()
|
|
3327
3328
|
|
|
3328
|
-
const queryFn = vi.fn<unknown
|
|
3329
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3329
3330
|
queryFn.mockImplementation(() => 'data')
|
|
3330
3331
|
|
|
3331
|
-
const prefetchQueryFn = vi.fn<unknown
|
|
3332
|
+
const prefetchQueryFn = vi.fn<Array<unknown>, Promise<string>>()
|
|
3332
3333
|
prefetchQueryFn.mockImplementation(async () => {
|
|
3333
3334
|
await sleep(10)
|
|
3334
3335
|
return 'not yet...'
|
|
@@ -3494,7 +3495,7 @@ describe('createQuery', () => {
|
|
|
3494
3495
|
|
|
3495
3496
|
it('should mark query as fetching, when using initialData', async () => {
|
|
3496
3497
|
const key = queryKey()
|
|
3497
|
-
const results: DefinedCreateQueryResult<string
|
|
3498
|
+
const results: Array<DefinedCreateQueryResult<string>> = []
|
|
3498
3499
|
|
|
3499
3500
|
function Page() {
|
|
3500
3501
|
const result = createQuery(() => ({
|
|
@@ -3529,7 +3530,7 @@ describe('createQuery', () => {
|
|
|
3529
3530
|
|
|
3530
3531
|
it('should initialize state properly, when initialData is falsy', async () => {
|
|
3531
3532
|
const key = queryKey()
|
|
3532
|
-
const results: DefinedCreateQueryResult<number
|
|
3533
|
+
const results: Array<DefinedCreateQueryResult<number>> = []
|
|
3533
3534
|
|
|
3534
3535
|
function Page() {
|
|
3535
3536
|
const result = createQuery(() => ({
|
|
@@ -3561,7 +3562,7 @@ describe('createQuery', () => {
|
|
|
3561
3562
|
// // See https://github.com/tannerlinsley/react-query/issues/214
|
|
3562
3563
|
it('data should persist when enabled is changed to false', async () => {
|
|
3563
3564
|
const key = queryKey()
|
|
3564
|
-
const results: DefinedCreateQueryResult<string
|
|
3565
|
+
const results: Array<DefinedCreateQueryResult<string>> = []
|
|
3565
3566
|
|
|
3566
3567
|
function Page() {
|
|
3567
3568
|
const [shouldFetch, setShouldFetch] = createSignal(true)
|
|
@@ -3601,7 +3602,7 @@ describe('createQuery', () => {
|
|
|
3601
3602
|
|
|
3602
3603
|
it('it should support enabled:false in query object syntax', async () => {
|
|
3603
3604
|
const key = queryKey()
|
|
3604
|
-
const queryFn = vi.fn<unknown
|
|
3605
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
3605
3606
|
queryFn.mockImplementation(() => 'data')
|
|
3606
3607
|
|
|
3607
3608
|
function Page() {
|
|
@@ -3711,7 +3712,7 @@ describe('createQuery', () => {
|
|
|
3711
3712
|
|
|
3712
3713
|
it('should not cause memo churn when data does not change', async () => {
|
|
3713
3714
|
const key = queryKey()
|
|
3714
|
-
const queryFn = vi.fn<unknown
|
|
3715
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
3715
3716
|
const memoFn = vi.fn()
|
|
3716
3717
|
|
|
3717
3718
|
function Page() {
|
|
@@ -3794,7 +3795,7 @@ describe('createQuery', () => {
|
|
|
3794
3795
|
it('should refetch in an interval depending on function result', async () => {
|
|
3795
3796
|
const key = queryKey()
|
|
3796
3797
|
let count = 0
|
|
3797
|
-
const states: CreateQueryResult<number
|
|
3798
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
3798
3799
|
|
|
3799
3800
|
function Page() {
|
|
3800
3801
|
const state = createQuery(() => ({
|
|
@@ -3866,7 +3867,7 @@ describe('createQuery', () => {
|
|
|
3866
3867
|
|
|
3867
3868
|
it('should not interval fetch with a refetchInterval of 0', async () => {
|
|
3868
3869
|
const key = queryKey()
|
|
3869
|
-
const states: CreateQueryResult<number
|
|
3870
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
3870
3871
|
|
|
3871
3872
|
function Page() {
|
|
3872
3873
|
const state = createQuery(() => ({
|
|
@@ -3947,7 +3948,7 @@ describe('createQuery', () => {
|
|
|
3947
3948
|
it('should refetch if any query instance becomes enabled', async () => {
|
|
3948
3949
|
const key = queryKey()
|
|
3949
3950
|
|
|
3950
|
-
const queryFn = vi.fn<unknown
|
|
3951
|
+
const queryFn = vi.fn<Array<unknown>, string>().mockReturnValue('data')
|
|
3951
3952
|
|
|
3952
3953
|
function Disabled() {
|
|
3953
3954
|
createQuery(() => ({ queryKey: key, queryFn, enabled: false }))
|
|
@@ -3984,7 +3985,7 @@ describe('createQuery', () => {
|
|
|
3984
3985
|
it('should use placeholder data while the query loads', async () => {
|
|
3985
3986
|
const key1 = queryKey()
|
|
3986
3987
|
|
|
3987
|
-
const states: CreateQueryResult<string
|
|
3988
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
3988
3989
|
|
|
3989
3990
|
function Page() {
|
|
3990
3991
|
const state = createQuery(() => ({
|
|
@@ -4029,7 +4030,8 @@ describe('createQuery', () => {
|
|
|
4029
4030
|
it('should use placeholder data even for disabled queries', async () => {
|
|
4030
4031
|
const key1 = queryKey()
|
|
4031
4032
|
|
|
4032
|
-
const states: { state: CreateQueryResult<string>; count: number }
|
|
4033
|
+
const states: Array<{ state: CreateQueryResult<string>; count: number }> =
|
|
4034
|
+
[]
|
|
4033
4035
|
|
|
4034
4036
|
function Page() {
|
|
4035
4037
|
const [count, setCount] = createSignal(0)
|
|
@@ -4095,7 +4097,7 @@ describe('createQuery', () => {
|
|
|
4095
4097
|
it('placeholder data should run through select', async () => {
|
|
4096
4098
|
const key1 = queryKey()
|
|
4097
4099
|
|
|
4098
|
-
const states: CreateQueryResult<string
|
|
4100
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4099
4101
|
|
|
4100
4102
|
function Page() {
|
|
4101
4103
|
const state = createQuery(() => ({
|
|
@@ -4141,7 +4143,7 @@ describe('createQuery', () => {
|
|
|
4141
4143
|
it('placeholder data function result should run through select', async () => {
|
|
4142
4144
|
const key1 = queryKey()
|
|
4143
4145
|
|
|
4144
|
-
const states: CreateQueryResult<string
|
|
4146
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4145
4147
|
let placeholderFunctionRunCount = 0
|
|
4146
4148
|
|
|
4147
4149
|
function Page() {
|
|
@@ -4393,7 +4395,7 @@ describe('createQuery', () => {
|
|
|
4393
4395
|
|
|
4394
4396
|
it('should cancel the query if the signal was consumed and there are no more subscriptions', async () => {
|
|
4395
4397
|
const key = queryKey()
|
|
4396
|
-
const states: CreateQueryResult<string
|
|
4398
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4397
4399
|
|
|
4398
4400
|
const queryFn: QueryFunction<
|
|
4399
4401
|
string,
|
|
@@ -4463,7 +4465,7 @@ describe('createQuery', () => {
|
|
|
4463
4465
|
|
|
4464
4466
|
it('should refetch when quickly switching to a failed query', async () => {
|
|
4465
4467
|
const key = queryKey()
|
|
4466
|
-
const states: CreateQueryResult<string
|
|
4468
|
+
const states: Array<CreateQueryResult<string>> = []
|
|
4467
4469
|
|
|
4468
4470
|
const queryFn = async () => {
|
|
4469
4471
|
await sleep(50)
|
|
@@ -4513,7 +4515,7 @@ describe('createQuery', () => {
|
|
|
4513
4515
|
|
|
4514
4516
|
it('should update query state and refetch when reset with resetQueries', async () => {
|
|
4515
4517
|
const key = queryKey()
|
|
4516
|
-
const states: CreateQueryResult<number
|
|
4518
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4517
4519
|
let count = 0
|
|
4518
4520
|
|
|
4519
4521
|
function Page() {
|
|
@@ -4587,7 +4589,7 @@ describe('createQuery', () => {
|
|
|
4587
4589
|
|
|
4588
4590
|
it('should update query state and not refetch when resetting a disabled query with resetQueries', async () => {
|
|
4589
4591
|
const key = queryKey()
|
|
4590
|
-
const states: CreateQueryResult<number
|
|
4592
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4591
4593
|
let count = 0
|
|
4592
4594
|
|
|
4593
4595
|
function Page() {
|
|
@@ -4705,7 +4707,7 @@ describe('createQuery', () => {
|
|
|
4705
4707
|
})
|
|
4706
4708
|
|
|
4707
4709
|
it('should refetch when changed enabled to true in error state', async () => {
|
|
4708
|
-
const queryFn = vi.fn<unknown
|
|
4710
|
+
const queryFn = vi.fn<Array<unknown>, unknown>()
|
|
4709
4711
|
queryFn.mockImplementation(async () => {
|
|
4710
4712
|
await sleep(10)
|
|
4711
4713
|
return Promise.reject(new Error('Suspense Error Bingo'))
|
|
@@ -4900,7 +4902,7 @@ describe('createQuery', () => {
|
|
|
4900
4902
|
|
|
4901
4903
|
it('should have no error in pending state when refetching after error occurred', async () => {
|
|
4902
4904
|
const key = queryKey()
|
|
4903
|
-
const states: CreateQueryResult<number
|
|
4905
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
4904
4906
|
const error = new Error('oops')
|
|
4905
4907
|
|
|
4906
4908
|
let count = 0
|
|
@@ -5759,7 +5761,7 @@ describe('createQuery', () => {
|
|
|
5759
5761
|
|
|
5760
5762
|
it('it should have status=error on mount when a query has failed', async () => {
|
|
5761
5763
|
const key = queryKey()
|
|
5762
|
-
const states: CreateQueryResult<unknown
|
|
5764
|
+
const states: Array<CreateQueryResult<unknown>> = []
|
|
5763
5765
|
const error = new Error('oops')
|
|
5764
5766
|
|
|
5765
5767
|
const queryFn = async (): Promise<unknown> => {
|
|
@@ -28,7 +28,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
28
28
|
|
|
29
29
|
it('should render the correct amount of times in Suspense mode', async () => {
|
|
30
30
|
const key = queryKey()
|
|
31
|
-
const states: CreateQueryResult<number
|
|
31
|
+
const states: Array<CreateQueryResult<number>> = []
|
|
32
32
|
|
|
33
33
|
let count = 0
|
|
34
34
|
let renders = 0
|
|
@@ -84,7 +84,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
84
84
|
|
|
85
85
|
it('should return the correct states for a successful infinite query', async () => {
|
|
86
86
|
const key = queryKey()
|
|
87
|
-
const states: CreateInfiniteQueryResult<InfiniteData<number
|
|
87
|
+
const states: Array<CreateInfiniteQueryResult<InfiniteData<number>>> = []
|
|
88
88
|
|
|
89
89
|
function Page() {
|
|
90
90
|
const [multiplier, setMultiplier] = createSignal(1)
|
|
@@ -143,7 +143,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
143
143
|
it('should not call the queryFn twice when used in Suspense mode', async () => {
|
|
144
144
|
const key = queryKey()
|
|
145
145
|
|
|
146
|
-
const queryFn = vi.fn<unknown
|
|
146
|
+
const queryFn = vi.fn<Array<unknown>, string>()
|
|
147
147
|
queryFn.mockImplementation(() => {
|
|
148
148
|
sleep(10)
|
|
149
149
|
return 'data'
|
|
@@ -663,7 +663,7 @@ describe("useQuery's in Suspense mode", () => {
|
|
|
663
663
|
it('should not call the queryFn when not enabled', async () => {
|
|
664
664
|
const key = queryKey()
|
|
665
665
|
|
|
666
|
-
const queryFn = vi.fn<unknown
|
|
666
|
+
const queryFn = vi.fn<Array<unknown>, Promise<string>>()
|
|
667
667
|
queryFn.mockImplementation(async () => {
|
|
668
668
|
await sleep(10)
|
|
669
669
|
return '23'
|
|
@@ -59,7 +59,7 @@ describe('useIsFetching', () => {
|
|
|
59
59
|
const key1 = queryKey()
|
|
60
60
|
const key2 = queryKey()
|
|
61
61
|
|
|
62
|
-
const isFetchings: number
|
|
62
|
+
const isFetchings: Array<number> = []
|
|
63
63
|
|
|
64
64
|
function IsFetching() {
|
|
65
65
|
const isFetching = useIsFetching()
|
|
@@ -125,7 +125,7 @@ describe('useIsFetching', () => {
|
|
|
125
125
|
const key1 = queryKey()
|
|
126
126
|
const key2 = queryKey()
|
|
127
127
|
|
|
128
|
-
const isFetchings: number
|
|
128
|
+
const isFetchings: Array<number> = []
|
|
129
129
|
|
|
130
130
|
function One() {
|
|
131
131
|
createQuery(() => ({
|
|
@@ -8,7 +8,7 @@ import { createQueryClient, setActTimeout, sleep } from './utils'
|
|
|
8
8
|
|
|
9
9
|
describe('useIsMutating', () => {
|
|
10
10
|
it('should return the number of fetching mutations', async () => {
|
|
11
|
-
const isMutatings: number
|
|
11
|
+
const isMutatings: Array<number> = []
|
|
12
12
|
const queryClient = createQueryClient()
|
|
13
13
|
|
|
14
14
|
function IsMutating() {
|
|
@@ -63,7 +63,7 @@ describe('useIsMutating', () => {
|
|
|
63
63
|
})
|
|
64
64
|
|
|
65
65
|
it('should filter correctly by mutationKey', async () => {
|
|
66
|
-
const isMutatings: number
|
|
66
|
+
const isMutatings: Array<number> = []
|
|
67
67
|
const queryClient = createQueryClient()
|
|
68
68
|
|
|
69
69
|
function IsMutating() {
|
|
@@ -108,7 +108,7 @@ describe('useIsMutating', () => {
|
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
it('should filter correctly by predicate', async () => {
|
|
111
|
-
const isMutatings: number
|
|
111
|
+
const isMutatings: Array<number> = []
|
|
112
112
|
const queryClient = createQueryClient()
|
|
113
113
|
|
|
114
114
|
function IsMutating() {
|
package/src/createQueries.ts
CHANGED
|
@@ -95,62 +95,70 @@ type GetResults<T> =
|
|
|
95
95
|
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
96
96
|
*/
|
|
97
97
|
export type QueriesOptions<
|
|
98
|
-
T extends any
|
|
99
|
-
Result extends any
|
|
98
|
+
T extends Array<any>,
|
|
99
|
+
Result extends Array<any> = [],
|
|
100
100
|
Depth extends ReadonlyArray<number> = [],
|
|
101
101
|
> = Depth['length'] extends MAXIMUM_DEPTH
|
|
102
|
-
? CreateQueryOptionsForCreateQueries
|
|
102
|
+
? Array<CreateQueryOptionsForCreateQueries>
|
|
103
103
|
: T extends []
|
|
104
104
|
? []
|
|
105
105
|
: T extends [infer Head]
|
|
106
106
|
? [...Result, GetOptions<Head>]
|
|
107
107
|
: T extends [infer Head, ...infer Tail]
|
|
108
108
|
? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]>
|
|
109
|
-
: unknown
|
|
109
|
+
: Array<unknown> extends T
|
|
110
110
|
? T
|
|
111
111
|
: // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!
|
|
112
112
|
// use this to infer the param types in the case of Array.map() argument
|
|
113
|
-
T extends
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
113
|
+
T extends Array<
|
|
114
|
+
CreateQueryOptionsForCreateQueries<
|
|
115
|
+
infer TQueryFnData,
|
|
116
|
+
infer TError,
|
|
117
|
+
infer TData,
|
|
118
|
+
infer TQueryKey
|
|
119
|
+
>
|
|
120
|
+
>
|
|
121
|
+
? Array<
|
|
122
|
+
CreateQueryOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>
|
|
123
|
+
>
|
|
120
124
|
: // Fallback
|
|
121
|
-
CreateQueryOptionsForCreateQueries
|
|
125
|
+
Array<CreateQueryOptionsForCreateQueries>
|
|
122
126
|
|
|
123
127
|
/**
|
|
124
128
|
* QueriesResults reducer recursively maps type param to results
|
|
125
129
|
*/
|
|
126
130
|
export type QueriesResults<
|
|
127
|
-
T extends any
|
|
128
|
-
Result extends any
|
|
131
|
+
T extends Array<any>,
|
|
132
|
+
Result extends Array<any> = [],
|
|
129
133
|
Depth extends ReadonlyArray<number> = [],
|
|
130
134
|
> = Depth['length'] extends MAXIMUM_DEPTH
|
|
131
|
-
? CreateQueryResult
|
|
135
|
+
? Array<CreateQueryResult>
|
|
132
136
|
: T extends []
|
|
133
137
|
? []
|
|
134
138
|
: T extends [infer Head]
|
|
135
139
|
? [...Result, GetResults<Head>]
|
|
136
140
|
: T extends [infer Head, ...infer Tail]
|
|
137
141
|
? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]>
|
|
138
|
-
: T extends
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
: T extends Array<
|
|
143
|
+
CreateQueryOptionsForCreateQueries<
|
|
144
|
+
infer TQueryFnData,
|
|
145
|
+
infer TError,
|
|
146
|
+
infer TData,
|
|
147
|
+
any
|
|
148
|
+
>
|
|
149
|
+
>
|
|
144
150
|
? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
Array<
|
|
152
|
+
CreateQueryResult<
|
|
153
|
+
unknown extends TData ? TQueryFnData : TData,
|
|
154
|
+
unknown extends TError ? DefaultError : TError
|
|
155
|
+
>
|
|
156
|
+
>
|
|
149
157
|
: // Fallback
|
|
150
|
-
CreateQueryResult
|
|
158
|
+
Array<CreateQueryResult>
|
|
151
159
|
|
|
152
160
|
export function createQueries<
|
|
153
|
-
T extends any
|
|
161
|
+
T extends Array<any>,
|
|
154
162
|
TCombinedResult = QueriesResults<T>,
|
|
155
163
|
>(
|
|
156
164
|
queriesOptions: Accessor<{
|
package/src/utils.ts
CHANGED