get-eventually / eventually-rs

Event Sourcing for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add EventStore::stream_all operation

ar3s3ru opened this issue · comments

The EventStore trait currently only supports stream operation, to stream events for a single "source" (i.e. Aggregate).

To move forward with the Projections and Subscriptions support, we need a stream_all method in order to stream the whole Event Store.

Proposed change:

pub trait EventStore {
    // ...
    
    fn stream_all(&self, select: Select) -> BoxFuture<Result<EventStream<Self>, Self::Error>>;
}

With this change, the PersistedEvent data now has to also include a SourceId type:

pub struct PersistedEvent<T, SourceId> {
    id: SourceId,
    event: T,
    // ...
}

impl<T, SourceId> PersistedEvent<T, SourceId> {
    /// Creates a new [`EventBuilder`] from the provided Event value and its Source id.
    ///
    /// [`EventBuilder`]: persistent/struct.EventBuilder.html
    #[inline]
    pub fn from(id: SourceId, event: T) -> persistent::EventBuilder<T, SourceId> {
        persistent::EventBuilder { id, event }
    }

    // ...
}

This will also require changes to the EventStream type:

pub type EventStream<'a, S> = BoxStream<'a, Result<
    PersistedEvent<<S as EventStore>::SourceId, <S as EventStore>::Event>,
    <S as EventStore>::Error
>>;