pub trait EventStore: Send + Sync {
// Required methods
fn append_event(
&self,
draft: EventDraft,
) -> BoxFuture<'_, Result<EventRecord, StoreError>>;
fn append_event_with_image(
&self,
draft: EventDraft,
image: ImageDraft,
) -> BoxFuture<'_, Result<EventRecord, StoreError>>;
fn history(
&self,
query: HistoryQuery,
) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>;
fn audit_page(
&self,
print_id: PrintId,
after: Option<EventId>,
page_size: u32,
) -> BoxFuture<'_, Result<AuditPage, StoreError>>;
fn stored_after(
&self,
query: StoredQuery,
) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>;
fn newest_stored(
&self,
) -> BoxFuture<'_, Result<Option<EventId>, StoreError>>;
fn on_stored(&self, signal: StoredSignal);
}Expand description
The event log.
Every method is asynchronous, the trait is dyn-compatible, and it is
shareable across threads, because its consumers hold it behind
Arc<dyn EventStore>.
Required Methods§
Sourcefn append_event(
&self,
draft: EventDraft,
) -> BoxFuture<'_, Result<EventRecord, StoreError>>
fn append_event( &self, draft: EventDraft, ) -> BoxFuture<'_, Result<EventRecord, StoreError>>
Append one event, minting its identifier.
Sourcefn append_event_with_image(
&self,
draft: EventDraft,
image: ImageDraft,
) -> BoxFuture<'_, Result<EventRecord, StoreError>>
fn append_event_with_image( &self, draft: EventDraft, image: ImageDraft, ) -> BoxFuture<'_, Result<EventRecord, StoreError>>
Append one event together with the image it arrived with, minting both identifiers, and answer the event carrying that image.
The event and its image row are one write: no read of the event —
a history read, a cursor read, or a follower woken by
EventStore::on_stored — can find it without its image, and a write
refused leaves neither. The image belongs to the print the event does,
or to none when the event belongs to none.
§Errors
Refuses an event naming a print nothing holds, as
EventStore::append_event does, and answers StoreError::Io when
the image’s bytes cannot be written — in which case no event is stored.
Sourcefn history(
&self,
query: HistoryQuery,
) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>
fn history( &self, query: HistoryQuery, ) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>
Read a print’s events, newest first.
Answers newest first. An empty kinds means every kind rather
than no kinds. An absent limit takes DEFAULT_HISTORY_WINDOW, and a
limit above MAX_HISTORY_LIMIT is refused rather than clamped —
resolve_history_limit is the one resolution of that rule.
Sourcefn audit_page(
&self,
print_id: PrintId,
after: Option<EventId>,
page_size: u32,
) -> BoxFuture<'_, Result<AuditPage, StoreError>>
fn audit_page( &self, print_id: PrintId, after: Option<EventId>, page_size: u32, ) -> BoxFuture<'_, Result<AuditPage, StoreError>>
Read one page of a print’s whole history, oldest first.
after is the identifier of the last event of the previous page, and is
absent for the first page. The page size is resolved by
resolve_history_limit like a history read’s limit, so a page above
MAX_HISTORY_LIMIT is refused rather than clamped.
Sourcefn stored_after(
&self,
query: StoredQuery,
) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>
fn stored_after( &self, query: StoredQuery, ) -> BoxFuture<'_, Result<Vec<EventRecord>, StoreError>>
Read the events stored after a point, in the order they were stored.
Answers oldest first by the store’s own sequence — the order the
events were appended in, whatever their received_at — scoped as
StoredQuery says. A print with no event yet starts after the newest
event stored. The limit is resolved by resolve_history_limit.
§Errors
Refuses a cursor naming no event with StoreError::NotFound, and a
limit above MAX_HISTORY_LIMIT with StoreError::LimitRefused.
Sourcefn newest_stored(&self) -> BoxFuture<'_, Result<Option<EventId>, StoreError>>
fn newest_stored(&self) -> BoxFuture<'_, Result<Option<EventId>, StoreError>>
The newest event stored, by the store’s own sequence, when there is one.
Sourcefn on_stored(&self, signal: StoredSignal)
fn on_stored(&self, signal: StoredSignal)
Raise this signal after every write that stores an event has committed, from now on.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".