Event Store¶
event_store
¶
Event Store infrastructure.
This module provides the EventStorePort port and its in-memory implementation.
EventStorePort
¶
Bases: ABC
EventStorePort port.
The EventStorePort is responsible for persisting and retrieving events
for aggregate roots. It follows the Event Sourcing pattern.
Source code in src/forging_blocks/infrastructure/event_store.py
save_events(aggregate_id: str, events: List[dict[str, Any]], expected_version: Optional[int] = None) -> None
abstractmethod
async
¶
Save a list of events for an aggregate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate_id
|
str
|
The unique identifier of the aggregate. |
required |
events
|
List[dict[str, Any]]
|
The list of events to save. |
required |
expected_version
|
Optional[int]
|
The expected version of the aggregate. |
None
|
Raises:
| Type | Description |
|---|---|
ConcurrencyError
|
If the expected version does not match the current version. |
Source code in src/forging_blocks/infrastructure/event_store.py
get_events(aggregate_id: str, from_version: Optional[int] = None, to_version: Optional[int] = None) -> list[dict[str, object]]
abstractmethod
async
¶
Retrieve events for an aggregate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate_id
|
str
|
The unique identifier of the aggregate. |
required |
from_version
|
Optional[int]
|
The starting version (inclusive). |
None
|
to_version
|
Optional[int]
|
The ending version (inclusive). |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, object]]
|
A list of events. |
Source code in src/forging_blocks/infrastructure/event_store.py
get_snapshot(aggregate_id: str, version: int) -> dict[str, object] | None
abstractmethod
async
¶
Retrieve a snapshot of an aggregate at a specific version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate_id
|
str
|
The unique identifier of the aggregate. |
required |
version
|
int
|
The version of the snapshot. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, object] | None
|
The snapshot data, or None if not found. |
Source code in src/forging_blocks/infrastructure/event_store.py
save_snapshot(aggregate_id: str, version: int, snapshot: dict[str, object]) -> None
abstractmethod
async
¶
Save a snapshot of an aggregate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate_id
|
str
|
The unique identifier of the aggregate. |
required |
version
|
int
|
The version of the snapshot. |
required |
snapshot
|
dict[str, object]
|
The snapshot data. |
required |