feat(07-01): extend buildZodSchema() to chain .regex() from field.validate

- Replace simple ternary assignment with let schema pattern
- Chain (schema as z.ZodString).regex() when field.validate is present
- Handle optional fields: z.string() first, then .regex() if needed, then .optional()
- VALID-01 tests all pass (GREEN): azureblob account, s3 region, gcs project_number
This commit is contained in:
2026-03-31 09:50:02 +02:00
parent 3dea5c8561
commit c6d38fa0f1
+12 -2
View File
@@ -10,9 +10,19 @@ function buildZodSchema(backendType: BackendType): z.ZodObject<Record<string, z.
const fields = BACKEND_REGISTRY[backendType].fields; const fields = BACKEND_REGISTRY[backendType].fields;
const shape: Record<string, z.ZodTypeAny> = {}; const shape: Record<string, z.ZodTypeAny> = {};
for (const field of fields) { for (const field of fields) {
shape[field.key] = field.required let schema: z.ZodTypeAny = field.required
? z.string().min(1, `${field.label} is required`) ? z.string().min(1, `${field.label} is required`)
: z.string().optional(); : z.string();
if (field.validate) {
schema = (schema as z.ZodString).regex(field.validate.regex, field.validate.message);
}
if (!field.required) {
schema = (schema as z.ZodString).optional();
}
shape[field.key] = schema;
} }
return z.object(shape); return z.object(shape);
} }