hocuspocus_rs_ws/store/
mod.rs

1// Portions of this module and its submodules are adapted from the Hocuspocus
2// JavaScript server (https://github.com/ueberdosis/hocuspocus) and y-sweet
3// (https://github.com/y-sweet/y-sweet), both distributed under the MIT license.
4// Adapted code retains the original license terms.
5
6pub mod memory;
7pub mod s3;
8
9use async_trait::async_trait;
10use thiserror::Error;
11
12#[derive(Error, Debug)]
13pub enum StoreError {
14    #[error("Store bucket does not exist. {0}")]
15    BucketDoesNotExist(String),
16    #[error("Object does not exist. {0}")]
17    DoesNotExist(String),
18    #[error("Not authorized to access store. {0}")]
19    NotAuthorized(String),
20    #[error("Error connecting to store. {0}")]
21    ConnectionError(String),
22}
23
24pub type Result<T> = std::result::Result<T, StoreError>;
25
26#[async_trait]
27pub trait Store: Send + Sync {
28    async fn init(&self) -> Result<()>;
29    async fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
30    async fn set(&self, key: &str, value: Vec<u8>) -> Result<()>;
31    async fn remove(&self, key: &str) -> Result<()>;
32    async fn exists(&self, key: &str) -> Result<bool>;
33}