Skip to content

es cqrs

Sclable CI edited this page Apr 29, 2024 · 199 revisions

Module: es-cqrs

Table of contents

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

AggregateConstructor

Ƭ AggregateConstructor<T>: (id: string, userId: string) => T

Type parameters

Name Type
T extends Aggregate

Type declaration

• (id, userId): T

Parameters
Name Type
id string
userId string
Returns

T

Defined in

packages/es-cqrs/src/aggregate.ts:97


Command

Ƭ Command: INestCommand

Command interface

Implement this to create unique commands. There is no restriction on what the command class can have.

Example:

import { Command } from '@sclable/es-cqrs'
import { v4 } from 'uuid'

export class CreateAccountCommand implements Command {}

export class AccountNameChangeCommand implements Command {
  public constructor(public readonly id: string, public readonly name: string) {}
}

To handle these commands implement the ICommandHandler interface so that it finds or creates the needed aggregate, call the modifying method that will create the event and persist the aggregate in the repository. The resolve method should return the object needed for this command to finish (usually an ID).

Example:

import { CommandHandler, ICommandHandler, InjectRepository, Repository } from '@sclable/es-cqrs'
import { AccountNameChangeCommand } from './commands'
import { AccountAggregate } from './aggregates'

@CommandHandler(AccountNameChangeCommand)
export class SomeCommandHandler implements ICommandHandler<AccountNameChangeCommand> {

  public constructor(@InjectRepository(AccountAggregate) private readonly repo: Repository<AccountAggregate>) {}

  async execute(command: AccountNameChangeCommand): Promise<any> {
    const agg = await this.repo.find(command.id)
    agg.changeName(command.name)
    return this.repo.persist(agg)
  }
}

Defined in

packages/es-cqrs/src/interfaces/command.ts:43


EventConstructor

Ƭ EventConstructor: (aggregateId: string, aggregateType: string, revision: number, createdAt: Date, userId: string, data: any, customOptions?: CustomEventOptions) => Event

Constructor signature used to reconstruct an Event instance from the event store

Type declaration

• (aggregateId, aggregateType, revision, createdAt, userId, data, customOptions?): Event

Parameters
Name Type
aggregateId string
aggregateType string
revision number
createdAt Date
userId string
data any
customOptions? CustomEventOptions
Returns

Event

Defined in

packages/es-cqrs/src/interfaces/event.ts:109

Variables

InmemoryEventStoreProvider

Const InmemoryEventStoreProvider: AsyncProvider<EventStoreProvider>

Defined in

packages/es-cqrs/src/event-store/inmemory-event-store.ts:98

Functions

EventSourcableAggregate

EventSourcableAggregate(...events): ClassDecorator

Decorator to define events that can affect the aggregate

Parameters

Name Type
...events EventConstructor[]

Returns

ClassDecorator

Defined in

packages/es-cqrs/src/decorators/event-sourcable-aggregate.decorator.ts:7


InjectRepository

InjectRepository<T>(aggregate): PropertyDecorator & ParameterDecorator

Aggregate repository injector for command handlers

Type parameters

Name Type
T extends Aggregate

Parameters

Name Type
aggregate AggregateConstructor<T>

Returns

PropertyDecorator & ParameterDecorator

Defined in

packages/es-cqrs/src/decorators/inject-repository.decorator.ts:9


createAsyncProvider

createAsyncProvider<T>(provider, token): Provider

Type parameters

Name
T

Parameters

Name Type
provider AsyncProvider<T>
token string

Returns

Provider

Defined in

packages/es-cqrs/src/interfaces/async-provider.ts:16


createAsyncProviders

createAsyncProviders<T>(provider, token): Provider[]

Type parameters

Name
T

Parameters

Name Type
provider AsyncProvider<T>
token string

Returns

Provider[]

Defined in

packages/es-cqrs/src/interfaces/async-provider.ts:46

Clone this wiki locally