CommandRepository
Defined in: packages/ddd-core/persistence/command-repository.abstract.ts:37
Base class for write-side (command) repositories.
Persists an entity or aggregate state via the abstract save method and receives an
ICache instance. Subclasses annotate save() with the @Cache decorator
to perform automatic write-through caching or cache eviction upon mutation.
Example
Section titled “Example”Creating a command repository with the Cache decorator
@Injectable()export class CreateUserCommandRepository extends CommandRepository<User, UserSnapshot> { constructor( @Inject(CACHE_TOKEN) protected readonly cache: ICache<UserSnapshot>, @Inject(MIKRO_ORM_CLIENT) private readonly store: MikroOrmStore, ) { super(cache); }
@Cache<User, UserSnapshot>( (user) => cacheKey(User.aggregateName, { id: user.id }), ) async save(user: User): Promise<UserSnapshot> { const created = await this.store.em.upsert(User, user); return created.toJSON(); }}Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TEntity
Section titled “TEntity”TEntity = unknown
The aggregate entity type accepted by save.
TResult
Section titled “TResult”TResult = unknown | null
The persisted result type returned by save.
TCache
Section titled “TCache”TCache = unknown
Implements
Section titled “Implements”ICommandRepository<TEntity,TResult>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CommandRepository<
TEntity,TResult,TCache>(cache):CommandRepository<TEntity,TResult,TCache>
Defined in: packages/ddd-core/persistence/command-repository.abstract.ts:43
Parameters
Section titled “Parameters”ICache<TCache>
Returns
Section titled “Returns”CommandRepository<TEntity, TResult, TCache>
Properties
Section titled “Properties”
protectedreadonlycache:ICache<TCache>
Defined in: packages/ddd-core/persistence/command-repository.abstract.ts:43
Methods
Section titled “Methods”save()
Section titled “save()”
abstractsave(entity):Promise<TResult|null>
Defined in: packages/ddd-core/persistence/command-repository.abstract.ts:45
Persists the aggregate/payload.
Returning null is the conventional deletion result used by the DDD cache
decorator to trigger eviction/barrier behavior.
Parameters
Section titled “Parameters”entity
Section titled “entity”TEntity
Returns
Section titled “Returns”Promise<TResult | null>