import { Factory, Meta } from './factory'; import { LairRecord } from './record'; export interface InternalDb { [factoryName: string]: { [recordId: string]: LairRecord; }; } export interface InternalMetaStore { [factoryName: string]: Meta; } export interface CRUDOptions { depth?: number; ignoreRelated?: string[] | boolean; handleNotAttrs?: boolean; } export interface DevInfoItem { count: number; id: number; meta: InternalMetaStore; } export interface DevInfo { [factoryName: string]: DevInfoItem; } export interface CreateOneData { id?: string; [prop: string]: any; } export interface ParentData { factoryName: string; attrName: string; } export interface RelationshipOptions { maxDepth: number; currentDepth: number; ignoreRelated: string[] | boolean; } export interface RelatedFor { factoryName: string; id: string; attrName: string; } export declare class Lair { /** * Lair implements singleton-pattern * Use this method to get it's instance */ static getLair(): Lair; /** * It will drop existing database and unregister all factories */ static cleanLair(): void; private static instance; verbose: boolean; private factories; private relationships; private db; meta: InternalMetaStore; private afterCreateQueue; private constructor(); /** * Register factory instance in the Lair * Lair works only with registered factories */ registerFactory(factoryInstanceOrClass: Factory | typeof Factory): void; /** * Create number of records for needed factory and put then to the db * This method can be used only for initial db filling */ createRecords(factoryName: string, count: number): void; /** * Load records data from the predefined JSON's to the db * This method can be used only for initial db filling */ loadRecords(factoryName: string, data: Record[]): void; /** * Filter records of needed factory * Callback is called with one parameter - record */ queryMany(factoryName: string, clb: (record: LairRecord) => boolean, options?: CRUDOptions): LairRecord[]; /** * Get all records of needed factory */ getAll(factoryName: string, options?: CRUDOptions): LairRecord[]; /** * Get one record of needed factory by its id */ getOne(factoryName: string, id: string, options?: CRUDOptions): LairRecord; /** * Filter one record of needed factory * Callback is called with one parameter - record */ queryOne(factoryName: string, clb: (record: LairRecord) => boolean, options?: CRUDOptions): LairRecord; /** * Create one record of needed factory * ID is auto generated for new record. Don't include it to `data` (`data.id` will be skipped) * All `data`-fields than not declared in the factory will be skipped * Relationships with records of other factories will be automatically updated. * Important! All related records should already be in the db */ createOne(factoryName: string, data: CreateOneData, options?: CRUDOptions): LairRecord; /** * Update one record of needed factory * ID and any field from `data` which doesn't exist in the factory's meta will be skipped (same as for `createOne`) * Relationships with records of other factories will be automatically updated. * Important! All related records should already be in the db */ updateOne(factoryName: string, id: string, data: Record, options?: CRUDOptions): LairRecord; /** * Delete one record of needed factory * Relationships with records of other factories will be automatically updated */ deleteOne(factoryName: string, id: string): void; /** * Get info about current Lair state: * - Registered factories * - ID-value for each factory * - Records count for each factory * - Meta-info for each factory */ getDevInfo(): DevInfo; private hasType; private addType; private internalCreateRecords; private getRecordWithRelationships; private isRelated; private createAttrValue; private createOneToOneAttrValue; private createManyToOneAttrValue; private createOneToManyAttrValue; private createManyToManyAttrValue; getMetaFor(factoryNameOrClass: any): Meta; private getRelatedFactoryNames; }