@athenna/validator
Version:
The Athenna validation solution. Built on top of VineJS.
61 lines (60 loc) • 1.74 kB
TypeScript
/**
* @athenna/validator
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Vine } from '#src';
import type { SchemaTypes, ExtendReturnType } from '#src/types';
import { Macroable } from '@athenna/common';
import type { Infer, ValidationOptions } from '@vinejs/vine/types';
export declare class ValidatorImpl extends Macroable {
/**
* This getter will return the vine instance to
* build your validation schemas:
*
* ```ts
* const schema = v.object({
* name: v.string(),
* email: v.string().email(),
* password: v.string().minLength(8).maxLength(32).confirmed()
* })
* ```
*/
get schema(): Vine;
/**
* Validate data by passing a schema and data. Also
* accepts other fields such as message provider
* and error reporter.
*
* ```ts
* const data = { name: 'Lenon' }
* const schema = v.object({ name: v.string() })
*
* await v.validate({ schema, data })
* ```
*/
validate(options: {
schema: SchemaTypes;
data: any;
} & ValidationOptions<Record<string, any> | undefined>): Promise<Infer<SchemaTypes>>;
/**
* Extend vine validation schema by adding new
* validation rules or add custom messages:
*
* ```ts
* Validate.extend().string('lenon', (value, options, field) => {
* if (!Is.String(value)) {
* return
* }
*
* if (value !== 'lenon') {
* field.report('The {{ field }} field value is not lenon', 'lenon', field)
* }
* })
* ```
*/
extend(): ExtendReturnType;
}