@gabliam/validate-joi
Version:
Gabliam plugin for add validation with joi on web
93 lines (92 loc) • 3.25 kB
TypeScript
import { Joi, ValueExtractor } from '@gabliam/core';
export declare function isValidatorOptions(value: any): value is ValidatorOptions;
export declare function isValidatorConstructor(value: any): value is ValidatorConstructor;
export interface Validator {
params?: Joi.SchemaLike;
headers?: Joi.SchemaLike;
query?: Joi.SchemaLike;
body?: Joi.SchemaLike;
}
export interface ValidatorOptions extends ValidatorOptionsConstructor {
/**
* If true, add ValidateSendErrorInterceptor and ValidateInterceptor to method
* default: true
*/
useInterceptors?: boolean;
}
export interface ValidatorOptionsConstructor {
validator: Validator;
options?: ValidationOptions;
}
export type ValidatorConstructor = (valueValidator: ValueExtractor) => Validator | ValidatorOptionsConstructor;
export type ValidatorType = keyof Validator;
export interface ValidationOptions extends Joi.ValidationOptions {
escapeHtml?: boolean;
}
export declare const listParamToValidate: ValidatorType[];
export declare const constructValidator: (validator: Validator | ValidatorOptions, options?: ValidationOptions) => {
rules: Map<keyof Validator, Joi.Schema<any>>;
validationOptions: {
escapeHtml: boolean;
messages?: Joi.LanguageMessages | undefined;
abortEarly?: boolean | undefined;
allowUnknown?: boolean | undefined;
artifacts?: boolean | undefined;
cache?: boolean | undefined;
context?: Joi.Context | undefined;
convert?: boolean | undefined;
dateFormat?: "string" | "date" | "iso" | "time" | "utc" | undefined;
debug?: boolean | undefined;
errors?: Joi.ErrorFormattingOptions | undefined;
externals?: boolean | undefined;
noDefaults?: boolean | undefined;
nonEnumerables?: boolean | undefined;
presence?: Joi.PresenceMode | undefined;
skipFunctions?: boolean | undefined;
stripUnknown?: boolean | {
arrays?: boolean | undefined;
objects?: boolean | undefined;
} | undefined;
};
};
/**
* Type of the `Validate` decorator / constructor function.
*/
export interface ValidateDecorator {
/**
* Decorator that marks a property to use a validator
*
* @usageNotes
*
*
* ```typescript
* @Controller('/')
* class SampleController {
* @Validate({
* query: {
* name: Joi.string().required()
* }
* })
* @Get('/')
* hello(@QueryParam('name') name: string) {
* return 'Hello';
* }
* }
* ```
*/
(validator: Validator | ValidatorOptions | ValidatorConstructor, options?: ValidationOptions, useInterceptors?: boolean): MethodDecorator;
/**
* see the `@Validate` decorator.
*/
new (validator: Validator | ValidatorOptions | ValidatorConstructor, options?: ValidationOptions, useInterceptors?: boolean): any;
}
/**
* `Validate` decorator and metadata.
*/
export interface Validate {
rules?: Map<ValidatorType, Joi.Schema>;
validatorCreator?: ValidatorConstructor;
validationOptions: ValidationOptions;
useInterceptors?: boolean;
}
export declare const Validate: ValidateDecorator;