Configuration schema for validation
Implementations can use any validation library (Zod, Joi, etc.)
import { z } from 'zod';const schema = z.object({ port: z.number().int().positive(), host: z.string().default('localhost'),});class ZodConfigSchema implements ConfigSchema<MyConfig> { async validate(data: unknown): Promise<ValidationResult<MyConfig>> { const result = schema.safeParse(data); if (result.success) { return { success: true, data: result.data }; } return { success: false, errors: result.error.errors.map(e => ({ path: e.path.join('.'), message: e.message, })), }; }} Copy
import { z } from 'zod';const schema = z.object({ port: z.number().int().positive(), host: z.string().default('localhost'),});class ZodConfigSchema implements ConfigSchema<MyConfig> { async validate(data: unknown): Promise<ValidationResult<MyConfig>> { const result = schema.safeParse(data); if (result.success) { return { success: true, data: result.data }; } return { success: false, errors: result.error.errors.map(e => ({ path: e.path.join('.'), message: e.message, })), }; }}
Validate configuration data
The data to validate
Validation result with validated data or errors
Configuration schema for validation
Implementations can use any validation library (Zod, Joi, etc.)
Example