UNPKG

vulcain-corejs

Version:
127 lines (126 loc) 3.41 kB
import 'reflect-metadata'; import { RequestContext } from '../servers/requestContext'; export interface ModelOptions { name?: string; extends?: string; description?: string; bind?: ((data) => any) | boolean; validate?: (entity, ctx?: RequestContext) => string; storageName?: string; hasSensibleData?: boolean; } export declare function Model(options?: ModelOptions): (target: Function) => void; /** * Property definition * * @export * @interface PropertyOptions */ export interface PropertyOptions { /** * Base type * * @type {string} - a valid base type * @memberOf PropertyOptions */ type: string; /** * List of values for 'enum' type * * @type {string[]} - An array of values * @memberOf PropertyOptions */ values?: string[]; /** * True is this property is required * * @type {boolean} * @memberOf PropertyOptions */ required?: boolean; /** * Property description * * @type {string} * @memberOf PropertyOptions */ description?: string; /** * Item type property of type 'ArrayOf' * * @type {string} - A valid type for all elements of the array * @memberOf PropertyOptions */ item?: string; /** * Entity key - Only one property by entity can be define. * * @type {boolean} * @memberOf PropertyOptions */ isKey?: boolean; /** * Used to create an unique index key - Supports multiple property keys * * @type {boolean} * @memberOf PropertyOptions */ unique?: boolean; /** * List of validators - Do not use directly, use @Validator instead * * @type {Array<any>} * @memberOf PropertyOptions */ validators?: Array<any>; /** * Function to transform an input value. If null or false, the value are ignored. * * * @memberOf PropertyOptions */ bind?: ((val, entity) => any) | boolean; /** * Provide a way to check if a validation should be done. * validation are skipped, if the function returns false. * * @memberOf PropertyOptions */ dependsOn?: (entity) => boolean; /** * Custom validation. This validation runs after all others validators * * * @memberOf PropertyOptions */ validate?: (val, ctx?: RequestContext) => string; /** * Define if the property contains sensible data. * Sensible datas are obfuscated and are removed from get request. * This behavior only works with built-in provider and command. * * @type {boolean} * @memberOf PropertyOptions */ sensible?: boolean; /** * Default value * * @memberOf PropertyOptions */ defaultValue?: any; } export declare function Property(info: PropertyOptions): (target: any, key: any) => void; export declare function Validator(name: string, info?: any): (target: any, key: any) => void; export interface ReferenceOptions { item: string; cardinality: 'one' | 'many'; required?: boolean; description?: string; bind?: ((val) => any) | boolean; dependsOn?: (entity) => boolean; validate?: (val, ctx?: RequestContext) => string; validators?: Array<any>; type?: string; } export declare function Reference(info: ReferenceOptions): (target: any, key: any) => void;