octonom
Version:
Object Document Mapper for any database
26 lines (25 loc) • 1.24 kB
TypeScript
import { HookHandlersMap, Hooks } from './hooks';
import { ISanitizeOptions, ISchema, ISchemaInstance, IToObjectOptions, PopulateMap, SchemaMap } from './schema/schema';
export declare type Constructor<T = {}> = new (...args: any[]) => T;
export interface IModelConstructor<T extends Model> {
schemaMap: SchemaMap;
hooks: Hooks<T>;
new (data: Partial<T>, sanitizeOptions?: ISanitizeOptions): T;
}
export interface IModel {
constructor: typeof Model;
}
export declare function Hook<TModel extends Model, K extends keyof HookHandlersMap<TModel>>(name: K, handler: HookHandlersMap<TModel>[K][0]): (constructor: IModelConstructor<TModel>) => void;
export declare const getShadowInstance: symbol;
export declare class Model {
static schemaMap: SchemaMap;
static hooks: Hooks<Model>;
static setSchema(key: string, schema: ISchema<any, ISchemaInstance>): void;
constructor(value?: any, sanitizeOptions?: ISanitizeOptions);
inspect(): Partial<this>;
populate(populateMap: PopulateMap<this>): Promise<this>;
set(data: Partial<this>, options?: ISanitizeOptions, runHooks?: boolean): void;
toObject(options?: IToObjectOptions): Partial<this>;
toJSON(): Partial<this>;
validate(): Promise<void>;
}