aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/events.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/document/events.rs')
-rw-r--r--src/document/events.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/document/events.rs b/src/document/events.rs
index 95e99c9..1079999 100644
--- a/src/document/events.rs
+++ b/src/document/events.rs
@@ -163,6 +163,22 @@ pub(crate) fn started(fold: &str, root: &[u8], kept: &[Vec<u8>]) -> anyhow::Resu
Ok(doc.with_actor(ActorId::random()))
}
+/// The checkpoint `doc` holds at `_continuum/checkpoint`, where a remake's snapshot holds
+/// one other than the root (`snapshot`).
+pub(crate) fn checkpoint(doc: &impl ReadDoc) -> Option<Vec<u8>> {
+ let continuum = match doc.get(automerge::ROOT, meta::ROOT) {
+ Ok(Some((Value::Object(ObjType::Map), id))) => id,
+ _ => return None,
+ };
+ match doc.get(&continuum, meta::CHECKPOINT) {
+ Ok(Some((Value::Scalar(value), _))) => match value.as_ref() {
+ ScalarValue::Bytes(bytes) => Some(bytes.clone()),
+ _ => None,
+ },
+ _ => None,
+ }
+}
+
/// The ID of the store `doc` holds, its swarm's, where it holds one.
pub(crate) fn swarm(doc: &impl ReadDoc) -> Option<Id> {
match store::read_plain(doc, &meta::path(&[meta::SWARM])) {