// src/schemas/index.ts // Zod schemas derived programmatically from the Backend Schema Registry. // DO NOT hand-write z.object() calls with hardcoded field names — all shapes come from the registry. // Adding a field to BACKEND_REGISTRY automatically adds it to validation. // BACKEND_SCHEMAS is auto-generated from registry keys — no manual per-backend calls needed. import { z } from 'zod'; import { BACKEND_REGISTRY, BackendType } from './registry'; function buildZodSchema(backendType: BackendType): z.ZodObject> { const fields = BACKEND_REGISTRY[backendType].fields; const shape: Record = {}; for (const field of fields) { let schema: z.ZodTypeAny = field.required ? z.string().min(1, `${field.label} is required`) : z.string(); if ('validate' in field && 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); } // Auto-generated from registry keys — expands automatically when BACKEND_REGISTRY grows. // No manual buildZodSchema() call needed per new backend. export const BACKEND_SCHEMAS = Object.fromEntries( (Object.keys(BACKEND_REGISTRY) as BackendType[]).map(t => [t, buildZodSchema(t)]) ) as Record>;