refactor(lib): remove keys and just get a slug from the label

This commit is contained in:
Lewis Wynne 2026-03-23 17:02:46 +00:00
parent 7dc4bd8a11
commit 456e7e8feb
5 changed files with 26 additions and 30 deletions

View file

@ -1,5 +1,6 @@
import { z } from 'zod';
import type { FieldDef, Template } from './types';
import { slugify } from './utils/slugify';
function zodForField(field: FieldDef): z.ZodTypeAny {
switch (field.type) {
@ -29,7 +30,7 @@ export function buildCharacterSchema(template: Template): z.ZodObject<Record<str
const shape: Record<string, z.ZodTypeAny> = {};
for (const record of template.records) {
for (const field of record.fields) {
shape[field.key] = zodForField(field);
shape[slugify(field.label)] = zodForField(field);
}
}
return z.object(shape).partial();