Skip to content

Modules

Everything is exported from effect-cqrs as a namespace, as in import { Aggregate, ViewModel } from "effect-cqrs", and each module also has its own path, such as effect-cqrs/ViewModel.

Defines aggregates. Source

Export What it is
make<State>()({ name, events, initial, projection }) Starts an aggregate, to which .command(name, { payload, handler }) adds commands
evolve(aggregate, state, event, meta) Applies one event with the aggregate’s projection
EventMeta, CommandContext What projections and handlers receive besides the event or payload
State, Event, CommandName, Payload, CommandError, Context Types derived from an aggregate

Runs an aggregate against the event store. Source

Export What it is
make(aggregate, { maxRetries, stateCacheSize }) The service: commands, dispatch, readModel, history
CommandResult, HistoryEntry What a command and history return
UnknownCommand, InvalidCommand, EventDecodeError Its errors, besides the store’s
makeEventDecoder, makeEventEncoder Convert between stored JSON and an aggregate’s events

Projects events into read models. Source

Export What it is
make({ name, aggregates, handlers, dispose }) Defines a view model
layer([...]) Runs view models in the background and provides ViewModels
ViewModels The service: replay, caughtUp, status
ViewModelError, UnknownViewModel A handler’s failure, and a replay of an unknown name

The append-only log. Source

Export What it is
EventStore The service: append, read, subscribe, head, changes
layerMemory, makeMemory The store in memory
make(backend), Backend Builds a store on another database
StoredEvent, EventFilter, AppendInput What it stores, selects and takes
ConcurrencyConflict, EventStoreError Its errors

How far each view model has read. Source

Export What it is
Checkpoints The service: get and set
layerMemory Checkpoints in memory

Durable stores through effect/sql. SQLite, PostgreSQL

Export What it is
layer(options) The event store, given a SqlClient
layerCheckpoints(options) Checkpoints in the same database
Options eventsTable and checkpointsTable

Tests an aggregate. Source

Export What it is
make(aggregate) A fixture: givenEvents, when, whenFails, inspectState
Scenario, Outcome The chain, and what yielding it gives
ExpectationFailed The defect a failed expectation raises