interface IValidationService
Since 0.1.0

Data validation service.

Examples

Example 1

const validation = ctx.services.get<IValidationService>(CAPABILITIES.VALIDATION);
const result = validation.validate<User>(UserSchema, await ctx.request.json());
if (result.success) {
  save(result.value);
}

Methods

validate<T>(
schema: unknown,
data: unknown
): Result<T, readonly ValidationIssue[]>

Validates data against a schema.

Creates middleware that validates one part of the request and stores the parsed value in request state.

Usage

import { type IValidationService } from "common/src/index.ts";