crdb_core/
db.rs

1use crate::{BinPtr, EventId, Importance, Object, ObjectId, Updatedness};
2use std::sync::Arc;
3
4// TODO(api-high): Review what's in this trait (and in Client/ServerSideDb), and verify that everything is necessary
5// and, for Db, couldn't be moved to one of the side-specific traits.
6pub trait Db: 'static + waaaa::Send + waaaa::Sync {
7    /// Returns the new latest snapshot if it actually changed
8    ///
9    /// `updatedness` is the up-to-date-ness of this creation, or `None` if it is not known yet
10    /// (eg. it was initiated client-side and has not round-tripped to server yet)
11    fn create<T: Object>(
12        &self,
13        object_id: ObjectId,
14        created_at: EventId,
15        object: Arc<T>,
16        updatedness: Option<Updatedness>,
17        additional_importance: Importance,
18    ) -> impl waaaa::Future<Output = crate::Result<Option<Arc<T>>>>;
19
20    /// Returns the new latest snapshot if it actually changed
21    ///
22    /// `updatedness` is the up-to-date-ness of this submission, or `None` if it is not known yet
23    /// (eg. it was initiated client-side and has not round-tripped to server yet)
24    fn submit<T: Object>(
25        &self,
26        object_id: ObjectId,
27        event_id: EventId,
28        event: Arc<T::Event>,
29        updatedness: Option<Updatedness>,
30        additional_importance: Importance,
31    ) -> impl waaaa::Future<Output = crate::Result<Option<Arc<T>>>>;
32
33    fn get_latest<T: Object>(
34        &self,
35        object_id: ObjectId,
36        importance: Importance,
37    ) -> impl waaaa::Future<Output = crate::Result<Arc<T>>>;
38
39    fn create_binary(
40        &self,
41        binary_id: BinPtr,
42        data: Arc<[u8]>,
43    ) -> impl waaaa::Future<Output = crate::Result<()>>;
44
45    fn get_binary(
46        &self,
47        binary_id: BinPtr,
48    ) -> impl waaaa::Future<Output = crate::Result<Option<Arc<[u8]>>>>;
49
50    /// Returns the number of errors that happened while re-encoding
51    fn reencode_old_versions<T: Object>(&self) -> impl waaaa::Future<Output = usize>;
52
53    fn assert_invariants_generic(&self) -> impl waaaa::Future<Output = ()>;
54    fn assert_invariants_for<T: Object>(&self) -> impl waaaa::Future<Output = ()>;
55}