joiful
Version:
TypeScript Declarative Validation. Decorate your class properties to validate them using Joi.
72 lines (71 loc) • 3.25 kB
TypeScript
import * as Joi from 'joi';
import { JoifulOptions } from './decorators/common';
import { ArrayPropertyDecoratorOptions } from './decorators/array';
import { ObjectPropertyDecoratorOptions } from './decorators/object';
import { Validator } from './validation';
import { AnyClass } from './core';
export declare class Joiful {
private readonly options;
constructor(options?: JoifulOptions);
get joi(): Joi.Root;
/**
* Property decorator that allows the property to be any type.
*/
any: () => import("./decorators/common").PropertyDecorator<any, import("./decorators/any").AnySchemaModifiers>;
/**
* Property decorator that constrains the property to be an array.
*/
array: (options?: ArrayPropertyDecoratorOptions | undefined) => import("./decorators/common").PropertyDecorator<any[], import("./decorators/array").ArraySchemaModifiers>;
/**
* Property decorator that constrains the property to be a boolean.
*/
boolean: () => import("./decorators/common").PropertyDecorator<Boolean, import("./decorators/boolean").BooleanSchemaModifiers>;
/**
* Property decorator that constrains the property to be a Date.
*/
date: () => import("./decorators/common").PropertyDecorator<Date, import("./decorators/date").DateSchemaModifiers>;
/**
* Property decorator that constrains the property to be a Function.
*/
func: () => import("./decorators/common").PropertyDecorator<Function, import("./decorators/function").FunctionSchemaModifiers>;
/**
* Property decorator that constrains the property to another schema.
* This allows defining classes that reference themself. e.g.
*
* @example
* class TreeNode {
* @jf.string().required()
* title: string;
*
* @jf.array().items((joi) => joi.link('...'))
* children: TreeNode[];
* }
*/
link: (ref?: string | undefined) => import("./decorators/common").PropertyDecorator<any, import("./decorators/link").LinkSchemaModifiers>;
/**
* Property decorator that constrains the property to be a number.
*/
number: () => import("./decorators/common").PropertyDecorator<number, import("./decorators/number").NumberSchemaModifiers>;
/**
* Property decorator that constrains the property to be an object.
*/
object: (options?: ObjectPropertyDecoratorOptions | undefined) => import("./decorators/common").PropertyDecorator<object, import("./decorators/object").ObjectSchemaModifiers>;
/**
* Property decorator that constrains the property to be a string.
*/
string: () => import("./decorators/common").PropertyDecorator<string, import("./decorators/string").StringSchemaModifiers>;
/**
* Method decorator that validates the parameters passed into the method.
*/
validateParams: (options?: {
validator?: Validator | undefined;
} | undefined) => MethodDecorator;
/**
* Returns the Joi schema associated with a class or undefined if there isn't one.
*/
getSchema: (Class: AnyClass) => Joi.ObjectSchema | undefined;
/**
* Returns whether the given class has a Joi schema associated with it
*/
hasSchema: (Class: AnyClass) => boolean;
}