1#[forbid(unsafe_code)]
2mod codec;
3mod doc;
4mod protocol;
5mod sync;
6
7pub use codec::*;
8pub use doc::{
9 Any, Array, Awareness, AwarenessEvent, Batch, Client, ClientMap, Clock, CrdtRead, CrdtReader, CrdtWrite,
10 CrdtWriter, Doc, DocOptions, HashMap as AHashMap, HashMapExt, History, HistoryOptions, Id, Map, RawDecoder,
11 RawEncoder, StateVector, StoreHistory, Text, Update, Value, batch_commit, encode_awareness_as_message,
12 encode_update_as_message, merge_updates_v1,
13};
14pub(crate) use doc::{Content, Item};
15use log::{debug, warn};
16use nom::IResult;
17pub use protocol::{
18 AwarenessState, AwarenessStates, DocMessage, SyncMessage, SyncMessageScanner, read_sync_message, write_sync_message,
19};
20use thiserror::Error;
21
22#[derive(Debug, Error, PartialEq)]
23pub enum JwstCodecError {
24 #[error("Unexpected Scenario")]
25 Unexpected,
26 #[error("Damaged document: corrupt json data")]
27 DamagedDocumentJson,
28 #[error("Incomplete document: {0}")]
29 IncompleteDocument(String),
30 #[error("Invalid write buffer: {0}")]
31 InvalidWriteBuffer(String),
32 #[error("Content does not support splitting in {0}")]
33 ContentSplitNotSupport(u64),
34 #[error("GC or Skip does not support splitting")]
35 ItemSplitNotSupport,
36 #[error("update is empty")]
37 UpdateIsEmpty,
38 #[error("invalid update")]
39 UpdateInvalid(#[from] nom::Err<nom::error::Error<usize>>),
40 #[error("update not fully consumed: {0}")]
41 UpdateNotFullyConsumed(usize),
42 #[error("invalid struct clock, expect {expect}, actually {actually}")]
43 StructClockInvalid { expect: u64, actually: u64 },
44 #[error("cannot find struct {clock} in {client_id}")]
45 StructSequenceInvalid { client_id: u64, clock: u64 },
46 #[error("struct {0} not exists")]
47 StructSequenceNotExists(u64),
48 #[error("Invalid parent")]
49 InvalidParent,
50 #[error("Parent not found")]
51 ParentNotFound,
52 #[error("Invalid struct type, expect item, actually {0}")]
53 InvalidStructType(&'static str),
54 #[error("Can not cast known type to {0}")]
55 TypeCastError(&'static str),
56 #[error("Can not found root struct with name: {0}")]
57 RootStructNotFound(String),
58 #[error("Index {0} out of bound")]
59 IndexOutOfBound(u64),
60 #[error("Document has been released")]
61 DocReleased,
62 #[error("Unexpected type, expect {0}")]
63 UnexpectedType(&'static str),
64}
65
66pub type JwstCodecResult<T = ()> = Result<T, JwstCodecError>;