@ventlio/tanstack-query 0.3.0 → 0.3.2

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.
Files changed (49) hide show
  1. package/dist/config/bootstrapQueryRequest.js +1 -1
  2. package/dist/config/useQueryConfig.js +1 -27
  3. package/dist/config/useQueryConfig.js.map +1 -1
  4. package/dist/config/useQueryHeaders.js +15 -4
  5. package/dist/config/useQueryHeaders.js.map +1 -1
  6. package/dist/config/useReactNativeEnv.js +3 -3
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +123 -120
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/model/useKeyTrackerModel.d.ts +1 -1
  13. package/dist/model/useKeyTrackerModel.js +1 -5
  14. package/dist/model/useKeyTrackerModel.js.map +1 -1
  15. package/dist/queries/useDeleteRequest.d.ts +4 -4
  16. package/dist/queries/useDeleteRequest.js +11 -10
  17. package/dist/queries/useDeleteRequest.js.map +1 -1
  18. package/dist/queries/useGetInfiniteRequest.d.ts +4 -4
  19. package/dist/queries/useGetInfiniteRequest.js +23 -17
  20. package/dist/queries/useGetInfiniteRequest.js.map +1 -1
  21. package/dist/queries/useGetRequest.d.ts +4 -4
  22. package/dist/queries/useGetRequest.js +20 -14
  23. package/dist/queries/useGetRequest.js.map +1 -1
  24. package/dist/queries/usePatchRequest.d.ts +4 -4
  25. package/dist/queries/usePatchRequest.js +13 -16
  26. package/dist/queries/usePatchRequest.js.map +1 -1
  27. package/dist/queries/usePostRequest.d.ts +4 -4
  28. package/dist/queries/usePostRequest.js +13 -11
  29. package/dist/queries/usePostRequest.js.map +1 -1
  30. package/dist/stores/index.d.ts +1 -0
  31. package/dist/stores/usePauseFutureRequests.d.ts +7 -0
  32. package/dist/stores/usePauseFutureRequests.js +19 -0
  33. package/dist/stores/usePauseFutureRequests.js.map +1 -0
  34. package/dist/types/index.d.ts +4 -7
  35. package/package.json +3 -2
  36. package/src/config/bootstrapQueryRequest.ts +1 -1
  37. package/src/config/useQueryConfig.ts +4 -41
  38. package/src/config/useQueryHeaders.ts +18 -6
  39. package/src/config/useReactNativeEnv.ts +3 -3
  40. package/src/index.ts +2 -0
  41. package/src/model/useKeyTrackerModel.ts +1 -5
  42. package/src/queries/useDeleteRequest.ts +14 -11
  43. package/src/queries/useGetInfiniteRequest.ts +27 -19
  44. package/src/queries/useGetRequest.ts +24 -16
  45. package/src/queries/usePatchRequest.ts +17 -17
  46. package/src/queries/usePostRequest.ts +16 -12
  47. package/src/stores/index.ts +1 -0
  48. package/src/stores/usePauseFutureRequests.ts +25 -0
  49. package/src/types/index.ts +4 -7
@@ -3,11 +3,7 @@ import { useQueryClient } from '@tanstack/react-query';
3
3
  const useKeyTrackerModel = (keyTracker) => {
4
4
  const queryClient = useQueryClient();
5
5
  const getQueryKey = (innerKeyTracker) => {
6
- const meta = {
7
- ...queryClient.getDefaultOptions().mutations?.meta,
8
- ...queryClient.getDefaultOptions().queries?.meta,
9
- };
10
- const queryKey = meta[innerKeyTracker ?? keyTracker];
6
+ const queryKey = queryClient.getQueryData([innerKeyTracker ?? keyTracker]);
11
7
  return queryKey;
12
8
  };
13
9
  const refetchQuery = async (innerKeyTracker) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useKeyTrackerModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useKeyTrackerModel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
@@ -2,7 +2,7 @@ import type { UseQueryOptions } from '@tanstack/react-query';
2
2
  import type { IRequestError, IRequestSuccess } from '../request';
3
3
  import type { DefaultRequestOptions } from './queries.interface';
4
4
  export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultRequestOptions) => {
5
- isLoading: boolean | undefined;
5
+ isLoading: boolean;
6
6
  data: IRequestSuccess<TResponse>;
7
7
  error: any;
8
8
  isError: true;
@@ -31,7 +31,7 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
31
31
  cached?: boolean | undefined;
32
32
  }) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
