@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
59 lines (58 loc) • 1.74 kB
JavaScript
import { z as e } from "zod";
import { buildCommonSchema as o, jsonSchema as d, optionSchema as m } from "../validation.js";
const c = (a) => e.object({
values: m(a).array().optional(),
openForms: e.object({
dataSrc: e.union([e.literal("manual"), e.literal("variable"), e.literal("referenceLists")]),
// TODO: wire up infernologic type checking
itemsExpression: d.optional(),
service: e.string().optional(),
code: e.string().optional()
}),
validate: e.object({
minSelectedCount: e.null().or(e.number().int().gte(0)).optional(),
maxSelectedCount: e.null().or(e.number().int().gte(0)).optional()
})
}).superRefine((s, r) => {
var i, l;
if (((i = s == null ? void 0 : s.openForms) == null ? void 0 : i.dataSrc) === "manual" && ((s == null ? void 0 : s.values) ?? []).length < 1)
r.addIssue({
code: e.ZodIssueCode.too_small,
path: ["values"],
minimum: 1,
inclusive: !0,
type: "number"
});
else if (((l = s == null ? void 0 : s.openForms) == null ? void 0 : l.dataSrc) === "referenceLists") {
const {
service: t,
code: u
} = s.openForms;
t || r.addIssue({
code: e.ZodIssueCode.custom,
path: ["openForms", "service"],
message: a.formatMessage({
id: "7HlMn7",
defaultMessage: [{
type: 0,
value: "You must select a service."
}]
})
}), u || r.addIssue({
code: e.ZodIssueCode.custom,
path: ["openForms", "code"],
message: a.formatMessage({
id: "i/P7yw",
defaultMessage: [{
type: 0,
value: "You must select a table."
}]
})
});
}
}), g = ({
intl: a
}) => o(a).and(c(a));
export {
g as default
};