use thiserror::Error;
use crate::operation::OperationId;
#[derive(Error, Debug)]
pub enum DocumentBuilderError {
#[error("every document must contain one create operation")]
NoCreateOperation,
#[error("multiple CREATE operations found")]
MoreThanOneCreateOperation,
#[error("all operations in a document must follow the same schema")]
OperationSchemaNotMatching,
#[error("Schema must be set")]
SchemaMustBeSet,
#[error("operation {0} cannot be connected to the document graph")]
InvalidOperationLink(OperationId),
#[error(transparent)]
DocumentViewError(#[from] DocumentViewError),
#[error(transparent)]
GraphSortingError(#[from] crate::graph::error::GraphError),
}
#[derive(Error, Debug)]
pub enum DocumentError {
#[error("operation {0} does not update the documents current view")]
PreviousDoesNotMatch(OperationId),
#[error("CREATE operation used to update document")]
InvalidOperationType,
#[error("Operation {0} does not match the documents schema")]
InvalidSchemaId(OperationId),
#[error("Cannot perform a commit on a deleted document")]
UpdateOnDeleted,
#[error(transparent)]
DocumentViewError(#[from] DocumentViewError),
#[error(transparent)]
GraphSortingError(#[from] crate::graph::error::GraphError),
}
#[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),
}