Skip to main content

weavatrix_memory/
store.rs

1mod file;
2pub(crate) mod frame;
3mod in_memory;
4mod subscription;
5
6pub use file::{Durability, FileEventStore, FileStoreOptions, RecoveryPolicy};
7pub use in_memory::InMemoryStore;
8pub use subscription::{CatchUpSubscription, SubscriptionCheckpoint};
9
10use crate::{NewEvent, Result, StoredEvent, StreamId};
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum ExpectedVersion {
14    Any,
15    NoStream,
16    Exact(u64),
17}
18
19pub trait EventStore<E: Clone> {
20    /// Atomically appends a batch to one stream.
21    ///
22    /// # Errors
23    ///
24    /// Returns a version conflict, duplicate event, or capacity error without
25    /// committing a partial batch.
26    fn append(
27        &mut self,
28        stream: &StreamId,
29        expected: ExpectedVersion,
30        events: &[NewEvent<E>],
31    ) -> Result<Vec<StoredEvent<E>>>;
32
33    /// Appends an owned batch without requiring callers to retain the inputs.
34    ///
35    /// Stores may override this to move payloads into committed envelopes and
36    /// avoid the input clone required by [`Self::append`].
37    ///
38    /// # Errors
39    ///
40    /// Returns the same version, duplicate-event, capacity, or persistence
41    /// errors as [`Self::append`].
42    fn append_owned(
43        &mut self,
44        stream: &StreamId,
45        expected: ExpectedVersion,
46        events: Vec<NewEvent<E>>,
47    ) -> Result<Vec<StoredEvent<E>>> {
48        self.append(stream, expected, &events)
49    }
50
51    fn load_stream(&self, stream: &StreamId, after: Option<u64>) -> Vec<StoredEvent<E>>;
52
53    fn load_all(&self, after: Option<u64>, limit: usize) -> Vec<StoredEvent<E>>;
54
55    fn stream_version(&self, stream: &StreamId) -> Option<u64>;
56
57    fn len(&self) -> usize;
58
59    fn is_empty(&self) -> bool {
60        self.len() == 0
61    }
62}