@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
59 lines (58 loc) • 1.75 kB
JavaScript
import { z as e } from "zod";
import { buildCommonSchema as o, jsonSchema as m, optionSchema as c } from "../validation.js";
const f = (a) => e.object({
data: e.object({
// *can* be empty if an itemsExpression is set, it's only added back at runtime in
// the backend
values: c(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: m.optional(),
service: e.string().optional(),
code: e.string().optional()
})
}).superRefine((s, r) => {
var i, d, u;
if (((i = s == null ? void 0 : s.openForms) == null ? void 0 : i.dataSrc) === "manual" && (((d = s == null ? void 0 : s.data) == null ? void 0 : d.values) ?? []).length < 1)
r.addIssue({
code: e.ZodIssueCode.too_small,
path: ["data", "values"],
minimum: 1,
inclusive: !0,
type: "number"
});
else if (((u = s == null ? void 0 : s.openForms) == null ? void 0 : u.dataSrc) === "referenceLists") {
const {
service: l,
code: t
} = s.openForms;
l || r.addIssue({
code: e.ZodIssueCode.custom,
path: ["openForms", "service"],
message: a.formatMessage({
id: "7HlMn7",
defaultMessage: [{
type: 0,
value: "You must select a service."
}]
})
}), t || r.addIssue({
code: e.ZodIssueCode.custom,
path: ["openForms", "code"],
message: a.formatMessage({
id: "i/P7yw",
defaultMessage: [{
type: 0,
value: "You must select a table."
}]
})
});
}
}), h = ({
intl: a
}) => o(a).and(f(a));
export {
h as default
};