@xpresser/abolish
Version:
Using Abolish validator in Xpresserjs
83 lines (82 loc) • 3.27 kB
TypeScript
import type { AbolishSchema, ValidationResult } from "abolish/src/types";
import type { Abolish } from "abolish";
import type { AbolishCompiledObject } from "abolish/src/Compiler";
declare const AbolishRequestEngine_base: typeof import("xpresser/src/RequestEngine");
declare class AbolishRequestEngine extends AbolishRequestEngine_base {
/**
* Initialize abolish instance
*/
abolish: Abolish;
/**
* Validate data
* @param object
* @param rules
*/
validate<R extends Record<string, any> = Record<string, any>>(object: Record<string, any>, rules: AbolishSchema<R>): ValidationResult<R>;
validate<R extends Record<string, any>>(object: Record<string, any>, rules: AbolishCompiledObject): ValidationResult<R>;
/**
* Validate data Async
* @param object
* @param rules
*/
validateAsync<R extends Record<string, any> = Record<string, any>>(object: Record<string, any>, rules: AbolishSchema<R>): Promise<ValidationResult<R>>;
validateAsync<R extends Record<string, any>>(object: Record<string, any>, rules: AbolishCompiledObject): Promise<ValidationResult<R>>;
/**
* Use a specific abolish validator class
* @param abolish
*/
useAbolish<T = Abolish>(abolish: T): this;
/**
* Get new validator instance
*/
newAbolish(): Abolish;
/**
* Validate query data
* @param rules
*/
validateQuery<R extends Record<string, any> = Record<string, any>>(rules: AbolishSchema<R> | AbolishCompiledObject): ValidationResult<R>;
/**
* Validate body data
* @param rules
*/
validateBody<R extends Record<string, any> = Record<string, any>>(rules: AbolishSchema<R> | AbolishCompiledObject): ValidationResult<R>;
/**
* Validate query data Async
* @param rules
*/
validateQueryAsync<R extends Record<string, any> = Record<string, any>>(rules: AbolishSchema<R> | AbolishCompiledObject): Promise<ValidationResult<R>>;
/**
* Validate body data Async
* @param rules
*/
validateBodyAsync<R extends Record<string, any> = Record<string, any>>(rules: AbolishSchema<R> | AbolishCompiledObject): Promise<ValidationResult<R>>;
/**
* Get validated body data.
*/
validatedBody<R = Record<string, any>>(): R;
/**
* Validate body or throw error
* @param rules - Validation rules
*/
validateBodyOrThrow<T extends Record<string, any>>(rules: AbolishCompiledObject | AbolishSchema<T>): T;
/**
* Validate query or throw error
* @param rules - Validation rules
*/
validateQueryOrThrow<T extends Record<string, any>>(rules: AbolishCompiledObject | AbolishSchema<T>): T;
/**
* Validate body or throw error async
* @param rules - Validation rules
*/
validateBodyOrThrowAsync<T extends Record<string, any>>(rules: AbolishCompiledObject | AbolishSchema<T>): Promise<T>;
/**
* Validate query or throw error async
* @param rules - Validation rules
*/
validateQueryOrThrowAsync<T extends Record<string, any>>(rules: AbolishCompiledObject | AbolishSchema<T>): Promise<T>;
}
export = AbolishRequestEngine;
declare module "xpresser/types/http" {
interface Http extends AbolishRequestEngine {
}
}