33
33
  } | {
34
- isLoading: boolean | undefined;
34
+ isLoading: boolean;
35
35
  data: IRequestSuccess<TResponse>;
36
36
  error: null;
37
37
  isError: false;
@@ -60,7 +60,7 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
60
60
  cached?: boolean | undefined;
61
61
  }) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
62
62
  } | {
63
- isLoading: boolean | undefined;
63
+ isLoading: boolean;
64
64
  data: undefined;
65
65
  error: any;
66
66
  isError: true;
@@ -89,7 +89,7 @@ export declare const useDeleteRequest: <TResponse>(deleteOptions?: DefaultReques
89
89
  cached?: boolean | undefined;
90
90
  }) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
91
91
  } | {
92
- isLoading: boolean | undefined;
92
+ isLoading: boolean;
93
93
  data: undefined;
94
94
  error: null;
95
95
  isError: false;
@@ -7,13 +7,15 @@ import { useQueryHeaders } from '../config/useQueryHeaders.js';
7
7
  import 'axios';
8
8
  import { makeRequest } from '../request/make-request.js';
9
9
  import '../request/request.enum.js';
10
+ import { usePauseFutureRequests } from '../stores/usePauseFutureRequests.js';
10
11
 
11
12
  const useDeleteRequest = (deleteOptions) => {
12
13
  const { baseUrl, headers } = deleteOptions ?? {};
13
14
  const [requestPath, setRequestPath] = useState('');
14
15
  const [options, setOptions] = useState();
15
- const [destroyConfig, setDestroyConfig] = useState();
16
16
  const { options: queryConfigOptions } = useQueryConfig();
17
+ const [requestPayload, setRequestPayload] = useState();
18
+ const isFutureQueriesPaused = usePauseFutureRequests((state) => state.isFutureQueriesPaused);
17
19
  const { API_URL, TIMEOUT } = useEnvironmentVariables();
18
20
  const { getHeaders } = useQueryHeaders();
19
21
  const sendRequest = async (res, rej, queryKey) => {
@@ -28,7 +30,7 @@ const useDeleteRequest = (deleteOptions) => {
28
30
  timeout: TIMEOUT,
29
31
  };
30
32
  let shouldContinue = true;
31
- if (queryConfigOptions.queryMiddleware) {
33
+ if (queryConfigOptions?.queryMiddleware) {
32
34
  shouldContinue = await queryConfigOptions.queryMiddleware({ queryKey, ...requestOptions });
33
35
  }
34
36
  if (shouldContinue) {
@@ -52,7 +54,7 @@ const useDeleteRequest = (deleteOptions) => {
52
54
  return setOptions(fetchOptions);
53
55
  };
54
56
  const destroy = async (link, internalDeleteOptions) => {
55
- if (!queryConfigOptions.pauseFutureQueries) {
57
+ if (!isFutureQueriesPaused) {
56
58
  // set enabled to be true for every delete
57
59
  internalDeleteOptions = internalDeleteOptions ?? {};
58
60
  internalDeleteOptions.enabled = true;
@@ -61,19 +63,18 @@ const useDeleteRequest = (deleteOptions) => {
61
63
  return query.data;
62
64
  }
63
65
  else {
64
- // save delete config
65
- setDestroyConfig({ link, internalDeleteOptions });
66
+ setRequestPayload({ link, internalDeleteOptions });
66
67
  return undefined;
67
68
  }
68
69
  };
69
70
  useEffect(() => {
70
- if (!queryConfigOptions.pauseFutureQueries && destroyConfig) {
71
- destroy(destroyConfig.link, destroyConfig.internalDeleteOptions);
72
- setDestroyConfig(undefined);
71
+ if (!isFutureQueriesPaused && requestPayload) {
72
+ destroy(requestPayload.link, requestPayload.internalDeleteOptions);
73
+ setRequestPayload(undefined);
73
74
  }
74
75
  // eslint-disable-next-line react-hooks/exhaustive-deps
75
- }, [queryConfigOptions.pauseFutureQueries]);
76
- return { destroy, ...query, isLoading: query.isLoading || queryConfigOptions.pauseFutureQueries };
76
+ }, [isFutureQueriesPaused]);
77
+ return { destroy, ...query, isLoading: query.isLoading || isFutureQueriesPaused };
77
78
  };
78
79
 
79
80
  export { useDeleteRequest };
@@ -1 +1 @@
1
- {"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useDeleteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -17,7 +17,7 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
17
17
  }> | undefined;
18
18
  keyTracker?: string | undefined;
19
19
  } & DefaultRequestOptions) => {
20
- isLoading: boolean | undefined;
20
+ isLoading: boolean;
21
21
  data: undefined;
22
22
  error: any;
23
23
  isError: true;
@@ -58,7 +58,7 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
58
58
  pagination: Pagination;
59
59
  }>> | undefined>;
60
60
  } | {
61
- isLoading: boolean | undefined;
61
+ isLoading: boolean;
62
62
  data: undefined;
63
63
  error: null;
64
64
  isError: false;
@@ -99,7 +99,7 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
99
99
  pagination: Pagination;
100
100
  }>> | undefined>;
101
101
  } | {
102
- isLoading: boolean | undefined;
102
+ isLoading: boolean;
103
103
  data: InfiniteData<IRequestSuccess<TResponse & {
104
104
  pagination: Pagination;
105
105
  }>>;
@@ -142,7 +142,7 @@ export declare const useGetInfiniteRequest: <TResponse extends Record<string, an
142
142
  pagination: Pagination;
143
143
  }>> | undefined>;
144
144
  } | {
145
- isLoading: boolean | undefined;
145
+ isLoading: boolean;
146
146
  data: InfiniteData<IRequestSuccess<TResponse & {
147
147
  pagination: Pagination;
148
148
  }>>;
@@ -7,14 +7,16 @@ import { useQueryHeaders } from '../config/useQueryHeaders.js';
7
7
  import 'axios';
8
8
  import { makeRequest } from '../request/make-request.js';
9
9
  import '../request/request.enum.js';
10
+ import { usePauseFutureRequests } from '../stores/usePauseFutureRequests.js';
10
11
 
11
12
  const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl, headers, }) => {
12
13
  const { API_URL, TIMEOUT } = useEnvironmentVariables();
13
14
  const { getHeaders } = useQueryHeaders();
14
15
  const [requestPath, setRequestPath] = useState(path);
15
- const [queryConfig, setQueryConfig] = useState();
16
16
  const [options, setOptions] = useState(queryOptions);
17
- const { options: queryConfigOptions, setConfig } = useQueryConfig();
17
+ const { options: queryConfigOptions } = useQueryConfig();
18
+ const [requestPayload, setRequestPayload] = useState();
19
+ const isFutureQueriesPaused = usePauseFutureRequests((state) => state.isFutureQueriesPaused);
18
20
  let queryClient = useQueryClient();
19
21
  // eslint-disable-next-line react-hooks/exhaustive-deps
20
22
  queryClient = useMemo(() => queryClient, []);
@@ -29,7 +31,7 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
29
31
  timeout: TIMEOUT,
30
32
  };
