@ventlio/tanstack-query 0.2.78 → 0.2.80
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
CHANGED
|
@@ -681,9 +681,11 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
681
681
|
// get request headers
|
|
682
682
|
const globalHeaders = getHeaders();
|
|
683
683
|
const config = queryClient.getQueryData(['config']);
|
|
684
|
+
const { data, requestConfig } = postData;
|
|
685
|
+
delete requestConfig?.body;
|
|
684
686
|
const postResponse = await makeRequest({
|
|
685
687
|
path,
|
|
686
|
-
body:
|
|
688
|
+
body: data,
|
|
687
689
|
method: HttpMethod.POST,
|
|
688
690
|
isFormData,
|
|
689
691
|
headers: { ...globalHeaders, ...headers },
|
|
@@ -694,6 +696,7 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
694
696
|
fileSelectors,
|
|
695
697
|
},
|
|
696
698
|
onUploadProgress,
|
|
699
|
+
...requestConfig,
|
|
697
700
|
});
|
|
698
701
|
if (postResponse.status) {
|
|
699
702
|
// scroll to top after success
|
|
@@ -712,8 +715,8 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
712
715
|
};
|
|
713
716
|
// register post mutation
|
|
714
717
|
const mutation = useMutation(async (postData) => new Promise((res, rej) => sendRequest(res, rej, postData)));
|
|
715
|
-
const post = async (data, options) => {
|
|
716
|
-
return mutation.mutateAsync(data, options);
|
|
718
|
+
const post = async (data, options, requestConfig) => {
|
|
719
|
+
return mutation.mutateAsync({ data, requestConfig }, options);
|
|
717
720
|
};
|
|
718
721
|
return { post, uploadProgressPercent, ...mutation };
|
|
719
722
|
};
|
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,5 +1,5 @@
|
|
|
1
1
|
import type { MutateOptions } from '@tanstack/react-query';
|
|
2
|
-
import type { IRequestError, IRequestSuccess } from '../request';
|
|
2
|
+
import type { IMakeRequest, IRequestError, IRequestSuccess } from '../request';
|
|
3
3
|
import type { DefaultRequestOptions } from './queries.interface';
|
|
4
4
|
export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, headers, fileSelectors, }: {
|
|
5
5
|
path: string;
|
|
@@ -13,15 +13,27 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
|
|
|
13
13
|
isLoading: false;
|
|
14
14
|
isSuccess: false;
|
|
15
15
|
status: "idle";
|
|
16
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError,
|
|
16
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
17
|
+
data: any;
|
|
18
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
19
|
+
}, unknown>;
|
|
17
20
|
reset: () => void;
|
|
18
21
|
context: unknown;
|
|
19
22
|
failureCount: number;
|
|
20
23
|
failureReason: IRequestError | null;
|
|
21
24
|
isPaused: boolean;
|
|
22
|
-
variables:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
variables: {
|
|
26
|
+
data: any;
|
|
27
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
28
|
+
} | undefined;
|
|
29
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
30
|
+
data: any;
|
|
31
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
32
|
+
}, unknown>;
|
|
33
|
+
post: <T>(data?: T | undefined, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, {
|
|
34
|
+
data: T;
|
|
35
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
36
|
+
}, unknown> | undefined, requestConfig?: Omit<IMakeRequest, 'body'>) => Promise<IRequestSuccess<TResponse>>;
|
|
25
37
|
uploadProgressPercent: number;
|
|
26
38
|
} | {
|
|
27
39
|
data: undefined;
|
|
@@ -31,15 +43,27 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
|
|
|
31
43
|
isLoading: true;
|
|
32
44
|
isSuccess: false;
|
|
33
45
|
status: "loading";
|
|
34
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError,
|
|
46
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
47
|
+
data: any;
|
|
48
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
49
|
+
}, unknown>;
|
|
35
50
|
reset: () => void;
|
|
36
51
|
context: unknown;
|
|
37
52
|
failureCount: number;
|
|
38
53
|
failureReason: IRequestError | null;
|
|
39
54
|
isPaused: boolean;
|
|
40
|
-
variables:
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
variables: {
|
|
56
|
+
data: any;
|
|
57
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
60
|
+
data: any;
|
|
61
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
62
|
+
}, unknown>;
|
|
63
|
+
post: <T>(data?: T | undefined, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, {
|
|
64
|
+
data: T;
|
|
65
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
66
|
+
}, unknown> | undefined, requestConfig?: Omit<IMakeRequest, 'body'>) => Promise<IRequestSuccess<TResponse>>;
|
|
43
67
|
uploadProgressPercent: number;
|
|
44
68
|
} | {
|
|
45
69
|
data: undefined;
|
|
@@ -49,15 +73,27 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
|
|
|
49
73
|
isLoading: false;
|
|
50
74
|
isSuccess: false;
|
|
51
75
|
status: "error";
|
|
52
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError,
|
|
76
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
77
|
+
data: any;
|
|
78
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
79
|
+
}, unknown>;
|
|
53
80
|
reset: () => void;
|
|
54
81
|
context: unknown;
|
|
55
82
|
failureCount: number;
|
|
56
83
|
failureReason: IRequestError | null;
|
|
57
84
|
isPaused: boolean;
|
|
58
|
-
variables:
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
variables: {
|
|
86
|
+
data: any;
|
|
87
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
90
|
+
data: any;
|
|
91
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
92
|
+
}, unknown>;
|
|
93
|
+
post: <T>(data?: T | undefined, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, {
|
|
94
|
+
data: T;
|
|
95
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
96
|
+
}, unknown> | undefined, requestConfig?: Omit<IMakeRequest, 'body'>) => Promise<IRequestSuccess<TResponse>>;
|
|
61
97
|
uploadProgressPercent: number;
|
|
62
98
|
} | {
|
|
63
99
|
data: IRequestSuccess<TResponse>;
|
|
@@ -67,14 +103,26 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
|
|
|
67
103
|
isLoading: false;
|
|
68
104
|
isSuccess: true;
|
|
69
105
|
status: "success";
|
|
70
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError,
|
|
106
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
107
|
+
data: any;
|
|
108
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
109
|
+
}, unknown>;
|
|
71
110
|
reset: () => void;
|
|
72
111
|
context: unknown;
|
|
73
112
|
failureCount: number;
|
|
74
113
|
failureReason: IRequestError | null;
|
|
75
114
|
isPaused: boolean;
|
|
76
|
-
variables:
|
|
77
|
-
|
|
78
|
-
|
|
115
|
+
variables: {
|
|
116
|
+
data: any;
|
|
117
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
118
|
+
} | undefined;
|
|
119
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<IRequestSuccess<TResponse>, IRequestError, {
|
|
120
|
+
data: any;
|
|
121
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
122
|
+
}, unknown>;
|
|
123
|
+
post: <T>(data?: T | undefined, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, {
|
|
124
|
+
data: T;
|
|
125
|
+
requestConfig?: Omit<IMakeRequest, "body"> | undefined;
|
|
126
|
+
}, unknown> | undefined, requestConfig?: Omit<IMakeRequest, 'body'>) => Promise<IRequestSuccess<TResponse>>;
|
|
79
127
|
uploadProgressPercent: number;
|
|
80
128
|
};
|
|
@@ -19,9 +19,11 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
19
19
|
// get request headers
|
|
20
20
|
const globalHeaders = getHeaders();
|
|
21
21
|
const config = queryClient.getQueryData(['config']);
|
|
22
|
+
const { data, requestConfig } = postData;
|
|
23
|
+
delete requestConfig?.body;
|
|
22
24
|
const postResponse = await makeRequest({
|
|
23
25
|
path,
|
|
24
|
-
body:
|
|
26
|
+
body: data,
|
|
25
27
|
method: HttpMethod.POST,
|
|
26
28
|
isFormData,
|
|
27
29
|
headers: { ...globalHeaders, ...headers },
|
|
@@ -32,6 +34,7 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
32
34
|
fileSelectors,
|
|
33
35
|
},
|
|
34
36
|
onUploadProgress,
|
|
37
|
+
...requestConfig,
|
|
35
38
|
});
|
|
36
39
|
if (postResponse.status) {
|
|
37
40
|
// scroll to top after success
|
|
@@ -50,8 +53,8 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
|
|
|
50
53
|
};
|
|
51
54
|
// register post mutation
|
|
52
55
|
const mutation = useMutation(async (postData) => new Promise((res, rej) => sendRequest(res, rej, postData)));
|
|
53
|
-
const post = async (data, options) => {
|
|
54
|
-
return mutation.mutateAsync(data, options);
|
|
56
|
+
const post = async (data, options, requestConfig) => {
|
|
57
|
+
return mutation.mutateAsync({ data, requestConfig }, options);
|
|
55
58
|
};
|
|
56
59
|
return { post, uploadProgressPercent, ...mutation };
|
|
57
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePostRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePostRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { useEnvironmentVariables, useQueryHeaders, useReactNativeEnv } from '../
|
|
|
5
5
|
import type { RawAxiosRequestHeaders } from 'axios';
|
|
6
6
|
import { scrollToTop } from '../helpers';
|
|
7
7
|
import { useUploadProgress } from '../hooks';
|
|
8
|
-
import type { IRequestError, IRequestSuccess } from '../request';
|
|
8
|
+
import type { IMakeRequest, IRequestError, IRequestSuccess } from '../request';
|
|
9
9
|
import { HttpMethod, makeRequest } from '../request';
|
|
10
10
|
import type { TanstackQueryConfig } from '../types';
|
|
11
11
|
import type { DefaultRequestOptions } from './queries.interface';
|
|
@@ -27,14 +27,21 @@ export const usePostRequest = <TResponse>({
|
|
|
27
27
|
const { isApp } = useReactNativeEnv();
|
|
28
28
|
const { uploadProgressPercent, onUploadProgress } = useUploadProgress();
|
|
29
29
|
|
|
30
|
-
const sendRequest = async (
|
|
30
|
+
const sendRequest = async (
|
|
31
|
+
res: (value: any) => void,
|
|
32
|
+
rej: (reason?: any) => void,
|
|
33
|
+
postData: { data: any; requestConfig?: IMakeRequest }
|
|
34
|
+
) => {
|
|
31
35
|
// get request headers
|
|
32
36
|
const globalHeaders: RawAxiosRequestHeaders = getHeaders();
|
|
33
37
|
const config = queryClient.getQueryData<TanstackQueryConfig>(['config']);
|
|
38
|
+
const { data, requestConfig } = postData;
|
|
39
|
+
|
|
40
|
+
delete requestConfig?.body;
|
|
34
41
|
|
|
35
42
|
const postResponse = await makeRequest<TResponse>({
|
|
36
43
|
path,
|
|
37
|
-
body:
|
|
44
|
+
body: data,
|
|
38
45
|
method: HttpMethod.POST,
|
|
39
46
|
isFormData,
|
|
40
47
|
headers: { ...globalHeaders, ...headers },
|
|
@@ -45,6 +52,7 @@ export const usePostRequest = <TResponse>({
|
|
|
45
52
|
fileSelectors,
|
|
46
53
|
},
|
|
47
54
|
onUploadProgress,
|
|
55
|
+
...requestConfig,
|
|
48
56
|
});
|
|
49
57
|
|
|
50
58
|
if (postResponse.status) {
|
|
@@ -64,14 +72,25 @@ export const usePostRequest = <TResponse>({
|
|
|
64
72
|
};
|
|
65
73
|
|
|
66
74
|
// register post mutation
|
|
67
|
-
const mutation = useMutation<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
const mutation = useMutation<
|
|
76
|
+
IRequestSuccess<TResponse>,
|
|
77
|
+
IRequestError,
|
|
78
|
+
{ data: any; requestConfig?: Omit<IMakeRequest, 'body'> }
|
|
79
|
+
>(async (postData) => new Promise<IRequestSuccess<TResponse>>((res, rej) => sendRequest(res, rej, postData)));
|
|
80
|
+
|
|
81
|
+
const post = async <T>(
|
|
82
|
+
data?: T,
|
|
83
|
+
options?:
|
|
84
|
+
| MutateOptions<
|
|
85
|
+
IRequestSuccess<TResponse>,
|
|
86
|
+
IRequestError,
|
|
87
|
+
{ data: T; requestConfig?: Omit<IMakeRequest, 'body'> },
|
|
88
|
+
unknown
|
|
89
|
+
>
|
|
90
|
+
| undefined,
|
|
91
|
+
requestConfig?: Omit<IMakeRequest, 'body'>
|
|
73
92
|
): Promise<IRequestSuccess<TResponse>> => {
|
|
74
|
-
return mutation.mutateAsync(data, options);
|
|
93
|
+
return mutation.mutateAsync({ data, requestConfig }, options);
|
|
75
94
|
};
|
|
76
95
|
|
|
77
96
|
return { post, uploadProgressPercent, ...mutation };
|