@ventlio/tanstack-query 0.2.66 → 0.2.69
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 +9 -3
- package/dist/index.mjs.map +1 -1
- package/dist/queries/useDeleteRequest.d.ts +12 -4
- package/dist/queries/useDeleteRequest.js +1 -1
- package/dist/queries/usePatchRequest.js +9 -3
- package/dist/queries/usePatchRequest.js.map +1 -1
- package/package.json +1 -1
- package/src/queries/useDeleteRequest.ts +2 -2
- package/src/queries/usePatchRequest.ts +11 -3
package/dist/index.mjs
CHANGED
|
@@ -424,8 +424,8 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
424
424
|
// set enabled to be true for every delete
|
|
425
425
|
internalDeleteOptions = internalDeleteOptions ?? {};
|
|
426
426
|
internalDeleteOptions.enabled = true;
|
|
427
|
-
await updatedPathAsync(link);
|
|
428
427
|
await setOptionsAsync(internalDeleteOptions);
|
|
428
|
+
await updatedPathAsync(link);
|
|
429
429
|
return query.data;
|
|
430
430
|
};
|
|
431
431
|
return { destroy, ...query };
|
|
@@ -541,6 +541,8 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
|
|
|
541
541
|
const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
542
542
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
543
543
|
const { getHeaders } = useQueryHeaders();
|
|
544
|
+
const queryClient = useQueryClient();
|
|
545
|
+
const config = queryClient.getQueryData(['config']);
|
|
544
546
|
const sendRequest = async (res, rej, data) => {
|
|
545
547
|
// get request headers
|
|
546
548
|
const globalHeaders = getHeaders();
|
|
@@ -554,12 +556,16 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
554
556
|
});
|
|
555
557
|
if (patchResponse.status) {
|
|
556
558
|
// scroll to top after success
|
|
557
|
-
|
|
559
|
+
if (config?.options?.context !== 'app') {
|
|
560
|
+
scrollToTop();
|
|
561
|
+
}
|
|
558
562
|
res(patchResponse);
|
|
559
563
|
}
|
|
560
564
|
else {
|
|
561
565
|
// scroll to top after error
|
|
562
|
-
|
|
566
|
+
if (config?.options?.context !== 'app') {
|
|
567
|
+
scrollToTop();
|
|
568
|
+
}
|
|
563
569
|
rej(patchResponse);
|
|
564
570
|
}
|
|
565
571
|
};
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -27,7 +27,9 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
27
27
|
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
28
28
|
remove: () => void;
|
|
29
29
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
30
|
-
destroy: (link: string, internalDeleteOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]>
|
|
30
|
+
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
31
|
+
cached?: boolean | undefined;
|
|
32
|
+
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
31
33
|
} | {
|
|
32
34
|
data: IRequestSuccess<TResponse>;
|
|
33
35
|
error: null;
|
|
@@ -54,7 +56,9 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
54
56
|
refetch: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<IRequestSuccess<TResponse>, any>>;
|
|
55
57
|
remove: () => void;
|
|
56
58
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
57
|
-
destroy: (link: string, internalDeleteOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]>
|
|
59
|
+
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
60
|
+
cached?: boolean | undefined;
|
|
61
|
+
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
58
62
|
} | {
|
|
59
63
|
data: undefined;
|
|
60
64
|
error: any;
|
|
@@ -81,7 +85,9 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
81
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>>;
|
|
82
86
|
remove: () => void;
|
|
83
87
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
84
|
-
destroy: (link: string, internalDeleteOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]>
|
|
88
|
+
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
89
|
+
cached?: boolean | undefined;
|
|
90
|
+
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
85
91
|
} | {
|
|
86
92
|
data: undefined;
|
|
87
93
|
error: null;
|
|
@@ -108,5 +114,7 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
|
|
|
108
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>>;
|
|
109
115
|
remove: () => void;
|
|
110
116
|
fetchStatus: import("@tanstack/react-query").FetchStatus;
|
|
111
|
-
destroy: (link: string, internalDeleteOptions?: UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]>
|
|
117
|
+
destroy: (link: string, internalDeleteOptions?: (UseQueryOptions<IRequestSuccess<TResponse | undefined>, IRequestError, IRequestSuccess<TResponse | undefined>, any[]> & {
|
|
118
|
+
cached?: boolean | undefined;
|
|
119
|
+
}) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
|
|
112
120
|
};
|
|
@@ -40,8 +40,8 @@ const useDeleteRequest = (deleteOptions) => {
|
|
|
40
40
|
// set enabled to be true for every delete
|
|
41
41
|
internalDeleteOptions = internalDeleteOptions ?? {};
|
|
42
42
|
internalDeleteOptions.enabled = true;
|
|
43
|
-
await updatedPathAsync(link);
|
|
44
43
|
await setOptionsAsync(internalDeleteOptions);
|
|
44
|
+
await updatedPathAsync(link);
|
|
45
45
|
return query.data;
|
|
46
46
|
};
|
|
47
47
|
return { destroy, ...query };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation } from '@tanstack/react-query';
|
|
1
|
+
import { useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { useEnvironmentVariables } from '../config/useEnvironmentVariables.js';
|
|
3
3
|
import { useQueryHeaders } from '../config/useQueryHeaders.js';
|
|
4
4
|
import { scrollToTop } from '../helpers/scrollToTop.js';
|
|
@@ -9,6 +9,8 @@ import { HttpMethod } from '../request/request.enum.js';
|
|
|
9
9
|
const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
10
10
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
11
11
|
const { getHeaders } = useQueryHeaders();
|
|
12
|
+
const queryClient = useQueryClient();
|
|
13
|
+
const config = queryClient.getQueryData(['config']);
|
|
12
14
|
const sendRequest = async (res, rej, data) => {
|
|
13
15
|
// get request headers
|
|
14
16
|
const globalHeaders = getHeaders();
|
|
@@ -22,12 +24,16 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
|
|
|
22
24
|
});
|
|
23
25
|
if (patchResponse.status) {
|
|
24
26
|
// scroll to top after success
|
|
25
|
-
|
|
27
|
+
if (config?.options?.context !== 'app') {
|
|
28
|
+
scrollToTop();
|
|
29
|
+
}
|
|
26
30
|
res(patchResponse);
|
|
27
31
|
}
|
|
28
32
|
else {
|
|
29
33
|
// scroll to top after error
|
|
30
|
-
|
|
34
|
+
if (config?.options?.context !== 'app') {
|
|
35
|
+
scrollToTop();
|
|
36
|
+
}
|
|
31
37
|
rej(patchResponse);
|
|
32
38
|
}
|
|
33
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePatchRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePatchRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -56,14 +56,14 @@ export const useDeleteRequest = <TResponse>(deleteOptions?: DefaultRequestOption
|
|
|
56
56
|
IRequestError,
|
|
57
57
|
IRequestSuccess<TResponse | undefined>,
|
|
58
58
|
Array<any>
|
|
59
|
-
>
|
|
59
|
+
> & { cached?: boolean }
|
|
60
60
|
): Promise<IRequestSuccess<TResponse> | undefined> => {
|
|
61
61
|
// set enabled to be true for every delete
|
|
62
62
|
internalDeleteOptions = internalDeleteOptions ?? {};
|
|
63
63
|
internalDeleteOptions.enabled = true;
|
|
64
64
|
|
|
65
|
-
await updatedPathAsync(link);
|
|
66
65
|
await setOptionsAsync(internalDeleteOptions);
|
|
66
|
+
await updatedPathAsync(link);
|
|
67
67
|
|
|
68
68
|
return query.data;
|
|
69
69
|
};
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { MutateOptions } from '@tanstack/react-query';
|
|
2
|
-
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
3
3
|
import type { RawAxiosRequestHeaders } from 'axios';
|
|
4
4
|
import { useEnvironmentVariables, useQueryHeaders } from '../config';
|
|
5
5
|
import { scrollToTop } from '../helpers';
|
|
6
6
|
import { HttpMethod, makeRequest } from '../request';
|
|
7
7
|
import type { IRequestError, IRequestSuccess } from '../request/request.interface';
|
|
8
|
+
import type { TanstackQueryConfig } from '../types';
|
|
8
9
|
import type { DefaultRequestOptions } from './queries.interface';
|
|
9
10
|
|
|
10
11
|
export const usePatchRequest = <TResponse>({ path, baseUrl, headers }: { path: string } & DefaultRequestOptions) => {
|
|
11
12
|
const { API_URL, TIMEOUT } = useEnvironmentVariables();
|
|
12
13
|
|
|
13
14
|
const { getHeaders } = useQueryHeaders();
|
|
15
|
+
const queryClient = useQueryClient();
|
|
16
|
+
|
|
17
|
+
const config = queryClient.getQueryData<TanstackQueryConfig>(['config']);
|
|
14
18
|
|
|
15
19
|
const sendRequest = async (res: (value: any) => void, rej: (reason?: any) => void, data: any) => {
|
|
16
20
|
// get request headers
|
|
@@ -27,11 +31,15 @@ export const usePatchRequest = <TResponse>({ path, baseUrl, headers }: { path: s
|
|
|
27
31
|
|
|
28
32
|
if (patchResponse.status) {
|
|
29
33
|
// scroll to top after success
|
|
30
|
-
|
|
34
|
+
if (config?.options?.context !== 'app') {
|
|
35
|
+
scrollToTop();
|
|
36
|
+
}
|
|
31
37
|
res(patchResponse as IRequestSuccess<TResponse>);
|
|
32
38
|
} else {
|
|
33
39
|
// scroll to top after error
|
|
34
|
-
|
|
40
|
+
if (config?.options?.context !== 'app') {
|
|
41
|
+
scrollToTop();
|
|
42
|
+
}
|
|
35
43
|
rej(patchResponse);
|
|
36
44
|
}
|
|
37
45
|
};
|