UNPKG

vulcain-corejs

Version:
134 lines (133 loc) 3.73 kB
import { IContainer } from '../di/resolvers'; import { PropertyOptions } from './annotations'; import { ReferenceOptions } from './annotations'; export interface ErrorMessage { message: string; id: string; property?: string; } export interface SchemaDescription { name: string; properties: { [index: string]: PropertyOptions; }; references: { [index: string]: ReferenceOptions; }; extends?: SchemaDescription | string; hasSensibleData?: boolean; bind?: (obj) => any; validate?: (val, Container: IContainer) => string; storageName?: string; idProperty?: string; } /** * Schema definition */ export declare class Schema { name: string; description: SchemaDescription; private _domain; /** * Current domain model * @returns {Domain} */ domain: Domain; extends: SchemaDescription; /** * Create a new schema * @param domain : current domain model * @param name : schema name or schema */ constructor(domain: Domain, name: string); /** * * @param origin * @returns {null|any|{}} */ bind(origin: any, old?: any): any; validate(obj: any): ErrorMessage[]; getIdProperty(): string; getId(obj: any): any; encrypt(entity: any): any; decrypt(entity: any): any; /** * Copy an entity to another taking into account references defined in schema * * @param {any} target * @param {any} source * @param {SchemaDescription} [schema] * @returns * * @memberOf Schema */ deepAssign(target: any, source: any, schema?: SchemaDescription): any; } /** * Domain model */ export declare class Domain { name: string; private container; private _schemaDescriptions; private types; private builder; constructor(name: string, container: IContainer, defaultTypes?: any); addSchemaDescription(schema: any, name?: string): string; /** * Get a registered schema by name * Throws an exception if not exists * @param {string} schema name * @returns a schema */ getSchema(name: string | Function): Schema; /** * Get all schemas * * @readonly */ schemas: SchemaDescription[]; /** * Do not use directly * * @param {string} name * @returns */ findSchemaDescription(name: string): SchemaDescription; /** * Do not use directly * * @readonly */ schemaDescriptions: SchemaDescription[]; addTypes(types: any, ns?: string): void; addType(name: string, type: string, info: any, ns?: string): void; _findType(name: string): any; /** * Remove all sensible data * * @param {any} entity * @param {any} schemaName * @returns */ obfuscate(entity: any, schema: Schema): void; /** * Convert a new object from an other based on a specific schema * @param origin : initial object to convert * @param schemaName : schema to used (default=current schema) * @param obj : existing object to use * @returns {any} */ bind(origin: any, schemaName?: string | SchemaDescription, obj?: any): any; private applyBinding(prop, origin, val); private isMany(relSchema); /** * Validate an object * @param val : Object to validate * @param schemaName : schema to use (default=current schema) * @returns Array<string> : A list of errors */ validate(val: any, schemaName?: string | SchemaDescription): ErrorMessage[]; resolveSchemaDescription(schemaName: string | SchemaDescription, val?: any): SchemaDescription; getIdProperty(schemaName?: string | SchemaDescription): string; }