// Type definitions for factory-girl 5.0 // Project: https://github.com/aexmachina/factory-girl#readme // Definitions by: Stack Builders // Sebastián Estrella // Luis Fernando Alvarez // Olivier Kamers // Dan McNamara // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 declare const factory: factory.Static; declare namespace factory { type Generator = () => T; type Definition = T | Generator | Promise; type Attributes = { [P in keyof T]: Definition; }; type MaybeReadonlyArray = T | ReadonlyArray; type BuildOptions = Record; type Initializer = | Attributes | ((buildOptions?: BO) => Attributes) | ((buildOptions?: BO) => Promise>); interface Static { factory: Static; /** * Associate the factory to other model */ assoc(name: string, key?: string, attrs?: Attributes, buildOptions?: BuildOptions): any; /** * Associate the factory to a model that's not persisted */ assocAttrs(name: string, key?: string, attrs?: Attributes, buildOptions?: BuildOptions): any; /** * Associate the factory to multiple other models */ assocMany(name: string, num: number, key?: string, attrs?: Attributes, buildOptions?: BuildOptions): any[]; /** * Associate the factory to multiple other models that aren't persisted */ assocAttrsMany( name: string, num: number, key?: string, attrs?: Attributes, buildOptions?: BuildOptions, ): any[]; /** * Generates and returns model attributes as an object hash instead of the model instance */ attrs(name: string, attrs?: Attributes>, buildOptions?: BuildOptions): Promise; /** * Generates and returns a collection of model attributes as an object hash instead of the model instance */ attrsMany( name: string, num: number, attrs?: MaybeReadonlyArray>>, buildOptions?: BuildOptions | ReadonlyArray, ): Promise; /** * Builds a new model instance that is not persisted */ build(name: string, attrs?: Attributes>, buildOptions?: BuildOptions): Promise; /** * Builds an array of model instances that are not persisted */ buildMany( name: string, num: number, attrs?: MaybeReadonlyArray>>, buildOptions?: MaybeReadonlyArray, ): Promise; /** * Destroys all of the created models */ cleanUp(): void; /** * Builds a new model instance that is persisted */ create(name: string, attrs?: Attributes>, buildOptions?: BuildOptions): Promise; /** * Builds an array of model instances that are persisted */ createMany( name: string, num: number, attrs?: MaybeReadonlyArray>>, buildOptions?: MaybeReadonlyArray, ): Promise; createMany( name: string, attrs?: ReadonlyArray>>, buildOptions?: MaybeReadonlyArray, ): Promise; /** * Define a new factory with a set of options */ define(name: string, model: any, attrs: Initializer>, options?: Options): void; /** * Extends a factory */ extend(parent: string, name: string, initializer: any, options?: Options): any; /** * Generate values sequentially inside a factory */ seq(name?: string): Generator; seq(name: string, fn: (sequence: number) => T): Generator; seq(fn: (sequence: number) => T): Generator; sequence(name?: string): Generator; sequence(name: string, fn: (sequence: number) => T): Generator; sequence(fn: (sequence: number) => T): Generator; /** * Register an adapter, either as default or tied to a specific model */ setAdapter(adapter: any, name?: string): void; /** * Reset sequence generator with the given name * or all generators if no name is given. */ resetSequence(name?: string): void; resetSeq(name?: string): void; chance(chanceMethod: string, ...options: any): any; } interface Options { afterBuild?: Hook; afterCreate?: Hook; } type Hook = (model: any, attrs: T[], options: any) => void; } export = factory; export as namespace factory;