Skip to content

@joakimbugge/seeder


@joakimbugge/seeder / SeedContext

Interface: SeedContext

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

Base context passed through a seed operation. Available inside factory callbacks.

Extended by

Properties

previous?

ts
optional previous?: ReadonlyMap<Function, readonly any[]>;

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

Instances created earlier in the current createMany batch, keyed by entity class. When creating instance i, previous.get(EntityClass) contains instances 0..i-1 in order.

Each entry is a snapshot taken just before the corresponding instance is created, so the array length always equals the number of completed instances of that type so far.

Child entities inherit the parent's map, so a child factory can also read parent-batch entries. The child's own type starts with an empty array when its batch begins — instances from an unrelated sibling batch of the same type are never visible.

Example

ts
// Each booking starts the day after the previous one ends.
@Seed((ctx, self: Booking) => {
  const last = (ctx.previous?.get(Booking) as Booking[] | undefined)?.at(-1)
  return last ? last.to.plus({ days: 1 }) : DateTime.now()
})
from!: DateTime

relations?

ts
optional relations?: boolean;

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

Set to false to skip automatic relation seeding. Scalar and embedded properties are still seeded; only relation properties decorated with a bare @Seed() are skipped.

Default

ts
true

Released under the MIT License.