@bit.rhplus/data 0.0.6 → 0.0.8

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.
@@ -0,0 +1,327 @@
1
+ export function useApiQuery(key: any, api: any, params: {} | undefined, returnFn: any, ui?: boolean): {
2
+ updateData: (updateFn: any) => void;
3
+ data: any;
4
+ error: Error;
5
+ isError: true;
6
+ isPending: false;
7
+ isLoading: false;
8
+ isLoadingError: false;
9
+ isRefetchError: true;
10
+ isSuccess: false;
11
+ isPlaceholderData: false;
12
+ status: "error";
13
+ dataUpdatedAt: number;
14
+ errorUpdatedAt: number;
15
+ failureCount: number;
16
+ failureReason: Error | null;
17
+ errorUpdateCount: number;
18
+ isFetched: boolean;
19
+ isFetchedAfterMount: boolean;
20
+ isFetching: boolean;
21
+ isInitialLoading: boolean;
22
+ isPaused: boolean;
23
+ isRefetching: boolean;
24
+ isStale: boolean;
25
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
26
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
27
+ promise: Promise<any>;
28
+ } | {
29
+ updateData: (updateFn: any) => void;
30
+ data: any;
31
+ error: null;
32
+ isError: false;
33
+ isPending: false;
34
+ isLoading: false;
35
+ isLoadingError: false;
36
+ isRefetchError: false;
37
+ isSuccess: true;
38
+ isPlaceholderData: false;
39
+ status: "success";
40
+ dataUpdatedAt: number;
41
+ errorUpdatedAt: number;
42
+ failureCount: number;
43
+ failureReason: Error | null;
44
+ errorUpdateCount: number;
45
+ isFetched: boolean;
46
+ isFetchedAfterMount: boolean;
47
+ isFetching: boolean;
48
+ isInitialLoading: boolean;
49
+ isPaused: boolean;
50
+ isRefetching: boolean;
51
+ isStale: boolean;
52
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
53
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
54
+ promise: Promise<any>;
55
+ } | {
56
+ updateData: (updateFn: any) => void;
57
+ data: undefined;
58
+ error: Error;
59
+ isError: true;
60
+ isPending: false;
61
+ isLoading: false;
62
+ isLoadingError: true;
63
+ isRefetchError: false;
64
+ isSuccess: false;
65
+ isPlaceholderData: false;
66
+ status: "error";
67
+ dataUpdatedAt: number;
68
+ errorUpdatedAt: number;
69
+ failureCount: number;
70
+ failureReason: Error | null;
71
+ errorUpdateCount: number;
72
+ isFetched: boolean;
73
+ isFetchedAfterMount: boolean;
74
+ isFetching: boolean;
75
+ isInitialLoading: boolean;
76
+ isPaused: boolean;
77
+ isRefetching: boolean;
78
+ isStale: boolean;
79
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
80
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
81
+ promise: Promise<any>;
82
+ } | {
83
+ updateData: (updateFn: any) => void;
84
+ data: undefined;
85
+ error: null;
86
+ isError: false;
87
+ isPending: true;
88
+ isLoading: true;
89
+ isLoadingError: false;
90
+ isRefetchError: false;
91
+ isSuccess: false;
92
+ isPlaceholderData: false;
93
+ status: "pending";
94
+ dataUpdatedAt: number;
95
+ errorUpdatedAt: number;
96
+ failureCount: number;
97
+ failureReason: Error | null;
98
+ errorUpdateCount: number;
99
+ isFetched: boolean;
100
+ isFetchedAfterMount: boolean;
101
+ isFetching: boolean;
102
+ isInitialLoading: boolean;
103
+ isPaused: boolean;
104
+ isRefetching: boolean;
105
+ isStale: boolean;
106
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
107
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
108
+ promise: Promise<any>;
109
+ } | {
110
+ updateData: (updateFn: any) => void;
111
+ data: undefined;
112
+ error: null;
113
+ isError: false;
114
+ isPending: true;
115
+ isLoadingError: false;
116
+ isRefetchError: false;
117
+ isSuccess: false;
118
+ isPlaceholderData: false;
119
+ status: "pending";
120
+ dataUpdatedAt: number;
121
+ errorUpdatedAt: number;
122
+ failureCount: number;
123
+ failureReason: Error | null;
124
+ errorUpdateCount: number;
125
+ isFetched: boolean;
126
+ isFetchedAfterMount: boolean;
127
+ isFetching: boolean;
128
+ isLoading: boolean;
129
+ isInitialLoading: boolean;
130
+ isPaused: boolean;
131
+ isRefetching: boolean;
132
+ isStale: boolean;
133
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
134
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
135
+ promise: Promise<any>;
136
+ } | {
137
+ updateData: (updateFn: any) => void;
138
+ data: any;
139
+ isError: false;
140
+ error: null;
141
+ isPending: false;
142
+ isLoading: false;
143
+ isLoadingError: false;
144
+ isRefetchError: false;
145
+ isSuccess: true;
146
+ isPlaceholderData: true;
147
+ status: "success";
148
+ dataUpdatedAt: number;
149
+ errorUpdatedAt: number;
150
+ failureCount: number;
151
+ failureReason: Error | null;
152
+ errorUpdateCount: number;
153
+ isFetched: boolean;
154
+ isFetchedAfterMount: boolean;
155
+ isFetching: boolean;
156
+ isInitialLoading: boolean;
157
+ isPaused: boolean;
158
+ isRefetching: boolean;
159
+ isStale: boolean;
160
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
161
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
162
+ promise: Promise<any>;
163
+ };
164
+ export function useApiQuerySilence(key: any, api: any, params: {} | undefined, returnFn: any): {
165
+ updateData: (updateFn: any) => void;
166
+ data: any;
167
+ error: Error;
168
+ isError: true;
169
+ isPending: false;
170
+ isLoading: false;
171
+ isLoadingError: false;
172
+ isRefetchError: true;
173
+ isSuccess: false;
174
+ isPlaceholderData: false;
175
+ status: "error";
176
+ dataUpdatedAt: number;
177
+ errorUpdatedAt: number;
178
+ failureCount: number;
179
+ failureReason: Error | null;
180
+ errorUpdateCount: number;
181
+ isFetched: boolean;
182
+ isFetchedAfterMount: boolean;
183
+ isFetching: boolean;
184
+ isInitialLoading: boolean;
185
+ isPaused: boolean;
186
+ isRefetching: boolean;
187
+ isStale: boolean;
188
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
189
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
190
+ promise: Promise<any>;
191
+ } | {
192
+ updateData: (updateFn: any) => void;
193
+ data: any;
194
+ error: null;
195
+ isError: false;
196
+ isPending: false;
197
+ isLoading: false;
198
+ isLoadingError: false;
199
+ isRefetchError: false;
200
+ isSuccess: true;
201
+ isPlaceholderData: false;
202
+ status: "success";
203
+ dataUpdatedAt: number;
204
+ errorUpdatedAt: number;
205
+ failureCount: number;
206
+ failureReason: Error | null;
207
+ errorUpdateCount: number;
208
+ isFetched: boolean;
209
+ isFetchedAfterMount: boolean;
210
+ isFetching: boolean;
211
+ isInitialLoading: boolean;
212
+ isPaused: boolean;
213
+ isRefetching: boolean;
214
+ isStale: boolean;
215
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
216
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
217
+ promise: Promise<any>;
218
+ } | {
219
+ updateData: (updateFn: any) => void;
220
+ data: undefined;
221
+ error: Error;
222
+ isError: true;
223
+ isPending: false;
224
+ isLoading: false;
225
+ isLoadingError: true;
226
+ isRefetchError: false;
227
+ isSuccess: false;
228
+ isPlaceholderData: false;
229
+ status: "error";
230
+ dataUpdatedAt: number;
231
+ errorUpdatedAt: number;
232
+ failureCount: number;
233
+ failureReason: Error | null;
234
+ errorUpdateCount: number;
235
+ isFetched: boolean;
236
+ isFetchedAfterMount: boolean;
237
+ isFetching: boolean;
238
+ isInitialLoading: boolean;
239
+ isPaused: boolean;
240
+ isRefetching: boolean;
241
+ isStale: boolean;
242
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
243
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
244
+ promise: Promise<any>;
245
+ } | {
246
+ updateData: (updateFn: any) => void;
247
+ data: undefined;
248
+ error: null;
249
+ isError: false;
250
+ isPending: true;
251
+ isLoading: true;
252
+ isLoadingError: false;
253
+ isRefetchError: false;
254
+ isSuccess: false;
255
+ isPlaceholderData: false;
256
+ status: "pending";
257
+ dataUpdatedAt: number;
258
+ errorUpdatedAt: number;
259
+ failureCount: number;
260
+ failureReason: Error | null;
261
+ errorUpdateCount: number;
262
+ isFetched: boolean;
263
+ isFetchedAfterMount: boolean;
264
+ isFetching: boolean;
265
+ isInitialLoading: boolean;
266
+ isPaused: boolean;
267
+ isRefetching: boolean;
268
+ isStale: boolean;
269
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
270
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
271
+ promise: Promise<any>;
272
+ } | {
273
+ updateData: (updateFn: any) => void;
274
+ data: undefined;
275
+ error: null;
276
+ isError: false;
277
+ isPending: true;
278
+ isLoadingError: false;
279
+ isRefetchError: false;
280
+ isSuccess: false;
281
+ isPlaceholderData: false;
282
+ status: "pending";
283
+ dataUpdatedAt: number;
284
+ errorUpdatedAt: number;
285
+ failureCount: number;
286
+ failureReason: Error | null;
287
+ errorUpdateCount: number;
288
+ isFetched: boolean;
289
+ isFetchedAfterMount: boolean;
290
+ isFetching: boolean;
291
+ isLoading: boolean;
292
+ isInitialLoading: boolean;
293
+ isPaused: boolean;
294
+ isRefetching: boolean;
295
+ isStale: boolean;
296
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
297
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
298
+ promise: Promise<any>;
299
+ } | {
300
+ updateData: (updateFn: any) => void;
301
+ data: any;
302
+ isError: false;
303
+ error: null;
304
+ isPending: false;
305
+ isLoading: false;
306
+ isLoadingError: false;
307
+ isRefetchError: false;
308
+ isSuccess: true;
309
+ isPlaceholderData: true;
310
+ status: "success";
311
+ dataUpdatedAt: number;
312
+ errorUpdatedAt: number;
313
+ failureCount: number;
314
+ failureReason: Error | null;
315
+ errorUpdateCount: number;
316
+ isFetched: boolean;
317
+ isFetchedAfterMount: boolean;
318
+ isFetching: boolean;
319
+ isInitialLoading: boolean;
320
+ isPaused: boolean;
321
+ isRefetching: boolean;
322
+ isStale: boolean;
323
+ refetch: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<any, Error>>;
324
+ fetchStatus: import("@tanstack/react-query").FetchStatus;
325
+ promise: Promise<any>;
326
+ };
327
+ export function useStaticQuery(key: any, staticData: any): import("@tanstack/react-query").DefinedUseQueryResult<any, Error>;
@@ -0,0 +1,39 @@
1
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
2
+ import useData from '.';
3
+ export const useApiQuery = (key, api, params = {}, returnFn, ui = true) => {
4
+ const { fetchData, fetchDataUIAsync } = useData();
5
+ const queryClient = useQueryClient();
6
+ return {
7
+ ...useQuery({
8
+ queryKey: [key], // Přidáváme params do queryKey
9
+ queryFn: async () => {
10
+ const response = ui
11
+ ? await fetchDataUIAsync(api, params)
12
+ : await fetchData(api, params);
13
+ if (returnFn) {
14
+ return returnFn(response.data);
15
+ }
16
+ return response.data;
17
+ },
18
+ }),
19
+ // Funkce pro manuální aktualizaci dat
20
+ updateData: (updateFn) => {
21
+ queryClient.setQueryData([key], (oldData) => {
22
+ // Aktualizace queryKey i zde
23
+ if (!oldData)
24
+ return oldData;
25
+ return updateFn(oldData);
26
+ });
27
+ },
28
+ };
29
+ };
30
+ export const useApiQuerySilence = (key, api, params = {}, returnFn) => useApiQuery(key, api, params, returnFn, false);
31
+ export const useStaticQuery = (key, staticData) => {
32
+ return useQuery({
33
+ queryKey: [key],
34
+ queryFn: () => Promise.resolve(staticData),
35
+ initialData: staticData,
36
+ staleTime: Infinity,
37
+ });
38
+ };
39
+ //# sourceMappingURL=reactQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactQuery.js","sourceRoot":"","sources":["../reactQuery.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,OAAO,MAAM,GAAG,CAAC;AAExB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE;IACxE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,OAAO,EAAE,CAAC;IAClD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,OAAO;QACL,GAAG,QAAQ,CAAC;YACV,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,+BAA+B;YAChD,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,QAAQ,GAAG,EAAE;oBACjB,CAAC,CAAC,MAAM,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC;oBACrC,CAAC,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBAEjC,IAAI,QAAQ,EAAE,CAAC;oBACb,OAAO,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBACjC,CAAC;gBAED,OAAO,QAAQ,CAAC,IAAI,CAAC;YACvB,CAAC;SACF,CAAC;QACF,sCAAsC;QACtC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;YACvB,WAAW,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE;gBAC1C,6BAA6B;gBAC7B,IAAI,CAAC,OAAO;oBAAE,OAAO,OAAO,CAAC;gBAC7B,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC3B,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,EAAE,EAAE,CAClE,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE;IAChD,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,GAAG,CAAC;QACf,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;QAC1C,WAAW,EAAE,UAAU;QACvB,SAAS,EAAE,QAAQ;KACpB,CAAC,CAAC;AACL,CAAC,CAAC"}
package/index.js CHANGED
@@ -56,12 +56,11 @@ export default function useData() {
56
56
  tempLink.download = fileName;
57
57
  tempLink.click();
58
58
  }
