query-harbor 0.0.8 → 0.0.10

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.
@@ -1,9 +1,10 @@
1
- import { AxiosRequestHeaders, AxiosResponse } from 'axios';
1
+ import { AxiosResponse } from 'axios';
2
+ export type ApiHeaders = Record<string, string | number | boolean>;
2
3
  interface ActionHandlerParams {
3
4
  action: "GET" | "POST" | "PUT" | "DELETE";
4
5
  url: string;
5
6
  data?: any;
6
- headers?: AxiosRequestHeaders;
7
+ headers?: ApiHeaders;
7
8
  }
8
9
  export interface ApiSuccessResponse {
9
10
  status: true;
@@ -1 +1 @@
1
- {"version":3,"file":"apiHandler.d.ts","sourceRoot":"","sources":["../../src/hooks/apiHandler.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlE,UAAU,mBAAmB;IACzB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,mBAAmB,CAAC;CACjC;AAGD,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,gBAAgB;IACtB,MAAM,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,WAAW,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAGzD,eAAO,MAAM,aAAa,mCAA0C,mBAAmB,KAAG,OAAO,CAAC,aAAa,CAiB9G,CAAC;AAGF,eAAO,MAAM,UAAU,mCAA0C,mBAAmB,KAAG,OAAO,CAAC,WAAW,CA8CzG,CAAC"}
1
+ {"version":3,"file":"apiHandler.d.ts","sourceRoot":"","sources":["../../src/hooks/apiHandler.ts"],"names":[],"mappings":"AAAA,OAAc,EAAuB,aAAa,EAAE,MAAM,OAAO,CAAC;AAGlE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAGnE,UAAU,mBAAmB;IACzB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,UAAU,CAAC;CACxB;AAGD,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,IAAI,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,gBAAgB;IACtB,MAAM,EAAE,KAAK,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,WAAW,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAGzD,eAAO,MAAM,aAAa,mCAA0C,mBAAmB,KAAG,OAAO,CAAC,aAAa,CAkB9G,CAAC;AAGF,eAAO,MAAM,UAAU,mCAA0C,mBAAmB,KAAG,OAAO,CAAC,WAAW,CA8CzG,CAAC"}
@@ -1,29 +1,36 @@
1
- interface UseGlobalInfiniteQueryParams<T> {
1
+ interface InfiniteQueryParams {
2
2
  url: string;
3
- queryKey: string[];
4
- methodType: "GET" | "POST" | "PUT" | "DELETE";
5
- data?: T;
3
+ queryKey: string[] | any;
4
+ method: "GET" | "POST" | "PUT" | "DELETE";
5
+ data?: any;
6
6
  enabled?: boolean;
7
+ cacheTime?: number;
7
8
  staleTime?: number;
9
+ responseDataKey?: string;
8
10
  }
9
- interface QueryResult<T> {
10
- data: T[];
11
- nextPage?: number;
12
- hasMore: boolean;
13
- totalCount: number;
11
+ interface ApiResponse<T> {
12
+ [key: string]: T[] | any;
13
+ pagination?: {
14
+ totalCount: number;
15
+ page: number;
16
+ limit: number;
17
+ totalPages: number;
18
+ };
19
+ totalCount?: number;
20
+ limit?: number;
21
+ page?: number;
22
+ totalPages?: number;
14
23
  }
15
- /**
16
- * Custom hook for handling infinite scrolling queries with React Query.
17
- */
18
- export declare const useGlobalInfiniteQuery: <T>({ url, queryKey, methodType, data, enabled, staleTime, }: UseGlobalInfiniteQueryParams<T>) => {
19
- refetchQuery: () => void;
24
+ declare const useGlobalInfiniteQuery: <T>({ url, queryKey, method, data, enabled, staleTime, responseDataKey, }: InfiniteQueryParams) => {
25
+ refetchQuery: () => Promise<void>;
20
26
  queryData: any[];
21
27
  isLoading: boolean;
22
28
  isError: boolean;
23
29
  error: Error | null;
24
- fetchNextPage: (options?: import('@tanstack/react-query').FetchNextPageOptions) => Promise<import('@tanstack/react-query').InfiniteQueryObserverResult<import('@tanstack/react-query').InfiniteData<QueryResult<T>, unknown>, Error>>;
30
+ fetchNextPage: (options?: import('@tanstack/react-query').FetchNextPageOptions) => Promise<import('@tanstack/react-query').InfiniteQueryObserverResult<import('@tanstack/react-query').InfiniteData<ApiResponse<T>, unknown>, Error>>;
25
31
  hasNextPage: boolean;
26
32
  totalCount: number;
33
+ otherData: any;
27
34
  };
28
- export {};
35
+ export default useGlobalInfiniteQuery;
29
36
  //# sourceMappingURL=useGlobalInfiniteQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGlobalInfiniteQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useGlobalInfiniteQuery.ts"],"names":[],"mappings":"AAIA,UAAU,4BAA4B,CAAC,C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C;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,QAAA,MAAM,sBAAsB,GAAI,CAAC,yEAQ9B,mBAAmB;;;;;;;;;;CAqFrB,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -1,15 +1,16 @@
1
1
  interface UseGlobalMutationParams<T> {
2
2
  url: string;
3
3
  queriesToInvalidate?: string[];
4
- methodType: "POST" | "PUT" | "DELETE";
4
+ method: "GET" | "POST" | "PUT" | "DELETE";
5
5
  data?: T;
6
6
  isFormData?: boolean;
7
- closePopup?: (state: boolean) => void;
7
+ onSuccess?: (data: any) => void;
8
8
  excludedIndexKeys?: string[];
9
9
  }
10
10
  interface MutationFunctionParams<T> {
11
11
  isPriorityDataAvailable?: boolean;
12
12
  priorityData?: T;
13
+ url?: string;
13
14
  }
14
15
  /**
15
16
  * Custom hook for handling global mutations with React Query.
@@ -22,7 +23,7 @@ interface MutationFunctionParams<T> {
22
23
  * @param {Array<string>} [excludedIndexKeys] - Keys for which array indices should not be included in FormData.
23
24
  * @returns {Object} An object containing mutation-related functions and state.
24
25
  */
25
- export declare const useGlobalMutation: <T extends Record<string, any>>({ url, queriesToInvalidate, methodType, data, isFormData, closePopup, excludedIndexKeys, }: UseGlobalMutationParams<T>) => {
26
+ export declare const useGlobalMutation: <T extends Record<string, any>>({ url, queriesToInvalidate, method, data, isFormData, onSuccess: onMutationSuccess, excludedIndexKeys, }: UseGlobalMutationParams<T>) => {
26
27
  runMutation: (params?: MutationFunctionParams<T>) => void;
27
28
  mutationLoading: boolean;
28
29
  mutationData: any;
@@ -1 +1 @@
1
- {"version":3,"file":"useGlobalMutation.d.ts","sourceRoot":"","sources":["../../src/hooks/useGlobalMutation.ts"],"names":[],"mappings":"AAIA,UAAU,uBAAuB,CAAC,CAAC;IAC/B,GAAG,EAAE,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H,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,4GAQ5D,uBAAuB,CAAC,CAAC,CAAC;2BA8FK,sBAAsB,CAAC,CAAC,CAAC;;;;;CAe1D,CAAC"}
@@ -1,12 +1,14 @@
1
1
  import { QueryKey } from '@tanstack/react-query';
2
2
  interface UseGlobalQueryParams {
3
3
  url: string;
4
+ baseUrl?: string;
4
5
  queryKey: QueryKey;
5
- methodType: "GET" | "POST" | "PUT" | "DELETE";
6
+ method: "GET" | "POST" | "PUT" | "DELETE";
6
7
  data?: any;
7
8
  enabled?: boolean;
8
9
  staleTime?: number;
9
10
  refetchOnWindowFocus?: boolean;
11
+ select?: (data: any) => any;
10
12
  }
11
13
  interface UseGlobalQueryReturn {
12
14
  refetchQuery: () => void;
@@ -54,6 +56,6 @@ interface UseGlobalQueryReturn {
54
56
  * );
55
57
  *
56
58
  */
57
- export declare const useGlobalQuery: ({ url, queryKey, methodType, data, enabled, staleTime, refetchOnWindowFocus }: UseGlobalQueryParams) => UseGlobalQueryReturn;
59
+ export declare const useGlobalQuery: ({ url, baseUrl, queryKey, method, data, enabled, staleTime, refetchOnWindowFocus, select }: UseGlobalQueryParams) => UseGlobalQueryReturn;
58
60
  export {};
59
61
  //# sourceMappingURL=useGlobalQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGlobalQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useGlobalQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAK3F,UAAU,oBAAoB;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC9C,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE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CHANGED
@@ -1,5 +1,5 @@
1
1
  export { useGlobalQuery } from './hooks/useGlobalQuery';
2
2
  export { useGlobalMutation } from './hooks/useGlobalMutation';
3
- export { useGlobalInfiniteQuery } from './hooks/useGlobalInfiniteQuery';
3
+ export * from './hooks/useGlobalInfiniteQuery';
4
4
  export { useCookie } from './hooks/useCookie';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
@@ -1,50 +1,51 @@
1
- import { useQueryClient as N, useQuery as b, useMutation as v, useInfiniteQuery as L } from "@tanstack/react-query";
2
- import { useCookies as j } from "react-cookie";
3
- import F from "axios";
4
- const M = ({ cookieName: i }) => {
5
- const [s, o, n] = j([i]);
6
- return { cookie: s, setCookie: o, removeCookie: n };
7
- }, q = async ({ action: i, url: s, data: o, headers: n }) => {
8
- switch (i) {
1
+ import { useQueryClient as $, useQuery as v, useMutation as M } from "@tanstack/react-query";
2
+ import { useCookies as N } from "react-cookie";
3
+ import k from "axios";
4
+ const b = ({ cookieName: o }) => {
5
+ const [a, e, d] = N([o]);
6
+ return { cookie: a, setCookie: e, removeCookie: d };
7
+ }, j = async ({ action: o, url: a, data: e, headers: d }) => {
8
+ const n = d;
9
+ switch (o) {
9
10
  case "GET":
10
- return await F.get(s, { headers: n });
11
+ return await k.get(a, { headers: n });
11
12
  case "POST":
12
- return await F.post(s, o, { headers: n });
13
+ return await k.post(a, e, { headers: n });
13
14
  case "PUT":
14
- return await F.put(s, o, { headers: n });
15
+ return await k.put(a, e, { headers: n });
15
16
  case "DELETE":
16
- return await F.delete(s, { data: o, headers: n });
17
+ return await k.delete(a, { data: e, headers: n });
17
18
  default:
18
- throw new Error(`Invalid action: ${i}`);
19
+ throw new Error(`Invalid action: ${o}`);
19
20
  }
20
- }, I = async ({ action: i, url: s, data: o, headers: n }) => {
21
- var y, m, P, d, r, e, a;
21
+ }, Q = async ({ action: o, url: a, data: e, headers: d }) => {
22
+ var n, m, E, y, i, g, r;
22
23
  try {
23
- const c = await q({ action: i, url: s, data: o, headers: n });
24
- return c.status >= 200 && c.status <= 299 ? {
24
+ const s = await j({ action: o, url: a, data: e, headers: d });
25
+ return s.status >= 200 && s.status <= 299 ? {
25
26
  status: !0,
26
- data: c.data,
27
- message: c.data.message,
28
- statusCode: c.status
27
+ data: s.data,
28
+ message: s.data.message,
29
+ statusCode: s.status
29
30
  } : {
30
31
  status: !1,
31
32
  error: "API Failed",
32
33
  message: "API Failed",
33
- statusCode: c.status
34
+ statusCode: s.status
34
35
  };
35
- } catch (c) {
36
- if (F.isAxiosError(c)) {
37
- const t = c;
36
+ } catch (s) {
37
+ if (k.isAxiosError(s)) {
38
+ const t = s;
38
39
  return t.message === "Network Error" ? {
39
40
  status: !1,
40
41
  error: "Network Error",
41
42
  message: "Network Error"
42
43
  } : {
43
44
  status: !1,
44
- type: (m = (y = t.response) == null ? void 0 : y.data) == null ? void 0 : m.type,
45
- message: ((d = (P = t.response) == null ? void 0 : P.data) == null ? void 0 : d.message) || "API Failed",
46
- error: ((e = (r = t.response) == null ? void 0 : r.data) == null ? void 0 : e.error) || "API Failed",
47
- statusCode: (a = t.response) == null ? void 0 : a.status
45
+ type: (m = (n = t.response) == null ? void 0 : n.data) == null ? void 0 : m.type,
46
+ message: ((y = (E = t.response) == null ? void 0 : E.data) == null ? void 0 : y.message) || "API Failed",
47
+ error: ((g = (i = t.response) == null ? void 0 : i.data) == null ? void 0 : g.error) || "API Failed",
48
+ statusCode: (r = t.response) == null ? void 0 : r.status
48
49
  };
49
50
  }
50
51
  return {
@@ -53,176 +54,121 @@ const M = ({ cookieName: i }) => {
53
54
  message: "API Failed"
54
55
  };
55
56
  }
56
- }, B = ({
57
- url: i,
58
- queryKey: s,
59
- methodType: o,
57
+ }, z = ({
58
+ url: o,
59
+ baseUrl: a,
60
+ queryKey: e,
61
+ method: d,
60
62
  data: n,
61
- enabled: y = !0,
62
- staleTime: m = 5 * 60 * 1e3,
63
- refetchOnWindowFocus: P = !1
63
+ enabled: m = !0,
64
+ staleTime: E = 5 * 60 * 1e3,
65
+ refetchOnWindowFocus: y = !1,
66
+ select: i
64
67
  }) => {
65
- const d = N(), { cookie: r } = M({ cookieName: "accessToken" });
66
- let e = {};
67
- r != null && r.accessToken && (e = { Authorization: `Bearer ${r.accessToken}` });
68
- const a = b({
69
- queryKey: s,
68
+ const g = $(), { cookie: r } = b({ cookieName: "accessToken" });
69
+ let s = {};
70
+ r != null && r.accessToken && (s = { Authorization: `Bearer ${r.accessToken}` });
71
+ const t = v({
72
+ queryKey: e,
70
73
  queryFn: async () => {
71
74
  try {
72
- const t = await I({
73
- action: o,
74
- url: i,
75
+ const u = await Q({
76
+ action: d,
77
+ url: o,
75
78
  data: n,
76
- headers: e
79
+ headers: s
77
80
  });
78
- return t != null && t.data ? t.data : { totalCount: 0, data: [] };
79
- } catch (t) {
80
- throw console.error("Query Error:", t), t;
81
+ return u != null && u.data ? u.data : { totalCount: 0, data: [] };
82
+ } catch (u) {
83
+ throw console.error("Query Error:", u), u;
81
84
  }
82
85
  },
83
- enabled: y,
84
- staleTime: m,
85
- refetchOnWindowFocus: P
86
+ enabled: m,
87
+ staleTime: E,
88
+ refetchOnWindowFocus: y,
89
+ select: i
86
90
  });
87
91
  return {
88
92
  refetchQuery: () => {
89
- d.invalidateQueries({ queryKey: s });
93
+ g.invalidateQueries({ queryKey: e });
90
94
  },
91
- queryData: a.data,
92
- isLoading: a.isLoading,
93
- isError: a.isError,
94
- error: a.error
95
+ queryData: t.data,
96
+ isLoading: t.isLoading,
97
+ isError: t.isError,
98
+ error: t.error
95
99
  };
96
- }, H = ({
97
- url: i,
98
- queriesToInvalidate: s,
99
- methodType: o,
100
- data: n,
101
- isFormData: y,
102
- closePopup: m,
103
- excludedIndexKeys: P
100
+ }, B = ({
101
+ url: o,
102
+ queriesToInvalidate: a,
103
+ method: e,
104
+ data: d,
105
+ isFormData: n,
106
+ onSuccess: m,
107
+ excludedIndexKeys: E
104
108
  }) => {
105
109
  var t;
106
- const d = N(), { cookie: r } = M({ cookieName: "accessToken" });
107
- let e = {};
108
- r != null && r.accessToken && (e = { Authorization: `Bearer ${r == null ? void 0 : r.accessToken}` });
109
- const a = v({
110
- mutationFn: async ({ isPriorityDataAvailable: w, priorityData: k }) => {
111
- const C = w ? k : n;
112
- if (y) {
113
- const x = new FormData(), p = (u, l, g = "", A = {}) => {
114
- if (l == null) return;
115
- const { excludedIndexKeys: S = [] } = A;
116
- Array.isArray(l) ? l.forEach((h, $) => {
117
- const T = S.includes(g) ? g : g ? `${g}[${$}]` : `${$}`;
118
- h instanceof File ? u.append(T, h) : typeof h == "object" && h !== null ? p(u, h, T, A) : u.append(T, String(h));
119
- }) : typeof l == "object" && l !== null ? l instanceof File ? u.append(g, l) : Object.keys(l).forEach((h) => {
120
- p(u, l[h], g ? `${g}[${h}]` : h, A);
121
- }) : u.append(g, String(l));
110
+ const y = $(), { cookie: i } = b({ cookieName: "accessToken" });
111
+ let g = {};
112
+ i != null && i.accessToken && (g = { Authorization: `Bearer ${i == null ? void 0 : i.accessToken}` });
113
+ const r = M({
114
+ mutationFn: async ({ isPriorityDataAvailable: f, priorityData: u, url: L = o }) => {
115
+ const p = f ? u : d;
116
+ if (n) {
117
+ const F = new FormData(), A = (w, c, h = "", I = {}) => {
118
+ if (c == null || c == null) return;
119
+ const { excludedIndexKeys: P = [] } = I;
120
+ Array.isArray(c) ? c.forEach((l, S) => {
121
+ const T = (P == null ? void 0 : P.includes(h)) ? h : h ? `${h}[${S}]` : `${S}`;
122
+ l instanceof File ? w.append(T, l) : typeof l == "object" && l !== null ? A(w, l, T, I) : w.append(T, String(l));
123
+ }) : typeof c == "object" && c !== null ? c instanceof File ? w.append(h, c) : Object.keys(c).forEach((l) => {
124
+ A(w, c[l], h ? `${h}[${l}]` : l, I);
125
+ }) : w.append(h, String(c));
122
126
  };
123
- Object.keys(C || {}).forEach((u) => {
124
- p(x, C == null ? void 0 : C[u], u, { excludedIndexKeys: P });
127
+ Object.keys(p || {}).forEach((w) => {
128
+ A(F, p == null ? void 0 : p[w], w, { excludedIndexKeys: E });
125
129
  });
126
- const { status: f, message: E, data: Q } = await I({
127
- action: o,
128
- url: i,
129
- data: x,
130
- headers: e
130
+ const { status: C, message: q, data: x } = await Q({
131
+ action: e,
132
+ url: o,
133
+ data: F,
134
+ headers: g
131
135
  });
132
- if (f)
133
- return Q;
134
- throw new Error(E || "Something went wrong!");
136
+ if (C)
137
+ return x;
138
+ throw new Error(q || "Something went wrong!");
135
139
  } else {
136
- const { status: x, message: p, data: f } = await I({
137
- action: o,
138
- url: i,
139
- data: C,
140
- headers: e
140
+ const { status: F, message: A, data: C } = await Q({
141
+ action: e,
142
+ url: o,
143
+ data: p,
144
+ headers: g
141
145
  });
142
- if (x)
143
- return f;
144
- throw new Error(p || "Something went wrong!");
146
+ if (F)
147
+ return C;
148
+ throw new Error(A || "Something went wrong!");
145
149
  }
146
150
  },
147
- onSuccess: () => {
148
- d.invalidateQueries({ queryKey: s }), m && m(!1);
151
+ onSuccess: (f) => {
152
+ y.invalidateQueries({ queryKey: a }), m && m(f);
149
153
  },
150
- onError: (w) => (console.error("mutationError", w.message), w.message)
154
+ onError: (f) => (console.error("mutationError", f.message), f.message)
151
155
  });
152
156
  return {
153
- runMutation: (w) => {
157
+ runMutation: (f) => {
154
158
  try {
155
- a.mutate(w || {});
156
- } catch (k) {
157
- console.error("Mutation Error: ", k);
159
+ r.mutate(f || {});
160
+ } catch (u) {
161
+ console.error("Mutation Error: ", u);
158
162
  }
159
163
  },
160
- mutationLoading: a.isPending,
161
- mutationData: a.data,
162
- mutationError: (t = a.error) == null ? void 0 : t.message,
163
- isMutationSucceeded: a.isSuccess
164
- };
165
- }, W = ({
166
- url: i,
167
- queryKey: s,
168
- methodType: o,
169
- data: n,
170
- enabled: y = !0,
171
- staleTime: m = 5 * 60 * 1e3
172
- }) => {
173
- var w, k, C, x, p;
174
- const P = N(), { cookie: d } = M({ cookieName: "accessToken" });
175
- let r = {};
176
- d != null && d.accessToken && (r = { Authorization: `Bearer ${d.accessToken}` });
177
- const e = L({
178
- queryKey: s,
179
- queryFn: async ({ pageParam: f = 1 }) => {
180
- try {
181
- const E = await I({
182
- action: o,
183
- url: i,
184
- data: {
185
- ...n,
186
- page: f
187
- },
188
- headers: r
189
- });
190
- if (E != null && E.data) {
191
- const { data: Q, page: u, totalPages: l, totalCount: g } = E.data, A = u < l;
192
- return {
193
- data: Q,
194
- nextPage: A ? u + 1 : void 0,
195
- hasMore: A,
196
- totalCount: g
197
- };
198
- } else
199
- return { totalCount: 0, data: [], hasMore: !1 };
200
- } catch (E) {
201
- throw console.error("Query Error:", E), E;
202
- }
203
- },
204
- initialPageParam: 1,
205
- getNextPageParam: (f) => f.hasMore ? f.nextPage : void 0,
206
- enabled: y,
207
- staleTime: m,
208
- refetchOnWindowFocus: !1
209
- }), a = () => {
210
- P.invalidateQueries({ queryKey: s });
211
- }, c = ((k = (w = e == null ? void 0 : e.data) == null ? void 0 : w.pages) == null ? void 0 : k.flatMap((f) => f.data)) || [], t = ((p = (x = (C = e == null ? void 0 : e.data) == null ? void 0 : C.pages) == null ? void 0 : x[0]) == null ? void 0 : p.totalCount) ?? 0;
212
- return {
213
- refetchQuery: a,
214
- queryData: c,
215
- isLoading: e.isLoading,
216
- isError: e.isError,
217
- error: e.error,
218
- fetchNextPage: e.fetchNextPage,
219
- hasNextPage: e.hasNextPage,
220
- totalCount: t
164
+ mutationLoading: r.isPending,
165
+ mutationData: r.data,
166
+ mutationError: (t = r.error) == null ? void 0 : t.message,
167
+ isMutationSucceeded: r.isSuccess
221
168
  };
222
169
  };
223
170
  export {
224
- M as useCookie,
225
- W as useGlobalInfiniteQuery,
226
- H as useGlobalMutation,
227
- B as useGlobalQuery
171
+ b as useCookie,
172
+ B as useGlobalMutation,
173
+ z as useGlobalQuery
228
174
  };
@@ -1 +1 @@
1
- (function(c,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@tanstack/react-query"),require("react-cookie"),require("axios")):typeof define=="function"&&define.amd?define(["exports","@tanstack/react-query","react-cookie","axios"],g):(c=typeof globalThis<"u"?globalThis:c||self,g(c.QueryHarbor={},c.ReactQuery,c.ReactCookie,c.axios))})(this,function(c,g,q,Q){"use strict";const x=({cookieName:i})=>{const[s,o,n]=q.useCookies([i]);return{cookie:s,setCookie:o,removeCookie:n}},$=async({action:i,url:s,data:o,headers:n})=>{switch(i){case"GET":return await Q.get(s,{headers:n});case"POST":return await Q.post(s,o,{headers:n});case"PUT":return await Q.put(s,o,{headers:n});case"DELETE":return await Q.delete(s,{data:o,headers:n});default:throw new Error(`Invalid action: ${i}`)}},M=async({action:i,url:s,data:o,headers:n})=>{var k,E,P,f,r,e,a;try{const u=await $({action:i,url:s,data:o,headers:n});return u.status>=200&&u.status<=299?{status:!0,data:u.data,message:u.data.message,statusCode:u.status}:{status:!1,error:"API Failed",message:"API Failed",statusCode:u.status}}catch(u){if(Q.isAxiosError(u)){const t=u;return t.message==="Network Error"?{status:!1,error:"Network Error",message:"Network Error"}:{status:!1,type:(E=(k=t.response)==null?void 0:k.data)==null?void 0:E.type,message:((f=(P=t.response)==null?void 0:P.data)==null?void 0:f.message)||"API Failed",error:((e=(r=t.response)==null?void 0:r.data)==null?void 0:e.error)||"API Failed",statusCode:(a=t.response)==null?void 0:a.status}}return{status:!1,error:"API Failed",message:"API Failed"}}},v=({url:i,queryKey:s,methodType:o,data:n,enabled:k=!0,staleTime:E=3e5,refetchOnWindowFocus:P=!1})=>{const f=g.useQueryClient(),{cookie:r}=x({cookieName:"accessToken"});let e={};r!=null&&r.accessToken&&(e={Authorization:`Bearer ${r.accessToken}`});const a=g.useQuery({queryKey:s,queryFn:async()=>{try{const t=await M({action:o,url:i,data:n,headers:e});return t!=null&&t.data?t.data:{totalCount:0,data:[]}}catch(t){throw console.error("Query Error:",t),t}},enabled:k,staleTime:E,refetchOnWindowFocus:P});return{refetchQuery:()=>{f.invalidateQueries({queryKey:s})},queryData:a.data,isLoading:a.isLoading,isError:a.isError,error:a.error}},G=({url:i,queriesToInvalidate:s,methodType:o,data:n,isFormData:k,closePopup:E,excludedIndexKeys:P})=>{var t;const f=g.useQueryClient(),{cookie:r}=x({cookieName:"accessToken"});let e={};r!=null&&r.accessToken&&(e={Authorization:`Bearer ${r==null?void 0:r.accessToken}`});const a=g.useMutation({mutationFn:async({isPriorityDataAvailable:m,priorityData:A})=>{const p=m?A:n;if(k){const T=new FormData,I=(l,d,y="",F={})=>{if(d==null)return;const{excludedIndexKeys:L=[]}=F;Array.isArray(d)?d.forEach((w,S)=>{const N=L.includes(y)?y:y?`${y}[${S}]`:`${S}`;w instanceof File?l.append(N,w):typeof w=="object"&&w!==null?I(l,w,N,F):l.append(N,String(w))}):typeof d=="object"&&d!==null?d instanceof File?l.append(y,d):Object.keys(d).forEach(w=>{I(l,d[w],y?`${y}[${w}]`:w,F)}):l.append(y,String(d))};Object.keys(p||{}).forEach(l=>{I(T,p==null?void 0:p[l],l,{excludedIndexKeys:P})});const{status:h,message:C,data:b}=await M({action:o,url:i,data:T,headers:e});if(h)return b;throw new Error(C||"Something went wrong!")}else{const{status:T,message:I,data:h}=await M({action:o,url:i,data:p,headers:e});if(T)return h;throw new Error(I||"Something went wrong!")}},onSuccess:()=>{f.invalidateQueries({queryKey:s}),E&&E(!1)},onError:m=>(console.error("mutationError",m.message),m.message)});return{runMutation:m=>{try{a.mutate(m||{})}catch(A){console.error("Mutation Error: ",A)}},mutationLoading:a.isPending,mutationData:a.data,mutationError:(t=a.error)==null?void 0:t.message,isMutationSucceeded:a.isSuccess}},j=({url:i,queryKey:s,methodType:o,data:n,enabled:k=!0,staleTime:E=3e5})=>{var m,A,p,T,I;const P=g.useQueryClient(),{cookie:f}=x({cookieName:"accessToken"});let r={};f!=null&&f.accessToken&&(r={Authorization:`Bearer ${f.accessToken}`});const e=g.useInfiniteQuery({queryKey:s,queryFn:async({pageParam:h=1})=>{try{const C=await M({action:o,url:i,data:{...n,page:h},headers:r});if(C!=null&&C.data){const{data:b,page:l,totalPages:d,totalCount:y}=C.data,F=l<d;return{data:b,nextPage:F?l+1:void 0,hasMore:F,totalCount:y}}else return{totalCount:0,data:[],hasMore:!1}}catch(C){throw console.error("Query Error:",C),C}},initialPageParam:1,getNextPageParam:h=>h.hasMore?h.nextPage:void 0,enabled:k,staleTime:E,refetchOnWindowFocus:!1}),a=()=>{P.invalidateQueries({queryKey:s})},u=((A=(m=e==null?void 0:e.data)==null?void 0:m.pages)==null?void 0:A.flatMap(h=>h.data))||[],t=((I=(T=(p=e==null?void 0:e.data)==null?void 0:p.pages)==null?void 0:T[0])==null?void 0:I.totalCount)??0;return{refetchQuery:a,queryData:u,isLoading:e.isLoading,isError:e.isError,error:e.error,fetchNextPage:e.fetchNextPage,hasNextPage:e.hasNextPage,totalCount:t}};c.useCookie=x,c.useGlobalInfiniteQuery=j,c.useGlobalMutation=G,c.useGlobalQuery=v,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("@tanstack/react-query"),require("react-cookie"),require("axios")):typeof define=="function"&&define.amd?define(["exports","@tanstack/react-query","react-cookie","axios"],y):(n=typeof globalThis<"u"?globalThis:n||self,y(n.QueryHarbor={},n.ReactQuery,n.ReactCookie,n.axios))})(this,function(n,y,M,C){"use strict";const q=({cookieName:o})=>{const[a,e,f]=M.useCookies([o]);return{cookie:a,setCookie:e,removeCookie:f}},j=async({action:o,url:a,data:e,headers:f})=>{const u=f;switch(o){case"GET":return await C.get(a,{headers:u});case"POST":return await C.post(a,e,{headers:u});case"PUT":return await C.put(a,e,{headers:u});case"DELETE":return await C.delete(a,{data:e,headers:u});default:throw new Error(`Invalid action: ${o}`)}},P=async({action:o,url:a,data:e,headers:f})=>{var u,m,k,p,i,g,r;try{const s=await j({action:o,url:a,data:e,headers:f});return s.status>=200&&s.status<=299?{status:!0,data:s.data,message:s.data.message,statusCode:s.status}:{status:!1,error:"API Failed",message:"API Failed",statusCode:s.status}}catch(s){if(C.isAxiosError(s)){const t=s;return t.message==="Network Error"?{status:!1,error:"Network Error",message:"Network Error"}:{status:!1,type:(m=(u=t.response)==null?void 0:u.data)==null?void 0:m.type,message:((p=(k=t.response)==null?void 0:k.data)==null?void 0:p.message)||"API Failed",error:((g=(i=t.response)==null?void 0:i.data)==null?void 0:g.error)||"API Failed",statusCode:(r=t.response)==null?void 0:r.status}}return{status:!1,error:"API Failed",message:"API Failed"}}},v=({url:o,baseUrl:a,queryKey:e,method:f,data:u,enabled:m=!0,staleTime:k=3e5,refetchOnWindowFocus:p=!1,select:i})=>{const g=y.useQueryClient(),{cookie:r}=q({cookieName:"accessToken"});let s={};r!=null&&r.accessToken&&(s={Authorization:`Bearer ${r.accessToken}`});const t=y.useQuery({queryKey:e,queryFn:async()=>{try{const c=await P({action:f,url:o,data:u,headers:s});return c!=null&&c.data?c.data:{totalCount:0,data:[]}}catch(c){throw console.error("Query Error:",c),c}},enabled:m,staleTime:k,refetchOnWindowFocus:p,select:i});return{refetchQuery:()=>{g.invalidateQueries({queryKey:e})},queryData:t.data,isLoading:t.isLoading,isError:t.isError,error:t.error}},G=({url:o,queriesToInvalidate:a,method:e,data:f,isFormData:u,onSuccess:m,excludedIndexKeys:k})=>{var t;const p=y.useQueryClient(),{cookie:i}=q({cookieName:"accessToken"});let g={};i!=null&&i.accessToken&&(g={Authorization:`Bearer ${i==null?void 0:i.accessToken}`});const r=y.useMutation({mutationFn:async({isPriorityDataAvailable:h,priorityData:c,url:L=o})=>{const A=h?c:f;if(u){const F=new FormData,T=(w,l,E="",I={})=>{if(l==null||l==null)return;const{excludedIndexKeys:S=[]}=I;Array.isArray(l)?l.forEach((d,$)=>{const Q=(S==null?void 0:S.includes(E))?E:E?`${E}[${$}]`:`${$}`;d instanceof File?w.append(Q,d):typeof d=="object"&&d!==null?T(w,d,Q,I):w.append(Q,String(d))}):typeof l=="object"&&l!==null?l instanceof File?w.append(E,l):Object.keys(l).forEach(d=>{T(w,l[d],E?`${E}[${d}]`:d,I)}):w.append(E,String(l))};Object.keys(A||{}).forEach(w=>{T(F,A==null?void 0:A[w],w,{excludedIndexKeys:k})});const{status:b,message:N,data:H}=await P({action:e,url:o,data:F,headers:g});if(b)return H;throw new Error(N||"Something went wrong!")}else{const{status:F,message:T,data:b}=await P({action:e,url:o,data:A,headers:g});if(F)return b;throw new Error(T||"Something went wrong!")}},onSuccess:h=>{p.invalidateQueries({queryKey:a}),m&&m(h)},onError:h=>(console.error("mutationError",h.message),h.message)});return{runMutation:h=>{try{r.mutate(h||{})}catch(c){console.error("Mutation Error: ",c)}},mutationLoading:r.isPending,mutationData:r.data,mutationError:(t=r.error)==null?void 0:t.message,isMutationSucceeded:r.isSuccess}};n.useCookie=q,n.useGlobalMutation=G,n.useGlobalQuery=v,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "query-harbor",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"