Skip to content

@joakimbugge/seeder


@joakimbugge/seeder / SeedFactory

Type Alias: SeedFactory<T, TEntity, TContext>

ts
type SeedFactory<T, TEntity, TContext> = (context, self, index) => T | Promise<T>;

Defined in: packages/seeder/src/seed/registry.ts:57

Factory callback passed to @Seed. Receives the seed context, the partially built entity, and a zero-based index that counts up across a createMany/saveMany batch.

Properties are seeded sequentially in declaration order, so any property declared above the current one is already set on self and can be read to derive the current value.

The optional TContext parameter lets ORM packages expose a narrowed factory type whose context includes connection-specific fields (e.g. dataSource, em) without needing duplicate implementations. Defaults to the base SeedContext.

Type Parameters

T

T = unknown

TEntity

TEntity = any

TContext

TContext extends SeedContext = SeedContext

Parameters

context

TContext

self

TEntity

index

number

Returns

T | Promise<T>

Example

ts
@Seed((_, __, i) => `user-${i}@example.com`)
email!: string

Released under the MIT License.