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