eventsourcing
Event sourcing for Louise apps: aggregates as deciders, an event store behind an effect (in memory, in process, or in PostgreSQL), a state cache per aggregate, catch-up projections, and values sealed at rest. It is the infrastructure toki2 and Starfleet API grew, shared so the two copies stop drifting (ADR 0076).
import eventsourcing/aggregate.{type Aggregate, Aggregate}
import eventsourcing/decider.{type Decider, Decider}
pub fn decider :: -> Decider<Command, Event, State, Rejection>
{
Decider(initial: Unregistered, evolve: evolve, decide: decide)
}
// One stream per aggregate: `account-<id>`, its events in `codec`'s form.
pub fn accounts :: -> Aggregate<Command, Event, State, Rejection>
{
Aggregate("account", decider (), account_codec.codec (), aggregate.own_partition)
}
aggregate.execute (accounts ()) cache (id.text account_id) Register(name, hash, now)
| Module | What |
|---|---|
decider | Decider(initial, evolve, decide), replay, fold, decide: pure. |
codec, payload | An event's stored form: a kind and a MessagePack map, with typed fields. |
aggregate | Load a state (from its cache, then only newer events) and execute a command at the expected version, retried with backoff on a conflict. |
state_cache | The latest (version, state) of each aggregate, in one actor; forget drops one after its events were redacted. |
trouble | Failed, Busy or Contended: what store trouble means to a caller. |
projection | Views folded from the whole log or one partition, caught up in batches. |
event_store | The port (an effect). Adapters: event_store/memory (a pure log), event_store/in_process (an actor), event_store/postgres/stored_events (PostgreSQL, each value sealed). redact gives one stored event new data in place, to erase what a person asked to have forgotten (ADR 0078). |
event_store/postgres/schema | migrate: the events and schema_changes tables, under an advisory lock. An app's own tables are the app's. |
sealing | ChaCha20-Poly1305 with a key derived from a root key under the app's label, each value bound to its row. |
id, backoff | UUIDv7 ids in Crockford base 32; the pause between conflicting attempts. |
louise test runs every test; the PostgreSQL ones need LOUISE_PG_URL and
skip without it. Run them natively with --jobs 1.