Expand description
Building blocks for DDD-based applications with CQRS and event sourcing, on top of EventSourcingDB.
Modules§
- testing
- Given-when-then for deciders, and a database in a container for the tests
that need a real one. The module needs the feature
testing, andDatabasethe featuretestcontainers, which turns ontestingas well, so that a test that only checks a decider builds without Docker.
Structs§
- Decider
- A decision on a command, given the state of its subject: the events to write, or an error if the command is refused.
- Domain
Error - A business rule that refused a command, with a message for the caller.
- Empty
Range - The bounds of a read leave no room for an event, such as one before
"0", one after"0"and before"1", or one after the largest revision,2^63-1. No event can ever lie in such a range, so it is a mistake of whoever chose the bounds, which usually come from a request, and it belongs to no category. A range that is only empty for now, such as the one after the last event written so far, is no such mistake, since events can still come there, so reading hands out no events for it, without an error. - EventOn
- An event together with the subject it is written to, for
Store::write. - Event
Schema - The schema of an event type, for registration with the database.
- Failure
- What failed, as in
reading "/books/42", and the error that caused it, if there is one, such as the error of the client SDK. - NotA
Revision - A value that was meant to be a revision, but is not one.
- Precondition
- A condition that must hold for the events of a command to be written.
- Read
Options - Narrows down which events
Store::readhands out, or turns around the order it hands them out in. A read has one lower bound, one upper bound, and one order, so options that contradict each other can not be written: - Store
- Reads from and writes to EventSourcingDB, through the client SDK.
- Store
Builder - Builds a
Store, whichStore::buildercreates. - Subject
Scheme - How a subject is composed: literal segments and placeholders in braces, as
in
/tenant/{tenant}/workshop/{workshop}. - Subject
Values Error - The values that
SubjectScheme::checkrefuses, with a message that may reach the caller of an API. - Subjects
- What a read or a projection reads: a subject, and whether the subjects below
it belong to it. Create it with
treeorexact, so that every read says which of the two it means, rather than relying on a default. - Upcast
Event - A stored event as upcasters see it: its type and its data, which an upcaster changes, and its subject, ID, time and source, which it reads.
- Upcasters
- The set of upcasters for the event types of an application, which translate stored events of an older type into a newer shape, before any state or projection sees them.
Enums§
- Category
- What a failure means for its caller, on two axes: whether it is a matter of the domain or of the machinery, and whether trying again unchanged could help.
- Error
- Any failure of architecturekit, where
Dis the error of a decider, so that a function that calls several operations can pass their failures on with?. - Execute
Error - Why executing a command failed, where
Dis the error of its decider. - IfLatest
Event IsMissing - What
LowerBound::FromLatestEventreads if the subject has no event of the type yet. - Load
Error - Why loading a state failed.
- Lower
Bound - Where the events of a read start.
- Order
- The order in which a read hands out the events.
- Permanent
- A failure of the category
Category::Permanent: trying again will not help. - Preconditions
Error - Why a command declares its preconditions in a way they can not be honored
(see
check_preconditions). - Read
Error - Why reading events failed.
- Read
Options Error - Why the options of a read are refused (see
check_read_options). - Register
Schemas Error - Why registering the schemas of events failed.
- Transient
- A failure of the category
Category::Transient: trying again later, unchanged, may succeed. - Upper
Bound - Where the events of a read end.
- Write
Error - Why writing events failed.
Traits§
- Categorized
- An error that names its
Category. - Command
- A command, which knows the subject it acts on, and the conditions under which its events may be written.
- Event
- The data of an event, which describes what has happened.
- Events
- The events a state evolves by, as one enum with a variant per event type.
- Schema
- The JSON schema of a type, which describes exactly what serde writes for it.
- State
- The state a command decides on, together with the rule that builds it from events.
Functions§
- check_
preconditions - Checks that a command declares its preconditions in a way they can be honored, before anything is read, as executing a command does.
- check_
read_ options - Checks the options of a read as
Store::readchecks them before it asks the database. Use it to check bounds that come from a request before a side effect that must not happen for a read that is refused, such as recording who reads. The database may still refuse a read that passes, such as one from a latest event that comes after the upper bound. - compare_
revisions - Compares two revisions as numbers, since event IDs are decimal strings, and “10” sorts before “9” as text.
- parse_
revision - Reads a revision, which is an event ID of EventSourcingDB, as a number.
- replay
- Folds a sequence of events into a state, starting from
Default. It is meant for tests, where the history is at hand as typed events. - replay_
stored - Folds stored events into a state, running the upcasters on the way, exactly as reading from the database would. It is meant for tests of upcasters, which need the shape of an older version.
- step
- Takes a state a single event further, by the same rules as
replay. It starts from the given state instead ofDefault, and leaves that as it is, so that the state before and after the event are both at hand, for example for a history that tells what an event changed. - step_
stored - Takes a state a single stored event further, running the upcasters on the
way, exactly as reading from the database would. If the upcasters turn the
event into several, the state evolves by all of them. Otherwise, it behaves
like
step.
Derive Macros§
- Event
- Derives
architecturekit::Eventandarchitecturekit::Schemafor the data of an event. Seearchitecturekit::Event. - Events
- Derives
architecturekit::Eventsfor the enum of the events a state evolves by. Seearchitecturekit::Events. - Schema
- Derives
architecturekit::Schemafor a type in the data of an event. Seearchitecturekit::Schema.