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:
+12
-2
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user