Skip to content

IWriteSideAggregateRepository

Defined in: packages/ddd-core/application/ports/write-side-aggregate-repository.port.ts:27

Write-side repository contract for commands that mutate an existing aggregate.

findById() must read authoritative persistence and must not use a read-side result cache. Adapters backed by an ORM identity map should force a refresh so optimistic-concurrency checks are based on current persisted state.

Use this contract in update/delete command handlers that must authorize and mutate the real aggregate before saving it.

const user = await repository.findById(command.id);
if (!user) throw new EntityNotFoundException('User', command.id);
authorizer.authorize('update', user);
user.update({ department: command.department });
await repository.save(user);

TEntity

Rehydrated aggregate type.

TId = string

Aggregate identifier type.

findById(id): Promise<TEntity | null>

Defined in: packages/ddd-core/application/ports/write-side-aggregate-repository.port.ts:35

Loads the current authoritative aggregate for a mutating command.

TId

Aggregate identifier.

Promise<TEntity | null>

The rehydrated aggregate, or null when it does not exist.


save(entity): Promise<unknown>

Defined in: packages/ddd-core/application/ports/command-repository.port.ts:28

Persists the aggregate/payload.

Returning null is the conventional deletion result used by the DDD cache decorator to trigger eviction/barrier behavior.

TEntity

Promise<unknown>

ICommandRepository.save