pub mod auth;
pub mod backend;
pub mod constants;
pub mod crdt;
pub mod database;
pub mod entry;
pub mod instance;
pub mod store;
pub mod sync;
pub mod transaction;
pub mod user;
pub use database::Database;
pub use entry::Entry;
pub use instance::{Instance, WeakInstance};
pub use store::Store;
pub use transaction::Transaction;
#[cfg(feature = "y-crdt")]
pub mod y_crdt {
pub use yrs::*;
}
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialize(#[from] serde_json::Error),
#[error(transparent)]
Auth(auth::AuthError),
#[error(transparent)]
Backend(backend::BackendError),
#[error(transparent)]
Instance(instance::InstanceError),
#[error(transparent)]
CRDT(crdt::CRDTError),
#[error(transparent)]
Store(store::StoreError),
#[error(transparent)]
Transaction(transaction::TransactionError),
#[error(transparent)]
Sync(sync::SyncError),
#[error(transparent)]
Entry(entry::EntryError),
#[error(transparent)]
Id(entry::id::IdError),
#[error(transparent)]
User(user::UserError),
}
impl From<sync::SyncError> for Error {
fn from(err: sync::SyncError) -> Self {
Error::Sync(err)
}
}
impl From<entry::EntryError> for Error {
fn from(err: entry::EntryError) -> Self {
Error::Entry(err)
}
}
impl From<entry::id::IdError> for Error {
fn from(err: entry::id::IdError) -> Self {
Error::Id(err)
}
}
impl From<user::UserError> for Error {
fn from(err: user::UserError) -> Self {
Error::User(err)
}
}
impl Error {
pub fn module(&self) -> &'static str {
match self {
Error::Auth(_) => "auth",
Error::Backend(_) => "backend",
Error::Instance(_) => "instance",
Error::CRDT(_) => "crdt",
Error::Store(_) => "store",
Error::Transaction(_) => "transaction",
Error::Sync(_) => "sync",
Error::Entry(_) => "entry",
Error::Id(_) => "id",
Error::User(_) => "user",
Error::Io(_) => "io",
Error::Serialize(_) => "serialize",
}
}
pub fn is_not_found(&self) -> bool {
match self {
Error::Auth(auth_err) => auth_err.is_key_not_found(),
Error::Backend(backend_err) => backend_err.is_not_found(),
Error::Instance(base_err) => base_err.is_not_found(),
Error::CRDT(crdt_err) => crdt_err.is_not_found_error(),
Error::Store(store_err) => store_err.is_not_found(),
Error::Sync(sync_err) => sync_err.is_not_found(),
_ => false,
}
}
pub fn is_permission_denied(&self) -> bool {
match self {
Error::Auth(auth_err) => auth_err.is_permission_denied(),
Error::Transaction(transaction_err) => transaction_err.is_authentication_error(),
_ => false,
}
}
pub fn is_conflict(&self) -> bool {
match self {
Error::Instance(base_err) => base_err.is_already_exists(),
_ => false,
}
}
pub fn is_authentication_error(&self) -> bool {
match self {
Error::Auth(_) => true,
Error::Instance(base_err) => base_err.is_authentication_error(),
Error::Transaction(transaction_err) => transaction_err.is_authentication_error(),
_ => false,
}
}
pub fn is_database_error(&self) -> bool {
matches!(self, Error::Backend(_))
}
pub fn is_integrity_error(&self) -> bool {
match self {
Error::Backend(backend_err) => backend_err.is_integrity_error(),
_ => false,
}
}
pub fn is_io_error(&self) -> bool {
match self {
Error::Io(_) => true,
Error::Backend(backend_err) => backend_err.is_io_error(),
_ => false,
}
}
pub fn is_base_database_error(&self) -> bool {
matches!(self, Error::Instance(_))
}
pub fn is_validation_error(&self) -> bool {
match self {
Error::Id(_) => true, Error::Instance(base_err) => base_err.is_validation_error(),
Error::Backend(backend_err) => backend_err.is_logical_error(),
Error::Transaction(transaction_err) => transaction_err.is_validation_error(),
Error::Entry(entry_err) => entry_err.is_validation_error(),
_ => false,
}
}
pub fn is_operation_error(&self) -> bool {
match self {
Error::Instance(base_err) => base_err.is_operation_error(),
Error::Store(store_err) => store_err.is_operation_error(),
Error::Transaction(transaction_err) => transaction_err.is_validation_error(),
_ => false,
}
}
pub fn is_type_error(&self) -> bool {
match self {
Error::Store(store_err) => store_err.is_type_error(),
_ => false,
}
}
pub fn is_crdt_error(&self) -> bool {
matches!(self, Error::CRDT(_))
}
pub fn is_crdt_merge_error(&self) -> bool {
match self {
Error::CRDT(crdt_err) => crdt_err.is_merge_error(),
_ => false,
}
}
pub fn is_crdt_serialization_error(&self) -> bool {
match self {
Error::CRDT(crdt_err) => crdt_err.is_serialization_error(),
_ => false,
}
}
pub fn is_crdt_type_error(&self) -> bool {
match self {
Error::CRDT(crdt_err) => crdt_err.is_type_error(),
_ => false,
}
}
pub fn is_store_error(&self) -> bool {
matches!(self, Error::Store(_))
}
pub fn is_store_serialization_error(&self) -> bool {
match self {
Error::Store(store_err) => store_err.is_serialization_error(),
_ => false,
}
}
pub fn is_store_type_error(&self) -> bool {
match self {
Error::Store(store_err) => store_err.is_type_error(),
_ => false,
}
}
pub fn is_already_committed(&self) -> bool {
match self {
Error::Transaction(transaction_err) => transaction_err.is_already_committed(),
_ => false,
}
}
pub fn is_entry_error(&self) -> bool {
match self {
Error::Transaction(transaction_err) => transaction_err.is_entry_error(),
Error::Entry(_) => true,
_ => false,
}
}
pub fn is_id_error(&self) -> bool {
matches!(self, Error::Id(_))
}
pub fn is_entry_validation_error(&self) -> bool {
match self {
Error::Entry(entry_err) => entry_err.is_validation_error(),
_ => false,
}
}
pub fn is_entry_serialization_error(&self) -> bool {
match self {
Error::Entry(entry_err) => entry_err.is_serialization_error(),
_ => false,
}
}
}