import { z } from 'zod';
function parseFieldDefault(key, definition) {
    if (definition.default === undefined) {
        return undefined;
    }
    const parsed = definition.schema.safeParse(definition.default);
    if (!parsed.success) {
        throw new Error(`Invalid default for session authoring field "${key}"`);
    }
    return parsed.data;
}
export function buildSessionAuthoringFieldArtifacts(definitions) {
    const shape = {};
    const defaults = {};
    for (const key of Object.keys(definitions)) {
        const definition = definitions[key];
        shape[key] = definition.schema;
        const parsedDefault = parseFieldDefault(String(key), definition);
        if (parsedDefault !== undefined) {
            defaults[key] = parsedDefault;
        }
    }
    return {
        definitions,
        shape,
        valueSchema: z.object(shape).strict(),
        defaults,
    };
}
//# sourceMappingURL=buildFieldArtifacts.js.map