diff --git a/src/schemas/index.ts b/src/schemas/index.ts new file mode 100644 index 0000000..ac35398 --- /dev/null +++ b/src/schemas/index.ts @@ -0,0 +1,28 @@ +// 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. + +import { z } from 'zod'; +import { BACKEND_REGISTRY, BackendType } from './registry'; + +function buildZodSchema(backendType: BackendType): z.ZodObject> { + const fields = BACKEND_REGISTRY[backendType]; + const shape: Record = {}; + for (const field of fields) { + shape[field.key] = field.required + ? z.string().min(1, `${field.label} is required`) + : z.string().optional(); + } + return z.object(shape); +} + +export const BACKEND_SCHEMAS = { + azureblob: buildZodSchema('azureblob'), + s3: buildZodSchema('s3'), + 's3-compatible': buildZodSchema('s3-compatible'), +} as const; + +// Utility type: infer TypeScript type from a backend's Zod schema +export type BackendFormValues = + z.infer;