synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
352 lines (351 loc) • 8.26 kB
JavaScript
import * as y from "../../synapse-client/SynapseClient.js";
import { allowNotFoundError as Q } from "../../synapse-client/SynapseClientUtils.js";
import "@sage-bionetworks/synapse-types";
import { entityJsonKeys as k } from "../../utils/functions/EntityTypeUtils.js";
import "../../utils/SynapseConstants.js";
import { createTableUpdateTransactionRequest as S } from "../../utils/functions/TableColumnSchemaUtils.js";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import { useSynapseContext as o } from "../../utils/context/SynapseContext.js";
import { useQueryClient as a, useMutation as E, useQuery as f, queryOptions as g, skipToken as q, useSuspenseQuery as K, useInfiniteQuery as C, useQueries as T } from "@tanstack/react-query";
import { pick as p, omit as w } from "lodash-es";
import { useMemo as A } from "react";
import { getNextPageParamForPaginatedResults as P } from "../InfiniteQueryUtils.js";
import { invalidateAllQueriesForEntity as l } from "../QueryFilterUtils.js";
import { useGetEntityBundleSuspenseQueryOptions as G } from "./useEntityBundle.js";
function L() {
const { keyFactory: e, accessToken: n } = o();
return (s, r) => g({
queryKey: e.getEntityVersionQueryKey(s, r),
queryFn: s ? () => y.getEntity(
n,
s,
r?.toString()
) : q
});
}
function X(e, n, s) {
const r = L();
return f({
...s,
...r(e, n)
});
}
function Y(e, n) {
const { accessToken: s, keyFactory: r } = o(), t = A(
() => ({
queries: e.map((c) => ({
queryKey: r.getEntityVersionQueryKey(
c.id,
c.versionNumber
),
queryFn: () => y.getEntity(
s,
c.id,
c.versionNumber
),
options: n
}))
}),
[s, e, r, n]
);
return T(t);
}
function Z(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
mutationFn: (t) => y.createEntity(t, s),
onSuccess: async (t, c, u) => {
const i = r.getEntityQueryKey(t.id);
n.setQueryData(i, t), n.setQueryData(
r.getEntityLookupQueryKey({
parentId: t.parentId,
entityName: t.name
}),
t.id
), await l(
n,
r,
t.id,
i
), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function _(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: (t) => y.updateEntity(t, s),
onSuccess: async (t, c, u) => {
const i = r.getEntityQueryKey(t.id);
n.setQueryData(i, t), await l(
n,
r,
t.id,
i
), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function $(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: async (t) => {
const c = await y.getEntity(
s,
t
);
return await y.deleteEntity(s, t), c.parentId;
},
onSuccess: async (t, c, u) => {
await l(n, r, c), t && await l(n, r, t), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function H(e, n = 0, s = 200, r) {
const { accessToken: t, keyFactory: c } = o();
return f({
...r,
queryKey: c.getPaginatedEntityVersionsQueryKey(
e,
s,
n
),
queryFn: () => y.getEntityVersions(e, t, n, s)
});
}
function I(e, n) {
const { accessToken: r, keyFactory: t } = o();
return C({
...n,
queryKey: t.getEntityVersionsQueryKey(e),
queryFn: async (c) => await y.getEntityVersions(
e,
r,
c.pageParam,
200
),
initialPageParam: void 0,
getNextPageParam: P
});
}
function V(e) {
return p(e, k[e.concreteType]);
}
function d(e) {
return w(e, k[e.concreteType]);
}
function j(e, n, s, r) {
const { accessToken: t, keyFactory: c } = o();
return f({
...r,
queryKey: c.getEntityJsonQueryKey(
e,
n,
s
),
queryFn: () => y.getEntityJson(
e,
n,
s,
t
),
select: (u) => {
const i = V(u), m = d(u);
return {
entity: u,
entityMetadata: i,
annotations: m
};
}
});
}
function ee(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: (t) => {
const c = t.id;
return y.updateEntityJson(c, t, s);
},
onSuccess: async (t, c, u) => {
const i = t.id, m = r.getEntityJsonQueryKey(
i,
void 0,
!1
);
n.setQueryData(m, t), await l(
n,
r,
i,
m
), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function te(e, n) {
const { accessToken: s, keyFactory: r } = o();
return f({
...n,
queryKey: r.getEntityPathQueryKey(e),
queryFn: () => y.getEntityPath(e, s)
});
}
function ne(e, n) {
const { accessToken: s, keyFactory: r } = o();
return f({
...n,
queryKey: r.getEntityPathQueryKey(e),
queryFn: () => y.getEntityACL(e, s)
});
}
function se(e, n) {
const { accessToken: s, keyFactory: r } = o();
return f({
...n,
queryKey: r.getEntityAliasQueryKey(e),
queryFn: () => y.getEntityAlias(e, s)
});
}
function re(e, n, s) {
const { accessToken: r, keyFactory: t } = o();
return f({
...s,
queryKey: t.getEntityEvaluationsQueryKey(e),
queryFn: () => y.getAllEntityEvaluations(e, n, r)
});
}
function ce(e, n) {
const { accessToken: s, keyFactory: r } = o();
return f({
...n,
queryKey: r.getEntityPermissionsQueryKey(e),
queryFn: () => y.getEntityPermissions(e, s)
});
}
const F = async (e, n, s, r) => {
const t = r.getEntityACLQueryKey(e);
n && s.setQueryData(t, n), await l(
s,
r,
e,
t
);
};
function ue(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: (t) => y.createEntityACL(t, s),
onSuccess: async (t, c, u) => {
await F(
t.id,
t,
n,
r
), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function ye(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: (t) => y.updateEntityACL(t, s),
onSuccess: async (t, c, u) => {
await F(
t.id,
t,
n,
r
), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function oe(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: (t) => y.deleteEntityACL(t, s),
onSuccess: async (t, c, u) => {
await F(c, null, n, r), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function D(e) {
return G(
e,
void 0,
{
includeBenefactorACL: !0
},
(s) => s.benefactorAcl
);
}
function ie(e, n) {
const s = D(e);
return K({
...n,
...s
});
}
function ae(e) {
const n = a(), { accessToken: s, keyFactory: r } = o();
return E({
...e,
mutationFn: async (t) => {
const c = await S(
s,
t.entityId,
t.originalColumnModels,
t.newColumnModels
);
return y.updateTable(c, s);
},
onSuccess: async (t, c, u) => {
await l(
n,
r,
c.entityId
), e?.onSuccess && await e.onSuccess(t, c, u);
}
});
}
function Ee() {
const { keyFactory: e, synapseClient: n } = o();
return (s) => g({
queryKey: e.getEntityLookupQueryKey(s),
queryFn: async () => (await Q(
() => n.entityServicesClient.postRepoV1EntityChild({
entityLookupRequest: s
})
))?.id ?? null
});
}
export {
V as getStandardEntityFields,
d as removeStandardEntityFields,
Z as useCreateEntity,
ue as useCreateEntityACL,
$ as useDeleteEntity,
oe as useDeleteEntityACL,
Y as useGetEntities,
X as useGetEntity,
ne as useGetEntityACL,
se as useGetEntityAlias,
re as useGetEntityEvaluations,
Ee as useGetEntityLookupQueryOptions,
te as useGetEntityPath,
ce as useGetEntityPermissions,
L as useGetEntityQueryOptions,
j as useGetJson,
H as useGetVersions,
I as useGetVersionsInfinite,
ie as useSuspenseGetEntityBenefactorACL,
_ as useUpdateEntity,
ye as useUpdateEntityACL,
ae as useUpdateTableColumns,
ee as useUpdateViaJson
};
//# sourceMappingURL=useEntity.js.map