import { Schema, type ValidationResult, type ValidatorContext, } from "../validation.ts"; export type EnumSchemaOptions = { description?: string; default?: V; }; export class EnumSchema< const V extends null | string | number | boolean, > extends Schema { constructor( readonly values: readonly V[], readonly options: EnumSchemaOptions = {}, ) { super(); } validateInContext( input: unknown = this.options.default, ctx: ValidatorContext, ): ValidationResult { if (!(this.values as readonly unknown[]).includes(input)) { return ctx.issueInvalidValue(input, this.values); } return ctx.success(input as V); } }