import type { HttpMiddleware } from "@egomobile/http-server"; import type { Schema } from "../types/index.js"; import type { Nilable, Nullable } from "../types/internal.js"; /** * A validation error. */ export interface IValidationError { /** * A context, if available. */ context: Nullable; /** * The details. */ details: string; /** * The message text. */ message: string; } /** * A function, that is invoked, when validation of body data * fails against a schema fails. * * @param {IValidationError[]} errors The errors. * @param {TRequest} request The request context. * @param {TResponse} response The response context. */ export type ValidationFailedHandler = (errros: IValidationError[], request: TRequest, response: TResponse) => any; /** * The default function, which is invoked when validation of body data * fails against a schema fails. * * @param {IValidationError[]} errors The list of errors. * @param {any} request The request context. * @param {any} response The response context. */ export declare const defaultValidationFailedHandler: ValidationFailedHandler; /** * Creates a new middleware, which validates value in * `body` property of request context against a schema. * * @param {Schema} schema The schema. * @param {Nilable>} [onValidationFailed] The custom validation error handler. * * @returns {HttpMiddleware} The new middleare. */ export declare function validate(schema: Schema, onValidationFailed?: Nilable>): HttpMiddleware;