@hortiview/modulebase 0.0.12119 → 0.0.12550
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/QueryClientProvider-Q_mWQTzQ.js +435 -0
- package/dist/{_baseGet-Bh5zJ_C8.js → _baseGet-B7FwMMGI.js} +9 -9
- package/dist/api-D9Lmqe6S.js +458 -0
- package/dist/components/ModuleBase.js +127 -312
- package/dist/hooks/useCustom.d.ts +2 -1
- package/dist/hooks/useCustom.js +15 -13
- package/dist/hooks/useCustomMutation.d.ts +8 -0
- package/dist/hooks/useCustomMutation.js +21 -0
- package/dist/hooks/useEntity.d.ts +3 -9
- package/dist/hooks/useEntity.js +36 -30
- package/dist/hooks/useOption.d.ts +1 -1
- package/dist/hooks/useOption.js +20 -18
- package/dist/hooks/useServiceBus.d.ts +15 -0
- package/dist/hooks/useServiceBus.js +17 -0
- package/dist/hooks/useStores.d.ts +2 -1
- package/dist/hooks/useStores.js +11 -841
- package/dist/main.d.ts +3 -0
- package/dist/main.js +121 -115
- package/dist/mutation-X73nm7Df.js +192 -0
- package/dist/omit-B7MWDtHq.js +835 -0
- package/dist/query-CRIVoEP7.js +277 -0
- package/dist/types/BaseProps.d.ts +3 -0
- package/dist/types/ModuleApi.d.ts +77 -4
- package/dist/types/Requests.d.ts +2 -1
- package/dist/types/ServiceBus.d.ts +17 -0
- package/dist/types/ServiceBus.js +1 -0
- package/dist/useMutation-3rykrmeD.js +97 -0
- package/dist/{useQuery-znAyMQW1.js → useQuery-CwwWze9O.js} +96 -98
- package/dist/utils/api.d.ts +20 -0
- package/dist/utils/api.js +9 -0
- package/dist/utils/baseFetches.d.ts +19 -0
- package/dist/utils/baseFetches.js +19 -0
- package/dist/utils/fetches.d.ts +31 -22
- package/dist/utils/fetches.js +19 -14
- package/dist/utils-DxRR_XLb.js +9 -0
- package/package.json +2 -2
- package/dist/QueryClientProvider-DQv4Y3Qu.js +0 -707
- package/dist/fetches-DUCQo_6B.js +0 -477
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { S as N,
|
|
1
|
+
import { S as N, x as U, b as f, f as w, q as O, a as H, y as Q, z as M, t as V, o as z, r as k, n as A, u as W } from "./QueryClientProvider-Q_mWQTzQ.js";
|
|
2
|
+
import { f as $ } from "./query-CRIVoEP7.js";
|
|
2
3
|
import * as p from "react";
|
|
3
4
|
import "react/jsx-runtime";
|
|
4
|
-
|
|
5
|
+
import { s as K, n as _ } from "./utils-DxRR_XLb.js";
|
|
6
|
+
var G = class extends N {
|
|
5
7
|
constructor(e, t) {
|
|
6
8
|
super(), this.options = t, this.#s = e, this.#r = null, this.#i = U(), this.options.experimental_prefetchInRender || this.#i.reject(
|
|
7
9
|
new Error("experimental_prefetchInRender feature flag is not enabled")
|
|
@@ -15,20 +17,20 @@ var $ = class extends N {
|
|
|
15
17
|
#c;
|
|
16
18
|
#i;
|
|
17
19
|
#r;
|
|
18
|
-
#
|
|
20
|
+
#y;
|
|
19
21
|
#l;
|
|
20
22
|
// This property keeps track of the last query with defined data.
|
|
21
23
|
// It will be used to pass the previous data and query to the placeholder function between renders.
|
|
22
24
|
#d;
|
|
23
|
-
#h;
|
|
24
25
|
#o;
|
|
26
|
+
#h;
|
|
25
27
|
#n;
|
|
26
28
|
#f = /* @__PURE__ */ new Set();
|
|
27
29
|
bindMethods() {
|
|
28
30
|
this.refetch = this.refetch.bind(this);
|
|
29
31
|
}
|
|
30
32
|
onSubscribe() {
|
|
31
|
-
this.listeners.size === 1 && (this.#e.addObserver(this),
|
|
33
|
+
this.listeners.size === 1 && (this.#e.addObserver(this), q(this.#e, this.options) ? this.#u() : this.updateResult(), this.#R());
|
|
32
34
|
}
|
|
33
35
|
onUnsubscribe() {
|
|
34
36
|
this.hasListeners() || this.destroy();
|
|
@@ -67,13 +69,13 @@ var $ = class extends N {
|
|
|
67
69
|
r,
|
|
68
70
|
this.options,
|
|
69
71
|
s
|
|
70
|
-
) && this.#u(), this.updateResult(t), a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || O(this.options.staleTime, this.#e) !== O(s.staleTime, this.#e)) && this.#
|
|
71
|
-
const u = this.#
|
|
72
|
+
) && this.#u(), this.updateResult(t), a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || O(this.options.staleTime, this.#e) !== O(s.staleTime, this.#e)) && this.#b();
|
|
73
|
+
const u = this.#m();
|
|
72
74
|
a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || u !== this.#n) && this.#g(u);
|
|
73
75
|
}
|
|
74
76
|
getOptimisticResult(e) {
|
|
75
77
|
const t = this.#s.getQueryCache().build(this.#s, e), s = this.createResult(t, e);
|
|
76
|
-
return
|
|
78
|
+
return X(this, s) && (this.#t = s, this.#c = this.options, this.#a = this.#e.state), s;
|
|
77
79
|
}
|
|
78
80
|
getCurrentResult() {
|
|
79
81
|
return this.#t;
|
|
@@ -115,9 +117,9 @@ var $ = class extends N {
|
|
|
115
117
|
this.options,
|
|
116
118
|
e
|
|
117
119
|
);
|
|
118
|
-
return e?.throwOnError || (t = t.catch(
|
|
120
|
+
return e?.throwOnError || (t = t.catch(H)), t;
|
|
119
121
|
}
|
|
120
|
-
#
|
|
122
|
+
#b() {
|
|
121
123
|
this.#v();
|
|
122
124
|
const e = O(
|
|
123
125
|
this.options.staleTime,
|
|
@@ -126,77 +128,77 @@ var $ = class extends N {
|
|
|
126
128
|
if (Q || this.#t.isStale || !M(e))
|
|
127
129
|
return;
|
|
128
130
|
const s = V(this.#t.dataUpdatedAt, e) + 1;
|
|
129
|
-
this.#
|
|
131
|
+
this.#o = setTimeout(() => {
|
|
130
132
|
this.#t.isStale || this.updateResult();
|
|
131
133
|
}, s);
|
|
132
134
|
}
|
|
133
|
-
#
|
|
135
|
+
#m() {
|
|
134
136
|
return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.#e) : this.options.refetchInterval) ?? !1;
|
|
135
137
|
}
|
|
136
138
|
#g(e) {
|
|
137
|
-
this.#O(), this.#n = e, !(Q || f(this.options.enabled, this.#e) === !1 || !M(this.#n) || this.#n === 0) && (this.#
|
|
138
|
-
(this.options.refetchIntervalInBackground ||
|
|
139
|
+
this.#O(), this.#n = e, !(Q || f(this.options.enabled, this.#e) === !1 || !M(this.#n) || this.#n === 0) && (this.#h = setInterval(() => {
|
|
140
|
+
(this.options.refetchIntervalInBackground || z.isFocused()) && this.#u();
|
|
139
141
|
}, this.#n));
|
|
140
142
|
}
|
|
141
|
-
#
|
|
142
|
-
this.#
|
|
143
|
+
#R() {
|
|
144
|
+
this.#b(), this.#g(this.#m());
|
|
143
145
|
}
|
|
144
146
|
#v() {
|
|
145
|
-
this.#
|
|
147
|
+
this.#o && (clearTimeout(this.#o), this.#o = void 0);
|
|
146
148
|
}
|
|
147
149
|
#O() {
|
|
148
|
-
this.#
|
|
150
|
+
this.#h && (clearInterval(this.#h), this.#h = void 0);
|
|
149
151
|
}
|
|
150
152
|
createResult(e, t) {
|
|
151
|
-
const s = this.#e, r = this.options, a = this.#t, u = this.#a, i = this.#c,
|
|
152
|
-
let n = { ...c },
|
|
153
|
+
const s = this.#e, r = this.options, a = this.#t, u = this.#a, i = this.#c, o = e !== s ? e.state : this.#p, { state: c } = e;
|
|
154
|
+
let n = { ...c }, R = !1, l;
|
|
153
155
|
if (t._optimisticResults) {
|
|
154
|
-
const
|
|
155
|
-
(
|
|
156
|
+
const h = this.hasListeners(), b = !h && q(e, t), m = h && L(e, s, t, r);
|
|
157
|
+
(b || m) && (n = {
|
|
156
158
|
...n,
|
|
157
|
-
|
|
159
|
+
...$(c.data, e.options)
|
|
158
160
|
}), t._optimisticResults === "isRestoring" && (n.fetchStatus = "idle");
|
|
159
161
|
}
|
|
160
|
-
let { error: x, errorUpdatedAt: F, status:
|
|
162
|
+
let { error: x, errorUpdatedAt: F, status: y } = n;
|
|
161
163
|
if (t.select && n.data !== void 0)
|
|
162
|
-
if (a && n.data === u?.data && t.select === this.#
|
|
164
|
+
if (a && n.data === u?.data && t.select === this.#y)
|
|
163
165
|
l = this.#l;
|
|
164
166
|
else
|
|
165
167
|
try {
|
|
166
|
-
this.#
|
|
167
|
-
} catch (
|
|
168
|
-
this.#r =
|
|
168
|
+
this.#y = t.select, l = t.select(n.data), l = k(a?.data, l, t), this.#l = l, this.#r = null;
|
|
169
|
+
} catch (h) {
|
|
170
|
+
this.#r = h;
|
|
169
171
|
}
|
|
170
172
|
else
|
|
171
173
|
l = n.data;
|
|
172
|
-
if (t.placeholderData !== void 0 && l === void 0 &&
|
|
173
|
-
let
|
|
174
|
+
if (t.placeholderData !== void 0 && l === void 0 && y === "pending") {
|
|
175
|
+
let h;
|
|
174
176
|
if (a?.isPlaceholderData && t.placeholderData === i?.placeholderData)
|
|
175
|
-
|
|
176
|
-
else if (
|
|
177
|
+
h = a.data;
|
|
178
|
+
else if (h = typeof t.placeholderData == "function" ? t.placeholderData(
|
|
177
179
|
this.#d?.state.data,
|
|
178
180
|
this.#d
|
|
179
|
-
) : t.placeholderData, t.select &&
|
|
181
|
+
) : t.placeholderData, t.select && h !== void 0)
|
|
180
182
|
try {
|
|
181
|
-
|
|
182
|
-
} catch (
|
|
183
|
-
this.#r =
|
|
183
|
+
h = t.select(h), this.#r = null;
|
|
184
|
+
} catch (b) {
|
|
185
|
+
this.#r = b;
|
|
184
186
|
}
|
|
185
|
-
|
|
187
|
+
h !== void 0 && (y = "success", l = k(
|
|
186
188
|
a?.data,
|
|
187
|
-
|
|
189
|
+
h,
|
|
188
190
|
t
|
|
189
|
-
),
|
|
191
|
+
), R = !0);
|
|
190
192
|
}
|
|
191
|
-
this.#r && (x = this.#r, l = this.#l, F = Date.now(),
|
|
192
|
-
const C = n.fetchStatus === "fetching", S =
|
|
193
|
-
status:
|
|
193
|
+
this.#r && (x = this.#r, l = this.#l, F = Date.now(), y = "error");
|
|
194
|
+
const C = n.fetchStatus === "fetching", S = y === "pending", E = y === "error", D = S && C, P = l !== void 0, d = {
|
|
195
|
+
status: y,
|
|
194
196
|
fetchStatus: n.fetchStatus,
|
|
195
197
|
isPending: S,
|
|
196
|
-
isSuccess:
|
|
198
|
+
isSuccess: y === "success",
|
|
197
199
|
isError: E,
|
|
198
|
-
isInitialLoading:
|
|
199
|
-
isLoading:
|
|
200
|
+
isInitialLoading: D,
|
|
201
|
+
isLoading: D,
|
|
200
202
|
data: l,
|
|
201
203
|
dataUpdatedAt: n.dataUpdatedAt,
|
|
202
204
|
error: x,
|
|
@@ -205,33 +207,33 @@ var $ = class extends N {
|
|
|
205
207
|
failureReason: n.fetchFailureReason,
|
|
206
208
|
errorUpdateCount: n.errorUpdateCount,
|
|
207
209
|
isFetched: n.dataUpdateCount > 0 || n.errorUpdateCount > 0,
|
|
208
|
-
isFetchedAfterMount: n.dataUpdateCount >
|
|
210
|
+
isFetchedAfterMount: n.dataUpdateCount > o.dataUpdateCount || n.errorUpdateCount > o.errorUpdateCount,
|
|
209
211
|
isFetching: C,
|
|
210
212
|
isRefetching: C && !S,
|
|
211
|
-
isLoadingError: E && !
|
|
213
|
+
isLoadingError: E && !P,
|
|
212
214
|
isPaused: n.fetchStatus === "paused",
|
|
213
|
-
isPlaceholderData:
|
|
214
|
-
isRefetchError: E &&
|
|
215
|
+
isPlaceholderData: R,
|
|
216
|
+
isRefetchError: E && P,
|
|
215
217
|
isStale: I(e, t),
|
|
216
218
|
refetch: this.refetch,
|
|
217
219
|
promise: this.#i
|
|
218
220
|
};
|
|
219
221
|
if (this.options.experimental_prefetchInRender) {
|
|
220
|
-
const
|
|
222
|
+
const h = (v) => {
|
|
221
223
|
d.status === "error" ? v.reject(d.error) : d.data !== void 0 && v.resolve(d.data);
|
|
222
|
-
},
|
|
224
|
+
}, b = () => {
|
|
223
225
|
const v = this.#i = d.promise = U();
|
|
224
|
-
|
|
225
|
-
},
|
|
226
|
-
switch (
|
|
226
|
+
h(v);
|
|
227
|
+
}, m = this.#i;
|
|
228
|
+
switch (m.status) {
|
|
227
229
|
case "pending":
|
|
228
|
-
e.queryHash === s.queryHash &&
|
|
230
|
+
e.queryHash === s.queryHash && h(m);
|
|
229
231
|
break;
|
|
230
232
|
case "fulfilled":
|
|
231
|
-
(d.status === "error" || d.data !==
|
|
233
|
+
(d.status === "error" || d.data !== m.value) && b();
|
|
232
234
|
break;
|
|
233
235
|
case "rejected":
|
|
234
|
-
(d.status !== "error" || d.error !==
|
|
236
|
+
(d.status !== "error" || d.error !== m.reason) && b();
|
|
235
237
|
break;
|
|
236
238
|
}
|
|
237
239
|
}
|
|
@@ -251,8 +253,8 @@ var $ = class extends N {
|
|
|
251
253
|
const g = new Set(
|
|
252
254
|
i ?? this.#f
|
|
253
255
|
);
|
|
254
|
-
return this.options.throwOnError && g.add("error"), Object.keys(this.#t).some((
|
|
255
|
-
const c =
|
|
256
|
+
return this.options.throwOnError && g.add("error"), Object.keys(this.#t).some((o) => {
|
|
257
|
+
const c = o;
|
|
256
258
|
return this.#t[c] !== t[c] && g.has(c);
|
|
257
259
|
});
|
|
258
260
|
};
|
|
@@ -266,10 +268,10 @@ var $ = class extends N {
|
|
|
266
268
|
this.#e = e, this.#p = e.state, this.hasListeners() && (t?.removeObserver(this), e.addObserver(this));
|
|
267
269
|
}
|
|
268
270
|
onQueryUpdate() {
|
|
269
|
-
this.updateResult(), this.hasListeners() && this.#
|
|
271
|
+
this.updateResult(), this.hasListeners() && this.#R();
|
|
270
272
|
}
|
|
271
273
|
#S(e) {
|
|
272
|
-
|
|
274
|
+
A.batch(() => {
|
|
273
275
|
e.listeners && this.listeners.forEach((t) => {
|
|
274
276
|
t(this.#t);
|
|
275
277
|
}), this.#s.getQueryCache().notify({
|
|
@@ -279,11 +281,11 @@ var $ = class extends N {
|
|
|
279
281
|
});
|
|
280
282
|
}
|
|
281
283
|
};
|
|
282
|
-
function
|
|
284
|
+
function J(e, t) {
|
|
283
285
|
return f(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && t.retryOnMount === !1);
|
|
284
286
|
}
|
|
285
|
-
function
|
|
286
|
-
return
|
|
287
|
+
function q(e, t) {
|
|
288
|
+
return J(e, t) || e.state.data !== void 0 && T(e, t, t.refetchOnMount);
|
|
287
289
|
}
|
|
288
290
|
function T(e, t, s) {
|
|
289
291
|
if (f(t.enabled, e) !== !1) {
|
|
@@ -298,12 +300,12 @@ function L(e, t, s, r) {
|
|
|
298
300
|
function I(e, t) {
|
|
299
301
|
return f(t.enabled, e) !== !1 && e.isStaleByTime(O(t.staleTime, e));
|
|
300
302
|
}
|
|
301
|
-
function
|
|
303
|
+
function X(e, t) {
|
|
302
304
|
return !w(e.getCurrentResult(), t);
|
|
303
305
|
}
|
|
304
|
-
var
|
|
305
|
-
|
|
306
|
-
function
|
|
306
|
+
var B = p.createContext(!1), Y = () => p.useContext(B);
|
|
307
|
+
B.Provider;
|
|
308
|
+
function Z() {
|
|
307
309
|
let e = !1;
|
|
308
310
|
return {
|
|
309
311
|
clearReset: () => {
|
|
@@ -315,13 +317,7 @@ function Y() {
|
|
|
315
317
|
isReset: () => e
|
|
316
318
|
};
|
|
317
319
|
}
|
|
318
|
-
var
|
|
319
|
-
function te(e, t) {
|
|
320
|
-
return typeof e == "function" ? e(...t) : !!e;
|
|
321
|
-
}
|
|
322
|
-
function j() {
|
|
323
|
-
}
|
|
324
|
-
var se = (e, t) => {
|
|
320
|
+
var ee = p.createContext(Z()), te = () => p.useContext(ee), se = (e, t) => {
|
|
325
321
|
(e.suspense || e.throwOnError || e.experimental_prefetchInRender) && (t.isReset() || (e.retryOnMount = !1));
|
|
326
322
|
}, re = (e) => {
|
|
327
323
|
p.useEffect(() => {
|
|
@@ -333,41 +329,43 @@ var se = (e, t) => {
|
|
|
333
329
|
throwOnError: s,
|
|
334
330
|
query: r,
|
|
335
331
|
suspense: a
|
|
336
|
-
}) => e.isError && !t.isReset() && !e.isFetching && r && (a && e.data === void 0 ||
|
|
332
|
+
}) => e.isError && !t.isReset() && !e.isFetching && r && (a && e.data === void 0 || K(s, [e.error, r])), ne = (e) => {
|
|
337
333
|
const t = e.staleTime;
|
|
338
334
|
e.suspense && (e.staleTime = typeof t == "function" ? (...s) => Math.max(t(...s), 1e3) : Math.max(t ?? 1e3, 1e3), typeof e.gcTime == "number" && (e.gcTime = Math.max(e.gcTime, 1e3)));
|
|
339
|
-
}, ae = (e, t) => e.isLoading && e.isFetching && !t,
|
|
335
|
+
}, ae = (e, t) => e.isLoading && e.isFetching && !t, oe = (e, t) => e?.suspense && t.isPending, j = (e, t, s) => t.fetchOptimistic(e).catch(() => {
|
|
340
336
|
s.clearReset();
|
|
341
337
|
});
|
|
342
|
-
function
|
|
338
|
+
function he(e, t, s) {
|
|
343
339
|
if (process.env.NODE_ENV !== "production" && (typeof e != "object" || Array.isArray(e)))
|
|
344
340
|
throw new Error(
|
|
345
341
|
'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
|
|
346
342
|
);
|
|
347
|
-
const r =
|
|
343
|
+
const r = W(), a = Y(), u = te(), i = r.defaultQueryOptions(e);
|
|
348
344
|
r.getDefaultOptions().queries?._experimental_beforeQuery?.(
|
|
349
345
|
i
|
|
350
|
-
),
|
|
351
|
-
|
|
346
|
+
), process.env.NODE_ENV !== "production" && (i.queryFn || console.error(
|
|
347
|
+
`[${i.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`
|
|
348
|
+
)), i._optimisticResults = a ? "isRestoring" : "optimistic", ne(i), se(i, u), re(u);
|
|
349
|
+
const g = !r.getQueryCache().get(i.queryHash), [o] = p.useState(
|
|
352
350
|
() => new t(
|
|
353
351
|
r,
|
|
354
352
|
i
|
|
355
353
|
)
|
|
356
|
-
), c =
|
|
354
|
+
), c = o.getOptimisticResult(i), n = !a && e.subscribed !== !1;
|
|
357
355
|
if (p.useSyncExternalStore(
|
|
358
356
|
p.useCallback(
|
|
359
|
-
(
|
|
360
|
-
const l = n ?
|
|
361
|
-
return
|
|
357
|
+
(R) => {
|
|
358
|
+
const l = n ? o.subscribe(A.batchCalls(R)) : _;
|
|
359
|
+
return o.updateResult(), l;
|
|
362
360
|
},
|
|
363
|
-
[
|
|
361
|
+
[o, n]
|
|
364
362
|
),
|
|
365
|
-
() =>
|
|
366
|
-
() =>
|
|
363
|
+
() => o.getCurrentResult(),
|
|
364
|
+
() => o.getCurrentResult()
|
|
367
365
|
), p.useEffect(() => {
|
|
368
|
-
|
|
369
|
-
}, [i,
|
|
370
|
-
throw
|
|
366
|
+
o.setOptions(i, { listeners: !1 });
|
|
367
|
+
}, [i, o]), oe(i, c))
|
|
368
|
+
throw j(i, o, u);
|
|
371
369
|
if (ie({
|
|
372
370
|
result: c,
|
|
373
371
|
errorResetBoundary: u,
|
|
@@ -381,17 +379,17 @@ function oe(e, t, s) {
|
|
|
381
379
|
c
|
|
382
380
|
), i.experimental_prefetchInRender && !Q && ae(c, a) && (g ? (
|
|
383
381
|
// Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
|
|
384
|
-
|
|
382
|
+
j(i, o, u)
|
|
385
383
|
) : (
|
|
386
384
|
// subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
|
|
387
385
|
r.getQueryCache().get(i.queryHash)?.promise
|
|
388
|
-
))?.catch(
|
|
389
|
-
|
|
390
|
-
}), i.notifyOnChangeProps ? c :
|
|
386
|
+
))?.catch(_).finally(() => {
|
|
387
|
+
o.updateResult();
|
|
388
|
+
}), i.notifyOnChangeProps ? c : o.trackResult(c);
|
|
391
389
|
}
|
|
392
|
-
function
|
|
393
|
-
return
|
|
390
|
+
function pe(e, t) {
|
|
391
|
+
return he(e, G);
|
|
394
392
|
}
|
|
395
393
|
export {
|
|
396
|
-
|
|
394
|
+
pe as u
|
|
397
395
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseResponse, httpMethod, Query, RequestConfig } from '../types/Requests';
|
|
2
|
+
export declare const getConfig: (token: string, organizationId?: string, languageId?: string, method?: httpMethod, customHeaders?: Headers) => RequestConfig;
|
|
3
|
+
/**
|
|
4
|
+
* a fetch function to handle requests and returns the response. if the response is unauthorized, it tries to refresh the token and retries the request
|
|
5
|
+
* @param url - the complete url build by {@link prependBaseUrl}
|
|
6
|
+
* @param config - the request config including auth headers
|
|
7
|
+
* @param throwFullMessage - if the full error message should be thrown or only the message behind the status code
|
|
8
|
+
* @param withResponseHandling - if the response should be handled by the {@link handleResponse} method or not ("hide" the error)
|
|
9
|
+
* @param tries - the number of retries, default is 1
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const fetchWithErrorHandling: <T>(url: string, config: RequestConfig, tries?: number, withResponseHandling?: boolean) => Promise<BaseResponse<T>>;
|
|
13
|
+
export declare const handleResponse: (response: Response) => Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* a helper function to format the query string
|
|
16
|
+
* @param query - the query object to format
|
|
17
|
+
* @param withApiVersion - if the api version should be added to the query string
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare const formatQuery: (query?: Query, withApiVersion?: boolean) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseResponse, httpMethod, Query } from '../types/Requests';
|
|
2
|
+
/**
|
|
3
|
+
* a fetch function to handle CUD requests and returns the response.
|
|
4
|
+
* @param url endpoint to fetch (CUD) data from
|
|
5
|
+
* @param data data to send
|
|
6
|
+
* @param method method to use (POST, PUT, DELETE, PATCH)
|
|
7
|
+
* @param customToken token to use (default is the modulePermissionToken)
|
|
8
|
+
* @param headers (optional) custom headers to use
|
|
9
|
+
* @returns Promise<BaseResponse<R>> response from the fetch
|
|
10
|
+
*/
|
|
11
|
+
export declare const baseMutation: <T, R>(url: string, data: T, method: Omit<httpMethod, "GET">, customToken?: string, headers?: Headers) => Promise<BaseResponse<R>>;
|
|
12
|
+
/**
|
|
13
|
+
* a fetch function to handle GET requests and returns the response.
|
|
14
|
+
* @param url url to GET data from
|
|
15
|
+
* @param query query to use for the GET request
|
|
16
|
+
* @param customToken token to use (default is the modulePermissionToken)
|
|
17
|
+
* @returns Promise<BaseResponse<T>> response from the fetch
|
|
18
|
+
*/
|
|
19
|
+
export declare const baseFetch: <T>(url: string, query: Query, customToken?: string) => Promise<BaseResponse<T>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { a as d, f, i as m, b as S } from "../api-D9Lmqe6S.js";
|
|
2
|
+
import { useBasePropsStore as t } from "../stores/BasePropsStore.js";
|
|
3
|
+
const k = (n, o, a, e, s) => {
|
|
4
|
+
const r = e ?? t.getState().modulePermissionToken, g = t.getState().organizationId, i = t.getState().currentLanguageId, c = t.getState().throwError;
|
|
5
|
+
if (!r)
|
|
6
|
+
return c?.("No token found", 404), Promise.reject();
|
|
7
|
+
const u = d(r, g, i, a, s);
|
|
8
|
+
return u.body = JSON.stringify(o), f(n, u);
|
|
9
|
+
}, E = (n, o, a) => {
|
|
10
|
+
const e = a ?? t.getState().modulePermissionToken, s = t.getState().organizationId, r = t.getState().currentLanguageId, g = t.getState().throwError;
|
|
11
|
+
if (!e)
|
|
12
|
+
return g?.("No token found", 404), Promise.reject();
|
|
13
|
+
const i = d(e, s, r), c = m(o) ? "" : S(o);
|
|
14
|
+
return f(`${n}${c}`, i);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
E as baseFetch,
|
|
18
|
+
k as baseMutation
|
|
19
|
+
};
|
package/dist/utils/fetches.d.ts
CHANGED
|
@@ -1,26 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const getModuleDependedEntities: <T>(moduleId: string, entityId: string) => Promise<BaseResponse<T>>;
|
|
4
|
-
export declare const fetchFromCustomApi: <T>(endpoint: string, token?: string) => Promise<BaseResponse<T>>;
|
|
5
|
-
export declare const fetchFromModuleApi: <T>(endpoint: string) => Promise<BaseResponse<T>>;
|
|
6
|
-
export declare const fetchFromCommonApi: <T>(endpoint: string) => Promise<BaseResponse<T>>;
|
|
7
|
-
export declare const baseFetch: <T>(url: string, query: Query, customToken?: string) => Promise<BaseResponse<T>>;
|
|
8
|
-
export declare const getConfig: (token: string, organizationId?: string, languageId?: string, method?: "GET" | "POST" | "PATCH" | "DELETE" | "PUT") => RequestConfig;
|
|
1
|
+
import { httpMethod } from '../types/Requests';
|
|
2
|
+
export declare const mutateOnCustomApi: <T, R>(endpoint: string, data: T, method?: Omit<httpMethod, "GET">, token?: string, headers?: Headers) => Promise<import('../types/Requests').BaseResponse<R>>;
|
|
9
3
|
/**
|
|
10
|
-
* a fetch function to
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @
|
|
14
|
-
* @param withResponseHandling - if the response should be handled by the {@link handleResponse} method or not ("hide" the error)
|
|
15
|
-
* @param tries - the number of retries, default is 1
|
|
16
|
-
* @returns
|
|
4
|
+
* a fetch function to get a certain farmorganization entity from the moduleApi (will be used in useEntity)
|
|
5
|
+
* @param moduleId moduleID to get the entity from
|
|
6
|
+
* @param entityId entityID of the entity to get
|
|
7
|
+
* @returns entity to get
|
|
17
8
|
*/
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const handleResponse: (response: Response) => Promise<any>;
|
|
9
|
+
export declare const getFarmOrgEntities: <T>(moduleId: string, entityId: string) => Promise<import('../types/Requests').BaseResponse<T>>;
|
|
20
10
|
/**
|
|
21
|
-
* a
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @returns
|
|
11
|
+
* a fetch function to get a certain MODULEDEPENDED entity from the moduleApi (will be used in useEntity)
|
|
12
|
+
* @param moduleId moduleID to get the entity from
|
|
13
|
+
* @param entityId entityID of the entity to get
|
|
14
|
+
* @returns entity to get
|
|
25
15
|
*/
|
|
26
|
-
export declare const
|
|
16
|
+
export declare const getModuleDependedEntities: <T>(moduleId: string, entityId: string) => Promise<import('../types/Requests').BaseResponse<T>>;
|
|
17
|
+
/**
|
|
18
|
+
* a fetch function to handle GET requests and returns the response.
|
|
19
|
+
* @param endpoint custom endpoint to GET data from
|
|
20
|
+
* @param token token to use (default is the modulePermissionToken)
|
|
21
|
+
* @returns Promise<BaseResponse<T>> response from the fetch
|
|
22
|
+
*/
|
|
23
|
+
export declare const fetchFromCustomApi: <T>(endpoint: string, token?: string) => Promise<import('../types/Requests').BaseResponse<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* a fetch function to handle GET requests and returns the response.
|
|
26
|
+
* @param endpoint endpoint of moduleApi to fetch data from
|
|
27
|
+
* @returns Promise<BaseResponse<T>> response from the fetch
|
|
28
|
+
*/
|
|
29
|
+
export declare const fetchFromModuleApi: <T>(endpoint: string) => Promise<import('../types/Requests').BaseResponse<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* a fetch function to handle GET requests and returns the response.
|
|
32
|
+
* @param endpoint endpoint of commonApi to fetch data from
|
|
33
|
+
* @returns Promise<BaseResponse<T>> response from the fetch
|
|
34
|
+
*/
|
|
35
|
+
export declare const fetchFromCommonApi: <T>(endpoint: string) => Promise<import('../types/Requests').BaseResponse<T>>;
|
package/dist/utils/fetches.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../
|
|
3
|
-
import "
|
|
4
|
-
|
|
1
|
+
import { useBasePropsStore as u } from "../stores/BasePropsStore.js";
|
|
2
|
+
import { useEnvironmentStore as r } from "../stores/EnvironmentStore.js";
|
|
3
|
+
import { baseMutation as c, baseFetch as o } from "./baseFetches.js";
|
|
4
|
+
const g = (e, t, n = "POST", m, s) => c(e, t, n, m, s), A = (e, t) => i(`getAllFarmOrgEntities/${e}/${t}`), d = (e, t) => i(`ModuleDependedEntities/${e}/${t}`), E = (e, t) => o(`${e}`, {}, t), i = (e) => {
|
|
5
|
+
const t = r.getState().environment, n = u.getState().organizationId;
|
|
6
|
+
return o(
|
|
7
|
+
`${t?.MODULE_AUTH_API}${t?.API_PREFIX}/${n}/${e}`,
|
|
8
|
+
{}
|
|
9
|
+
);
|
|
10
|
+
}, F = (e) => {
|
|
11
|
+
const t = r.getState().environment;
|
|
12
|
+
return o(`${t?.COMMON_API}${t?.API_PREFIX}/${e}`, {});
|
|
13
|
+
};
|
|
5
14
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
h as getConfig,
|
|
13
|
-
d as getFarmOrgEntities,
|
|
14
|
-
g as getModuleDependedEntities,
|
|
15
|
-
c as handleResponse
|
|
15
|
+
F as fetchFromCommonApi,
|
|
16
|
+
E as fetchFromCustomApi,
|
|
17
|
+
i as fetchFromModuleApi,
|
|
18
|
+
A as getFarmOrgEntities,
|
|
19
|
+
d as getModuleDependedEntities,
|
|
20
|
+
g as mutateOnCustomApi
|
|
16
21
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hortiview/modulebase",
|
|
3
3
|
"description": "This is a base module for hortiview",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12550",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Falk Menge <falk.menge.ext@bayer.com>",
|
|
7
7
|
"contributors": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@microsoft/signalr": "^8.0.7",
|
|
27
|
-
"@tanstack/react-query": "^5.
|
|
27
|
+
"@tanstack/react-query": "^5.67.3",
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"odata-query": "^7.0.9",
|
|
30
30
|
"react": "^18.3.1",
|