Suite of AT Protocol TypeScript libraries built on web standards
1import {
2 Schema,
3 type ValidationResult,
4 type Validator,
5 type ValidatorContext,
6} from "../validation.ts";
7
8export class NullableSchema<T> extends Schema<T | null> {
9 declare readonly ["_lex"]: { output: T | null };
10
11 constructor(readonly schema: Validator<T>) {
12 super();
13 }
14
15 validateInContext(
16 input: unknown,
17 ctx: ValidatorContext,
18 ): ValidationResult<T | null> {
19 if (input === null) {
20 return ctx.success(null);
21 }
22 return ctx.validate(input, this.schema);
23 }
24}