153 lines
3.8 KiB
JavaScript
153 lines
3.8 KiB
JavaScript
import { a as w, f as $ } from "./chunks/BiProvider-B7XtDeW9.js";
|
|
import { A as z, B as I, C as M, K as x, P as J, b as V, c as W, d as X, e as Y, g as Z, h as _, i as D, j as N, k as ee, l as ne, m as te, n as se, o as re, p as ie, q as oe, s as ue, u as ce, r as ae } from "./chunks/BiProvider-B7XtDeW9.js";
|
|
import { useQueryClient as v, useMutation as Q, useQuery as k } from "@tanstack/react-query";
|
|
import { usePermission as fe } from "./core-runtime.js";
|
|
function g(e) {
|
|
return Array.isArray(e) ? e : [e];
|
|
}
|
|
function U(e) {
|
|
return [...g(e), "list"];
|
|
}
|
|
function A(e, n) {
|
|
return [...g(e), n];
|
|
}
|
|
function j(e, n) {
|
|
if (!n) return e;
|
|
const y = new URLSearchParams();
|
|
Object.entries(n).forEach(([m, f]) => {
|
|
f != null && f !== "" && y.append(m, f);
|
|
});
|
|
const d = y.toString();
|
|
return d ? `${e}?${d}` : e;
|
|
}
|
|
function S(e, n) {
|
|
return typeof e == "function" ? e(n == null ? void 0 : n.id, n) : e;
|
|
}
|
|
function B(e = {}) {
|
|
const { id: n, ...y } = e;
|
|
return y;
|
|
}
|
|
function E(e, n) {
|
|
return `${e.replace(/\/$/, "")}/${n}`;
|
|
}
|
|
function F(e) {
|
|
return `use${e.charAt(0).toUpperCase()}${e.slice(1)}`;
|
|
}
|
|
function G(e, n) {
|
|
return typeof e == "function" ? e(n) : e;
|
|
}
|
|
function H({
|
|
key: e,
|
|
url: n,
|
|
actions: y = {},
|
|
axiosInstance: d = w,
|
|
fetcher: m = $
|
|
}) {
|
|
const f = g(e), P = U(e);
|
|
function q(t, s = {}) {
|
|
return k({
|
|
queryKey: t ? [...P, t] : P,
|
|
queryFn: () => m(j(n, t)),
|
|
...s
|
|
});
|
|
}
|
|
function C(t, s = {}) {
|
|
return k({
|
|
queryKey: A(e, t),
|
|
queryFn: () => m(E(n, t)),
|
|
enabled: !!t,
|
|
...s
|
|
});
|
|
}
|
|
function p(t, s = {}) {
|
|
const K = v(), r = y[t];
|
|
if (!r)
|
|
throw new Error(`Action "${t}" is not defined.`);
|
|
return Q({
|
|
mutationKey: [...f, t],
|
|
mutationFn: async (o = {}) => {
|
|
const u = r.method || "post", c = S(r.url || n, o), a = G(r.requestConfig, o), i = r.body ? r.body(o) : r.sendRawPayload ? o : B(o);
|
|
let l;
|
|
if (u === "get")
|
|
l = await d.get(
|
|
c,
|
|
a ? {
|
|
...i,
|
|
...a
|
|
} : i
|
|
);
|
|
else if (u === "delete") {
|
|
const h = i && Object.keys(i).length > 0;
|
|
l = await d.delete(
|
|
c,
|
|
a || h ? {
|
|
...a || {},
|
|
...h ? { data: i } : {}
|
|
} : void 0
|
|
);
|
|
} else
|
|
l = await d[u](
|
|
c,
|
|
i,
|
|
a
|
|
);
|
|
return l.data;
|
|
},
|
|
onSuccess: (...o) => {
|
|
var l;
|
|
const [u, c] = o;
|
|
K.invalidateQueries({
|
|
queryKey: P
|
|
});
|
|
const a = (c == null ? void 0 : c.id) ?? (u == null ? void 0 : u.id);
|
|
a && K.invalidateQueries({
|
|
queryKey: A(e, a)
|
|
});
|
|
const i = typeof r.invalidateKeys == "function" ? r.invalidateKeys(u, c) : r.invalidateKeys;
|
|
i == null || i.forEach((h) => {
|
|
K.invalidateQueries({ queryKey: h });
|
|
}), (l = s.onSuccess) == null || l.call(s, ...o);
|
|
},
|
|
...s
|
|
});
|
|
}
|
|
const b = Object.keys(y).reduce((t, s) => (t[F(s)] = (K = {}) => p(s, K), t), {});
|
|
return {
|
|
key: f,
|
|
listKey: P,
|
|
useGet: q,
|
|
useItem: C,
|
|
useAction: p,
|
|
...b
|
|
};
|
|
}
|
|
export {
|
|
z as AdminGuard,
|
|
I as BiProvider,
|
|
M as Can,
|
|
x as KeycloakProvider,
|
|
J as PanelAccessGuard,
|
|
V as PermissionProvider,
|
|
w as api,
|
|
W as checkPermission,
|
|
X as clearCachedPermissions,
|
|
Y as configureApi,
|
|
H as createApi,
|
|
Z as createPermissionSet,
|
|
$ as fetcher,
|
|
_ as getApi,
|
|
D as getCachedPermissions,
|
|
N as getKeycloakToken,
|
|
ee as getPermissions,
|
|
ne as initKeycloak,
|
|
te as isKeycloakAuthenticated,
|
|
se as isKeycloakInitialized,
|
|
re as loginKeycloak,
|
|
ie as logoutKeycloak,
|
|
oe as permissionKeys,
|
|
ue as setCachedPermissions,
|
|
ce as updateKeycloakToken,
|
|
fe as usePermission,
|
|
ae as usePermissionsQuery
|
|
};
|