@ventlio/tanstack-query 0.5.4 → 0.5.5
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/config/bootstrapQueryRequest.d.ts +4 -4
- package/dist/config/bootstrapQueryRequest.js +15 -15
- package/dist/config/config.interface.d.ts +4 -4
- package/dist/config/index.d.ts +6 -6
- package/dist/config/useEnvironmentVariables.d.ts +2 -2
- package/dist/config/useEnvironmentVariables.js +8 -8
- package/dist/config/useQueryConfig.d.ts +2 -2
- package/dist/config/useQueryConfig.js +5 -5
- package/dist/config/useQueryHeaders.d.ts +2 -2
- package/dist/config/useQueryHeaders.js +9 -9
- package/dist/config/useReactNativeEnv.d.ts +5 -5
- package/dist/config/useReactNativeEnv.js +6 -6
- package/dist/helpers/index.d.ts +2 -2
- package/dist/helpers/scrollToTop.d.ts +1 -1
- package/dist/helpers/scrollToTop.js +5 -5
- package/dist/helpers/timeFuncs.d.ts +1 -1
- package/dist/helpers/timeFuncs.js +7 -7
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/useUploadProgress.d.ts +5 -5
- package/dist/hooks/useUploadProgress.js +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +907 -830
- package/dist/index.mjs.map +1 -1
- package/dist/model/index.d.ts +4 -4
- package/dist/model/model.interface.d.ts +11 -11
- package/dist/model/useKeyTrackerModel.d.ts +4 -4
- package/dist/model/useKeyTrackerModel.js +14 -14
- package/dist/model/useQueryModel.d.ts +2 -2
- package/dist/model/useQueryModel.js +115 -115
- package/dist/model/useRefetchQuery.d.ts +3 -3
- package/dist/model/useRefetchQuery.js +10 -10
- package/dist/queries/index.d.ts +6 -6
- package/dist/queries/queries.interface.d.ts +17 -17
- package/dist/queries/useDeleteRequest.d.ts +60 -60
- package/dist/queries/useDeleteRequest.js +86 -71
- package/dist/queries/useDeleteRequest.js.map +1 -1
- package/dist/queries/useGetInfiniteRequest.d.ts +108 -110
- package/dist/queries/useGetInfiniteRequest.js +117 -102
- package/dist/queries/useGetInfiniteRequest.js.map +1 -1
- package/dist/queries/useGetRequest.d.ts +73 -74
- package/dist/queries/useGetRequest.js +148 -133
- package/dist/queries/useGetRequest.js.map +1 -1
- package/dist/queries/usePatchRequest.d.ts +86 -86
- package/dist/queries/usePatchRequest.js +86 -70
- package/dist/queries/usePatchRequest.js.map +1 -1
- package/dist/queries/usePostRequest.d.ts +149 -157
- package/dist/queries/usePostRequest.js +94 -78
- package/dist/queries/usePostRequest.js.map +1 -1
- package/dist/queries/usePutRequest.d.ts +86 -86
- package/dist/request/axios-instance.d.ts +3 -3
- package/dist/request/axios-instance.js +6 -6
- package/dist/request/buildFormData.d.ts +1 -1
- package/dist/request/buildFormData.js +40 -40
- package/dist/request/index.d.ts +6 -6
- package/dist/request/make-request.d.ts +2 -2
- package/dist/request/make-request.js +80 -80
- package/dist/request/request.enum.d.ts +11 -11
- package/dist/request/request.enum.js +12 -12
- package/dist/request/request.interface.d.ts +48 -48
- package/dist/request/transformer.d.ts +7 -7
- package/dist/request/transformer.js +18 -18
- package/dist/stores/index.d.ts +2 -2
- package/dist/stores/useHeaderStore.d.ts +7 -7
- package/dist/stores/useHeaderStore.js +5 -5
- package/dist/stores/usePauseFutureRequests.d.ts +7 -7
- package/dist/stores/usePauseFutureRequests.js +13 -13
- package/dist/types/index.d.ts +34 -29
- package/package.json +2 -2
- package/src/queries/useDeleteRequest.ts +24 -5
- package/src/queries/useGetInfiniteRequest.ts +21 -2
- package/src/queries/useGetRequest.ts +26 -9
- package/src/queries/usePatchRequest.ts +21 -1
- package/src/queries/usePostRequest.ts +21 -1
- package/src/queries/usePutRequest.ts +21 -1
- package/src/request/make-request.ts +2 -2
- package/src/request/transformer.ts +1 -1
- package/src/types/index.ts +5 -1
|
@@ -3,86 +3,86 @@ import { axiosInstance } from './axios-instance.js';
|
|
|
3
3
|
import { HttpMethod, ContentType } from './request.enum.js';
|
|
4
4
|
import { errorTransformer, successTransformer } from './transformer.js';
|
|
5
5
|
|
|
6
|
-
async function makeRequest({ body = {}, method = HttpMethod.GET, path, isFormData, headers = {}, baseURL, timeout, appFileConfig, onUploadProgress, }) {
|
|
7
|
-
// check if file is included in mobile app environment and extract all file input to avoid
|
|
8
|
-
// it being formatted to object using axios formData builder
|
|
9
|
-
const isApp = appFileConfig?.isApp;
|
|
10
|
-
const appFiles = isApp ? getAppFiles(body, appFileConfig.fileSelectors) : {};
|
|
11
|
-
// configure body
|
|
12
|
-
body = (isFormData ? axios.toFormData(body) : body);
|
|
13
|
-
// configure request header1
|
|
14
|
-
configureRequestHeader(isFormData, headers, isApp, appFiles, body);
|
|
15
|
-
try {
|
|
16
|
-
const axiosRequest = axiosInstance({ baseURL, headers, timeout });
|
|
17
|
-
const axiosRequestConfig = {
|
|
18
|
-
url: path,
|
|
19
|
-
method,
|
|
20
|
-
onUploadProgress,
|
|
21
|
-
};
|
|
22
|
-
if (Object.keys(body).length > 0 || (isFormData && !isApp && [...body.keys()].length > 0)) {
|
|
23
|
-
axiosRequestConfig.data = body;
|
|
24
|
-
}
|
|
25
|
-
// send request
|
|
26
|
-
const resp = await axiosRequest(axiosRequestConfig);
|
|
27
|
-
// get response json
|
|
28
|
-
const jsonResp = await resp.data;
|
|
29
|
-
// get response code
|
|
30
|
-
const responseCode = resp.status;
|
|
31
|
-
if (responseCode > 299) {
|
|
32
|
-
// server returned an error
|
|
33
|
-
return errorTransformer({ ...jsonResp, statusCode: responseCode });
|
|
34
|
-
}
|
|
35
|
-
return successTransformer({
|
|
36
|
-
statusCode: responseCode,
|
|
37
|
-
...jsonResp,
|
|
38
|
-
status: resp.status,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
const errorData = error?.response?.data;
|
|
43
|
-
return errorTransformer({
|
|
44
|
-
statusCode: error.status,
|
|
45
|
-
message: error.message,
|
|
46
|
-
code: error.status || error.statusCode,
|
|
47
|
-
...errorData,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const configureRequestHeader = (isFormData, headers, isApp, appFiles, body) => {
|
|
52
|
-
if (!isFormData) {
|
|
53
|
-
headers['Content-Type'] = ContentType.APPLICATION_JSON;
|
|
54
|
-
}
|
|
55
|
-
else if (isApp) {
|
|
56
|
-
headers['Content-Type'] = ContentType.MULTIPART_FORM_DATA;
|
|
57
|
-
// add the app files
|
|
58
|
-
for (const fileKey in appFiles) {
|
|
59
|
-
const currentFile = appFiles[fileKey];
|
|
60
|
-
if (Array.isArray(currentFile)) {
|
|
61
|
-
for (const innerFile of currentFile) {
|
|
62
|
-
body.append(fileKey, innerFile);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
body.append(fileKey, currentFile);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
delete headers['Content-Type'];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
function getAppFiles(body, fileSelectors = []) {
|
|
75
|
-
const files = {};
|
|
76
|
-
if (body) {
|
|
77
|
-
if (fileSelectors.length > 0) {
|
|
78
|
-
//
|
|
79
|
-
for (const fileKey of fileSelectors) {
|
|
80
|
-
files[fileKey] = body[fileKey];
|
|
81
|
-
delete body[fileKey];
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return files;
|
|
6
|
+
async function makeRequest({ body = {}, method = HttpMethod.GET, path, isFormData, headers = {}, baseURL, timeout, appFileConfig, onUploadProgress, }) {
|
|
7
|
+
// check if file is included in mobile app environment and extract all file input to avoid
|
|
8
|
+
// it being formatted to object using axios formData builder
|
|
9
|
+
const isApp = appFileConfig?.isApp;
|
|
10
|
+
const appFiles = isApp ? getAppFiles(body, appFileConfig.fileSelectors) : {};
|
|
11
|
+
// configure body
|
|
12
|
+
body = (isFormData ? axios.toFormData(body) : body);
|
|
13
|
+
// configure request header1
|
|
14
|
+
configureRequestHeader(isFormData, headers, isApp, appFiles, body);
|
|
15
|
+
try {
|
|
16
|
+
const axiosRequest = axiosInstance({ baseURL, headers, timeout });
|
|
17
|
+
const axiosRequestConfig = {
|
|
18
|
+
url: path,
|
|
19
|
+
method,
|
|
20
|
+
onUploadProgress,
|
|
21
|
+
};
|
|
22
|
+
if (Object.keys(body).length > 0 || (isFormData && !isApp && [...body.keys()].length > 0)) {
|
|
23
|
+
axiosRequestConfig.data = body;
|
|
24
|
+
}
|
|
25
|
+
// send request
|
|
26
|
+
const resp = await axiosRequest(axiosRequestConfig);
|
|
27
|
+
// get response json
|
|
28
|
+
const jsonResp = await resp.data;
|
|
29
|
+
// get response code
|
|
30
|
+
const responseCode = resp.status;
|
|
31
|
+
if (responseCode > 299) {
|
|
32
|
+
// server returned an error
|
|
33
|
+
return errorTransformer({ ...jsonResp, statusCode: responseCode });
|
|
34
|
+
}
|
|
35
|
+
return successTransformer({
|
|
36
|
+
statusCode: responseCode,
|
|
37
|
+
...jsonResp,
|
|
38
|
+
status: resp.status,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const errorData = error?.response?.data;
|
|
43
|
+
return errorTransformer({
|
|
44
|
+
statusCode: error.status,
|
|
45
|
+
message: error.message,
|
|
46
|
+
code: error.status || error.statusCode,
|
|
47
|
+
...errorData,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const configureRequestHeader = (isFormData, headers, isApp, appFiles, body) => {
|
|
52
|
+
if (!isFormData) {
|
|
53
|
+
headers['Content-Type'] = ContentType.APPLICATION_JSON;
|
|
54
|
+
}
|
|
55
|
+
else if (isApp) {
|
|
56
|
+
headers['Content-Type'] = ContentType.MULTIPART_FORM_DATA;
|
|
57
|
+
// add the app files
|
|
58
|
+
for (const fileKey in appFiles) {
|
|
59
|
+
const currentFile = appFiles[fileKey];
|
|
60
|
+
if (Array.isArray(currentFile)) {
|
|
61
|
+
for (const innerFile of currentFile) {
|
|
62
|
+
body.append(fileKey, innerFile);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
body.append(fileKey, currentFile);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
delete headers['Content-Type'];
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function getAppFiles(body, fileSelectors = []) {
|
|
75
|
+
const files = {};
|
|
76
|
+
if (body) {
|
|
77
|
+
if (fileSelectors.length > 0) {
|
|
78
|
+
//
|
|
79
|
+
for (const fileKey of fileSelectors) {
|
|
80
|
+
files[fileKey] = body[fileKey];
|
|
81
|
+
delete body[fileKey];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return files;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export { makeRequest };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export declare enum HttpMethod {
|
|
2
|
-
GET = "GET",
|
|
3
|
-
POST = "POST",
|
|
4
|
-
PUT = "PUT",
|
|
5
|
-
PATCH = "PATCH",
|
|
6
|
-
DELETE = "DELETE"
|
|
7
|
-
}
|
|
8
|
-
export declare enum ContentType {
|
|
9
|
-
APPLICATION_JSON = "application/json",
|
|
10
|
-
MULTIPART_FORM_DATA = "multipart/form-data"
|
|
11
|
-
}
|
|
1
|
+
export declare enum HttpMethod {
|
|
2
|
+
GET = "GET",
|
|
3
|
+
POST = "POST",
|
|
4
|
+
PUT = "PUT",
|
|
5
|
+
PATCH = "PATCH",
|
|
6
|
+
DELETE = "DELETE"
|
|
7
|
+
}
|
|
8
|
+
export declare enum ContentType {
|
|
9
|
+
APPLICATION_JSON = "application/json",
|
|
10
|
+
MULTIPART_FORM_DATA = "multipart/form-data"
|
|
11
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var HttpMethod;
|
|
2
|
-
(function (HttpMethod) {
|
|
3
|
-
HttpMethod["GET"] = "GET";
|
|
4
|
-
HttpMethod["POST"] = "POST";
|
|
5
|
-
HttpMethod["PUT"] = "PUT";
|
|
6
|
-
HttpMethod["PATCH"] = "PATCH";
|
|
7
|
-
HttpMethod["DELETE"] = "DELETE";
|
|
8
|
-
})(HttpMethod || (HttpMethod = {}));
|
|
9
|
-
var ContentType;
|
|
10
|
-
(function (ContentType) {
|
|
11
|
-
ContentType["APPLICATION_JSON"] = "application/json";
|
|
12
|
-
ContentType["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
1
|
+
var HttpMethod;
|
|
2
|
+
(function (HttpMethod) {
|
|
3
|
+
HttpMethod["GET"] = "GET";
|
|
4
|
+
HttpMethod["POST"] = "POST";
|
|
5
|
+
HttpMethod["PUT"] = "PUT";
|
|
6
|
+
HttpMethod["PATCH"] = "PATCH";
|
|
7
|
+
HttpMethod["DELETE"] = "DELETE";
|
|
8
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
9
|
+
var ContentType;
|
|
10
|
+
(function (ContentType) {
|
|
11
|
+
ContentType["APPLICATION_JSON"] = "application/json";
|
|
12
|
+
ContentType["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
13
13
|
})(ContentType || (ContentType = {}));
|
|
14
14
|
|
|
15
15
|
export { ContentType, HttpMethod };
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import type { AxiosProgressEvent, RawAxiosRequestHeaders } from 'axios';
|
|
2
|
-
import type { HttpMethod } from './request.enum';
|
|
3
|
-
export interface IMakeRequest {
|
|
4
|
-
baseURL: string;
|
|
5
|
-
timeout?: number;
|
|
6
|
-
path: string;
|
|
7
|
-
body?: Record<string, any> | null;
|
|
8
|
-
method?: HttpMethod;
|
|
9
|
-
isFormData?: boolean;
|
|
10
|
-
headers: RawAxiosRequestHeaders;
|
|
11
|
-
appFileConfig?: AppFileConfig;
|
|
12
|
-
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
|
13
|
-
}
|
|
14
|
-
export interface AppFileConfig {
|
|
15
|
-
fileSelectors?: string[];
|
|
16
|
-
isApp: boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface AxiosInstanceOption {
|
|
19
|
-
bearerToken?: string;
|
|
20
|
-
contentType?: string;
|
|
21
|
-
}
|
|
22
|
-
export interface IRequestError {
|
|
23
|
-
statusCode: number;
|
|
24
|
-
message: string;
|
|
25
|
-
timeStamp: Date;
|
|
26
|
-
status: boolean;
|
|
27
|
-
data?: any;
|
|
28
|
-
}
|
|
29
|
-
export interface IRequestSuccess<T> {
|
|
30
|
-
statusCode: number;
|
|
31
|
-
message: string;
|
|
32
|
-
timeStamp: Date;
|
|
33
|
-
status: boolean;
|
|
34
|
-
data: T;
|
|
35
|
-
}
|
|
36
|
-
export interface IServerRequestSuccess {
|
|
37
|
-
status?: boolean;
|
|
38
|
-
data: any;
|
|
39
|
-
message?: string;
|
|
40
|
-
}
|
|
41
|
-
export interface IServerRequestError {
|
|
42
|
-
status?: boolean;
|
|
43
|
-
code?: number;
|
|
44
|
-
success?: boolean;
|
|
45
|
-
message: string;
|
|
46
|
-
error?: Record<string, any>;
|
|
47
|
-
data?: Record<string, any>;
|
|
48
|
-
}
|
|
1
|
+
import type { AxiosProgressEvent, RawAxiosRequestHeaders } from 'axios';
|
|
2
|
+
import type { HttpMethod } from './request.enum';
|
|
3
|
+
export interface IMakeRequest {
|
|
4
|
+
baseURL: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
path: string;
|
|
7
|
+
body?: Record<string, any> | null;
|
|
8
|
+
method?: HttpMethod;
|
|
9
|
+
isFormData?: boolean;
|
|
10
|
+
headers: RawAxiosRequestHeaders;
|
|
11
|
+
appFileConfig?: AppFileConfig;
|
|
12
|
+
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
|
13
|
+
}
|
|
14
|
+
export interface AppFileConfig {
|
|
15
|
+
fileSelectors?: string[];
|
|
16
|
+
isApp: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface AxiosInstanceOption {
|
|
19
|
+
bearerToken?: string;
|
|
20
|
+
contentType?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IRequestError {
|
|
23
|
+
statusCode: number;
|
|
24
|
+
message: string;
|
|
25
|
+
timeStamp: Date;
|
|
26
|
+
status: boolean;
|
|
27
|
+
data?: any;
|
|
28
|
+
}
|
|
29
|
+
export interface IRequestSuccess<T> {
|
|
30
|
+
statusCode: number;
|
|
31
|
+
message: string;
|
|
32
|
+
timeStamp: Date;
|
|
33
|
+
status: boolean;
|
|
34
|
+
data: T;
|
|
35
|
+
}
|
|
36
|
+
export interface IServerRequestSuccess {
|
|
37
|
+
status?: boolean;
|
|
38
|
+
data: any;
|
|
39
|
+
message?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface IServerRequestError {
|
|
42
|
+
status?: boolean;
|
|
43
|
+
code?: number;
|
|
44
|
+
success?: boolean;
|
|
45
|
+
message: string;
|
|
46
|
+
error?: Record<string, any>;
|
|
47
|
+
data?: Record<string, any>;
|
|
48
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IRequestError, IRequestSuccess, IServerRequestError, IServerRequestSuccess } from './request.interface';
|
|
2
|
-
export declare const errorTransformer: (data: IServerRequestError & {
|
|
3
|
-
statusCode: number;
|
|
4
|
-
}) => IRequestError;
|
|
5
|
-
export declare const successTransformer: <T>(data: IServerRequestSuccess & {
|
|
6
|
-
statusCode: number;
|
|
7
|
-
}) => IRequestSuccess<T>;
|
|
1
|
+
import type { IRequestError, IRequestSuccess, IServerRequestError, IServerRequestSuccess } from './request.interface';
|
|
2
|
+
export declare const errorTransformer: (data: IServerRequestError & {
|
|
3
|
+
statusCode: number;
|
|
4
|
+
}) => IRequestError;
|
|
5
|
+
export declare const successTransformer: <T>(data: IServerRequestSuccess & {
|
|
6
|
+
statusCode: number;
|
|
7
|
+
}) => IRequestSuccess<T>;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
//
|
|
2
|
-
const errorTransformer = (data) => {
|
|
3
|
-
return {
|
|
4
|
-
timeStamp: new Date(),
|
|
5
|
-
|
|
6
|
-
data
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
//
|
|
11
|
-
const successTransformer = (data) => {
|
|
12
|
-
return {
|
|
13
|
-
message: data.message ?? 'Request successful',
|
|
14
|
-
statusCode: data.statusCode,
|
|
15
|
-
timeStamp: new Date(),
|
|
16
|
-
status: true,
|
|
17
|
-
data: data.data,
|
|
18
|
-
};
|
|
1
|
+
//
|
|
2
|
+
const errorTransformer = (data) => {
|
|
3
|
+
return {
|
|
4
|
+
timeStamp: new Date(),
|
|
5
|
+
data: data.data,
|
|
6
|
+
...data,
|
|
7
|
+
status: false,
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
//
|
|
11
|
+
const successTransformer = (data) => {
|
|
12
|
+
return {
|
|
13
|
+
message: data.message ?? 'Request successful',
|
|
14
|
+
statusCode: data.statusCode,
|
|
15
|
+
timeStamp: new Date(),
|
|
16
|
+
status: true,
|
|
17
|
+
data: data.data,
|
|
18
|
+
};
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export { errorTransformer, successTransformer };
|
package/dist/stores/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './useHeaderStore';
|
|
2
|
-
export * from './usePauseFutureRequests';
|
|
1
|
+
export * from './useHeaderStore';
|
|
2
|
+
export * from './usePauseFutureRequests';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { QueryHeaders } from '../types';
|
|
2
|
-
interface IUserHeaders {
|
|
3
|
-
headers: QueryHeaders | undefined;
|
|
4
|
-
setHeader: (headers: QueryHeaders) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare const useHeaderStore: import("zustand").UseBoundStore<import("zustand").StoreApi<IUserHeaders>>;
|
|
7
|
-
export {};
|
|
1
|
+
import type { QueryHeaders } from '../types';
|
|
2
|
+
interface IUserHeaders {
|
|
3
|
+
headers: QueryHeaders | undefined;
|
|
4
|
+
setHeader: (headers: QueryHeaders) => void;
|
|
5
|
+
}
|
|
6
|
+
export declare const useHeaderStore: import("zustand").UseBoundStore<import("zustand").StoreApi<IUserHeaders>>;
|
|
7
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
|
|
3
|
-
const useHeaderStore = create((set) => ({
|
|
4
|
-
headers: undefined,
|
|
5
|
-
setHeader(headers) {
|
|
6
|
-
set({ headers });
|
|
7
|
-
},
|
|
3
|
+
const useHeaderStore = create((set) => ({
|
|
4
|
+
headers: undefined,
|
|
5
|
+
setHeader(headers) {
|
|
6
|
+
set({ headers });
|
|
7
|
+
},
|
|
8
8
|
}));
|
|
9
9
|
|
|
10
10
|
export { useHeaderStore };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export interface PauseFutureRequest {
|
|
2
|
-
isFutureQueriesPaused: boolean;
|
|
3
|
-
isFutureMutationsPaused: boolean;
|
|
4
|
-
pauseFutureMutation: (status: boolean) => void;
|
|
5
|
-
pauseFutureQueries: (status: boolean) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const usePauseFutureRequests: import("zustand").UseBoundStore<import("zustand").StoreApi<PauseFutureRequest>>;
|
|
1
|
+
export interface PauseFutureRequest {
|
|
2
|
+
isFutureQueriesPaused: boolean;
|
|
3
|
+
isFutureMutationsPaused: boolean;
|
|
4
|
+
pauseFutureMutation: (status: boolean) => void;
|
|
5
|
+
pauseFutureQueries: (status: boolean) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const usePauseFutureRequests: import("zustand").UseBoundStore<import("zustand").StoreApi<PauseFutureRequest>>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { create } from 'zustand';
|
|
2
2
|
|
|
3
|
-
const usePauseFutureRequests = create((set) => {
|
|
4
|
-
const pauseFutureQueries = (status) => {
|
|
5
|
-
return set({ isFutureQueriesPaused: status });
|
|
6
|
-
};
|
|
7
|
-
const pauseFutureMutation = (status) => {
|
|
8
|
-
return set({ isFutureQueriesPaused: status });
|
|
9
|
-
};
|
|
10
|
-
return {
|
|
11
|
-
isFutureMutationsPaused: false,
|
|
12
|
-
isFutureQueriesPaused: false,
|
|
13
|
-
pauseFutureQueries,
|
|
14
|
-
pauseFutureMutation,
|
|
15
|
-
};
|
|
3
|
+
const usePauseFutureRequests = create((set) => {
|
|
4
|
+
const pauseFutureQueries = (status) => {
|
|
5
|
+
return set({ isFutureQueriesPaused: status });
|
|
6
|
+
};
|
|
7
|
+
const pauseFutureMutation = (status) => {
|
|
8
|
+
return set({ isFutureQueriesPaused: status });
|
|
9
|
+
};
|
|
10
|
+
return {
|
|
11
|
+
isFutureMutationsPaused: false,
|
|
12
|
+
isFutureQueriesPaused: false,
|
|
13
|
+
pauseFutureQueries,
|
|
14
|
+
pauseFutureMutation,
|
|
15
|
+
};
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
export { usePauseFutureRequests };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
|
-
import type { QueryKey } from '@tanstack/react-query';
|
|
2
|
-
import type { RawAxiosRequestHeaders } from 'axios';
|
|
3
|
-
import type { IMakeRequest } from '../request';
|
|
4
|
-
export interface BootstrapConfig {
|
|
5
|
-
environments?: {
|
|
6
|
-
appBaseUrl: string;
|
|
7
|
-
appTimeout: number;
|
|
8
|
-
};
|
|
9
|
-
context?: ContextType;
|
|
10
|
-
modelConfig?: BootstrapModelConfig;
|
|
11
|
-
mutationMiddleware?: (mutateRequestConfig?: IMakeRequest & {
|
|
12
|
-
mutationKey: QueryKey;
|
|
13
|
-
}) => Promise<boolean>;
|
|
14
|
-
queryMiddleware?: (queryRequestConfig?: IMakeRequest & {
|
|
15
|
-
queryKey: QueryKey;
|
|
16
|
-
}) => Promise<boolean>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import type { QueryKey } from '@tanstack/react-query';
|
|
2
|
+
import type { RawAxiosRequestHeaders } from 'axios';
|
|
3
|
+
import type { IMakeRequest, IRequestError, IRequestSuccess } from '../request';
|
|
4
|
+
export interface BootstrapConfig {
|
|
5
|
+
environments?: {
|
|
6
|
+
appBaseUrl: string;
|
|
7
|
+
appTimeout: number;
|
|
8
|
+
};
|
|
9
|
+
context?: ContextType;
|
|
10
|
+
modelConfig?: BootstrapModelConfig;
|
|
11
|
+
mutationMiddleware?: (mutateRequestConfig?: IMakeRequest & {
|
|
12
|
+
mutationKey: QueryKey;
|
|
13
|
+
}) => Promise<boolean>;
|
|
14
|
+
queryMiddleware?: (queryRequestConfig?: IMakeRequest & {
|
|
15
|
+
queryKey: QueryKey;
|
|
16
|
+
}) => Promise<boolean>;
|
|
17
|
+
middleware?: <T = any>(next: () => Promise<IRequestSuccess<T> | IRequestError>, configs?: {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
path: string;
|
|
20
|
+
body?: Record<string, any>;
|
|
21
|
+
}) => Promise<false | IRequestSuccess<T>>;
|
|
22
|
+
}
|
|
23
|
+
export interface BootstrapModelConfig {
|
|
24
|
+
idColumn: string;
|
|
25
|
+
}
|
|
26
|
+
export type ContextType = 'app' | 'web' | 'electronjs';
|
|
27
|
+
export interface TanstackQueryConfig {
|
|
28
|
+
options?: BootstrapConfig;
|
|
29
|
+
}
|
|
30
|
+
export interface IUseQueryHeaders {
|
|
31
|
+
getHeaders: () => QueryHeaders;
|
|
32
|
+
setQueryHeaders: (header: QueryHeaders) => void;
|
|
33
|
+
}
|
|
34
|
+
export type QueryHeaders = RawAxiosRequestHeaders | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ventlio/tanstack-query",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"ts-jest": "^29.1.0",
|
|
81
81
|
"ts-node": "^10.9.1",
|
|
82
82
|
"tslib": "^2.5.0",
|
|
83
|
-
"typescript": "^
|
|
83
|
+
"typescript": "^5.5.4"
|
|
84
84
|
},
|
|
85
85
|
"files": [
|
|
86
86
|
"dist/**/*",
|
|
@@ -40,12 +40,31 @@ export const useDeleteRequest = <TResponse>(deleteOptions?: DefaultRequestOption
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
if (shouldContinue) {
|
|
43
|
-
|
|
43
|
+
let deleteResponse: IRequestError | IRequestSuccess<TResponse>;
|
|
44
|
+
if (queryConfigOptions?.middleware) {
|
|
45
|
+
// perform global middleware
|
|
46
|
+
const middlewareResponse = await queryConfigOptions.middleware(
|
|
47
|
+
async () => await makeRequest<TResponse>(requestOptions),
|
|
48
|
+
{
|
|
49
|
+
path: requestUrl,
|
|
50
|
+
baseUrl: baseUrl ?? API_URL,
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (!middlewareResponse) {
|
|
55
|
+
rej();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
deleteResponse = middlewareResponse;
|
|
60
|
+
} else {
|
|
61
|
+
deleteResponse = await makeRequest<TResponse>(requestOptions);
|
|
62
|
+
}
|
|
44
63
|
|
|
45
|
-
if (
|
|
46
|
-
res(
|
|
64
|
+
if (deleteResponse.status) {
|
|
65
|
+
res(deleteResponse as IRequestSuccess<TResponse>);
|
|
47
66
|
} else {
|
|
48
|
-
rej(
|
|
67
|
+
rej(deleteResponse);
|
|
49
68
|
}
|
|
50
69
|
} else {
|
|
51
70
|
rej(null);
|
|
@@ -101,5 +120,5 @@ export const useDeleteRequest = <TResponse>(deleteOptions?: DefaultRequestOption
|
|
|
101
120
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
121
|
}, [isFutureQueriesPaused]);
|
|
103
122
|
|
|
104
|
-
return { destroy, ...query, isLoading: query.isLoading || isFutureQueriesPaused };
|
|
123
|
+
return { destroy, ...query, isLoading: (query.isLoading as boolean) || isFutureQueriesPaused };
|
|
105
124
|
};
|
|
@@ -73,7 +73,26 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
if (shouldContinue) {
|
|
76
|
-
|
|
76
|
+
let getResponse: IRequestError | IRequestSuccess<TResponse>;
|
|
77
|
+
if (queryConfigOptions?.middleware) {
|
|
78
|
+
// perform global middleware
|
|
79
|
+
const middlewareResponse = await queryConfigOptions.middleware(
|
|
80
|
+
async () => await makeRequest<TResponse>(requestOptions),
|
|
81
|
+
{
|
|
82
|
+
path,
|
|
83
|
+
baseUrl: baseUrl ?? API_URL,
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (!middlewareResponse) {
|
|
88
|
+
rej();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getResponse = middlewareResponse;
|
|
93
|
+
} else {
|
|
94
|
+
getResponse = await makeRequest<TResponse>(requestOptions);
|
|
95
|
+
}
|
|
77
96
|
|
|
78
97
|
if (getResponse.status) {
|
|
79
98
|
res(getResponse as IRequestSuccess<TResponse & { pagination: Pagination }>);
|
|
@@ -185,6 +204,6 @@ export const useGetInfiniteRequest = <TResponse extends Record<string, any>>({
|
|
|
185
204
|
return {
|
|
186
205
|
get,
|
|
187
206
|
...query,
|
|
188
|
-
isLoading: query.isLoading || isFutureQueriesPaused,
|
|
207
|
+
isLoading: (query.isLoading as boolean) || isFutureQueriesPaused,
|
|
189
208
|
};
|
|
190
209
|
};
|