@ventlio/tanstack-query 0.2.34 → 0.2.36
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/README.md +16 -12
- package/dist/config/bootstrapQueryRequest.d.ts +2 -0
- package/dist/config/bootstrapQueryRequest.js +18 -0
- package/dist/config/bootstrapQueryRequest.js.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/config/bootstrapQueryRequest.ts +17 -0
- package/src/config/index.ts +1 -0
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ But we were not discouraged. So, we set out to find a solution which led to the
|
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
+
> Please note that this package is still being developed and may not function as expected. We are working to refine its implementation structure to meet a functional standard. The documentation may not align with the current implementation, so if you encounter any difficulties while setting up the package, please raise an issue in the GitHub repository. We appreciate your patience and understanding as we work to improve this package.
|
|
14
|
+
|
|
13
15
|
## Install
|
|
14
16
|
|
|
15
17
|
> You must install @tanstack/react-query and axios first to use this package
|
|
@@ -28,10 +30,22 @@ $ npm install @ventlio/tanstack-query
|
|
|
28
30
|
$ yarn add @ventlio/tanstack-query
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
|
|
31
34
|
## Getting Started
|
|
32
35
|
|
|
33
36
|
Follow the below instructions to have the package running on your project
|
|
34
37
|
|
|
38
|
+
### Set the environment variables
|
|
39
|
+
```env
|
|
40
|
+
# For ReactJS
|
|
41
|
+
REACT_APP_API_URL='https://build.ventlio.com'
|
|
42
|
+
REACT_APP_API_TIMEOUT=300000
|
|
43
|
+
|
|
44
|
+
# For NextJS
|
|
45
|
+
NEXT_PUBLIC_API_URL='https://build.ventlio.com'
|
|
46
|
+
NEXT_PUBLIC_API_TIMEOUT=300000
|
|
47
|
+
|
|
48
|
+
```
|
|
35
49
|
```js
|
|
36
50
|
import { QueryClient } from '@tanstack/react-query';
|
|
37
51
|
import { TanstackQueryConfig } from '@ventlio/tanstack-query';
|
|
@@ -40,16 +54,8 @@ import { TanstackQueryConfig } from '@ventlio/tanstack-query';
|
|
|
40
54
|
const queryClient = new QueryClient();
|
|
41
55
|
|
|
42
56
|
// do this before adding the queryClient to QueryClientProvider
|
|
43
|
-
queryClient
|
|
44
|
-
|
|
45
|
-
(['config'],
|
|
46
|
-
{
|
|
47
|
-
baseURL: 'https://pokeapi.co/api/v2',
|
|
48
|
-
timeout: 10000,
|
|
49
|
-
headers: {
|
|
50
|
-
Authorization: `Bearer Hello`,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
57
|
+
bootstrapQueryRequest(queryClient);
|
|
58
|
+
|
|
53
59
|
```
|
|
54
60
|
|
|
55
61
|
You can now use it in a QueryClientProvider
|
|
@@ -78,9 +84,7 @@ import {
|
|
|
78
84
|
} from '@ventlio/tanstack-query';
|
|
79
85
|
|
|
80
86
|
function LoginPage() {
|
|
81
|
-
const { baseURL, setQueryBaseUrl } = useQueryBaseURL();
|
|
82
87
|
const { headers, setQueryHeaders } = useQueryHeaders();
|
|
83
|
-
const { timeout, setQueryTimeout } = useQueryTimeout();
|
|
84
88
|
|
|
85
89
|
useEffect(() => {
|
|
86
90
|
// after user has logged in successfully set the authorization header token
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const bootstrapQueryRequest = (queryClient) => {
|
|
4
|
+
// make query config doesn't expire
|
|
5
|
+
queryClient.setQueryDefaults(['config'], {
|
|
6
|
+
staleTime: Infinity,
|
|
7
|
+
cacheTime: Infinity,
|
|
8
|
+
});
|
|
9
|
+
// set default query confg
|
|
10
|
+
queryClient.setQueryData(['config'], {
|
|
11
|
+
headers: {
|
|
12
|
+
Authorization: ``,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.bootstrapQueryRequest = bootstrapQueryRequest;
|
|
18
|
+
//# sourceMappingURL=bootstrapQueryRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrapQueryRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;"}
|
package/dist/config/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var bootstrapQueryRequest = require('./config/bootstrapQueryRequest.js');
|
|
3
4
|
var useEnvironmentVariables = require('./config/useEnvironmentVariables.js');
|
|
4
5
|
var useQueryConfig = require('./config/useQueryConfig.js');
|
|
5
6
|
var useQueryHeaders = require('./config/useQueryHeaders.js');
|
|
@@ -20,6 +21,7 @@ var transformer = require('./request/transformer.js');
|
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
|
|
24
|
+
exports.bootstrapQueryRequest = bootstrapQueryRequest.bootstrapQueryRequest;
|
|
23
25
|
exports.useEnvironmentVariables = useEnvironmentVariables.useEnvironmentVariables;
|
|
24
26
|
exports.useQueryConfig = useQueryConfig.useQueryConfig;
|
|
25
27
|
exports.useQueryHeaders = useQueryHeaders.useQueryHeaders;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,6 +2,20 @@ import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
|
2
2
|
import { useState, useMemo, useEffect, startTransition } from 'react';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
|
|
5
|
+
const bootstrapQueryRequest = (queryClient) => {
|
|
6
|
+
// make query config doesn't expire
|
|
7
|
+
queryClient.setQueryDefaults(['config'], {
|
|
8
|
+
staleTime: Infinity,
|
|
9
|
+
cacheTime: Infinity,
|
|
10
|
+
});
|
|
11
|
+
// set default query confg
|
|
12
|
+
queryClient.setQueryData(['config'], {
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: ``,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
5
19
|
const useEnvironmentVariables = () => {
|
|
6
20
|
const url = process.env.REACT_APP_API_URL || process.env.NEXT_PUBLIC_API_URL;
|
|
7
21
|
const timeout = process.env.REACT_APP_API_TIMEOUT || process.env.NEXT_PUBLIC_API_TIMEOUT;
|
|
@@ -415,5 +429,5 @@ const usePostRequest = ({ path, isFormData = false, }) => {
|
|
|
415
429
|
return { post, ...mutation };
|
|
416
430
|
};
|
|
417
431
|
|
|
418
|
-
export { ContentType, HttpMethod, axiosInstance, buildFormData, errorTransformer, getDateInFuture, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetRequest, useKeyTrackerModel, usePatchRequest, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useRefetchQuery };
|
|
432
|
+
export { ContentType, HttpMethod, axiosInstance, bootstrapQueryRequest, buildFormData, errorTransformer, getDateInFuture, makeRequest, scrollToTop, successTransformer, useDeleteRequest, useEnvironmentVariables, useGetRequest, useKeyTrackerModel, usePatchRequest, usePostRequest, useQueryConfig, useQueryHeaders, useQueryModel, useRefetchQuery };
|
|
419
433
|
//# sourceMappingURL=index.mjs.map
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { TanstackQueryConfig } from '../types';
|
|
3
|
+
|
|
4
|
+
export const bootstrapQueryRequest = (queryClient: QueryClient): void => {
|
|
5
|
+
// make query config doesn't expire
|
|
6
|
+
queryClient.setQueryDefaults(['config'], {
|
|
7
|
+
staleTime: Infinity,
|
|
8
|
+
cacheTime: Infinity,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
// set default query confg
|
|
12
|
+
queryClient.setQueryData<TanstackQueryConfig>(['config'], {
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: ``,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
};
|
package/src/config/index.ts
CHANGED