Μετάβαση στο περιεχόμενο

CommandRepository

Αυτό το περιεχόμενο δεν είναι ακόμη διαθέσιμο στη γλώσσα σου.

Defined in: packages/core/persistence/command-repository.abstract.ts:36

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.

Creating a command repository with the Cache decorator

export class CreateUserCommandRepository extends CommandRepository<User, UserSnapshot> {
  constructor(
    protected readonly cache: ICache<UserSnapshot>,
    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();
  }
}

TEntity = unknown

The aggregate entity type accepted by save.

TResult = unknown | null

The persisted result type returned by save.

TCache = unknown

new CommandRepository<TEntity, TResult, TCache>(cache): CommandRepository<TEntity, TResult, TCache>

Defined in: packages/core/persistence/command-repository.abstract.ts:42

ICache<TCache>

CommandRepository<TEntity, TResult, TCache>

protected readonly cache: ICache<TCache>

Defined in: packages/core/persistence/command-repository.abstract.ts:42

abstract save(entity): Promise<TResult | null>

Defined in: packages/core/persistence/command-repository.abstract.ts:44

Persists the aggregate/payload.

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

TEntity

Promise<TResult | null>

ICommandRepository.save