synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
105 lines (104 loc) • 3.37 kB
JavaScript
import { AdditionalPropertiesSchemaField as o } from "./field/AdditionalPropertiesSchemaField.js";
import { englishStringTranslator as u, TranslatableString as a } from "@rjsf/utils";
import { JSONPath as l } from "jsonpath-plus";
import { isObject as p, groupBy as c, flatMap as f, isEmpty as h } from "lodash-es";
function j(e = {}, t = {}) {
const r = g(t);
return {
$schema: "http://json-schema.org/draft-07/schema#",
// Spread the validation schema to ensure all other references are included
// Top level properties like "$defs" get lost if we simply put the entire schema in `allOf`
...e,
// JSON Schemas for Synapse types use "definitions", so it should be manually merged.
definitions: {
...t.definitions,
...e.definitions
},
allOf: [
...e.allOf || [],
// Add in the entity properties
{
type: "object",
properties: r
}
],
// Always allow adding additional annotations (though it may violate the validationSchema)
additionalProperties: !0
};
}
function E(e = {}) {
return {
...Object.keys(
e
).reduce((r, s) => ({ ...r, [s]: { "ui:widget": "hidden" } }), {}),
"ui:globalOptions": {
copyable: !1,
// copy button clutters the UI, is not very useful since schemas are flat objects
duplicateKeySuffixSeparator: "_"
// the default duplicateKeySuffixSeparator creates invalid annotation keys
},
additionalProperties: {
"ui:field": o
}
};
}
function P(e) {
const t = {};
return Object.keys(e).forEach((r) => {
let s = e[r];
Array.isArray(s) ? (s = s.filter((i) => i != null), h(s) || (t[r] = s)) : t[r] = s;
}), t;
}
function A(e = {}) {
return Object.keys(e).reduce(
(t, r) => (e[r] !== null && (t[r] = e[r]), t),
{}
);
}
function S(e) {
return e.property?.startsWith("[") ? e.property.substring(2, e.property.length - 2) : e.property?.startsWith(".") ? e.property.substring(1) : e.property || "";
}
function w(e) {
const t = c(e, (r) => r.property);
return Object.keys(t).map((r) => {
const s = t[r];
s.some(
(n) => n.message === "should match some schema in anyOf"
) && s.every((n) => n.message === "should be string" || n.message === "should be equal to constant" ? !0 : n.message === "should match some schema in anyOf") && s.length > 0 && (s[0].message = "should be equal to one of the allowed values", t[r] = [s[0]]);
}), e = f(t), e;
}
function F(e) {
return Array.isArray(e) ? e : [e];
}
function N(e, t) {
return !!(e && Object.keys(e).length > 0 && t);
}
function g(e) {
const t = {}, r = l({
path: "$..properties",
json: e
});
for (const s of r)
Object.assign(t, s);
return p(e.properties) && Object.assign(t, e.properties), t;
}
function W(e) {
return !e || !e.startsWith("org.sagebionetworks") ? null : "org.sagebionetworks-" + e.substring(20);
}
function k(e, t) {
return e === a.NewStringDefault ? "" : u(e, t);
}
export {
F as convertToArray,
k as customTranslateString,
A as dropNullValues,
P as dropNullishArrayValues,
S as getFriendlyPropertyName,
j as getJsonSchemaForForm,
g as getPossibleTopLevelPropertiesInObjectSchema,
W as getSchemaIdForConcreteType,
E as getUiSchemaForForm,
N as shouldLiveValidate,
w as transformErrors
};
//# sourceMappingURL=AnnotationEditorUtils.js.map