synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
77 lines (76 loc) • 1.75 kB
JavaScript
import { hasSchema as u } from "@hyperjump/json-schema";
import { registerSchema as s } from "@hyperjump/json-schema/draft-07";
import * as o from "@hyperjump/json-schema/annotated-instance/experimental";
import { annotate as c } from "@hyperjump/json-schema/annotations/experimental";
import { useQuery as f } from "@tanstack/react-query";
import { useState as p, useEffect as d } from "react";
function i(e, t, r) {
if (t) {
for (const [
n,
a
] of o.entries(t))
if (o.value(n) === e)
return o.annotation(
a,
r
)[0];
}
}
function N(e, t) {
if (t) {
const r = i(
e,
t,
"title"
);
if (r)
return r;
}
return e;
}
function R(e, t) {
if (t)
return i(e, t, "description");
}
function l(e) {
const [t, r] = p(!1);
return d(() => {
if (e && e.$id)
if (u(e.$id))
r(!0);
else
try {
s(e), r(!0);
} catch (n) {
console.error(
"Unable to register JSON Schema in @hyperjump/json-schema:",
n
);
}
}, [e]), t;
}
function v(e, t) {
const r = l(t);
return f({
queryKey: ["getAnnotatedInstance", { json: e, schema: t, schemaIsRegistered: r }],
queryFn: () => {
if (e && t && r)
try {
return c(t.$id, e);
} catch (n) {
console.error("Could not create annotated schema instance:", n);
}
return null;
},
enabled: !!(t && e)
});
}
export {
R as getDisplayedAnnotationDescription,
N as getDisplayedAnnotationTitle,
i as getSchemaAnnotationForProperty,
v as useGetAnnotatedJsonInstance,
l as useRegisterSchema
};
//# sourceMappingURL=SchemaAnnotationUtils.js.map