lores_app_node/stores/
mod.rs1use std::future::Future;
2use std::pin::Pin;
3
4use futures::Stream;
5
6use crate::types::{NodeId, OperationId};
7
8pub(crate) struct StorePublishResult {
10 pub operation_id: Option<OperationId>,
12 pub node_id: Option<NodeId>,
14}
15
16#[derive(Debug)]
18pub enum StoreError {
19 RegionNotBound(String),
21 Other(String),
23}
24
25impl std::fmt::Display for StoreError {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 match self {
28 StoreError::RegionNotBound(msg) => write!(f, "{msg}"),
29 StoreError::Other(msg) => write!(f, "{msg}"),
30 }
31 }
32}
33
34impl std::error::Error for StoreError {}
35
36pub(crate) struct RawOperationEvent {
39 pub payload: Vec<u8>,
40 pub author: Option<Vec<u8>>,
42 pub operation_id: Option<Vec<u8>>,
44 pub timestamp: Option<u64>,
46}
47
48impl RawOperationEvent {
49 pub(crate) fn new_local(payload: Vec<u8>) -> Self {
51 Self {
52 payload,
53 author: None,
54 operation_id: None,
55 timestamp: None,
56 }
57 }
58}
59
60pub(crate) type OperationStream = Pin<Box<dyn Stream<Item = Result<RawOperationEvent, StoreError>> + Send>>;
62
63pub(crate) trait OperationStore: Send + Sync + 'static {
68 fn publish(
70 &mut self,
71 payload: Vec<u8>,
72 idempotency_key: Option<String>,
73 ) -> Pin<Box<dyn Future<Output = Result<StorePublishResult, StoreError>> + Send + '_>>;
74
75 fn subscribe(&mut self) -> Pin<Box<dyn Future<Output = Result<OperationStream, StoreError>> + Send + '_>>;
80
81 fn replay(&mut self) -> Pin<Box<dyn Future<Output = Result<OperationStream, StoreError>> + Send + '_>> {
83 Box::pin(async move {
84 let s: OperationStream = Box::pin(futures::stream::empty());
85 Ok(s)
86 })
87 }
88}
89pub(crate) mod grpc;
90pub(crate) mod local;
91pub(crate) mod outbox;