31
33
  let shouldContinue = true;
32
- if (queryConfigOptions.queryMiddleware) {
34
+ if (queryConfigOptions?.queryMiddleware) {
33
35
  shouldContinue = await queryConfigOptions.queryMiddleware({ queryKey, ...requestOptions });
34
36
  }
35
37
  if (shouldContinue) {
@@ -61,7 +63,7 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
61
63
  return pathname + '?' + queryParams.toString();
62
64
  };
63
65
  const query = useInfiniteQuery([requestPath, {}], ({ pageParam = requestPath, queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey, pageParam)), {
64
- enabled: load || !queryConfigOptions.pauseFutureQueries,
66
+ enabled: load && !isFutureQueriesPaused,
65
67
  getNextPageParam: (lastPage) => constructPaginationLink('next_page', lastPage),
66
68
  getPreviousPageParam: (lastPage) => constructPaginationLink('previous_page', lastPage),
67
69
  ...options,
@@ -72,16 +74,23 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
72
74
  });
73
75
  };
74
76
  const get = async (link, fetchOptions) => {
75
- if (!queryConfigOptions.pauseFutureQueries) {
77
+ if (!isFutureQueriesPaused) {
76
78
  await setOptionsAsync(fetchOptions);
77
79
  await updatedPathAsync(link);
78
80
  return query.data;
79
81
  }
80
82
  else {
81
- setQueryConfig({ link, fetchOptions });
83
+ setRequestPayload({ link, fetchOptions });
82
84
  return undefined;
83
85
  }
84
86
  };
87
+ useEffect(() => {
88
+ if (!isFutureQueriesPaused && requestPayload) {
89
+ get(requestPayload.link, requestPayload.fetchOptions);
90
+ setRequestPayload(undefined);
91
+ }
92
+ // eslint-disable-next-line react-hooks/exhaustive-deps
93
+ }, [isFutureQueriesPaused]);
85
94
  const updatedPathAsync = async (link) => {
86
95
  startTransition(() => {
87
96
  setRequestPath(link);
@@ -89,21 +98,18 @@ const useGetInfiniteRequest = ({ path, load = false, queryOptions, keyTracker, b
89
98
  };
90
99
  useEffect(() => {
91
100
  if (keyTracker) {
92
- setConfig({ [keyTracker]: [requestPath, {}] });
101
+ // set expiration time for the tracker
102
+ queryClient.setQueryDefaults([keyTracker], {
103
+ cacheTime: Infinity,
104
+ staleTime: Infinity,
105
+ });
106
+ queryClient.setQueryData([keyTracker], [requestPath, {}]);
93
107
  }
94
- // eslint-disable-next-line react-hooks/exhaustive-deps
95
- }, [keyTracker, requestPath]);
96
- useEffect(() => {
97
- if (!queryConfigOptions.pauseFutureQueries && queryConfig) {
98
- get(queryConfig.link, queryConfig.fetchOptions);
99
- setQueryConfig(undefined);
100
- }
101
- // eslint-disable-next-line react-hooks/exhaustive-deps
102
- }, [queryConfigOptions.pauseFutureQueries]);
108
+ }, [keyTracker, requestPath, queryClient, queryOptions?.staleTime]);
103
109
  return {
104
110
  get,
105
111
  ...query,
106
- isLoading: query.isLoading || queryConfigOptions.pauseFutureQueries,
112
+ isLoading: query.isLoading || isFutureQueriesPaused,
107
113
  };
108
114
  };
109
115
 
@@ -1 +1 @@
1
- {"version":3,"file":"useGetInfiniteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useGetInfiniteRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -8,7 +8,7 @@ export declare const useGetRequest: <TResponse extends Record<string, any>>({ pa
8
8
  queryOptions?: TanstackQueryOption<TResponse> | undefined;
9
9
  keyTracker?: string | undefined;
10
10
  } & DefaultRequestOptions) => {
11
- isLoading: boolean | undefined;
11
+ isLoading: boolean;
12
12
  setRequestPath: import("react").Dispatch<import("react").SetStateAction<string>>;
13
13
  nextPage: () => void;
14
14
  prevPage: () => void;
@@ -41,7 +41,7 @@ export declare const useGetRequest: <TResponse extends Record<string, any>>({ pa
41
41
  remove: () => void;
42
42
  fetchStatus: import("@tanstack/react-query").FetchStatus;
43
43
  } | {
44
- isLoading: boolean | undefined;
44
+ isLoading: boolean;
45
45
  setRequestPath: import("react").Dispatch<import("react").SetStateAction<string>>;
46
46
  nextPage: () => void;
47
47
  prevPage: () => void;
@@ -74,7 +74,7 @@ export declare const useGetRequest: <TResponse extends Record<string, any>>({ pa
74
74
  remove: () => void;
75
75
  fetchStatus: import("@tanstack/react-query").FetchStatus;
76
76
  } | {
77
- isLoading: boolean | undefined;
77
+ isLoading: boolean;
78
78
  setRequestPath: import("react").Dispatch<import("react").SetStateAction<string>>;
79
79
  nextPage: () => void;
80
80
  prevPage: () => void;
@@ -107,7 +107,7 @@ export declare const useGetRequest: <TResponse extends Record<string, any>>({ pa
107
107
  remove: () => void;
108
108
  fetchStatus: import("@tanstack/react-query").FetchStatus;
109
109
  } | {
110
- isLoading: boolean | undefined;
110
+ isLoading: boolean;
111
111
  setRequestPath: import("react").Dispatch<import("react").SetStateAction<string>>;
112
112
  nextPage: () => void;
113
113
  prevPage: () => void;
@@ -7,6 +7,7 @@ import { useQueryHeaders } from '../config/useQueryHeaders.js';
7
7
  import 'axios';
8
8
  import { makeRequest } from '../request/make-request.js';
9
9
  import '../request/request.enum.js';
10
+ import { usePauseFutureRequests } from '../stores/usePauseFutureRequests.js';
10
11
 
11
12
  const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl, headers, }) => {
12
13
  const [requestPath, setRequestPath] = useState(path);
@@ -14,8 +15,9 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
14
15
  const [page, setPage] = useState(1);
15
16
  const { API_URL, TIMEOUT } = useEnvironmentVariables();
16
17
  const { getHeaders } = useQueryHeaders();
17
- const { options: queryConfigOptions, setConfig } = useQueryConfig();
18
- const [queryConfig, setQueryConfig] = useState();
18
+ const { options: queryConfigOptions } = useQueryConfig();
19
+ const [requestPayload, setRequestPayload] = useState();
20
+ const isFutureQueriesPaused = usePauseFutureRequests((state) => state.isFutureQueriesPaused);
19
21
  let queryClient = useQueryClient();
20
22
  // eslint-disable-next-line react-hooks/exhaustive-deps
21
23
  queryClient = useMemo(() => queryClient, []);
@@ -32,7 +34,7 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
32
34
  timeout: TIMEOUT,
33
35
  };
34
36
  let shouldContinue = true;
35
- if (queryConfigOptions.queryMiddleware) {
37
+ if (queryConfigOptions?.queryMiddleware) {
36
38
  shouldContinue = await queryConfigOptions.queryMiddleware({ queryKey, ...requestOptions });
37
39
  }
38
40
  if (shouldContinue) {
@@ -53,7 +55,7 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
53
55
  }
54
56
  };
55
57
  const query = useQuery([requestPath, {}], ({ queryKey }) => new Promise((res, rej) => sendRequest(res, rej, queryKey)), {
56
- enabled: load,
58
+ enabled: load && !isFutureQueriesPaused,
57
59
  ...options,
58
60
  });
59
61
  useEffect(() => {
@@ -63,10 +65,14 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
63
65
  }, [path]);
64
66
  useEffect(() => {
65
67
  if (keyTracker) {
66
- setConfig({ [keyTracker]: [requestPath, {}] });
68
+ // set expiration time for the tracker
69
+ queryClient.setQueryDefaults([keyTracker], {
70
+ cacheTime: Infinity,
71
+ staleTime: Infinity,
72
+ });
73
+ queryClient.setQueryData([keyTracker], [requestPath, {}]);
67
74
  }
68
- // eslint-disable-next-line react-hooks/exhaustive-deps
69
- }, [keyTracker, requestPath]);
75
+ }, [keyTracker, requestPath, queryClient, queryOptions?.staleTime]);
70
76
  const nextPage = () => {
71
77
  if (query.data?.data.pagination) {
72
78
  const pagination = query.data.data.pagination;
@@ -109,26 +115,26 @@ const useGetRequest = ({ path, load = false, queryOptions, keyTracker, baseUrl,
109
115
  });
110
116
  };
111
117
  const get = async (link, fetchOptions) => {
112
- if (!queryConfigOptions.pauseFutureQueries) {
118
+ if (!isFutureQueriesPaused) {
113
119
  await setOptionsAsync(fetchOptions);
114
120
  await updatedPathAsync(link);
115
121
  return query.data;
116
122
  }
117
123
  else {
118
- setQueryConfig({ link, fetchOptions });
124
+ setRequestPayload({ link, fetchOptions });
119
125
  return undefined;
120
126
  }
121
127
  };
122
128
  useEffect(() => {
123
- if (!queryConfigOptions.pauseFutureQueries && queryConfig) {
124
- get(queryConfig.link, queryConfig.fetchOptions);
125
- setQueryConfig(undefined);
129
+ if (!isFutureQueriesPaused && requestPayload) {
130
+ get(requestPayload.link, requestPayload.fetchOptions);
131
+ setRequestPayload(undefined);
126
132
  }
127
133
  // eslint-disable-next-line react-hooks/exhaustive-deps
128
- }, [queryConfigOptions.pauseFutureQueries]);
134
+ }, [isFutureQueriesPaused]);
129
135
  return {
130
136
  ...query,
131
- isLoading: query.isLoading || queryConfigOptions.pauseFutureQueries,
137
+ isLoading: query.isLoading || isFutureQueriesPaused,
132
138
  setRequestPath,
133
139
  nextPage,
134
140
  prevPage,
@@ -1 +1 @@
1
- {"version":3,"file":"useGetRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useGetRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -4,7 +4,7 @@ import type { DefaultRequestOptions } from './queries.interface';
4
4
  export declare const usePatchRequest: <TResponse>({ path, baseUrl, headers }: {
5
5
  path: string;
6
6
  } & DefaultRequestOptions) => {
7
- isLoading: boolean | undefined;
7
+ isLoading: boolean;
8
8
  data: undefined;
9
9
  error: null;
10
10
  isError: false;
@@ -22,7 +22,7 @@ export declare const usePatchRequest: <TResponse>({ path, baseUrl, headers }: {
22
22
  patch: (data: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
23
23
  uploadProgressPercent: number;
24
24
  } | {
25
- isLoading: boolean | undefined;
25
+ isLoading: boolean;
26
26
  data: undefined;
27
27
  error: null;
28
28
  isError: false;
@@ -40,7 +40,7 @@ export declare const usePatchRequest: <TResponse>({ path, baseUrl, headers }: {
40
40
  patch: (data: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
41
41
  uploadProgressPercent: number;
42
42
  } | {
43
- isLoading: boolean | undefined;
43
+ isLoading: boolean;
44
44
  data: undefined;
45
45
  error: IRequestError;
46
46
  isError: true;
@@ -58,7 +58,7 @@ export declare const usePatchRequest: <TResponse>({ path, baseUrl, headers }: {
58
58
  patch: (data: any, options?: MutateOptions<IRequestSuccess<TResponse>, IRequestError, void, unknown> | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
59
59
  uploadProgressPercent: number;
60
60
  } | {
61
- isLoading: boolean | undefined;
61
+ isLoading: boolean;
62
62
  data: IRequestSuccess<TResponse>;
63
63
  error: null;
64
64
  isError: false;
@@ -9,11 +9,13 @@ import { useUploadProgress } from '../hooks/useUploadProgress.js';
9
9
  import 'axios';
10
10
  import { makeRequest } from '../request/make-request.js';
11
11
  import { HttpMethod } from '../request/request.enum.js';
12
+ import { usePauseFutureRequests } from '../stores/usePauseFutureRequests.js';
12
13
 
13
14
  const usePatchRequest = ({ path, baseUrl, headers }) => {
14
15
  const { API_URL, TIMEOUT } = useEnvironmentVariables();
15
16
  const { uploadProgressPercent, onUploadProgress } = useUploadProgress();
16
- const [mutationConfig, setMutationConfig] = useState();
17
+ const [requestPayload, setRequestPayload] = useState();
18
+ const isFutureMutationsPaused = usePauseFutureRequests((state) => state.isFutureMutationsPaused);
17
19
  const { getHeaders } = useQueryHeaders();
18
20
  const config = useQueryConfig();
19
21
  const sendRequest = async (res, rej, data) => {
@@ -29,7 +31,7 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
29
31
  onUploadProgress,
30
32
  };
31
33
  let shouldContinue = true;
32
- if (config.options.mutationMiddleware) {
34
+ if (config.options?.mutationMiddleware) {
33
35
  shouldContinue = await config.options.mutationMiddleware({
34
36
  mutationKey: [path, { type: 'mutation' }],
35
37
  ...requestOptions,
@@ -39,14 +41,14 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
39
41
  const patchResponse = await makeRequest(requestOptions);
40
42
  if (patchResponse.status) {
41
43
  // scroll to top after success
42
- if (config.options.context !== 'app') {
44
+ if (config.options?.context !== 'app') {
43
45
  scrollToTop();
44
46
  }
45
47
  res(patchResponse);
46
48
  }
47
49
  else {
48
50
  // scroll to top after error
49
- if (config.options.context !== 'app') {
51
+ if (config.options?.context !== 'app') {
50
52
  scrollToTop();
51
53
  }
52
54
  rej(patchResponse);
@@ -61,27 +63,22 @@ const usePatchRequest = ({ path, baseUrl, headers }) => {
61
63
  return sendRequest(res, rej, dataData);
62
64
  }), { mutationKey: [path, { type: 'mutation' }] });
63
65
  const patch = async (data, options) => {
64
- if (!config.options.pauseFutureMutations) {
66
+ if (!isFutureMutationsPaused) {
65
67
  return mutation.mutateAsync(data, options);
66
68
  }
67
69
  else {
68
- setMutationConfig({ data, options });
70
+ setRequestPayload({ data, options });
69
71
  return undefined;
70
72
  }
71
73
  };
72
74
  useEffect(() => {
73
- if (!config.options.pauseFutureMutations && mutationConfig) {
74
- patch(mutationConfig.data, mutationConfig.options);
75
- setMutationConfig(undefined);
75
+ if (!isFutureMutationsPaused && requestPayload) {
76
+ patch(requestPayload.data, requestPayload.options);
77
+ setRequestPayload(undefined);
76
78
  }
77
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
78
- }, [config.options.pauseFutureMutations]);
79
- return {
80
- patch,
81
- uploadProgressPercent,
82
- ...mutation,
83
- isLoading: mutation.isLoading || config.options.pauseFutureMutations,
84
- };
80
+ }, [isFutureMutationsPaused]);
81
+ return { patch, uploadProgressPercent, ...mutation, isLoading: mutation.isLoading || isFutureMutationsPaused };
85
82
  };
86
83
 
87
84
  export { usePatchRequest };
@@ -1 +1 @@
1
- {"version":3,"file":"usePatchRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"usePatchRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -6,11 +6,11 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
6
6
  isFormData?: boolean | undefined;
7
7
  fileSelectors?: string[] | undefined;
8
8
  } & DefaultRequestOptions) => {
9
+ isLoading: boolean;
9
10
  data: undefined;
10
11
  error: null;
11
12
  isError: false;
12
13
  isIdle: true;
13
- isLoading: false;
14
14
  isSuccess: false;
15
15
  status: "idle";
16
16
  mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
@@ -42,11 +42,11 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
42
42
  }) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
43
43
  uploadProgressPercent: number;
44
44
  } | {
45
+ isLoading: boolean;
45
46
  data: undefined;
46
47
  error: null;
47
48
  isError: false;
48
49
  isIdle: false;
49
- isLoading: true;
50
50
  isSuccess: false;
51
51
  status: "loading";
52
52
  mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
@@ -78,11 +78,11 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
78
78
  }) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
79
79
  uploadProgressPercent: number;
80
80
  } | {
81
+ isLoading: boolean;
81
82
  data: undefined;
82
83
  error: IRequestError;
83
84
  isError: true;
84
85
  isIdle: false;
85
- isLoading: false;
86
86
  isSuccess: false;
87
87
  status: "error";
88
88
  mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
@@ -114,11 +114,11 @@ export declare const usePostRequest: <TResponse>({ path, isFormData, baseUrl, he
114
114
  }) | undefined) => Promise<IRequestSuccess<TResponse> | undefined>;
115
115
  uploadProgressPercent: number;
116
116
  } | {
117
+ isLoading: boolean;
117
118
  data: IRequestSuccess<TResponse>;
118
119
  error: null;
119
120
  isError: false;
120
121
  isIdle: false;
121
- isLoading: false;
122
122
  isSuccess: true;
123
123
  status: "success";
124
124
  mutate: import("@tanstack/react-query").UseMutateFunction<IRequestSuccess<TResponse>, IRequestError, {
@@ -10,14 +10,16 @@ import { useUploadProgress } from '../hooks/useUploadProgress.js';
10
10
  import 'axios';
11
11
  import { makeRequest } from '../request/make-request.js';
12
12
  import { HttpMethod } from '../request/request.enum.js';
13
+ import { usePauseFutureRequests } from '../stores/usePauseFutureRequests.js';
13
14
 
14
15
  const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelectors, }) => {
15
16
  const { API_URL, TIMEOUT } = useEnvironmentVariables();
16
17
  const config = useQueryConfig();
17
- const [mutationConfig, setMutationConfig] = useState();
18
18
  const { getHeaders } = useQueryHeaders();
19
19
  const { isApp } = useReactNativeEnv();
20
20
  const { uploadProgressPercent, onUploadProgress } = useUploadProgress();
21
+ const [requestPayload, setRequestPayload] = useState();
22
+ const isFutureMutationsPaused = usePauseFutureRequests((state) => state.isFutureMutationsPaused);
21
23
  const sendRequest = async (res, rej, postData) => {
22
24
  // get request headers
23
25
  const globalHeaders = getHeaders();
@@ -39,7 +41,7 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
39
41
  ...requestConfig,
40
42
  };
41
43
  let shouldContinue = true;
42
- if (config.options.mutationMiddleware) {
44
+ if (config.options?.mutationMiddleware) {
43
45
  shouldContinue = await config.options.mutationMiddleware({
44
46
  mutationKey: [path, { type: 'mutation' }],
45
47
  ...requestOptions,
@@ -49,14 +51,14 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
49
51
  const postResponse = await makeRequest(requestOptions);
50
52
  if (postResponse.status) {
51
53
  // scroll to top after success
52
- if (config.options.context !== 'app') {
54
+ if (config.options?.context !== 'app') {
53
55
  scrollToTop();
54
56
  }
55
57
  res(postResponse);
56
58
  }
57
59
  else {
58
60
  // scroll to top after error
59
- if (config.options.context !== 'app') {
61
+ if (config.options?.context !== 'app') {
60
62
  scrollToTop();
61
63
  }
62
64
  rej(postResponse);
@@ -71,23 +73,23 @@ const usePostRequest = ({ path, isFormData = false, baseUrl, headers, fileSelect
71
73
  mutationKey: [path, { type: 'mutation' }],
72
74
  });
73
75
  const post = async (data, options) => {
74
- if (!config.options.pauseFutureMutations) {
76
+ if (!isFutureMutationsPaused) {
75
77
  const { requestConfig, ...otherOptions } = options ?? {};
76
78
  return mutation.mutateAsync({ data, requestConfig }, otherOptions);
77
79
  }
78
80
  else {
79
- setMutationConfig({ data, options });
81
+ setRequestPayload({ data, options });
80
82
  return undefined;
81
83
  }
82
84
  };
83
85
  useEffect(() => {
84
- if (!config.options.pauseFutureMutations && mutationConfig) {
85
- post(mutationConfig.data, mutationConfig.options);
86
- setMutationConfig(undefined);
86
+ if (!isFutureMutationsPaused && requestPayload) {
87
+ post(requestPayload.data, requestPayload.options);
88
+ setRequestPayload(undefined);
87
89
  }
88
90
  // eslint-disable-next-line react-hooks/exhaustive-deps
89
- }, [config.options.pauseFutureMutations]);
90
- return { post, uploadProgressPercent, ...mutation };
91
+ }, [isFutureMutationsPaused]);
92
+ return { post, uploadProgressPercent, ...mutation, isLoading: mutation.isLoading || isFutureMutationsPaused };
91
93
  };
92
94
 
93
95
  export { usePostRequest };
@@ -1 +1 @@
1
- {"version":3,"file":"usePostRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"usePostRequest.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ export * from './usePauseFutureRequests';
@@ -0,0 +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>>;