@ventlio/tanstack-query 0.3.8 → 0.5.0
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 +36 -30
- package/dist/index.mjs.map +1 -1
- package/dist/model/useKeyTrackerModel.d.ts +1 -1
- package/dist/model/useQueryModel.d.ts +1 -1
- package/dist/model/useQueryModel.js +6 -6
- package/dist/model/useRefetchQuery.d.ts +1 -1
- package/dist/model/useRefetchQuery.js +1 -1
- package/dist/queries/useDeleteRequest.d.ts +6 -66
- package/dist/queries/useDeleteRequest.js +7 -3
- package/dist/queries/useDeleteRequest.js.map +1 -1
- package/dist/queries/useGetInfiniteRequest.d.ts +25 -109
- package/dist/queries/useGetInfiniteRequest.js +3 -2
- package/dist/queries/useGetInfiniteRequest.js.map +1 -1
- package/dist/queries/useGetRequest.d.ts +10 -78
- package/dist/queries/useGetRequest.js +9 -12
- package/dist/queries/useGetRequest.js.map +1 -1
- package/dist/queries/usePatchRequest.d.ts +21 -13
- package/dist/queries/usePatchRequest.js +7 -4
- package/dist/queries/usePatchRequest.js.map +1 -1
- package/dist/queries/usePostRequest.d.ts +30 -25
- package/dist/queries/usePostRequest.js +3 -2
- package/dist/queries/usePostRequest.js.map +1 -1
- package/package.json +2 -2
- package/src/model/useKeyTrackerModel.ts +2 -2
- package/src/model/useQueryModel.ts +7 -7
- package/src/model/useRefetchQuery.ts +1 -1
- package/src/queries/useDeleteRequest.ts +7 -7
- package/src/queries/useGetInfiniteRequest.ts +14 -19
- package/src/queries/useGetRequest.ts +12 -20
- package/src/queries/usePatchRequest.ts +5 -5
- package/src/queries/usePostRequest.ts +4 -2
package/dist/index.mjs
CHANGED
|
@@ -123,7 +123,7 @@ const useKeyTrackerModel = (keyTracker) => {
|
|
|
123
123
|
return { refetchQuery, getQueryKey };
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
const useQueryModel = (keyTracker
|
|
126
|
+
const useQueryModel = (keyTracker) => {
|
|
127
127
|
const queryClient = useQueryClient();
|
|
128
128
|
const { getQueryKey } = useKeyTrackerModel(keyTracker);
|
|
129
129
|
const queryKey = getQueryKey();
|
|
@@ -141,13 +141,13 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
141
141
|
queryClient.setQueryData(queryKey, records);
|
|
142
142
|
}
|
|
143
143
|
else {
|
|
144
|
-
const queryData = queryClient.getQueryData(queryKey
|
|
144
|
+
const queryData = queryClient.getQueryData(queryKey) ?? {};
|
|
145
145
|
queryClient.setQueryData(queryKey, lodashSet(queryData, path, records));
|
|
146
146
|
}
|
|
147
147
|
return data;
|
|
148
148
|
};
|
|
149
149
|
const findAll = (path) => {
|
|
150
|
-
const data = queryClient.getQueryData(queryKey
|
|
150
|
+
const data = queryClient.getQueryData(queryKey);
|
|
151
151
|
if (!data) {
|
|
152
152
|
return [];
|
|
153
153
|
}
|
|
@@ -169,7 +169,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
169
169
|
return data.find((record) => record[modelConfig.idColumn] === id);
|
|
170
170
|
};
|
|
171
171
|
const get = (path) => {
|
|
172
|
-
let data = queryClient.getQueryData(queryKey
|
|
172
|
+
let data = queryClient.getQueryData(queryKey);
|
|
173
173
|
if (path) {
|
|
174
174
|
data = result(data, path);
|
|
175
175
|
}
|
|
@@ -207,7 +207,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
207
207
|
queryClient.setQueryData(queryKey, newData);
|
|
208
208
|
}
|
|
209
209
|
else {
|
|
210
|
-
const queryData = queryClient.getQueryData(queryKey
|
|
210
|
+
const queryData = queryClient.getQueryData(queryKey) ?? {};
|
|
211
211
|
queryClient.setQueryData(queryKey, lodashSet(queryData, path, newData));
|
|
212
212
|
}
|
|
213
213
|
return updatedRecord;
|
|
@@ -232,7 +232,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
232
232
|
queryClient.setQueryData(queryKey, newData);
|
|
233
233
|
}
|
|
234
234
|
else {
|
|
235
|
-
const queryData = queryClient.getQueryData(queryKey
|
|
235
|
+
const queryData = queryClient.getQueryData(queryKey) ?? {};
|
|
236
236
|
queryClient.setQueryData(queryKey, lodashSet(queryData, path, newData));
|
|
237
237
|
}
|
|
238
238
|
return updated;
|
|
@@ -247,7 +247,7 @@ const useRefetchQuery = async (queryKey) => {
|
|
|
247
247
|
queryKey: innerQueryKey ?? queryKey,
|
|
248
248
|
exact: true,
|
|
249
249
|
}, { throwOnError: true, cancelRefetch: true });
|
|
250
|
-
return queryClient.getQueriesData(innerQueryKey ?? queryKey);
|
|
250
|
+
return queryClient.getQueriesData({ queryKey: innerQueryKey ?? queryKey });
|
|
251
251
|
};
|
|
252
252
|
return { refetchQuery };
|
|
253
253
|
};
|
|
@@ -450,7 +450,12 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
450
450
|
rej(null);
|
|
451
451
|
}
|
|
452
452
|
};
|
|
453
|
-
const query = useQuery(
|
|
453
|
+
const query = useQuery({
|
|
454
|
+
queryKey: [requestPath, {}],
|
|
455
|
+
queryFn: ({ queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey)),
|
|
456
|
+
enabled: false,
|
|
457
|
+
...options,
|
|
458
|
+
});
|
|
454
459
|
const updatedPathAsync = async (link) => {
|
|
455
460
|
return setRequestPath(link);
|
|
456
461
|
};
|
|
@@ -460,8 +465,7 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
460
465
|
const destroy = async (link, internalDeleteOptions) => {
|
|
461
466
|
if (!isFutureQueriesPaused) {
|
|
462
467
|
// set enabled to be true for every delete
|
|
463
|
-
internalDeleteOptions = internalDeleteOptions ?? {};
|
|
464
|
-
internalDeleteOptions.enabled = true;
|
|
468
|
+
internalDeleteOptions = internalDeleteOptions ?? { queryKey: [] };
|
|
465
469
|
await setOptionsAsync(internalDeleteOptions);
|
|
466
470
|
await updatedPathAsync(link);
|
|
467
471
|
return query.data;
|
|
@@ -533,7 +537,9 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
533
537
|
queryParams.set('page', String(lastPageItem));
|
|
534
538
|
return pathname + '?' + queryParams.toString();
|
|
535
539
|
};
|
|
536
|
-
const query = useInfiniteQuery(
|
|
540
|
+
const query = useInfiniteQuery({
|
|
541
|
+
queryKey: [requestPath, {}],
|
|
542
|
+
queryFn: ({ pageParam = requestPath, queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey, pageParam)),
|
|
537
543
|
enabled: load && !isFutureQueriesPaused,
|
|
538
544
|
getNextPageParam: (lastPage) => constructPaginationLink('next_page', lastPage),
|
|
539
545
|
getPreviousPageParam: (lastPage) => constructPaginationLink('previous_page', lastPage),
|
|
@@ -571,7 +577,6 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
571
577
|
if (keyTracker) {
|
|
572
578
|
// set expiration time for the tracker
|
|
573
579
|
queryClient.setQueryDefaults([keyTracker], {
|
|
574
|
-
cacheTime: Infinity,
|
|
575
580
|
staleTime: Infinity,
|
|
576
581
|
});
|
|
577
582
|
queryClient.setQueryData([keyTracker], [requestPath, {}]);
|
|
@@ -627,7 +632,9 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
627
632
|
res(null);
|
|
628
633
|
}
|
|
629
634
|
};
|
|
630
|
-
const query = useQuery(
|
|
635
|
+
const query = useQuery({
|
|
636
|
+
queryKey: [requestPath, {}],
|
|
637
|
+
queryFn: ({ queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey)),
|
|
631
638
|
enabled: load && !isFutureQueriesPaused,
|
|
632
639
|
...options,
|
|
633
640
|
});
|
|
@@ -640,27 +647,22 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
640
647
|
if (keyTracker) {
|
|
641
648
|
// set expiration time for the tracker
|
|
642
649
|
queryClient.setQueryDefaults([keyTracker], {
|
|
643
|
-
cacheTime: Infinity,
|
|
644
650
|
staleTime: Infinity,
|
|
645
651
|
});
|
|
646
652
|
queryClient.setQueryData([keyTracker], [requestPath, {}]);
|
|
647
653
|
}
|
|
648
654
|
}, [keyTracker, requestPath, queryClient, queryOptions?.staleTime]);
|
|
649
|
-
const nextPage = (
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (data?.data.pagination) {
|
|
653
|
-
const pagination = data.data.pagination;
|
|
655
|
+
const nextPage = () => {
|
|
656
|
+
if (query.data?.data.pagination) {
|
|
657
|
+
const pagination = query.data.data.pagination;
|
|
654
658
|
if (pagination.next_page !== pagination.current_page && pagination.next_page > pagination.current_page) {
|
|
655
659
|
setRequestPath(constructPaginationLink(requestPath, pagination.next_page));
|
|
656
660
|
}
|
|
657
661
|
}
|
|
658
662
|
};
|
|
659
|
-
const prevPage = (
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (data?.data.pagination) {
|
|
663
|
-
const pagination = data.data.pagination;
|
|
663
|
+
const prevPage = () => {
|
|
664
|
+
if (query.data?.data.pagination) {
|
|
665
|
+
const pagination = query.data.data.pagination;
|
|
664
666
|
if (pagination.previous_page !== pagination.current_page && pagination.previous_page < pagination.current_page) {
|
|
665
667
|
setRequestPath(constructPaginationLink(requestPath, pagination.previous_page));
|
|
666
668
|
}
|
|
@@ -769,9 +771,12 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
769
771
|
}
|
|
770
772
|
};
|
|
771
773
|
// register post mutation
|
|
772
|
-
const mutation = useMutation(
|
|
773
|
-
|
|
774
|
-
|
|
774
|
+
const mutation = useMutation({
|
|
775
|
+
mutationFn: (dataData) => new Promise((res, rej) => {
|
|
776
|
+
return sendRequest(res, rej, dataData);
|
|
777
|
+
}),
|
|
778
|
+
mutationKey: [path, { type: 'mutation' }],
|
|
779
|
+
});
|
|
775
780
|
const patch = async (data, options) => {
|
|
776
781
|
if (!isFutureMutationsPaused) {
|
|
777
782
|
return mutation.mutateAsync(data, options);
|
|
@@ -788,7 +793,7 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
788
793
|
}
|
|
789
794
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
790
795
|
}, [isFutureMutationsPaused]);
|
|
791
|
-
return { patch, uploadProgressPercent, ...mutation, isLoading: mutation.
|
|
796
|
+
return { patch, uploadProgressPercent, ...mutation, isLoading: mutation.isPending || isFutureMutationsPaused };
|
|
792
797
|
};
|
|
793
798
|
|
|
794
799
|
const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelectors, }) => {
|
|
@@ -847,7 +852,8 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
847
852
|
}
|
|
848
853
|
};
|
|
849
854
|
// register post mutation
|
|
850
|
-
const mutation = useMutation(
|
|
855
|
+
const mutation = useMutation({
|
|
856
|
+
mutationFn: async (postData) => new Promise((res, rej) => sendRequest(res, rej, postData)),
|
|
851
857
|
mutationKey: [path, { type: 'mutation' }],
|
|
852
858
|
});
|
|
853
859
|
const post = async (data, options) => {
|
|
@@ -867,7 +873,7 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
867
873
|
}
|
|
868
874
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
869
875
|
}, [isFutureMutationsPaused]);
|
|
870
|
-
return { post, uploadProgressPercent, ...mutation, isLoading: mutation.
|
|
876
|
+
return { post, uploadProgressPercent, ...mutation, isLoading: mutation.isPending || isFutureMutationsPaused };
|
|
871
877
|
};
|
|
872
878
|
|
|
873
879
|
export { ContentType, HttpMethod, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, getDateInFuture, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetInfiniteRequest, useGetRequest, useHeaderStore, useKeyTrackerModel, usePatchRequest, usePauseFutureRequests, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useReactNativeEnv, useRefetchQuery, useUploadProgress };
|
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,2 +1,2 @@
|
|
|
1
1
|
import type { QueryModelBuilder } from './model.interface';
|
|
2
|
-
export declare const useQueryModel: <T>(keyTracker: string
|
|
2
|
+
export declare const useQueryModel: <T>(keyTracker: string) => QueryModelBuilder<T>;
|
|
@@ -7,7 +7,7 @@ import '../stores/useHeaderStore.js';
|
|
|
7
7
|
import '../stores/usePauseFutureRequests.js';
|
|
8
8
|
import { useKeyTrackerModel } from './useKeyTrackerModel.js';
|
|
9
9
|
|
|
10
|
-
const useQueryModel = (keyTracker
|
|
10
|
+
const useQueryModel = (keyTracker) => {
|
|
11
11
|
const queryClient = useQueryClient();
|
|
12
12
|
const { getQueryKey } = useKeyTrackerModel(keyTracker);
|
|
13
13
|
const queryKey = getQueryKey();
|
|
@@ -25,13 +25,13 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
25
25
|
queryClient.setQueryData(queryKey, records);
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
const queryData = queryClient.getQueryData(queryKey
|
|
28
|
+
const queryData = queryClient.getQueryData(queryKey) ?? {};
|
|
29
29
|
queryClient.setQueryData(queryKey, lodashSet(queryData, path, records));
|
|
30
30
|
}
|
|
31
31
|
return data;
|
|
32
32
|
};
|
|
33
33
|
const findAll = (path) => {
|
|
34
|
-
const data = queryClient.getQueryData(queryKey
|
|
34
|
+
const data = queryClient.getQueryData(queryKey);
|
|
35
35
|
if (!data) {
|
|
36
36
|
return [];
|
|
37
37
|
}
|
|
@@ -53,7 +53,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
53
53
|
return data.find((record) => record[modelConfig.idColumn] === id);
|
|
54
54
|
};
|
|
55
55
|
const get = (path) => {
|
|
56
|
-
let data = queryClient.getQueryData(queryKey
|
|
56
|
+
let data = queryClient.getQueryData(queryKey);
|
|
57
57
|
if (path) {
|
|
58
58
|
data = result(data, path);
|
|
59
59
|
}
|
|
@@ -91,7 +91,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
91
91
|
queryClient.setQueryData(queryKey, newData);
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
|
-
const queryData = queryClient.getQueryData(queryKey
|
|
94
|
+
const queryData = queryClient.getQueryData(queryKey) ?? {};
|
|
95
95
|
queryClient.setQueryData(queryKey, lodashSet(queryData, path, newData));
|
|
96
96
|
}
|
|
97
97
|
return updatedRecord;
|
|
@@ -116,7 +116,7 @@ const useQueryModel = (keyTracker, exact = true) => {
|
|
|
116
116
|
queryClient.setQueryData(queryKey, newData);
|
|
117
117
|
}
|
|
118
118
|
else {
|
|
119
|
-
const queryData = queryClient.getQueryData(queryKey
|
|
119
|
+
const queryData = queryClient.getQueryData(queryKey) ?? {};
|
|
120
120
|
queryClient.setQueryData(queryKey, lodashSet(queryData, path, newData));
|
|
121
121
|
}
|
|
122
122
|
return updated;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const useRefetchQuery: (queryKey: any[]) => Promise<{
|
|
2
|
-
refetchQuery: <T>(innerQueryKey?: any[]) => Promise<[import("@tanstack/
|
|
2
|
+
refetchQuery: <T>(innerQueryKey?: any[]) => Promise<[import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").t, T | undefined][]>;
|
|
3
3
|
}>;
|
|
@@ -7,7 +7,7 @@ const useRefetchQuery = async (queryKey) => {
|
|
|
7
7
|
queryKey: innerQueryKey ?? queryKey,
|
|
8
8
|
exact: true,
|
|
9
9
|
}, { throwOnError: true, cancelRefetch: true });
|
|
10
|
-
return queryClient.getQueriesData(innerQueryKey ?? queryKey);
|
|
10
|
+
return queryClient.getQueriesData({ queryKey: innerQueryKey ?? queryKey });
|
|
11
11
|
};
|
|
12
12
|
return { refetchQuery };
|
|
13
13
|
};
|
|
@@ -6,6 +6,7 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
6
6
|
data: IRequestSuccess<TResponse>;
|
|
7
7
|
error: any;
|
|
8
8
|
isError: true;
|
|
9
|
+
isPending: false;
|
|
9
10
|
isLoadingError: false;
|
|
10
11
|
isRefetchError: true;
|
|
11
12
|
isSuccess: false;
|
|
@@ -21,12 +22,10 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
21
22
|
isInitialLoading: boolean;
|
|
22
23
|
isPaused: boolean;
|
|
23
24
|
isPlaceholderData: boolean;
|
|
24
|
-
isPreviousData: boolean;
|
|
25
25
|
isRefetching: boolean;
|
|
26
26
|
isStale: boolean;
|
|
27
|
-
refetch:
|
|
28
|
-
|
|
29
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
27
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").a4 | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ak<IRequestSuccess<TResponse>, any>>;
|
|
28
|
+
fetchStatus: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ac;
|
|
30
29
|
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
31
30
|
cached?: boolean | undefined;
|
|
32
31
|
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
@@ -35,6 +34,7 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
35
34
|
data: IRequestSuccess<TResponse>;
|
|
36
35
|
error: null;
|
|
37
36
|
isError: false;
|
|
37
|
+
isPending: false;
|
|
38
38
|
isLoadingError: false;
|
|
39
39
|
isRefetchError: false;
|
|
40
40
|
isSuccess: true;
|
|
@@ -50,70 +50,10 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
50
50
|
isInitialLoading: boolean;
|
|
51
51
|
isPaused: boolean;
|
|
52
52
|
isPlaceholderData: boolean;
|
|
53
|
-
isPreviousData: boolean;
|
|
54
53
|
isRefetching: boolean;
|
|
55
54
|
isStale: boolean;
|
|
56
|
-
refetch:
|
|
57
|
-
|
|
58
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
59
|
-
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
60
|
-
cached?: boolean | undefined;
|
|
61
|
-
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
62
|
-
} | {
|
|
63
|
-
isLoading: boolean;
|
|
64
|
-
data: undefined;
|
|
65
|
-
error: any;
|
|
66
|
-
isError: true;
|
|
67
|
-
isLoadingError: true;
|
|
68
|
-
isRefetchError: false;
|
|
69
|
-
isSuccess: false;
|
|
70
|
-
status: "error";
|
|
71
|
-
dataUpdatedAt: number;
|
|
72
|
-
errorUpdatedAt: number;
|
|
73
|
-
failureCount: number;
|
|
74
|
-
failureReason: any;
|
|
75
|
-
errorUpdateCount: number;
|
|
76
|
-
isFetched: boolean;
|
|
77
|
-
isFetchedAfterMount: boolean;
|
|
78
|
-
isFetching: boolean;
|
|
79
|
-
isInitialLoading: boolean;
|
|
80
|
-
isPaused: boolean;
|
|
81
|
-
isPlaceholderData: boolean;
|
|
82
|
-
isPreviousData: boolean;
|
|
83
|
-
isRefetching: boolean;
|
|
84
|
-
isStale: boolean;
|
|
85
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
86
|
-
remove: () => void;
|
|
87
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
88
|
-
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
89
|
-
cached?: boolean | undefined;
|
|
90
|
-
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
91
|
-
} | {
|
|
92
|
-
isLoading: boolean;
|
|
93
|
-
data: undefined;
|
|
94
|
-
error: null;
|
|
95
|
-
isError: false;
|
|
96
|
-
isLoadingError: false;
|
|
97
|
-
isRefetchError: false;
|
|
98
|
-
isSuccess: false;
|
|
99
|
-
status: "loading";
|
|
100
|
-
dataUpdatedAt: number;
|
|
101
|
-
errorUpdatedAt: number;
|
|
102
|
-
failureCount: number;
|
|
103
|
-
failureReason: any;
|
|
104
|
-
errorUpdateCount: number;
|
|
105
|
-
isFetched: boolean;
|
|
106
|
-
isFetchedAfterMount: boolean;
|
|
107
|
-
isFetching: boolean;
|
|
108
|
-
isInitialLoading: boolean;
|
|
109
|
-
isPaused: boolean;
|
|
110
|
-
isPlaceholderData: boolean;
|
|
111
|
-
isPreviousData: boolean;
|
|
112
|
-
isRefetching: boolean;
|
|
113
|
-
isStale: boolean;
|
|
114
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
115
|
-
remove: () => void;
|
|
116
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
55
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").a4 | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ak<IRequestSuccess<TResponse>, any>>;
|
|
56
|
+
fetchStatus: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ac;
|
|
117
57
|
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
118
58
|
cached?: boolean | undefined;
|
|
119
59
|
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
@@ -45,7 +45,12 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
45
45
|
rej(null);
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
const query = useQuery(
|
|
48
|
+
const query = useQuery({
|
|
49
|
+
queryKey: [requestPath, {}],
|
|
50
|
+
queryFn: ({ queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey)),
|
|
51
|
+
enabled: false,
|
|
52
|
+
...options,
|
|
53
|
+
});
|
|
49
54
|
const updatedPathAsync = async (link) => {
|
|
50
55
|
return setRequestPath(link);
|
|
51
56
|
};
|
|
@@ -55,8 +60,7 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
55
60
|
const destroy = async (link, internalDeleteOptions) => {
|
|
56
61
|
if (!isFutureQueriesPaused) {
|
|
57
62
|
// set enabled to be true for every delete
|
|
58
|
-
internalDeleteOptions = internalDeleteOptions ?? {};
|
|
59
|
-
internalDeleteOptions.enabled = true;
|
|
63
|
+
internalDeleteOptions = internalDeleteOptions ?? { queryKey: [] };
|
|
60
64
|
await setOptionsAsync(internalDeleteOptions);
|
|
61
65
|
await updatedPathAsync(link);
|
|
62
66
|
return query.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
2
2
|
import type { IRequestError, IRequestSuccess } from '../request';
|
|
3
3
|
import type { DefaultRequestOptions, TanstackInfiniteQueryOption } from './queries.interface';
|
|
4
4
|
interface Pagination {
|
|
@@ -18,105 +18,24 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
18
18
|
keyTracker?: string | undefined;
|
|
19
19
|
} & DefaultRequestOptions) => {
|
|
20
20
|
isLoading: boolean;
|
|
21
|
-
data:
|
|
22
|
-
error: any;
|
|
23
|
-
isError: true;
|
|
24
|
-
isLoadingError: true;
|
|
25
|
-
isRefetchError: false;
|
|
26
|
-
isSuccess: false;
|
|
27
|
-
status: "error";
|
|
28
|
-
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
29
|
-
pagination: Pagination;
|
|
30
|
-
}>, any>>;
|
|
31
|
-
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
32
|
-
pagination: Pagination;
|
|
33
|
-
}>, any>>;
|
|
34
|
-
hasNextPage?: boolean | undefined;
|
|
35
|
-
hasPreviousPage?: boolean | undefined;
|
|
36
|
-
isFetchingNextPage: boolean;
|
|
37
|
-
isFetchingPreviousPage: boolean;
|
|
38
|
-
dataUpdatedAt: number;
|
|
39
|
-
errorUpdatedAt: number;
|
|
40
|
-
failureCount: number;
|
|
41
|
-
failureReason: any;
|
|
42
|
-
errorUpdateCount: number;
|
|
43
|
-
isFetched: boolean;
|
|
44
|
-
isFetchedAfterMount: boolean;
|
|
45
|
-
isFetching: boolean;
|
|
46
|
-
isInitialLoading: boolean;
|
|
47
|
-
isPaused: boolean;
|
|
48
|
-
isPlaceholderData: boolean;
|
|
49
|
-
isPreviousData: boolean;
|
|
50
|
-
isRefetching: boolean;
|
|
51
|
-
isStale: boolean;
|
|
52
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<IRequestSuccess<TResponse & {
|
|
53
|
-
pagination: Pagination;
|
|
54
|
-
}>>, any>>;
|
|
55
|
-
remove: () => void;
|
|
56
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
57
|
-
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<InfiniteData<IRequestSuccess<TResponse & {
|
|
58
|
-
pagination: Pagination;
|
|
59
|
-
}>> | undefined>;
|
|
60
|
-
} | {
|
|
61
|
-
isLoading: boolean;
|
|
62
|
-
data: undefined;
|
|
63
|
-
error: null;
|
|
64
|
-
isError: false;
|
|
65
|
-
isLoadingError: false;
|
|
66
|
-
isRefetchError: false;
|
|
67
|
-
isSuccess: false;
|
|
68
|
-
status: "loading";
|
|
69
|
-
fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
21
|
+
data: IRequestSuccess<TResponse & {
|
|
70
22
|
pagination: Pagination;
|
|
71
|
-
}
|
|
72
|
-
fetchPreviousPage: (options?: import("@tanstack/react-query").FetchPreviousPageOptions | undefined) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<IRequestSuccess<TResponse & {
|
|
73
|
-
pagination: Pagination;
|
|
74
|
-
}>, any>>;
|
|
75
|
-
hasNextPage?: boolean | undefined;
|
|
76
|
-
hasPreviousPage?: boolean | undefined;
|
|
77
|
-
isFetchingNextPage: boolean;
|
|
78
|
-
isFetchingPreviousPage: boolean;
|
|
79
|
-
dataUpdatedAt: number;
|
|
80
|
-
errorUpdatedAt: number;
|
|
81
|
-
failureCount: number;
|
|
82
|
-
failureReason: any;
|
|
83
|
-
errorUpdateCount: number;
|
|
84
|
-
isFetched: boolean;
|
|
85
|
-
isFetchedAfterMount: boolean;
|
|
86
|
-
isFetching: boolean;
|
|
87
|
-
isInitialLoading: boolean;
|
|
88
|
-
isPaused: boolean;
|
|
89
|
-
isPlaceholderData: boolean;
|
|
90
|
-
isPreviousData: boolean;
|
|
91
|
-
isRefetching: boolean;
|
|
92
|
-
isStale: boolean;
|
|
93
|
-
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<IRequestSuccess<TResponse & {
|
|
94
|
-
pagination: Pagination;
|
|
95
|
-
}>>, any>>;
|
|
96
|
-
remove: () => void;
|
|
97
|
-
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
98
|
-
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<InfiniteData<IRequestSuccess<TResponse & {
|
|
99
|
-
pagination: Pagination;
|
|
100
|
-
}>> | undefined>;
|
|
101
|
-
} | {
|
|
102
|
-
isLoading: boolean;
|
|
103
|
-
data: InfiniteData<IRequestSuccess<TResponse & {
|
|
104
|
-
pagination: Pagination;
|
|
105
|
-
}>>;
|
|
23
|
+
}>;
|
|
106
24
|
error: any;
|
|
107
25
|
isError: true;
|
|
26
|
+
isPending: false;
|
|
108
27
|
isLoadingError: false;
|
|
109
28
|
isRefetchError: true;
|
|
110
29
|
isSuccess: false;
|
|
111
30
|
status: "error";
|
|
112
|
-
fetchNextPage: (options?: import("@tanstack/
|
|
31
|
+
fetchNextPage: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").a9 | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").as<IRequestSuccess<TResponse & {
|
|
113
32
|
pagination: Pagination;
|
|
114
33
|
}>, any>>;
|
|
115
|
-
fetchPreviousPage: (options?: import("@tanstack/
|
|
34
|
+
fetchPreviousPage: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").aa | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").as<IRequestSuccess<TResponse & {
|
|
116
35
|
pagination: Pagination;
|
|
117
36
|
}>, any>>;
|
|
118
|
-
hasNextPage
|
|
119
|
-
hasPreviousPage
|
|
37
|
+
hasNextPage: boolean;
|
|
38
|
+
hasPreviousPage: boolean;
|
|
120
39
|
isFetchingNextPage: boolean;
|
|
121
40
|
isFetchingPreviousPage: boolean;
|
|
122
41
|
dataUpdatedAt: number;
|
|
@@ -130,36 +49,35 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
130
49
|
isInitialLoading: boolean;
|
|
131
50
|
isPaused: boolean;
|
|
132
51
|
isPlaceholderData: boolean;
|
|
133
|
-
isPreviousData: boolean;
|
|
134
52
|
isRefetching: boolean;
|
|
135
53
|
isStale: boolean;
|
|
136
|
-
refetch:
|
|
54
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").a4 | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ak<IRequestSuccess<TResponse & {
|
|
137
55
|
pagination: Pagination;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<InfiniteData<IRequestSuccess<TResponse & {
|
|
56
|
+
}>, any>>;
|
|
57
|
+
fetchStatus: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ac;
|
|
58
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse & {
|
|
142
59
|
pagination: Pagination;
|
|
143
|
-
}
|
|
60
|
+
}> | undefined>;
|
|
144
61
|
} | {
|
|
145
62
|
isLoading: boolean;
|
|
146
|
-
data:
|
|
63
|
+
data: IRequestSuccess<TResponse & {
|
|
147
64
|
pagination: Pagination;
|
|
148
|
-
}
|
|
65
|
+
}>;
|
|
149
66
|
error: null;
|
|
150
67
|
isError: false;
|
|
68
|
+
isPending: false;
|
|
151
69
|
isLoadingError: false;
|
|
152
70
|
isRefetchError: false;
|
|
153
71
|
isSuccess: true;
|
|
154
72
|
status: "success";
|
|
155
|
-
fetchNextPage: (options?: import("@tanstack/
|
|
73
|
+
fetchNextPage: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").a9 | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").as<IRequestSuccess<TResponse & {
|
|
156
74
|
pagination: Pagination;
|
|
157
75
|
}>, any>>;
|
|
158
|
-
fetchPreviousPage: (options?: import("@tanstack/
|
|
76
|
+
fetchPreviousPage: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").aa | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").as<IRequestSuccess<TResponse & {
|
|
159
77
|
pagination: Pagination;
|
|
160
78
|
}>, any>>;
|
|
161
|
-
hasNextPage
|
|
162
|
-
hasPreviousPage
|
|
79
|
+
hasNextPage: boolean;
|
|
80
|
+
hasPreviousPage: boolean;
|
|
163
81
|
isFetchingNextPage: boolean;
|
|
164
82
|
isFetchingPreviousPage: boolean;
|
|
165
83
|
dataUpdatedAt: number;
|
|
@@ -173,16 +91,14 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
|
|
|
173
91
|
isInitialLoading: boolean;
|
|
174
92
|
isPaused: boolean;
|
|
175
93
|
isPlaceholderData: boolean;
|
|
176
|
-
isPreviousData: boolean;
|
|
177
94
|
isRefetching: boolean;
|
|
178
95
|
isStale: boolean;
|
|
179
|
-
refetch:
|
|
96
|
+
refetch: (options?: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").a4 | undefined) => Promise<import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ak<IRequestSuccess<TResponse & {
|
|
180
97
|
pagination: Pagination;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<InfiniteData<IRequestSuccess<TResponse & {
|
|
98
|
+
}>, any>>;
|
|
99
|
+
fetchStatus: import("@tanstack/query-core/build/legacy/queryClient-K0zFyarY").ac;
|
|
100
|
+
get: (link: string, fetchOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> | undefined) => Promise<IRequestSuccess<TResponse & {
|
|
185
101
|
pagination: Pagination;
|
|
186
|
-
}
|
|
102
|
+
}> | undefined>;
|
|
187
103
|
};
|
|
188
104
|
export {};
|
|
@@ -61,7 +61,9 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
61
61
|
queryParams.set('page', String(lastPageItem));
|
|
62
62
|
return pathname + '?' + queryParams.toString();
|
|
63
63
|
};
|
|
64
|
-
const query = useInfiniteQuery(
|
|
64
|
+
const query = useInfiniteQuery({
|
|
65
|
+
queryKey: [requestPath, {}],
|
|
66
|
+
queryFn: ({ pageParam = requestPath, queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey, pageParam)),
|
|
65
67
|
enabled: load && !isFutureQueriesPaused,
|
|
66
68
|
getNextPageParam: (lastPage) => constructPaginationLink('next_page', lastPage),
|
|
67
69
|
getPreviousPageParam: (lastPage) => constructPaginationLink('previous_page', lastPage),
|
|
@@ -99,7 +101,6 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
|
|
|
99
101
|
if (keyTracker) {
|
|
100
102
|
// set expiration time for the tracker
|
|
101
103
|
queryClient.setQueryDefaults([keyTracker], {
|
|
102
|
-
cacheTime: Infinity,
|
|
103
104
|
staleTime: Infinity,
|
|
104
105
|
});
|
|
105
106
|
queryClient.setQueryData([keyTracker], [requestPath, {}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetInfiniteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGetInfiniteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|