59
-
59
+
60
60
  return {
61
61
  fetchData,
62
62
  fetchDataUIAsync,
63
63
  getFileURL,
64
64
  downloadFileURL
65
65
  }
66
- }
67
-
66
+ }
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@bit.rhplus/data",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "homepage": "https://bit.cloud/remote-scope/data",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "remote-scope",
8
8
  "name": "data",
9
- "version": "0.0.6"
9
+ "version": "0.0.8"
10
10
  },
11
11
  "dependencies": {
12
+ "@tanstack/react-query": "^5.66.9",
12
13
  "@rhplus/wieldy.api": "0.0.10"
13
14
  },
14
15
  "devDependencies": {
package/reactQuery.js ADDED
@@ -0,0 +1,44 @@
1
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
2
+ import useData from '.';
3
+
4
+ export const useApiQuery = (key, api, params = {}, returnFn, ui = true) => {
5
+ const { fetchData, fetchDataUIAsync } = useData();
6
+ const queryClient = useQueryClient();
7
+
8
+ return {
9
+ ...useQuery({
10
+ queryKey: [key], // Přidáváme params do queryKey
11
+ queryFn: async () => {
12
+ const response = ui
13
+ ? await fetchDataUIAsync(api, params)
14
+ : await fetchData(api, params);
15
+
16
+ if (returnFn) {
17
+ return returnFn(response.data);
18
+ }
19
+
20
+ return response.data;
21
+ },
22
+ }),
23
+ // Funkce pro manuální aktualizaci dat
24
+ updateData: (updateFn) => {
25
+ queryClient.setQueryData([key], (oldData) => {
26
+ // Aktualizace queryKey i zde
27
+ if (!oldData) return oldData;
28
+ return updateFn(oldData);
29
+ });
30
+ },
31
+ };
32
+ };
33
+
34
+ export const useApiQuerySilence = (key, api, params = {}, returnFn) =>
35
+ useApiQuery(key, api, params, returnFn, false);
36
+
37
+ export const useStaticQuery = (key, staticData) => {
38
+ return useQuery({
39
+ queryKey: [key],
40
+ queryFn: () => Promise.resolve(staticData),
41
+ initialData: staticData,
42
+ staleTime: Infinity,
43
+ });
44
+ };