nstreams-core 0.2.2

Generic versioned event stream handler with history replay
Documentation
use async_trait::async_trait;

use crate::event::{EventVersion, StreamEvent};
use crate::namespace::Namespace;

/// Persistent event storage keyed by namespace.
#[async_trait]
pub trait EventStore: Send + Sync {
    /// Ensure storage exists for the namespace.
    async fn ensure_namespace<N: Namespace>(&self, namespace: &N) -> crate::Result<()>;

    /// Allocate the next monotonic version and persist the event atomically.
    async fn persist_next<N: Namespace>(
        &self,
        namespace: &N,
        payload: &[u8],
        filter_value: Option<&str>,
    ) -> crate::Result<StreamEvent>;

    /// Load up to `limit` most recent events in ascending version order.
    async fn load_history<N: Namespace>(
        &self,
        namespace: &N,
        limit: u64,
    ) -> crate::Result<Vec<StreamEvent>>;

    /// Load events with version strictly greater than `after_version`.
    async fn load_after_version<N: Namespace>(
        &self,
        namespace: &N,
        after_version: EventVersion,
        limit: u64,
    ) -> crate::Result<Vec<StreamEvent>>;

    /// Latest assigned version for the namespace, if any events exist.
    async fn latest_version<N: Namespace>(
        &self,
        namespace: &N,
    ) -> crate::Result<Option<EventVersion>>;
}