UNPKG

@adonisjs/lucid

Version:

SQL ORM built on top of Active Record pattern

81 lines (80 loc) 2.8 kB
import { Hooks } from '@poppinss/hooks'; import { LucidModel, ExtractModelRelations } from '@ioc:Adonis/Lucid/Orm'; import { EventsList, HooksHandler, StateCallback, MergeCallback, NewUpCallback, DefineCallback, FactoryModelContract, FactoryRelationContract } from '@ioc:Adonis/Lucid/Factory'; import { FactoryManager } from './index'; /** * Factory model exposes the API to define a model factory with custom * states and relationships */ export declare class FactoryModel<Model extends LucidModel> implements FactoryModelContract<Model> { model: Model; define: DefineCallback<Model>; manager: FactoryManager; /** * Method to instantiate a new model instance. This method can be * overridden using the `newUp` public method. */ newUpModelInstance: NewUpCallback<FactoryModelContract<LucidModel>>; /** * Method to merge runtime attributes with the model instance. This method * can be overridden using the `merge` method. */ mergeAttributes: MergeCallback<FactoryModelContract<LucidModel>>; /** * A collection of factory states */ states: { [key: string]: StateCallback<Model>; }; /** * A collection of factory relations */ relations: { [relation: string]: FactoryRelationContract; }; /** * A set of registered hooks */ hooks: Hooks; constructor(model: Model, define: DefineCallback<Model>, manager: FactoryManager); /** * Register a before event hook */ before(event: EventsList, handler: HooksHandler<any>): this; /** * Register an after event hook */ after(event: EventsList, handler: HooksHandler<any>): this; /** * Returns state callback defined on the model factory. Raises an * exception, when state is not registered */ getState(state: string): StateCallback<Model>; /** * Returns the pre-registered relationship factory function, along with * the original model relation. */ getRelation(relation: string): FactoryRelationContract; /** * Define custom state for the factory. When executing the factory, * you can apply the pre-defined states */ state(state: string, callback: StateCallback<Model>): any; /** * Define a relationship on another factory */ relation<K extends ExtractModelRelations<InstanceType<Model>>>(relation: Extract<K, string>, callback: any): any; /** * Define a custom `newUp` method */ newUp(callback: NewUpCallback<any>): this; /** * Define a custom `merge` method */ merge(callback: MergeCallback<any>): this; /** * Build factory model and return factory builder. The builder is then * used to make/create model instances */ build(): any; }