- Add placeholder property to TextFieldMD3 component and props interface - Fix vite.config.ts to import defineConfig from vitest/config instead of vite - Add type guard for validate property in schemas/index.ts to handle readonly array union types - Remove unused StepIndicatorWithDispatch placeholder function from tests Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
// 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<Record<string, z.ZodTypeAny>> {
|
|
const fields = BACKEND_REGISTRY[backendType].fields;
|
|
const shape: Record<string, z.ZodTypeAny> = {};
|
|
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<BackendType, ReturnType<typeof buildZodSchema>>;
|