Skip to content

@joakimbugge/seeder


@joakimbugge/seeder / Seed

Function: Seed()

Call Signature

ts
function Seed(): PropertyDecorator;

Defined in: packages/seeder/src/seed/decorator.ts:13

Marks a relation property for auto-seeding.

The related entity class is inferred from ORM metadata. One instance is created and recursively seeded (including its own @Seed properties).

Circular back-references are broken automatically: if the related class is already being seeded higher up in the same call chain, the property is left undefined.

Returns

PropertyDecorator

Call Signature

ts
function Seed(options): PropertyDecorator;

Defined in: packages/seeder/src/seed/decorator.ts:25

Marks a relation property for auto-seeding with options.

Use count on one-to-many and many-to-many properties to control how many related entities are created. Ignored for one-to-one and many-to-one.

Parameters

options

SeedOptions

Returns

PropertyDecorator

Example

ts
@Seed({ count: 3 })
books!: Book[]

Call Signature

ts
function Seed<TEntity, TContext>(factory): PropertyDecorator;

Defined in: packages/seeder/src/seed/decorator.ts:38

Marks a property with a factory callback.

The factory receives the current seed context and can return any value, including a Promise. Use this for scalar properties or when you need full control over how a related entity is resolved.

Type Parameters

TEntity

TEntity extends object = object

TContext

TContext extends SeedContext = SeedContext

Parameters

factory

SeedFactory<unknown, TEntity, TContext>

Returns

PropertyDecorator

Example

ts
@Seed(() => faker.internet.email())
email!: string

Call Signature

ts
function Seed<TEntity, TContext>(factory, options): PropertyDecorator;

Defined in: packages/seeder/src/seed/decorator.ts:44

Marks a property with a factory callback and additional options.

Type Parameters

TEntity

TEntity extends object = object

TContext

TContext extends SeedContext = SeedContext

Parameters

factory

SeedFactory<unknown, TEntity, TContext>

options

SeedOptions

Returns

PropertyDecorator

Released under the MIT License.