use thiserror::Error;
use crate::operation::OperationId;
#[derive(Error, Debug)]
pub enum DocumentBuilderError {
#[error("Schema must be set")]
SchemaMustBeSet,
#[error("operation {0} cannot be connected to the document graph")]
InvalidOperationLink(OperationId),
#[error("multiple CREATE operations found when building operation graph")]
MultipleCreateOperations,
#[error(transparent)]
DocumentViewError(#[from] DocumentViewError),
#[error(transparent)]
GraphSortingError(#[from] crate::graph::error::GraphError),
#[error(transparent)]
DocumentReducerError(#[from] DocumentReducerError),
}
#[derive(Error, Debug)]
pub enum DocumentError {
#[error("operation {0} does not update the documents current view")]
PreviousDoesNotMatch(OperationId),
#[error("Operation {0} does not match the documents schema")]
InvalidSchemaId(OperationId),
#[error("Cannot perform a commit on a deleted document")]
UpdateOnDeleted,
#[error("Cannot update an existing document with a create operation")]
CommitCreate,
#[error(transparent)]
DocumentViewError(#[from] DocumentViewError),
#[error(transparent)]
GraphSortingError(#[from] crate::graph::error::GraphError),
}
#[derive(Error, Debug)]
pub enum DocumentReducerError {
#[error("The first operation of a document must be a CREATE")]
FirstOperationNotCreate,
#[error(transparent)]
DocumentError(#[from] DocumentError),
}
#[derive(Error, Debug)]
#[allow(missing_copy_implementations)]
pub enum DocumentViewError {
#[error("operation must be instantiated from a CREATE operation")]
NotCreateOperation,
#[error("operation passed to update() must be UPDATE or DELETE")]
NotUpdateOrDeleteOperation,
}
#[derive(Error, Debug)]
pub enum DocumentViewIdError {
#[error("expected sorted operation ids in document view id")]
UnsortedOperationIds,
#[error("expected one or more operation ids")]
ZeroOperationIds,
#[error(transparent)]
InvalidOperationId(#[from] crate::operation::error::OperationIdError),
}
#[derive(Error, Debug)]
pub enum DocumentIdError {
#[error(transparent)]
OperationIdError(#[from] crate::operation::error::OperationIdError),
}