From c6d38fa0f197486476d5f00d814b3702470ae443 Mon Sep 17 00:00:00 2001 From: Kawa Date: Tue, 31 Mar 2026 09:50:02 +0200 Subject: [PATCH] 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 --- src/schemas/index.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/schemas/index.ts b/src/schemas/index.ts index 8bcdb3b..94817ce 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -10,9 +10,19 @@ function buildZodSchema(backendType: BackendType): z.ZodObject = {}; 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().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); }