synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
95 lines (94 loc) • 3.21 kB
JavaScript
import { ColumnTypeEnum as r } from "@sage-bionetworks/synapse-types";
import { canHaveSize as S, canHaveMaxListLength as h, MAX_LIST_LENGTH as d, MAX_STRING_SIZE as g } from "../TableColumnSchemaEditorUtils.js";
import { z as e } from "zod";
import { getDefaultValueValidator as V } from "./DefaultValueValidator.js";
import y from "./EnumValuesValidator.js";
import { optionalStringSchema as m } from "./OptionalStringSchema.js";
import { omit as l } from "lodash-es";
const i = e.union([e.literal("enumeration"), e.literal("range")]), b = e.object({
property: e.enum(["FREQUENCY", "VALUE"]).optional(),
direction: e.enum(["DESC", "ASC"]).optional()
}), s = e.object({
name: e.string().min(1, { message: "Name is required" }),
columnType: e.nativeEnum(r)
}), c = s.merge(
e.object({
jsonPath: e.string().startsWith("$"),
facetType: i
})
), f = s.merge(
e.object({
id: e.string().optional(),
defaultValue: e.union([e.string(), e.array(e.any())]).optional(),
maximumSize: e.union([m, e.number()]).pipe(
e.coerce.number().finite().int().min(1).max(g).optional()
),
maximumListLength: e.union([m, e.number()]).pipe(
e.coerce.number().finite().int().min(1).max(d).optional()
),
enumValues: e.array(
e.union([
e.string(),
// enumValues is allowed on INTEGER type, but the backend stores them as strings, so allow passing integers
e.number().int()
]).pipe(e.coerce.string())
).optional(),
jsonSubColumns: e.array(c).optional(),
facetType: i.optional(),
facetSortConfig: b.optional()
})
), C = f.refine((n) => n.maximumSize == null || S(n.columnType), {
message: "Size is not allowed for this column type",
path: ["maximumSize"]
}).refine(
(n) => n.maximumListLength == null || h(n.columnType),
{
message: "Maximum list length is not allowed for this column type",
path: ["maximumListLength"]
}
).refine(
(n) => n.jsonSubColumns != null ? n.columnType === r.JSON : !0,
{
message: "Only JSON columns can have JSON sub-columns.",
path: ["columnType"]
}
).transform((n, t) => {
if (n.defaultValue != null) {
const o = V(n.columnType).safeParse(n.defaultValue);
let a;
return o.success ? a = o.data : (o.error.issues.forEach((u) => {
t.addIssue({ ...u, path: ["defaultValue"] });
}), a = void 0), { ...n, defaultValue: a };
}
return l(n, "defaultValue");
}).transform((n, t) => {
if (n.enumValues != null) {
const o = y(n.columnType).safeParse(n.enumValues);
let a;
return o.success ? a = o.data : (o.error.issues.forEach((u) => {
t.addIssue({ ...u, path: ["enumValues"] });
}), a = void 0), { ...n, enumValues: a };
}
return l(n, "enumValues");
}), T = e.array(C), j = c.merge(
e.object({
isSelected: e.boolean()
})
);
f.merge(
e.object({
isSelected: e.boolean(),
isOriginallyDefaultColumn: e.boolean(),
jsonSubColumns: e.array(j).optional()
})
);
function D(n) {
return T.safeParse(n);
}
export {
T as columnModelFormDataZodSchema,
C as columnModelZodSchema,
c as jsonSubColumnModelZodSchema,
D as validateColumnModelFormData
};
//# sourceMappingURL=ColumnModelValidator.js.map