@ventlio/tanstack-query 0.2.74 → 0.2.75
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/dist/index.mjs +0 -2
- package/dist/index.mjs.map +1 -1
- package/dist/queries/useGetInfiniteRequest.d.ts +54 -19
- package/dist/queries/useGetInfiniteRequest.js +0 -2
- package/dist/queries/useGetInfiniteRequest.js.map +1 -1
- package/package.json +1 -1
- package/src/queries/useGetInfiniteRequest.ts +10 -8
package/dist/index.mjs
CHANGED
|
@@ -486,10 +486,8 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
486
486
|
queryClient.setQueryData([keyTracker], [path, {}]);
|
|
487
487
|
}
|
|
488
488
|
}, [keyTracker, path, queryClient, queryOptions?.staleTime]);
|
|
489
|
-
const flattenedData = query.data?.pages.flat() ?? [];
|
|
490
489
|
return {
|
|
491
490
|
...query,
|
|
492
|
-
flattenedData,
|
|
493
491
|
};
|
|
494
492
|
};
|
|
495
493
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { IRequestSuccess } from '../request';
|
|
2
2
|
import type { DefaultRequestOptions, TanstackInfiniteQueryOption } from './queries.interface';
|
|
3
|
+
interface Pagination {
|
|
4
|
+
previous_page: number;
|
|
5
|
+
current_page: number;
|
|
6
|
+
next_page: number;
|
|
7
|
+
size: number;
|
|
8
|
+
page_count: number;
|
|
9
|
+
total: number;
|
|
10
|
+
}
|
|
3
11
|
export declare const useGetInfiniteRequest: <TResponse extends Record<string, any>>({ path, load, queryOptions, keyTracker, baseUrl, headers, }: {
|
|
4
12
|
path: string;
|
|
5
13
|
load?: boolean | undefined;
|
|
6
|
-
queryOptions?: TanstackInfiniteQueryOption<TResponse
|
|
14
|
+
queryOptions?: TanstackInfiniteQueryOption<TResponse & {
|
|
15
|
+
pagination: Pagination;
|
|
16
|
+
}> | undefined;
|
|
7
17
|
keyTracker?: string | undefined;
|
|
8
18
|
} & DefaultRequestOptions) => {
|
|
9
|
-
flattenedData: IRequestSuccess<TResponse>[];
|
|
10
19
|
data: undefined;
|
|
11
20
|
error: any;
|
|
12
21
|
isError: true;
|
|
@@ -15,8 +24,12 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
15
24
|
isRefetchError: false;
|
|
16
25
|
isSuccess: false;
|
|
17
26
|
status: "error";
|
|
18
|
-
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse
|
|
19
|
-
|
|
27
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
28
|
+
pagination: Pagination;
|
|
29
|
+
}>, any>>;
|
|
30
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
31
|
+
pagination: Pagination;
|
|
32
|
+
}>, any>>;
|
|
20
33
|
hasNextPage?: boolean | undefined;
|
|
21
34
|
hasPreviousPage?: boolean | undefined;
|
|
22
35
|
isFetchingNextPage: boolean;
|
|
@@ -35,11 +48,12 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
35
48
|
isPreviousData: boolean;
|
|
36
49
|
isRefetching: boolean;
|
|
37
50
|
isStale: boolean;
|
|
38
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse
|
|
51
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse & {
|
|
52
|
+
pagination: Pagination;
|
|
53
|
+
}>>, any>>;
|
|
39
54
|
remove: () => void;
|
|
40
55
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
41
56
|
} | {
|
|
42
|
-
flattenedData: IRequestSuccess<TResponse>[];
|
|
43
57
|
data: undefined;
|
|
44
58
|
error: null;
|
|
45
59
|
isError: false;
|
|
@@ -48,8 +62,12 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
48
62
|
isRefetchError: false;
|
|
49
63
|
isSuccess: false;
|
|
50
64
|
status: "loading";
|
|
51
|
-
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse
|
|
52
|
-
|
|
65
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
66
|
+
pagination: Pagination;
|
|
67
|
+
}>, any>>;
|
|
68
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
69
|
+
pagination: Pagination;
|
|
70
|
+
}>, any>>;
|
|
53
71
|
hasNextPage?: boolean | undefined;
|
|
54
72
|
hasPreviousPage?: boolean | undefined;
|
|
55
73
|
isFetchingNextPage: boolean;
|
|
@@ -68,12 +86,15 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
68
86
|
isPreviousData: boolean;
|
|
69
87
|
isRefetching: boolean;
|
|
70
88
|
isStale: boolean;
|
|
71
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse
|
|
89
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse & {
|
|
90
|
+
pagination: Pagination;
|
|
91
|
+
}>>, any>>;
|
|
72
92
|
remove: () => void;
|
|
73
93
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
74
94
|
} | {
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
data: import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse & {
|
|
96
|
+
pagination: Pagination;
|
|
97
|
+
}>>;
|
|
77
98
|
error: any;
|
|
78
99
|
isError: true;
|
|
79
100
|
isLoading: false;
|
|
@@ -81,8 +102,12 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
81
102
|
isRefetchError: true;
|
|
82
103
|
isSuccess: false;
|
|
83
104
|
status: "error";
|
|
84
|
-
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse
|
|
85
|
-
|
|
105
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
106
|
+
pagination: Pagination;
|
|
107
|
+
}>, any>>;
|
|
108
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
109
|
+
pagination: Pagination;
|
|
110
|
+
}>, any>>;
|
|
86
111
|
hasNextPage?: boolean | undefined;
|
|
87
112
|
hasPreviousPage?: boolean | undefined;
|
|
88
113
|
isFetchingNextPage: boolean;
|
|
@@ -101,12 +126,15 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
101
126
|
isPreviousData: boolean;
|
|
102
127
|
isRefetching: boolean;
|
|
103
128
|
isStale: boolean;
|
|
104
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse
|
|
129
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse & {
|
|
130
|
+
pagination: Pagination;
|
|
131
|
+
}>>, any>>;
|
|
105
132
|
remove: () => void;
|
|
106
133
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
107
134
|
} | {
|
|
108
|
-
|
|
109
|
-
|
|
135
|
+
data: import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse & {
|
|
136
|
+
pagination: Pagination;
|
|
137
|
+
}>>;
|
|
110
138
|
error: null;
|
|
111
139
|
isError: false;
|
|
112
140
|
isLoading: false;
|
|
@@ -114,8 +142,12 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
114
142
|
isRefetchError: false;
|
|
115
143
|
isSuccess: true;
|
|
116
144
|
status: "success";
|
|
117
|
-
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse
|
|
118
|
-
|
|
145
|
+
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
146
|
+
pagination: Pagination;
|
|
147
|
+
}>, any>>;
|
|
148
|
+
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
149
|
+
pagination: Pagination;
|
|
150
|
+
}>, any>>;
|
|
119
151
|
hasNextPage?: boolean | undefined;
|
|
120
152
|
hasPreviousPage?: boolean | undefined;
|
|
121
153
|
isFetchingNextPage: boolean;
|
|
@@ -134,7 +166,10 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
134
166
|
isPreviousData: boolean;
|
|
135
167
|
isRefetching: boolean;
|
|
136
168
|
isStale: boolean;
|
|
137
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse
|
|
169
|
+
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<import("@tanstack/react-query").InfiniteData<IRequestSuccess<TResponse & {
|
|
170
|
+
pagination: Pagination;
|
|
171
|
+
}>>, any>>;
|
|
138
172
|
remove: () => void;
|
|
139
173
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
140
174
|
};
|
|
175
|
+
export {};
|
|
@@ -61,10 +61,8 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
61
61
|
queryClient.setQueryData([keyTracker], [path, {}]);
|
|
62
62
|
}
|
|
63
63
|
}, [keyTracker, path, queryClient, queryOptions?.staleTime]);
|
|
64
|
-
const flattenedData = query.data?.pages.flat() ?? [];
|
|
65
64
|
return {
|
|
66
65
|
...query,
|
|
67
|
-
flattenedData,
|
|
68
66
|
};
|
|
69
67
|
};
|
|
70
68
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetInfiniteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGetInfiniteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
26
26
|
}: {
|
|
27
27
|
path: string;
|
|
28
28
|
load?: boolean;
|
|
29
|
-
queryOptions?: TanstackInfiniteQueryOption<TResponse>;
|
|
29
|
+
queryOptions?: TanstackInfiniteQueryOption<TResponse & { pagination: Pagination }>;
|
|
30
30
|
keyTracker?: string;
|
|
31
31
|
} & DefaultRequestOptions) => {
|
|
32
32
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
@@ -39,7 +39,10 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
39
39
|
|
|
40
40
|
const sendRequest = async (
|
|
41
41
|
res: (
|
|
42
|
-
value:
|
|
42
|
+
value:
|
|
43
|
+
| IRequestError
|
|
44
|
+
| IRequestSuccess<TResponse & { pagination: Pagination }>
|
|
45
|
+
| PromiseLike<IRequestError | IRequestSuccess<TResponse & { pagination: Pagination }>>
|
|
43
46
|
) => void,
|
|
44
47
|
rej: (reason?: any) => void,
|
|
45
48
|
pageParam?: string
|
|
@@ -56,7 +59,7 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
56
59
|
});
|
|
57
60
|
|
|
58
61
|
if (getResponse.status) {
|
|
59
|
-
res(getResponse as IRequestSuccess<TResponse>);
|
|
62
|
+
res(getResponse as IRequestSuccess<TResponse & { pagination: Pagination }>);
|
|
60
63
|
} else {
|
|
61
64
|
rej(getResponse);
|
|
62
65
|
}
|
|
@@ -65,10 +68,12 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
65
68
|
}
|
|
66
69
|
};
|
|
67
70
|
|
|
68
|
-
const query = useInfiniteQuery<any, any, IRequestSuccess<TResponse>>(
|
|
71
|
+
const query = useInfiniteQuery<any, any, IRequestSuccess<TResponse & { pagination: Pagination }>>(
|
|
69
72
|
[path, {}],
|
|
70
73
|
({ pageParam = path }) =>
|
|
71
|
-
new Promise<IRequestSuccess<TResponse> | IRequestError>((res, rej) =>
|
|
74
|
+
new Promise<IRequestSuccess<TResponse & { pagination: Pagination }> | IRequestError>((res, rej) =>
|
|
75
|
+
sendRequest(res, rej, pageParam)
|
|
76
|
+
),
|
|
72
77
|
{
|
|
73
78
|
enabled: load,
|
|
74
79
|
getNextPageParam: (lastPage, pages) => constructPaginationLink('next_page', lastPage, pages),
|
|
@@ -112,10 +117,7 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
112
117
|
}
|
|
113
118
|
}, [keyTracker, path, queryClient, queryOptions?.staleTime]);
|
|
114
119
|
|
|
115
|
-
const flattenedData = query.data?.pages.flat() ?? [];
|
|
116
|
-
|
|
117
120
|
return {
|
|
118
121
|
...query,
|
|
119
|
-
flattenedData,
|
|
120
122
|
};
|
|
121
123
|
};
|