@tanstack/solid-query 5.0.0-beta.17 → 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 +59 -52
- 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 +5 -5
- 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,14 +62,14 @@ 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(() => ({
|
|
69
69
|
queryKey: key,
|
|
70
70
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
71
71
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
72
|
-
|
|
72
|
+
initialPageParam: 0,
|
|
73
73
|
}))
|
|
74
74
|
createRenderEffect(() => {
|
|
75
75
|
states.push({ ...state })
|
|
@@ -170,7 +170,7 @@ describe('useInfiniteQuery', () => {
|
|
|
170
170
|
|
|
171
171
|
retry: 1,
|
|
172
172
|
retryDelay: 10,
|
|
173
|
-
|
|
173
|
+
initialPageParam: start,
|
|
174
174
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
175
175
|
}))
|
|
176
176
|
|
|
@@ -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')
|
|
@@ -213,7 +214,7 @@ describe('useInfiniteQuery', () => {
|
|
|
213
214
|
},
|
|
214
215
|
|
|
215
216
|
getNextPageParam: () => 1,
|
|
216
|
-
|
|
217
|
+
initialPageParam: 0,
|
|
217
218
|
placeholderData: keepPreviousData,
|
|
218
219
|
notifyOnChangeProps: 'all',
|
|
219
220
|
}))
|
|
@@ -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(() => ({
|
|
@@ -315,7 +316,7 @@ describe('useInfiniteQuery', () => {
|
|
|
315
316
|
pageParams: data.pageParams,
|
|
316
317
|
}),
|
|
317
318
|
getNextPageParam: () => undefined,
|
|
318
|
-
|
|
319
|
+
initialPageParam: 0,
|
|
319
320
|
}))
|
|
320
321
|
createRenderEffect(() => {
|
|
321
322
|
states.push({ ...state })
|
|
@@ -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() {
|
|
@@ -361,7 +362,7 @@ describe('useInfiniteQuery', () => {
|
|
|
361
362
|
}
|
|
362
363
|
},
|
|
363
364
|
getNextPageParam: () => undefined,
|
|
364
|
-
|
|
365
|
+
initialPageParam: 0,
|
|
365
366
|
}))
|
|
366
367
|
createRenderEffect(() => {
|
|
367
368
|
states.push({ ...state })
|
|
@@ -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(() => ({
|
|
@@ -408,7 +410,7 @@ describe('useInfiniteQuery', () => {
|
|
|
408
410
|
}),
|
|
409
411
|
notifyOnChangeProps: 'all',
|
|
410
412
|
getNextPageParam: () => 1,
|
|
411
|
-
|
|
413
|
+
initialPageParam: 0,
|
|
412
414
|
}))
|
|
413
415
|
|
|
414
416
|
createRenderEffect(
|
|
@@ -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
|
|
@@ -479,7 +482,7 @@ describe('useInfiniteQuery', () => {
|
|
|
479
482
|
},
|
|
480
483
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
481
484
|
getPreviousPageParam: (firstPage) => firstPage - 1,
|
|
482
|
-
|
|
485
|
+
initialPageParam: start,
|
|
483
486
|
notifyOnChangeProps: 'all',
|
|
484
487
|
}))
|
|
485
488
|
|
|
@@ -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(() => ({
|
|
@@ -567,7 +571,7 @@ describe('useInfiniteQuery', () => {
|
|
|
567
571
|
|
|
568
572
|
getPreviousPageParam: (firstPage) => firstPage - 1,
|
|
569
573
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
570
|
-
|
|
574
|
+
initialPageParam: 10,
|
|
571
575
|
notifyOnChangeProps: 'all',
|
|
572
576
|
}))
|
|
573
577
|
|
|
@@ -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
|
|
@@ -688,7 +693,7 @@ describe('useInfiniteQuery', () => {
|
|
|
688
693
|
},
|
|
689
694
|
|
|
690
695
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
691
|
-
|
|
696
|
+
initialPageParam: start,
|
|
692
697
|
notifyOnChangeProps: 'all',
|
|
693
698
|
}))
|
|
694
699
|
|
|
@@ -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>
|
|
@@ -786,7 +791,7 @@ describe('useInfiniteQuery', () => {
|
|
|
786
791
|
queryKey: key,
|
|
787
792
|
queryFn: fetchPage,
|
|
788
793
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
789
|
-
|
|
794
|
+
initialPageParam: start,
|
|
790
795
|
}))
|
|
791
796
|
|
|
792
797
|
createEffect(() => {
|
|
@@ -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>
|
|
@@ -868,7 +873,7 @@ describe('useInfiniteQuery', () => {
|
|
|
868
873
|
queryKey: key,
|
|
869
874
|
queryFn: fetchPage,
|
|
870
875
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
871
|
-
|
|
876
|
+
initialPageParam: start,
|
|
872
877
|
}))
|
|
873
878
|
|
|
874
879
|
createEffect(() => {
|
|
@@ -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
|
|
@@ -930,7 +935,7 @@ describe('useInfiniteQuery', () => {
|
|
|
930
935
|
},
|
|
931
936
|
|
|
932
937
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
933
|
-
|
|
938
|
+
initialPageParam: start,
|
|
934
939
|
notifyOnChangeProps: 'all',
|
|
935
940
|
}))
|
|
936
941
|
|
|
@@ -992,7 +997,7 @@ describe('useInfiniteQuery', () => {
|
|
|
992
997
|
getNextPageParam: (_, allPages) => {
|
|
993
998
|
return allPages.length === 4 ? undefined : allPages.length
|
|
994
999
|
},
|
|
995
|
-
|
|
1000
|
+
initialPageParam: 0,
|
|
996
1001
|
}))
|
|
997
1002
|
|
|
998
1003
|
return null
|
|
@@ -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)
|
|
@@ -1043,7 +1049,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1043
1049
|
|
|
1044
1050
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1045
1051
|
notifyOnChangeProps: 'all',
|
|
1046
|
-
|
|
1052
|
+
initialPageParam: firstPage(),
|
|
1047
1053
|
}))
|
|
1048
1054
|
|
|
1049
1055
|
createRenderEffect(() => {
|
|
@@ -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(() => ({
|
|
@@ -1136,7 +1143,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1136
1143
|
|
|
1137
1144
|
initialData: { pages: [1], pageParams: [1] },
|
|
1138
1145
|
getNextPageParam: (lastPage) => lastPage + 1,
|
|
1139
|
-
|
|
1146
|
+
initialPageParam: 0,
|
|
1140
1147
|
notifyOnChangeProps: 'all',
|
|
1141
1148
|
}))
|
|
1142
1149
|
|
|
@@ -1201,13 +1208,13 @@ 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(() => ({
|
|
1208
1215
|
queryKey: key,
|
|
1209
1216
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
1210
|
-
|
|
1217
|
+
initialPageParam: 1,
|
|
1211
1218
|
getNextPageParam: () => undefined,
|
|
1212
1219
|
}))
|
|
1213
1220
|
|
|
@@ -1245,13 +1252,13 @@ 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(() => ({
|
|
1252
1259
|
queryKey: key,
|
|
1253
1260
|
queryFn: ({ pageParam }): number => pageParam,
|
|
1254
|
-
|
|
1261
|
+
initialPageParam: 10,
|
|
1255
1262
|
initialData: { pages: [10], pageParams: [10] },
|
|
1256
1263
|
getNextPageParam: (lastPage) => (lastPage === 10 ? 11 : undefined),
|
|
1257
1264
|
}))
|
|
@@ -1289,13 +1296,13 @@ 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(() => ({
|
|
1296
1303
|
queryKey: key,
|
|
1297
1304
|
queryFn: ({ pageParam }): number => pageParam,
|
|
1298
|
-
|
|
1305
|
+
initialPageParam: 10,
|
|
1299
1306
|
initialData: { pages: [10], pageParams: [10] },
|
|
1300
1307
|
getNextPageParam: () => undefined,
|
|
1301
1308
|
}))
|
|
@@ -1333,13 +1340,13 @@ 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(() => ({
|
|
1340
1347
|
queryKey: key,
|
|
1341
1348
|
queryFn: ({ pageParam }) => Number(pageParam),
|
|
1342
|
-
|
|
1349
|
+
initialPageParam: 1,
|
|
1343
1350
|
getNextPageParam: (lastPage) => (lastPage === 1 ? 2 : undefined),
|
|
1344
1351
|
select: (data) => ({
|
|
1345
1352
|
pages: data.pages.map((x) => x.toString()),
|
|
@@ -1402,7 +1409,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1402
1409
|
queryKey: key,
|
|
1403
1410
|
queryFn: ({ pageParam }) =>
|
|
1404
1411
|
fetchItemsWithLimit(pageParam, fetchCountRef++),
|
|
1405
|
-
|
|
1412
|
+
initialPageParam: 0,
|
|
1406
1413
|
getNextPageParam: (lastPage) => lastPage.nextId,
|
|
1407
1414
|
}))
|
|
1408
1415
|
|
|
@@ -1536,7 +1543,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1536
1543
|
fetchCountRef++,
|
|
1537
1544
|
pageParam === MAX || (pageParam === MAX - 1 && isRemovedLastPage()),
|
|
1538
1545
|
),
|
|
1539
|
-
|
|
1546
|
+
initialPageParam: 0,
|
|
1540
1547
|
getNextPageParam: (lastPage) => lastPage.nextId,
|
|
1541
1548
|
}))
|
|
1542
1549
|
|
|
@@ -1670,7 +1677,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1670
1677
|
queryKey: key,
|
|
1671
1678
|
queryFn,
|
|
1672
1679
|
getNextPageParam: () => undefined,
|
|
1673
|
-
|
|
1680
|
+
initialPageParam: 0,
|
|
1674
1681
|
}))
|
|
1675
1682
|
return (
|
|
1676
1683
|
<div>
|
|
@@ -1704,7 +1711,7 @@ describe('useInfiniteQuery', () => {
|
|
|
1704
1711
|
queryKey: key,
|
|
1705
1712
|
queryFn,
|
|
1706
1713
|
getNextPageParam: () => undefined,
|
|
1707
|
-
|
|
1714
|
+
initialPageParam: 0,
|
|
1708
1715
|
}),
|
|
1709
1716
|
() => queryClient,
|
|
1710
1717
|
)
|
|
@@ -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
|
}
|